Просмотр исходного кода

feat(cfc-frontend): S-cfc-477 ai.aiyunyi.detectPage 识别流程页实现使绿 (19P/1S)

Administrator 3 часов назад
Родитель
Сommit
92c817fd75
2 измененных файлов с 505 добавлено и 8 удалено
  1. 500 0
      cfc-frontend/pages/health/ai-detect.vue
  2. 5 8
      cfc-frontend/pages/health/report-upload.vue

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

@@ -0,0 +1,500 @@
+<template>
+  <view class="ai-detect-page">
+    <!-- 检测人选择:复用 report-upload 的成员归属口径 -->
+    <view class="section">
+      <view class="section-title">选择检测人</view>
+      <scroll-view class="member-list" scroll-y>
+        <view
+          v-for="(member, idx) in familyMembers"
+          :key="getMemberKey(member, idx)"
+          class="member-item"
+          :class="{ 'member-selected': member._selected }"
+          @click="chooseMember(member)"
+        >
+          <text class="member-name">{{ member.nickname || member.name || '家庭成员' }}</text>
+          <text v-if="member._selected" class="member-check">✓</text>
+        </view>
+      </scroll-view>
+    </view>
+
+    <!-- 素材来源:拍照 / 图库 / 微信聊天 -->
+    <view class="section">
+      <view class="section-title">选择检测素材</view>
+      <view class="source-row">
+        <view class="source-btn" @click="choosePhoto">
+          <text class="source-icon">📷</text>
+          <text class="source-label">拍照</text>
+        </view>
+        <view class="source-btn" @click="choosePhotoFromAlbum">
+          <text class="source-icon">🖼️</text>
+          <text class="source-label">相册</text>
+        </view>
+        <view class="source-btn" @click="chooseFromChat">
+          <text class="source-icon">💬</text>
+          <text class="source-label">微信聊天</text>
+        </view>
+      </view>
+      <view v-if="photos.length" class="photo-list">
+        <view v-for="(photo, pidx) in photos" :key="getPhotoKey(photo, pidx)" class="photo-item">
+          <image class="photo-thumb" :src="photo" mode="aspectFill"></image>
+          <text class="photo-remove" @click="removePhoto(pidx)">×</text>
+        </view>
+      </view>
+      <text v-else class="empty-tip">请至少选择一张检测照片</text>
+    </view>
+
+    <!-- 数据使用声明 -->
+    <view class="section">
+      <view class="disclaimer-box" @click="toggleAgree">
+        <view class="disclaimer-checkbox" :class="{ 'disclaimer-checked': agreedToTerms }">
+          <text v-if="agreedToTerms" class="disclaimer-checkmark">✓</text>
+        </view>
+        <text class="disclaimer-label">我已阅读并同意以下声明</text>
+      </view>
+      <text class="disclaimer-desc">上传的照片仅用于本次 AI 检测分析,未经授权不会提供给任何第三方。</text>
+    </view>
+
+    <!-- 进度面板:异步生成报告期间保持「识别中」 -->
+    <view v-if="detecting" class="progress-panel">
+      <view class="progress-spinner"></view>
+      <text class="progress-text">{{ progressText || '识别中...' }}</text>
+      <text class="progress-sub">正在生成检测报告,请稍候</text>
+    </view>
+
+    <!-- 错误分支:未开通 / 次数用完 / 网络失败均明确提示,不白屏不崩溃 -->
+    <view v-if="errorMessage" class="error-panel">
+      <text class="error-text">{{ errorMessage }}</text>
+      <text class="error-hint">服务未开通请联系运营;检测次数用完请重新购买;网络失败请重试</text>
+    </view>
+
+    <view class="submit-row">
+      <view class="submit-btn" :class="{ 'submit-disabled': detecting }" @click="startDetect">
+        <text class="submit-label">{{ detecting ? '识别中' : '开始识别' }}</text>
+      </view>
+    </view>
+  </view>
+</template>
+
+<script>
+import { aiyunyiDetect, getFamilyMemberList } from '@/utils/api.js'
+import { pickImage } from '@/utils/image-picker.js'
+import { normalizeMembers, memberIdOf } from '@/utils/memberNormalize.js'
+import fontScaleMixin from '@/mixins/font-scale.js'
+
+// 报告异步生成的轮询节奏:复用现有报告上传的 4s 间隔
+var POLL_INTERVAL = 4000
+var MAX_POLL_COUNT = 30
+
+export default {
+  mixins: [fontScaleMixin],
+  data() {
+    return {
+      memberId: null,
+      familyMembers: [],
+      agreedToTerms: false,
+      photos: [],
+      detecting: false,
+      progressText: '识别中...',
+      errorMessage: '',
+      reportId: null,
+      _pollCount: 0,
+      _pollTimer: null
+    }
+  },
+  onLoad(options) {
+    if (options && options.memberId) {
+      this.memberId = parseInt(options.memberId)
+    }
+    this.loadMembers()
+  },
+  onUnload() {
+    if (this._pollTimer) {
+      clearTimeout(this._pollTimer)
+      this._pollTimer = null
+    }
+  },
+  methods: {
+    getMemberKey: function (member, idx) {
+      var id = memberIdOf(member)
+      return id !== null && id !== undefined ? ('m' + id) : ('m' + idx)
+    },
+    getPhotoKey: function (photo, idx) {
+      return 'p' + idx
+    },
+    loadMembers: function () {
+      var self = this
+      getFamilyMemberList({}).then(function (res) {
+        var list = (res && res.data) || []
+        self.familyMembers = normalizeMembers(list instanceof Array ? list : [], {
+          userId: uni.getStorageSync('userId')
+        })
+        var target = self.memberId
+        for (var i = 0; i < self.familyMembers.length; i++) {
+          var cur = memberIdOf(self.familyMembers[i])
+          self.familyMembers[i]._selected = (target !== null && cur === target)
+        }
+      }).catch(function () {
+        self.familyMembers = []
+      })
+    },
+    chooseMember: function (member) {
+      var id = memberIdOf(member)
+      this.memberId = id
+      var list = this.familyMembers || []
+      for (var i = 0; i < list.length; i++) {
+        list[i]._selected = (memberIdOf(list[i]) === id)
+      }
+    },
+    toggleAgree: function () {
+      this.agreedToTerms = !this.agreedToTerms
+    },
+    // 拍照 / 图库:统一走 pickImage,sourceType 同时含 camera 与 album
+    choosePhoto: function () {
+      this.pickFromCamera(['camera', 'album'])
+    },
+    choosePhotoFromAlbum: function () {
+      this.pickFromCamera(['album', 'camera'])
+    },
+    pickFromCamera: function (sourceType) {
+      var self = this
+      pickImage({
+        count: 9,
+        sizeType: ['compressed'],
+        sourceType: sourceType || ['camera', 'album'],
+        success: function (res) {
+          var paths = (res && res.tempFilePaths) || []
+          if (paths.length) {
+            self.photos = self.photos.concat(paths)
+          }
+        },
+        fail: function () {
+          uni.showToast({ title: '选图失败,请重试', icon: 'none' })
+        }
+      })
+    },
+    // 微信聊天来源:小程序必须用 chooseMessageFile
+    chooseFromChat: function () {
+      var self = this
+      uni.chooseMessageFile({
+        count: 9,
+        type: 'image',
+        success: function (res) {
+          var files = (res && res.tempFiles) || []
+          var paths = []
+          for (var i = 0; i < files.length; i++) {
+            if (files[i] && files[i].path) paths.push(files[i].path)
+          }
+          if (paths.length) {
+            self.photos = self.photos.concat(paths)
+          }
+        },
+        fail: function () {
+          uni.showToast({ title: '选图失败,请重试', icon: 'none' })
+        }
+      })
+    },
+    removePhoto: function (idx) {
+      var next = []
+      for (var i = 0; i < this.photos.length; i++) {
+        if (i !== idx) next.push(this.photos[i])
+      }
+      this.photos = next
+    },
+    normalizeError: function (err) {
+      var code = err && err.code
+      if (code === 'NO_PRODUCT') return '该服务尚未开通,请联系运营'
+      if (code === 'NO_ITEM') return '检测次数已用完,请重新购买'
+      if (err instanceof Error || !err || !err.message) return '网络失败,请重试'
+      return err.message
+    },
+    // 提交识别:成员归属 + 声明勾选 + 素材三重门禁,任一不满足则拦截提示
+    startDetect: async function () {
+      var self = this
+      self.errorMessage = ''
+      if (!self.memberId) {
+        uni.showToast({ title: '请先选择检测人', icon: 'none' })
+        return
+      }
+      if (!self.agreedToTerms) {
+        uni.showToast({ title: '请先阅读并同意声明', icon: 'none' })
+        return
+      }
+      if (!self.photos || !self.photos.length) {
+        uni.showToast({ title: '请先选择至少一张检测照片', icon: 'none' })
+        return
+      }
+      self.detecting = true
+      self.progressText = '识别中...'
+      uni.showLoading({ title: '识别中...' })
+      try {
+        var res = await aiyunyiDetect({
+          memberId: self.memberId,
+          photos: self.photos.slice()
+        })
+        if (res && res.code !== 200 && res.code !== 0) {
+          throw { code: res.code, message: res.message || '识别失败' }
+        }
+        var data = (res && res.data) || {}
+        if (data.reportId) {
+          self.finishWithReport(data.reportId)
+          return
+        }
+        // 平台异步生成报告:进入 4s 轮询,保持「识别中」状态
+        self._pollCount = 0
+        self._pollTimer = setTimeout(function () { self.pollStatus() }, POLL_INTERVAL)
+      } catch (err) {
+        self.failWithError(err)
+      }
+    },
+    pollStatus: function () {
+      var self = this
+      self._pollCount = (self._pollCount || 0) + 1
+      if (self._pollCount > MAX_POLL_COUNT) {
+        self.detecting = false
+        self.progressText = ''
+        self.errorMessage = '识别超时,请稍后在报告列表查看'
+        uni.hideLoading()
+        uni.showToast({ title: self.errorMessage, icon: 'none' })
+        return
+      }
+      aiyunyiDetect({ memberId: self.memberId, poll: true }).then(function (res) {
+        var data = (res && res.data) || {}
+        if (data.reportId || data.status === 2 || data.completed) {
+          self.finishWithReport(data.reportId || self.reportId)
+          return
+        }
+        self.progressText = '识别中...'
+        self._pollTimer = setTimeout(function () { self.pollStatus() }, 4000)
+      }).catch(function (err) {
+        self.failWithError(err)
+      })
+    },
+    finishWithReport: function (reportId) {
+      var self = this
+      self.reportId = reportId
+      self.detecting = false
+      self.progressText = ''
+      self.errorMessage = ''
+      uni.hideLoading()
+      uni.navigateTo({
+        url: '/pages/health/ai-report-detail?reportId=' + reportId
+      })
+    },
+    failWithError: function (err) {
+      var self = this
+      self.detecting = false
+      self.progressText = ''
+      self.errorMessage = self.normalizeError(err)
+      uni.hideLoading()
+      uni.showToast({ title: self.errorMessage, icon: 'none' })
+    }
+  }
+}
+</script>
+
+<style scoped>
+.ai-detect-page {
+  min-height: 100vh;
+  background: #f7f8fa;
+  padding: 24rpx;
+  box-sizing: border-box;
+}
+.section {
+  background: #fff;
+  border-radius: 16rpx;
+  padding: 24rpx;
+  margin-bottom: 24rpx;
+}
+.section-title {
+  font-size: 30rpx;
+  font-weight: 600;
+  color: #222;
+  margin-bottom: 20rpx;
+}
+.member-list {
+  max-height: 320rpx;
+}
+.member-item {
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  padding: 20rpx 0;
+  border-bottom: 1rpx solid #f0f0f0;
+}
+.member-selected .member-name {
+  color: #e08a3c;
+  font-weight: 600;
+}
+.member-name {
+  font-size: 28rpx;
+  color: #333;
+}
+.member-check {
+  color: #e08a3c;
+  font-size: 28rpx;
+}
+.source-row {
+  display: flex;
+  flex-direction: row;
+  align-items: center;
+  justify-content: space-between;
+}
+.source-btn {
+  flex: 1;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+  padding: 24rpx 0;
+  margin: 0 8rpx;
+  background: #fff8ef;
+  border-radius: 12rpx;
+}
+.source-icon {
+  font-size: 44rpx;
+}
+.source-label {
+  font-size: 26rpx;
+  color: #555;
+  margin-top: 12rpx;
+}
+.photo-list {
+  display: flex;
+  flex-direction: row;
+  flex-wrap: wrap;
+  margin-top: 20rpx;
+}
+.photo-item {
+  position: relative;
+  width: 160rpx;
+  height: 160rpx;
+  margin: 8rpx;
+}
+.photo-thumb {
+  width: 160rpx;
+  height: 160rpx;
+  border-radius: 8rpx;
+}
+.photo-remove {
+  position: absolute;
+  top: 0;
+  right: 0;
+  width: 40rpx;
+  height: 40rpx;
+  line-height: 40rpx;
+  text-align: center;
+  background: rgba(0, 0, 0, 0.5);
+  color: #fff;
+  font-size: 28rpx;
+  border-radius: 0 8rpx 0 8rpx;
+}
+.empty-tip {
+  display: block;
+  font-size: 24rpx;
+  color: #999;
+  margin-top: 20rpx;
+}
+.disclaimer-box {
+  display: flex;
+  flex-direction: row;
+  align-items: center;
+}
+.disclaimer-checkbox {
+  width: 34rpx;
+  height: 34rpx;
+  border: 2rpx solid #ccc;
+  border-radius: 6rpx;
+  margin-right: 14rpx;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+}
+.disclaimer-checked {
+  background: #e08a3c;
+  border-color: #e08a3c;
+}
+.disclaimer-checkmark {
+  color: #fff;
+  font-size: 24rpx;
+}
+.disclaimer-label {
+  font-size: 26rpx;
+  color: #444;
+}
+.disclaimer-desc {
+  display: block;
+  font-size: 22rpx;
+  color: #999;
+  margin-top: 14rpx;
+  line-height: 1.6;
+}
+.progress-panel {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  background: #fff;
+  border-radius: 16rpx;
+  padding: 40rpx 24rpx;
+  margin-bottom: 24rpx;
+}
+.progress-spinner {
+  width: 60rpx;
+  height: 60rpx;
+  border: 6rpx solid #f3e2ce;
+  border-top-color: #e08a3c;
+  border-radius: 50%;
+  animation: spin 1s linear infinite;
+}
+@keyframes spin {
+  to { transform: rotate(360deg); }
+}
+.progress-text {
+  font-size: 30rpx;
+  color: #e08a3c;
+  font-weight: 600;
+  margin-top: 20rpx;
+}
+.progress-sub {
+  font-size: 24rpx;
+  color: #999;
+  margin-top: 10rpx;
+}
+.error-panel {
+  background: #fff3f3;
+  border-radius: 16rpx;
+  padding: 24rpx;
+  margin-bottom: 24rpx;
+}
+.error-text {
+  display: block;
+  font-size: 26rpx;
+  color: #c0392b;
+  font-weight: 600;
+}
+.error-hint {
+  display: block;
+  font-size: 22rpx;
+  color: #a66;
+  margin-top: 12rpx;
+  line-height: 1.6;
+}
+.submit-row {
+  padding: 16rpx 0 40rpx;
+}
+.submit-btn {
+  background: #e08a3c;
+  border-radius: 44rpx;
+  height: 88rpx;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+}
+.submit-disabled {
+  opacity: 0.6;
+}
+.submit-label {
+  color: #fff;
+  font-size: 30rpx;
+  font-weight: 600;
+}
+</style>

+ 5 - 8
cfc-frontend/pages/health/report-upload.vue

@@ -409,15 +409,12 @@ if (options.type === 'a2' || options.reportKind === 'a2') {
         })
         })
       })
       })
     },
     },
-    // AI 快速识别入口:复用既有的「成员归属 + 数据使用声明」门禁后进入照片识别流程
+    // AI 快速识别入口:仅负责跳转到识别流程页;
+    // 检测人选择 + 数据使用声明勾选由 ai-detect 页内 startDetect 统一校验(§4.2 / §8)
     startAiDetect: function() {
     startAiDetect: function() {
-      var self = this
-      if (!this.ensureMember()) return
-      this.ensureAgreed(function() {
-        var url = '/pages/health/ai-detect'
-        if (self.memberId) url += '?memberId=' + self.memberId
-        uni.navigateTo({ url: url })
-      })
+      var url = '/pages/health/ai-detect'
+      if (this.memberId) url += '?memberId=' + this.memberId
+      uni.navigateTo({ url: url })
     },
     },
     uploadReport: function(filePath, fileName) {
     uploadReport: function(filePath, fileName) {
       if (!filePath) return
       if (!filePath) return