Просмотр исходного кода

修复完善信息 提交按钮 禁用问题

cc12458 7 месяцев назад
Родитель
Сommit
29503ac15c

+ 3 - 1
miniprogram/components/button/button.json

@@ -1,4 +1,6 @@
 {
   "component": true,
-  "usingComponents": {}
+  "usingComponents": {
+    "t-loading": "tdesign-miniprogram/loading/loading"
+  }
 }

+ 2 - 0
miniprogram/components/button/button.scss

@@ -31,6 +31,8 @@
       color: white;
       border-radius: 5px;
       left: 10px;
+
+      --td-loading-color: #fff;
     }
   }
 

+ 1 - 1
miniprogram/components/button/button.ts

@@ -4,7 +4,7 @@ Component({
   observers: {
     loading(this: any, val: boolean) {
       // 当外部声明 loading 时,同步禁用状态
-      this.setData({ isDisabled: !!val });
+      if (this.data.disableOnClick) this.setData({ isDisabled: !!val });
     },
   },
   lifetimes: {

+ 2 - 1
miniprogram/components/button/button.wxml

@@ -11,6 +11,7 @@
     disabled="{{isDisabled}}"
     hover-class="{{isDisabled ? '' : 'hover'}}"
   >
-    {{list[index].name}}
+    <t-loading wx:if="{{loading}}" theme="spinner" size="36rpx" slot="note" />
+    <block wx:else>{{list[index].name}}</block>
   </button>
 </view>

+ 3 - 1
miniprogram/lib/use/use-phone.ts

@@ -26,7 +26,7 @@ export function usePhoneNumber() {
       _updateStatus.push(callback);
       callback(status)
     },
-    getPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber) {
+    getPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber, callback?: (value?: string) => void) {
       const code = event.detail.code;
       if (!code) return;
       _updateStatus.forEach(cb => cb('loading'))
@@ -38,10 +38,12 @@ export function usePhoneNumber() {
       }).then(phone => {
         value = phone;
         status = 'success';
+        if (typeof callback === 'function') callback(value)
 
         _updataValue.forEach(cb => cb(value))
         _updateStatus.forEach(cb => cb(status))
       }, (error) => {
+        if (typeof callback === 'function') callback()
         _updateStatus.forEach(cb => cb('pending'))
         wx.showModal({ title: '获取失败', content: error.errMsg || error.message, showCancel: false })
       })

+ 11 - 8
miniprogram/module/user/pages/user-certification/user-certification.ts

@@ -80,11 +80,7 @@ Component({
       else this.setData({ "privacyContract.agree": agree });
     },
     onAgree() {
-      const submitBtn = this.selectComponent("#submitBtn");
-      console.log("onAgree-->");
-
       this.setData({ "privacyContract.agree": true });
-      if (submitBtn) submitBtn.resetState();
     },
     async verifyCardno(event: WechatMiniprogram.InputConfirm) {
       const value = event.detail.value;
@@ -104,19 +100,18 @@ Component({
     },
     async onSubmit(event: WechatMiniprogram.FormSubmit) {
       if (this.data.submitting) return;
-      this.setData({ submitting: true });
+      this.resetSubmitState(true);
       const data = { ...this.data.model, ...event.detail.value };
       data.phone = this.data.model.phone;
-      const submitBtn = this.selectComponent("#submitBtn");
       if (!data.phone) {
-        if (submitBtn) submitBtn.resetState();
+        this.resetSubmitState(false);
         return getTickleContext.call(this).showWarnMessage("请获取手机号码");
       }
       if (!data.agemust) {
         data.agemust = this.data.privacyContract.agree ? "Y" : "N";
       }
       if (data.agemust === "N") {
-        if (submitBtn) submitBtn.resetState();
+        this.resetSubmitState(false);
         this.setData({ "privacyContract.show": true });
         return wx.showToast({
           title: `请阅读并同意${this.data.privacyContract.name}`,
@@ -146,5 +141,13 @@ Component({
         wx.hideLoading();
       }
     },
+    resetSubmitState(loading: boolean) {
+      if (loading) this.setData({ submitting: true });
+      else {
+        this.setData({ submitting: false });
+        const submitBtn = this.selectComponent("#submitBtn");
+        if (submitBtn) submitBtn.resetState();
+      }
+    }
   },
 });

+ 1 - 1
miniprogram/module/user/pages/user-certification/user-certification.wxml

@@ -1,6 +1,6 @@
 <wxs src="../../../../core/wxs/dictionary.wxs" module="dictionary" />
 <!--module/user/pages/user-certification/user-certification.wxml-->
-<t-navbar title="完善信息" left-arrow />
+<t-navbar title="完善信息" left-arrow="{{!hide}}" />
 <scroll-view class="page-scroll__container" type="list" scroll-y style="{{containerStyle}}">
   <form bindsubmit="onSubmit">
     <view class="open-button">