a611045db2
数字人内容库支持角色、世界书和预设管理;账号实验中心覆盖生命周期、指定用户、分组解释、漏斗和审计;更新星港品牌与默认导航,保留原兼容路由。
193 lines
5.1 KiB
Vue
193 lines
5.1 KiB
Vue
<script setup lang="ts">
|
|
/** 星港管理端登录,凭据由用户输入,不内置默认账号密码。 */
|
|
import Motion from "./utils/motion";
|
|
import { useRouter } from "vue-router";
|
|
import { message } from "@/utils/message";
|
|
import { loginRules } from "./utils/rule";
|
|
import { ref, reactive, toRaw } from "vue";
|
|
import { debounce } from "@pureadmin/utils";
|
|
import { useNav } from "@/layout/hooks/useNav";
|
|
import { useEventListener } from "@vueuse/core";
|
|
import type { FormInstance } from "element-plus";
|
|
import { useLayout } from "@/layout/hooks/useLayout";
|
|
import { useUserStoreHook } from "@/store/modules/user";
|
|
import { getTopMenu } from "@/router/utils";
|
|
import { bg, avatar, illustration } from "./utils/static";
|
|
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
|
import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange";
|
|
|
|
import dayIcon from "@/assets/svg/day.svg?component";
|
|
import darkIcon from "@/assets/svg/dark.svg?component";
|
|
import Lock from "~icons/ri/lock-fill";
|
|
import User from "~icons/ri/user-3-fill";
|
|
|
|
defineOptions({
|
|
name: "Login"
|
|
});
|
|
|
|
const router = useRouter();
|
|
const loading = ref(false);
|
|
const disabled = ref(false);
|
|
const ruleFormRef = ref<FormInstance>();
|
|
|
|
const { initStorage } = useLayout();
|
|
initStorage();
|
|
|
|
const { dataTheme, overallStyle, dataThemeChange } = useDataThemeChange();
|
|
dataThemeChange(overallStyle.value);
|
|
const { title } = useNav();
|
|
|
|
const ruleForm = reactive({
|
|
username: "",
|
|
password: ""
|
|
});
|
|
|
|
function getErrorMessage(error: unknown, fallback: string) {
|
|
const message = (
|
|
error as { response?: { data?: { error?: { message?: string } } } }
|
|
)?.response?.data?.error?.message;
|
|
|
|
if (message) return message;
|
|
if (error instanceof Error && error.message) return error.message;
|
|
return fallback;
|
|
}
|
|
|
|
const onLogin = async (formEl: FormInstance | undefined) => {
|
|
if (!formEl) return;
|
|
|
|
try {
|
|
await formEl.validate();
|
|
} catch {
|
|
return;
|
|
}
|
|
|
|
loading.value = true;
|
|
try {
|
|
const res = await useUserStoreHook().loginByUsername({
|
|
username: ruleForm.username,
|
|
password: ruleForm.password
|
|
});
|
|
|
|
if (res.success) {
|
|
disabled.value = true;
|
|
const redirect = router.currentRoute.value.query.redirect as
|
|
| string
|
|
| undefined;
|
|
await router.push(redirect || getTopMenu(true)?.path || "/access-denied");
|
|
message("登录成功", { type: "success" });
|
|
}
|
|
} catch (error) {
|
|
message(getErrorMessage(error, "登录失败"), { type: "error" });
|
|
} finally {
|
|
disabled.value = false;
|
|
loading.value = false;
|
|
}
|
|
};
|
|
|
|
const immediateDebounce: any = debounce(
|
|
formRef => onLogin(formRef),
|
|
1000,
|
|
true
|
|
);
|
|
|
|
useEventListener(document, "keydown", ({ code }) => {
|
|
if (
|
|
["Enter", "NumpadEnter"].includes(code) &&
|
|
!disabled.value &&
|
|
!loading.value
|
|
)
|
|
immediateDebounce(ruleFormRef.value);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="select-none">
|
|
<img :src="bg" class="wave" />
|
|
<div class="flex-c absolute right-5 top-3">
|
|
<!-- 主题 -->
|
|
<el-switch
|
|
v-model="dataTheme"
|
|
inline-prompt
|
|
:active-icon="dayIcon"
|
|
:inactive-icon="darkIcon"
|
|
@change="dataThemeChange"
|
|
/>
|
|
</div>
|
|
<div class="login-container">
|
|
<div class="img">
|
|
<component :is="toRaw(illustration)" />
|
|
</div>
|
|
<div class="login-box">
|
|
<div class="login-form">
|
|
<avatar class="avatar" />
|
|
<Motion>
|
|
<h2 class="outline-hidden">{{ title }}</h2>
|
|
</Motion>
|
|
|
|
<el-form
|
|
ref="ruleFormRef"
|
|
:model="ruleForm"
|
|
:rules="loginRules"
|
|
size="large"
|
|
>
|
|
<Motion :delay="100">
|
|
<el-form-item
|
|
:rules="[
|
|
{
|
|
required: true,
|
|
message: '请输入账号',
|
|
trigger: 'blur'
|
|
}
|
|
]"
|
|
prop="username"
|
|
>
|
|
<el-input
|
|
v-model="ruleForm.username"
|
|
clearable
|
|
placeholder="账号"
|
|
:prefix-icon="useRenderIcon(User)"
|
|
/>
|
|
</el-form-item>
|
|
</Motion>
|
|
|
|
<Motion :delay="150">
|
|
<el-form-item prop="password">
|
|
<el-input
|
|
v-model="ruleForm.password"
|
|
clearable
|
|
show-password
|
|
placeholder="密码"
|
|
:prefix-icon="useRenderIcon(Lock)"
|
|
/>
|
|
</el-form-item>
|
|
</Motion>
|
|
|
|
<Motion :delay="250">
|
|
<el-button
|
|
class="w-full mt-4!"
|
|
size="default"
|
|
type="primary"
|
|
:loading="loading"
|
|
:disabled="disabled"
|
|
@click="onLogin(ruleFormRef)"
|
|
>
|
|
登录
|
|
</el-button>
|
|
</Motion>
|
|
</el-form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
@import url("@/style/login.css");
|
|
</style>
|
|
|
|
<style lang="scss" scoped>
|
|
:deep(.el-input-group__append, .el-input-group__prepend) {
|
|
padding: 0;
|
|
}
|
|
</style>
|