Explorar o código

fix(upload): 责任声明勾选改方法调用+箭头函数消除this丢失隐患

- @click 内联赋值表达式 agreedToTerms=!agreedToTerms 改为 toggleAgree() 方法调用
- ensureAgreed/startPick/uploadAndGoConfirm 内 var self=this 全部改为箭头函数
- 修复某些情况下点击上传按钮无反应的问题
liaoxg hai 1 mes
pai
achega
1e7a7cee06
Modificáronse 1 ficheiros con 21 adicións e 21 borrados
  1. 21 21
      cfc-frontend/pages/health/report-upload.vue

+ 21 - 21
cfc-frontend/pages/health/report-upload.vue

@@ -31,7 +31,7 @@
 
       <!-- 责任声明 -->
       <view class="form-item disclaimer-box">
-        <view class="disclaimer-check" @click="agreedToTerms = !agreedToTerms">
+        <view class="disclaimer-check" @click="toggleAgree">
           <view class="disclaimer-checkbox" :class="{ 'disclaimer-checked': agreedToTerms }">
             <text class="disclaimer-checkmark" v-if="agreedToTerms">✓</text>
           </view>
@@ -128,35 +128,37 @@ export default {
     this.memberId = options.memberId ? parseInt(options.memberId) : null
   },
   methods: {
+    // 切换同意声明
+    toggleAgree() {
+      this.agreedToTerms = !this.agreedToTerms
+    },
     // 未勾选声明时弹窗确认
     ensureAgreed(isPhoto) {
       if (this.agreedToTerms) {
         this.startPick(isPhoto)
         return
       }
-      var self = this
       uni.showModal({
         title: '数据使用声明',
-        content: '上传报告即代表您同意平台使用报告数据进行分析并提供个性化健康解决方案;平台承诺未经您授权,不会以任何形式将您的报告提供给其他任何个人或机构。点击「同意并继续」即表示您已阅读并同意。',
+        content: '上传报告即代表您同意平台使用本报告数据进行分析,为您提供个性化健康解决方案;未经您授权,平台不会以任何形式将您的报告内容提供给其他任何个人或机构。点击「同意并继续」即表示您已阅读并同意。',
         confirmText: '同意并继续',
         cancelText: '暂不',
-        success: function(res) {
+        success: (res) => {
           if (res.confirm) {
-            self.agreedToTerms = true
-            self.startPick(isPhoto)
+            this.agreedToTerms = true
+            this.startPick(isPhoto)
           }
         }
       })
     },
     startPick(isPhoto) {
-      var self = this
       if (isPhoto) {
         uni.chooseImage({
           count: 1,
           sourceType: ['camera', 'album'],
-          success: function(res) {
-            self.photoPath = res.tempFilePaths[0]
-            self.uploadAndGoConfirm(self.photoPath, 'image')
+          success: (res) => {
+            this.photoPath = res.tempFilePaths[0]
+            this.uploadAndGoConfirm(this.photoPath, 'image')
           }
         })
       } else {
@@ -164,14 +166,14 @@ export default {
           count: 1,
           type: 'file',
           extension: ['pdf'],
-          success: function(res) {
+          success: (res) => {
             var files = res.tempFiles
             if (files && files.length > 0) {
-              self.selectedFile = files[0]
-              self.uploadAndGoConfirm(files[0].path, '')
+              this.selectedFile = files[0]
+              this.uploadAndGoConfirm(files[0].path, '')
             }
           },
-          fail: function(e) {
+          fail: (e) => {
             console.log('选择文件取消或失败', e)
           }
         })
@@ -187,23 +189,21 @@ export default {
     },
     // 上传文件 → 自动跳转确认页(确认页按 draftId 触发解析并自动刷新显示结果)
     uploadAndGoConfirm(filePath, type) {
-      var self = this
       if (!filePath) return
-      self.uploading = true
+      this.uploading = true
       uni.showLoading({ title: '上传中...' })
-      uploadReportOnly(filePath, type).then(function(res) {
+      uploadReportOnly(filePath, type).then((res) => {
         uni.hideLoading()
-        self.uploading = false
+        this.uploading = false
         var draftId = res.data && res.data.draftId
         if (!draftId) {
           uni.showToast({ title: (res && res.message) || '上传失败', icon: 'none' })
           return
         }
-        // 只传 draftId,确认页自行解析
         uni.redirectTo({ url: '/pages/health/report-detail?draftId=' + draftId })
-      }).catch(function(err) {
+      }).catch((err) => {
         uni.hideLoading()
-        self.uploading = false
+        this.uploading = false
         var msg = (err && err.message) || '上传失败,请重试'
         uni.showToast({ title: msg, icon: 'none' })
       })