Browse Source

微信登录暂时先不搞

lifanagju_citu 7 months ago
parent
commit
17b22834be
1 changed files with 42 additions and 2 deletions
  1. 42 2
      layout/components/authModal/login/index.vue

+ 42 - 2
layout/components/authModal/login/index.vue

@@ -58,7 +58,11 @@
             <uni-easyinput type="password" placeholder="请输入密码" v-model="state.account.password" :inputBorder="false"></uni-easyinput>
           </uni-forms-item>
         </uni-forms>
-        <view class="register" @tap="handleChangeRegister">还没有登录账户?去注册</view>
+        <view class="quickLogon">
+          <button v-if="showWxLogon" class="wxLogon" type="text" :plain="true" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信登录</button>
+          <view v-else></view>
+          <view class="register" @tap="handleChangeRegister">还没有登录账户?去注册</view>
+        </view>
         <button class="send-button" @tap="handleLogin"> 登 录  </button>
         <view class="agreement-box ss-flex ss-row-center">
           <uni-icons size="20" :type="protocol ? 'checkbox-filled' : 'circle'" :color="protocol ? '#00897B' : '#ccc'" @tap="protocol = !protocol"></uni-icons>
@@ -228,6 +232,29 @@ function handleChangeLogin () {
   changeType.value = 'login'
 }
 
+const showWxLogon = false
+// 微信登录
+const getPhoneNumber = async (e) => {
+  if (!protocol.value) return await uni.showToast({ title: '请先阅读并同意用户协议和隐私政策', icon: 'none' })
+  if (e?.detail?.errMsg !== 'getPhoneNumber:ok') {
+    uni.showToast({ title: '微信登录失败', icon: 'none' })
+    return
+  }
+  changeType.value = 'login'
+  wx.login({
+    success: async (result) => {
+      const wxLoginCode = result?.code || ''
+      const query = {
+        wxLoginCode,
+        iv: e.detail.iv,
+        encryptedData: e.detail.encryptedData,
+      }
+      await useUserStore.handleSmsLogin(query, current.value === 0)
+    },
+    fail:(res)=> { console.log("获取登录凭证code失败!", res) }
+  })
+}
+
 async function handleRegister () {
   const validate = await unref(registerForm).validate()
   if (!validate) return
@@ -271,11 +298,24 @@ const handleLogin = async () => {
   color: #00897B;
   margin-top: 30rpx;
 }
+.quickLogon {
+  display: flex;
+  justify-content: space-between;
+  padding: 0 20rpx;
+  align-items: center;
+}
+.wxLogon {
+  font-size: .85em;
+  color: #00897B;
+  border: none;
+  margin: 0;
+  padding: 0;
+}
 .register {
   widows: 100%;
   font-size: .85em;
   color: red;
-  text-align: right;
+  // text-align: right;
   &.login {
     color: #00897B;
   }