调整首页页面布局

This commit is contained in:
Eamon
2026-06-01 16:02:27 +08:00
parent e0bdcabbfe
commit 9f74483345
11 changed files with 967 additions and 553 deletions

View File

@@ -25,42 +25,47 @@ import {
} from "@/components/ui/select"
import type { Coupon } from "@/models/coupon"
const schema = z.object({
name: z.string().min(1, "请输入优惠券名称"),
amount: z.string()
.min(1, "请输入优惠券金额")
.regex(/^\d+(\.\d+)?$/, "请输入有效的金额数字")
.refine(val => Number(val) > 0, "优惠券金额必须大于0"),
count: z.string()
.min(1, "请输入优惠券数量")
.regex(/^\d+$/, "请输入正整数")
.refine(val => Number(val) >= 1, "优惠券数量至少为1"),
min_amount: z.string()
.min(1, "请输入最低消费金额")
.regex(/^\d+(\.\d+)?$/, "请输入有效的金额数字")
.refine(val => Number(val) >= 0, "最低消费金额不能为负数"),
expire_at: z.string().optional(),
expire_type: z.string().min(1, "请选择过期类型"),
expire_in: z.string().optional(),
status:z.string().optional()
}).superRefine((data, ctx) => {
const expireType = Number(data.expire_type);
if (!data.expire_type) return;
if (expireType === 1 && !data.expire_at) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "请选择过期时间",
path: ["expire_at"]
});
}
if (expireType === 2 && !data.expire_in) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "请输入过期时长天数",
path: ["expire_in"]
});
}
})
const schema = z
.object({
name: z.string().min(1, "请输入优惠券名称"),
amount: z
.string()
.min(1, "请输入优惠券金额")
.regex(/^\d+(\.\d+)?$/, "请输入有效的金额数字")
.refine(val => Number(val) > 0, "优惠券金额必须大于0"),
count: z
.string()
.min(1, "请输入优惠券数量")
.regex(/^\d+$/, "请输入正整数")
.refine(val => Number(val) >= 1, "优惠券数量至少为1"),
min_amount: z
.string()
.min(1, "请输入最低消费金额")
.regex(/^\d+(\.\d+)?$/, "请输入有效的金额数字")
.refine(val => Number(val) >= 0, "最低消费金额不能为负数"),
expire_at: z.string().optional(),
expire_type: z.string().min(1, "请选择过期类型"),
expire_in: z.string().optional(),
status: z.string().optional(),
})
.superRefine((data, ctx) => {
const expireType = Number(data.expire_type)
if (!data.expire_type) return
if (expireType === 1 && !data.expire_at) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "请选择过期时间",
path: ["expire_at"],
})
}
if (expireType === 2 && !data.expire_in) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "请输入过期时长天数",
path: ["expire_in"],
})
}
})
export function UpdateCoupon(props: {
coupon: Coupon
@@ -88,7 +93,7 @@ export function UpdateCoupon(props: {
const watchExpireType = watch("expire_type")
const onSubmit = async (data: z.infer<typeof schema>) => {
try {
const expireType = Number(data.expire_type)
const expireType = Number(data.expire_type)
const payload = {
id: props.coupon.id,
name: data.name,
@@ -100,7 +105,7 @@ export function UpdateCoupon(props: {
expire_at: data.expire_at ? new Date(data.expire_at) : undefined,
expire_in: expireType === 2 ? Number(data.expire_in) : undefined,
}
const resp = await updateCoupon(payload)
const resp = await updateCoupon(payload)
if (resp.success) {
toast.success("优惠券修改成功")
props.onSuccess?.()
@@ -119,7 +124,7 @@ export function UpdateCoupon(props: {
reset({
name: props.coupon.name,
count: String(props.coupon.count),
amount: String(props.coupon.amount ),
amount: String(props.coupon.amount),
min_amount: String(props.coupon.min_amount),
expire_at: props.coupon.expire_at
? new Date(props.coupon.expire_at).toISOString().split("T")[0]
@@ -245,7 +250,7 @@ export function UpdateCoupon(props: {
</div>
)}
/>
{watchExpireType === "1" && (
{watchExpireType === "1" && (
<Controller
control={control}
name="expire_at"
@@ -271,13 +276,15 @@ export function UpdateCoupon(props: {
name="expire_in"
render={({ field, fieldState }) => (
<div className="flex items-start gap-4">
<FieldLabel className="w-28 pt-2">:</FieldLabel>
<FieldLabel className="w-28 pt-2">
:
</FieldLabel>
<div className="flex-1">
<Input
type="number"
<Input
type="number"
min="0"
placeholder="请输入过期天数"
{...field}
{...field}
/>
<FieldError>{fieldState.error?.message}</FieldError>
</div>