重构为js

This commit is contained in:
2026-07-02 18:42:32 +08:00
parent f2c23cf6a5
commit 1db8bac454
45 changed files with 1248 additions and 3078 deletions

View File

@@ -1,33 +1,24 @@
<script lang="ts" setup>
<script setup>
import { computed, reactive, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useUserStore } from "@/store/modules/user.js";
import { encryptPasswordPayload } from '@/utils/passwordEncrypt.js'
import { encryptPasswordPayload } from "@/utils/passwordEncrypt.js";
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
const form = reactive({
username: "",
password: "",
password: ""
});
const loading = ref(false);
const errorMessage = ref("");
const redirectPath = computed(() => {
const redirect = route.query.redirect;
if (
typeof redirect === "string" &&
redirect.startsWith("/") &&
!redirect.startsWith("//")
) {
if (typeof redirect === "string" && redirect.startsWith("/") && !redirect.startsWith("//")) {
return redirect;
}
return "/dashboard/integrated-center";
});
// 校验登录表单,避免空账号或空密码提交到后端。
function validateLoginForm() {
if (!form.username.trim()) {
errorMessage.value = "请输入账号";
@@ -39,23 +30,18 @@ function validateLoginForm() {
}
return true;
}
// 提交登录信息,成功后回到登录前访问的页面。
async function handleLogin() {
if (!validateLoginForm() || loading.value) {
return;
}
loading.value = true;
errorMessage.value = "";
try {
const encryptedForm = await encryptPasswordPayload(form, ['password'])
await userStore.login(encryptedForm)
const encryptedForm = await encryptPasswordPayload(form, ["password"]);
await userStore.login(encryptedForm);
router.replace(redirectPath.value);
} catch (error) {
errorMessage.value =
error instanceof Error ? error.message : "登录失败,请检查账号或密码";
errorMessage.value = error instanceof Error ? error.message : "登录失败\,请检查账号或密码";
} finally {
loading.value = false;
}