mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-04-01 17:23:48 +08:00
fix z
This commit is contained in:
@@ -87,7 +87,7 @@ import useAlertStore from "@/composables/store/useAlertStore";
|
||||
import DOMPurify from "dompurify";
|
||||
import { Modal, type ModalInterface, initFlowbite } from "flowbite";
|
||||
import { marked } from "marked";
|
||||
import { nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { z } from "zod";
|
||||
import Button from "../components/Button.vue";
|
||||
import UserUpsertModal from "../components/UserUpsertModal.vue";
|
||||
@@ -193,23 +193,12 @@ const chatByMode = async (message: string) => {
|
||||
};
|
||||
|
||||
const handleSendClick = async () => {
|
||||
try {
|
||||
scrollToBottom();
|
||||
const validInputMessage = z
|
||||
.string({ message: "消息不能为空" })
|
||||
.min(1, "消息不能为空")
|
||||
.parse(inputMessage.value);
|
||||
await chatByMode(validInputMessage);
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
alertStore.showAlert({
|
||||
level: "error",
|
||||
content: error.errors[0].message,
|
||||
});
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
scrollToBottom();
|
||||
const validInputMessage = z
|
||||
.string({ message: "消息不能为空" })
|
||||
.min(1, "消息不能为空")
|
||||
.parse(inputMessage.value);
|
||||
await chatByMode(validInputMessage);
|
||||
};
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
@@ -45,26 +45,19 @@ const handleLogin = async () => {
|
||||
password: z.string().min(1, "密码至少1个字符"),
|
||||
});
|
||||
|
||||
try {
|
||||
const validatedData = userSchema.parse({
|
||||
username: username.value,
|
||||
password: password.value,
|
||||
});
|
||||
await userAuth.signIn(validatedData.username, validatedData.password);
|
||||
alertStore.showAlert({
|
||||
level: "success",
|
||||
content: "登录成功",
|
||||
});
|
||||
const redirectPath =
|
||||
(route.query.redirect as string) ||
|
||||
`${RoutePath.DASHBOARD}/${RoutePath.USERVIEW}`;
|
||||
router.push(redirectPath);
|
||||
} catch (e) {
|
||||
alertStore.showAlert({
|
||||
level: "error",
|
||||
content: e instanceof z.ZodError ? e.errors[0].message : "账号或密码错误",
|
||||
});
|
||||
}
|
||||
const validatedData = userSchema.parse({
|
||||
username: username.value,
|
||||
password: password.value,
|
||||
});
|
||||
await userAuth.signIn(validatedData.username, validatedData.password);
|
||||
alertStore.showAlert({
|
||||
level: "success",
|
||||
content: "登录成功",
|
||||
});
|
||||
const redirectPath =
|
||||
(route.query.redirect as string) ||
|
||||
`${RoutePath.DASHBOARD}/${RoutePath.USERVIEW}`;
|
||||
router.push(redirectPath);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
@@ -78,47 +78,38 @@ onMounted(() => {
|
||||
|
||||
const handleUpdateClick = async () => {
|
||||
let validatedData = undefined;
|
||||
try {
|
||||
validatedData = z
|
||||
.object({
|
||||
username: z
|
||||
.string({
|
||||
message: "用户名不能为空",
|
||||
})
|
||||
.min(4, "用户名长度不能小于4个字符"),
|
||||
password: z
|
||||
.string()
|
||||
.min(5, "密码长度不能小于5个字符")
|
||||
.optional()
|
||||
.nullable(),
|
||||
confirmPassword: z.string().optional().nullable(),
|
||||
enable: z.boolean({
|
||||
message: "状态不能为空",
|
||||
}),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
if (data.password) {
|
||||
return data.password === data.confirmPassword;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{ message: "密码输入不一致。" },
|
||||
)
|
||||
.parse(userForm.value);
|
||||
await upsertCurrentUser(validatedData);
|
||||
alertStore.showAlert({
|
||||
content: "操作成功",
|
||||
level: "success",
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
alertStore.showAlert({
|
||||
level: "error",
|
||||
content: error.errors[0].message,
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
validatedData = z
|
||||
.object({
|
||||
username: z
|
||||
.string({
|
||||
message: "用户名不能为空",
|
||||
})
|
||||
.min(4, "用户名长度不能小于4个字符"),
|
||||
password: z
|
||||
.string()
|
||||
.min(5, "密码长度不能小于5个字符")
|
||||
.optional()
|
||||
.nullable(),
|
||||
confirmPassword: z.string().optional().nullable(),
|
||||
enable: z.boolean({
|
||||
message: "状态不能为空",
|
||||
}),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
if (data.password) {
|
||||
return data.password === data.confirmPassword;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{ message: "密码输入不一致。" },
|
||||
)
|
||||
.parse(userForm.value);
|
||||
await upsertCurrentUser(validatedData);
|
||||
alertStore.showAlert({
|
||||
content: "操作成功",
|
||||
level: "success",
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user