|
@@ -41,16 +41,7 @@
|
|
|
<view class="divider"></view>
|
|
<view class="divider"></view>
|
|
|
<view class="detail-body"><mp-html :content="article.content" :domain="config.API_BASE_URL" :tag-style="contentTagStyle" /></view>
|
|
<view class="detail-body"><mp-html :content="article.content" :domain="config.API_BASE_URL" :tag-style="contentTagStyle" /></view>
|
|
|
|
|
|
|
|
- <!-- 关联商品推荐(文章标签 ↔ 商品标签匹配,登录/匿名均可返回) -->
|
|
|
|
|
- <view v-if="relatedProducts.length > 0" class="related-section">
|
|
|
|
|
- <view class="related-header">
|
|
|
|
|
- <text class="related-title">相关商品</text>
|
|
|
|
|
- <text class="related-subtitle">根据文章内容推荐</text>
|
|
|
|
|
- </view>
|
|
|
|
|
- <dimension-products :products="relatedProducts" @productClick="goRelatedProduct" />
|
|
|
|
|
- </view>
|
|
|
|
|
-
|
|
|
|
|
- <!-- 相关文章(按标签关联,无匹配整块隐藏) -->
|
|
|
|
|
|
|
+ <!-- 相关文章(按标签关联,无匹配整块隐藏;触底分页加载) -->
|
|
|
<view v-if="relatedArticles.length > 0" class="related-section">
|
|
<view v-if="relatedArticles.length > 0" class="related-section">
|
|
|
<view class="related-header">
|
|
<view class="related-header">
|
|
|
<text class="related-title">相关文章</text>
|
|
<text class="related-title">相关文章</text>
|
|
@@ -71,6 +62,18 @@
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
+ <view v-if="relatedArticlesLoading" class="related-loading-hint">加载中...</view>
|
|
|
|
|
+ </view>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 关联商品推荐(文章标签 ↔ 商品标签匹配,登录/匿名均可返回;商城两列大卡片样式,触底分页加载) -->
|
|
|
|
|
+ <view v-if="relatedProducts.length > 0" class="related-section">
|
|
|
|
|
+ <view class="related-header">
|
|
|
|
|
+ <text class="related-title">相关商品</text>
|
|
|
|
|
+ <text class="related-subtitle">根据文章内容推荐</text>
|
|
|
|
|
+ </view>
|
|
|
|
|
+ <dimension-products :products="relatedProducts" layout="mall" @productClick="goRelatedProduct" />
|
|
|
|
|
+ <view v-if="relatedProductsLoading" class="related-loading-hint">加载中...</view>
|
|
|
|
|
+ <view v-else-if="relatedProductsNoMore" class="related-loading-hint dim">没有更多了</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
<!-- 评论区(已屏蔽) -->
|
|
<!-- 评论区(已屏蔽) -->
|
|
@@ -108,7 +111,11 @@
|
|
|
</view>
|
|
</view>
|
|
|
<text class="q-title">{{ currentQuestion.question }}</text>
|
|
<text class="q-title">{{ currentQuestion.question }}</text>
|
|
|
<view class="q-options">
|
|
<view class="q-options">
|
|
|
- <text v-for="(opt, oi) in currentQuestion.options" :key="oi" class="q-option" :class="{ selected: quizAnswers[currentQuizIndex] === String.fromCharCode(65 + oi) }" @click="selectQuizAnswer(currentQuizIndex, oi)">{{ opt }}</text>
|
|
|
|
|
|
|
+ <view v-for="(opt, oi) in currentQuestionOptions" :key="oi" class="q-option-row" :class="opt.selected ? 'selected' : ''" @click="selectQuizAnswer(currentQuizIndex, oi)">
|
|
|
|
|
+ <text class="q-option-letter">{{ opt.letter }}.</text>
|
|
|
|
|
+ <text class="q-option-text">{{ opt.text }}</text>
|
|
|
|
|
+ <text class="q-option-check">✓</text>
|
|
|
|
|
+ </view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="quiz-nav">
|
|
<view class="quiz-nav">
|
|
|
<button v-if="currentQuizIndex > 0" class="quiz-prev" @click="goPrevQuestion">上一题</button>
|
|
<button v-if="currentQuizIndex > 0" class="quiz-prev" @click="goPrevQuestion">上一题</button>
|
|
@@ -148,6 +155,9 @@ export default {
|
|
|
articleId: '', article: null, loading: true, error: false, errorMsg: '',
|
|
articleId: '', article: null, loading: true, error: false, errorMsg: '',
|
|
|
relatedProducts: [],
|
|
relatedProducts: [],
|
|
|
relatedArticles: [],
|
|
relatedArticles: [],
|
|
|
|
|
+ // 关联区块分页状态
|
|
|
|
|
+ relatedProductsPage: 1, relatedProductsLoading: false, relatedProductsNoMore: false,
|
|
|
|
|
+ relatedArticlesPage: 1, relatedArticlesLoading: false, relatedArticlesNoMore: false,
|
|
|
readingSeconds: 0, lastReportedSeconds: 0, readingCompleted: false,
|
|
readingSeconds: 0, lastReportedSeconds: 0, readingCompleted: false,
|
|
|
isTimerRunning: false, timerHandle: null, syncHandle: null,
|
|
isTimerRunning: false, timerHandle: null, syncHandle: null,
|
|
|
currentChildId: null, isLogin: false,
|
|
currentChildId: null, isLogin: false,
|
|
@@ -173,6 +183,20 @@ export default {
|
|
|
currentQuestion: function() {
|
|
currentQuestion: function() {
|
|
|
if (!this.quizQuestions || !this.quizQuestions.length) return null
|
|
if (!this.quizQuestions || !this.quizQuestions.length) return null
|
|
|
return this.quizQuestions[this.currentQuizIndex] || null
|
|
return this.quizQuestions[this.currentQuizIndex] || null
|
|
|
|
|
+ },
|
|
|
|
|
+ // 当前题的选项展示数据:统一派生字母、剥离后端自带前缀、标记选中态。
|
|
|
|
|
+ // 避免在模板 :class / 插值中调用方法(小程序渲染层不支持)且数组索引访问不响应。
|
|
|
|
|
+ currentQuestionOptions: function() {
|
|
|
|
|
+ var q = this.currentQuestion
|
|
|
|
|
+ if (!q || !q.options) return []
|
|
|
|
|
+ var selected = this.quizAnswers[this.currentQuizIndex] || ''
|
|
|
|
|
+ return q.options.map(function(opt, oi) {
|
|
|
|
|
+ var letter = String.fromCharCode(65 + oi)
|
|
|
|
|
+ var s = opt ? opt.toString().trim() : ''
|
|
|
|
|
+ // 剥离 "A." / "A)" / "(A)" 等常见前缀,字母由下方单独渲染避免重复
|
|
|
|
|
+ var cleaned = s.replace(/^[A-Za-z][\.\)\::]\s*/i, '').trim()
|
|
|
|
|
+ return { letter: letter, text: cleaned, selected: selected === letter }
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
onLoad(options) {
|
|
onLoad(options) {
|
|
@@ -220,33 +244,78 @@ export default {
|
|
|
this.article.content = this.resolveContentUrls(this.article.content)
|
|
this.article.content = this.resolveContentUrls(this.article.content)
|
|
|
this.setShareInfo('推荐阅读: ' + (res.data.title || ''), '/pages/article-center/article-detail?id=' + id)
|
|
this.setShareInfo('推荐阅读: ' + (res.data.title || ''), '/pages/article-center/article-detail?id=' + id)
|
|
|
this.startReadingTimer()
|
|
this.startReadingTimer()
|
|
|
- // 关联商品:放在 loadDetail 内只走一次(onShow 不重复请求,避免双发)
|
|
|
|
|
- this.loadRelatedProducts(id)
|
|
|
|
|
- // 相关文章:同样只走一次,无匹配时为空数组 → 模板整块隐藏
|
|
|
|
|
- this.loadRelatedArticles(id)
|
|
|
|
|
|
|
+ // 关联区块:放在 loadDetail 内只走一次(onShow 不重复请求,避免双发);先重置分页状态再加载第 1 页
|
|
|
|
|
+ this.resetRelatedState()
|
|
|
|
|
+ this.loadRelatedProducts(id, 1, false)
|
|
|
|
|
+ this.loadRelatedArticles(id, 1, false)
|
|
|
} else { this.error = true; this.errorMsg = '文章不存在或无权限查看' }
|
|
} else { this.error = true; this.errorMsg = '文章不存在或无权限查看' }
|
|
|
} catch (e) { this.error = true; this.errorMsg = '加载失败' }
|
|
} catch (e) { this.error = true; this.errorMsg = '加载失败' }
|
|
|
finally { this.loading = false }
|
|
finally { this.loading = false }
|
|
|
},
|
|
},
|
|
|
- // 加载文章关联商品(后端按 标签匹配数 > 用户权重 > 家庭权重 > 销量 排序)
|
|
|
|
|
- loadRelatedProducts: function(articleId) {
|
|
|
|
|
|
|
+ // 重置关联区块分页状态(loadDetail 每次加载前调用,避免切文章后旧状态残留)
|
|
|
|
|
+ resetRelatedState: function() {
|
|
|
|
|
+ this.relatedProductsPage = 1
|
|
|
|
|
+ this.relatedProductsLoading = false
|
|
|
|
|
+ this.relatedProductsNoMore = false
|
|
|
|
|
+ this.relatedArticlesPage = 1
|
|
|
|
|
+ this.relatedArticlesLoading = false
|
|
|
|
|
+ this.relatedArticlesNoMore = false
|
|
|
|
|
+ },
|
|
|
|
|
+ // 加载文章关联商品(后端按 标签匹配数 > 用户权重 > 家庭权重 > 销量 排序),每页 4 个,触底翻页
|
|
|
|
|
+ loadRelatedProducts: function(articleId, page, append) {
|
|
|
var self = this
|
|
var self = this
|
|
|
if (!articleId) return
|
|
if (!articleId) return
|
|
|
- getArticleRelatedProducts({ articleId: articleId, size: 4 }).then(function(res) {
|
|
|
|
|
|
|
+ var pg = page || 1
|
|
|
|
|
+ if (pg === 1) {
|
|
|
|
|
+ this.relatedProducts = []
|
|
|
|
|
+ this.relatedProductsNoMore = false
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.relatedProductsLoading) return
|
|
|
|
|
+ this.relatedProductsLoading = true
|
|
|
|
|
+ getArticleRelatedProducts({ articleId: articleId, size: 4, page: pg }).then(function(res) {
|
|
|
|
|
+ self.relatedProductsLoading = false
|
|
|
if (res && res.code === 200 && res.data && Array.isArray(res.data)) {
|
|
if (res && res.code === 200 && res.data && Array.isArray(res.data)) {
|
|
|
- self.relatedProducts = res.data
|
|
|
|
|
|
|
+ if (append && pg > 1) {
|
|
|
|
|
+ self.relatedProducts = self.relatedProducts.concat(res.data)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.relatedProducts = res.data
|
|
|
|
|
+ }
|
|
|
|
|
+ if (res.data.length < 4) self.relatedProductsNoMore = true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.relatedProductsNoMore = true
|
|
|
}
|
|
}
|
|
|
- }).catch(function() { self.relatedProducts = [] })
|
|
|
|
|
|
|
+ }).catch(function() {
|
|
|
|
|
+ self.relatedProductsLoading = false
|
|
|
|
|
+ self.relatedProductsNoMore = true
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
- // 加载相关文章(后端按共享标签数降序,无匹配返回空数组 → 前端整块隐藏)
|
|
|
|
|
- loadRelatedArticles: function(articleId) {
|
|
|
|
|
|
|
+ // 加载相关文章(后端按共享标签数降序),每页 3 篇,触底翻页;无匹配返回空数组 → 前端整块隐藏
|
|
|
|
|
+ loadRelatedArticles: function(articleId, page, append) {
|
|
|
var self = this
|
|
var self = this
|
|
|
if (!articleId) return
|
|
if (!articleId) return
|
|
|
- getRelatedArticles({ articleId: articleId, size: 3 }).then(function(res) {
|
|
|
|
|
|
|
+ var pg = page || 1
|
|
|
|
|
+ if (pg === 1) {
|
|
|
|
|
+ this.relatedArticles = []
|
|
|
|
|
+ this.relatedArticlesNoMore = false
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.relatedArticlesLoading) return
|
|
|
|
|
+ this.relatedArticlesLoading = true
|
|
|
|
|
+ getRelatedArticles({ articleId: articleId, size: 3, page: pg }).then(function(res) {
|
|
|
|
|
+ self.relatedArticlesLoading = false
|
|
|
if (res && res.code === 200 && res.data && Array.isArray(res.data)) {
|
|
if (res && res.code === 200 && res.data && Array.isArray(res.data)) {
|
|
|
- self.relatedArticles = res.data
|
|
|
|
|
|
|
+ if (append && pg > 1) {
|
|
|
|
|
+ self.relatedArticles = self.relatedArticles.concat(res.data)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.relatedArticles = res.data
|
|
|
|
|
+ }
|
|
|
|
|
+ if (res.data.length < 3) self.relatedArticlesNoMore = true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.relatedArticlesNoMore = true
|
|
|
}
|
|
}
|
|
|
- }).catch(function() { self.relatedArticles = [] })
|
|
|
|
|
|
|
+ }).catch(function() {
|
|
|
|
|
+ self.relatedArticlesLoading = false
|
|
|
|
|
+ self.relatedArticlesNoMore = true
|
|
|
|
|
+ })
|
|
|
},
|
|
},
|
|
|
// 跳转相关文章详情
|
|
// 跳转相关文章详情
|
|
|
goRelatedArticle: function(item) {
|
|
goRelatedArticle: function(item) {
|
|
@@ -294,7 +363,18 @@ export default {
|
|
|
}
|
|
}
|
|
|
return best ? best.code : ''
|
|
return best ? best.code : ''
|
|
|
},
|
|
},
|
|
|
- onScrollToBottom() {},
|
|
|
|
|
|
|
+ onScrollToBottom: function() {
|
|
|
|
|
+ // 触底优先翻页「相关商品」(页面下方区块),商品加载完再翻「相关文章」
|
|
|
|
|
+ if (this.relatedProducts.length > 0 && !this.relatedProductsNoMore && !this.relatedProductsLoading) {
|
|
|
|
|
+ this.relatedProductsPage++
|
|
|
|
|
+ this.loadRelatedProducts(this.articleId, this.relatedProductsPage, true)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.relatedArticles.length > 0 && !this.relatedArticlesNoMore && !this.relatedArticlesLoading) {
|
|
|
|
|
+ this.relatedArticlesPage++
|
|
|
|
|
+ this.loadRelatedArticles(this.articleId, this.relatedArticlesPage, true)
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
startNewReadingSession: function() {
|
|
startNewReadingSession: function() {
|
|
|
// 每次进入文章详情页都从 0 开始新会话,时长不延续上一次
|
|
// 每次进入文章详情页都从 0 开始新会话,时长不延续上一次
|
|
|
this.readingSeconds = 0
|
|
this.readingSeconds = 0
|
|
@@ -471,7 +551,9 @@ export default {
|
|
|
this.showResult = false
|
|
this.showResult = false
|
|
|
},
|
|
},
|
|
|
selectQuizAnswer: function(qi, oi) {
|
|
selectQuizAnswer: function(qi, oi) {
|
|
|
- this.quizAnswers[qi] = String.fromCharCode(65 + oi)
|
|
|
|
|
|
|
+ // Vue 2 中数组索引直接赋值(quizAnswers[qi] = x)不触发响应式更新,
|
|
|
|
|
+ // 必须用 $set 才能驱动选中态/圆点高亮刷新
|
|
|
|
|
+ this.$set(this.quizAnswers, qi, String.fromCharCode(65 + oi))
|
|
|
},
|
|
},
|
|
|
// 一题一页:上一题 / 下一题
|
|
// 一题一页:上一题 / 下一题
|
|
|
goPrevQuestion: function() {
|
|
goPrevQuestion: function() {
|
|
@@ -522,6 +604,8 @@ export default {
|
|
|
.related-header { display: flex; align-items: baseline; margin-bottom: 16rpx; }
|
|
.related-header { display: flex; align-items: baseline; margin-bottom: 16rpx; }
|
|
|
.related-title { font-size: 30rpx; font-weight: bold; color: #333; }
|
|
.related-title { font-size: 30rpx; font-weight: bold; color: #333; }
|
|
|
.related-subtitle { font-size: 20rpx; color: #999; margin-left: 12rpx; }
|
|
.related-subtitle { font-size: 20rpx; color: #999; margin-left: 12rpx; }
|
|
|
|
|
+.related-loading-hint { text-align: center; font-size: 22rpx; color: #F97316; padding: 16rpx 0 8rpx; }
|
|
|
|
|
+.related-loading-hint.dim { color: #bbb; }
|
|
|
|
|
|
|
|
/* 相关文章 */
|
|
/* 相关文章 */
|
|
|
.ra-list { display: flex; flex-direction: column; gap: 16rpx; }
|
|
.ra-list { display: flex; flex-direction: column; gap: 16rpx; }
|
|
@@ -557,8 +641,14 @@ export default {
|
|
|
.quiz-dot.done { background: #FDBA74; }
|
|
.quiz-dot.done { background: #FDBA74; }
|
|
|
.q-title { font-size: 30rpx; font-weight: 600; color: #333; line-height: 1.5; margin-bottom: 20rpx; }
|
|
.q-title { font-size: 30rpx; font-weight: 600; color: #333; line-height: 1.5; margin-bottom: 20rpx; }
|
|
|
.q-options { display: flex; flex-direction: column; gap: 12rpx; }
|
|
.q-options { display: flex; flex-direction: column; gap: 12rpx; }
|
|
|
-.q-option { padding: 16rpx 20rpx; border: 2rpx solid #E5E7EB; border-radius: 12rpx; font-size: 26rpx; color: #333; }
|
|
|
|
|
-.q-option.selected { border-color: #F97316; background: #FFF7ED; color: #92400E; }
|
|
|
|
|
|
|
+.q-option-row { display: flex; align-items: center; padding: 16rpx 20rpx; border: 2rpx solid #E5E7EB; border-radius: 12rpx; }
|
|
|
|
|
+.q-option-row.selected { border-color: #F97316; background: #FFF7ED; }
|
|
|
|
|
+.q-option-letter { width: 44rpx; font-size: 26rpx; font-weight: 600; color: #666; flex-shrink: 0; }
|
|
|
|
|
+.q-option-row.selected .q-option-letter { color: #F97316; }
|
|
|
|
|
+.q-option-text { flex: 1; min-width: 0; font-size: 26rpx; color: #333; }
|
|
|
|
|
+.q-option-row.selected .q-option-text { color: #92400E; }
|
|
|
|
|
+.q-option-check { width: 32rpx; height: 32rpx; border-radius: 50%; border: 3rpx solid #D1D5DB; color: transparent; font-size: 20rpx; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
|
|
|
|
|
+.q-option-row.selected .q-option-check { border-color: #F97316; background: #F97316; color: #fff; }
|
|
|
.quiz-nav { display: flex; gap: 16rpx; margin-top: 28rpx; }
|
|
.quiz-nav { display: flex; gap: 16rpx; margin-top: 28rpx; }
|
|
|
.quiz-prev { flex: 1; padding: 20rpx; background: #fff; color: #F97316; border: 2rpx solid #F97316; font-size: 28rpx; border-radius: 12rpx; }
|
|
.quiz-prev { flex: 1; padding: 20rpx; background: #fff; color: #F97316; border: 2rpx solid #F97316; font-size: 28rpx; border-radius: 12rpx; }
|
|
|
.quiz-prev::after { border: none; }
|
|
.quiz-prev::after { border: none; }
|