Răsfoiți Sursa

feat(frontend): S-cfc-504 单视频文章详情页默认全屏播放(article.detail.videoFullscreen)

Administrator 7 ore în urmă
părinte
comite
46e5aff104
1 a modificat fișierele cu 45 adăugiri și 2 ștergeri
  1. 45 2
      cfc-frontend/pages/article-center/article-detail.vue

+ 45 - 2
cfc-frontend/pages/article-center/article-detail.vue

@@ -39,7 +39,14 @@
           <text class="detail-summary-text">{{ article.summary }}</text>
           <text class="detail-summary-text">{{ article.summary }}</text>
         </view>
         </view>
         <view class="divider"></view>
         <view class="divider"></view>
-        <view class="detail-body"><mp-html :content="article.content" :domain="apiBaseUrl" :tag-style="contentTagStyle" /></view>
+        <view class="detail-body">
+          <video v-if="singleVideoSrc" id="article-single-video" class="detail-single-video"
+            :src="singleVideoSrc" :poster="article.coverImage || ''"
+            :autoplay="true" :controls="true" :show-center-play-btn="true"
+            object-fit="contain"
+            @play="onSingleVideoReady" @loadedmetadata="onSingleVideoReady" />
+          <mp-html v-else :content="article.content" :domain="apiBaseUrl" :tag-style="contentTagStyle" />
+        </view>
 
 
         <!-- 内容关联(相关文章 / 相关活动 / 相关商品,按标签匹配;无匹配整块隐藏,触底分页加载) -->
         <!-- 内容关联(相关文章 / 相关活动 / 相关商品,按标签匹配;无匹配整块隐藏,触底分页加载) -->
         <related-content ref="relatedContent" source-type="article" :source-id="articleId" />
         <related-content ref="relatedContent" source-type="article" :source-id="articleId" />
@@ -134,7 +141,10 @@ export default {
       showQuiz: false, quizQuestions: [], quizAnswers: [], showResult: false, quizResult: {}, quizRecordId: null, currentQuizIndex: 0,
       showQuiz: false, quizQuestions: [], quizAnswers: [], showResult: false, quizResult: {}, quizRecordId: null, currentQuizIndex: 0,
       mascotList: [{ icon: '🐶', name: '浠宝' }, { icon: '🐼', name: '福宝' }],
       mascotList: [{ icon: '🐶', name: '浠宝' }, { icon: '🐼', name: '福宝' }],
       mascotIcon: '🐶', mascotName: '浠宝',
       mascotIcon: '🐶', mascotName: '浠宝',
-      taskId: null
+      taskId: null,
+      // 单视频文章默认全屏(article.detail.videoFullscreen)
+      singleVideoSrc: '',          // 视频-only 文章解析出的 src;空=不启用
+      videoFullscreenFired: false  // 全屏守卫(只自动进一次)
     }
     }
   },
   },
   computed: {
   computed: {
@@ -212,6 +222,9 @@ export default {
           this.article = res.data
           this.article = res.data
           this.article.coverImage = this.getImageUrl(this.article.coverImage)
           this.article.coverImage = this.getImageUrl(this.article.coverImage)
           this.article.content = this.resolveContentUrls(this.article.content)
           this.article.content = this.resolveContentUrls(this.article.content)
+          // 单视频文章默认全屏:正文仅含一条视频(无实质文本/图片/其他媒体)时启用全屏播放
+          var rawContent = this.article.content || ''
+          this.singleVideoSrc = this.isVideoOnlyContent(rawContent) ? this.extractVideoSrc(rawContent) : ''
           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()
           // 内容关联区块由 <related-content> 组件自加载(sourceId=articleId),无需在此触发
           // 内容关联区块由 <related-content> 组件自加载(sourceId=articleId),无需在此触发
@@ -219,6 +232,35 @@ export default {
       } catch (e) { this.error = true; this.errorMsg = '加载失败' }
       } catch (e) { this.error = true; this.errorMsg = '加载失败' }
       finally { this.loading = false }
       finally { this.loading = false }
     },
     },
+    // 单视频文章判定:正文仅含一条视频(容忍编辑器尾部空段 <p><br></p> 等),无实质文本/图片/其他媒体/链接
+    isVideoOnlyContent: function (html) {
+      if (!html || typeof html !== 'string') return false
+      var videoRe = /<video\b[\s\S]*?(?:<\/video>|\/>)/gi
+      var videos = html.match(videoRe)
+      if (!videos || videos.length !== 1) return false
+      var rest = html.replace(videoRe, '')
+      // 剩余内容若含实质媒体/链接标签(img/iframe/source/audio/a 等),即使无文本也视为实质内容
+      if (/<(img|iframe|source|audio|embed|object|link|a|button|input|table|form)\b/i.test(rest)) return false
+      var text = rest.replace(/<[^>]+>/g, '').replace(/&nbsp;/gi, ' ').replace(/&[a-z]+;/gi, ' ').replace(/\s+/g, '')
+      return text === ''
+    },
+    // 从唯一 video 解析播放地址:优先 video src,其次内嵌 source src,无则空串
+    extractVideoSrc: function (html) {
+      if (!html || typeof html !== 'string') return ''
+      var m = html.match(/<video\b[^>]*?\ssrc\s*=\s*["']([^"']+)["']/i)
+      if (m) return m[1]
+      var s = html.match(/<source\b[^>]*?\ssrc\s*=\s*["']([^"']+)["']/i)
+      return s ? s[1] : ''
+    },
+    // 单视频就绪后自动进全屏(守卫:只自动进一次)
+    onSingleVideoReady: function () {
+      if (this.singleVideoSrc && !this.videoFullscreenFired) {
+        this.videoFullscreenFired = true
+        try {
+          uni.createVideoContext('article-single-video', this).requestFullScreen()
+        } catch (e) {}
+      }
+    },
     formatDate(d) { return d ? d.slice(0, 10) : '' },
     formatDate(d) { return d ? d.slice(0, 10) : '' },
     getImageUrl: function(path) {
     getImageUrl: function(path) {
       if (!path) return ''
       if (!path) return ''
@@ -481,6 +523,7 @@ export default {
 .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; }
 .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; }
 .divider { height: 1rpx; background: $facade-hairline-2; margin: 24rpx $uni-space-lg; }
 .divider { height: 1rpx; background: $facade-hairline-2; margin: 24rpx $uni-space-lg; }
 .detail-body { padding: 0 $uni-space-page; font-size: calc(32rpx * var(--font-scale, 1)); color: $facade-text-deep-2; line-height: 1.8; }
 .detail-body { padding: 0 $uni-space-page; font-size: calc(32rpx * var(--font-scale, 1)); color: $facade-text-deep-2; line-height: 1.8; }
+.detail-single-video { width: 100%; height: 480rpx; border-radius: 16rpx; background: #000; display: block; }
 
 
 .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; }
 .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; }
 .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; }
 .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; }