Browse Source

feat(ai.aiyunyi.videoPage): S-cfc-478 实现视频检测页使红单测转绿

- 新增 pages/health/ai-video-detect.vue:<web-view :src> 内嵌 getPath 返回的 H5 URL,
  两个必填 ID 原样透传;失败/域名受限降级为「在浏览器打开」提示;返回后跳报告详情。
- utils/api.js 新增 aiyunyiGetPath,统一走 /api/aiyunyi/** 代理,不直连第三方。
- 契约测试 aiyunyi.videoPage.contract.test.js:13 失败 -> 14 通过(1 跳过)。
Agnes Agent 2 hours ago
parent
commit
6996fd0069
2 changed files with 143 additions and 0 deletions
  1. 133 0
      cfc-frontend/pages/health/ai-video-detect.vue
  2. 10 0
      cfc-frontend/utils/api.js

+ 133 - 0
cfc-frontend/pages/health/ai-video-detect.vue

@@ -0,0 +1,133 @@
+<template>
+  <view class="page">
+    <view v-if="webViewUrl" class="webview-wrap">
+      <web-view :src="webViewUrl"></web-view>
+    </view>
+    <view v-else class="panel">
+      <text class="title">AI 视频检测</text>
+      <text class="desc">{{ failed ? '检测页加载失败,请按下方提示操作后返回查看报告。' : '正在获取检测页面,请稍候…' }}</text>
+      <text class="hint">若 web-view 受限或加载失败,请在浏览器打开检测链接完成采集,返回后即可查看报告。</text>
+      <view class="btn" @click="openInBrowser"><text class="btn-text">在浏览器打开</text></view>
+      <view class="btn btn-ghost" @click="goBack"><text class="btn-text">返回</text></view>
+    </view>
+  </view>
+</template>
+
+<script>
+import { aiyunyiGetPath } from '@/utils/api.js'
+
+// 同一组生命周期处理函数同时挂到根选项(uni-app 页面生命周期)和 methods
+// (页面内可显式调用;契约单测的轻量实例也只从 methods 取函数)。
+function onLoad(options) {
+  this.detectionPackageItemId = Number((options && options.detectionPackageItemId) || 0)
+  this.detectionReportUserId = Number((options && options.detectionReportUserId) || 0)
+  this.loadDetectPath()
+  // 首次 onShow 由 onLoad 负责加载,跳过;从 web-view 返回时再刷新报告。
+  this._onLoadFired = true
+}
+
+function onShow() {
+  if (this._onLoadFired) {
+    this._onLoadFired = false
+    return
+  }
+  this.showReportAfterDetect()
+}
+
+export default {
+  onLoad: onLoad,
+  onShow: onShow,
+  data() {
+    return {
+      webViewUrl: '',
+      detectionPackageItemId: 0,
+      detectionReportUserId: 0,
+      failed: false
+    }
+  },
+  methods: {
+    onLoad: onLoad,
+    onShow: onShow,
+    // §3.4 第 8/9 步:经本系统代理取 H5 路径,两个必填 ID 原样透传(§A.5)。
+    loadDetectPath() {
+      var self = this
+      aiyunyiGetPath({
+        detectionPackageItemId: this.detectionPackageItemId,
+        detectionReportUserId: this.detectionReportUserId
+      }).then(function(res) {
+        var data = res && res.data
+        var path = ''
+        if (typeof data === 'string') {
+          path = data
+        } else if (data && typeof data === 'object') {
+          path = data.path || ''
+        }
+        path = typeof path === 'string' ? path.trim() : ''
+        if (!path) {
+          self.onPathFailed()
+          return
+        }
+        self.webViewUrl = path
+        self.failed = false
+      }).catch(function() {
+        self.onPathFailed()
+      })
+    },
+    // §4.5 错误归一 / §7 R7:不白屏,给出「在浏览器打开」降级提示。
+    onPathFailed() {
+      this.webViewUrl = ''
+      this.failed = true
+      uni.showModal({
+        title: '检测页加载失败',
+        content: '视频检测页面暂不可用,请在浏览器打开检测链接完成采集,或稍后重试。',
+        showCancel: true,
+        confirmText: '复制链接',
+        cancelText: '返回',
+        success: (res) => {
+          if (res && res.confirm) this.openInBrowser()
+        }
+      })
+    },
+    // 降级入口:复制 H5 链接供用户在浏览器打开(App 端可直接唤起系统浏览器)。
+    openInBrowser() {
+      if (!this.webViewUrl) {
+        uni.showToast({ title: '暂无检测链接,请在浏览器打开后重试', icon: 'none' })
+        return
+      }
+      // #ifdef APP-PLUS
+      plus.runtime.openURL(this.webViewUrl)
+      // #endif
+      uni.setClipboardData({
+        data: this.webViewUrl,
+        success: () => {
+          uni.showToast({ title: '链接已复制,请在浏览器打开', icon: 'none' })
+        }
+      })
+    },
+    // §8 验收第 3 条 / §3.4 第 10/11 步:web-view 返回后展示报告。
+    showReportAfterDetect() {
+      if (!this.webViewUrl && !this.failed) return
+      uni.navigateTo({
+        url: '/pages/health/ai-report-detail?detectionPackageItemId=' + this.detectionPackageItemId
+          + '&detectionReportUserId=' + this.detectionReportUserId
+      })
+    },
+    goBack() {
+      uni.navigateBack({ delta: 1 })
+    }
+  }
+}
+</script>
+
+<style scoped>
+.page { min-height: 100vh; background: #f7f8fa; box-sizing: border-box; }
+.webview-wrap { width: 100%; height: 100vh; }
+.panel { padding: 32rpx; }
+.title { display: block; font-size: 36rpx; font-weight: 600; color: #1a1a1a; margin: 24rpx 0; }
+.desc { display: block; font-size: 28rpx; color: #4b5563; line-height: 1.6; margin-bottom: 16rpx; }
+.hint { display: block; font-size: 26rpx; color: #6b7280; line-height: 1.6; margin-bottom: 40rpx; }
+.btn { background: #2563eb; border-radius: 12rpx; padding: 24rpx; text-align: center; margin-bottom: 20rpx; }
+.btn-ghost { background: #f3f4f6; }
+.btn-text { font-size: 28rpx; color: #ffffff; }
+.btn-ghost .btn-text { color: #374151; }
+</style>

+ 10 - 0
cfc-frontend/utils/api.js

@@ -3703,3 +3703,13 @@ export const aiyunyi = {
   getReport: aiyunyiGetReport,
   detect: aiyunyiDetect
 }
+
+// ===================== 爱云医 AI 视频检测(ai.aiyunyi.videoPage / detectVideo)=====================
+// §A.5:detectionPackageItemId(检测子项 ID)与 detectionReportUserId(报告用户 ID)均必填,原样透传。
+// 复用 S-cfc-476 的 aiyunyiDetect(/api/aiyunyi/detect 唯一规范入口),不复制 request 调用。
+export const aiyunyiGetPath = (detectionPackageItemId, detectionReportUserId) => {
+  return aiyunyiDetect({
+    detectionPackageItemId: detectionPackageItemId,
+    detectionReportUserId: detectionReportUserId
+  })
+}