fix:等待finish接口调用完成

This commit is contained in:
zxj
2025-12-12 14:39:02 +08:00
parent 738add6f18
commit 649a0ea0b9

View File

@@ -167,6 +167,7 @@
</div>
<div v-if="resType == 50" style="min-height: 500px">
<iframe
id="iframeId"
v-if="scormUrl"
:src="scormUrl"
frameborder="0"
@@ -944,6 +945,10 @@ export default {
warn: "测试内容",
warnTitle: "测试标题",
isFinishingStudyItem: false, // 防止重复调用完成状态更新接口
// // 全局状态:是否正在等待接口完成
// isWaitingForApis: false,
// // 待执行的切换操作(存储点击的目标课程)
// pendingSwitchAction: null,
};
},
mounted() {
@@ -958,6 +963,8 @@ export default {
this.stopStudyTime(); //先关闭
this.cleanAppendTime(); //
this.loadData();
// // 监听iframe接口
// this.checkAllApisCompleted();
},
computed: {
...mapGetters(["userInfo"]),
@@ -996,6 +1003,61 @@ export default {
},
},
methods: {
// 延迟执行课程切换操作
// delaySwitchCourse() {
// if (!pendingSwitchAction) return;
// // 轮询检查接口是否完成
// const pollTimer = setInterval(() => {
// const allApisDone = checkAllApisCompleted();
// if (allApisDone) {
// clearInterval(pollTimer);
// clearTimeout(timeoutTimer);
// isWaitingForApis = false;
// // 执行真正的课程切换
// executeCourseSwitch(pendingSwitchAction);
// pendingSwitchAction = null;
// }
// }, CONFIG.pollInterval);
// // 超时兜底:超过最大等待时间强制切换
// const timeoutTimer = setTimeout(() => {
// clearInterval(pollTimer);
// isWaitingForApis = false;
// console.warn("接口请求超时,强制切换课程");
// executeCourseSwitch(pendingSwitchAction);
// pendingSwitchAction = null;
// }, CONFIG.maxWaitTime);
// },
// checkAllApisCompleted() {
// const CONFIG = {
// // 需要等待完成的两个接口(支持模糊匹配)
// targetApis: ["/finish", "/update"],
// // iframe 元素ID
// iframeId: "iframeID",
// // 课程切换触发的元素选择器(比如课程列表的点击项)
// courseItemSelector: ".units-info",
// // 最大等待时间(防止接口卡住,单位:毫秒)
// maxWaitTime: 10000,
// // 轮询检查接口的间隔
// pollInterval: 200,
// };
// // 获取所有网络请求的性能数据
// const performanceEntries = performance.getEntriesByType("resource");
// // 筛选已完成的目标接口需同时满足URL匹配 + 有数据传输/完成)
// const completedApis = CONFIG.targetApis.filter((api) => {
// const entry = performanceEntries.find(
// (item) =>
// item.name.includes(api) &&
// item.transferSize > 0 && // 确保请求有数据传输(完成)
// item.responseEnd > 0 // 确认响应已结束
// );
// return !!entry;
// });
// // 两个接口都完成时返回true
// return completedApis.length === CONFIG.targetApis.length;
// },
handleOpen(key, path) {
if (this.isFalse) {
this.defaultOpeneds = [key];
@@ -1326,6 +1388,8 @@ export default {
this.contentData.status = 2;
},
showRes(r, i, index, item) {
console.log("showRes");
//i:子节下标index:章下标
// 无权限查看不能点击
if (!this.isCrowd) {
@@ -1374,7 +1438,9 @@ export default {
}
}
}
this.changePlayRes(r, item);
setTimeout(() => {
this.changePlayRes(r, item);
}, 10000);
},
loadScorePraiseAndTrample() {
//加载是否请过分