report-upload.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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. uni.chooseMessageFile({
  162. count: 1,
  163. type: 'all',
  164. success: function(res) {
  165. var files = res.tempFiles
  166. if (files && files.length > 0) {
  167. self.uploadReport(files[0].path, files[0].name || '聊天文件')
  168. }
  169. },
  170. fail: function() {
  171. // 用户取消或失败,静默处理
  172. }
  173. })
  174. })
  175. },
  176. takePhoto: function() {
  177. var self = this
  178. this.ensureAgreed(function() {
  179. uni.chooseImage({
  180. count: 1,
  181. sourceType: ['camera', 'album'],
  182. success: function(res) {
  183. if (res.tempFilePaths && res.tempFilePaths.length > 0) {
  184. self.uploadReport(res.tempFilePaths[0], '照片')
  185. }
  186. }
  187. })
  188. })
  189. },
  190. uploadReport: function(filePath, fileName) {
  191. if (!filePath) return
  192. var self = this
  193. self.uploading = true
  194. self.uploadingText = '正在上传文件...'
  195. uni.showLoading({ title: '上传中...' })
  196. // 不传 type,让后端通过指纹自动判断报告类型
  197. uploadReportOnly(filePath).then(function(res) {
  198. uni.hideLoading()
  199. self.uploading = false
  200. var draftId = res.data && res.data.draftId
  201. if (!draftId) {
  202. uni.showToast({ title: (res && res.message) || '上传失败', icon: 'none' })
  203. return
  204. }
  205. self.collectDraftId = draftId
  206. self.collecting = true
  207. self.collectError = ''
  208. self.collectFileName = fileName || '报告文件'
  209. self.startCollectPolling(draftId)
  210. }).catch(function(err) {
  211. uni.hideLoading()
  212. self.uploading = false
  213. var msg = (err && err.message) || '上传失败,请重试'
  214. uni.showToast({ title: msg, icon: 'none' })
  215. })
  216. },
  217. stopCollectPolling: function() {
  218. if (this.collectTimer) {
  219. clearInterval(this.collectTimer)
  220. this.collectTimer = null
  221. }
  222. },
  223. startCollectPolling: function(draftId) {
  224. var self = this
  225. self.stopCollectPolling()
  226. self.collectPollCount = 0
  227. self.pollCollectStatus(draftId)
  228. self.collectTimer = setInterval(function() {
  229. self.pollCollectStatus(draftId)
  230. }, 4000)
  231. },
  232. pollCollectStatus: function(draftId) {
  233. var self = this
  234. self.collectPollCount = (self.collectPollCount || 0) + 1
  235. // 约 6 分钟仍未完成:停轮询,提示去列表看进度
  236. if (self.collectPollCount > 90) {
  237. self.stopCollectPolling()
  238. self.collectError = '解析耗时较长,可去报告列表查看进度,无需重复上传'
  239. return
  240. }
  241. getReportCollectStatus(draftId).then(function(res) {
  242. var data = res.data || {}
  243. var status = data.parseStatus
  244. if (status === 'completed') {
  245. self.stopCollectPolling()
  246. self.collecting = false
  247. uni.showToast({ title: '报告已采集完成', icon: 'success', duration: 2000 })
  248. var reportId = data.reportId
  249. var reportType = data.reportType || 'gut_flora'
  250. setTimeout(function() {
  251. if (reportId) {
  252. // 统一跳转到健康报告详情页(后端指纹识别后统一入库到 health_report 表)
  253. if (reportType === 'gut_flora') {
  254. uni.redirectTo({ url: '/pages/health/gut-flora-detail?reportId=' + reportId })
  255. } else {
  256. uni.redirectTo({ url: '/pages/health/report-detail?reportType=' + reportType + '&reportId=' + reportId })
  257. }
  258. } else {
  259. uni.redirectTo({ url: '/pages/health/report-list' })
  260. }
  261. }, 600)
  262. } else if (status === 'failed') {
  263. self.stopCollectPolling()
  264. self.collectError = data.parseError || '报告采集失败,请重试'
  265. uni.showToast({ title: self.collectError, icon: 'none', duration: 3000 })
  266. }
  267. }).catch(function() {
  268. // 轮询失败静默,下次继续
  269. })
  270. },
  271. goReportList: function() {
  272. this.stopCollectPolling()
  273. uni.redirectTo({ url: '/pages/health/report-list' })
  274. },
  275. cancelCollect: function() {
  276. this.stopCollectPolling()
  277. this.collecting = false
  278. this.collectDraftId = null
  279. this.collectFileName = ''
  280. this.collectError = ''
  281. }
  282. }
  283. }
  284. </script>
  285. <style scoped>
  286. .upload-container {
  287. min-height: 100vh;
  288. background: #F5F7FA;
  289. padding-bottom: env(safe-area-inset-bottom);
  290. }
  291. .tip-banner {
  292. display: flex;
  293. flex-direction: row;
  294. align-items: center;
  295. background: #E3F2FD;
  296. margin: 20rpx 30rpx;
  297. padding: 20rpx 24rpx;
  298. border-radius: 16rpx;
  299. }
  300. .tip-icon {
  301. font-size: 32rpx;
  302. margin-right: 16rpx;
  303. flex-shrink: 0;
  304. }
  305. .tip-text {
  306. font-size: 24rpx;
  307. color: #1565C0;
  308. line-height: 1.5;
  309. }
  310. .form-section {
  311. margin: 0 30rpx;
  312. }
  313. .form-item {
  314. background: #fff;
  315. border-radius: 16rpx;
  316. padding: 24rpx;
  317. margin-bottom: 20rpx;
  318. }
  319. .form-label {
  320. font-size: 26rpx;
  321. font-weight: bold;
  322. color: #333;
  323. display: block;
  324. margin-bottom: 16rpx;
  325. }
  326. /* 上传方式卡片 */
  327. .upload-methods {
  328. display: flex;
  329. flex-direction: row;
  330. gap: 16rpx;
  331. margin-bottom: 20rpx;
  332. }
  333. .upload-card {
  334. flex: 1;
  335. display: flex;
  336. flex-direction: column;
  337. align-items: center;
  338. justify-content: center;
  339. padding: 32rpx 12rpx;
  340. border-radius: 20rpx;
  341. text-align: center;
  342. min-height: 200rpx;
  343. }
  344. .upload-card:active {
  345. opacity: 0.85;
  346. }
  347. .upload-card-icon {
  348. width: 80rpx;
  349. height: 80rpx;
  350. border-radius: 20rpx;
  351. font-size: 40rpx;
  352. display: flex;
  353. align-items: center;
  354. justify-content: center;
  355. margin-bottom: 16rpx;
  356. }
  357. .upload-card-title {
  358. font-size: 26rpx;
  359. font-weight: 600;
  360. color: #333;
  361. margin-bottom: 8rpx;
  362. }
  363. .upload-card-desc {
  364. font-size: 20rpx;
  365. color: #94A3B8;
  366. line-height: 1.5;
  367. }
  368. .card-chat {
  369. background: #F0F7FF;
  370. border: 2rpx dashed #93C5FD;
  371. }
  372. .card-chat .upload-card-icon {
  373. background: linear-gradient(135deg, #3B82F6, #1D4ED8);
  374. color: #fff;
  375. }
  376. .card-photo {
  377. background: #FFF7ED;
  378. border: 2rpx solid #FED7AA;
  379. }
  380. .card-photo .upload-card-icon {
  381. background: linear-gradient(135deg, #FB923C, #EA580C);
  382. color: #fff;
  383. }
  384. /* 采集中面板 */
  385. .collecting-panel {
  386. margin-bottom: 20rpx;
  387. }
  388. .collecting-card {
  389. display: flex;
  390. flex-direction: row;
  391. align-items: flex-start;
  392. background: #FFF8E6;
  393. border: 1rpx solid #F5D78E;
  394. border-radius: 16rpx;
  395. padding: 28rpx 24rpx;
  396. }
  397. .collecting-icon {
  398. width: 56rpx;
  399. height: 56rpx;
  400. border-radius: 50%;
  401. background: #F0B429;
  402. display: flex;
  403. align-items: center;
  404. justify-content: center;
  405. margin-right: 20rpx;
  406. flex-shrink: 0;
  407. }
  408. .spinner {
  409. width: 28rpx;
  410. height: 28rpx;
  411. border: 4rpx solid rgba(255,255,255,0.4);
  412. border-top-color: #fff;
  413. border-radius: 50%;
  414. animation: collecting-spin 1s linear infinite;
  415. }
  416. @keyframes collecting-spin {
  417. 0% { transform: rotate(0deg); }
  418. 100% { transform: rotate(360deg); }
  419. }
  420. .collecting-fail-mark {
  421. font-size: 32rpx;
  422. color: #fff;
  423. font-weight: bold;
  424. }
  425. .collecting-info {
  426. flex: 1;
  427. display: flex;
  428. flex-direction: column;
  429. min-width: 0;
  430. }
  431. .collecting-title {
  432. font-size: 30rpx;
  433. font-weight: 600;
  434. color: #7A5C00;
  435. }
  436. .collecting-file {
  437. font-size: 24rpx;
  438. color: #A08A45;
  439. margin-top: 6rpx;
  440. overflow: hidden;
  441. text-overflow: ellipsis;
  442. white-space: nowrap;
  443. }
  444. .collecting-hint {
  445. font-size: 22rpx;
  446. color: #C0A75A;
  447. margin-top: 8rpx;
  448. line-height: 1.5;
  449. }
  450. .collecting-actions {
  451. display: flex;
  452. flex-direction: row;
  453. gap: 16rpx;
  454. margin-top: 16rpx;
  455. }
  456. .collecting-btn {
  457. flex: 1;
  458. height: 72rpx;
  459. line-height: 72rpx;
  460. text-align: center;
  461. background: #5B9BD5;
  462. color: #fff;
  463. font-size: 28rpx;
  464. border-radius: 12rpx;
  465. }
  466. .collecting-cancel {
  467. padding: 0 24rpx;
  468. height: 72rpx;
  469. line-height: 72rpx;
  470. text-align: center;
  471. background: #fff;
  472. border: 1rpx solid #D1D5DB;
  473. color: #666;
  474. font-size: 28rpx;
  475. border-radius: 12rpx;
  476. }
  477. /* 上传中状态 */
  478. .analyzing-status {
  479. display: flex;
  480. flex-direction: row;
  481. align-items: center;
  482. }
  483. .analyzing-text {
  484. font-size: 26rpx;
  485. color: #5B9BD5;
  486. }
  487. /* 责任声明 */
  488. .disclaimer-box {
  489. background: #FFF8F0;
  490. border: 2rpx solid #FDE68A;
  491. }
  492. .disclaimer-check {
  493. display: flex;
  494. flex-direction: row;
  495. align-items: center;
  496. margin-bottom: 12rpx;
  497. }
  498. .disclaimer-checkbox {
  499. width: 36rpx;
  500. height: 36rpx;
  501. border-radius: 6rpx;
  502. border: 2rpx solid #CBD5E1;
  503. background: #fff;
  504. display: flex;
  505. align-items: center;
  506. justify-content: center;
  507. flex-shrink: 0;
  508. margin-right: 12rpx;
  509. }
  510. .disclaimer-checked {
  511. background: #5B9BD5;
  512. border-color: #5B9BD5;
  513. }
  514. .disclaimer-checkmark {
  515. font-size: 24rpx;
  516. color: #fff;
  517. font-weight: bold;
  518. }
  519. .disclaimer-label {
  520. font-size: 24rpx;
  521. color: #333;
  522. font-weight: 500;
  523. }
  524. .disclaimer-content {
  525. background: #FFFDF5;
  526. border-radius: 10rpx;
  527. padding: 16rpx;
  528. margin-left: 48rpx;
  529. }
  530. .disclaimer-text {
  531. font-size: 22rpx;
  532. color: #92400E;
  533. line-height: 1.6;
  534. }
  535. /* 上传说明 */
  536. .guide-section {
  537. margin: 0 30rpx 30rpx;
  538. background: #fff;
  539. border-radius: 20rpx;
  540. padding: 28rpx 24rpx;
  541. box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.04);
  542. }
  543. .guide-header {
  544. display: flex;
  545. flex-direction: row;
  546. align-items: center;
  547. margin-bottom: 20rpx;
  548. }
  549. .guide-header-icon {
  550. font-size: 32rpx;
  551. margin-right: 12rpx;
  552. }
  553. .guide-header-title {
  554. font-size: 28rpx;
  555. font-weight: 600;
  556. color: #1E293B;
  557. }
  558. .guide-item {
  559. display: flex;
  560. flex-direction: row;
  561. align-items: flex-start;
  562. margin-bottom: 20rpx;
  563. }
  564. .guide-icon-box {
  565. width: 64rpx;
  566. height: 64rpx;
  567. border-radius: 16rpx;
  568. display: flex;
  569. align-items: center;
  570. justify-content: center;
  571. margin-right: 16rpx;
  572. flex-shrink: 0;
  573. }
  574. .guide-icon {
  575. font-size: 32rpx;
  576. }
  577. .guide-icon-blue { background: #DBEAFE; }
  578. .guide-icon-green { background: #DCFCE7; }
  579. .guide-icon-orange { background: #FFEDD5; }
  580. .guide-icon-purple { background: #EDE9FE; }
  581. .guide-icon-teal { background: #CCFBF1; }
  582. .guide-info {
  583. flex: 1;
  584. }
  585. .guide-name {
  586. font-size: 26rpx;
  587. font-weight: 600;
  588. color: #334155;
  589. display: block;
  590. margin-bottom: 4rpx;
  591. }
  592. .guide-desc {
  593. font-size: 22rpx;
  594. color: #94A3B8;
  595. line-height: 1.5;
  596. }
  597. .guide-tips {
  598. margin-top: 8rpx;
  599. padding-top: 16rpx;
  600. border-top: 1rpx solid #F1F5F9;
  601. }
  602. .guide-tips-title {
  603. font-size: 24rpx;
  604. font-weight: 600;
  605. color: #64748B;
  606. display: block;
  607. margin-bottom: 8rpx;
  608. }
  609. .guide-tips-item {
  610. font-size: 22rpx;
  611. color: #94A3B8;
  612. display: block;
  613. line-height: 1.7;
  614. }
  615. </style>