Browse Source

feat: 手机号快捷登陆

xiansin 2 years ago
parent
commit
d955e5469a

+ 3 - 1
mini/api/user/index.js

xqd
@@ -40,12 +40,14 @@ export async function login(account, password, code) {
 }
 
 export async function phoneQuickLogin(data) {
-  return new Promise(resolve => {
+  return new Promise((resolve, reject) => {
     return request.post(
       '/auth/wechat/minni/phone',
       data
     ).then(res => {
       resolve(res)
+    }).catch(err => {
+      reject(err)
     })
   })
 }

+ 1 - 1
mini/components/SwiperBox/index.vue

xqd
@@ -98,7 +98,7 @@ export default {
       flex-direction: row;
       justify-content: center;
       position: relative;
-      margin-bottom: 25%;
+      margin-bottom: 10%;
 
       &__line {
         height: 1rpx;

+ 24 - 7
mini/pages/login.vue

xqd xqd xqd
@@ -27,7 +27,6 @@
         color="#000"
         shape="square"
         :custom-style="btnStyle"
-        :loading="loading"
         @click="handleLogin"
       />
       <view
@@ -54,7 +53,6 @@ export default {
         password: ''
       },
       path: '/pages/index',
-      loading: false,
       inputStyle: {
         borderRadius: 0,
         borderColor: '#000 !important',
@@ -84,26 +82,45 @@ export default {
         this.$u.toast('请输入密码')
         return
       }
-      this.loading = true
+      this.$loading('登陆中...')
       uni.login({
         provider: uni.$u.platform,
         success: loginRes => {
           uni.hideLoading()
           this.$api.user.login(this.model.account, this.model.password, loginRes.code).then(async res => {
-            this.loading = false
+            this.$hideLoading()
             await this.$store.dispatch('user/token', res.data.token)
             await this.$store.dispatch('user/info', res.data.user_info)
             uni.reLaunch({
               url: this.path.replace('//', '/')
             })
           }).catch(() => {
-            this.loading = false
+            this.$hideLoading()
           })
         }
       })
     },
-    getPhoneNumber(res) {
-      console.log('-->data', res)
+    getPhoneNumber({ detail }) {
+      this.$loading('登陆中...')
+      uni.login({
+        provider: uni.$u.platform,
+        success: loginRes => {
+          const data = {
+            iv: detail.iv,
+            encryptedData: detail.encryptedData,
+            code: loginRes.code
+          }
+          this.$api.user.phoneQuickLogin(data).then(async res => {
+            await this.$store.dispatch('user/token', res.data.token)
+            await this.$store.dispatch('user/info', res.data.user_info)
+            uni.reLaunch({
+              url: this.path.replace('//', '/')
+            })
+          }).catch(() => {
+            this.$hideLoading()
+          })
+        }
+      })
     }
   },
   onLoad() {

+ 2 - 2
mini/setting.js

xqd
@@ -7,7 +7,7 @@ module.exports = {
   // 版本
   VERSION: '0.0.1',
   // API 接口URL
-  BASE_URL: IS_DEV ? 'http://www.jcs.me/api' : 'https://t3.9026.com/api',
+  BASE_URL: IS_DEV ? 'http://www.jcs.me/api' : 'https://t31.9026.com/api',
   // API 接口URL
-  IMAGE_URL: IS_DEV ? 'http://www.jcs.me/static/image' : 'https://t3.9026.com/static/image'
+  IMAGE_URL: IS_DEV ? 'http://www.jcs.me/static/image' : 'https://t31.9026.com/static/image'
 }

+ 1 - 0
server/.gitignore

xqd
@@ -18,3 +18,4 @@ yarn-error.log
 .user.ini
 _ide_helper.php
 server.zip
+/server.7z

+ 5 - 3
server/app/Http/Controllers/V1/AuthController.php

xqd xqd
@@ -90,9 +90,10 @@ class AuthController extends Controller
                 'iv'            => 'required',
             ]);
             $app = Factory::miniProgram(config('wechat.mini_program.default'));
-            $user = \user()->makeVisible('remember_token');
-            $decryptedData = $app->encryptor->decryptData($user['remember_token'], $req['iv'], $req['encryptedData']);
+            $data = $app->auth->session($req['code']);
+            $user = User::where('open_id',$data['openid'])->first();
 
+            $decryptedData = $app->encryptor->decryptData($data['session_key'], $req['iv'], $req['encryptedData']);
             $account = Account::where('account', $decryptedData['phoneNumber'])
                 ->where('status', 1)
                 ->first();
@@ -101,11 +102,12 @@ class AuthController extends Controller
             }
 
             $user = User::where('id', $user['id'])->first();
+            $user->remember_token = $data['session_key'];
             if($user->mobile != $decryptedData['phoneNumber']) {
                 $user->mobile = $decryptedData['phoneNumber'];
                 $user->account_id = $account->id;
-                $user->save();
             }
+            $user->save();
 
             $token = Auth::guard('api')->fromUser($user);