diff --git a/package.json b/package.json index a19c2f2..8fc2d3c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lanhu-admin", - "version": "1.4.0", + "version": "1.5.0", "private": true, "scripts": { "dev": "next dev -H 0.0.0.0 -p 3001 --turbopack", diff --git a/src/actions/product.ts b/src/actions/product.ts index 5c96cfc..26f6807 100644 --- a/src/actions/product.ts +++ b/src/actions/product.ts @@ -45,6 +45,7 @@ export async function updateProductSku(data: { price?: string discount_id?: number | null price_min?: string + count_min?: number | null }) { return callByUser("/api/admin/product/sku/update", { id: data.id, @@ -53,6 +54,7 @@ export async function updateProductSku(data: { price: data.price, discount_id: data.discount_id, price_min: data.price_min, + count_min: data.count_min, }) } diff --git a/src/app/(root)/gateway/page.tsx b/src/app/(root)/gateway/page.tsx index 549dee1..c633af2 100644 --- a/src/app/(root)/gateway/page.tsx +++ b/src/app/(root)/gateway/page.tsx @@ -1,33 +1,22 @@ "use client" +import { format } from "date-fns" import { Suspense, useState } from "react" import { toast } from "sonner" -import { deletegateway, getGatewayPage } from "@/actions/gateway" +import { getGatewayPage } from "@/actions/gateway" +import { Auth } from "@/components/auth" import { DataTable, useDataTable } from "@/components/data-table" import { Page } from "@/components/page" -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, - AlertDialogTrigger, -} from "@/components/ui/alert-dialog" import { Button } from "@/components/ui/button" +import { ScopeProxyWrite } from "@/lib/scopes" import type { Gateway } from "@/models/gateway" import CreatePage from "./create" -import { format } from "date-fns" -import { ScopeProxyWrite } from "@/lib/scopes" -import { Auth } from "@/components/auth" export default function GatewayPage() { const [loading, setLoading] = useState(false) const table = useDataTable((page, size) => getGatewayPage({ page, size })) - + return ( @@ -42,12 +31,11 @@ export default function GatewayPage() { {...table} status={loading ? "load" : "done"} columns={[ - // { header: "id", accessorKey: "id" }, { header: "域名", accessorKey: "host", }, - { header: "IP地址", accessorKey: "ip" }, + { header: "IP地址", accessorKey: "ip" }, { header: "MAC地址", accessorKey: "mac", @@ -74,7 +62,10 @@ export default function GatewayPage() { header: "操作", cell: ({ row }) => (
- + +
), }, @@ -84,53 +75,3 @@ export default function GatewayPage() {
) } - -function Delete({ - gateway, - onSuccess, -}: { - gateway: Gateway - onSuccess?: () => void -}) { - const [loading, setLoading] = useState(false) - const handleConfirm = async () => { - setLoading(true) - try { - const resp = await deletegateway(gateway.id) - if (resp.success) { - toast.success("删除成功") - onSuccess?.() - } else { - toast.error(resp.message ?? "删除失败") - } - } catch (error) { - const message = error instanceof Error ? error.message : error - toast.error(`接口请求错误: ${message}`) - } finally { - setLoading(false) - } - } - return ( - - - - - - - 确认删除 - - 确定要删除「{gateway.host || gateway.ip}」吗?此操作不可撤销。 - - - - 取消 - - 删除 - - - - - ) -} diff --git a/src/app/(root)/product/create.tsx b/src/app/(root)/product/create.tsx index 30dd67e..79cb610 100644 --- a/src/app/(root)/product/create.tsx +++ b/src/app/(root)/product/create.tsx @@ -46,6 +46,7 @@ const schema = z "请输入有效的正数单价", ), discount_id: z.string().optional(), + count_min: z.string().min(1, "请输入最低购买数量"), price_min: z .string() .min(1, "请输入最低价格") @@ -177,19 +178,6 @@ export function CreateProductSku(props: { placeholder="请输入单价" {...field} aria-invalid={fieldState.invalid} - // onChange={(e: React.ChangeEvent) => { - // let value = e.target.value - // value = value.replace(/[^\d.]/g, "") - // const dotCount = (value.match(/\./g) || []).length - // if (dotCount > 1) { - // value = value.slice(0, value.lastIndexOf(".")) - // } - // if (value.includes(".")) { - // const [int, dec] = value.split(".") - // value = `${int}.${dec.slice(0, 2)}` - // } - // field.onChange(value) - // }} /> {fieldState.invalid && ( @@ -208,19 +196,6 @@ export function CreateProductSku(props: { placeholder="请输入最低价格" {...field} aria-invalid={fieldState.invalid} - // onChange={(e: React.ChangeEvent) => { - // let value = e.target.value - // value = value.replace(/[^\d.]/g, "") - // const dotCount = (value.match(/\./g) || []).length - // if (dotCount > 1) { - // value = value.slice(0, value.lastIndexOf(".")) - // } - // if (value.includes(".")) { - // const [int, dec] = value.split(".") - // value = `${int}.${dec.slice(0, 2)}` - // } - // field.onChange(value) - // }} /> {fieldState.invalid && ( @@ -228,7 +203,26 @@ export function CreateProductSku(props: { )} /> - + ( + + + 最低购买数量 + + + {fieldState.invalid && ( + + )} + + )} + /> format(row.created_at, "yyyy-MM-dd HH:mm"), diff --git a/src/app/(root)/product/update.tsx b/src/app/(root)/product/update.tsx index ff03011..6b7142f 100644 --- a/src/app/(root)/product/update.tsx +++ b/src/app/(root)/product/update.tsx @@ -46,6 +46,16 @@ const schema = z "请输入有效的正数单价", ), discount_id: z.string().optional(), + count_min: z + .string() + .min(1, "请输入最低购买数量") + .refine( + v => + !Number.isNaN(Number(v)) && + Number.isInteger(Number(v)) && + Number(v) > 0, + "请输入有效的正整数", + ), price_min: z .string() .min(1, "请输入最低价格") @@ -82,6 +92,7 @@ export function UpdateProductSku(props: { price: props.sku.price, discount_id: props.sku.discount ? String(props.sku.discount.id) : "", price_min: props.sku.price_min ?? "", + count_min: String(props.sku.count_min), }, }) @@ -107,7 +118,9 @@ export function UpdateProductSku(props: { ? Number(data.discount_id) : null, price_min: data.price_min, + count_min: Number(data.count_min), }) + console.log(resp, "resp") if (resp.success) { toast.success("套餐修改成功") @@ -130,6 +143,7 @@ export function UpdateProductSku(props: { price: props.sku.price, discount_id: props.sku.discount ? String(props.sku.discount.id) : "", price_min: props.sku.price_min ?? "", + count_min: props.sku.count_min ? String(props.sku.count_min) : "", }) } setOpen(value) @@ -180,19 +194,6 @@ export function UpdateProductSku(props: { placeholder="请输入单价" {...field} aria-invalid={fieldState.invalid} - // onChange={(e: React.ChangeEvent) => { - // let value = e.target.value - // value = value.replace(/[^\d.]/g, "") - // const dotCount = (value.match(/\./g) || []).length - // if (dotCount > 1) { - // value = value.slice(0, value.lastIndexOf(".")) - // } - // if (value.includes(".")) { - // const [int, dec] = value.split(".") - // value = `${int}.${dec.slice(0, 2)}` - // } - // field.onChange(value) - // }} /> {fieldState.invalid && ( @@ -205,25 +206,34 @@ export function UpdateProductSku(props: { name="price_min" render={({ field, fieldState }) => ( - 最低价格 + + 最低价格 + ) => { - // let value = e.target.value - // value = value.replace(/[^\d.]/g, "") - // const dotCount = (value.match(/\./g) || []).length - // if (dotCount > 1) { - // value = value.slice(0, value.lastIndexOf(".")) - // } - // if (value.includes(".")) { - // const [int, dec] = value.split(".") - // value = `${int}.${dec.slice(0, 2)}` - // } - // field.onChange(value) - // }} + /> + {fieldState.invalid && ( + + )} + + )} + /> + ( + + + 最低购买数量 + + {fieldState.invalid && ( diff --git a/src/models/product_sku.ts b/src/models/product_sku.ts index d08344b..2db9dec 100644 --- a/src/models/product_sku.ts +++ b/src/models/product_sku.ts @@ -11,4 +11,6 @@ export type ProductSku = Model & { product?: Product price_min?: string discount?: ProductDiscount + sort: number + count_min: number }