article-detail.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <view class="detail-container" :style="{ '--font-scale': fontScale }">
  3. <!-- 登录浮层(全局组件,页面内弹出底部登录) -->
  4. <login-sheet ref="loginSheet" @success="onSheetLoginSuccess" />
  5. <view v-if="loading" class="loading-wrap">
  6. <view class="loading-spinner"></view>
  7. <text class="loading-text">加载中...</text>
  8. </view>
  9. <view v-else-if="error" class="error-wrap">
  10. <text class="error-icon">📄</text>
  11. <text class="error-text">{{ errorMsg }}</text>
  12. <button class="retry-btn" @click="loadDetail(articleId)">重新加载</button>
  13. </view>
  14. <template v-else-if="article">
  15. <scroll-view scroll-y class="content-scroll" @scrolltolower="onScrollToBottom">
  16. <image v-if="article.coverImage" class="detail-cover" :src="article.coverImage" mode="widthFix" lazy-load />
  17. <text class="detail-title">{{ article.title }}</text>
  18. <view class="detail-meta">
  19. <text class="meta-author">{{ article.author || '浠艾福' }}</text>
  20. <text class="meta-sep">|</text>
  21. <text class="meta-date">{{ formatDate(article.publishedAt) }}</text>
  22. <text class="meta-sep">|</text>
  23. <text class="meta-readtime">{{ article.readTime || 3 }}分钟阅读</text>
  24. <text class="reading-time-badge" v-if="isLogin && !readingCompleted">{{ formatReadingTime(readingSeconds) }}</text>
  25. <text class="reading-time-badge completed" v-else-if="isLogin && readingCompleted">✅ 阅读完成</text>
  26. <text class="meta-sep" v-if="isLogin">|</text>
  27. <text class="meta-readcount">{{ article.viewCount || 0 }}人阅读</text>
  28. </view>
  29. <view class="detail-category-row">
  30. <text class="detail-category">{{ article.categoryName || '' }}</text>
  31. </view>
  32. <view v-if="article.relatedDimensions" class="detail-dimensions">
  33. <view v-for="dim in parseDimensions(article)" :key="dim.code" class="dim-bar-item">
  34. <view class="dim-bar" :style="{ background: dim.color, width: dim.weight + '%' }"></view>
  35. <text class="dim-label">{{ dim.name }}</text>
  36. </view>
  37. </view>
  38. <view class="detail-summary" v-if="article.summary">
  39. <text class="detail-summary-text">{{ article.summary }}</text>
  40. </view>
  41. <view class="divider"></view>
  42. <view class="detail-body"><mp-html :content="article.content" :domain="apiBaseUrl" :tag-style="contentTagStyle" /></view>
  43. <!-- 内容关联(相关文章 / 相关活动 / 相关商品,按标签匹配;无匹配整块隐藏,触底分页加载) -->
  44. <related-content ref="relatedContent" source-type="article" :source-id="articleId" />
  45. <!-- 评论区(已屏蔽) -->
  46. <view style="height: 200rpx;"></view>
  47. </scroll-view>
  48. <!-- 底部(听文章在右下角、生成海报在左下角) -->
  49. <view class="detail-footer">
  50. <view class="share-btn" @click="generatePoster">
  51. <image class="share-btn-icon" src="/static/icons/poster-white.png" mode="aspectFit" />
  52. <text class="share-btn-text">生成海报</text>
  53. </view>
  54. <view v-if="isLogin" class="listen-btn" :class="{ playing: audioPlaying }" @click="toggleArticleAudio">
  55. <text class="listen-btn-icon">{{ audioLoading ? '⏳' : (audioPlaying ? '⏸' : '🔊') }}</text>
  56. <text class="listen-btn-text">{{ audioLoading ? '生成中' : (audioPlaying ? '停止' : '听文章') }}</text>
  57. </view>
  58. </view>
  59. </template>
  60. <ContentSharePoster :show="showPoster" :title="(article && article.title) || ''" :coverImage="(article && article.coverImage) || ''" :qrCodeBase64="posterQrCode || ''" typeLabel="好文推荐" :dimensionCode="posterDimension || ''" :summary="posterSummary || ''" :inviteText="posterInviteText || ''" @close="closePoster" />
  61. <!-- 浠宝答题弹窗(一题一页) -->
  62. <view class="quiz-mask" v-if="showQuiz" @click="closeQuiz">
  63. <view class="quiz-dialog" @click.stop>
  64. <view class="quiz-mascot">
  65. <text class="mascot-icon">{{ mascotIcon }}</text>
  66. <text class="mascot-name">{{ mascotName }}</text>
  67. </view>
  68. <template v-if="currentQuestion">
  69. <view class="quiz-step-bar">
  70. <text class="quiz-step-text">第 {{ currentQuizIndex + 1 }} / {{ quizQuestions.length }} 题</text>
  71. <view class="quiz-dots">
  72. <view v-for="(q, qi) in quizQuestions" :key="qi" class="quiz-dot" :class="{ active: qi === currentQuizIndex, done: quizAnswers[qi] }"></view>
  73. </view>
  74. </view>
  75. <text class="q-title">{{ currentQuestion.question }}</text>
  76. <view class="q-options">
  77. <view v-for="(opt, oi) in currentQuestionOptions" :key="oi" class="q-option-row" :class="opt.selected ? 'selected' : ''" @click="selectQuizAnswer(currentQuizIndex, oi)">
  78. <text class="q-option-letter">{{ opt.letter }}.</text>
  79. <text class="q-option-text">{{ opt.text }}</text>
  80. <text class="q-option-check">✓</text>
  81. </view>
  82. </view>
  83. <view class="quiz-nav">
  84. <button v-if="currentQuizIndex > 0" class="quiz-prev" @click="goPrevQuestion">上一题</button>
  85. <button v-if="currentQuizIndex < quizQuestions.length - 1" class="quiz-submit" @click="goNextQuestion">下一题</button>
  86. <button v-else class="quiz-submit" @click="submitQuiz">提交答案</button>
  87. </view>
  88. </template>
  89. </view>
  90. </view>
  91. <!-- 答题结果 -->
  92. <view class="result-mask" v-if="showResult">
  93. <view class="result-dialog">
  94. <text class="result-icon">{{ resultIcon }}</text>
  95. <text class="result-text">答对 {{ quizResult.correctCount }}/{{ quizResult.totalQuestions }} 题</text>
  96. <text class="result-energy">获得 {{ quizResult.cfEarned }} CF值 + {{ quizResult.energyEarned }} 能量 ⚡</text>
  97. <button class="result-btn" @click="closeResult">知道了</button>
  98. </view>
  99. </view>
  100. </view>
  101. </template>
  102. <script>
  103. import { BrandColors } from '../../utils/brand-colors.js'
  104. import { getArticleDetail, getArticleAudio, reportReadingTime, getShareQrCode, completeArticleRead, generateQuiz, submitQuiz, completeTask } from '@/utils/api.js'
  105. import shareMixin from '../../components/share-mixin.js'
  106. import ContentSharePoster from '@/components/ContentSharePoster.vue'
  107. import RelatedContent from '@/components/RelatedContent.vue'
  108. import MpHtml from '@/components/mp-html/mp-html.vue'
  109. import config from '@/config.js'
  110. import { getFontScale } from '@/utils/fontScale.js'
  111. export default {
  112. mixins: [shareMixin],
  113. components: { ContentSharePoster, RelatedContent, MpHtml },
  114. data() {
  115. return {
  116. articleId: '', article: null, loading: true, error: false, errorMsg: '',
  117. readingSeconds: 0, lastReportedSeconds: 0, readingCompleted: false,
  118. isTimerRunning: false, timerHandle: null, syncHandle: null,
  119. currentChildId: null, isLogin: false,
  120. // 听文章(AI 朗读)
  121. audioUrls: [], audioPlaying: false, audioLoading: false, audioContext: null, audioChunkIndex: 0,
  122. showPoster: false, posterQrCode: '',
  123. posterDimension: '', posterSummary: '', posterInviteText: '',
  124. fontScale: 1,
  125. // 答题
  126. showQuiz: false, quizQuestions: [], quizAnswers: [], showResult: false, quizResult: {}, quizRecordId: null, currentQuizIndex: 0,
  127. mascotList: [{ icon: '🐶', name: '浠宝' }, { icon: '🐼', name: '福宝' }],
  128. mascotIcon: '🐶', mascotName: '浠宝',
  129. taskId: null
  130. }
  131. },
  132. computed: {
  133. // 模板中无法直接访问模块级 import 的 config(Vue 模板绑定解析为实例属性 this.config,实例上无此属性
  134. // → undefined.API_BASE_URL 抛错,导致文章详情页渲染中断)。经 computed 暴露 API 域名供模板使用;
  135. // 方法内仍可直接用模块级 config(函数作用域闭包引用,正常)。
  136. apiBaseUrl() {
  137. return config.API_BASE_URL
  138. },
  139. contentTagStyle() {
  140. var scale = this.fontScale || 1
  141. var fontSize = 32 * scale
  142. return { p: 'font-size:' + fontSize + 'rpx;color:#444;line-height:1.8;', div: 'font-size:' + fontSize + 'rpx;color:#444;line-height:1.8;', section: 'font-size:' + fontSize + 'rpx;color:#444;line-height:1.8;', li: 'font-size:' + fontSize + 'rpx;color:#444;line-height:1.8;', blockquote: 'font-size:' + fontSize + 'rpx;color:#444;line-height:1.8;' }
  143. },
  144. // 当前展示的一题(一题一页)
  145. currentQuestion: function() {
  146. if (!this.quizQuestions || !this.quizQuestions.length) return null
  147. return this.quizQuestions[this.currentQuizIndex] || null
  148. },
  149. // 当前题的选项展示数据:统一派生字母、剥离后端自带前缀、标记选中态。
  150. // 避免在模板 :class / 插值中调用方法(小程序渲染层不支持)且数组索引访问不响应。
  151. currentQuestionOptions: function() {
  152. var q = this.currentQuestion
  153. if (!q || !q.options) return []
  154. var selected = this.quizAnswers[this.currentQuizIndex] || ''
  155. return q.options.map(function(opt, oi) {
  156. var letter = String.fromCharCode(65 + oi)
  157. var s = opt ? opt.toString().trim() : ''
  158. // 剥离 "A." / "A)" / "(A)" 等常见前缀,字母由下方单独渲染避免重复
  159. var cleaned = s.replace(/^[A-Za-z][\.\)\::]\s*/i, '').trim()
  160. return { letter: letter, text: cleaned, selected: selected === letter }
  161. })
  162. }
  163. },
  164. onLoad(options) {
  165. this.mascotIcon = this.mascotList[Math.floor(Math.random() * 2)].icon
  166. this.mascotName = this.mascotList[Math.floor(Math.random() * 2)].name
  167. // 兼容旧分享链接:refCode / inviteCode 参数(shareMixin onLoad 也会处理,此处显式兜底)
  168. if (options && (options.refCode || options.inviteCode)) {
  169. this.autoBindInviteCode(options.refCode || options.inviteCode)
  170. }
  171. var aid = ''
  172. if (options && options.id) {
  173. aid = options.id
  174. } else if (options && options.scene) {
  175. try {
  176. var sceneDecoded = decodeURIComponent(options.scene)
  177. var idMatch = sceneDecoded.match(/id=(\d+)/)
  178. if (idMatch && idMatch[1]) aid = idMatch[1]
  179. var refMatch = sceneDecoded.match(/ref=([^&]+)/)
  180. if (refMatch && refMatch[1]) this.autoBindInviteCode(refMatch[1])
  181. } catch (e) {}
  182. }
  183. if (aid) { this.articleId = aid; this.loadDetail(aid) }
  184. else { this.error = true; this.errorMsg = '参数错误'; this.loading = false }
  185. this.taskId = options && options.taskId ? parseInt(options.taskId) : null
  186. this.currentChildId = uni.getStorageSync('currentChildId') || null
  187. this.isLogin = !!uni.getStorageSync('token')
  188. },
  189. onShow() {
  190. this.fontScale = getFontScale()
  191. var memberId = uni.getStorageSync('currentChildId')
  192. if (!this.article || this.error) return
  193. // 已登录用户(本人/成员/规划师)均可计时,匿名用户不计时
  194. if (this.isLogin) this.startNewReadingSession()
  195. },
  196. onHide() { this.pauseReadingTimer(); this.stopArticleAudio() },
  197. onUnload() { this.pauseReadingTimer(); this.stopArticleAudio() },
  198. methods: {
  199. async loadDetail(id) {
  200. this.loading = true; this.error = false
  201. try {
  202. var res = await getArticleDetail({ id: id })
  203. if (res.code === 200 && res.data) {
  204. this.article = res.data
  205. this.article.coverImage = this.getImageUrl(this.article.coverImage)
  206. this.article.content = this.resolveContentUrls(this.article.content)
  207. this.setShareInfo('推荐阅读: ' + (res.data.title || ''), '/pages/article-center/article-detail?id=' + id)
  208. this.startReadingTimer()
  209. // 内容关联区块由 <related-content> 组件自加载(sourceId=articleId),无需在此触发
  210. } else { this.error = true; this.errorMsg = '文章不存在或无权限查看' }
  211. } catch (e) { this.error = true; this.errorMsg = '加载失败' }
  212. finally { this.loading = false }
  213. },
  214. formatDate(d) { return d ? d.slice(0, 10) : '' },
  215. getImageUrl: function(path) {
  216. if (!path) return ''
  217. if (path.indexOf('http://') === 0 || path.indexOf('https://') === 0) return path
  218. return config.API_BASE_URL + path
  219. },
  220. resolveContentUrls: function(html) {
  221. if (!html) return html
  222. // 将富文本内容中的相对图片路径(/uploads/...)拼接为绝对 URL
  223. return html.replace(/(src|href)=["']\/(uploads\/[^"']+)/g, function(match, attr, path) {
  224. return attr + '="' + config.API_BASE_URL + '/' + path + '"'
  225. })
  226. },
  227. parseDimensions: function(article) {
  228. var dimMap = { body: { code: 'body', color: BrandColors.body, name: '身' }, mind: { code: 'mind', color: BrandColors.mind, name: '心' }, wisdom: { code: 'wisdom', color: BrandColors.wisdom, name: '智' }, action: { code: 'action', color: BrandColors.success, name: '行' }, wealth: { code: 'wealth', color: BrandColors.wealth, name: '富' } }
  229. var raw = article && article.relatedDimensions ? article.relatedDimensions.split(',').map(function(s) { return s.trim().toLowerCase() }) : []
  230. var weights = null
  231. if (article && article.dimensionWeights) try { var w = JSON.parse(article.dimensionWeights); if (w && typeof w === 'object') weights = w } catch (e) {}
  232. if (!weights) {
  233. var n = raw.filter(function(c) { return dimMap[c] }).length
  234. if (n > 0) { var base = Math.floor(100 / n); var rem = 100 - base * n; weights = {}; var i = 0; raw.forEach(function(c) { if (!dimMap[c]) return; weights[c] = i < rem ? base + 1 : base; i++ }) }
  235. }
  236. return raw.filter(function(c) { return dimMap[c] }).map(function(c) { return { code: dimMap[c].code, name: dimMap[c].name, color: dimMap[c].color, weight: (weights && weights[c]) ? weights[c] : 20 } })
  237. },
  238. getMainDimension: function() {
  239. var dims = this.article ? this.parseDimensions(this.article) : []
  240. var best = null
  241. var i
  242. for (i = 0; i < dims.length; i++) {
  243. if (!best || dims[i].weight > best.weight) best = dims[i]
  244. }
  245. return best ? best.code : ''
  246. },
  247. onScrollToBottom: function() {
  248. // 触底翻页内容关联区块(文章→活动→商品,按组件内 DOM 顺序)
  249. if (this.$refs.relatedContent && this.$refs.relatedContent.loadMore) {
  250. this.$refs.relatedContent.loadMore()
  251. }
  252. },
  253. startNewReadingSession: function() {
  254. // 每次进入文章详情页都从 0 开始新会话,时长不延续上一次
  255. this.readingSeconds = 0
  256. this.lastReportedSeconds = 0
  257. this.startReadingTimer()
  258. },
  259. // 获取当前操作对象的 memberId:优先 currentChildId(切换视角),否则用 userId
  260. getActiveMemberId: function() {
  261. var mid = uni.getStorageSync('currentChildId')
  262. if (mid) return parseInt(mid)
  263. var uid = uni.getStorageSync('userId')
  264. return uid ? parseInt(uid) : null
  265. },
  266. startReadingTimer: function() {
  267. // 无登录态时不计时(匿名浏览只显示时长要求,不计时)
  268. if (!this.isLogin) return
  269. if (this.isTimerRunning || this.readingCompleted) return
  270. this.isTimerRunning = true
  271. var self = this
  272. this.timerHandle = setInterval(function() { self.readingSeconds++ }, 1000)
  273. // 每 10 秒自动记录一次该用户已读时长
  274. this.syncHandle = setInterval(function() { self.reportReadingTime() }, 10000)
  275. },
  276. pauseReadingTimer: function() {
  277. if (!this.isTimerRunning) return
  278. this.isTimerRunning = false
  279. if (this.timerHandle) { clearInterval(this.timerHandle); this.timerHandle = null }
  280. if (this.syncHandle) { clearInterval(this.syncHandle); this.syncHandle = null }
  281. this.reportReadingTime()
  282. },
  283. async reportReadingTime() {
  284. var delta = this.readingSeconds - this.lastReportedSeconds
  285. if (delta <= 0) return
  286. this.lastReportedSeconds = this.readingSeconds
  287. var memberId = this.getActiveMemberId()
  288. if (!this.isLogin || !this.article) return
  289. reportReadingTime({ articleId: this.article.id, memberId: memberId || 0, durationSeconds: delta })
  290. // 达到阅读时长自动完成
  291. var targetSeconds = (this.article.readTime || 3) * 60
  292. if (!this.readingCompleted && this.readingSeconds >= targetSeconds) {
  293. this.readingCompleted = true
  294. this.pauseReadingTimer()
  295. try { await completeArticleRead({ articleId: this.article.id, memberId: memberId || 0, durationSeconds: this.readingSeconds }) } catch (e) {}
  296. uni.showToast({ title: '阅读完成 +5能量', icon: 'success' })
  297. // 弹出答题(登录用户)
  298. this.startQuiz()
  299. }
  300. },
  301. formatReadingTime: function(seconds) {
  302. if (seconds < 60) return '已读 ' + seconds + '秒'
  303. var min = Math.floor(seconds / 60); var sec = seconds % 60
  304. return '已读 ' + min + '分' + (sec > 0 ? sec + '秒' : '')
  305. },
  306. // 听文章:首次点击拉取(或复用已生成)音频,多段顺序播放;播放期间保证阅读计时运行
  307. async toggleArticleAudio() {
  308. if (this.audioPlaying) { this.stopArticleAudio(); return }
  309. if (this.audioLoading || !this.article) return
  310. if (this.audioUrls && this.audioUrls.length > 0) { this.playAudioChunk(0); return }
  311. this.audioLoading = true
  312. try {
  313. var res = await getArticleAudio({ articleId: this.article.id })
  314. if (res.code === 200 && res.data && res.data.audioUrls && res.data.audioUrls.length > 0) {
  315. this.audioUrls = res.data.audioUrls
  316. this.playAudioChunk(0)
  317. } else {
  318. uni.showToast({ title: (res && res.message) || '抱歉,音频暂不可用', icon: 'none' })
  319. }
  320. } catch (e) {
  321. uni.showToast({ title: '音频生成失败,请稍后重试', icon: 'none' })
  322. } finally {
  323. this.audioLoading = false
  324. }
  325. },
  326. playAudioChunk: function(index) {
  327. var self = this
  328. // 播放期间保证阅读计时运行(未登录不计时)
  329. if (this.isLogin && !this.isTimerRunning && !this.readingCompleted) this.startReadingTimer()
  330. this.audioChunkIndex = index
  331. var ctx = uni.createInnerAudioContext()
  332. this.audioContext = ctx
  333. ctx.src = this.audioUrls[index]
  334. ctx.onEnded(function() {
  335. if (index + 1 < self.audioUrls.length) { self.playAudioChunk(index + 1) }
  336. else { self.stopArticleAudio() }
  337. })
  338. ctx.onError(function() {
  339. uni.showToast({ title: '播放失败', icon: 'none' })
  340. self.stopArticleAudio()
  341. })
  342. ctx.play()
  343. this.audioPlaying = true
  344. },
  345. stopArticleAudio: function() {
  346. if (this.audioContext) {
  347. try { this.audioContext.stop() } catch (e) {}
  348. try { this.audioContext.destroy() } catch (e) {}
  349. this.audioContext = null
  350. }
  351. this.audioPlaying = false
  352. },
  353. async generatePoster() {
  354. if (!this.articleId) return
  355. uni.showLoading({ title: '生成海报中...' })
  356. try {
  357. if (!this.referralCode) {
  358. await this.loadReferralCode()
  359. }
  360. var scene = 'id=' + this.articleId + (this.referralCode ? '&ref=' + this.referralCode : '')
  361. if (scene.length > 32) {
  362. scene = scene.substring(0, 32)
  363. }
  364. var res = await getShareQrCode('pages/article-center/article-detail', scene)
  365. if (res && res.data) {
  366. this.posterQrCode = res.data.qrCodeBase64 || ''
  367. this.posterDimension = this.getMainDimension()
  368. this.posterSummary = (this.article && this.article.summary) || ''
  369. this.posterInviteText = '「' + (uni.getStorageSync('nickname') || '好友') + '」邀请你一起阅读这篇文章'
  370. this.showPoster = true
  371. }
  372. } catch (e) { uni.showToast({ title: '生成失败', icon: 'none' }) }
  373. finally { uni.hideLoading() }
  374. },
  375. // 答题
  376. async startQuiz() {
  377. if (!this.isLogin) {
  378. uni.showToast({ title: '登录后即可完成知识测评', icon: 'none' })
  379. setTimeout(() => { this.openLoginSheet() }, 1500)
  380. return
  381. }
  382. var memberId = this.getActiveMemberId()
  383. try {
  384. var res = await generateQuiz({ articleId: this.articleId, memberId: memberId || 0 })
  385. if (res.code === 200 && res.data && res.data.questions && res.data.questions.length > 0) {
  386. this.quizRecordId = res.data.recordId
  387. this.quizQuestions = res.data.questions
  388. this.quizAnswers = []
  389. this.currentQuizIndex = 0
  390. this.showQuiz = true
  391. }
  392. } catch (e) {}
  393. },
  394. async submitQuiz() {
  395. var memberId = this.getActiveMemberId()
  396. var answers = []
  397. for (var i = 0; i < this.quizQuestions.length; i++) {
  398. answers.push(this.quizAnswers[i] || '')
  399. }
  400. try {
  401. var res = await submitQuiz({ recordId: this.quizRecordId, memberId: parseInt(memberId || 0), answers: answers })
  402. if (res.code === 200) {
  403. this.quizResult = res.data || {}
  404. this.showQuiz = false
  405. this.showResult = true
  406. // 有关联任务:答完题即完成打卡任务
  407. if (this.taskId && memberId) {
  408. try {
  409. var cr = await completeTask(this.taskId, parseInt(memberId), '', '阅读+答题完成', 'text')
  410. if (cr && cr.data) {
  411. uni.showToast({ title: '任务已完成', icon: 'success' })
  412. }
  413. } catch (e) { /* ignore */ }
  414. }
  415. }
  416. } catch (e) {}
  417. },
  418. closePoster: function() {
  419. this.showPoster = false
  420. },
  421. closeQuiz: function() {
  422. this.showQuiz = false
  423. },
  424. closeResult: function() {
  425. this.showResult = false
  426. },
  427. selectQuizAnswer: function(qi, oi) {
  428. // Vue 2 中数组索引直接赋值(quizAnswers[qi] = x)不触发响应式更新,
  429. // 必须用 $set 才能驱动选中态/圆点高亮刷新
  430. this.$set(this.quizAnswers, qi, String.fromCharCode(65 + oi))
  431. },
  432. // 一题一页:上一题 / 下一题
  433. goPrevQuestion: function() {
  434. if (this.currentQuizIndex > 0) this.currentQuizIndex--
  435. },
  436. goNextQuestion: function() {
  437. if (this.currentQuizIndex < this.quizQuestions.length - 1) this.currentQuizIndex++
  438. }
  439. }
  440. }
  441. </script>
  442. <style scoped lang="scss">
  443. .detail-container { min-height: 100vh; background: $app-surface; }
  444. .loading-wrap { display: flex; flex-direction: column; align-items: center; padding-top: 300rpx; }
  445. .loading-spinner { width: 60rpx; height: 60rpx; border: 4rpx solid $facade-hairline; border-top-color: $uni-info; border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 20rpx; }
  446. @keyframes spin { 0% { transform: rotate(0deg); } 360% { transform: rotate(360deg); } }
  447. .loading-text { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-muted; }
  448. .error-wrap { display: flex; flex-direction: column; align-items: center; padding-top: 300rpx; }
  449. .error-icon { font-size: calc($uni-font-size-6xl * var(--font-scale, 1)); margin-bottom: 24rpx; }
  450. .error-text { font-size: calc(28rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-bottom: $uni-space-lg; }
  451. .retry-btn { width: 240rpx; height: 72rpx; line-height: 72rpx; background: $brand-primary; color: $app-surface; font-size: calc(28rpx * var(--font-scale, 1)); border-radius: 24rpx; text-align: center; border: none; }
  452. .content-scroll { height: calc(100vh - 120rpx); }
  453. .detail-cover { width: 100%; display: block; }
  454. .detail-title { display: block; font-size: calc(36rpx * var(--font-scale, 1)); font-weight: bold; color: $facade-text-strong; line-height: 1.4; padding: $uni-space-lg $uni-space-page 0; }
  455. .detail-meta { display: flex; align-items: center; padding: 16rpx $uni-space-page 0; font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-muted; flex-wrap: wrap; }
  456. .meta-author { color: $uni-info; }
  457. .meta-sep { margin: 0 12rpx; color: $facade-border-soft; }
  458. .reading-time-badge { margin-left: auto; font-size: calc(20rpx * var(--font-scale, 1)); color: $uni-info; background: rgba(14, 165, 233, 0.08); padding: 4rpx 12rpx; border-radius: 24rpx; white-space: nowrap; }
  459. .reading-time-badge.completed { color: $status-success; background: rgba(16,185,129,0.1); }
  460. .meta-readcount {
  461. font-size: calc(20rpx * var(--font-scale, 1));
  462. color: $facade-text-ghost-light;
  463. }
  464. .detail-category-row { padding: 16rpx $uni-space-page 0; }
  465. .detail-category { display: inline-block; font-size: calc(20rpx * var(--font-scale, 1)); color: $uni-info; background: rgba(14, 165, 233, 0.1); padding: 4rpx 16rpx; border-radius: 8rpx; }
  466. .detail-dimensions { padding: 16rpx $uni-space-page 0; display: flex; gap: 12rpx; }
  467. .dim-bar-item { flex: 1; }
  468. .dim-bar { height: 8rpx; border-radius: 8rpx; }
  469. .dim-label { font-size: calc(18rpx * var(--font-scale, 1)); color: $facade-text-muted; text-align: center; display: block; margin-top: 4rpx; }
  470. .detail-summary { padding: 20rpx $uni-space-page; }
  471. .detail-summary-text { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-faint; line-height: 1.7; display: block; border-left: 4rpx solid $brand-primary; padding-left: 20rpx; }
  472. .divider { height: 1rpx; background: $facade-hairline-2; margin: 24rpx $uni-space-lg; }
  473. .detail-body { padding: 0 $uni-space-page; font-size: calc(32rpx * var(--font-scale, 1)); color: $facade-text-deep-2; line-height: 1.8; }
  474. .detail-footer { position: fixed; bottom: 0; left: 0; right: 0; background: $app-surface; padding: 20rpx $uni-space-page; display: flex; align-items: center; gap: 16rpx; box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.06); z-index: 10; }
  475. .share-btn { height: 72rpx; padding: 0 $uni-space-page; background: linear-gradient(135deg, $brand-primary, $brand-primary-light); border-radius: 24rpx; display: flex; align-items: center; justify-content: center; border: none; }
  476. .share-btn::after { border: none; }
  477. .share-btn-icon { width: calc(34rpx * var(--font-scale, 1)); height: calc(34rpx * var(--font-scale, 1)); margin-right: 8rpx; flex-shrink: 0; }
  478. .share-btn-text { font-size: calc(26rpx * var(--font-scale, 1)); color: $app-surface; font-weight: 600; }
  479. .listen-btn { height: 72rpx; padding: 0 $uni-space-page; background: rgba(14, 165, 233, 0.1); border: 2rpx solid $uni-info; border-radius: 24rpx; display: flex; align-items: center; justify-content: center; }
  480. .listen-btn.playing { background: rgba(14, 165, 233, 0.2); }
  481. .listen-btn-icon { font-size: calc(30rpx * var(--font-scale, 1)); margin-right: 8rpx; }
  482. .listen-btn-text { font-size: calc(26rpx * var(--font-scale, 1)); color: $uni-info; font-weight: 600; }
  483. /* 答题弹窗 */
  484. .quiz-mask, .result-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 999; display: flex; align-items: center; justify-content: center; }
  485. .quiz-dialog, .result-dialog { background: $app-surface; border-radius: 24rpx; width: 650rpx; padding: 32rpx; }
  486. .quiz-mascot { display: flex; align-items: center; justify-content: center; gap: 12rpx; margin-bottom: 16rpx; }
  487. .mascot-icon { font-size: calc($uni-font-size-4xl * var(--font-scale, 1)); }
  488. .mascot-name { font-size: calc(32rpx * var(--font-scale, 1)); font-weight: 700; color: $brand-primary; }
  489. .quiz-step-bar { display: flex; align-items: center; justify-content: center; margin-bottom: 24rpx; }
  490. .quiz-step-text { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-right: 12rpx; }
  491. .quiz-dots { display: flex; align-items: center; gap: 8rpx; }
  492. .quiz-dot { width: 12rpx; height: 12rpx; border-radius: 50%; background: $facade-gray-200; }
  493. .quiz-dot.active { background: $brand-primary; }
  494. .quiz-dot.done { background: $mat-orange-300; }
  495. .q-title { font-size: calc(30rpx * var(--font-scale, 1)); font-weight: 600; color: $facade-text-strong; line-height: 1.5; margin-bottom: 20rpx; }
  496. .q-options { display: flex; flex-direction: column; gap: 12rpx; }
  497. .q-option-row { display: flex; align-items: center; padding: 16rpx 20rpx; border: 2rpx solid $facade-gray-200; border-radius: 16rpx; }
  498. .q-option-row.selected { border-color: $brand-primary; background: $uni-primary-pale; }
  499. .q-option-letter { width: 44rpx; font-size: calc(26rpx * var(--font-scale, 1)); font-weight: 600; color: $facade-text-body; flex-shrink: 0; }
  500. .q-option-row.selected .q-option-letter { color: $brand-primary; }
  501. .q-option-text { flex: 1; min-width: 0; font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-strong; }
  502. .q-option-row.selected .q-option-text { color: $status-warning-strong; }
  503. .q-option-check { width: 32rpx; height: 32rpx; border-radius: 50%; border: 3rpx solid $app-border-strong; color: transparent; font-size: calc(20rpx * var(--font-scale, 1)); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
  504. .q-option-row.selected .q-option-check { border-color: $brand-primary; background: $brand-primary; color: $app-surface; }
  505. .quiz-nav { display: flex; gap: 16rpx; margin-top: 28rpx; }
  506. .quiz-prev { flex: 1; padding: 20rpx; background: $app-surface; color: $brand-primary; border: 2rpx solid $brand-primary; font-size: calc(28rpx * var(--font-scale, 1)); border-radius: 16rpx; }
  507. .quiz-prev::after { border: none; }
  508. .quiz-submit { flex: 1; padding: 20rpx; background: linear-gradient(135deg, $brand-primary, $brand-primary-light); color: $app-surface; font-size: calc(28rpx * var(--font-scale, 1)); border-radius: 16rpx; border: none; }
  509. .quiz-submit::after { border: none; }
  510. .result-btn { width: 100%; padding: 20rpx; background: linear-gradient(135deg, $brand-primary, $brand-primary-light); color: $app-surface; font-size: calc(28rpx * var(--font-scale, 1)); border-radius: 16rpx; border: none; margin-top: 20rpx; }
  511. .result-dialog { text-align: center; }
  512. .result-icon { font-size: calc($uni-font-size-5xl * var(--font-scale, 1)); }
  513. .result-text { font-size: calc(32rpx * var(--font-scale, 1)); font-weight: 700; color: $facade-text-strong; margin: 16rpx 0; }
  514. .result-energy { font-size: calc(28rpx * var(--font-scale, 1)); color: $brand-primary; }
  515. </style>