瀏覽代碼

🔥 短信登录:接入完成

YunaiV 1 年之前
父節點
當前提交
1d9b304026

+ 17 - 4
sheep/api/member/auth.js

@@ -1,6 +1,19 @@
 import request from '@/sheep/request';
 
 const AuthUtil = {
+  // 使用手机 + 验证码登录
+  smsLogin: (data) => {
+    return request({
+      url: '/app-api/member/auth/sms-login',
+      method: 'POST',
+      data,
+      custom: {
+        showSuccess: true,
+        loadingMsg: '登录中',
+        successMsg: '登录成功',
+      },
+    });
+  },
   // 发送手机验证码
   sendSmsCode: (mobile, scene) => {
     return request({
@@ -8,20 +21,20 @@ const AuthUtil = {
       method: 'POST',
       data: {
         mobile,
-        scene
+        scene,
       },
       custom: {
         loadingMsg: '发送中',
         showSuccess: true,
-        successMsg: '发送成功'
-      }
+        successMsg: '发送成功',
+      },
     });
   },
   // 登出系统
   logout: () => {
     return request({
       url: '/app-api/member/auth/logout',
-      method: 'POST'
+      method: 'POST',
     });
   },
 };

+ 1 - 1
sheep/components/s-auth-modal/components/account-login.vue

@@ -4,10 +4,10 @@
     <!-- 标题栏 -->
     <view class="head-box ss-m-b-60 ss-flex-col">
       <view class="ss-flex ss-m-b-20">
-        <view class="head-title ss-m-r-40 head-title-animation">账号登录</view>
         <view class="head-title-active head-title-line" @tap="showAuthModal('smsLogin')">
           短信登录
         </view>
+        <view class="head-title ss-m-r-40 head-title-animation">账号登录</view>
       </view>
       <view class="head-subtitle">如果未设置过密码,请点击忘记密码</view>
     </view>

+ 11 - 7
sheep/components/s-auth-modal/components/sms-login.vue

@@ -4,10 +4,10 @@
     <!-- 标题栏 -->
     <view class="head-box ss-m-b-60">
       <view class="ss-flex ss-m-b-20">
+        <view class="head-title head-title-line head-title-animation">短信登录</view>
         <view class="head-title-active ss-m-r-40" @tap="showAuthModal('accountLogin')">
           账号登录
         </view>
-        <view class="head-title head-title-line head-title-animation">短信登录</view>
       </view>
       <view class="head-subtitle">未注册的手机号,验证后自动注册账号</view>
     </view>
@@ -59,10 +59,11 @@
 </template>
 
 <script setup>
-  import { computed, watch, ref, reactive, unref } from 'vue';
+  import { ref, reactive, unref } from 'vue';
   import sheep from '@/sheep';
   import { code, mobile } from '@/sheep/validate/form';
   import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
+  import AuthUtil from '@/sheep/api/member/auth';
 
   const smsLoginRef = ref(null);
 
@@ -89,22 +90,25 @@
     },
   });
 
-  // 2.短信登录
+  // 短信登录
   async function smsLoginSubmit() {
+    // 参数校验
     const validate = await unref(smsLoginRef)
       .validate()
       .catch((error) => {
         console.log('error: ', error);
       });
-    if (!validate) return;
-
+    if (!validate) {
+      return;
+    }
     if (!props.agreeStatus) {
       emits('onConfirm', true)
       sheep.$helper.toast('请勾选同意');
       return;
     }
-    const { error } = await sheep.$api.user.smsLogin(state.model);
-    if (error === 0) {
+    // 提交数据
+    const { code } = await AuthUtil.smsLogin(state.model);
+    if (code === 0) {
       closeAuthModal();
     }
   }

+ 2 - 2
sheep/components/s-auth-modal/s-auth-modal.vue

@@ -19,7 +19,7 @@
       <change-mobile v-if="authType === 'changeMobile'" />
 
       <!-- 6.修改密码 changePassword-->
-      <change-passwrod v-if="authType === 'changePassword'" />
+      <changePassword v-if="authType === 'changePassword'" />
 
       <!-- 8.微信小程序授权 changeUsername-->
       <mp-authorization v-if="authType === 'mpAuthorization'" />
@@ -109,7 +109,7 @@
   import smsLogin from './components/sms-login.vue';
   import resetPassword from './components/reset-password.vue';
   import changeMobile from './components/change-mobile.vue';
-  import changePasswrod from './components/change-password.vue';
+  import changePassword from './components/change-password.vue';
   import mpAuthorization from './components/mp-authorization.vue';
   import { closeAuthModal, showAuthModal } from '@/sheep/hooks/useModal';
 

+ 4 - 1
sheep/hooks/useModal.js

@@ -6,7 +6,7 @@ import test from '@/sheep/helper/test.js';
 import $api from '@/sheep/api';
 
 // 打开授权弹框
-export function showAuthModal(type = 'accountLogin') {
+export function showAuthModal(type = 'smsLogin') {
   const modal = $store('modal');
   if (modal.auth !== '') {
     closeAuthModal();
@@ -87,6 +87,9 @@ export function getSmsCode(event, mobile) {
     case 'changePassword':
       scene = 3;
       break;
+    case 'smsLogin':
+      scene = 1;
+      break;
   }
   $api.AuthUtil.sendSmsCode(mobile, scene).then((res) => {
     if (res.code === 0) {

+ 1 - 0
sheep/request/index.js

@@ -113,6 +113,7 @@ http.interceptors.response.use(
 		if (response.header.authorization || response.header.Authorization) {
 			$store('user').setToken(response.header.authorization || response.header.Authorization);
 		}
+    // TODO 芋艿:如果是登录的 API,则自动设置 token
 
 		response.config.custom.showLoading && closeLoading();
 		if (response.data.error !== 0 && response.data.code !== 0) {