ソースを参照

refactor(login): 重构登录页面逻辑

- 修改了登录流程,增加了无登录状态的处理
- 优化了页面显示逻辑,注释掉了部分不需要的代码
- 调整了微信登录的处理方式,增加了 getIsNoLogin 方法
mws 4 ヶ月 前
コミット
48e5b59165
2 ファイル変更41 行追加23 行削除
  1. 13 13
      pages/hexiao/login.vue
  2. 28 10
      pages/login.vue

+ 13 - 13
pages/hexiao/login.vue

@@ -26,7 +26,7 @@
         </view>
       </view>
 
-     <view v-if="showTel">
+     <view >
        <view class="form-group">
          <view class="input-wrapper">
            <uni-icons type="person" size="24" color="#cccccc"></uni-icons>
@@ -48,18 +48,18 @@
 
        <button class="login-btn" @click="handleLogin">登 录</button>
      </view>
-    <view v-if="!showTel">
-      <view>
-        请点击下方按钮进行授权登录
-      </view>
-      <button class="login-btn" open-type="getPhoneNumber" @getphonenumber="handlePhone">
-        授权登录
-      </button>
-    </view>
-    <view style="font-size: 12px;margin-top:12%;" @click="showTel = !showTel">
-      <view v-if="!showTel">使用手机号验证码登录</view>
-      <view v-if="showTel">一键登录</view>
-    </view>
+<!--    <view v-if="!showTel">-->
+<!--      <view>-->
+<!--        请点击下方按钮进行授权登录-->
+<!--      </view>-->
+<!--      <button class="login-btn" open-type="getPhoneNumber" @getphonenumber="handlePhone">-->
+<!--        授权登录-->
+<!--      </button>-->
+<!--    </view>-->
+<!--    <view style="font-size: 12px;margin-top:12%;" @click="showTel = !showTel">-->
+<!--      <view v-if="!showTel">使用手机号验证码登录</view>-->
+<!--      <view v-if="showTel">一键登录</view>-->
+<!--    </view>-->
     </view>
   </view>
 </template>

+ 28 - 10
pages/login.vue

@@ -12,7 +12,8 @@
  	} from '@/utils/auth'
  	import {
  		login,
- 		verifyScanCode
+ 		verifyScanCode,
+    getIsNoLogin
  	} from '@/api/login'
  	import {
  		getScanData
@@ -46,25 +47,28 @@
  					this.status = true;
  				}
  				wx.login({
- 					success(res) {
- 						if (res.code) {
+ 					success(resLogin) {
+ 						if (resLogin.code) {
  							// 例如发送到服务器进行登录态验证等操作
- 							login(that.scanCode, res.code).then(res => {
+ 							login(that.scanCode, resLogin.code).then(res => {
  								console.log('登录成功', res);
  								if (res.code === 0) {
  									if (res.data.isWxAuth == 1) {
  										uni.setStorageSync('Authorization-status', true);
  									}
+                  if ((that.scanCode === '' || that.scanCode === undefined) && res.data.roles.length > 1){
+                     that.getIsNoLogin(res.data.uid);
+                     return;
+                  }
+
  									that.scanCode = res.data.qrCode;
- 									setToken(res.data.sessionId)
+ 									setToken(res.data.sessionId);
  									that.path = res.data.page_path;
  									that.verify();
  								} else {
  									if (res.code === 98) {
- 										uni.showToast({
- 											title: '请重新扫描二维码进入页面',
- 											icon: 'none'
- 										});
+ 										that.getIsNoLogin();
+ 										return;
  									} else {
 										uni.showToast({
 											title: res.msg,
@@ -123,7 +127,21 @@
  						})
  					}
  				})
- 			}
+ 			},
+      getIsNoLogin(uid) {
+        wx.login({
+          success(resLogin) {
+            if (resLogin.code) {
+              getIsNoLogin({jsCode:resLogin.code}).then(res => {
+                  // 跳转登陆页
+                  uni.redirectTo({
+                    url: '/pages/hexiao/login?uid=0'
+                  })
+              })
+            }
+          }
+        });
+      }
  		}
  	}
  </script>