mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-04-11 08:47:21 +00:00
fix z
This commit is contained in:
@@ -90,19 +90,9 @@ const handleSubmit = async () => {
|
|||||||
.max(15, "部门名称最多15个字符"),
|
.max(15, "部门名称最多15个字符"),
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
const validatedData = schema.parse(formData.value);
|
||||||
const validatedData = schema.parse(formData.value);
|
await onSubmit(validatedData);
|
||||||
await onSubmit(validatedData);
|
updateFormData(undefined);
|
||||||
updateFormData(undefined);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof z.ZodError) {
|
|
||||||
alertStore.showAlert({
|
|
||||||
level: "error",
|
|
||||||
content: error.errors[0].message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -106,45 +106,35 @@ watch(() => llm, updateFormData, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
try {
|
const llmSchema = z.object({
|
||||||
const llmSchema = z.object({
|
id: z.number({
|
||||||
id: z.number({
|
message: "id不能为空",
|
||||||
message: "id不能为空",
|
}),
|
||||||
}),
|
name: z.string({
|
||||||
name: z.string({
|
message: "名称不能为空",
|
||||||
message: "名称不能为空",
|
}),
|
||||||
}),
|
modelName: z.string({
|
||||||
modelName: z.string({
|
message: "模型名称不能为空",
|
||||||
message: "模型名称不能为空",
|
}),
|
||||||
}),
|
apiKey: z.string({
|
||||||
apiKey: z.string({
|
message: "apiKey不能为空",
|
||||||
message: "apiKey不能为空",
|
}),
|
||||||
}),
|
url: z.string({
|
||||||
url: z.string({
|
message: "url不能为空",
|
||||||
message: "url不能为空",
|
}),
|
||||||
}),
|
enable: z.boolean({
|
||||||
enable: z.boolean({
|
message: "状态不能为空",
|
||||||
message: "状态不能为空",
|
}),
|
||||||
}),
|
priority: z.number({
|
||||||
priority: z.number({
|
message: "优先级必须为数字",
|
||||||
message: "优先级必须为数字",
|
}),
|
||||||
}),
|
type: z.string({
|
||||||
type: z.string({
|
message: "类型不能为空",
|
||||||
message: "类型不能为空",
|
}),
|
||||||
}),
|
});
|
||||||
});
|
const validatedData = llmSchema.parse(formData.value);
|
||||||
const validatedData = llmSchema.parse(formData.value);
|
await onSubmit(validatedData);
|
||||||
await onSubmit(validatedData);
|
updateFormData(undefined);
|
||||||
updateFormData(undefined);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof z.ZodError) {
|
|
||||||
alertStore.showAlert({
|
|
||||||
level: "error",
|
|
||||||
content: error.errors[0].message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -86,18 +86,8 @@ const handleSubmit = async () => {
|
|||||||
.max(15, "权限代码最多15个字符"),
|
.max(15, "权限代码最多15个字符"),
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
const validatedData = permissionSchema.parse(formData.value);
|
||||||
const validatedData = permissionSchema.parse(formData.value);
|
await onSubmit(validatedData);
|
||||||
await onSubmit(validatedData);
|
updateFormData(undefined);
|
||||||
updateFormData(undefined);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof z.ZodError) {
|
|
||||||
alertStore.showAlert({
|
|
||||||
level: "error",
|
|
||||||
content: error.errors[0].message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -78,19 +78,9 @@ const handleSubmit = async () => {
|
|||||||
.max(15, "岗位名称最多15个字符"),
|
.max(15, "岗位名称最多15个字符"),
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
const validatedData = schema.parse(formData.value);
|
||||||
const validatedData = schema.parse(formData.value);
|
await onSubmit(validatedData);
|
||||||
await onSubmit(validatedData);
|
updateFormData(undefined);
|
||||||
updateFormData(undefined);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof z.ZodError) {
|
|
||||||
alertStore.showAlert({
|
|
||||||
level: "error",
|
|
||||||
content: error.errors[0].message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -86,19 +86,9 @@ const handleSubmit = async () => {
|
|||||||
.max(15, "角色代码最多15个字符"),
|
.max(15, "角色代码最多15个字符"),
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
const validatedData = roleSchema.parse(formData.value);
|
||||||
const validatedData = roleSchema.parse(formData.value);
|
await onSubmit(validatedData);
|
||||||
await onSubmit(validatedData);
|
updateFormData(undefined);
|
||||||
updateFormData(undefined);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof z.ZodError) {
|
|
||||||
alertStore.showAlert({
|
|
||||||
level: "error",
|
|
||||||
content: error.errors[0].message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -69,17 +69,7 @@ const handleSubmit = async () => {
|
|||||||
.min(5, "表达式的长度非法"),
|
.min(5, "表达式的长度非法"),
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
const validatedData = jobSchema.parse(formData.value);
|
||||||
const validatedData = jobSchema.parse(formData.value);
|
await onSubmit(validatedData.cronExpression);
|
||||||
await onSubmit(validatedData.cronExpression);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof z.ZodError) {
|
|
||||||
alertStore.showAlert({
|
|
||||||
level: "error",
|
|
||||||
content: error.errors[0].message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -130,10 +130,9 @@ const handleSubmit = async () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const validatedData = userSchema.parse(formData.value);
|
const validatedData = userSchema.parse(formData.value);
|
||||||
await onSubmit(validatedData);
|
await onSubmit(validatedData);
|
||||||
updateFormData(undefined);
|
updateFormData(undefined);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ import useAlertStore from "@/composables/store/useAlertStore";
|
|||||||
import DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
import { Modal, type ModalInterface, initFlowbite } from "flowbite";
|
import { Modal, type ModalInterface, initFlowbite } from "flowbite";
|
||||||
import { marked } from "marked";
|
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 { z } from "zod";
|
||||||
import Button from "../components/Button.vue";
|
import Button from "../components/Button.vue";
|
||||||
import UserUpsertModal from "../components/UserUpsertModal.vue";
|
import UserUpsertModal from "../components/UserUpsertModal.vue";
|
||||||
@@ -193,23 +193,12 @@ const chatByMode = async (message: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSendClick = async () => {
|
const handleSendClick = async () => {
|
||||||
try {
|
scrollToBottom();
|
||||||
scrollToBottom();
|
const validInputMessage = z
|
||||||
const validInputMessage = z
|
.string({ message: "消息不能为空" })
|
||||||
.string({ message: "消息不能为空" })
|
.min(1, "消息不能为空")
|
||||||
.min(1, "消息不能为空")
|
.parse(inputMessage.value);
|
||||||
.parse(inputMessage.value);
|
await chatByMode(validInputMessage);
|
||||||
await chatByMode(validInputMessage);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof z.ZodError) {
|
|
||||||
alertStore.showAlert({
|
|
||||||
level: "error",
|
|
||||||
content: error.errors[0].message,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|||||||
@@ -45,26 +45,19 @@ const handleLogin = async () => {
|
|||||||
password: z.string().min(1, "密码至少1个字符"),
|
password: z.string().min(1, "密码至少1个字符"),
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
const validatedData = userSchema.parse({
|
||||||
const validatedData = userSchema.parse({
|
username: username.value,
|
||||||
username: username.value,
|
password: password.value,
|
||||||
password: password.value,
|
});
|
||||||
});
|
await userAuth.signIn(validatedData.username, validatedData.password);
|
||||||
await userAuth.signIn(validatedData.username, validatedData.password);
|
alertStore.showAlert({
|
||||||
alertStore.showAlert({
|
level: "success",
|
||||||
level: "success",
|
content: "登录成功",
|
||||||
content: "登录成功",
|
});
|
||||||
});
|
const redirectPath =
|
||||||
const redirectPath =
|
(route.query.redirect as string) ||
|
||||||
(route.query.redirect as string) ||
|
`${RoutePath.DASHBOARD}/${RoutePath.USERVIEW}`;
|
||||||
`${RoutePath.DASHBOARD}/${RoutePath.USERVIEW}`;
|
router.push(redirectPath);
|
||||||
router.push(redirectPath);
|
|
||||||
} catch (e) {
|
|
||||||
alertStore.showAlert({
|
|
||||||
level: "error",
|
|
||||||
content: e instanceof z.ZodError ? e.errors[0].message : "账号或密码错误",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
@@ -78,47 +78,38 @@ onMounted(() => {
|
|||||||
|
|
||||||
const handleUpdateClick = async () => {
|
const handleUpdateClick = async () => {
|
||||||
let validatedData = undefined;
|
let validatedData = undefined;
|
||||||
try {
|
|
||||||
validatedData = z
|
validatedData = z
|
||||||
.object({
|
.object({
|
||||||
username: z
|
username: z
|
||||||
.string({
|
.string({
|
||||||
message: "用户名不能为空",
|
message: "用户名不能为空",
|
||||||
})
|
})
|
||||||
.min(4, "用户名长度不能小于4个字符"),
|
.min(4, "用户名长度不能小于4个字符"),
|
||||||
password: z
|
password: z
|
||||||
.string()
|
.string()
|
||||||
.min(5, "密码长度不能小于5个字符")
|
.min(5, "密码长度不能小于5个字符")
|
||||||
.optional()
|
.optional()
|
||||||
.nullable(),
|
.nullable(),
|
||||||
confirmPassword: z.string().optional().nullable(),
|
confirmPassword: z.string().optional().nullable(),
|
||||||
enable: z.boolean({
|
enable: z.boolean({
|
||||||
message: "状态不能为空",
|
message: "状态不能为空",
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.refine(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
if (data.password) {
|
if (data.password) {
|
||||||
return data.password === data.confirmPassword;
|
return data.password === data.confirmPassword;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
{ message: "密码输入不一致。" },
|
{ message: "密码输入不一致。" },
|
||||||
)
|
)
|
||||||
.parse(userForm.value);
|
.parse(userForm.value);
|
||||||
await upsertCurrentUser(validatedData);
|
await upsertCurrentUser(validatedData);
|
||||||
alertStore.showAlert({
|
alertStore.showAlert({
|
||||||
content: "操作成功",
|
content: "操作成功",
|
||||||
level: "success",
|
level: "success",
|
||||||
});
|
});
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof z.ZodError) {
|
|
||||||
alertStore.showAlert({
|
|
||||||
level: "error",
|
|
||||||
content: error.errors[0].message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user