验证码登陆

This commit is contained in:
republicline 2024-08-15 11:11:55 +08:00
parent 41089bbd71
commit b10dc89005
5 changed files with 517 additions and 452 deletions

3
.env
View File

@ -2,4 +2,7 @@ VITE_PWD_ENC_KEY='thanks,rax4cloud'
VITE_OAUTH2_PASSWORD_CLIENT='rax:rax' VITE_OAUTH2_PASSWORD_CLIENT='rax:rax'
# OAUTH2 短信客户端信息
VITE_OAUTH2_MOBILE_CLIENT='app:app'
VITE_RAX_BASE_URL='/api' VITE_RAX_BASE_URL='/api'

31
src/api/login-phone.ts Normal file
View File

@ -0,0 +1,31 @@
import request from '@/utils/request';
import {Session} from "@/utils/storage";
const FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded';
export const sendMobileCode = (mobile: any) => {
return request({
url: '/admin/mobile/' + mobile,
method: 'get',
});
};
export const loginByMobile = (mobile: any, code: any) => {
const grant_type = 'mobile';
const scope = 'server';
const basicAuth = 'Basic ' + window.btoa(import.meta.env.VITE_OAUTH2_MOBILE_CLIENT);
Session.set('basicAuth', basicAuth);
return request({
url: '/admin/oauth2/token',
headers: {
skipToken: true,
Authorization: basicAuth,
'Content-Type': FORM_CONTENT_TYPE,
},
method: 'post',
data: {mobile: mobile, code: code, grant_type, scope},
});
};

View File

@ -58,10 +58,10 @@ export const constantRoute = [
] ]
}, },
{ {
path: '/remote-manage', path: '/remote-manage/remote-manage',
name: '远程管理', name: '远程管理',
component: () => import('@/views/remote-manage/index.vue'), component: () => import('@/views/remote-manage/index.vue'),
redirect: '/remote-manage/remote-manage', // redirect: '/remote-manage/remote-manage',
children: [ children: [
{ {
path: '/remote-manage/remote-manage', path: '/remote-manage/remote-manage',

View File

@ -68,7 +68,7 @@
</template> </template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-button class="login-btn" type="primary" @click="login('code')">登录</el-button> <el-button class="login-btn" type="primary" @click="logWithPhone">登录</el-button>
</div> </div>
</el-form> </el-form>
</div> </div>
@ -144,6 +144,7 @@ import * as loginApi from "@/api/login";
import {Session} from "@/utils/storage"; import {Session} from "@/utils/storage";
import * as hospitalApi from "@/api/hospital"; import * as hospitalApi from "@/api/hospital";
import {REGEXP} from "@/enum/global-enum"; import {REGEXP} from "@/enum/global-enum";
import {loginByMobile, sendMobileCode} from "@/api/login-phone";
// //
@ -156,7 +157,7 @@ const phoneAreas: any = getPhoneAreasData()
// //
let loading = ref(false); let loading = ref(false);
// //
const validatorPhone = (rule: any, value: any, callback: any) => { const validatorPhone = (value: any, callback: any) => {
if (value.indexOf('****') >= 0) { if (value.indexOf('****') >= 0) {
return callback().trim(); return callback().trim();
} }
@ -167,6 +168,7 @@ const validatorPhone = (rule: any, value: any, callback: any) => {
} }
} }
const loginRules = reactive({ const loginRules = reactive({
account: [ account: [
{required: true, message: '请输入用户名', trigger: 'change'} {required: true, message: '请输入用户名', trigger: 'change'}
@ -305,6 +307,7 @@ const selectPhoneArea = (e: string) => {
const sendCode = () => { const sendCode = () => {
if (loginParams.value.isSendCode) return if (loginParams.value.isSendCode) return
let num = 60 let num = 60
sendMobileCode(loginParams.value.phone);
ElMessage.success('发送成功!') ElMessage.success('发送成功!')
loginParams.value.isSendCode = true loginParams.value.isSendCode = true
loginParams.value.sendText = '请' + num + '秒后重新发送' loginParams.value.sendText = '请' + num + '秒后重新发送'
@ -347,6 +350,34 @@ function refreshImg() {
captchaImgUrl.value = '/api/admin/code/textImage?randomStr=' + randomStr captchaImgUrl.value = '/api/admin/code/textImage?randomStr=' + randomStr
} }
function logWithPhone() {
loginByMobile(loginParams.value.phone, loginParams.value.code)
.then((data: any) => {
sliderVConf.value.isShowSelf = false
if (data.code == 1 || data.error) {
ElMessage.error(data.msg ? data.msg : data.error)
loading.value = false
} else {
// token
loginPost(data)
router.removeRoute("root");
router.addRoute({
name: "root",
path: "/",
redirect: "/home"
})
router.replace('/home')
loading.value = false
ElNotification({
type: 'success',
message: '欢迎回来',
title: `HI,${getTime()}`
});
}
})
}
function sliderSuccess() { function sliderSuccess() {
loginApi.login({ loginApi.login({
username: loginParams.value.account, // username: loginParams.value.account, //

View File

@ -24,16 +24,16 @@ export default defineConfig({
proxy: { proxy: {
'/api': { '/api': {
// target: 'http://localhost:9999', // 目标服务器地址 // target: 'http://localhost:9999', // 目标服务器地址
// target: 'http://localhost:6379', // 目标服务器地址 target: 'http://localhost:6379', // 目标服务器地址
target: 'http://110.41.142.124:6379', // 目标服务器地址 // target: 'http://110.41.142.124:6379', // 目标服务器地址
ws: true, // 是否启用 WebSocket ws: true, // 是否启用 WebSocket
changeOrigin: true, // 是否修改请求头中的 Origin 字段 changeOrigin: true, // 是否修改请求头中的 Origin 字段
rewrite: (path) => path.replace(/^\/api/, ''), rewrite: (path) => path.replace(/^\/api/, ''),
}, },
'/socket.io': { '/socket.io': {
// target: 'ws://localhost:9999', // target: 'ws://localhost:9999',
// target: 'ws://localhost:6379', target: 'ws://localhost:6379',
target: 'ws://110.41.142.124:6379', // target: 'ws://110.41.142.124:6379',
ws: true, ws: true,
changeOrigin: true, changeOrigin: true,
rewrite: (path) => path.replace(/^\/socket.io/, ''), rewrite: (path) => path.replace(/^\/socket.io/, ''),