Commit 19857bb6 by Lin

fix(prelearnBridge): 修复预学习数据处理逻辑

- 更新了预学习弹窗的数据结构,确保正确解析和使用活动产品ID及剩余跳过次数。
- 移除了不必要的API调用,简化了学习状态检查逻辑。
- 添加了调试日志以便于跟踪数据流。
1 parent 7b0ffcdf
......@@ -33,7 +33,7 @@ export default {
},
prelearnContext: {
type: Object,
default: () => ({skipCount: 2})
default: () => ({skipCount:0})
}
},
computed: {
......
......@@ -67,8 +67,10 @@ export default {
if (item.learnStatus !== 'NOT_STUDY') return
this.$emit('start-study', item, index)
console.log('预学习桥接页跳转***', item);
console.log('预学习桥接页跳转***', this.prelearnData);
this.prelearnData.activityProductId = item.activityProductId
const prelearnDataStr = encodeURIComponent(JSON.stringify(this.prelearnData))
console.log('预学习桥接页跳转***', prelearnDataStr);
uni.navigateTo({
url: `/pages/common/prelearnBridge?prelearnData=${prelearnDataStr}&entrySource=home_popup`,
fail: (err) => {
......
......@@ -144,13 +144,21 @@ export default {
try {
const prelearnData = JSON.parse(decodeURIComponent(options.prelearnData))
console.log('[prelearnBridge] 预学习弹窗数据 prelearnData:', prelearnData)
const { activityId, activityProductId, entrySource } = prelearnData
const { activityId, packages, remainingSkipCount, entrySource } = prelearnData
if (activityId != null) {
this.prelearnContext.activityId = String(activityId)
}
const notStudyPackage = (packages || []).find(
(pkg) => pkg.learnStatus === 'NOT_STUDY'
)
const activityProductId = prelearnData.activityProductId
?? notStudyPackage?.activityProductId
if (activityProductId != null) {
this.prelearnContext.activityProductId = String(activityProductId)
}
if (remainingSkipCount != null) {
this.prelearnContext.skipCount = remainingSkipCount
}
if (entrySource) {
this.prelearnContext.entrySource = entrySource
}
......@@ -740,11 +748,13 @@ export default {
// #endif
},
async checkMainPushStaffLearnStatus() {
console.log('[prelearnBridge] goodsInfo res:',this.goodsInfo)
console.log('[prelearnBridge] prelearnContext res:', this.prelearnContext)
const res = await uni.$api.activityApi.getPrelearnScriptBoardAPI({
activityId: this.goodsInfo.activityId || this.prelearnContext.activityId,
activityProductId: this.goodsInfo.productId || this.prelearnContext.activityProductId,
})
console.log('[prelearnBridge] getPrelearnScriptBoardAPI res:', res)
console.log('[prelearnBridge] 查询状态结果 res:', res)
const status = Number(res?.staffLearnStatus)
return status === 1 || status === 2
},
......@@ -761,8 +771,8 @@ export default {
this.navigateBack()
return
}
if (Number(this.isMainPush) === 1) {
console.log('this.isMainPush***', this.isMainPush);
// if (Number(this.isMainPush) === 1) {
try {
const learned = await this.checkMainPushStaffLearnStatus()
console.log("学习状态查询***", learned);
......@@ -775,31 +785,33 @@ export default {
console.error('[prelearnBridge] 预学习状态查询失败:', error)
this.showMainPushBackTip()
}
return
}
try {
const res = await uni.$api.commonApi.getPrelernHomePopupAPI()
console.log('[prelearnBridge] getPrelernHomePopupAPI res:', res)
const packages = res.packages || []
const allStudied = packages.length > 0 && packages.every(
(pkg) => pkg.learnStatus === 'STUDIED'
)
if (allStudied) {
this.navigateBack()
return
}
if (res.activityId != null) {
this.prelearnContext.activityId = String(res.activityId)
}
this.prelearnContext.skipCount = res.remainingSkipCount ?? 0
this.showBackPopup = true
} catch (error) {
console.error('[prelearnBridge] 预学习返回弹框查询失败:', error)
this.showBackPopup = true
}
// }
// try {
// const res = await uni.$api.commonApi.getPrelernHomePopupAPI()
// console.log('[prelearnBridge] getPrelernHomePopupAPI res:', res)
// const packages = res.packages || []
// const allStudied = packages.length > 0 && packages.every(
// (pkg) => pkg.learnStatus === 'STUDIED'
// )
// if (allStudied) {
// this.navigateBack()
// return
// }
// if (res.activityId != null) {
// this.prelearnContext.activityId = String(res.activityId)
// }
// // 仅当接口返回有效值时更新,避免 undefined 覆盖 onLoad 已写入的 skipCount
// if (res.remainingSkipCount != null) {
// this.prelearnContext.skipCount = res.remainingSkipCount
// }
// this.showBackPopup = true
// } catch (error) {
// console.error('[prelearnBridge] 预学习返回弹框查询失败:', error)
// this.showBackPopup = true
// }
},
handleBackPopupCancel() {
this.showBackPopup = false
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!