فهرست منبع

微信登录受线上开关控制

chendeben 1 سال پیش
والد
کامیت
6c0de54d40
2فایلهای تغییر یافته به همراه110 افزوده شده و 4 حذف شده
  1. 1 0
      entry/src/main/ets/common/util/UserUtil.ets
  2. 109 4
      entry/src/main/ets/pages/UserCenter.ets

+ 1 - 0
entry/src/main/ets/common/util/UserUtil.ets

@@ -113,6 +113,7 @@ export interface VipPlanApi {
 
 export interface VipPlanListApiData {
   plans: VipPlanApi[];
+  show_wx_login?: boolean;
 }
 
 export interface VipPlanListApiResponse {

+ 109 - 4
entry/src/main/ets/pages/UserCenter.ets

@@ -184,6 +184,7 @@ export struct UserCenter {
   @StorageProp('topRectHeight') topRectHeight: number = px2vp(AppUtil.getStatusBarHeight());
   @StorageProp('currentColorMode') @Watch('onColorModeChange') currentMode: number =
     ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
+  @State showWxLogin: boolean = false;
   private wxApi = WXApi
   private wxEventHandler = WXEventHandler
 
@@ -263,8 +264,11 @@ export struct UserCenter {
     let params = router.getParams() as Record<string, Object>;
     let fromSyncNoble = params && params['fromSyncNoble'] === true;
     if (fromSyncNoble) {
-      // 自动弹出登录框
-      this.huaweiQuickLogin();
+      if (this.showWxLogin) {
+        this.showLoginDialog();
+      } else {
+        this.huaweiQuickLogin();
+      }
     } else if (!this.isLogin && Utility.isNobleForOld()) {
       DialogHelper.showCustomContentDialog({
         dialogId: 'syncNobleDialog',
@@ -277,7 +281,11 @@ export struct UserCenter {
           {
             value: '去登录',
             action: () => {
-              this.huaweiQuickLogin();
+              if (this.showWxLogin) {
+                this.showLoginDialog();
+              } else {
+                this.huaweiQuickLogin();
+              }
             }
           }
         ]
@@ -285,6 +293,98 @@ export struct UserCenter {
     }
   }
 
+  showLoginDialog() {
+    DialogHelper.showCustomContentDialog({
+      dialogId: 'loginDialog',
+      title: '',
+      autoCancel: true,
+      contentBuilder: () => {
+        this.loginDialogContentBuilder();
+      },
+      buttons: []
+    });
+  }
+  // 登录方式选择弹窗内容
+  @Builder
+  loginDialogContentBuilder(): void {
+    Column() {
+      Row() {
+        // 微信登录图标按钮
+        Column() {
+          Button({ type: ButtonType.Normal, stateEffect: true }) {
+            Column() {
+              Image($r('app.media.wx_logo'))
+                .width(56)
+                .height(56)
+                .margin({ bottom: 8 })
+              Text('微信登录')
+                .fontSize(15)
+                .fontWeight(FontWeight.Bold)
+                .fontColor('#333')
+            }
+            .alignItems(HorizontalAlign.Center)
+          }
+          .width(100)
+          .height(100)
+          .visibility(PreferencesUtil.getBooleanSync('isShowWX',false)?Visibility.Visible:Visibility.None)
+          .backgroundColor(Color.White)
+          // .border({ color: this.themeColor, width: 2 })
+          .borderRadius(20)
+          .onClick(async () => {
+            this.payType = 0;
+            // 微信登录
+            let req = new wxopensdk.SendAuthReq
+            req.isOption1 = false
+            req.nonAutomatic = true
+            req.scope = 'snsapi_userinfo,snsapi_friend,snsapi_message,snsapi_contact'
+            req.state = 'none'
+            req.transaction = 'test123'
+            let finished = await this.wxApi.sendReq(getContext(this) as common.UIAbilityContext, req)
+            console.log('send request finished: ', finished)
+            DialogHelper.closeDialog('loginDialog');
+          })
+        }
+        .margin({ right: 24 })
+
+        // 华为账号登录图标按钮
+        Column() {
+          Button({ type: ButtonType.Normal, stateEffect: true }) {
+            Column() {
+              Image($r('app.media.huawei'))
+                .width(56)
+                .height(56)
+                .margin({ bottom: 8 })
+              Text('华为登录')
+                .fontSize(15)
+                .fontWeight(FontWeight.Bold)
+                .fontColor('#333')
+            }
+            .alignItems(HorizontalAlign.Center)
+          }
+          .width(100)
+          .height(100)
+          .backgroundColor(Color.White)
+          // .border({ color: this.themeColor, width: 2 })
+          .borderRadius(20)
+          .onClick(() => {
+            this.payType = 1;
+            this.huaweiQuickLogin();
+            DialogHelper.closeDialog('loginDialog');
+          })
+        }
+      }
+      .justifyContent(FlexAlign.Center)
+      .width('100%')
+    }
+    .padding({
+      left: 24,
+      right: 24,
+      top: 8,
+      bottom: 24
+    })
+    .width('100%')
+  }
+
   aboutToDisappear() {
     this.wxEventHandler.unregisterOnWXRespCallback(this.onWXResp)
   }
@@ -451,7 +551,11 @@ export struct UserCenter {
       }
       .onClick(() => {
         if (!this.isLogin) {
-          this.huaweiQuickLogin();
+          if (this.showWxLogin) {
+            this.showLoginDialog();
+          } else {
+            this.huaweiQuickLogin();
+          }
         }
       })
       .width('100%')
@@ -952,6 +1056,7 @@ export struct UserCenter {
         let json: VipPlanListApiResponse = JSON.parse(res) as VipPlanListApiResponse;
         if (json.code === 0 && json.data && json.data.plans) {
           this.vipPlans = json.data.plans;
+          this.showWxLogin = !!json.data.show_wx_login;
           if (this.vipPlans.length > 0) {
             this.selectedPayPlan = this.vipPlans[0]; // 默认选中第一个套餐
           }