修改pk自动提交增加一个参数,增加签到判断
This commit is contained in:
@@ -119,13 +119,15 @@
|
||||
emits(
|
||||
'checkInFun',
|
||||
true,
|
||||
[{ changePoints: 5 }],
|
||||
[
|
||||
{
|
||||
pointsBadgeImg: '/traoss/tras3/show/S3F0250181220722025110713501700000661177',
|
||||
pointsBadgeName: '黄金徽章'
|
||||
}
|
||||
]
|
||||
res.body.points,
|
||||
res.body.pointsBadges,
|
||||
// [{ changePoints: 5 }],
|
||||
// [
|
||||
// {
|
||||
// pointsBadgeImg: '/traoss/tras3/show/S3F0250181220722025110713501700000661177',
|
||||
// pointsBadgeName: '黄金徽章'
|
||||
// }
|
||||
// ]
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -208,7 +210,7 @@
|
||||
|
||||
const open = (checkInToday, days) => {
|
||||
isSigned.value = checkInToday === 'Y' ? true : false; // 今日签到状态
|
||||
isSigned.value = false; // 今日签到状态
|
||||
// isSigned.value = false; // 今日签到状态
|
||||
continuousDay.value = days; // 连续签到
|
||||
// 示例:X=10时,以"10天前"为第1天,生成35天列表
|
||||
try {
|
||||
|
||||
@@ -26,67 +26,94 @@ import {
|
||||
export default function usePointsAndBadge() {
|
||||
const badgeRef = ref(null);
|
||||
const pointsRef = ref(null);
|
||||
|
||||
const pointAndBadgesRun = async (type, taskId = null, complete = () => {}) => {
|
||||
try {
|
||||
// 调用积分接口
|
||||
console.log('调用积分接口');
|
||||
const res = await addPointsByTask({
|
||||
type,
|
||||
taskId
|
||||
});
|
||||
if (type === '04') { // 完成课程练习,自己处理逻辑
|
||||
return {
|
||||
points: res.body.points,
|
||||
message: res.body.message,
|
||||
taskBadges: res.body.taskBadges ?? [],
|
||||
}
|
||||
}
|
||||
console.log('调用积分接口', res);
|
||||
console.log('pointsRefpointsRef', pointsRef.value);
|
||||
// 06AI问答 不弹出积分窗口
|
||||
if (type === '06') {
|
||||
if (res.body.pointsBadges.length > 0) {
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
badgeRef.value.open(res.body.points, res.body.pointsBadges, () => {
|
||||
badgeRef.value.close()
|
||||
complete(true, '', res);
|
||||
});
|
||||
}, pop_up_time);
|
||||
});
|
||||
} else {
|
||||
complete(true, '', res);
|
||||
}
|
||||
return
|
||||
}
|
||||
// 弹出积分窗口
|
||||
pointsRef.value.open(res.body.points, res.body.pointsBadges, (status, pointsList, badgesList) => {
|
||||
pointsRef.value.close()
|
||||
if (badgesList.length > 0) {
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
badgeRef.value.open(pointsList, badgesList, () => {
|
||||
badgeRef.value.close()
|
||||
complete(true, '积分获取成功', res);
|
||||
});
|
||||
}, pop_up_time);
|
||||
});
|
||||
} else {
|
||||
/**
|
||||
* 处理积分和徽章弹窗逻辑(提取的独立方法)
|
||||
* @param {number} points - 积分值
|
||||
* @param {Array} pointsBadges - 积分关联的徽章列表
|
||||
* @param {Function} complete - 完成回调函数
|
||||
* @param {any} res - 接口返回数据
|
||||
*/
|
||||
const handlePointsBadgePopup = (points, pointsBadges, complete = () => {}, res = {}) => {
|
||||
// AI问答仅弹徽章弹窗
|
||||
if (points?.length > 0) {
|
||||
// 普通场景:先弹积分弹窗,再弹徽章弹窗
|
||||
pointsRef.value?.open(points, pointsBadges, (status, pointsList, badgesList) => {
|
||||
pointsRef.value.close();
|
||||
// 有徽章则弹徽章弹窗,否则直接完成
|
||||
if (badgesList?.length > 0) {
|
||||
nextTick(() => {
|
||||
setTimeout(() => {
|
||||
badgeRef.value.open(pointsList, badgesList, () => {
|
||||
badgeRef.value.close();
|
||||
complete(true, '积分获取成功', res);
|
||||
});
|
||||
}, pop_up_time);
|
||||
});
|
||||
} else {
|
||||
complete(true, '积分获取成功', res);
|
||||
}
|
||||
});
|
||||
} else if (pointsBadges?.length > 0) {
|
||||
badgeRef.value.open([], pointsBadges, () => {
|
||||
badgeRef.value.close();
|
||||
complete(true, '积分获取成功', res);
|
||||
}
|
||||
});
|
||||
// complete(true, '积分获取成功', res);
|
||||
} catch (error) {
|
||||
// console.error(`类型${type}积分获取失败:`, error);
|
||||
// console.log('积分获取失败')
|
||||
complete(false, '积分获取失败', error);
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
pointAndBadgesRun,
|
||||
badgeRef,
|
||||
pointsRef
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 积分和徽章处理主方法
|
||||
* @param {string} type - 任务类型(04:课程练习,06:AI问答,其他:普通任务)
|
||||
* @param {string|null} taskId - 任务ID
|
||||
* @param {Function} complete - 完成回调(status, message, data)
|
||||
*/
|
||||
const pointAndBadgesRun = async (type, taskId = null, complete = () => {}) => {
|
||||
|
||||
try {
|
||||
console.log('调用积分接口');
|
||||
const res = await addPointsByTask({
|
||||
type,
|
||||
taskId
|
||||
});
|
||||
|
||||
// 防御性处理:确保res.body存在
|
||||
if (!res?.body) {
|
||||
complete(false, '积分接口返回数据异常', res);
|
||||
return;
|
||||
}
|
||||
const {
|
||||
points,
|
||||
pointsBadges,
|
||||
message = ''
|
||||
} = res.body;
|
||||
|
||||
// 分支逻辑:按类型处理
|
||||
switch (type) {
|
||||
case '04': // 04:课程练习,自定义返回逻辑,不弹弹窗
|
||||
complete(true, '', res.body); // 补充回调,避免调用方等待
|
||||
return;
|
||||
case '06': // 06:AI问答,仅弹徽章弹窗
|
||||
if (pointsBadges?.length > 0) {
|
||||
handlePointsBadgePopup(points, pointsBadges, complete, res);
|
||||
} else {
|
||||
complete(true, '', res);
|
||||
}
|
||||
return;
|
||||
// 其他类型:弹积分+徽章弹窗
|
||||
default:
|
||||
handlePointsBadgePopup(points, pointsBadges, complete, res);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
// 细化错误信息:区分网络错误/接口错误
|
||||
const errorMsg = error?.message || '积分获取失败';
|
||||
complete(false, `积分获取失败:${errorMsg}`, error);
|
||||
}
|
||||
};
|
||||
return {
|
||||
pointAndBadgesRun,
|
||||
handlePointsBadgePopup,
|
||||
badgeRef,
|
||||
pointsRef
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user