report-upload.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <template>
  2. <view class="upload-container">
  3. <!-- 说明提示 -->
  4. <view class="tip-banner">
  5. <text class="tip-icon">📋</text>
  6. <text class="tip-text">上传体检/菌群/DAN测评等报告,后台自动识别类型并解析</text>
  7. </view>
  8. <!-- 上传方式 -->
  9. <view class="form-section">
  10. <view class="upload-methods">
  11. <view class="upload-card card-chat" @click="pickFromChat">
  12. <view class="upload-card-icon">💬</view>
  13. <text class="upload-card-title">从聊天选取</text>
  14. <text class="upload-card-desc">微信聊天中的 PDF/图片</text>
  15. </view>
  16. <view class="upload-card card-photo" @click="takePhoto">
  17. <view class="upload-card-icon">📷</view>
  18. <text class="upload-card-title">拍照上传</text>
  19. <text class="upload-card-desc">拍摄纸质报告或舌象</text>
  20. </view>
  21. </view>
  22. <!-- 采集中面板 -->
  23. <view class="collecting-panel" v-if="collecting">
  24. <view class="collecting-card">
  25. <view class="collecting-icon">
  26. <view class="spinner" v-if="!collectError"></view>
  27. <text class="collecting-fail-mark" v-else>!</text>
  28. </view>
  29. <view class="collecting-info">
  30. <text class="collecting-title">{{ collectError ? '采集失败' : '数据采集中' }}</text>
  31. <text class="collecting-file">{{ collectFileName || '报告文件' }}</text>
  32. <text class="collecting-hint">{{ collectError || '后台正在识别报告类型并解析,完成后自动入库' }}</text>
  33. </view>
  34. </view>
  35. <view class="collecting-actions">
  36. <view class="collecting-btn" @click="goReportList">去报告列表查看</view>
  37. <view class="collecting-cancel" @click="cancelCollect">取消</view>
  38. </view>
  39. </view>
  40. <!-- 上传中 -->
  41. <view class="form-item" v-if="uploading">
  42. <text class="form-label">上传中...</text>
  43. <view class="analyzing-status">
  44. <text class="analyzing-text">{{ uploadingText }}</text>
  45. </view>
  46. </view>
  47. <!-- 责任声明 -->
  48. <view class="form-item disclaimer-box">
  49. <view class="disclaimer-check" @click="toggleAgree">
  50. <view class="disclaimer-checkbox" :class="{ 'disclaimer-checked': agreedToTerms }">
  51. <text class="disclaimer-checkmark" v-if="agreedToTerms">✓</text>
  52. </view>
  53. <text class="disclaimer-label">我已阅读并同意以下声明</text>
  54. </view>
  55. <view class="disclaimer-content">
  56. <text class="disclaimer-text">我同意平台使用本报告数据进行分析,为我提供个性化健康解决方案;未经我授权,平台不会以任何形式将我的报告内容提供给其他任何个人或机构。</text>
  57. </view>
  58. </view>
  59. </view>
  60. <!-- 上传说明 -->
  61. <view class="guide-section">
  62. <view class="guide-header">
  63. <text class="guide-header-icon">📖</text>
  64. <text class="guide-header-title">支持的报告类型</text>
  65. </view>
  66. <view class="guide-list">
  67. <view class="guide-item">
  68. <view class="guide-icon-box guide-icon-blue"><text class="guide-icon">📄</text></view>
  69. <view class="guide-info">
  70. <text class="guide-name">体检报告</text>
  71. <text class="guide-desc">血常规、尿常规、生化检验等,支持 PDF 或清晰照片</text>
  72. </view>
  73. </view>
  74. <view class="guide-item">
  75. <view class="guide-icon-box guide-icon-green"><text class="guide-icon">🦠</text></view>
  76. <view class="guide-info">
  77. <text class="guide-name">肠道菌群检测报告</text>
  78. <text class="guide-desc">支持 PDF 或清晰照片,AI 自动解读菌群健康</text>
  79. </view>
  80. </view>
  81. <view class="guide-item">
  82. <view class="guide-icon-box guide-icon-purple"><text class="guide-icon">🧠</text></view>
  83. <view class="guide-info">
  84. <text class="guide-name">DAN 测评报告</text>
  85. <text class="guide-desc">A2/B4 等成长测评 PDF,自动解析维度数据</text>
  86. </view>
  87. </view>
  88. <view class="guide-item">
  89. <view class="guide-icon-box guide-icon-orange"><text class="guide-icon">👅</text></view>
  90. <view class="guide-info">
  91. <text class="guide-name">舌象照片</text>
  92. <text class="guide-desc">拍摄舌象照片,AI 辅助舌诊分析</text>
  93. </view>
  94. </view>
  95. <view class="guide-item">
  96. <view class="guide-icon-box guide-icon-teal"><text class="guide-icon">⚖️</text></view>
  97. <view class="guide-info">
  98. <text class="guide-name">体脂秤报告</text>
  99. <text class="guide-desc">拍摄体脂秤显示屏,自动提取体重、BMI、体脂率等</text>
  100. </view>
  101. </view>
  102. </view>
  103. <view class="guide-tips">
  104. <text class="guide-tips-title">温馨提示</text>
  105. <text class="guide-tips-item">· 上传后系统自动识别报告类型,无需手动选择</text>
  106. <text class="guide-tips-item">· 请确保报告清晰完整,以便准确解析</text>
  107. <text class="guide-tips-item">· 确认入库后将自动生成成长方案,可再分解为每日任务</text>
  108. </view>
  109. </view>
  110. </view>
  111. </template>
  112. <script>
  113. import { uploadReportOnly, getReportCollectStatus } from '../../utils/api.js'
  114. export default {
  115. data() {
  116. return {
  117. memberId: null,
  118. uploading: false,
  119. agreedToTerms: false,
  120. uploadingText: '正在上传文件...',
  121. collectDraftId: null,
  122. collectTimer: null,
  123. collecting: false,
  124. collectFileName: '',
  125. collectError: '',
  126. collectPollCount: 0
  127. }
  128. },
  129. onLoad: function(options) {
  130. this.memberId = options.memberId ? parseInt(options.memberId) : null
  131. },
  132. onUnload: function() {
  133. this.stopCollectPolling()
  134. },
  135. methods: {
  136. toggleAgree: function() {
  137. this.agreedToTerms = !this.agreedToTerms
  138. },
  139. ensureAgreed: function(callback) {
  140. if (this.agreedToTerms) {
  141. callback()
  142. return
  143. }
  144. var self = this
  145. uni.showModal({
  146. title: '数据使用声明',
  147. content: '上传报告即代表您同意平台使用本报告数据进行分析,为您提供个性化健康解决方案;未经您授权,平台不会以任何形式将您的报告内容提供给其他任何个人或机构。点击「同意继续」即表示您已阅读并同意。',
  148. confirmText: '同意继续',
  149. cancelText: '暂不',
  150. success: function(res) {
  151. if (res.confirm) {
  152. self.agreedToTerms = true
  153. callback()
  154. }
  155. }
  156. })
  157. },
  158. pickFromChat: function() {
  159. var self = this
  160. this.ensureAgreed(function() {
  161. // type='all' 的选择器默认停留在图片 tab,用户难以发现可切换选文件。
  162. // 改为先弹 actionSheet 让用户明确选择图片或文件,分别走对应 type。
  163. uni.showActionSheet({
  164. itemList: ['聊天中的文件(PDF等)', '聊天中的图片'],
  165. success: function(res) {
  166. if (res.tapIndex === 0) {
  167. self.chooseChatFile('file', '聊天文件')
  168. } else if (res.tapIndex === 1) {
  169. self.chooseChatFile('image', '聊天图片')
  170. }
  171. },
  172. fail: function() {
  173. // 用户取消,静默处理
  174. }
  175. })
  176. })
  177. },
  178. chooseChatFile: function(type, fallbackName) {
  179. var self = this
  180. uni.chooseMessageFile({
  181. count: 1,
  182. type: type,
  183. success: function(res) {
  184. var files = res.tempFiles
  185. if (files && files.length > 0) {
  186. self.uploadReport(files[0].path, files[0].name || fallbackName)
  187. }
  188. },
  189. fail: function() {
  190. // 用户取消或失败,静默处理
  191. }
  192. })
  193. },
  194. takePhoto: function() {
  195. var self = this
  196. this.ensureAgreed(function() {
  197. uni.chooseImage({
  198. count: 1,
  199. sourceType: ['camera', 'album'],
  200. success: function(res) {
  201. if (res.tempFilePaths && res.tempFilePaths.length > 0) {
  202. self.uploadReport(res.tempFilePaths[0], '照片')
  203. }
  204. }
  205. })
  206. })
  207. },
  208. uploadReport: function(filePath, fileName) {
  209. if (!filePath) return
  210. var self = this
  211. self.uploading = true
  212. self.uploadingText = '正在上传文件...'
  213. uni.showLoading({ title: '上传中...' })
  214. // 不传 type,让后端通过指纹自动判断报告类型
  215. uploadReportOnly(filePath).then(function(res) {
  216. uni.hideLoading()
  217. self.uploading = false
  218. var data = res.data || {}
  219. // 处理重复上传:duplicate=true
  220. if (data.duplicate) {
  221. if (data.collecting) {
  222. self.collectDraftId = data.draftId
  223. self.collecting = true
  224. self.collectError = data.message || '该报告正在解析中,请稍候'
  225. self.collectFileName = fileName || '报告文件'
  226. self.startCollectPolling(data.draftId)
  227. } else {
  228. // 已完成,跳转详情
  229. var reportId = data.reportId
  230. if (reportId) {
  231. self.goToDetail(reportId, 'gut_flora')
  232. }
  233. }
  234. uni.showToast({ title: data.message || '该报告已上传过', icon: 'none', duration: 3000 })
  235. return
  236. }
  237. var draftId = data.draftId
  238. if (!draftId) {
  239. uni.showToast({ title: (res && res.message) || '上传失败', icon: 'none' })
  240. return
  241. }
  242. self.collectDraftId = draftId
  243. self.collecting = true
  244. self.collectError = ''
  245. self.collectFileName = fileName || '报告文件'
  246. self.startCollectPolling(draftId)
  247. }).catch(function(err) {
  248. uni.hideLoading()
  249. self.uploading = false
  250. var msg = (err && err.message) || '上传失败,请重试'
  251. uni.showToast({ title: msg, icon: 'none' })
  252. })
  253. },
  254. stopCollectPolling: function() {
  255. if (this.collectTimer) {
  256. clearInterval(this.collectTimer)
  257. this.collectTimer = null
  258. }
  259. },
  260. startCollectPolling: function(draftId) {
  261. var self = this
  262. self.stopCollectPolling()
  263. self.collectPollCount = 0
  264. self.pollCollectStatus(draftId)
  265. self.collectTimer = setInterval(function() {
  266. self.pollCollectStatus(draftId)
  267. }, 4000)
  268. },
  269. pollCollectStatus: function(draftId) {
  270. var self = this
  271. self.collectPollCount = (self.collectPollCount || 0) + 1
  272. // 约 6 分钟仍未完成:停轮询,提示去列表看进度
  273. if (self.collectPollCount > 90) {
  274. self.stopCollectPolling()
  275. self.collectError = '解析耗时较长,可去报告列表查看进度,无需重复上传'
  276. return
  277. }
  278. getReportCollectStatus(draftId).then(function(res) {
  279. var data = res.data || {}
  280. var status = data.parseStatus
  281. if (status === 'completed') {
  282. self.stopCollectPolling()
  283. self.collecting = false
  284. uni.showToast({ title: '报告已采集完成', icon: 'success', duration: 2000 })
  285. var reportId = data.reportId
  286. var reportType = data.reportType || 'gut_flora'
  287. setTimeout(function() {
  288. if (reportId) {
  289. // 统一跳转到健康报告详情页(后端指纹识别后统一入库到 health_report 表)
  290. if (reportType === 'gut_flora') {
  291. uni.redirectTo({ url: '/pages/health/gut-flora-detail?reportId=' + reportId })
  292. } else {
  293. uni.redirectTo({ url: '/pages/health/report-detail?reportType=' + reportType + '&reportId=' + reportId })
  294. }
  295. } else {
  296. uni.redirectTo({ url: '/pages/health/report-list' })
  297. }
  298. }, 600)
  299. } else if (status === 'failed') {
  300. self.stopCollectPolling()
  301. self.collectError = data.parseError || '报告采集失败,请重试'
  302. uni.showToast({ title: self.collectError, icon: 'none', duration: 3000 })
  303. }
  304. }).catch(function() {
  305. // 轮询失败静默,下次继续
  306. })
  307. },
  308. goReportList: function() {
  309. this.stopCollectPolling()
  310. uni.redirectTo({ url: '/pages/health/report-list' })
  311. },
  312. goToDetail: function(reportId, reportType) {
  313. var url
  314. if (reportType === 'gut_flora') {
  315. url = '/pages/health/gut-flora-detail?reportId=' + reportId
  316. } else {
  317. url = '/pages/health/report-detail?reportType=' + (reportType || 'gut_flora') + '&reportId=' + reportId
  318. }
  319. uni.redirectTo({ url: url })
  320. },
  321. cancelCollect: function() {
  322. this.stopCollectPolling()
  323. this.collecting = false
  324. this.collectDraftId = null
  325. this.collectFileName = ''
  326. this.collectError = ''
  327. }
  328. }
  329. }
  330. </script>
  331. <style scoped>
  332. .upload-container {
  333. min-height: 100vh;
  334. background: #F5F7FA;
  335. padding-bottom: env(safe-area-inset-bottom);
  336. }
  337. .tip-banner {
  338. display: flex;
  339. flex-direction: row;
  340. align-items: center;
  341. background: #E3F2FD;
  342. margin: 20rpx 30rpx;
  343. padding: 20rpx 24rpx;
  344. border-radius: 16rpx;
  345. }
  346. .tip-icon {
  347. font-size: 32rpx;
  348. margin-right: 16rpx;
  349. flex-shrink: 0;
  350. }
  351. .tip-text {
  352. font-size: 24rpx;
  353. color: #1565C0;
  354. line-height: 1.5;
  355. }
  356. .form-section {
  357. margin: 0 30rpx;
  358. }
  359. .form-item {
  360. background: #fff;
  361. border-radius: 16rpx;
  362. padding: 24rpx;
  363. margin-bottom: 20rpx;
  364. }
  365. .form-label {
  366. font-size: 26rpx;
  367. font-weight: bold;
  368. color: #333;
  369. display: block;
  370. margin-bottom: 16rpx;
  371. }
  372. /* 上传方式卡片 */
  373. .upload-methods {
  374. display: flex;
  375. flex-direction: row;
  376. gap: 16rpx;
  377. margin-bottom: 20rpx;
  378. }
  379. .upload-card {
  380. flex: 1;
  381. display: flex;
  382. flex-direction: column;
  383. align-items: center;
  384. justify-content: center;
  385. padding: 32rpx 12rpx;
  386. border-radius: 20rpx;
  387. text-align: center;
  388. min-height: 200rpx;
  389. }
  390. .upload-card:active {
  391. opacity: 0.85;
  392. }
  393. .upload-card-icon {
  394. width: 80rpx;
  395. height: 80rpx;
  396. border-radius: 20rpx;
  397. font-size: 40rpx;
  398. display: flex;
  399. align-items: center;
  400. justify-content: center;
  401. margin-bottom: 16rpx;
  402. }
  403. .upload-card-title {
  404. font-size: 26rpx;
  405. font-weight: 600;
  406. color: #333;
  407. margin-bottom: 8rpx;
  408. }
  409. .upload-card-desc {
  410. font-size: 20rpx;
  411. color: #94A3B8;
  412. line-height: 1.5;
  413. }
  414. .card-chat {
  415. background: #F0F7FF;
  416. border: 2rpx dashed #93C5FD;
  417. }
  418. .card-chat .upload-card-icon {
  419. background: linear-gradient(135deg, #3B82F6, #1D4ED8);
  420. color: #fff;
  421. }
  422. .card-photo {
  423. background: #FFF7ED;
  424. border: 2rpx solid #FED7AA;
  425. }
  426. .card-photo .upload-card-icon {
  427. background: linear-gradient(135deg, #FB923C, #EA580C);
  428. color: #fff;
  429. }
  430. /* 采集中面板 */
  431. .collecting-panel {
  432. margin-bottom: 20rpx;
  433. }
  434. .collecting-card {
  435. display: flex;
  436. flex-direction: row;
  437. align-items: flex-start;
  438. background: #FFF8E6;
  439. border: 1rpx solid #F5D78E;
  440. border-radius: 16rpx;
  441. padding: 28rpx 24rpx;
  442. }
  443. .collecting-icon {
  444. width: 56rpx;
  445. height: 56rpx;
  446. border-radius: 50%;
  447. background: #F0B429;
  448. display: flex;
  449. align-items: center;
  450. justify-content: center;
  451. margin-right: 20rpx;
  452. flex-shrink: 0;
  453. }
  454. .spinner {
  455. width: 28rpx;
  456. height: 28rpx;
  457. border: 4rpx solid rgba(255,255,255,0.4);
  458. border-top-color: #fff;
  459. border-radius: 50%;
  460. animation: collecting-spin 1s linear infinite;
  461. }
  462. @keyframes collecting-spin {
  463. 0% { transform: rotate(0deg); }
  464. 100% { transform: rotate(360deg); }
  465. }
  466. .collecting-fail-mark {
  467. font-size: 32rpx;
  468. color: #fff;
  469. font-weight: bold;
  470. }
  471. .collecting-info {
  472. flex: 1;
  473. display: flex;
  474. flex-direction: column;
  475. min-width: 0;
  476. }
  477. .collecting-title {
  478. font-size: 30rpx;
  479. font-weight: 600;
  480. color: #7A5C00;
  481. }
  482. .collecting-file {
  483. font-size: 24rpx;
  484. color: #A08A45;
  485. margin-top: 6rpx;
  486. overflow: hidden;
  487. text-overflow: ellipsis;
  488. white-space: nowrap;
  489. }
  490. .collecting-hint {
  491. font-size: 22rpx;
  492. color: #C0A75A;
  493. margin-top: 8rpx;
  494. line-height: 1.5;
  495. }
  496. .collecting-actions {
  497. display: flex;
  498. flex-direction: row;
  499. gap: 16rpx;
  500. margin-top: 16rpx;
  501. }
  502. .collecting-btn {
  503. flex: 1;
  504. height: 72rpx;
  505. line-height: 72rpx;
  506. text-align: center;
  507. background: #5B9BD5;
  508. color: #fff;
  509. font-size: 28rpx;
  510. border-radius: 12rpx;
  511. }
  512. .collecting-cancel {
  513. padding: 0 24rpx;
  514. height: 72rpx;
  515. line-height: 72rpx;
  516. text-align: center;
  517. background: #fff;
  518. border: 1rpx solid #D1D5DB;
  519. color: #666;
  520. font-size: 28rpx;
  521. border-radius: 12rpx;
  522. }
  523. /* 上传中状态 */
  524. .analyzing-status {
  525. display: flex;
  526. flex-direction: row;
  527. align-items: center;
  528. }
  529. .analyzing-text {
  530. font-size: 26rpx;
  531. color: #5B9BD5;
  532. }
  533. /* 责任声明 */
  534. .disclaimer-box {
  535. background: #FFF8F0;
  536. border: 2rpx solid #FDE68A;
  537. }
  538. .disclaimer-check {
  539. display: flex;
  540. flex-direction: row;
  541. align-items: center;
  542. margin-bottom: 12rpx;
  543. }
  544. .disclaimer-checkbox {
  545. width: 36rpx;
  546. height: 36rpx;
  547. border-radius: 6rpx;
  548. border: 2rpx solid #CBD5E1;
  549. background: #fff;
  550. display: flex;
  551. align-items: center;
  552. justify-content: center;
  553. flex-shrink: 0;
  554. margin-right: 12rpx;
  555. }
  556. .disclaimer-checked {
  557. background: #5B9BD5;
  558. border-color: #5B9BD5;
  559. }
  560. .disclaimer-checkmark {
  561. font-size: 24rpx;
  562. color: #fff;
  563. font-weight: bold;
  564. }
  565. .disclaimer-label {
  566. font-size: 24rpx;
  567. color: #333;
  568. font-weight: 500;
  569. }
  570. .disclaimer-content {
  571. background: #FFFDF5;
  572. border-radius: 10rpx;
  573. padding: 16rpx;
  574. margin-left: 48rpx;
  575. }
  576. .disclaimer-text {
  577. font-size: 22rpx;
  578. color: #92400E;
  579. line-height: 1.6;
  580. }
  581. /* 上传说明 */
  582. .guide-section {
  583. margin: 0 30rpx 30rpx;
  584. background: #fff;
  585. border-radius: 20rpx;
  586. padding: 28rpx 24rpx;
  587. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  588. }
  589. .guide-header {
  590. display: flex;
  591. flex-direction: row;
  592. align-items: center;
  593. margin-bottom: 20rpx;
  594. }
  595. .guide-header-icon {
  596. font-size: 32rpx;
  597. margin-right: 12rpx;
  598. }
  599. .guide-header-title {
  600. font-size: 28rpx;
  601. font-weight: 600;
  602. color: #1E293B;
  603. }
  604. .guide-item {
  605. display: flex;
  606. flex-direction: row;
  607. align-items: flex-start;
  608. margin-bottom: 20rpx;
  609. }
  610. .guide-icon-box {
  611. width: 64rpx;
  612. height: 64rpx;
  613. border-radius: 16rpx;
  614. display: flex;
  615. align-items: center;
  616. justify-content: center;
  617. margin-right: 16rpx;
  618. flex-shrink: 0;
  619. }
  620. .guide-icon {
  621. font-size: 32rpx;
  622. }
  623. .guide-icon-blue { background: #DBEAFE; }
  624. .guide-icon-green { background: #DCFCE7; }
  625. .guide-icon-orange { background: #FFEDD5; }
  626. .guide-icon-purple { background: #EDE9FE; }
  627. .guide-icon-teal { background: #CCFBF1; }
  628. .guide-info {
  629. flex: 1;
  630. }
  631. .guide-name {
  632. font-size: 26rpx;
  633. font-weight: 600;
  634. color: #334155;
  635. display: block;
  636. margin-bottom: 4rpx;
  637. }
  638. .guide-desc {
  639. font-size: 22rpx;
  640. color: #94A3B8;
  641. line-height: 1.5;
  642. }
  643. .guide-tips {
  644. margin-top: 8rpx;
  645. padding-top: 16rpx;
  646. border-top: 1rpx solid #F1F5F9;
  647. }
  648. .guide-tips-title {
  649. font-size: 24rpx;
  650. font-weight: 600;
  651. color: #64748B;
  652. display: block;
  653. margin-bottom: 8rpx;
  654. }
  655. .guide-tips-item {
  656. font-size: 22rpx;
  657. color: #94A3B8;
  658. display: block;
  659. line-height: 1.7;
  660. }
  661. </style>