Browse Source

feat: 优化刷新用户信息

xiansin 2 years ago
parent
commit
bfcde2ea9c
1 changed files with 24 additions and 2 deletions
  1. 24 2
      mini/pages/my/index.vue

+ 24 - 2
mini/pages/my/index.vue

xqd xqd xqd xqd xqd
@@ -138,7 +138,8 @@ export default {
         title: '用户信息获取',
         nickname: '',
         avatar: ''
-      }
+      },
+      btnLock: false
     }
   },
   computed: {
@@ -205,6 +206,8 @@ export default {
       })
     },
     handleGetUserInfo(res) {
+      if (this.btnLock) return
+      this.btnLock = true
       // #ifdef  MP-KUAISHOU
       this.$loading('数据刷新中...')
       uni.authorize({
@@ -221,15 +224,24 @@ export default {
                   code: code
                 }
                 this.$api.user.update(params).then(res => {
+                  this.btnLock = false
                   this.code = null
                   this.$hideLoading()
                   this.$store.dispatch('user/info', res.data)
                 }).catch(() => {
+                  this.code = null
+                  this.btnLock = false
                   this.$hideLoading()
                 })
               })
+            },
+            fail: () => {
+              this.btnLock = false
             }
           })
+        },
+        fail: () => {
+          this.btnLock = false
         }
       })
       // #endif
@@ -245,19 +257,25 @@ export default {
             }
             this.$loading('数据刷新中...')
             this.$api.user.update(params).then(res => {
+              this.btnLock = false
               this.code = null
               this.$hideLoading()
               this.$store.dispatch('user/info', res.data)
             }).catch(() => {
+              this.code = null
+              this.btnLock = false
               this.$hideLoading()
             })
           })
+        },
+        fail: () => {
+          this.btnLock = false
         }
       })
       // #endif
     },
     getCode() {
-      return new Promise(resolve => {
+      return new Promise((resolve, reject) => {
         if (this.code) {
           return resolve(this.code)
         }
@@ -270,6 +288,10 @@ export default {
               this.code = null
             }, 1000 * 4 * 60)
             resolve(this.code)
+          },
+          fail: () => {
+            this.btnLock = false
+            reject()
           }
         })
       })