report-upload.vue 18 KB

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