🔥 短信登录:接入完成

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'; import request from '@/sheep/request';
const AuthUtil = { const AuthUtil = {
// 使用手机 + 验证码登录
smsLogin: (data) => {
return request({
url: '/app-api/member/auth/sms-login',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '登录中',
successMsg: '登录成功',
},
});
},
// 发送手机验证码 // 发送手机验证码
sendSmsCode: (mobile, scene) => { sendSmsCode: (mobile, scene) => {
return request({ return request({
@ -8,20 +21,20 @@ const AuthUtil = {
method: 'POST', method: 'POST',
data: { data: {
mobile, mobile,
scene scene,
}, },
custom: { custom: {
loadingMsg: '发送中', loadingMsg: '发送中',
showSuccess: true, showSuccess: true,
successMsg: '发送成功' successMsg: '发送成功',
} },
}); });
}, },
// 登出系统 // 登出系统
logout: () => { logout: () => {
return request({ return request({
url: '/app-api/member/auth/logout', 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="head-box ss-m-b-60 ss-flex-col">
<view class="ss-flex ss-m-b-20"> <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 class="head-title-active head-title-line" @tap="showAuthModal('smsLogin')">
短信登录 短信登录
</view> </view>
<view class="head-title ss-m-r-40 head-title-animation">账号登录</view>
</view> </view>
<view class="head-subtitle">如果未设置过密码请点击忘记密码</view> <view class="head-subtitle">如果未设置过密码请点击忘记密码</view>
</view> </view>

View File

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

View File

@ -19,7 +19,7 @@
<change-mobile v-if="authType === 'changeMobile'" /> <change-mobile v-if="authType === 'changeMobile'" />
<!-- 6.修改密码 changePassword--> <!-- 6.修改密码 changePassword-->
<change-passwrod v-if="authType === 'changePassword'" /> <changePassword v-if="authType === 'changePassword'" />
<!-- 8.微信小程序授权 changeUsername--> <!-- 8.微信小程序授权 changeUsername-->
<mp-authorization v-if="authType === 'mpAuthorization'" /> <mp-authorization v-if="authType === 'mpAuthorization'" />
@ -109,7 +109,7 @@
import smsLogin from './components/sms-login.vue'; import smsLogin from './components/sms-login.vue';
import resetPassword from './components/reset-password.vue'; import resetPassword from './components/reset-password.vue';
import changeMobile from './components/change-mobile.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 mpAuthorization from './components/mp-authorization.vue';
import { closeAuthModal, showAuthModal } from '@/sheep/hooks/useModal'; 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'; import $api from '@/sheep/api';
// 打开授权弹框 // 打开授权弹框
export function showAuthModal(type = 'accountLogin') { export function showAuthModal(type = 'smsLogin') {
const modal = $store('modal'); const modal = $store('modal');
if (modal.auth !== '') { if (modal.auth !== '') {
closeAuthModal(); closeAuthModal();
@ -87,6 +87,9 @@ export function getSmsCode(event, mobile) {
case 'changePassword': case 'changePassword':
scene = 3; scene = 3;
break; break;
case 'smsLogin':
scene = 1;
break;
} }
$api.AuthUtil.sendSmsCode(mobile, scene).then((res) => { $api.AuthUtil.sendSmsCode(mobile, scene).then((res) => {
if (res.code === 0) { if (res.code === 0) {

View File

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