Commit 19857bb6 by Lin

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

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