2024-07-07 18:05:28 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<div class="login_form_box">
|
|
|
|
|
|
<a-form :rules="rules" :model="form" layout="vertical" @submit="onSubmit">
|
|
|
|
|
|
<a-form-item field="username" :hide-asterisk="true">
|
2025-04-10 16:57:26 +08:00
|
|
|
|
<a-input v-model="form.username" allow-clear placeholder="请输入账号:admin/common">
|
2024-07-07 18:05:28 +08:00
|
|
|
|
<template #prefix>
|
|
|
|
|
|
<icon-user />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-input>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item field="password" :hide-asterisk="true">
|
|
|
|
|
|
<a-input-password v-model="form.password" allow-clear placeholder="请输入密码">
|
|
|
|
|
|
<template #prefix>
|
|
|
|
|
|
<icon-lock />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-input-password>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item field="verifyCode" :hide-asterisk="true">
|
|
|
|
|
|
<div class="verifyCode">
|
|
|
|
|
|
<a-input style="width: 160px" v-model="form.verifyCode" allow-clear placeholder="请输入验证码" />
|
2025-07-05 09:04:48 +08:00
|
|
|
|
<s-verify-code :content-height="30" :font-size-max="30" :content-width="110" @verify-code-change="verifyCodeChange" />
|
2024-07-07 18:05:28 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item field="remember">
|
|
|
|
|
|
<div class="remember">
|
|
|
|
|
|
<a-checkbox v-model="form.remember">记住密码</a-checkbox>
|
|
|
|
|
|
<div class="forgot-password">忘记密码</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item>
|
|
|
|
|
|
<a-button long type="primary" html-type="submit">登录</a-button>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
</a-form>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="register">注册账号</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { useRouter } from "vue-router";
|
|
|
|
|
|
import { useUserInfoStore } from "@/store/modules/user-info";
|
2025-04-10 16:57:26 +08:00
|
|
|
|
import { loginAPI } from "@/api/modules/user/index";
|
2025-01-12 20:17:35 +08:00
|
|
|
|
import { useRoutesConfigStore } from "@/store/modules/route-config";
|
2025-04-10 16:57:26 +08:00
|
|
|
|
import { useSystemStore } from "@/store/modules/system";
|
|
|
|
|
|
let userStores = useUserInfoStore();
|
2025-01-12 20:17:35 +08:00
|
|
|
|
const routeStore = useRoutesConfigStore();
|
2024-07-07 18:05:28 +08:00
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
const form = ref({
|
|
|
|
|
|
username: "admin",
|
|
|
|
|
|
password: "123456",
|
|
|
|
|
|
verifyCode: null,
|
|
|
|
|
|
remember: false
|
|
|
|
|
|
});
|
|
|
|
|
|
const rules = ref({
|
|
|
|
|
|
username: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请输入账号"
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
password: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请输入密码"
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
verifyCode: [
|
|
|
|
|
|
{
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
message: "请输入验证码"
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
validator: (value: string, cb: any) => {
|
2024-10-31 14:47:46 +08:00
|
|
|
|
if (value !== verifyCode.value) {
|
2024-07-07 18:05:28 +08:00
|
|
|
|
cb("请输入正确的验证码");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
cb();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
});
|
2024-10-31 14:47:46 +08:00
|
|
|
|
const verifyCode = ref("");
|
|
|
|
|
|
const verifyCodeChange = (code: string) => (verifyCode.value = code);
|
2024-07-07 18:05:28 +08:00
|
|
|
|
|
2025-04-10 16:57:26 +08:00
|
|
|
|
// 提交表单
|
2024-10-08 15:14:10 +08:00
|
|
|
|
const onSubmit = async ({ errors }: any) => {
|
2024-07-07 18:05:28 +08:00
|
|
|
|
if (errors) return;
|
2025-04-10 16:57:26 +08:00
|
|
|
|
onLogin();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 登录
|
|
|
|
|
|
const onLogin = async () => {
|
|
|
|
|
|
// 登录
|
2024-10-31 14:47:46 +08:00
|
|
|
|
let res = await loginAPI(form.value);
|
2025-04-10 16:57:26 +08:00
|
|
|
|
// 存储token
|
|
|
|
|
|
await userStores.setToken(res.data.token);
|
|
|
|
|
|
// 加载用户信息
|
|
|
|
|
|
await userStores.setAccount();
|
2025-01-12 20:17:35 +08:00
|
|
|
|
// 加载路由信息
|
|
|
|
|
|
await routeStore.initSetRouter();
|
2025-04-10 16:57:26 +08:00
|
|
|
|
|
|
|
|
|
|
arcoMessage("success", "登录成功");
|
|
|
|
|
|
// 跳转首页
|
2024-07-07 18:05:28 +08:00
|
|
|
|
router.replace("/home");
|
2025-04-10 16:57:26 +08:00
|
|
|
|
// 设置字典
|
|
|
|
|
|
useSystemStore().setDictData();
|
2024-07-07 18:05:28 +08:00
|
|
|
|
};
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
.login_form_box {
|
|
|
|
|
|
margin-top: 28px;
|
|
|
|
|
|
.verifyCode {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2024-12-05 15:20:17 +08:00
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
width: 100%;
|
2024-07-07 18:05:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
.remember {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2024-12-05 15:20:17 +08:00
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
width: 100%;
|
2024-07-07 18:05:28 +08:00
|
|
|
|
.forgot-password {
|
|
|
|
|
|
color: $color-primary;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
.register {
|
|
|
|
|
|
font-size: $font-size-body-1;
|
2024-12-05 15:20:17 +08:00
|
|
|
|
color: $color-text-3;
|
|
|
|
|
|
text-align: center;
|
2024-07-07 18:05:28 +08:00
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|