feat: 登录接口和验证码登录
This commit is contained in:
@@ -3,7 +3,7 @@ import { request } from '@/plugins/http-fetch';
|
|||||||
// 登录方法
|
// 登录方法
|
||||||
export function login(data: Record<string, string>) {
|
export function login(data: Record<string, string>) {
|
||||||
return request({
|
return request({
|
||||||
url: '/securityManagement/v1/oauth/token',
|
url: '/securityManagement/v1/login',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: data,
|
data: data,
|
||||||
whithToken: false,
|
whithToken: false,
|
||||||
@@ -52,7 +52,7 @@ export function logout() {
|
|||||||
*/
|
*/
|
||||||
export function getCaptchaImage() {
|
export function getCaptchaImage() {
|
||||||
return request({
|
return request({
|
||||||
url: '/captchaImage',
|
url: '/securityManagement/v1/captchaImage',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
whithToken: false,
|
whithToken: false,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { GlobalFooter } from '@ant-design-vue/pro-layout';
|
import { GlobalFooter } from '@ant-design-vue/pro-layout';
|
||||||
import { message } from 'ant-design-vue/lib';
|
import { message } from 'ant-design-vue/lib';
|
||||||
import { reactive } from 'vue';
|
import { reactive, onMounted } from 'vue';
|
||||||
import useUserStore from '@/store/modules/user';
|
import useUserStore from '@/store/modules/user';
|
||||||
import useI18n from '@/hooks/useI18n';
|
import { getCaptchaImage } from '@/api/login';
|
||||||
import { regExpMobile } from '@/utils/regular-utils';
|
|
||||||
import { useRouter, useRoute } from 'vue-router';
|
import { useRouter, useRoute } from 'vue-router';
|
||||||
|
import useI18n from '@/hooks/useI18n';
|
||||||
|
import { toRaw } from 'vue';
|
||||||
const { t, changeLocale } = useI18n();
|
const { t, changeLocale } = useI18n();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -21,24 +22,37 @@ let state = reactive({
|
|||||||
username: 'admin',
|
username: 'admin',
|
||||||
/**密码 */
|
/**密码 */
|
||||||
password: 'rootaa',
|
password: 'rootaa',
|
||||||
|
/**验证码 */
|
||||||
|
code: '',
|
||||||
|
/**验证码uuid */
|
||||||
|
uuid: '',
|
||||||
},
|
},
|
||||||
/**表单提交点击状态 */
|
/**表单提交点击状态 */
|
||||||
fromClick: false,
|
fromClick: false,
|
||||||
|
/**验证码状态 */
|
||||||
|
captcha: {
|
||||||
|
/**验证码开关 */
|
||||||
|
enabled: false,
|
||||||
|
/**验证码图片地址 */
|
||||||
|
codeImg: '',
|
||||||
|
},
|
||||||
|
/**验证码点击状态 */
|
||||||
|
captchaClick: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
/**表单验证通过 */
|
/**表单验证通过 */
|
||||||
function fnFinish() {
|
function fnFinish() {
|
||||||
state.fromClick = true;
|
state.fromClick = true;
|
||||||
// 账号密码登录
|
// 账号密码登录
|
||||||
let form = {
|
// let form = {
|
||||||
userName: state.from.username,
|
// userName: state.from.username,
|
||||||
value: state.from.password,
|
// value: state.from.password,
|
||||||
grantType: 'password',
|
// grantType: 'password',
|
||||||
};
|
// };
|
||||||
|
|
||||||
// 发送请求
|
// 发送请求
|
||||||
useUserStore()
|
useUserStore()
|
||||||
.fnLogin(form)
|
.fnLogin(toRaw(state.from))
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.code === 1) {
|
if (res.code === 1) {
|
||||||
message.success(t('views.login.loginSuccess'), 3);
|
message.success(t('views.login.loginSuccess'), 3);
|
||||||
@@ -49,9 +63,38 @@ function fnFinish() {
|
|||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
state.fromClick = false;
|
state.fromClick = false;
|
||||||
|
// 刷新验证码
|
||||||
|
if (state.captcha.enabled) {
|
||||||
|
state.from.code = '';
|
||||||
|
fnGetCaptcha();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取验证码
|
||||||
|
*/
|
||||||
|
function fnGetCaptcha() {
|
||||||
|
if (state.captchaClick) return;
|
||||||
|
state.captchaClick = true;
|
||||||
|
getCaptchaImage().then(res => {
|
||||||
|
state.captchaClick = false;
|
||||||
|
if (res.code != 1) {
|
||||||
|
message.warning(`${res.msg}`, 3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.captcha.enabled = Boolean(res.captchaEnabled);
|
||||||
|
if (state.captcha.enabled) {
|
||||||
|
state.captcha.codeImg = res.img;
|
||||||
|
state.from.uuid = res.uuid;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fnGetCaptcha();
|
||||||
|
});
|
||||||
|
|
||||||
/**改变多语言 */
|
/**改变多语言 */
|
||||||
function fnChangeLocale(e: any) {
|
function fnChangeLocale(e: any) {
|
||||||
changeLocale(e.key);
|
changeLocale(e.key);
|
||||||
@@ -118,6 +161,43 @@ function fnChangeLocale(e: any) {
|
|||||||
</a-input-password>
|
</a-input-password>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
|
<a-row :gutter="8" v-if="state.captcha.enabled">
|
||||||
|
<a-col :span="16">
|
||||||
|
<a-form-item
|
||||||
|
name="code"
|
||||||
|
:rules="[
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
min: 1,
|
||||||
|
message: t('valid.codePlease'),
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
>
|
||||||
|
<a-input
|
||||||
|
v-model:value="state.from.code"
|
||||||
|
size="large"
|
||||||
|
:placeholder="t('valid.codeHit')"
|
||||||
|
:maxlength="6"
|
||||||
|
>
|
||||||
|
<template #prefix>
|
||||||
|
<RobotOutlined class="prefix-icon" />
|
||||||
|
</template>
|
||||||
|
</a-input>
|
||||||
|
</a-form-item>
|
||||||
|
</a-col>
|
||||||
|
<a-col :span="8">
|
||||||
|
<a-image
|
||||||
|
:alt="t('valid.codeHit')"
|
||||||
|
style="cursor: pointer; border-radius: 2px"
|
||||||
|
width="120px"
|
||||||
|
height="40px"
|
||||||
|
:preview="false"
|
||||||
|
:src="state.captcha.codeImg"
|
||||||
|
@click="fnGetCaptcha"
|
||||||
|
/>
|
||||||
|
</a-col>
|
||||||
|
</a-row>
|
||||||
|
|
||||||
<a-row
|
<a-row
|
||||||
:gutter="8"
|
:gutter="8"
|
||||||
justify="space-between"
|
justify="space-between"
|
||||||
|
|||||||
Reference in New Issue
Block a user