🔥 短信登录:接入完成

pull/29/head^2
YunaiV 2023-12-17 19:29:18 +08:00
parent 8a40fbf299
commit 1d9b304026
6 changed files with 36 additions and 15 deletions

View File

@ -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',
});
},
};

View File

@ -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>

View File

@ -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();
}
}

View File

@ -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';

View File

@ -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) {

View File

@ -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) {