Compare commits
9 Commits
a9e9ddd04b
...
5d9d3c844e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d9d3c844e | ||
|
|
545435d095 | ||
|
|
be03cf6440 | ||
|
|
7479b83f13 | ||
|
|
3387056ea9 | ||
|
|
8c26d81846 | ||
|
|
f72b6bddd0 | ||
|
|
76d2d480ed | ||
|
|
453d687c4a |
@@ -5,18 +5,18 @@
|
|||||||
"formatter": { "language_server": { "name": "biome" } },
|
"formatter": { "language_server": { "name": "biome" } },
|
||||||
"code_actions_on_format": {
|
"code_actions_on_format": {
|
||||||
"source.fixAll.biome": true,
|
"source.fixAll.biome": true,
|
||||||
"source.organizeImports.biome": true,
|
"source.organizeImports.biome": true
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
"TSX": {
|
"TSX": {
|
||||||
"formatter": { "language_server": { "name": "biome" } },
|
"formatter": { "language_server": { "name": "biome" } },
|
||||||
"code_actions_on_format": {
|
"code_actions_on_format": {
|
||||||
"source.fixAll.biome": true,
|
"source.fixAll.biome": true,
|
||||||
"source.organizeImports.biome": true,
|
"source.organizeImports.biome": true
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
"JSON": {
|
"JSON": {
|
||||||
"formatter": { "language_server": { "name": "biome" } },
|
"formatter": { "language_server": { "name": "biome" } }
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,15 @@
|
|||||||
"recommended": true,
|
"recommended": true,
|
||||||
"style": {
|
"style": {
|
||||||
"useNodejsImportProtocol": "off"
|
"useNodejsImportProtocol": "off"
|
||||||
|
},
|
||||||
|
"a11y": {
|
||||||
|
"useButtonType": "off",
|
||||||
|
"noLabelWithoutControl": "off",
|
||||||
|
"noSvgWithoutTitle": "off",
|
||||||
|
"useSemanticElements": "off"
|
||||||
|
},
|
||||||
|
"suspicious": {
|
||||||
|
"noArrayIndexKey": "off"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const config = {
|
const config = {
|
||||||
plugins: ["@tailwindcss/postcss"],
|
plugins: ["@tailwindcss/postcss"],
|
||||||
};
|
}
|
||||||
|
|
||||||
export default config;
|
export default config
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import type { PageRecord } from "@/lib/api"
|
|||||||
import type { Admin } from "@/models/admin"
|
import type { Admin } from "@/models/admin"
|
||||||
import { callByUser } from "./base"
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
|
export async function getAllAdmin() {
|
||||||
|
return callByUser<Admin[]>("/api/admin/admin/all")
|
||||||
|
}
|
||||||
|
|
||||||
export async function getPageAdmin(params: { page: number; size: number }) {
|
export async function getPageAdmin(params: { page: number; size: number }) {
|
||||||
return callByUser<PageRecord<Admin>>("/api/admin/admin/page", params)
|
return callByUser<PageRecord<Admin>>("/api/admin/admin/page", params)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,17 @@ import type { PageRecord } from "@/lib/api"
|
|||||||
import type { Batch } from "@/models/batch"
|
import type { Batch } from "@/models/batch"
|
||||||
import { callByUser } from "./base"
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
export async function getPageBatch(params: { page: number; size: number }) {
|
export async function getPageBatch(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
batch_no?: string
|
||||||
|
prov?: string
|
||||||
|
city?: string
|
||||||
|
isp?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}) {
|
||||||
return callByUser<PageRecord<Batch>>("/api/admin/batch/page", params)
|
return callByUser<PageRecord<Batch>>("/api/admin/batch/page", params)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,28 @@
|
|||||||
import type { PageRecord } from "@/lib/api"
|
import type { PageRecord } from "@/lib/api"
|
||||||
|
import { ProductCode } from "@/lib/base"
|
||||||
import type { Billing } from "@/models/billing"
|
import type { Billing } from "@/models/billing"
|
||||||
|
import type { ProductSku } from "@/models/product_sku"
|
||||||
import { callByUser } from "./base"
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
export async function getPageBill(params: { page: number; size: number }) {
|
export async function getPageBill(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
bill_no?: string
|
||||||
|
user_phone?: string
|
||||||
|
trade_inner_no?: string
|
||||||
|
resource_no?: string
|
||||||
|
sku_code?: string
|
||||||
|
product_code?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}) {
|
||||||
return callByUser<PageRecord<Billing>>("/api/admin/bill/page", params)
|
return callByUser<PageRecord<Billing>>("/api/admin/bill/page", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getSkuList(params: { product_code?: ProductCode }) {
|
||||||
|
const requestParams = {
|
||||||
|
...params,
|
||||||
|
...(params.product_code === ProductCode.All && { product_code: undefined }),
|
||||||
|
}
|
||||||
|
return callByUser<ProductSku[]>("/api/admin/product/sku/all", requestParams)
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,17 @@ import type { PageRecord } from "@/lib/api"
|
|||||||
import type { Channel } from "@/models/channel"
|
import type { Channel } from "@/models/channel"
|
||||||
import { callByUser } from "./base"
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
export async function getPageChannel(params: { page: number; size: number }) {
|
export async function getPageChannel(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
batch_no?: string
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
proxy_port?: number
|
||||||
|
proxy_host?: string
|
||||||
|
node_ip?: string
|
||||||
|
expired_at_start?: Date
|
||||||
|
expired_at_end?: Date
|
||||||
|
}) {
|
||||||
return callByUser<PageRecord<Channel>>("/api/admin/channel/page", params)
|
return callByUser<PageRecord<Channel>>("/api/admin/channel/page", params)
|
||||||
}
|
}
|
||||||
|
|||||||
34
src/actions/coupon.ts
Normal file
34
src/actions/coupon.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import type { PageRecord } from "@/lib/api"
|
||||||
|
import type { Coupon } from "@/models/coupon"
|
||||||
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
|
export async function getPagCoupon(params: { page: number; size: number }) {
|
||||||
|
return callByUser<PageRecord<Coupon>>("/api/admin/coupon/page", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createCoupon(data: {
|
||||||
|
code: string
|
||||||
|
amount: number
|
||||||
|
remark?: string
|
||||||
|
min_amount?: number
|
||||||
|
expire_at?: Date
|
||||||
|
}) {
|
||||||
|
return callByUser<Coupon>("/api/admin/coupon/create", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateCoupon(data: {
|
||||||
|
code: string
|
||||||
|
amount: number
|
||||||
|
remark?: string
|
||||||
|
min_amount?: number
|
||||||
|
expire_at?: Date
|
||||||
|
status?: number
|
||||||
|
}) {
|
||||||
|
return callByUser<Coupon>("/api/admin/coupon/update", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteCoupon(id: number) {
|
||||||
|
return callByUser<Coupon>("/api/admin/coupon/remove", {
|
||||||
|
id,
|
||||||
|
})
|
||||||
|
}
|
||||||
40
src/actions/cust.ts
Normal file
40
src/actions/cust.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import type { PageRecord } from "@/lib/api"
|
||||||
|
import type { Cust } from "@/models/cust"
|
||||||
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
|
export async function getPageCusts(params: { page: number; size: number }) {
|
||||||
|
return callByUser<PageRecord<Cust>>("/api/admin/user/page", params)
|
||||||
|
}
|
||||||
|
export async function updateCust(data: {
|
||||||
|
id: number
|
||||||
|
username?: string
|
||||||
|
email?: string
|
||||||
|
password?: string
|
||||||
|
admin_id?: number
|
||||||
|
discount_id?: number
|
||||||
|
status?: number
|
||||||
|
contact_qq?: string
|
||||||
|
contact_wechat?: string
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Cust>>("/api/admin/user/update", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createCust(data: {
|
||||||
|
phone: string
|
||||||
|
password?: string
|
||||||
|
username?: string
|
||||||
|
admin_id?: number
|
||||||
|
discount_id?: number
|
||||||
|
email?: string
|
||||||
|
name?: string
|
||||||
|
avatar?: string
|
||||||
|
status?: number
|
||||||
|
contact_qq?: string
|
||||||
|
contact_wechat?: string
|
||||||
|
}) {
|
||||||
|
return callByUser<PageRecord<Cust>>("/api/admin/user/create", data)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getBalance(params: { user_id: number; balance: string }) {
|
||||||
|
return callByUser<PageRecord<Cust>>("/api/admin/user/update/balance", params)
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import type { ProductDiscount } from "@/models/product_discount"
|
|||||||
import { callByUser } from "./base"
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
export async function getAllProductDiscount() {
|
export async function getAllProductDiscount() {
|
||||||
return callByUser<ProductDiscount[]>("/api/admin/product/discount/all")
|
return callByUser<ProductDiscount[]>("/api/admin/discount/all")
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPageProductDiscount(params: {
|
export async function getPageProductDiscount(params: {
|
||||||
@@ -13,7 +13,7 @@ export async function getPageProductDiscount(params: {
|
|||||||
size: number
|
size: number
|
||||||
}) {
|
}) {
|
||||||
return callByUser<PageRecord<ProductDiscount>>(
|
return callByUser<PageRecord<ProductDiscount>>(
|
||||||
"/api/admin/product/discount/page",
|
"/api/admin/discount/page",
|
||||||
params,
|
params,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ export async function createProductDiscount(data: {
|
|||||||
name: string
|
name: string
|
||||||
discount: string
|
discount: string
|
||||||
}) {
|
}) {
|
||||||
return callByUser<ProductDiscount>("/api/admin/product/discount/create", {
|
return callByUser<ProductDiscount>("/api/admin/discount/create", {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
discount: Number(data.discount),
|
discount: Number(data.discount),
|
||||||
})
|
})
|
||||||
@@ -33,7 +33,7 @@ export async function updateProductDiscount(data: {
|
|||||||
name?: string
|
name?: string
|
||||||
discount?: string
|
discount?: string
|
||||||
}) {
|
}) {
|
||||||
return callByUser<ProductDiscount>("/api/admin/product/discount/update", {
|
return callByUser<ProductDiscount>("/api/admin/discount/update", {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
discount: data.discount ? Number(data.discount) : undefined,
|
discount: data.discount ? Number(data.discount) : undefined,
|
||||||
@@ -41,7 +41,7 @@ export async function updateProductDiscount(data: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteProductDiscount(id: number) {
|
export async function deleteProductDiscount(id: number) {
|
||||||
return callByUser<ProductDiscount>("/api/admin/product/discount/remove", {
|
return callByUser<ProductDiscount>("/api/admin/discount/remove", {
|
||||||
id,
|
id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,32 @@ import type { PageRecord } from "@/lib/api"
|
|||||||
import type { Resources } from "@/models/resources"
|
import type { Resources } from "@/models/resources"
|
||||||
import { callByUser } from "./base"
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
export async function listResourceLong(params: { page: number; size: number }) {
|
export interface ResourceListParams {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
active?: boolean
|
||||||
|
mode?: number
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
expired?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listResourceLong(params: ResourceListParams) {
|
||||||
return callByUser<PageRecord<Resources>>(
|
return callByUser<PageRecord<Resources>>(
|
||||||
"/api/admin/resource/long/page",
|
"/api/admin/resource/long/page",
|
||||||
params,
|
params,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listResourceShort(params: {
|
export async function listResourceShort(params: ResourceListParams) {
|
||||||
page: number
|
|
||||||
size: number
|
|
||||||
}) {
|
|
||||||
return callByUser<PageRecord<Resources>>(
|
return callByUser<PageRecord<Resources>>(
|
||||||
"/api/admin/resource/short/page",
|
"/api/admin/resource/short/page",
|
||||||
params,
|
params,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateResource(data: { id: number; active?: boolean }) {
|
||||||
|
return callByUser<Resources>("/api/admin/resource/update", data)
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,16 @@ import type { PageRecord } from "@/lib/api"
|
|||||||
import type { Trade } from "@/models/trade"
|
import type { Trade } from "@/models/trade"
|
||||||
import { callByUser } from "./base"
|
import { callByUser } from "./base"
|
||||||
|
|
||||||
export async function getPageTrade(params: { page: number; size: number }) {
|
export async function getPageTrade(params: {
|
||||||
|
page: number
|
||||||
|
size: number
|
||||||
|
user_phone?: string
|
||||||
|
inner_no?: string
|
||||||
|
method?: number
|
||||||
|
platform?: number
|
||||||
|
status?: number
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}) {
|
||||||
return callByUser<PageRecord<Trade>>("/api/admin/trade/page", params)
|
return callByUser<PageRecord<Trade>>("/api/admin/trade/page", params)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,19 @@ export async function getPageUsers(params: { page: number; size: number }) {
|
|||||||
return callByUser<PageRecord<User>>("/api/admin/user/page", params)
|
return callByUser<PageRecord<User>>("/api/admin/user/page", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function bindAdmin(params: { id: number }) {
|
export async function bindAdmin(params: {
|
||||||
|
id: number
|
||||||
|
account?: string
|
||||||
|
name?: string
|
||||||
|
identified?: boolean
|
||||||
|
enabled?: boolean
|
||||||
|
assigned?: boolean
|
||||||
|
}) {
|
||||||
return callByUser("/api/admin/user/bind", {
|
return callByUser("/api/admin/user/bind", {
|
||||||
user_id: params.id,
|
user_id: params.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getPageUser(params: object) {
|
||||||
|
return callByUser<User>("/api/admin/user/get", params)
|
||||||
|
}
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ export default function AdminPage() {
|
|||||||
cell: ({ row }) => <RolesCell roles={row.original.roles ?? []} />,
|
cell: ({ row }) => <RolesCell roles={row.original.roles ?? []} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
|
|||||||
@@ -102,10 +102,17 @@ export default function Appbar(props: { admin: Admin }) {
|
|||||||
nodes: "节点列表",
|
nodes: "节点列表",
|
||||||
trade: "交易明细",
|
trade: "交易明细",
|
||||||
billing: "账单详情",
|
billing: "账单详情",
|
||||||
|
cust: "客户管理",
|
||||||
|
product: "产品管理",
|
||||||
resources: "套餐管理",
|
resources: "套餐管理",
|
||||||
batch: "使用记录",
|
batch: "提取记录",
|
||||||
channel: "IP管理",
|
channel: "IP管理",
|
||||||
pools: "IP池管理",
|
pools: "IP池管理",
|
||||||
|
coupon: "优惠券",
|
||||||
|
admin: "管理员",
|
||||||
|
permissions: "权限列表",
|
||||||
|
discount: "折扣管理",
|
||||||
|
statistics: "数据统计",
|
||||||
}
|
}
|
||||||
|
|
||||||
return labels[path] || path
|
return labels[path] || path
|
||||||
|
|||||||
@@ -1,36 +1,276 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
import { Suspense } from "react"
|
import { Suspense, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { z } from "zod"
|
||||||
import { getPageBatch } from "@/actions/batch"
|
import { getPageBatch } from "@/actions/batch"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
import type { Batch } from "@/models/batch"
|
import type { Batch } from "@/models/batch"
|
||||||
|
|
||||||
|
type APIFilterParams = {
|
||||||
|
phone?: string
|
||||||
|
batch_no?: string
|
||||||
|
resource_no?: string
|
||||||
|
prov?: string
|
||||||
|
city?: string
|
||||||
|
isp?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
user_phone: z.string().optional(),
|
||||||
|
resource_no: z.string().optional(),
|
||||||
|
batch_no: z.string().optional(),
|
||||||
|
prov: z.string().optional(),
|
||||||
|
city: z.string().optional(),
|
||||||
|
isp: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: z.string().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.created_at_start && data.created_at_end) {
|
||||||
|
const start = new Date(data.created_at_start)
|
||||||
|
const end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
if (end < start) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "结束时间不能早于开始时间",
|
||||||
|
path: ["created_at_end"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
type FilterSchema = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
export default function BatchPage() {
|
export default function BatchPage() {
|
||||||
|
const [filters, setFilters] = useState<APIFilterParams>({})
|
||||||
|
|
||||||
|
const { control, handleSubmit, reset } = useForm<FilterSchema>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
user_phone: "",
|
||||||
|
batch_no: "",
|
||||||
|
prov: "",
|
||||||
|
city: "",
|
||||||
|
isp: "all",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const table = useDataTable<Batch>((page, size) =>
|
const table = useDataTable<Batch>((page, size) =>
|
||||||
getPageBatch({ page, size }),
|
getPageBatch({ page, size, ...filters }),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: APIFilterParams = {}
|
||||||
|
if (data.user_phone?.trim()) result.phone = data.user_phone.trim()
|
||||||
|
if (data.batch_no?.trim()) result.batch_no = data.batch_no.trim()
|
||||||
|
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
||||||
|
if (data.prov?.trim()) result.prov = data.prov.trim()
|
||||||
|
if (data.city?.trim()) result.city = data.city.trim()
|
||||||
|
if (data.isp && data.isp !== "all") result.isp = data.isp
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<div>Loading...</div>}>
|
<div className="space-y-3">
|
||||||
<DataTable<Batch>
|
{/* 筛选表单 */}
|
||||||
{...table}
|
<form onSubmit={onFilter} className="bg-white p-4 rounded-lg">
|
||||||
columns={[
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
{ header: "ID", accessorKey: "id" },
|
<Controller
|
||||||
{ header: "批次号", accessorKey: "batch_no" },
|
name="batch_no"
|
||||||
{ header: "省份", accessorKey: "prov" },
|
control={control}
|
||||||
{ header: "城市", accessorKey: "city" },
|
render={({ field, fieldState }) => (
|
||||||
{ header: "提取IP", accessorKey: "ip" },
|
<Field
|
||||||
{ header: "运营商", accessorKey: "isp" },
|
data-invalid={fieldState.invalid}
|
||||||
{ header: "提取数量", accessorKey: "count" },
|
className="w-40 flex-none"
|
||||||
{ header: "资源数量", accessorKey: "resource_id" },
|
>
|
||||||
{
|
<FieldLabel>批次号</FieldLabel>
|
||||||
header: "提取时间",
|
<Input {...field} placeholder="请输入批次号" />
|
||||||
accessorKey: "time",
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
cell: ({ row }) =>
|
</Field>
|
||||||
format(new Date(row.original.time), "yyyy-MM-dd HH:mm"),
|
)}
|
||||||
},
|
/>
|
||||||
]}
|
<Controller
|
||||||
/>
|
name="resource_no"
|
||||||
</Suspense>
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>套餐号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入套餐号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="user_phone"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>会员号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入会员号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="prov"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-32 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>省份</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入省份" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="city"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-32 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>城市</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入城市" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="isp"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-32">
|
||||||
|
<FieldLabel>运营商</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="1">电信</SelectItem>
|
||||||
|
<SelectItem value="2">联通</SelectItem>
|
||||||
|
<SelectItem value="3">移动</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="created_at_start"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="created_at_end"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
|
<Button type="submit">筛选</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense fallback={<div>Loading...</div>}>
|
||||||
|
<DataTable<Batch>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{ header: "ID", accessorKey: "id" },
|
||||||
|
{
|
||||||
|
header: "会员号",
|
||||||
|
accessorFn: row => row.user?.phone || "-",
|
||||||
|
},
|
||||||
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
|
{ header: "批次号", accessorKey: "batch_no" },
|
||||||
|
{ header: "省份", accessorKey: "prov" },
|
||||||
|
{ header: "城市", accessorKey: "city" },
|
||||||
|
{ header: "提取IP", accessorKey: "ip" },
|
||||||
|
{ header: "运营商", accessorKey: "isp" },
|
||||||
|
{ header: "提取数量", accessorKey: "count" },
|
||||||
|
{
|
||||||
|
header: "提取时间",
|
||||||
|
accessorKey: "time",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.time), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,95 +1,460 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
import { CreditCard } from "lucide-react"
|
import { CreditCard, Wallet } from "lucide-react"
|
||||||
import { Suspense } from "react"
|
import { Suspense, useEffect, useState } from "react"
|
||||||
import { getPageBill } from "@/actions/bill"
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getPageBill, getSkuList } from "@/actions/bill"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import { ProductCode } from "@/lib/base"
|
||||||
import type { Billing } from "@/models/billing"
|
import type { Billing } from "@/models/billing"
|
||||||
|
|
||||||
|
type FilterValues = {
|
||||||
|
bill_no?: string
|
||||||
|
user_phone?: string
|
||||||
|
trade_inner_no?: string
|
||||||
|
resource_no?: string
|
||||||
|
sku_code?: string
|
||||||
|
product_code?: string
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
type SkuOption = {
|
||||||
|
resource_code: string
|
||||||
|
resource_name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
phone: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform(val => val?.trim()),
|
||||||
|
bill_no: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform(val => val?.trim()),
|
||||||
|
resource_no: z.string().optional(),
|
||||||
|
inner_no: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: z.string().optional(),
|
||||||
|
product_code: z.string().optional(),
|
||||||
|
sku_code: z.string().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.created_at_start && data.created_at_end) {
|
||||||
|
const start = new Date(data.created_at_start)
|
||||||
|
const end = new Date(data.created_at_end)
|
||||||
|
if (end < start) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "结束时间不能早于开始时间",
|
||||||
|
path: ["created_at_end"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
type FilterSchema = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
export default function BillingPage() {
|
export default function BillingPage() {
|
||||||
const table = useDataTable<Billing>((page, size) =>
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
getPageBill({ page, size }),
|
const [skuOptions, setSkuOptions] = useState<SkuOption[]>([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [skuProductCode, setSkuProductCode] = useState<ProductCode>(
|
||||||
|
ProductCode.All,
|
||||||
)
|
)
|
||||||
|
const { control, handleSubmit, reset } = useForm<FilterSchema>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
bill_no: "",
|
||||||
|
inner_no: "",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
phone: "",
|
||||||
|
resource_no: "",
|
||||||
|
sku_code: "all",
|
||||||
|
product_code: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setLoading(true)
|
||||||
|
getSkuList({
|
||||||
|
product_code: skuProductCode,
|
||||||
|
})
|
||||||
|
.then(resp => {
|
||||||
|
if (!resp.success) {
|
||||||
|
throw new Error(resp.message)
|
||||||
|
}
|
||||||
|
setSkuOptions(
|
||||||
|
resp.data.map(sku => ({
|
||||||
|
resource_code: sku.code,
|
||||||
|
resource_name: sku.name,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
console.error("获取套餐类型失败:", e)
|
||||||
|
toast.error(
|
||||||
|
`获取套餐类型失败:${e instanceof Error ? e.message : String(e)}`,
|
||||||
|
)
|
||||||
|
setSkuOptions([])
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setLoading(false)
|
||||||
|
})
|
||||||
|
}, [skuProductCode])
|
||||||
|
|
||||||
|
const table = useDataTable<Billing>((page, size) =>
|
||||||
|
getPageBill({ page, size, ...filters }),
|
||||||
|
)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterValues = {}
|
||||||
|
if (data.phone?.trim()) result.user_phone = data.phone.trim()
|
||||||
|
if (data.inner_no?.trim()) result.trade_inner_no = data.inner_no.trim()
|
||||||
|
if (data.bill_no?.trim()) result.bill_no = data.bill_no.trim()
|
||||||
|
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
||||||
|
if (data.product_code && data.product_code !== ProductCode.All) {
|
||||||
|
result.product_code = data.product_code
|
||||||
|
}
|
||||||
|
if (data.sku_code && data.sku_code !== "all") {
|
||||||
|
result.sku_code = data.sku_code
|
||||||
|
}
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<div className="space-y-3">
|
||||||
<DataTable<Billing>
|
<form onSubmit={onFilter} className="bg-white p-4">
|
||||||
{...table}
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
columns={[
|
<Controller
|
||||||
{ header: "ID", accessorKey: "id" },
|
name="phone"
|
||||||
{ header: "账单号", accessorKey: "bill_no" },
|
control={control}
|
||||||
{
|
render={({ field, fieldState }) => (
|
||||||
header: "账单详情",
|
<Field
|
||||||
accessorKey: "info",
|
data-invalid={fieldState.invalid}
|
||||||
cell: ({ row }) => {
|
className="w-40 flex-none"
|
||||||
const bill = row.original
|
>
|
||||||
|
<FieldLabel>会员号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入会员号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="resource_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>套餐号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入套餐号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="inner_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>订单号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入订单号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
return (
|
<Controller
|
||||||
<div className="flex items-center gap-2">
|
name="product_code"
|
||||||
{/* 类型展示 */}
|
control={control}
|
||||||
<div className="shrink-0">
|
render={({ field, fieldState }) => (
|
||||||
{bill.type === 1 && (
|
<Field
|
||||||
<div className="flex gap-2 items-center bg-orange-50 w-fit px-2 py-1 rounded-md">
|
data-invalid={fieldState.invalid}
|
||||||
<CreditCard size={16} />
|
className="w-32 flex-none"
|
||||||
<span>消费</span>
|
>
|
||||||
</div>
|
<FieldLabel>产品类型</FieldLabel>
|
||||||
)}
|
<Select
|
||||||
{bill.type === 2 && (
|
value={skuProductCode}
|
||||||
<div className="flex gap-2 items-center bg-green-50 w-fit px-2 py-1 rounded-md">
|
onValueChange={value => {
|
||||||
<CreditCard size={16} />
|
setSkuProductCode(value as ProductCode)
|
||||||
<span>退款</span>
|
field.onChange(value)
|
||||||
</div>
|
}}
|
||||||
)}
|
>
|
||||||
{bill.type === 3 && (
|
<SelectTrigger>
|
||||||
<div className="flex gap-2 items-center bg-blue-50 w-fit px-2 py-1 rounded-md">
|
<SelectValue
|
||||||
<CreditCard size={16} />
|
placeholder={"请选择"}
|
||||||
<span>充值</span>
|
defaultValue={
|
||||||
</div>
|
skuProductCode === ProductCode.All ? "全部" : ""
|
||||||
)}
|
}
|
||||||
|
/>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value={ProductCode.All}>全部</SelectItem>
|
||||||
|
<SelectItem value={ProductCode.Short}>短效</SelectItem>
|
||||||
|
<SelectItem value={ProductCode.Long}>长效</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="sku_code"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-32 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>套餐类型</FieldLabel>
|
||||||
|
<Select
|
||||||
|
value={loading ? undefined : field.value || "all"}
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder={loading ? "加载中..." : "全部"} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
{skuOptions.map(option => (
|
||||||
|
<SelectItem
|
||||||
|
key={option.resource_code}
|
||||||
|
value={option.resource_code}
|
||||||
|
>
|
||||||
|
{option.resource_name || option.resource_code}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="bill_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>账单号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入账单号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="created_at_start"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="created_at_end"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
|
<Button type="submit">筛选</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
reset()
|
||||||
|
setSkuProductCode(ProductCode.All)
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Billing>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{ header: "ID", accessorKey: "id" },
|
||||||
|
{ header: "会员号", accessorFn: row => row.user?.phone || "-" },
|
||||||
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
|
{
|
||||||
|
header: "账单详情",
|
||||||
|
accessorKey: "info",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const bill = row.original
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="shrink-0">
|
||||||
|
{bill.type === 1 && (
|
||||||
|
<div className="flex gap-2 items-center bg-orange-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>消费</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{bill.type === 2 && (
|
||||||
|
<div className="flex gap-2 items-center bg-green-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>退款</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{bill.type === 3 && (
|
||||||
|
<div className="flex gap-2 items-center bg-blue-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>充值</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm">{bill.info}</div>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "应付金额",
|
||||||
|
accessorKey: "amount",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const amount =
|
||||||
|
typeof row.original.amount === "string"
|
||||||
|
? parseFloat(row.original.amount)
|
||||||
|
: row.original.amount || 0
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
amount > 0 ? "text-green-500" : "text-orange-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
¥{amount.toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "实付金额",
|
||||||
|
accessorKey: "actual",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const actual =
|
||||||
|
typeof row.original.actual === "string"
|
||||||
|
? parseFloat(row.original.actual)
|
||||||
|
: row.original.actual || 0
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
actual > 0 ? "text-green-500" : "text-orange-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
¥{actual.toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ header: "账单号", accessorKey: "bill_no" },
|
||||||
|
{
|
||||||
|
header: "订单号",
|
||||||
|
accessorKey: "trade.inner_no",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const bill = row.original
|
||||||
|
|
||||||
{/* 账单详情 */}
|
return (
|
||||||
<div className="text-sm">{bill.info}</div>
|
<div className="flex items-center gap-2">
|
||||||
</div>
|
<div className="shrink-0 w-20">
|
||||||
)
|
{bill.trade?.acquirer === 1 && (
|
||||||
|
<div className="flex gap-2 items-center bg-blue-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>支付宝</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{bill.trade?.acquirer === 2 && (
|
||||||
|
<div className="flex gap-2 items-center bg-green-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>微信</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{bill.trade?.acquirer === 3 && (
|
||||||
|
<div className="flex gap-2 items-center bg-orange-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<CreditCard size={16} />
|
||||||
|
<span>银联</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{!bill.trade?.acquirer && (
|
||||||
|
<div className="flex gap-2 items-center bg-red-50 w-full px-2 py-1 rounded-md">
|
||||||
|
<Wallet size={16} />
|
||||||
|
<span>余额</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm">{bill.trade?.inner_no}</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
header: "创建时间",
|
||||||
header: "支付信息",
|
accessorKey: "created_at",
|
||||||
accessorKey: "amount",
|
cell: ({ row }) =>
|
||||||
cell: ({ row }) => {
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
const amount =
|
|
||||||
typeof row.original.amount === "string"
|
|
||||||
? parseFloat(row.original.amount)
|
|
||||||
: row.original.amount || 0
|
|
||||||
return (
|
|
||||||
<div className="flex gap-1">
|
|
||||||
<span
|
|
||||||
className={
|
|
||||||
amount > 0 ? "text-green-500" : "text-orange-500"
|
|
||||||
}
|
|
||||||
>
|
|
||||||
¥{amount.toFixed(2)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
},
|
]}
|
||||||
// { header: "资源数量", accessorKey: "resource_id" },
|
/>
|
||||||
{
|
</Suspense>
|
||||||
header: "创建时间",
|
</div>
|
||||||
accessorKey: "created_at",
|
|
||||||
cell: ({ row }) =>
|
|
||||||
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: "更新时间",
|
|
||||||
accessorKey: "updated_at",
|
|
||||||
cell: ({ row }) =>
|
|
||||||
format(new Date(row.original.updated_at), "yyyy-MM-dd HH:mm"),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,107 +1,328 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
import { Suspense } from "react"
|
import { Suspense, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { z } from "zod"
|
||||||
import { getPageChannel } from "@/actions/channel"
|
import { getPageChannel } from "@/actions/channel"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
import type { Channel } from "@/models/channel"
|
import type { Channel } from "@/models/channel"
|
||||||
|
|
||||||
|
type FilterValues = {
|
||||||
|
batch_no?: string
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
proxy_host?: string
|
||||||
|
proxy_port?: number
|
||||||
|
node_ip?: string
|
||||||
|
expired_at_start?: Date
|
||||||
|
expired_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
batch_no: z.string().optional(),
|
||||||
|
user_phone: z.string().optional(),
|
||||||
|
resource_no: z.string().optional(),
|
||||||
|
proxy_host: z.string().optional(),
|
||||||
|
proxy_port: z.string().optional(),
|
||||||
|
node_ip: z.string().optional(),
|
||||||
|
expired_at_start: z.string().optional(),
|
||||||
|
expired_at_end: z.string().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.expired_at_start && data.expired_at_end) {
|
||||||
|
const start = new Date(data.expired_at_start)
|
||||||
|
const end = new Date(data.expired_at_end)
|
||||||
|
|
||||||
|
if (end < start) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "结束时间不能早于开始时间",
|
||||||
|
path: ["expired_at_end"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
type FilterSchema = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
|
const ispMap: Record<number, string> = {
|
||||||
|
1: "电信",
|
||||||
|
2: "联通",
|
||||||
|
3: "移动",
|
||||||
|
}
|
||||||
|
|
||||||
export default function ChannelPage() {
|
export default function ChannelPage() {
|
||||||
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
|
|
||||||
|
const { control, handleSubmit, reset } = useForm<FilterSchema>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
batch_no: "",
|
||||||
|
user_phone: "",
|
||||||
|
resource_no: "",
|
||||||
|
proxy_port: "",
|
||||||
|
proxy_host: "",
|
||||||
|
node_ip: "",
|
||||||
|
expired_at_start: "",
|
||||||
|
expired_at_end: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const table = useDataTable<Channel>((page, size) =>
|
const table = useDataTable<Channel>((page, size) =>
|
||||||
getPageChannel({ page, size }),
|
getPageChannel({ page, size, ...filters }),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterValues = {}
|
||||||
|
if (data.batch_no?.trim()) result.batch_no = data.batch_no.trim()
|
||||||
|
if (data.user_phone?.trim()) result.user_phone = data.user_phone.trim()
|
||||||
|
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
||||||
|
if (data.proxy_host?.trim()) result.proxy_host = data.proxy_host.trim()
|
||||||
|
if (data.proxy_port?.trim())
|
||||||
|
result.proxy_port = Number(data.proxy_port.trim())
|
||||||
|
if (data.node_ip?.trim()) result.node_ip = data.node_ip.trim()
|
||||||
|
if (data.expired_at_start)
|
||||||
|
result.expired_at_start = new Date(data.expired_at_start)
|
||||||
|
if (data.expired_at_end)
|
||||||
|
result.expired_at_end = new Date(data.expired_at_end)
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<div className="space-y-3">
|
||||||
<DataTable<Channel>
|
<form onSubmit={onFilter} className="bg-white p-4 rounded-lg">
|
||||||
{...table}
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
columns={[
|
<Controller
|
||||||
{ header: "ID", accessorKey: "id" },
|
name="batch_no"
|
||||||
{ header: "批次号", accessorKey: "batch_no" },
|
control={control}
|
||||||
{ header: "省份", accessorKey: "filter_prov" },
|
render={({ field, fieldState }) => (
|
||||||
{ header: "城市", accessorKey: "filter_city" },
|
<Field
|
||||||
{
|
data-invalid={fieldState.invalid}
|
||||||
header: "运营商",
|
className="w-40 flex-none"
|
||||||
accessorKey: "filter_isp",
|
>
|
||||||
cell: ({ row }) => {
|
<FieldLabel>批次号</FieldLabel>
|
||||||
const value = row.getValue("filter_isp")
|
<Input {...field} placeholder="请输入批次号" />
|
||||||
if (!value || value === "all") return "不限"
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
if (value === 1) return "电信"
|
</Field>
|
||||||
if (value === 2) return "联通"
|
)}
|
||||||
if (value === 3) return "移动"
|
/>
|
||||||
return String(value)
|
<Controller
|
||||||
},
|
name="user_phone"
|
||||||
},
|
control={control}
|
||||||
{
|
render={({ field, fieldState }) => (
|
||||||
header: "代理地址",
|
<Field
|
||||||
accessorKey: "host",
|
data-invalid={fieldState.invalid}
|
||||||
cell: ({ row }) => {
|
className="w-40 flex-none"
|
||||||
const ip = row.original.host
|
>
|
||||||
const port = row.original.port
|
<FieldLabel>会员号</FieldLabel>
|
||||||
return (
|
<Input {...field} placeholder="请输入会员号" />
|
||||||
<span>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
{ip}:{port}{" "}
|
</Field>
|
||||||
</span>
|
)}
|
||||||
)
|
/>
|
||||||
},
|
<Controller
|
||||||
},
|
name="resource_no"
|
||||||
{
|
control={control}
|
||||||
header: "认证方式",
|
render={({ field, fieldState }) => (
|
||||||
cell: ({ row }) => {
|
<Field
|
||||||
const channel = row.original
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>套餐号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入套餐号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="proxy_host"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>代理IP</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入代理IP" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="proxy_port"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-32 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>代理端口</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入代理端口" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="node_ip"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>节点</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入节点" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="expired_at_start"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="expired_at_end"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
const hasWhitelist =
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
channel.whitelists && channel.whitelists.trim() !== ""
|
<Button type="submit">筛选</Button>
|
||||||
const hasAuth = channel.username && channel.password
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
return (
|
<Suspense>
|
||||||
<div className="flex flex-col gap-1 min-w-0">
|
<DataTable<Channel>
|
||||||
{hasWhitelist ? (
|
{...table}
|
||||||
<div className="flex flex-col">
|
columns={[
|
||||||
<span>白名单</span>
|
{ header: "ID", accessorKey: "id" },
|
||||||
<div className="flex flex-wrap gap-1 max-w-50">
|
{
|
||||||
{channel.whitelists.split(",").map(ip => (
|
header: "会员号",
|
||||||
<Badge key={ip.trim()} variant="secondary">
|
accessorFn: row => row.user?.phone || "-",
|
||||||
{ip.trim()}
|
},
|
||||||
</Badge>
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
))}
|
{ header: "批次号", accessorKey: "batch_no" },
|
||||||
|
{
|
||||||
|
header: "节点",
|
||||||
|
accessorFn: row => row.ip || row.edge_ref || row.edge_id,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
header: "自动配置",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const prov = row.original.filter_prov
|
||||||
|
const city = row.original.filter_city
|
||||||
|
const isp = row.original.filter_isp
|
||||||
|
const parts = []
|
||||||
|
if (prov && prov !== "all") parts.push(prov)
|
||||||
|
if (city && city !== "all") parts.push(city)
|
||||||
|
if (isp && isp !== "all") {
|
||||||
|
parts.push(ispMap[Number(isp)] || isp)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="text-sm">
|
||||||
|
{parts.length > 0 ? parts.join(" / ") : "不限"}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "网关地址",
|
||||||
|
accessorKey: "host",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<span>
|
||||||
|
{row.original.host}:{row.original.port}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "认证方式",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const channel = row.original
|
||||||
|
const hasWhitelist =
|
||||||
|
channel.whitelists && channel.whitelists.trim() !== ""
|
||||||
|
const hasAuth = channel.username && channel.password
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-1 min-w-0">
|
||||||
|
{hasWhitelist ? (
|
||||||
|
<div className="flex flex-col">
|
||||||
|
<span>白名单</span>
|
||||||
|
<div className="flex flex-wrap gap-1 max-w-50">
|
||||||
|
{channel.whitelists.split(",").map(ip => (
|
||||||
|
<Badge key={ip.trim()} variant="secondary">
|
||||||
|
{ip.trim()}
|
||||||
|
</Badge>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
) : hasAuth ? (
|
||||||
) : hasAuth ? (
|
<div className="flex flex-col">
|
||||||
<div className="flex flex-col">
|
<span>账号密码</span>
|
||||||
<span>账号密码</span>
|
<Badge variant="secondary">
|
||||||
<Badge variant="secondary">
|
{channel.username}:{channel.password}
|
||||||
{channel.username}:{channel.password}
|
</Badge>
|
||||||
</Badge>
|
</div>
|
||||||
</div>
|
) : (
|
||||||
) : (
|
<span className="text-sm text-gray-400">无认证</span>
|
||||||
<span className="text-sm text-gray-400">无认证</span>
|
)}
|
||||||
)}
|
</div>
|
||||||
</div>
|
)
|
||||||
)
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{ header: "资源数量", accessorKey: "resource_id" },
|
header: "过期时间",
|
||||||
{
|
accessorKey: "expired_at",
|
||||||
header: "创建时间",
|
cell: ({ row }) =>
|
||||||
accessorKey: "created_at",
|
format(new Date(row.original.expired_at), "yyyy-MM-dd HH:mm"),
|
||||||
cell: ({ row }) =>
|
},
|
||||||
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
]}
|
||||||
},
|
/>
|
||||||
{
|
</Suspense>
|
||||||
header: "更新时间",
|
</div>
|
||||||
accessorKey: "updated_at",
|
|
||||||
cell: ({ row }) =>
|
|
||||||
format(new Date(row.original.updated_at), "yyyy-MM-dd HH:mm"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: "过期时间",
|
|
||||||
accessorKey: "expired_at",
|
|
||||||
cell: ({ row }) =>
|
|
||||||
format(new Date(row.original.expired_at), "yyyy-MM-dd HH:mm"),
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</Suspense>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
202
src/app/(root)/coupon/create.tsx
Normal file
202
src/app/(root)/coupon/create.tsx
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { Plus } from "lucide-react"
|
||||||
|
import { useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import z from "zod"
|
||||||
|
import { createCoupon } from "@/actions/coupon"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { FieldError, FieldGroup, FieldLabel } from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
|
||||||
|
const schema = z.object({
|
||||||
|
code: z.string().min(1, "请输入优惠券名称"),
|
||||||
|
amount: z.string().min(1, "请输入优惠券金额"),
|
||||||
|
remark: z.string().optional(),
|
||||||
|
min_amount: z.string().optional(),
|
||||||
|
expire_at: z.string().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export function CreateDiscount(props: { onSuccess?: () => void }) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
resolver: zodResolver(schema),
|
||||||
|
defaultValues: {
|
||||||
|
code: "",
|
||||||
|
remark: "",
|
||||||
|
amount: "0",
|
||||||
|
min_amount: "0",
|
||||||
|
expire_at: "",
|
||||||
|
},
|
||||||
|
mode: "onChange",
|
||||||
|
})
|
||||||
|
|
||||||
|
const { control, handleSubmit, reset } = form
|
||||||
|
|
||||||
|
const onSubmit = async (data: z.infer<typeof schema>) => {
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
code: data.code,
|
||||||
|
amount: Number(data.amount),
|
||||||
|
remark: data?.remark,
|
||||||
|
min_amount: Number(data?.min_amount),
|
||||||
|
expire_at: data?.expire_at ? new Date(data.expire_at) : undefined,
|
||||||
|
}
|
||||||
|
const resp = await createCoupon(payload)
|
||||||
|
if (resp.success) {
|
||||||
|
reset()
|
||||||
|
toast.success("优惠券创建成功")
|
||||||
|
props.onSuccess?.()
|
||||||
|
setOpen(false)
|
||||||
|
} else {
|
||||||
|
toast.error(resp.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`接口请求错误: ${message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
open={open}
|
||||||
|
onOpenChange={newOpen => {
|
||||||
|
setOpen(newOpen)
|
||||||
|
if (!newOpen) {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button>
|
||||||
|
<Plus />
|
||||||
|
创建优惠券
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
|
||||||
|
<DialogContent className="max-w-3xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>创建优惠券</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form id="discount-create" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<FieldGroup>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="code"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">名称:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="remark"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">备注:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="amount"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">金额:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step={5}
|
||||||
|
{...field}
|
||||||
|
onChange={e => {
|
||||||
|
const value = e.target.value
|
||||||
|
if (value === "" || parseFloat(value) >= 0) {
|
||||||
|
field.onChange(value)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="min_amount"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">最低消费:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step={5}
|
||||||
|
{...field}
|
||||||
|
onChange={e => {
|
||||||
|
const value = e.target.value
|
||||||
|
if (value === "" || parseFloat(value) >= 0) {
|
||||||
|
field.onChange(value)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expire_at"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-30 pt-2">过期时间:</FieldLabel>
|
||||||
|
<Input
|
||||||
|
type="date"
|
||||||
|
min={new Date().toISOString().split("T")[0]}
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
<div className="flex-1">
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="ghost">取消</Button>
|
||||||
|
</DialogClose>
|
||||||
|
<Button type="submit" form="discount-create">
|
||||||
|
创建
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
150
src/app/(root)/coupon/page.tsx
Normal file
150
src/app/(root)/coupon/page.tsx
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
"use client"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { Suspense, useState } from "react"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { deleteCoupon, getPagCoupon } from "@/actions/coupon"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
AlertDialogTrigger,
|
||||||
|
} from "@/components/ui/alert-dialog"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import type { Coupon } from "@/models/coupon"
|
||||||
|
import { CreateDiscount } from "./create"
|
||||||
|
import { UpdateCoupon } from "./update"
|
||||||
|
|
||||||
|
export default function CouponPage() {
|
||||||
|
const table = useDataTable((page, size) => getPagCoupon({ page, size }))
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<div className="flex justify-between items-stretch">
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<CreateDiscount onSuccess={table.refresh} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Coupon>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{ header: "ID", accessorKey: "id" },
|
||||||
|
{ header: "所属用户", accessorKey: "user_id" },
|
||||||
|
{ header: "代码", accessorKey: "code" },
|
||||||
|
{ header: "备注", accessorKey: "remark" },
|
||||||
|
{ header: "金额", accessorKey: "amount" },
|
||||||
|
{ header: "最低消费金额", accessorKey: "min_amount" },
|
||||||
|
{
|
||||||
|
header: "状态",
|
||||||
|
accessorKey: "status",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const status = row.original.status
|
||||||
|
if (status === 0) {
|
||||||
|
return <span className="text-yellow-600">未使用</span>
|
||||||
|
}
|
||||||
|
if (status === 1) {
|
||||||
|
return <span className="text-green-600">已使用</span>
|
||||||
|
}
|
||||||
|
return <span>-</span>
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "过期时间",
|
||||||
|
accessorKey: "expire_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "创建时间",
|
||||||
|
accessorKey: "created_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "更新时间",
|
||||||
|
accessorKey: "updated_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.updated_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
|
header: "操作",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<UpdateCoupon
|
||||||
|
coupon={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
<DeleteCoupon
|
||||||
|
coupon={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function DeleteCoupon({
|
||||||
|
coupon,
|
||||||
|
onSuccess,
|
||||||
|
}: {
|
||||||
|
coupon: Coupon
|
||||||
|
onSuccess?: () => void
|
||||||
|
}) {
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const resp = await deleteCoupon(coupon.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 (
|
||||||
|
<AlertDialog>
|
||||||
|
<AlertDialogTrigger asChild>
|
||||||
|
<Button size="sm" variant="destructive" disabled={loading}>
|
||||||
|
删除
|
||||||
|
</Button>
|
||||||
|
</AlertDialogTrigger>
|
||||||
|
<AlertDialogContent size="sm">
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>确认删除</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
确定要删除折扣「{coupon.code}」吗?此操作不可撤销。
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||||
|
<AlertDialogAction variant="destructive" onClick={handleConfirm}>
|
||||||
|
删除
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
247
src/app/(root)/coupon/update.tsx
Normal file
247
src/app/(root)/coupon/update.tsx
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import z from "zod"
|
||||||
|
import { updateCoupon } from "@/actions/coupon"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { FieldError, FieldGroup, FieldLabel } from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import type { Coupon } from "@/models/coupon"
|
||||||
|
|
||||||
|
const schema = z.object({
|
||||||
|
code: z.string().min(1, "请输入优惠券名称"),
|
||||||
|
amount: z.string().min(1, "请输入优惠券金额"),
|
||||||
|
remark: z.string().optional(),
|
||||||
|
min_amount: z.string().optional(),
|
||||||
|
expire_at: z.string().optional(),
|
||||||
|
status: z.string().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export function UpdateCoupon(props: {
|
||||||
|
coupon: Coupon
|
||||||
|
onSuccess?: () => void
|
||||||
|
}) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
resolver: zodResolver(schema),
|
||||||
|
defaultValues: {
|
||||||
|
code: props.coupon.code || "",
|
||||||
|
remark: props.coupon.remark || "",
|
||||||
|
amount: String(props.coupon.amount || 0),
|
||||||
|
min_amount: String(props.coupon.min_amount || 0),
|
||||||
|
expire_at: props.coupon.expire_at
|
||||||
|
? new Date(props.coupon.expire_at).toISOString().split("T")[0]
|
||||||
|
: "",
|
||||||
|
status: String(props.coupon.status || "0"),
|
||||||
|
},
|
||||||
|
mode: "onChange",
|
||||||
|
})
|
||||||
|
|
||||||
|
const { control, handleSubmit, reset } = form
|
||||||
|
|
||||||
|
const onSubmit = async (data: z.infer<typeof schema>) => {
|
||||||
|
try {
|
||||||
|
const payload = {
|
||||||
|
id: props.coupon.id,
|
||||||
|
code: data.code,
|
||||||
|
amount: Number(data.amount),
|
||||||
|
remark: data.remark,
|
||||||
|
min_amount: Number(data.min_amount),
|
||||||
|
expire_at: data.expire_at ? new Date(data.expire_at) : undefined,
|
||||||
|
status: Number(data.status),
|
||||||
|
}
|
||||||
|
const resp = await updateCoupon(payload)
|
||||||
|
if (resp.success) {
|
||||||
|
toast.success("优惠券修改成功")
|
||||||
|
props.onSuccess?.()
|
||||||
|
setOpen(false)
|
||||||
|
} else {
|
||||||
|
toast.error(resp.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`接口请求错误: ${message}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenChange = (value: boolean) => {
|
||||||
|
if (value) {
|
||||||
|
reset({
|
||||||
|
code: props.coupon.code || "",
|
||||||
|
remark: props.coupon.remark || "",
|
||||||
|
amount: String(props.coupon.amount || 0),
|
||||||
|
min_amount: String(props.coupon.min_amount || 0),
|
||||||
|
expire_at: props.coupon.expire_at
|
||||||
|
? new Date(props.coupon.expire_at).toISOString().split("T")[0]
|
||||||
|
: "",
|
||||||
|
status: String(props.coupon.status || "0"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setOpen(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button size="sm" variant="secondary">
|
||||||
|
修改
|
||||||
|
</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
|
||||||
|
<DialogContent className="max-w-3xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>修改优惠券</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form id="coupon-update" onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<FieldGroup>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="code"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">名称:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="remark"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">备注:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="amount"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">金额:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step={5}
|
||||||
|
{...field}
|
||||||
|
onChange={e => {
|
||||||
|
const value = e.target.value
|
||||||
|
if (value === "" || parseFloat(value) >= 0) {
|
||||||
|
field.onChange(value)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="min_amount"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">最低消费:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
step={5}
|
||||||
|
{...field}
|
||||||
|
onChange={e => {
|
||||||
|
const value = e.target.value
|
||||||
|
if (value === "" || parseFloat(value) >= 0) {
|
||||||
|
field.onChange(value)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="expire_at"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">过期时间:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Input
|
||||||
|
type="date"
|
||||||
|
min={new Date().toISOString().split("T")[0]}
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="status"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<div className="flex items-start gap-4">
|
||||||
|
<FieldLabel className="w-28 pt-2">状态:</FieldLabel>
|
||||||
|
<div className="flex-1">
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择状态" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="0">未使用</SelectItem>
|
||||||
|
<SelectItem value="1">已使用</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="ghost">取消</Button>
|
||||||
|
</DialogClose>
|
||||||
|
<Button type="submit" form="coupon-update">
|
||||||
|
保存
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
162
src/app/(root)/cust/balanceDialog.tsx
Normal file
162
src/app/(root)/cust/balanceDialog.tsx
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import { useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getBalance } from "@/actions/cust"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import type { Cust } from "@/models/cust"
|
||||||
|
|
||||||
|
const balanceSchema = z.object({
|
||||||
|
balance: z
|
||||||
|
.string()
|
||||||
|
.min(1, "请输入余额")
|
||||||
|
.refine(val => !Number.isNaN(Number(val)), "请输入有效的数字")
|
||||||
|
.refine(val => Number(val) >= 0, "余额不能为负数"),
|
||||||
|
})
|
||||||
|
|
||||||
|
type BalanceFormValues = z.infer<typeof balanceSchema>
|
||||||
|
|
||||||
|
interface UpdateBalanceDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
currentUser: Cust | null
|
||||||
|
onSuccess: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function BalanceDialog({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
currentUser,
|
||||||
|
onSuccess,
|
||||||
|
}: UpdateBalanceDialogProps) {
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
|
||||||
|
const {
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
reset,
|
||||||
|
setValue,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm<BalanceFormValues>({
|
||||||
|
resolver: zodResolver(balanceSchema),
|
||||||
|
defaultValues: {
|
||||||
|
balance: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open && currentUser) {
|
||||||
|
const currentBalance = currentUser.balance?.toString() || "0"
|
||||||
|
const formattedBalance = Number(currentBalance).toFixed(2)
|
||||||
|
setValue("balance", formattedBalance)
|
||||||
|
}
|
||||||
|
}, [open, currentUser, setValue])
|
||||||
|
|
||||||
|
const onSubmit = async (data: BalanceFormValues) => {
|
||||||
|
if (!currentUser) return
|
||||||
|
setIsLoading(true)
|
||||||
|
try {
|
||||||
|
const result = await getBalance({
|
||||||
|
user_id: currentUser.id,
|
||||||
|
balance: data.balance,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
toast.success("修改余额成功")
|
||||||
|
onOpenChange(false)
|
||||||
|
reset()
|
||||||
|
onSuccess()
|
||||||
|
} else {
|
||||||
|
toast.error(result.message || "修改余额失败")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`网络错误,请稍后重试: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenChange = (open: boolean) => {
|
||||||
|
if (!open) {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
onOpenChange(open)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>修改余额</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
修改用户 {currentUser?.name || currentUser?.username} 的余额
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
|
<div className="grid gap-4 py-4">
|
||||||
|
<Field data-invalid={!!errors.balance}>
|
||||||
|
<FieldLabel>余额(元)</FieldLabel>
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
step="0.01"
|
||||||
|
min="0"
|
||||||
|
placeholder="请输入余额"
|
||||||
|
{...register("balance", {
|
||||||
|
setValueAs: value => {
|
||||||
|
if (!value) return ""
|
||||||
|
const num = Number(value)
|
||||||
|
if (Number.isNaN(num)) return value
|
||||||
|
return num.toFixed(2)
|
||||||
|
},
|
||||||
|
})}
|
||||||
|
onInput={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
let value = e.target.value
|
||||||
|
if (value.startsWith("-")) {
|
||||||
|
value = value.replace("-", "")
|
||||||
|
}
|
||||||
|
if (value.includes(".")) {
|
||||||
|
const parts = value.split(".")
|
||||||
|
if (parts[1] && parts[1].length > 2) {
|
||||||
|
value = `${parts[0]}.${parts[1].slice(0, 2)}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue("balance", value)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<FieldError>{errors.balance?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => handleOpenChange(false)}
|
||||||
|
>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={isLoading}>
|
||||||
|
{isLoading ? "保存中" : "保存"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
425
src/app/(root)/cust/create.tsx
Normal file
425
src/app/(root)/cust/create.tsx
Normal file
@@ -0,0 +1,425 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { useCallback, useEffect, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getAllAdmin } from "@/actions/admin"
|
||||||
|
import { createCust } from "@/actions/cust"
|
||||||
|
import { getAllProductDiscount } from "@/actions/product_discount"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import type { Admin } from "@/models/admin"
|
||||||
|
import type { ProductDiscount } from "@/models/product_discount"
|
||||||
|
|
||||||
|
// 表单验证规则
|
||||||
|
const addUserSchema = z
|
||||||
|
.object({
|
||||||
|
username: z.string().optional(),
|
||||||
|
password: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.refine(val => !val || val.length >= 6, { message: "密码至少6位" }),
|
||||||
|
confirmPassword: z.string().optional(),
|
||||||
|
phone: z.string().regex(/^1[3-9]\d{9}$/, "请输入正确的手机号格式"),
|
||||||
|
email: z
|
||||||
|
.string()
|
||||||
|
.email("请输入正确的邮箱格式")
|
||||||
|
.optional()
|
||||||
|
.or(z.literal("")),
|
||||||
|
name: z.string().optional(),
|
||||||
|
admin_id: z.string().optional(),
|
||||||
|
discount_id: z.string().optional(),
|
||||||
|
source: z.string().optional(),
|
||||||
|
avatar: z.string().optional(),
|
||||||
|
status: z.string().optional(),
|
||||||
|
contact_qq: z.string().optional(),
|
||||||
|
contact_wechat: z.string().optional(),
|
||||||
|
})
|
||||||
|
.refine(
|
||||||
|
data => {
|
||||||
|
if (data.password) {
|
||||||
|
return data.password === data.confirmPassword
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
message: "两次输入的密码不一致",
|
||||||
|
path: ["confirmPassword"],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
export type AddUserFormValues = z.infer<typeof addUserSchema>
|
||||||
|
|
||||||
|
interface AddUserDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
onSuccess?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AddUserDialog({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
onSuccess,
|
||||||
|
}: AddUserDialogProps) {
|
||||||
|
const [isAdding, setIsAdding] = useState(false)
|
||||||
|
const [discountList, setDiscountList] = useState<ProductDiscount[]>([])
|
||||||
|
const [isLoadingDiscount, setIsLoadingDiscount] = useState(false)
|
||||||
|
const [adminList, setAdminList] = useState<Admin[]>([])
|
||||||
|
const [isLoadingAdmin, setIsLoadingAdmin] = useState(false)
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
reset: resetAddForm,
|
||||||
|
} = useForm<AddUserFormValues>({
|
||||||
|
resolver: zodResolver(addUserSchema),
|
||||||
|
defaultValues: {
|
||||||
|
username: "",
|
||||||
|
password: "",
|
||||||
|
confirmPassword: "",
|
||||||
|
phone: "",
|
||||||
|
email: "",
|
||||||
|
name: "",
|
||||||
|
admin_id: "",
|
||||||
|
discount_id: "",
|
||||||
|
avatar: "",
|
||||||
|
status: "1",
|
||||||
|
contact_qq: "",
|
||||||
|
contact_wechat: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const statusOptions = [
|
||||||
|
{ value: "0", label: "禁用" },
|
||||||
|
{ value: "1", label: "正常" },
|
||||||
|
]
|
||||||
|
|
||||||
|
const fetchDiscountList = useCallback(async () => {
|
||||||
|
setIsLoadingDiscount(true)
|
||||||
|
try {
|
||||||
|
const res = await getAllProductDiscount()
|
||||||
|
if (res.success) {
|
||||||
|
setDiscountList(res.data || [])
|
||||||
|
} else {
|
||||||
|
toast.error(res.message || "获取折扣失败")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`获取折扣失败: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setIsLoadingDiscount(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const fetchAdminList = useCallback(async () => {
|
||||||
|
setIsLoadingAdmin(true)
|
||||||
|
try {
|
||||||
|
const res = await getAllAdmin()
|
||||||
|
if (res.success) {
|
||||||
|
setAdminList(res.data || [])
|
||||||
|
} else {
|
||||||
|
toast.error(res.message || "获取管理员失败")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`获取管理员失败: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setIsLoadingAdmin(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
fetchDiscountList()
|
||||||
|
fetchAdminList()
|
||||||
|
}
|
||||||
|
}, [open, fetchDiscountList, fetchAdminList])
|
||||||
|
|
||||||
|
const onSubmit = handleSubmit(async data => {
|
||||||
|
const payload = {
|
||||||
|
phone: data.phone,
|
||||||
|
username: data?.username,
|
||||||
|
password: data?.password,
|
||||||
|
email: data?.email || "",
|
||||||
|
name: data?.name,
|
||||||
|
admin_id: data.admin_id ? Number(data.admin_id) : undefined,
|
||||||
|
discount_id: data.discount_id ? Number(data.discount_id) : undefined,
|
||||||
|
avatar: data?.avatar,
|
||||||
|
status: data.status ? parseInt(data?.status) : 1,
|
||||||
|
contact_qq: data?.contact_qq,
|
||||||
|
contact_wechat: data?.contact_wechat,
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsAdding(true)
|
||||||
|
try {
|
||||||
|
const result = await createCust(payload)
|
||||||
|
if (result?.success) {
|
||||||
|
toast.success("添加用户成功")
|
||||||
|
onOpenChange(false)
|
||||||
|
resetAddForm()
|
||||||
|
onSuccess?.()
|
||||||
|
} else {
|
||||||
|
toast.error(result?.message || "添加失败")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
toast.error("添加失败,请稍后重试")
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
setIsAdding(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleOpenChange = (open: boolean) => {
|
||||||
|
if (!open) {
|
||||||
|
resetAddForm()
|
||||||
|
}
|
||||||
|
onOpenChange(open)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent className="max-w-3xl max-h-[90vh] overflow-y-auto">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>添加用户</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<form onSubmit={onSubmit} className="space-y-4">
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<Controller
|
||||||
|
name="username"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>用户名</FieldLabel>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder="请输入用户名"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="phone"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>手机号 *</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入手机号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<Controller
|
||||||
|
name="password"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>
|
||||||
|
用户密码
|
||||||
|
<span className="text-gray-400 text-xs">(选填)</span>
|
||||||
|
</FieldLabel>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
type="password"
|
||||||
|
placeholder="请输入密码(至少6位)"
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="confirmPassword"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>确认密码</FieldLabel>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
type="password"
|
||||||
|
placeholder="请再次输入密码"
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<Controller
|
||||||
|
name="name"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>真实姓名</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入真实姓名" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="email"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>邮箱</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入邮箱" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<Controller
|
||||||
|
name="status"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>用户状态</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger className="w-full h-9">
|
||||||
|
<SelectValue placeholder="请选择用户状态" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{statusOptions.map(option => (
|
||||||
|
<SelectItem key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<Controller
|
||||||
|
name="contact_qq"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>QQ联系方式</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入QQ联系方式" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="contact_wechat"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>微信/联系方式</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入微信或联系方式" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<Controller
|
||||||
|
name="discount_id"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>折扣</FieldLabel>
|
||||||
|
<Select
|
||||||
|
value={field.value}
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
disabled={isLoadingDiscount}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-full h-9">
|
||||||
|
<SelectValue placeholder="请选择折扣" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{discountList.map(discount => (
|
||||||
|
<SelectItem
|
||||||
|
key={discount.id}
|
||||||
|
value={discount.id.toString()}
|
||||||
|
>
|
||||||
|
{discount.name}({discount.discount}%)
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="admin_id"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>管理员</FieldLabel>
|
||||||
|
<Select
|
||||||
|
disabled={isLoadingAdmin}
|
||||||
|
value={field.value}
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-full h-9">
|
||||||
|
<SelectValue
|
||||||
|
placeholder={
|
||||||
|
isLoadingAdmin ? "加载中..." : "请选择管理员"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{adminList.map(admin => (
|
||||||
|
<SelectItem key={admin.id} value={admin.id.toString()}>
|
||||||
|
{admin.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FieldGroup className="flex-row justify-end gap-2 pt-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={isAdding}>
|
||||||
|
{isAdding ? "添加中..." : "确定添加"}
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
395
src/app/(root)/cust/page.tsx
Normal file
395
src/app/(root)/cust/page.tsx
Normal file
@@ -0,0 +1,395 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { format } from "date-fns"
|
||||||
|
import { Suspense, useCallback, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getPageCusts } from "@/actions/cust"
|
||||||
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import type { Cust } from "@/models/cust"
|
||||||
|
import { BalanceDialog } from "./balanceDialog"
|
||||||
|
import { AddUserDialog } from "./create"
|
||||||
|
import { UpdateDialog } from "./update"
|
||||||
|
|
||||||
|
type FilterValues = {
|
||||||
|
account?: string
|
||||||
|
name?: string
|
||||||
|
identified?: boolean
|
||||||
|
enabled?: boolean
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
account: z.string().optional(),
|
||||||
|
name: z.string().optional(),
|
||||||
|
identified: z.string().optional(),
|
||||||
|
enabled: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: z.string().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.created_at_start && data.created_at_end) {
|
||||||
|
const start = new Date(data.created_at_start)
|
||||||
|
const end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
if (end < start) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "结束时间不能早于开始时间",
|
||||||
|
path: ["created_at_end"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
type FormValues = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
|
export default function UserPage() {
|
||||||
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
|
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false)
|
||||||
|
const [isEditDialogOpen, setIsEditDialogOpen] = useState(false)
|
||||||
|
const [currentEditUser, setCurrentEditUser] = useState<Cust | null>(null)
|
||||||
|
const [balanceDialog, setBalanceDialog] = useState(false)
|
||||||
|
const [balance, setBalance] = useState<Cust | null>(null)
|
||||||
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
account: "",
|
||||||
|
name: "",
|
||||||
|
identified: "all",
|
||||||
|
enabled: "all",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchUsers = useCallback(
|
||||||
|
(page: number, size: number) => getPageCusts({ page, size, ...filters }),
|
||||||
|
[filters],
|
||||||
|
)
|
||||||
|
|
||||||
|
const table = useDataTable<Cust>(fetchUsers)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterValues = {}
|
||||||
|
if (data.account) result.account = data.account
|
||||||
|
if (data.name) result.name = data.name
|
||||||
|
if (data.identified && data.identified !== "all")
|
||||||
|
result.identified = data.identified === "1"
|
||||||
|
if (data.enabled && data.enabled !== "all")
|
||||||
|
result.enabled = data.enabled === "1"
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
const refreshTable = useCallback(() => {
|
||||||
|
table.refresh()
|
||||||
|
}, [table])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="account"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-80 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>账号/手机号/邮箱</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入账号/手机号/邮箱" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="name"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>姓名</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入姓名" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="identified"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-24">
|
||||||
|
<FieldLabel>实名状态</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger className="w-24">
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="1">已认证</SelectItem>
|
||||||
|
<SelectItem value="0">未认证</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="enabled"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-24">
|
||||||
|
<FieldLabel>账号状态</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="1">正常</SelectItem>
|
||||||
|
<SelectItem value="0">禁用</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="created_at_start"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="created_at_end"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
|
<Button type="submit">筛选</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
<Button type="button" onClick={() => setIsAddDialogOpen(true)}>
|
||||||
|
添加用户
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Cust>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{ header: "ID", accessorKey: "id" },
|
||||||
|
{ header: "账号", accessorKey: "username" },
|
||||||
|
{ header: "手机", accessorKey: "phone" },
|
||||||
|
{ header: "邮箱", accessorKey: "email" },
|
||||||
|
{ header: "姓名", accessorKey: "name" },
|
||||||
|
{
|
||||||
|
header: "客户来源",
|
||||||
|
accessorKey: "source",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const sourceMap: Record<number, string> = {
|
||||||
|
0: "官网注册",
|
||||||
|
1: "管理员添加",
|
||||||
|
2: "代理商注册",
|
||||||
|
3: "代理商添加",
|
||||||
|
}
|
||||||
|
return sourceMap[row.original.source] ?? "官网注册"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "余额",
|
||||||
|
accessorKey: "balance",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const balance = Number(row.original.balance) || 0
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
balance > 0 ? "text-green-500" : "text-orange-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
¥{balance.toFixed(2)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ header: "折扣", accessorKey: "discount.name" },
|
||||||
|
{
|
||||||
|
header: "实名状态",
|
||||||
|
accessorKey: "id_type",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<Badge
|
||||||
|
variant={row.original.id_type === 1 ? "default" : "secondary"}
|
||||||
|
className={
|
||||||
|
row.original.id_type === 1
|
||||||
|
? "bg-green-100 text-green-800"
|
||||||
|
: "bg-gray-100 text-gray-800"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{row.original.id_type === 1 ? "已认证" : "未认证"}
|
||||||
|
</Badge>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "身份证号",
|
||||||
|
accessorKey: "id_no",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const idNo = row.original.id_no
|
||||||
|
return idNo ? `${idNo.slice(0, 6)}****${idNo.slice(-4)}` : "-"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "账号状态",
|
||||||
|
accessorKey: "status",
|
||||||
|
cell: ({ row }) => (row.original.status === 1 ? "正常" : "禁用"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "联系方式",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const qq = row.original.contact_qq || ""
|
||||||
|
const wechat = row.original.contact_wechat || ""
|
||||||
|
const hasQQ = qq.trim() !== ""
|
||||||
|
const hasWechat = wechat.trim() !== ""
|
||||||
|
if (!hasQQ && !hasWechat) return null
|
||||||
|
return (
|
||||||
|
<div className="space-y-1">
|
||||||
|
{hasWechat && <div>微信:{wechat}</div>}
|
||||||
|
{hasQQ && <div>QQ:{qq}</div>}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ header: "客户经理", accessorKey: "admin.name" },
|
||||||
|
{
|
||||||
|
header: "最后登录时间",
|
||||||
|
accessorKey: "last_login",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
row.original.last_login
|
||||||
|
? format(
|
||||||
|
new Date(row.original.last_login),
|
||||||
|
"yyyy-MM-dd HH:mm",
|
||||||
|
)
|
||||||
|
: "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "最后登录IP",
|
||||||
|
accessorKey: "last_login_ip",
|
||||||
|
cell: ({ row }) => row.original.last_login_ip || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "创建时间",
|
||||||
|
accessorKey: "created_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
|
header: "操作",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
setBalance(row.original)
|
||||||
|
setBalanceDialog(true)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
修改余额
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setCurrentEditUser(row.original)
|
||||||
|
setIsEditDialogOpen(true)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
修改
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
|
||||||
|
<AddUserDialog
|
||||||
|
open={isAddDialogOpen}
|
||||||
|
onOpenChange={setIsAddDialogOpen}
|
||||||
|
onSuccess={refreshTable}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UpdateDialog
|
||||||
|
open={isEditDialogOpen}
|
||||||
|
onOpenChange={setIsEditDialogOpen}
|
||||||
|
currentUser={currentEditUser}
|
||||||
|
onSuccess={refreshTable}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<BalanceDialog
|
||||||
|
open={balanceDialog}
|
||||||
|
onOpenChange={setBalanceDialog}
|
||||||
|
currentUser={balance}
|
||||||
|
onSuccess={refreshTable}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
390
src/app/(root)/cust/update.tsx
Normal file
390
src/app/(root)/cust/update.tsx
Normal file
@@ -0,0 +1,390 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { getAllAdmin } from "@/actions/admin"
|
||||||
|
import { updateCust } from "@/actions/cust"
|
||||||
|
import { getAllProductDiscount } from "@/actions/product_discount"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
|
import type { Admin } from "@/models/admin"
|
||||||
|
import type { Cust } from "@/models/cust"
|
||||||
|
import type { ProductDiscount } from "@/models/product_discount"
|
||||||
|
|
||||||
|
// 表单验证规则
|
||||||
|
const editUserSchema = z
|
||||||
|
.object({
|
||||||
|
id: z.number(),
|
||||||
|
username: z.string().optional(),
|
||||||
|
email: z.string().email("邮箱格式不正确").optional().or(z.literal("")),
|
||||||
|
password: z.string().optional(),
|
||||||
|
confirmPassword: z.string().optional(),
|
||||||
|
admin_id: z.string().optional(),
|
||||||
|
discount_id: z.string().optional(),
|
||||||
|
status: z.string().optional(),
|
||||||
|
contact_qq: z.string().optional(),
|
||||||
|
contact_wechat: z.string().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.password && data.password.length < 6) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "密码至少6位",
|
||||||
|
path: ["password"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (data.password && data.password !== data.confirmPassword) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "两次输入的密码不一致",
|
||||||
|
path: ["confirmPassword"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export type EditUserFormValues = z.infer<typeof editUserSchema>
|
||||||
|
|
||||||
|
interface EditUserDialogProps {
|
||||||
|
open: boolean
|
||||||
|
onOpenChange: (open: boolean) => void
|
||||||
|
currentUser: Cust | null
|
||||||
|
onSuccess: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UpdateDialog({
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
currentUser,
|
||||||
|
onSuccess,
|
||||||
|
}: EditUserDialogProps) {
|
||||||
|
const [admins, setAdmins] = useState<Admin[]>([])
|
||||||
|
const [discounts, setDiscounts] = useState<ProductDiscount[]>([])
|
||||||
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
|
|
||||||
|
// 表单
|
||||||
|
const { control, handleSubmit, reset } = useForm<EditUserFormValues>({
|
||||||
|
resolver: zodResolver(editUserSchema),
|
||||||
|
defaultValues: {
|
||||||
|
id: 0,
|
||||||
|
username: "",
|
||||||
|
email: "",
|
||||||
|
password: "",
|
||||||
|
confirmPassword: "",
|
||||||
|
admin_id: "",
|
||||||
|
discount_id: "",
|
||||||
|
status: "",
|
||||||
|
contact_qq: "",
|
||||||
|
contact_wechat: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadOptions = async () => {
|
||||||
|
try {
|
||||||
|
const [adminRes, discountRes] = await Promise.all([
|
||||||
|
getAllAdmin(),
|
||||||
|
getAllProductDiscount(),
|
||||||
|
])
|
||||||
|
|
||||||
|
if (adminRes.success) {
|
||||||
|
setAdmins(adminRes.data)
|
||||||
|
} else {
|
||||||
|
toast.error(adminRes.message || "获取管理员失败")
|
||||||
|
setAdmins([])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discountRes.success) {
|
||||||
|
setDiscounts(discountRes.data)
|
||||||
|
} else {
|
||||||
|
toast.error(discountRes.message || "获取折扣方案失败")
|
||||||
|
setDiscounts([])
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "加载数据失败"
|
||||||
|
toast.error(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (open) {
|
||||||
|
loadOptions()
|
||||||
|
}
|
||||||
|
}, [open])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (currentUser) {
|
||||||
|
reset({
|
||||||
|
id: currentUser.id,
|
||||||
|
username: currentUser.username,
|
||||||
|
email: currentUser.email || "",
|
||||||
|
password: "",
|
||||||
|
confirmPassword: "",
|
||||||
|
admin_id: currentUser.admin_id ? String(currentUser.admin_id) : "",
|
||||||
|
discount_id: currentUser.discount_id
|
||||||
|
? String(currentUser.discount_id)
|
||||||
|
: "",
|
||||||
|
status:
|
||||||
|
currentUser.status !== undefined ? String(currentUser.status) : "",
|
||||||
|
contact_qq: currentUser.contact_qq || "",
|
||||||
|
contact_wechat: currentUser.contact_wechat || "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [currentUser, reset])
|
||||||
|
|
||||||
|
const onSubmit = async (data: EditUserFormValues) => {
|
||||||
|
setIsSubmitting(true)
|
||||||
|
try {
|
||||||
|
const updateData: {
|
||||||
|
id: number
|
||||||
|
username?: string
|
||||||
|
email?: string
|
||||||
|
password?: string
|
||||||
|
admin_id?: number
|
||||||
|
discount_id?: number
|
||||||
|
status?: number
|
||||||
|
contact_qq?: string
|
||||||
|
contact_wechat?: string
|
||||||
|
} = { id: data.id }
|
||||||
|
|
||||||
|
if (data.username && data.username.trim() !== "") {
|
||||||
|
updateData.username = data.username.trim()
|
||||||
|
}
|
||||||
|
if (data.email && data.email.trim() !== "") {
|
||||||
|
updateData.email = data.email.trim()
|
||||||
|
}
|
||||||
|
if (data.password && data.password.trim() !== "") {
|
||||||
|
updateData.password = data.password
|
||||||
|
}
|
||||||
|
if (data.admin_id && data.admin_id !== "") {
|
||||||
|
updateData.admin_id = Number(data.admin_id)
|
||||||
|
}
|
||||||
|
if (data.discount_id && data.discount_id !== "") {
|
||||||
|
updateData.discount_id = Number(data.discount_id)
|
||||||
|
}
|
||||||
|
if (data.status && data.status !== "") {
|
||||||
|
updateData.status = Number(data.status)
|
||||||
|
}
|
||||||
|
if (data.contact_qq !== undefined) {
|
||||||
|
updateData.contact_qq = data.contact_qq
|
||||||
|
}
|
||||||
|
if (data.contact_wechat !== undefined) {
|
||||||
|
updateData.contact_wechat = data.contact_wechat
|
||||||
|
}
|
||||||
|
const result = await updateCust(updateData)
|
||||||
|
if (result?.success) {
|
||||||
|
toast.success("修改成功")
|
||||||
|
onOpenChange(false)
|
||||||
|
onSuccess()
|
||||||
|
} else {
|
||||||
|
toast.error(result?.message || "修改失败")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("修改用户失败:", error)
|
||||||
|
const message =
|
||||||
|
error instanceof Error ? error.message : "修改失败,请稍后重试"
|
||||||
|
toast.error(`修改失败:${message}`)
|
||||||
|
} finally {
|
||||||
|
setIsSubmitting(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleOpenChange = (open: boolean) => {
|
||||||
|
if (!open) {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
onOpenChange(open)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent className="max-w-2xl max-h-[90vh] overflow-y-auto">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>修改用户</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4 py-2">
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<Controller
|
||||||
|
name="username"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>用户名</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入用户名" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="email"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>邮箱</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入邮箱" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="password"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>用户密码</FieldLabel>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
type="password"
|
||||||
|
placeholder="选填,修改请输入新密码(至少6位)"
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="confirmPassword"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid}>
|
||||||
|
<FieldLabel>确认密码</FieldLabel>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
type="password"
|
||||||
|
placeholder="请再次输入密码"
|
||||||
|
/>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="status"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>账号状态</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择账号状态" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="1">正常</SelectItem>
|
||||||
|
<SelectItem value="0">禁用</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="admin_id"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>客户经理</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择客户经理" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{admins.map(admin => (
|
||||||
|
<SelectItem key={admin.id} value={admin.id.toString()}>
|
||||||
|
{admin.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="discount_id"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>折扣方案</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="请选择折扣方案" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{discounts.map(discount => (
|
||||||
|
<SelectItem
|
||||||
|
key={discount.id}
|
||||||
|
value={discount.id.toString()}
|
||||||
|
>
|
||||||
|
{discount.name}({discount.discount}%)
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="contact_qq"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>QQ</FieldLabel>
|
||||||
|
<Input {...field} placeholder="QQ号" />
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="contact_wechat"
|
||||||
|
control={control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel>微信</FieldLabel>
|
||||||
|
<Input {...field} placeholder="微信号" />
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FieldGroup className="flex-row justify-end gap-2 pt-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => handleOpenChange(false)}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
>
|
||||||
|
取消
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={isSubmitting}>
|
||||||
|
{isSubmitting ? "提交中..." : "确认修改"}
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -92,7 +92,7 @@ export function CreateDiscount(props: { onSuccess?: () => void }) {
|
|||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Field>
|
<Field>
|
||||||
<FieldLabel htmlFor="discount-create-discount">
|
<FieldLabel htmlFor="discount-create-discount">
|
||||||
代码
|
折扣
|
||||||
</FieldLabel>
|
</FieldLabel>
|
||||||
<Input
|
<Input
|
||||||
id="discount-create-discount"
|
id="discount-create-discount"
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ export default function DiscountPage() {
|
|||||||
format(new Date(row.original.updated_at), "yyyy-MM-dd HH:mm"),
|
format(new Date(row.original.updated_at), "yyyy-MM-dd HH:mm"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export function UpdateDiscount(props: {
|
|||||||
render={({ field, fieldState }) => (
|
render={({ field, fieldState }) => (
|
||||||
<Field>
|
<Field>
|
||||||
<FieldLabel htmlFor="discount-update-discount">
|
<FieldLabel htmlFor="discount-update-discount">
|
||||||
代码
|
折扣
|
||||||
</FieldLabel>
|
</FieldLabel>
|
||||||
<Input
|
<Input
|
||||||
id="discount-update-discount"
|
id="discount-update-discount"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
ClipboardList,
|
ClipboardList,
|
||||||
Code,
|
Code,
|
||||||
ComputerIcon,
|
ComputerIcon,
|
||||||
|
ContactRound,
|
||||||
DollarSign,
|
DollarSign,
|
||||||
Home,
|
Home,
|
||||||
KeyRound,
|
KeyRound,
|
||||||
@@ -15,13 +16,14 @@ import {
|
|||||||
Shield,
|
Shield,
|
||||||
ShoppingBag,
|
ShoppingBag,
|
||||||
SquarePercent,
|
SquarePercent,
|
||||||
SquarePercentIcon,
|
TicketPercent,
|
||||||
Users,
|
Users,
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname } from "next/navigation"
|
||||||
import { createContext, type ReactNode, useContext, useState } from "react"
|
import { createContext, type ReactNode, useContext, useState } from "react"
|
||||||
import { twJoin } from "tailwind-merge"
|
import { twJoin } from "tailwind-merge"
|
||||||
|
import { Auth } from "@/components/auth"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||||
import { Separator } from "@/components/ui/separator"
|
import { Separator } from "@/components/ui/separator"
|
||||||
@@ -31,6 +33,21 @@ import {
|
|||||||
TooltipProvider,
|
TooltipProvider,
|
||||||
TooltipTrigger,
|
TooltipTrigger,
|
||||||
} from "@/components/ui/tooltip"
|
} from "@/components/ui/tooltip"
|
||||||
|
import {
|
||||||
|
ScopeAdminRead,
|
||||||
|
ScopeAdminRoleRead,
|
||||||
|
ScopeBatchRead,
|
||||||
|
ScopeBillRead,
|
||||||
|
ScopeChannelRead,
|
||||||
|
ScopeCouponRead,
|
||||||
|
ScopeDiscountRead,
|
||||||
|
ScopePermissionRead,
|
||||||
|
ScopeProductRead,
|
||||||
|
ScopeResourceRead,
|
||||||
|
ScopeTradeRead,
|
||||||
|
ScopeUserRead,
|
||||||
|
ScopeUserReadOne,
|
||||||
|
} from "@/lib/scopes"
|
||||||
|
|
||||||
// Navigation Context
|
// Navigation Context
|
||||||
interface NavigationContextType {
|
interface NavigationContextType {
|
||||||
@@ -77,13 +94,16 @@ interface NavItemProps {
|
|||||||
href: string
|
href: string
|
||||||
icon: LucideIcon
|
icon: LucideIcon
|
||||||
label: string
|
label: string
|
||||||
|
requiredScope?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function NavItem({ href, icon: Icon, label }: NavItemProps) {
|
function NavItem({ href, icon: Icon, label, requiredScope }: NavItemProps) {
|
||||||
|
// console.log(requiredScope, "requiredScope")
|
||||||
|
|
||||||
const { collapsed, isActive } = useNavigation()
|
const { collapsed, isActive } = useNavigation()
|
||||||
const active = isActive(href)
|
const active = isActive(href)
|
||||||
|
|
||||||
const linkContent = (
|
let linkContent = (
|
||||||
<Link
|
<Link
|
||||||
href={href}
|
href={href}
|
||||||
className={`flex items-center ${
|
className={`flex items-center ${
|
||||||
@@ -100,19 +120,25 @@ function NavItem({ href, icon: Icon, label }: NavItemProps) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (collapsed) {
|
if (collapsed) {
|
||||||
return (
|
linkContent = (
|
||||||
<li>
|
<Tooltip>
|
||||||
<Tooltip>
|
<TooltipTrigger asChild>{linkContent}</TooltipTrigger>
|
||||||
<TooltipTrigger asChild>{linkContent}</TooltipTrigger>
|
<TooltipContent side="right">
|
||||||
<TooltipContent side="right">
|
<p>{label}</p>
|
||||||
<p>{label}</p>
|
</TooltipContent>
|
||||||
</TooltipContent>
|
</Tooltip>
|
||||||
</Tooltip>
|
|
||||||
</li>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return <li>{linkContent}</li>
|
if (requiredScope) {
|
||||||
|
linkContent = (
|
||||||
|
<Auth scope={requiredScope}>
|
||||||
|
<li>{linkContent}</li>
|
||||||
|
</Auth>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return linkContent
|
||||||
}
|
}
|
||||||
|
|
||||||
// NavSeparator Component
|
// NavSeparator Component
|
||||||
@@ -128,6 +154,109 @@ function NavSeparator() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const menuSections: { title: string; items: NavItemProps[] }[] = [
|
||||||
|
{
|
||||||
|
title: "概览",
|
||||||
|
items: [
|
||||||
|
{ href: "/", icon: Home, label: "首页" },
|
||||||
|
{ href: "/statistics", icon: BarChart3, label: "数据统计" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "客户",
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
href: "/user",
|
||||||
|
icon: Users,
|
||||||
|
label: "客户认领",
|
||||||
|
requiredScope: ScopeUserReadOne,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/cust",
|
||||||
|
icon: ContactRound,
|
||||||
|
label: "客户管理",
|
||||||
|
requiredScope: ScopeUserRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/trade",
|
||||||
|
icon: Activity,
|
||||||
|
label: "交易明细",
|
||||||
|
requiredScope: ScopeTradeRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/billing",
|
||||||
|
icon: DollarSign,
|
||||||
|
label: "账单详情",
|
||||||
|
requiredScope: ScopeBillRead,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "运营",
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
href: "/product",
|
||||||
|
icon: ShoppingBag,
|
||||||
|
label: "产品管理",
|
||||||
|
requiredScope: ScopeProductRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/discount",
|
||||||
|
icon: SquarePercent,
|
||||||
|
label: "折扣管理",
|
||||||
|
requiredScope: ScopeDiscountRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/coupon",
|
||||||
|
icon: TicketPercent,
|
||||||
|
label: "优惠券",
|
||||||
|
requiredScope: ScopeCouponRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/resources",
|
||||||
|
icon: Package,
|
||||||
|
label: "套餐管理",
|
||||||
|
requiredScope: ScopeResourceRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/batch",
|
||||||
|
icon: ClipboardList,
|
||||||
|
label: "提取记录",
|
||||||
|
requiredScope: ScopeBatchRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/channel",
|
||||||
|
icon: Code,
|
||||||
|
label: "IP管理",
|
||||||
|
requiredScope: ScopeChannelRead,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: "系统",
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
href: "/admin",
|
||||||
|
icon: Shield,
|
||||||
|
label: "管理员",
|
||||||
|
requiredScope: ScopeAdminRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/roles",
|
||||||
|
icon: KeyRound,
|
||||||
|
label: "角色列表",
|
||||||
|
requiredScope: ScopeAdminRoleRead,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "/permissions",
|
||||||
|
icon: Shield,
|
||||||
|
label: "权限列表",
|
||||||
|
requiredScope: ScopePermissionRead,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
// Main Navigation Component
|
// Main Navigation Component
|
||||||
export default function Navigation() {
|
export default function Navigation() {
|
||||||
const [collapsed, setCollapsed] = useState(false)
|
const [collapsed, setCollapsed] = useState(false)
|
||||||
@@ -164,58 +293,19 @@ export default function Navigation() {
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Navigation Menu */}
|
{/* Navigation Menu */}
|
||||||
<ScrollArea className="flex-1 py-3">
|
<ScrollArea className="flex-1 py-3">
|
||||||
<nav className="space-y-3">
|
<nav className="space-y-3">
|
||||||
{/* 概览 */}
|
{menuSections.map((section, idx) => (
|
||||||
<NavGroup title="概览">
|
<div key={section.title}>
|
||||||
<NavItem href="/" icon={Home} label="首页" />
|
<NavGroup title={section.title}>
|
||||||
<NavItem href="/statistics" icon={BarChart3} label="数据统计" />
|
{section.items.map(item => (
|
||||||
</NavGroup>
|
<NavItem key={item.label} {...item} />
|
||||||
|
))}
|
||||||
{/*<NavSeparator />*/}
|
</NavGroup>
|
||||||
|
{idx !== menuSections.length - 1 && <NavSeparator />}
|
||||||
{/* IP 资源 */}
|
</div>
|
||||||
{/*<NavGroup title="IP 资源">
|
))}
|
||||||
<NavItem href="/proxy/nodes" icon={Globe} label="节点列表" />
|
|
||||||
<NavItem href="/proxy/pools" icon={Server} label="IP池管理" />
|
|
||||||
</NavGroup>*/}
|
|
||||||
|
|
||||||
<NavSeparator />
|
|
||||||
|
|
||||||
{/* 客户 */}
|
|
||||||
<NavGroup title="客户">
|
|
||||||
<NavItem href="/user" icon={Users} label="客户管理" />
|
|
||||||
<NavItem href="/trade" icon={Activity} label="交易明细" />
|
|
||||||
<NavItem href="/billing" icon={DollarSign} label="账单详情" />
|
|
||||||
</NavGroup>
|
|
||||||
|
|
||||||
<NavSeparator />
|
|
||||||
|
|
||||||
{/* 运营 */}
|
|
||||||
<NavGroup title="运营">
|
|
||||||
<NavItem href="/product" icon={ShoppingBag} label="产品管理" />
|
|
||||||
<NavItem
|
|
||||||
href="/discount"
|
|
||||||
icon={SquarePercent}
|
|
||||||
label="折扣管理"
|
|
||||||
/>
|
|
||||||
<NavItem href="/resources" icon={Package} label="套餐管理" />
|
|
||||||
<NavItem href="/batch" icon={ClipboardList} label="使用记录" />
|
|
||||||
<NavItem href="/channel" icon={Code} label="IP管理" />
|
|
||||||
</NavGroup>
|
|
||||||
|
|
||||||
<NavSeparator />
|
|
||||||
|
|
||||||
{/* 系统 */}
|
|
||||||
<NavGroup title="系统">
|
|
||||||
{/*<NavItem href="/settings" icon={Settings} label="系统设置" />*/}
|
|
||||||
<NavItem href="/admin" icon={Shield} label="管理员" />
|
|
||||||
<NavItem href="/roles" icon={KeyRound} label="角色列表" />
|
|
||||||
<NavItem href="/permissions" icon={Shield} label="权限列表" />
|
|
||||||
{/*<NavItem href="/logs" icon={FileText} label="系统日志" />*/}
|
|
||||||
</NavGroup>
|
|
||||||
</nav>
|
</nav>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import {
|
import {
|
||||||
flexRender,
|
|
||||||
getCoreRowModel,
|
getCoreRowModel,
|
||||||
getExpandedRowModel,
|
getExpandedRowModel,
|
||||||
type Row,
|
type Row,
|
||||||
|
|||||||
@@ -92,9 +92,8 @@ function Products(props: {
|
|||||||
|
|
||||||
function ProductSkus(props: { selected?: number }) {
|
function ProductSkus(props: { selected?: number }) {
|
||||||
const action = useCallback(
|
const action = useCallback(
|
||||||
(page: number, size: number) => {
|
(page: number, size: number) =>
|
||||||
return getPageProductSku({ page, size, product_id: props.selected })
|
getPageProductSku({ page, size, product_id: props.selected }),
|
||||||
},
|
|
||||||
[props.selected],
|
[props.selected],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -121,14 +120,16 @@ function ProductSkus(props: { selected?: number }) {
|
|||||||
columns={[
|
columns={[
|
||||||
{ header: "套餐编码", accessorKey: "code" },
|
{ header: "套餐编码", accessorKey: "code" },
|
||||||
{ header: "套餐名称", accessorKey: "name" },
|
{ header: "套餐名称", accessorKey: "name" },
|
||||||
{ header: "单价", accessorKey: "price" },
|
{ header: "单价", accessorFn: row => Number(row.price).toFixed(2) },
|
||||||
{ header: "折扣", accessorFn: row => row.discount?.name ?? "—" },
|
{ header: "折扣", accessorFn: row => row.discount?.name ?? "—" },
|
||||||
{
|
{
|
||||||
header: "最终价格",
|
header: "最终价格",
|
||||||
accessorFn: row =>
|
accessorFn: row => {
|
||||||
row.discount
|
const value = row.discount
|
||||||
? (Number(row.price) * Number(row.discount.discount)) / 100
|
? (Number(row.price) * Number(row.discount.discount)) / 100
|
||||||
: Number(row.price),
|
: Number(row.price)
|
||||||
|
return Number(value.toFixed(2))
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "创建时间",
|
header: "创建时间",
|
||||||
@@ -139,6 +140,8 @@ function ProductSkus(props: { selected?: number }) {
|
|||||||
accessorFn: row => format(row.updated_at, "yyyy-MM-dd HH:mm"),
|
accessorFn: row => format(row.updated_at, "yyyy-MM-dd HH:mm"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="flex gap-1">
|
<div className="flex gap-1">
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
'use client'
|
"use client"
|
||||||
import {useState, useEffect} from 'react'
|
import Link from "next/link"
|
||||||
import Link from 'next/link'
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
// 定义节点数据接口
|
// 定义节点数据接口
|
||||||
interface ProxyNode {
|
interface ProxyNode {
|
||||||
id: string;
|
id: string
|
||||||
ipAddress: string;
|
ipAddress: string
|
||||||
location: {
|
location: {
|
||||||
country: string;
|
country: string
|
||||||
region: string;
|
region: string
|
||||||
};
|
}
|
||||||
type: string;
|
type: string
|
||||||
status: 'online' | 'offline' | 'warning';
|
status: "online" | "offline" | "warning"
|
||||||
responseTime: number;
|
responseTime: number
|
||||||
lastCheckTime: string;
|
lastCheckTime: string
|
||||||
pool: string;
|
pool: string
|
||||||
isStatic: boolean;
|
isStatic: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProxyNodesPageProps = {}
|
export type ProxyNodesPageProps = {}
|
||||||
@@ -24,101 +24,101 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
const [loading, setLoading] = useState<boolean>(true)
|
const [loading, setLoading] = useState<boolean>(true)
|
||||||
|
|
||||||
const [nodes, setNodes] = useState<ProxyNode[]>([])
|
const [nodes, setNodes] = useState<ProxyNode[]>([])
|
||||||
const [searchTerm, setSearchTerm] = useState<string>('')
|
const [searchTerm, setSearchTerm] = useState<string>("")
|
||||||
const [filterStatus, setFilterStatus] = useState<string>('all')
|
const [filterStatus, setFilterStatus] = useState<string>("all")
|
||||||
const [filterType, setFilterType] = useState<string>('all')
|
const [filterType, setFilterType] = useState<string>("all")
|
||||||
const [filterPool, setFilterPool] = useState<string>('all')
|
const [filterPool, setFilterPool] = useState<string>("all")
|
||||||
|
|
||||||
// 模拟数据加载
|
// 模拟数据加载
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setNodes([
|
setNodes([
|
||||||
{
|
{
|
||||||
id: 'ip-1',
|
id: "ip-1",
|
||||||
ipAddress: '203.45.167.82',
|
ipAddress: "203.45.167.82",
|
||||||
location: {country: '美国', region: '纽约'},
|
location: { country: "美国", region: "纽约" },
|
||||||
type: '数据中心',
|
type: "数据中心",
|
||||||
status: 'online',
|
status: "online",
|
||||||
responseTime: 126,
|
responseTime: 126,
|
||||||
lastCheckTime: '2024-05-10 15:30:22',
|
lastCheckTime: "2024-05-10 15:30:22",
|
||||||
pool: '北美专用池',
|
pool: "北美专用池",
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'ip-2',
|
id: "ip-2",
|
||||||
ipAddress: '185.72.193.54',
|
ipAddress: "185.72.193.54",
|
||||||
location: {country: '德国', region: '法兰克福'},
|
location: { country: "德国", region: "法兰克福" },
|
||||||
type: '住宅',
|
type: "住宅",
|
||||||
status: 'online',
|
status: "online",
|
||||||
responseTime: 158,
|
responseTime: 158,
|
||||||
lastCheckTime: '2024-05-10 15:28:45',
|
lastCheckTime: "2024-05-10 15:28:45",
|
||||||
pool: '欧洲高速池',
|
pool: "欧洲高速池",
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'ip-3',
|
id: "ip-3",
|
||||||
ipAddress: '118.96.244.105',
|
ipAddress: "118.96.244.105",
|
||||||
location: {country: '新加坡', region: '中心区'},
|
location: { country: "新加坡", region: "中心区" },
|
||||||
type: '移动',
|
type: "移动",
|
||||||
status: 'warning',
|
status: "warning",
|
||||||
responseTime: 312,
|
responseTime: 312,
|
||||||
lastCheckTime: '2024-05-10 15:25:12',
|
lastCheckTime: "2024-05-10 15:25:12",
|
||||||
pool: '亚太地区池',
|
pool: "亚太地区池",
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'ip-4',
|
id: "ip-4",
|
||||||
ipAddress: '45.178.29.6',
|
ipAddress: "45.178.29.6",
|
||||||
location: {country: '加拿大', region: '多伦多'},
|
location: { country: "加拿大", region: "多伦多" },
|
||||||
type: '数据中心',
|
type: "数据中心",
|
||||||
status: 'online',
|
status: "online",
|
||||||
responseTime: 143,
|
responseTime: 143,
|
||||||
lastCheckTime: '2024-05-10 15:23:08',
|
lastCheckTime: "2024-05-10 15:23:08",
|
||||||
pool: '北美专用池',
|
pool: "北美专用池",
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'ip-5',
|
id: "ip-5",
|
||||||
ipAddress: '79.114.83.201',
|
ipAddress: "79.114.83.201",
|
||||||
location: {country: '英国', region: '伦敦'},
|
location: { country: "英国", region: "伦敦" },
|
||||||
type: '住宅',
|
type: "住宅",
|
||||||
status: 'offline',
|
status: "offline",
|
||||||
responseTime: 0,
|
responseTime: 0,
|
||||||
lastCheckTime: '2024-05-10 15:18:33',
|
lastCheckTime: "2024-05-10 15:18:33",
|
||||||
pool: '欧洲高速池',
|
pool: "欧洲高速池",
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'ip-6',
|
id: "ip-6",
|
||||||
ipAddress: '164.83.219.47',
|
ipAddress: "164.83.219.47",
|
||||||
location: {country: '日本', region: '东京'},
|
location: { country: "日本", region: "东京" },
|
||||||
type: '住宅',
|
type: "住宅",
|
||||||
status: 'online',
|
status: "online",
|
||||||
responseTime: 87,
|
responseTime: 87,
|
||||||
lastCheckTime: '2024-05-10 15:15:21',
|
lastCheckTime: "2024-05-10 15:15:21",
|
||||||
pool: '亚太地区池',
|
pool: "亚太地区池",
|
||||||
isStatic: true,
|
isStatic: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'ip-7',
|
id: "ip-7",
|
||||||
ipAddress: '221.67.93.143',
|
ipAddress: "221.67.93.143",
|
||||||
location: {country: '中国', region: '上海'},
|
location: { country: "中国", region: "上海" },
|
||||||
type: '移动',
|
type: "移动",
|
||||||
status: 'online',
|
status: "online",
|
||||||
responseTime: 104,
|
responseTime: 104,
|
||||||
lastCheckTime: '2024-05-10 15:10:46',
|
lastCheckTime: "2024-05-10 15:10:46",
|
||||||
pool: '亚太地区池',
|
pool: "亚太地区池",
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'ip-8',
|
id: "ip-8",
|
||||||
ipAddress: '37.209.148.72',
|
ipAddress: "37.209.148.72",
|
||||||
location: {country: '法国', region: '巴黎'},
|
location: { country: "法国", region: "巴黎" },
|
||||||
type: '数据中心',
|
type: "数据中心",
|
||||||
status: 'warning',
|
status: "warning",
|
||||||
responseTime: 276,
|
responseTime: 276,
|
||||||
lastCheckTime: '2024-05-10 15:05:19',
|
lastCheckTime: "2024-05-10 15:05:19",
|
||||||
pool: '欧洲高速池',
|
pool: "欧洲高速池",
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
@@ -129,16 +129,16 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
// 过滤节点数据
|
// 过滤节点数据
|
||||||
const filteredNodes = nodes.filter(node => {
|
const filteredNodes = nodes.filter(node => {
|
||||||
return (
|
return (
|
||||||
(searchTerm === '' ||
|
(searchTerm === "" ||
|
||||||
node.ipAddress.includes(searchTerm) ||
|
node.ipAddress.includes(searchTerm) ||
|
||||||
node.location.country.includes(searchTerm) ||
|
node.location.country.includes(searchTerm) ||
|
||||||
node.pool.includes(searchTerm)) &&
|
node.pool.includes(searchTerm)) &&
|
||||||
(filterStatus === 'all' ||
|
(filterStatus === "all" ||
|
||||||
(filterStatus === 'online' && node.status === 'online') ||
|
(filterStatus === "online" && node.status === "online") ||
|
||||||
(filterStatus === 'offline' && node.status === 'offline') ||
|
(filterStatus === "offline" && node.status === "offline") ||
|
||||||
(filterStatus === 'warning' && node.status === 'warning')) &&
|
(filterStatus === "warning" && node.status === "warning")) &&
|
||||||
(filterType === 'all' || node.type === filterType) &&
|
(filterType === "all" || node.type === filterType) &&
|
||||||
(filterPool === 'all' || node.pool === filterPool)
|
(filterPool === "all" || node.pool === filterPool)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -151,25 +151,43 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<h1 className="text-lg font-bold text-gray-900">节点列表</h1>
|
<h1 className="text-lg font-bold text-gray-900">节点列表</h1>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<button
|
<button className="bg-gray-50 border border-gray-200 text-gray-700 px-3 py-1.5 rounded-md text-sm font-medium flex items-center hover:bg-gray-100">
|
||||||
className="bg-gray-50 border border-gray-200 text-gray-700 px-3 py-1.5 rounded-md text-sm font-medium flex items-center hover:bg-gray-100">
|
<svg
|
||||||
<svg className="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
className="w-4 h-4 mr-1"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
strokeLinecap="round"
|
||||||
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
导出
|
导出
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button className="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1.5 rounded-md text-sm font-medium flex items-center">
|
||||||
className="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1.5 rounded-md text-sm font-medium flex items-center">
|
<svg
|
||||||
<svg className="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
className="w-4 h-4 mr-1"
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
添加节点
|
添加节点
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p className="mt-1 text-sm text-gray-500">查看和管理所有代理IP资源,支持多维度筛选</p>
|
<p className="mt-1 text-sm text-gray-500">
|
||||||
|
查看和管理所有代理IP资源,支持多维度筛选
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 统计信息区域 - 色块风格 */}
|
{/* 统计信息区域 - 色块风格 */}
|
||||||
@@ -178,15 +196,25 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<div className="bg-white p-4">
|
<div className="bg-white p-4">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="w-10 h-10 flex items-center justify-center bg-blue-50 rounded-md">
|
<div className="w-10 h-10 flex items-center justify-center bg-blue-50 rounded-md">
|
||||||
<svg className="h-5 w-5 text-blue-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg
|
||||||
|
className="h-5 w-5 text-blue-600"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
strokeLinecap="round"
|
||||||
d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-3">
|
<div className="ml-3">
|
||||||
<p className="text-xs font-medium text-gray-500">总IP数量</p>
|
<p className="text-xs font-medium text-gray-500">总IP数量</p>
|
||||||
<div className="text-lg font-semibold text-gray-900">152,487</div>
|
<div className="text-lg font-semibold text-gray-900">
|
||||||
|
152,487
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -195,18 +223,30 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<div className="bg-white p-4">
|
<div className="bg-white p-4">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="w-10 h-10 flex items-center justify-center bg-green-50 rounded-md">
|
<div className="w-10 h-10 flex items-center justify-center bg-green-50 rounded-md">
|
||||||
<svg className="h-5 w-5 text-green-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg
|
||||||
|
className="h-5 w-5 text-green-600"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
strokeLinecap="round"
|
||||||
d="M5 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M5 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-3">
|
<div className="ml-3">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<p className="text-xs font-medium text-gray-500">在线IP</p>
|
<p className="text-xs font-medium text-gray-500">在线IP</p>
|
||||||
<span className="ml-2 text-xs font-medium text-green-600">91%</span>
|
<span className="ml-2 text-xs font-medium text-green-600">
|
||||||
|
91%
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="text-lg font-semibold text-gray-900">
|
||||||
|
138,954
|
||||||
</div>
|
</div>
|
||||||
<div className="text-lg font-semibold text-gray-900">138,954</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -215,16 +255,26 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<div className="bg-white p-4">
|
<div className="bg-white p-4">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="w-10 h-10 flex items-center justify-center bg-indigo-50 rounded-md">
|
<div className="w-10 h-10 flex items-center justify-center bg-indigo-50 rounded-md">
|
||||||
<svg className="h-5 w-5 text-indigo-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg
|
||||||
|
className="h-5 w-5 text-indigo-600"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
strokeLinecap="round"
|
||||||
d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-3">
|
<div className="ml-3">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<p className="text-xs font-medium text-gray-500">IP池分布</p>
|
<p className="text-xs font-medium text-gray-500">IP池分布</p>
|
||||||
<span className="ml-2 text-xs font-medium text-gray-500">5个地区</span>
|
<span className="ml-2 text-xs font-medium text-gray-500">
|
||||||
|
5个地区
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-lg font-semibold text-gray-900">12</div>
|
<div className="text-lg font-semibold text-gray-900">12</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -235,16 +285,26 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<div className="bg-white p-4">
|
<div className="bg-white p-4">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="w-10 h-10 flex items-center justify-center bg-red-50 rounded-md">
|
<div className="w-10 h-10 flex items-center justify-center bg-red-50 rounded-md">
|
||||||
<svg className="h-5 w-5 text-red-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg
|
||||||
|
className="h-5 w-5 text-red-600"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
strokeLinecap="round"
|
||||||
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-3">
|
<div className="ml-3">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<p className="text-xs font-medium text-gray-500">异常IP</p>
|
<p className="text-xs font-medium text-gray-500">异常IP</p>
|
||||||
<span className="ml-2 text-xs font-medium text-red-600">需检查</span>
|
<span className="ml-2 text-xs font-medium text-red-600">
|
||||||
|
需检查
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-lg font-semibold text-gray-900">1,205</div>
|
<div className="text-lg font-semibold text-gray-900">1,205</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -285,7 +345,7 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<select
|
<select
|
||||||
className="px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 text-sm bg-white text-gray-700 flex-1"
|
className="px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 text-sm bg-white text-gray-700 flex-1"
|
||||||
value={filterStatus}
|
value={filterStatus}
|
||||||
onChange={(e) => setFilterStatus(e.target.value)}
|
onChange={e => setFilterStatus(e.target.value)}
|
||||||
>
|
>
|
||||||
<option value="all">全部状态</option>
|
<option value="all">全部状态</option>
|
||||||
<option value="online">在线</option>
|
<option value="online">在线</option>
|
||||||
@@ -296,7 +356,7 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<select
|
<select
|
||||||
className="px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 text-sm bg-white text-gray-700 flex-1"
|
className="px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 text-sm bg-white text-gray-700 flex-1"
|
||||||
value={filterType}
|
value={filterType}
|
||||||
onChange={(e) => setFilterType(e.target.value)}
|
onChange={e => setFilterType(e.target.value)}
|
||||||
>
|
>
|
||||||
<option value="all">全部类型</option>
|
<option value="all">全部类型</option>
|
||||||
<option value="数据中心">数据中心</option>
|
<option value="数据中心">数据中心</option>
|
||||||
@@ -307,7 +367,7 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<select
|
<select
|
||||||
className="px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 text-sm bg-white text-gray-700 flex-1"
|
className="px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 text-sm bg-white text-gray-700 flex-1"
|
||||||
value={filterPool}
|
value={filterPool}
|
||||||
onChange={(e) => setFilterPool(e.target.value)}
|
onChange={e => setFilterPool(e.target.value)}
|
||||||
>
|
>
|
||||||
<option value="all">全部池</option>
|
<option value="all">全部池</option>
|
||||||
<option value="北美专用池">北美专用池</option>
|
<option value="北美专用池">北美专用池</option>
|
||||||
@@ -327,7 +387,14 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
fill="none"
|
fill="none"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
>
|
>
|
||||||
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
|
<circle
|
||||||
|
className="opacity-25"
|
||||||
|
cx="12"
|
||||||
|
cy="12"
|
||||||
|
r="10"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="4"
|
||||||
|
></circle>
|
||||||
<path
|
<path
|
||||||
className="opacity-75"
|
className="opacity-75"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
@@ -340,79 +407,133 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<table className="min-w-full">
|
<table className="min-w-full">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col" className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50">
|
<th
|
||||||
|
scope="col"
|
||||||
|
className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50"
|
||||||
|
>
|
||||||
IP地址
|
IP地址
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50">
|
<th
|
||||||
|
scope="col"
|
||||||
|
className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50"
|
||||||
|
>
|
||||||
位置
|
位置
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50">
|
<th
|
||||||
|
scope="col"
|
||||||
|
className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50"
|
||||||
|
>
|
||||||
类型
|
类型
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50">
|
<th
|
||||||
|
scope="col"
|
||||||
|
className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50"
|
||||||
|
>
|
||||||
状态
|
状态
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50">
|
<th
|
||||||
|
scope="col"
|
||||||
|
className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50"
|
||||||
|
>
|
||||||
响应时间
|
响应时间
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50">
|
<th
|
||||||
|
scope="col"
|
||||||
|
className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50"
|
||||||
|
>
|
||||||
所属池
|
所属池
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" className="px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50">
|
<th
|
||||||
|
scope="col"
|
||||||
|
className="px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider border-b border-gray-200 bg-gray-50"
|
||||||
|
>
|
||||||
操作
|
操作
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="divide-y divide-gray-200">
|
<tbody className="divide-y divide-gray-200">
|
||||||
{filteredNodes.map((node, index) => (
|
{filteredNodes.map((node, index) => (
|
||||||
<tr key={node.id} className={index % 2 === 0 ? 'bg-white' : 'bg-gray-50'}>
|
<tr
|
||||||
|
key={node.id}
|
||||||
|
className={index % 2 === 0 ? "bg-white" : "bg-gray-50"}
|
||||||
|
>
|
||||||
<td className="px-4 py-3 whitespace-nowrap text-sm">
|
<td className="px-4 py-3 whitespace-nowrap text-sm">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<span className={`w-2 h-2 rounded-full mr-2 ${
|
<span
|
||||||
node.status === 'online' ? 'bg-green-500' :
|
className={`w-2 h-2 rounded-full mr-2 ${
|
||||||
node.status === 'offline' ? 'bg-red-500' : 'bg-yellow-500'
|
node.status === "online"
|
||||||
}`}></span>
|
? "bg-green-500"
|
||||||
<span className="font-medium text-gray-900">{node.ipAddress}</span>
|
: node.status === "offline"
|
||||||
|
? "bg-red-500"
|
||||||
|
: "bg-yellow-500"
|
||||||
|
}`}
|
||||||
|
></span>
|
||||||
|
<span className="font-medium text-gray-900">
|
||||||
|
{node.ipAddress}
|
||||||
|
</span>
|
||||||
{node.isStatic && (
|
{node.isStatic && (
|
||||||
<span className="ml-2 inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
|
<span className="ml-2 inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
|
||||||
静态
|
静态
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td className="px-4 py-3 whitespace-nowrap text-sm">
|
<td className="px-4 py-3 whitespace-nowrap text-sm">
|
||||||
<div className="text-gray-900">{node.location.country}</div>
|
<div className="text-gray-900">
|
||||||
<div className="text-xs text-gray-500">{node.location.region}</div>
|
{node.location.country}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-gray-500">
|
||||||
|
{node.location.region}
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td className="px-4 py-3 whitespace-nowrap">
|
<td className="px-4 py-3 whitespace-nowrap">
|
||||||
<span className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${
|
<span
|
||||||
node.type === '数据中心' ? 'bg-purple-100 text-purple-800' :
|
className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${
|
||||||
node.type === '住宅' ? 'bg-blue-100 text-blue-800' : 'bg-indigo-100 text-indigo-800'
|
node.type === "数据中心"
|
||||||
}`}>
|
? "bg-purple-100 text-purple-800"
|
||||||
{node.type}
|
: node.type === "住宅"
|
||||||
</span>
|
? "bg-blue-100 text-blue-800"
|
||||||
|
: "bg-indigo-100 text-indigo-800"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{node.type}
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td className="px-4 py-3 whitespace-nowrap text-sm">
|
<td className="px-4 py-3 whitespace-nowrap text-sm">
|
||||||
<span className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${
|
<span
|
||||||
node.status === 'online' ? 'bg-green-100 text-green-800' :
|
className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium ${
|
||||||
node.status === 'offline' ? 'bg-red-100 text-red-800' : 'bg-yellow-100 text-yellow-800'
|
node.status === "online"
|
||||||
}`}>
|
? "bg-green-100 text-green-800"
|
||||||
{node.status === 'online' ? '在线' : node.status === 'offline' ? '离线' : '异常'}
|
: node.status === "offline"
|
||||||
</span>
|
? "bg-red-100 text-red-800"
|
||||||
|
: "bg-yellow-100 text-yellow-800"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{node.status === "online"
|
||||||
|
? "在线"
|
||||||
|
: node.status === "offline"
|
||||||
|
? "离线"
|
||||||
|
: "异常"}
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td className="px-4 py-3 whitespace-nowrap text-sm text-gray-500">
|
<td className="px-4 py-3 whitespace-nowrap text-sm text-gray-500">
|
||||||
{node.responseTime > 0 ? (
|
{node.responseTime > 0 ? (
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<span className={`font-medium ${
|
<span
|
||||||
node.responseTime < 150 ? 'text-green-600' :
|
className={`font-medium ${
|
||||||
node.responseTime < 250 ? 'text-yellow-600' : 'text-red-600'
|
node.responseTime < 150
|
||||||
}`}>
|
? "text-green-600"
|
||||||
{node.responseTime} ms
|
: node.responseTime < 250
|
||||||
</span>
|
? "text-yellow-600"
|
||||||
|
: "text-red-600"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{node.responseTime} ms
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-gray-400">-</span>
|
<span className="text-gray-400">-</span>
|
||||||
@@ -424,7 +545,10 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td className="px-4 py-3 whitespace-nowrap text-right text-sm font-medium space-x-2">
|
<td className="px-4 py-3 whitespace-nowrap text-right text-sm font-medium space-x-2">
|
||||||
<Link href={`/proxy/nodes/${node.id}`} className="text-blue-600 hover:text-blue-900">
|
<Link
|
||||||
|
href={`/proxy/nodes/${node.id}`}
|
||||||
|
className="text-blue-600 hover:text-blue-900"
|
||||||
|
>
|
||||||
详情
|
详情
|
||||||
</Link>
|
</Link>
|
||||||
<button className="text-gray-600 hover:text-gray-900">
|
<button className="text-gray-600 hover:text-gray-900">
|
||||||
@@ -442,47 +566,53 @@ export default function ProxyNodesPage(props: ProxyNodesPageProps) {
|
|||||||
<div className="bg-gray-50 px-5 py-3 border-t border-gray-200">
|
<div className="bg-gray-50 px-5 py-3 border-t border-gray-200">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div className="text-sm text-gray-700">
|
<div className="text-sm text-gray-700">
|
||||||
显示 <span className="font-medium">1</span> 至 <span className="font-medium">8</span> 条,共 <span
|
显示 <span className="font-medium">1</span> 至{" "}
|
||||||
className="font-medium">152,487</span> 条结果
|
<span className="font-medium">8</span> 条,共{" "}
|
||||||
|
<span className="font-medium">152,487</span> 条结果
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<nav className="relative z-0 inline-flex -space-x-px">
|
<nav className="relative z-0 inline-flex -space-x-px">
|
||||||
<button
|
<button className="relative inline-flex items-center px-2 py-1.5 rounded-l-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
|
||||||
className="relative inline-flex items-center px-2 py-1.5 rounded-l-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
|
<svg
|
||||||
<svg className="h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
className="h-4 w-4"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
fill="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
fillRule="evenodd"
|
fillRule="evenodd"
|
||||||
d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"
|
d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"
|
||||||
clipRule="evenodd"/>
|
clipRule="evenodd"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium hover:bg-gray-50 text-blue-600 bg-blue-50 border-blue-300">
|
||||||
className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium hover:bg-gray-50 text-blue-600 bg-blue-50 border-blue-300">
|
|
||||||
1
|
1
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50">
|
||||||
className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50">
|
|
||||||
2
|
2
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50">
|
||||||
className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50">
|
|
||||||
3
|
3
|
||||||
</button>
|
</button>
|
||||||
<span
|
<span className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium text-gray-700">
|
||||||
className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium text-gray-700">
|
...
|
||||||
...
|
</span>
|
||||||
</span>
|
<button className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50">
|
||||||
<button
|
|
||||||
className="relative inline-flex items-center px-3 py-1.5 border border-gray-300 bg-white text-sm font-medium text-gray-700 hover:bg-gray-50">
|
|
||||||
152
|
152
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button className="relative inline-flex items-center px-2 py-1.5 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
|
||||||
className="relative inline-flex items-center px-2 py-1.5 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
|
<svg
|
||||||
<svg className="h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
className="h-4 w-4"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
fill="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
fillRule="evenodd"
|
fillRule="evenodd"
|
||||||
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
|
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
|
||||||
clipRule="evenodd"/>
|
clipRule="evenodd"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
'use client'
|
"use client"
|
||||||
import {useState, useEffect} from 'react'
|
import Link from "next/link"
|
||||||
import Link from 'next/link'
|
import { useEffect, useState } from "react"
|
||||||
|
|
||||||
export type ProxyPoolsPageProps = {}
|
export type ProxyPoolsPageProps = {}
|
||||||
|
|
||||||
// 定义IP池接口
|
// 定义IP池接口
|
||||||
interface ProxyPool {
|
interface ProxyPool {
|
||||||
id: string;
|
id: string
|
||||||
name: string;
|
name: string
|
||||||
description: string;
|
description: string
|
||||||
ips: number;
|
ips: number
|
||||||
activeIps: number;
|
activeIps: number
|
||||||
region: string;
|
region: string
|
||||||
type: string;
|
type: string
|
||||||
createdAt: string;
|
createdAt: string
|
||||||
status: 'active' | 'inactive' | 'maintenance';
|
status: "active" | "inactive" | "maintenance"
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
||||||
const [pools, setPools] = useState<ProxyPool[]>([])
|
const [pools, setPools] = useState<ProxyPool[]>([])
|
||||||
const [loading, setLoading] = useState<boolean>(true)
|
const [loading, setLoading] = useState<boolean>(true)
|
||||||
const [searchTerm, setSearchTerm] = useState<string>('')
|
const [searchTerm, setSearchTerm] = useState<string>("")
|
||||||
const [filterStatus, setFilterStatus] = useState<string>('all')
|
const [filterStatus, setFilterStatus] = useState<string>("all")
|
||||||
const [filterRegion, setFilterRegion] = useState<string>('all')
|
const [filterRegion, setFilterRegion] = useState<string>("all")
|
||||||
|
|
||||||
// 模拟数据加载
|
// 模拟数据加载
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -30,59 +30,59 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setPools([
|
setPools([
|
||||||
{
|
{
|
||||||
id: 'pool-1',
|
id: "pool-1",
|
||||||
name: '全球通用池',
|
name: "全球通用池",
|
||||||
description: '包含全球多个地区的高质量IP',
|
description: "包含全球多个地区的高质量IP",
|
||||||
ips: 5000,
|
ips: 5000,
|
||||||
activeIps: 4328,
|
activeIps: 4328,
|
||||||
region: '全球',
|
region: "全球",
|
||||||
type: '住宅IP',
|
type: "住宅IP",
|
||||||
createdAt: '2023-10-15',
|
createdAt: "2023-10-15",
|
||||||
status: 'active',
|
status: "active",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'pool-2',
|
id: "pool-2",
|
||||||
name: '北美专用池',
|
name: "北美专用池",
|
||||||
description: '美国和加拿大地区专用IP池',
|
description: "美国和加拿大地区专用IP池",
|
||||||
ips: 3200,
|
ips: 3200,
|
||||||
activeIps: 2950,
|
activeIps: 2950,
|
||||||
region: '北美',
|
region: "北美",
|
||||||
type: '数据中心IP',
|
type: "数据中心IP",
|
||||||
createdAt: '2023-11-02',
|
createdAt: "2023-11-02",
|
||||||
status: 'active',
|
status: "active",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'pool-3',
|
id: "pool-3",
|
||||||
name: '欧洲高速池',
|
name: "欧洲高速池",
|
||||||
description: '欧洲地区高速稳定IP',
|
description: "欧洲地区高速稳定IP",
|
||||||
ips: 2800,
|
ips: 2800,
|
||||||
activeIps: 2180,
|
activeIps: 2180,
|
||||||
region: '欧洲',
|
region: "欧洲",
|
||||||
type: '住宅IP',
|
type: "住宅IP",
|
||||||
createdAt: '2023-09-28',
|
createdAt: "2023-09-28",
|
||||||
status: 'active',
|
status: "active",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'pool-4',
|
id: "pool-4",
|
||||||
name: '亚太地区池',
|
name: "亚太地区池",
|
||||||
description: '亚洲和太平洋地区IP',
|
description: "亚洲和太平洋地区IP",
|
||||||
ips: 4200,
|
ips: 4200,
|
||||||
activeIps: 3890,
|
activeIps: 3890,
|
||||||
region: '亚太',
|
region: "亚太",
|
||||||
type: '移动IP',
|
type: "移动IP",
|
||||||
createdAt: '2023-12-05',
|
createdAt: "2023-12-05",
|
||||||
status: 'maintenance',
|
status: "maintenance",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'pool-5',
|
id: "pool-5",
|
||||||
name: '电商专用池',
|
name: "电商专用池",
|
||||||
description: '适用于电商平台的IP池',
|
description: "适用于电商平台的IP池",
|
||||||
ips: 1500,
|
ips: 1500,
|
||||||
activeIps: 1200,
|
activeIps: 1200,
|
||||||
region: '全球',
|
region: "全球",
|
||||||
type: '住宅IP',
|
type: "住宅IP",
|
||||||
createdAt: '2024-01-10',
|
createdAt: "2024-01-10",
|
||||||
status: 'inactive',
|
status: "inactive",
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@@ -92,25 +92,25 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
// 过滤IP池
|
// 过滤IP池
|
||||||
const filteredPools = pools.filter(pool => {
|
const filteredPools = pools.filter(pool => {
|
||||||
return (
|
return (
|
||||||
(searchTerm === '' ||
|
(searchTerm === "" ||
|
||||||
pool.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
pool.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||||
pool.description.toLowerCase().includes(searchTerm.toLowerCase())) &&
|
pool.description.toLowerCase().includes(searchTerm.toLowerCase())) &&
|
||||||
(filterStatus === 'all' || pool.status === filterStatus) &&
|
(filterStatus === "all" || pool.status === filterStatus) &&
|
||||||
(filterRegion === 'all' || pool.region === filterRegion)
|
(filterRegion === "all" || pool.region === filterRegion)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 获取状态颜色和文本
|
// 获取状态颜色和文本
|
||||||
const getStatusInfo = (status: string) => {
|
const getStatusInfo = (status: string) => {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 'active':
|
case "active":
|
||||||
return {color: 'bg-green-100 text-green-800', text: '运行中'}
|
return { color: "bg-green-100 text-green-800", text: "运行中" }
|
||||||
case 'inactive':
|
case "inactive":
|
||||||
return {color: 'bg-gray-100 text-gray-800', text: '未启用'}
|
return { color: "bg-gray-100 text-gray-800", text: "未启用" }
|
||||||
case 'maintenance':
|
case "maintenance":
|
||||||
return {color: 'bg-yellow-100 text-yellow-800', text: '维护中'}
|
return { color: "bg-yellow-100 text-yellow-800", text: "维护中" }
|
||||||
default:
|
default:
|
||||||
return {color: 'bg-gray-100 text-gray-800', text: '未知'}
|
return { color: "bg-gray-100 text-gray-800", text: "未知" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,10 +122,19 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
<h1 className="text-2xl font-bold text-gray-900">IP池管理</h1>
|
<h1 className="text-2xl font-bold text-gray-900">IP池管理</h1>
|
||||||
<p className="mt-1 text-sm text-gray-500">管理和配置代理IP池</p>
|
<p className="mt-1 text-sm text-gray-500">管理和配置代理IP池</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button className="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium flex items-center">
|
||||||
className="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium flex items-center">
|
<svg
|
||||||
<svg className="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
className="w-4 h-4 mr-2"
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6v6m0 0v6m0-6h6m-6 0H6"/>
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M12 6v6m0 0v6m0-6h6m-6 0H6"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
创建新IP池
|
创建新IP池
|
||||||
</button>
|
</button>
|
||||||
@@ -140,7 +149,7 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
placeholder="搜索IP池..."
|
placeholder="搜索IP池..."
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
|
className="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onChange={(e) => setSearchTerm(e.target.value)}
|
onChange={e => setSearchTerm(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<svg
|
<svg
|
||||||
className="absolute right-3 top-2.5 h-5 w-5 text-gray-400"
|
className="absolute right-3 top-2.5 h-5 w-5 text-gray-400"
|
||||||
@@ -159,11 +168,13 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
|
|
||||||
<div className="flex space-x-4">
|
<div className="flex space-x-4">
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">状态</label>
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
|
状态
|
||||||
|
</label>
|
||||||
<select
|
<select
|
||||||
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
|
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
|
||||||
value={filterStatus}
|
value={filterStatus}
|
||||||
onChange={(e) => setFilterStatus(e.target.value)}
|
onChange={e => setFilterStatus(e.target.value)}
|
||||||
>
|
>
|
||||||
<option value="all">全部状态</option>
|
<option value="all">全部状态</option>
|
||||||
<option value="active">运行中</option>
|
<option value="active">运行中</option>
|
||||||
@@ -174,11 +185,13 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">地区</label>
|
<label className="block text-sm font-medium text-gray-700 mb-1">
|
||||||
|
地区
|
||||||
|
</label>
|
||||||
<select
|
<select
|
||||||
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
|
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
|
||||||
value={filterRegion}
|
value={filterRegion}
|
||||||
onChange={(e) => setFilterRegion(e.target.value)}
|
onChange={e => setFilterRegion(e.target.value)}
|
||||||
>
|
>
|
||||||
<option value="all">全部地区</option>
|
<option value="all">全部地区</option>
|
||||||
<option value="全球">全球</option>
|
<option value="全球">全球</option>
|
||||||
@@ -195,20 +208,40 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="p-8 flex justify-center">
|
<div className="p-8 flex justify-center">
|
||||||
<svg
|
<svg
|
||||||
className="animate-spin h-8 w-8 text-blue-600" xmlns="http://www.w3.org/2000/svg" fill="none"
|
className="animate-spin h-8 w-8 text-blue-600"
|
||||||
viewBox="0 0 24 24">
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
|
<circle
|
||||||
|
className="opacity-25"
|
||||||
|
cx="12"
|
||||||
|
cy="12"
|
||||||
|
r="10"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="4"
|
||||||
|
></circle>
|
||||||
<path
|
<path
|
||||||
className="opacity-75" fill="currentColor"
|
className="opacity-75"
|
||||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
fill="currentColor"
|
||||||
|
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||||
|
></path>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
) : filteredPools.length === 0 ? (
|
) : filteredPools.length === 0 ? (
|
||||||
<div className="p-8 text-center">
|
<div className="p-8 text-center">
|
||||||
<svg className="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg
|
||||||
|
className="mx-auto h-12 w-12 text-gray-400"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={1.5}
|
strokeLinecap="round"
|
||||||
d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={1.5}
|
||||||
|
d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
<p className="mt-4 text-gray-500 text-lg">没有找到匹配的IP池</p>
|
<p className="mt-4 text-gray-500 text-lg">没有找到匹配的IP池</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -219,73 +252,93 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
<tr>
|
<tr>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
|
>
|
||||||
IP池名称
|
IP池名称
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
|
>
|
||||||
IP概况
|
IP概况
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
|
>
|
||||||
地区
|
地区
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
|
>
|
||||||
IP类型
|
IP类型
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
|
>
|
||||||
状态
|
状态
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
|
>
|
||||||
创建日期
|
创建日期
|
||||||
</th>
|
</th>
|
||||||
<th
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider"
|
||||||
|
>
|
||||||
操作
|
操作
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody className="bg-white divide-y divide-gray-200">
|
<tbody className="bg-white divide-y divide-gray-200">
|
||||||
{filteredPools.map((pool) => {
|
{filteredPools.map(pool => {
|
||||||
const statusInfo = getStatusInfo(pool.status)
|
const statusInfo = getStatusInfo(pool.status)
|
||||||
return (
|
return (
|
||||||
<tr key={pool.id} className="hover:bg-gray-50">
|
<tr key={pool.id} className="hover:bg-gray-50">
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div>
|
<div>
|
||||||
<div className="text-sm font-medium text-gray-900">{pool.name}</div>
|
<div className="text-sm font-medium text-gray-900">
|
||||||
<div className="text-sm text-gray-500 max-w-xs truncate">{pool.description}</div>
|
{pool.name}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm text-gray-500 max-w-xs truncate">
|
||||||
|
{pool.description}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
<div className="text-sm text-gray-900">总IP: {pool.ips.toLocaleString()}</div>
|
<div className="text-sm text-gray-900">
|
||||||
<div className="text-sm text-gray-500">活跃IP: {pool.activeIps.toLocaleString()}</div>
|
总IP: {pool.ips.toLocaleString()}
|
||||||
|
</div>
|
||||||
|
<div className="text-sm text-gray-500">
|
||||||
|
活跃IP: {pool.activeIps.toLocaleString()}
|
||||||
|
</div>
|
||||||
<div className="w-full bg-gray-200 rounded-full h-1.5 mt-1.5">
|
<div className="w-full bg-gray-200 rounded-full h-1.5 mt-1.5">
|
||||||
<div
|
<div
|
||||||
className="bg-blue-600 h-1.5 rounded-full"
|
className="bg-blue-600 h-1.5 rounded-full"
|
||||||
style={{width: `${(pool.activeIps / pool.ips) * 100}%`}}
|
style={{
|
||||||
|
width: `${(pool.activeIps / pool.ips) * 100}%`,
|
||||||
|
}}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
<div className="text-sm text-gray-900">{pool.region}</div>
|
<div className="text-sm text-gray-900">
|
||||||
|
{pool.region}
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
<div className="text-sm text-gray-900">{pool.type}</div>
|
<div className="text-sm text-gray-900">{pool.type}</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
<span
|
<span
|
||||||
className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${statusInfo.color}`}>
|
className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${statusInfo.color}`}
|
||||||
|
>
|
||||||
{statusInfo.text}
|
{statusInfo.text}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
@@ -293,11 +346,16 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
{pool.createdAt}
|
{pool.createdAt}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||||
<Link href={`/proxy/pools/${pool.id}`} className="text-blue-600 hover:text-blue-900 mr-4">
|
<Link
|
||||||
|
href={`/proxy/pools/${pool.id}`}
|
||||||
|
className="text-blue-600 hover:text-blue-900 mr-4"
|
||||||
|
>
|
||||||
详情
|
详情
|
||||||
</Link>
|
</Link>
|
||||||
<Link
|
<Link
|
||||||
href={`/proxy/pools/${pool.id}/edit`} className="text-indigo-600 hover:text-indigo-900 mr-4">
|
href={`/proxy/pools/${pool.id}/edit`}
|
||||||
|
className="text-indigo-600 hover:text-indigo-900 mr-4"
|
||||||
|
>
|
||||||
编辑
|
编辑
|
||||||
</Link>
|
</Link>
|
||||||
<button className="text-red-600 hover:text-red-900">
|
<button className="text-red-600 hover:text-red-900">
|
||||||
@@ -318,10 +376,18 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
<div className="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
|
<div className="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="p-3 rounded-full bg-blue-100 text-blue-600">
|
<div className="p-3 rounded-full bg-blue-100 text-blue-600">
|
||||||
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg
|
||||||
|
className="h-6 w-6"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
strokeLinecap="round"
|
||||||
d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-4">
|
<div className="ml-4">
|
||||||
@@ -332,7 +398,9 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
<div className="mt-4">
|
<div className="mt-4">
|
||||||
<div className="flex justify-between text-sm">
|
<div className="flex justify-between text-sm">
|
||||||
<span className="text-gray-500">活跃IP池</span>
|
<span className="text-gray-500">活跃IP池</span>
|
||||||
<span className="font-medium text-gray-900">{pools.filter(p => p.status === 'active').length}</span>
|
<span className="font-medium text-gray-900">
|
||||||
|
{pools.filter(p => p.status === "active").length}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -340,16 +408,26 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
<div className="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
|
<div className="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="p-3 rounded-full bg-green-100 text-green-600">
|
<div className="p-3 rounded-full bg-green-100 text-green-600">
|
||||||
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg
|
||||||
|
className="h-6 w-6"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
strokeLinecap="round"
|
||||||
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-4">
|
<div className="ml-4">
|
||||||
<h3 className="text-lg font-medium text-gray-900">总IP数量</h3>
|
<h3 className="text-lg font-medium text-gray-900">总IP数量</h3>
|
||||||
<div className="mt-1 text-3xl font-semibold">
|
<div className="mt-1 text-3xl font-semibold">
|
||||||
{pools.reduce((sum, pool) => sum + pool.ips, 0).toLocaleString()}
|
{pools
|
||||||
|
.reduce((sum, pool) => sum + pool.ips, 0)
|
||||||
|
.toLocaleString()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -357,7 +435,9 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
<div className="flex justify-between text-sm">
|
<div className="flex justify-between text-sm">
|
||||||
<span className="text-gray-500">活跃IP</span>
|
<span className="text-gray-500">活跃IP</span>
|
||||||
<span className="font-medium text-gray-900">
|
<span className="font-medium text-gray-900">
|
||||||
{pools.reduce((sum, pool) => sum + pool.activeIps, 0).toLocaleString()}
|
{pools
|
||||||
|
.reduce((sum, pool) => sum + pool.activeIps, 0)
|
||||||
|
.toLocaleString()}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -366,17 +446,29 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
<div className="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
|
<div className="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<div className="p-3 rounded-full bg-purple-100 text-purple-600">
|
<div className="p-3 rounded-full bg-purple-100 text-purple-600">
|
||||||
<svg className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg
|
||||||
|
className="h-6 w-6"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
strokeLinecap="round"
|
||||||
d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-4">
|
<div className="ml-4">
|
||||||
<h3 className="text-lg font-medium text-gray-900">IP利用率</h3>
|
<h3 className="text-lg font-medium text-gray-900">IP利用率</h3>
|
||||||
<div className="mt-1 text-3xl font-semibold">
|
<div className="mt-1 text-3xl font-semibold">
|
||||||
{Math.round((pools.reduce((sum, pool) => sum + pool.activeIps, 0) /
|
{Math.round(
|
||||||
pools.reduce((sum, pool) => sum + pool.ips, 0)) * 100)}%
|
(pools.reduce((sum, pool) => sum + pool.activeIps, 0) /
|
||||||
|
pools.reduce((sum, pool) => sum + pool.ips, 0)) *
|
||||||
|
100,
|
||||||
|
)}
|
||||||
|
%
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -385,8 +477,11 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
<div
|
<div
|
||||||
className="bg-purple-600 h-2 rounded-full"
|
className="bg-purple-600 h-2 rounded-full"
|
||||||
style={{
|
style={{
|
||||||
width: `${(pools.reduce((sum, pool) => sum + pool.activeIps, 0) /
|
width: `${
|
||||||
pools.reduce((sum, pool) => sum + pool.ips, 0)) * 100}%`,
|
(pools.reduce((sum, pool) => sum + pool.activeIps, 0) /
|
||||||
|
pools.reduce((sum, pool) => sum + pool.ips, 0)) *
|
||||||
|
100
|
||||||
|
}%`,
|
||||||
}}
|
}}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
@@ -398,10 +493,18 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
<div className="bg-blue-50 p-4 rounded-lg border border-blue-200">
|
<div className="bg-blue-50 p-4 rounded-lg border border-blue-200">
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
<div className="flex-shrink-0">
|
<div className="flex-shrink-0">
|
||||||
<svg className="h-5 w-5 text-blue-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
<svg
|
||||||
|
className="h-5 w-5 text-blue-600"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
stroke="currentColor"
|
||||||
|
>
|
||||||
<path
|
<path
|
||||||
strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
|
strokeLinecap="round"
|
||||||
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
strokeLinejoin="round"
|
||||||
|
strokeWidth={2}
|
||||||
|
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-3 flex-1 md:flex md:justify-between">
|
<div className="ml-3 flex-1 md:flex md:justify-between">
|
||||||
@@ -409,7 +512,10 @@ export default function ProxyPoolsPage(props: ProxyPoolsPageProps) {
|
|||||||
IP池是管理IP资源的基础单位。您可以创建不同用途的IP池,并为客户分配相应的访问权限。
|
IP池是管理IP资源的基础单位。您可以创建不同用途的IP池,并为客户分配相应的访问权限。
|
||||||
</p>
|
</p>
|
||||||
<p className="mt-3 text-sm md:mt-0 md:ml-6">
|
<p className="mt-3 text-sm md:mt-0 md:ml-6">
|
||||||
<a href="/help/proxy-pools" className="whitespace-nowrap font-medium text-blue-700 hover:text-blue-600">
|
<a
|
||||||
|
href="/help/proxy-pools"
|
||||||
|
className="whitespace-nowrap font-medium text-blue-700 hover:text-blue-600"
|
||||||
|
>
|
||||||
查看文档 <span aria-hidden="true">→</span>
|
查看文档 <span aria-hidden="true">→</span>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -1,10 +1,172 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { Suspense } from "react"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { listResourceLong, listResourceShort } from "@/actions/resources"
|
import { format, isBefore, isSameDay } from "date-fns"
|
||||||
|
import { Box, Loader2, Timer } from "lucide-react"
|
||||||
|
import { Suspense, useCallback, useMemo, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import {
|
||||||
|
listResourceLong,
|
||||||
|
listResourceShort,
|
||||||
|
updateResource,
|
||||||
|
} from "@/actions/resources"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Badge } from "@/components/ui/badge"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||||
import type { Resources } from "@/models/resources"
|
import type { Resources } from "@/models/resources"
|
||||||
|
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
user_phone: z.string().optional(),
|
||||||
|
resource_no: z.string().optional(),
|
||||||
|
status: z.string().optional(),
|
||||||
|
type: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: z.string().optional(),
|
||||||
|
expired: z.string().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.created_at_start && data.created_at_end) {
|
||||||
|
const start = new Date(data.created_at_start)
|
||||||
|
const end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
if (end < start) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "结束时间不能早于开始时间",
|
||||||
|
path: ["created_at_end"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
type FormValues = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
|
interface FilterParams {
|
||||||
|
user_phone?: string
|
||||||
|
resource_no?: string
|
||||||
|
active?: boolean
|
||||||
|
mode?: number
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
expired?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取资源类型
|
||||||
|
function getResourceType(resource: Resources): number {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short.type
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long.type
|
||||||
|
}
|
||||||
|
return resource.type
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取资源详情对象
|
||||||
|
function getResourceDetail(resource: Resources) {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取过期时间
|
||||||
|
function getExpireAt(resource: Resources): Date | null | undefined {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short.expire_at
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long.expire_at
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function getName(resource: Resources): string | null | undefined {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short.sku?.name
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long.sku?.name
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取最近使用时间
|
||||||
|
function getLastAt(resource: Resources): Date | null | undefined {
|
||||||
|
if ("short" in resource && resource.short) {
|
||||||
|
return resource.short.last_at
|
||||||
|
}
|
||||||
|
if ("long" in resource && resource.long) {
|
||||||
|
return resource.long.last_at
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
// 资源类型徽章
|
||||||
|
function ResourceTypeBadge({ resource }: { resource: Resources }) {
|
||||||
|
const type = getResourceType(resource)
|
||||||
|
if (type === 1) {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2 items-center bg-green-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<Timer size={20} />
|
||||||
|
<span>包时</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (type === 2) {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2 items-center bg-blue-50 w-fit px-2 py-1 rounded-md">
|
||||||
|
<Box size={20} />
|
||||||
|
<span>包量</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过期徽章
|
||||||
|
function ExpireBadge({ expireAt }: { expireAt: Date | null | undefined }) {
|
||||||
|
if (!expireAt) return null
|
||||||
|
if (isBefore(expireAt, new Date())) {
|
||||||
|
return <Badge variant="destructive">过期</Badge>
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化日期
|
||||||
|
function formatDateTime(date: Date | null | undefined) {
|
||||||
|
if (!date) return "-"
|
||||||
|
return format(date, "yyyy-MM-dd HH:mm")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算今日使用量
|
||||||
|
function getTodayUsage(lastAt: Date | null | undefined, daily: number) {
|
||||||
|
if (lastAt && isSameDay(lastAt, new Date())) {
|
||||||
|
return daily
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
export default function ResourcesPage() {
|
export default function ResourcesPage() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -41,21 +203,364 @@ interface ResourceListProps {
|
|||||||
function ResourceList({ resourceType }: ResourceListProps) {
|
function ResourceList({ resourceType }: ResourceListProps) {
|
||||||
const isLong = resourceType === "long"
|
const isLong = resourceType === "long"
|
||||||
const listFn = isLong ? listResourceLong : listResourceShort
|
const listFn = isLong ? listResourceLong : listResourceShort
|
||||||
const table = useDataTable<Resources>((page, size) => listFn({ page, size }))
|
const [filters, setFilters] = useState<FilterParams>({})
|
||||||
|
const [updatingId, setUpdatingId] = useState<number | null>(null)
|
||||||
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
user_phone: "",
|
||||||
|
resource_no: "",
|
||||||
|
status: "all",
|
||||||
|
type: "all",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
expired: "all",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const fetchResources = useCallback(
|
||||||
|
(page: number, size: number) => {
|
||||||
|
return listFn({ page, size, ...filters })
|
||||||
|
},
|
||||||
|
[listFn, filters],
|
||||||
|
)
|
||||||
|
|
||||||
|
const table = useDataTable<Resources>(fetchResources)
|
||||||
|
console.log(table, "我的套餐的table")
|
||||||
|
const refreshTable = useCallback(() => {
|
||||||
|
setFilters(prev => ({ ...prev }))
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const handleStatusChange = useCallback(
|
||||||
|
async (resource: Resources, newStatusValue: string) => {
|
||||||
|
const newActive = newStatusValue === "0"
|
||||||
|
if (newActive === resource.active) return
|
||||||
|
setUpdatingId(resource.id)
|
||||||
|
try {
|
||||||
|
await updateResource({
|
||||||
|
id: resource.id,
|
||||||
|
active: newActive,
|
||||||
|
})
|
||||||
|
toast.success("更新成功", {
|
||||||
|
description: `资源状态已更新为${newActive ? "启用" : "禁用"}`,
|
||||||
|
})
|
||||||
|
refreshTable()
|
||||||
|
} catch (error) {
|
||||||
|
console.error("更新状态失败:", error)
|
||||||
|
toast.error("更新失败", {
|
||||||
|
description: error instanceof Error ? error.message : "请稍后重试",
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
setUpdatingId(null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[refreshTable],
|
||||||
|
)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterParams = {}
|
||||||
|
if (data.user_phone?.trim()) result.user_phone = data.user_phone.trim()
|
||||||
|
if (data.resource_no?.trim()) result.resource_no = data.resource_no.trim()
|
||||||
|
if (data.status && data.status !== "all") {
|
||||||
|
result.active = data.status === "0"
|
||||||
|
}
|
||||||
|
if (data.type && data.type !== "all") {
|
||||||
|
result.mode = Number(data.type)
|
||||||
|
}
|
||||||
|
if (data.expired && data.expired !== "all") {
|
||||||
|
result.expired = data.expired === "1"
|
||||||
|
}
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
const columns = useMemo(
|
||||||
|
() => [
|
||||||
|
{ header: "ID", accessorKey: "id" },
|
||||||
|
{
|
||||||
|
header: "会员号",
|
||||||
|
accessorFn: (row: Resources) => row.user?.phone || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "套餐",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const resourceNo = row.original.resource_no
|
||||||
|
const name = getName(row.original)
|
||||||
|
const expireAt = getExpireAt(row.original)
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<div>{name}</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-xs text-gray-500">{resourceNo}</span>
|
||||||
|
<ExpireBadge expireAt={expireAt} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "类型",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
return <ResourceTypeBadge resource={row.original} />
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "IP时效",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const detail = getResourceDetail(row.original)
|
||||||
|
const live = detail?.live
|
||||||
|
if (live === undefined) return "-"
|
||||||
|
return <span>{isLong ? `${live}小时` : `${live}分钟`}</span>
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "使用情况",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const detail = getResourceDetail(row.original)
|
||||||
|
const type = getResourceType(row.original)
|
||||||
|
|
||||||
|
if (!detail) return <span>-</span>
|
||||||
|
|
||||||
|
if (type === 1) {
|
||||||
|
// 包时
|
||||||
|
const todayUsage = getTodayUsage(detail.last_at, detail.daily || 0)
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<span>
|
||||||
|
{todayUsage}/{detail.quota}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// 包量
|
||||||
|
if (isLong) {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
{detail.used < detail.quota ? (
|
||||||
|
<span className="text-green-500">正常</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-red-500">已用完</span>
|
||||||
|
)}
|
||||||
|
<span>|</span>
|
||||||
|
<span>
|
||||||
|
{detail.used}/{detail.quota}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<span>
|
||||||
|
{detail.used}/{detail.quota}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "最近使用时间",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const lastAt = getLastAt(row.original)
|
||||||
|
return lastAt ? formatDateTime(lastAt) : "暂未使用"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "开通时间",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
return formatDateTime(row.original.created_at)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...(!isLong
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
header: "到期时间",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
return formatDateTime(getExpireAt(row.original))
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
|
header: "状态",
|
||||||
|
cell: ({ row }: { row: { original: Resources } }) => {
|
||||||
|
const resource = row.original
|
||||||
|
const isLoading = updatingId === resource.id
|
||||||
|
const currentActive = resource.active
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Select
|
||||||
|
value={currentActive ? "0" : "1"}
|
||||||
|
onValueChange={val => handleStatusChange(resource, val)}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="min-w-20">
|
||||||
|
<SelectValue placeholder="状态" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent className="min-w-(--radix-select-trigger-width)">
|
||||||
|
<SelectItem value="0">启用</SelectItem>
|
||||||
|
<SelectItem value="1">禁用</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
{isLoading && (
|
||||||
|
<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[isLong, updatingId, handleStatusChange],
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<div className="space-y-3">
|
||||||
<DataTable<Resources>
|
<form onSubmit={onFilter} className="bg-white p-4 rounded-lg">
|
||||||
{...table}
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
columns={[
|
<Controller
|
||||||
{ header: "ID", accessorKey: "id" },
|
name="user_phone"
|
||||||
{ header: "套餐编号", accessorKey: "resource_no" },
|
control={control}
|
||||||
{ header: "状态", accessorKey: "active" },
|
render={({ field, fieldState }) => (
|
||||||
{ header: "类型", accessorKey: "type" },
|
<Field
|
||||||
{ header: "创建时间", accessorKey: "created_at" },
|
data-invalid={fieldState.invalid}
|
||||||
{ header: "更新时间", accessorKey: "updated_at" },
|
className="w-40 flex-none"
|
||||||
]}
|
>
|
||||||
/>
|
<FieldLabel>会员号</FieldLabel>
|
||||||
</Suspense>
|
<Input {...field} placeholder="请输入会员号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="resource_no"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>套餐号</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入套餐号" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="status"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-32">
|
||||||
|
<FieldLabel>状态</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="0">启用</SelectItem>
|
||||||
|
<SelectItem value="1">禁用</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="type"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-32">
|
||||||
|
<FieldLabel>类型</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="1">包时</SelectItem>
|
||||||
|
<SelectItem value="2">包量</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="expired"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-32">
|
||||||
|
<FieldLabel>是否过期</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="0">未过期</SelectItem>
|
||||||
|
<SelectItem value="1">已过期</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="created_at_start"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="created_at_end"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
|
<Button type="submit">筛选</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense fallback={<div className="text-center p-4">加载中...</div>}>
|
||||||
|
<DataTable<Resources> {...table} columns={columns} />
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ export default function RolesPage() {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: "action",
|
||||||
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
|
|||||||
@@ -1,129 +1,377 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
import { CheckCircle, Clock, XCircle } from "lucide-react"
|
import { CheckCircle, Clock, XCircle } from "lucide-react"
|
||||||
import { Suspense } from "react"
|
import { Suspense, useState } from "react"
|
||||||
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { z } from "zod"
|
||||||
import { getPageTrade } from "@/actions/trade"
|
import { getPageTrade } from "@/actions/trade"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select"
|
||||||
import type { Trade } from "@/models/trade"
|
import type { Trade } from "@/models/trade"
|
||||||
|
|
||||||
|
type FilterValues = {
|
||||||
|
user_phone?: string
|
||||||
|
inner_no?: string
|
||||||
|
method?: number
|
||||||
|
platform?: number
|
||||||
|
status?: number
|
||||||
|
created_at_start?: Date
|
||||||
|
created_at_end?: Date
|
||||||
|
}
|
||||||
|
const filterSchema = z
|
||||||
|
.object({
|
||||||
|
user_phone: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform(val => val?.trim()),
|
||||||
|
inner_no: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform(val => val?.trim()),
|
||||||
|
method: z.string().optional(),
|
||||||
|
platform: z.string().optional(),
|
||||||
|
status: z.string().optional(),
|
||||||
|
created_at_start: z.string().optional(),
|
||||||
|
created_at_end: z.string().optional(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.created_at_start && data.created_at_end) {
|
||||||
|
const start = new Date(data.created_at_start)
|
||||||
|
const end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
if (end < start) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: "结束时间不能早于开始时间",
|
||||||
|
path: ["created_at_end"],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
type FilterSchema = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
export default function TradePage() {
|
export default function TradePage() {
|
||||||
|
const [filters, setFilters] = useState<FilterValues>({})
|
||||||
|
|
||||||
|
const { control, handleSubmit, reset } = useForm<FilterSchema>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
user_phone: "",
|
||||||
|
inner_no: "",
|
||||||
|
method: "all",
|
||||||
|
platform: "all",
|
||||||
|
status: "all",
|
||||||
|
created_at_start: "",
|
||||||
|
created_at_end: "",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const table = useDataTable<Trade>((page, size) =>
|
const table = useDataTable<Trade>((page, size) =>
|
||||||
getPageTrade({ page, size }),
|
getPageTrade({ page, size, ...filters }),
|
||||||
)
|
)
|
||||||
|
const onFilter = handleSubmit(data => {
|
||||||
|
const result: FilterValues = {}
|
||||||
|
|
||||||
|
if (data.user_phone?.trim()) result.user_phone = data.user_phone.trim()
|
||||||
|
if (data.inner_no?.trim()) result.inner_no = data.inner_no.trim()
|
||||||
|
if (data.method && data.method !== "all")
|
||||||
|
result.method = Number(data.method)
|
||||||
|
if (data.platform && data.platform !== "all")
|
||||||
|
result.platform = Number(data.platform)
|
||||||
|
if (data.status && data.status !== "all")
|
||||||
|
result.status = Number(data.status)
|
||||||
|
if (data.created_at_start)
|
||||||
|
result.created_at_start = new Date(data.created_at_start)
|
||||||
|
if (data.created_at_end)
|
||||||
|
result.created_at_end = new Date(data.created_at_end)
|
||||||
|
|
||||||
|
setFilters(result)
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<div className="space-y-3">
|
||||||
<DataTable<Trade>
|
{/* 筛选表单 */}
|
||||||
{...table}
|
<form onSubmit={onFilter} className="bg-white p-4">
|
||||||
columns={[
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
{ header: "ID", accessorKey: "id" },
|
<Controller
|
||||||
{ header: "套餐号", accessorKey: "inner_no" },
|
name="user_phone"
|
||||||
{
|
control={control}
|
||||||
header: "支付方式",
|
render={({ field, fieldState }) => (
|
||||||
accessorKey: "method",
|
<Field
|
||||||
cell: ({ row }) => {
|
data-invalid={fieldState.invalid}
|
||||||
const methodMap: Record<number, string> = {
|
className="w-40 flex-none"
|
||||||
1: "支付宝",
|
>
|
||||||
2: "微信",
|
<FieldLabel>会员号</FieldLabel>
|
||||||
3: "其他",
|
<Input {...field} placeholder="请输入会员号" />
|
||||||
4: "支付宝",
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
5: "微信",
|
</Field>
|
||||||
}
|
)}
|
||||||
return (
|
/>
|
||||||
<div>{methodMap[row.original.method as number] || "未知"}</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: "支付金额",
|
|
||||||
accessorKey: "payment",
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const payment =
|
|
||||||
typeof row.original.payment === "string"
|
|
||||||
? parseFloat(row.original.payment)
|
|
||||||
: row.original.payment || 0
|
|
||||||
return (
|
|
||||||
<div className="flex gap-1">
|
|
||||||
<span
|
|
||||||
className={
|
|
||||||
payment > 0 ? "text-green-500" : "text-orange-500"
|
|
||||||
}
|
|
||||||
>
|
|
||||||
¥{payment.toFixed(2)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
header: "支付平台",
|
|
||||||
accessorKey: "platform",
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const platform = row.original.platform
|
|
||||||
if (!platform) return <span>-</span>
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
{platform === 1 ? (
|
|
||||||
<span>电脑网站</span>
|
|
||||||
) : platform === 2 ? (
|
|
||||||
<span>手机网站</span>
|
|
||||||
) : (
|
|
||||||
<span>-</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// { header: "已退款", accessorKey: "refunded" },
|
|
||||||
{
|
|
||||||
header: "支付状态",
|
|
||||||
accessorKey: "status",
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const status = row.original.status
|
|
||||||
|
|
||||||
switch (status) {
|
<Controller
|
||||||
case 0:
|
name="inner_no"
|
||||||
return (
|
control={control}
|
||||||
<div className="flex items-center gap-2 text-yellow-600">
|
render={({ field, fieldState }) => (
|
||||||
<Clock className="h-4 w-4" />
|
<Field
|
||||||
<span>待支付</span>
|
data-invalid={fieldState.invalid}
|
||||||
</div>
|
className="w-40 flex-none"
|
||||||
)
|
>
|
||||||
case 1:
|
<FieldLabel>订单号</FieldLabel>
|
||||||
return (
|
<Input {...field} placeholder="请输入订单号" />
|
||||||
<div className="flex items-center gap-2 text-green-600">
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
<CheckCircle className="h-4 w-4" />
|
</Field>
|
||||||
<span>支付成功</span>
|
)}
|
||||||
</div>
|
/>
|
||||||
)
|
|
||||||
case 2:
|
<Controller
|
||||||
return (
|
name="method"
|
||||||
<div className="flex items-center gap-2 text-gray-500">
|
control={control}
|
||||||
<XCircle className="h-4 w-4" />
|
render={({ field, fieldState }) => (
|
||||||
<span>取消支付</span>
|
<Field data-invalid={fieldState.invalid} className="w-24">
|
||||||
</div>
|
<FieldLabel>支付渠道</FieldLabel>
|
||||||
)
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
default:
|
<SelectTrigger>
|
||||||
return <span className="text-gray-400">-</span>
|
<SelectValue placeholder="全部" />
|
||||||
}
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="1">支付宝</SelectItem>
|
||||||
|
<SelectItem value="2">微信</SelectItem>
|
||||||
|
<SelectItem value="3">商福通</SelectItem>
|
||||||
|
<SelectItem value="4">商福通渠道支付宝</SelectItem>
|
||||||
|
<SelectItem value="5">商福通渠道微信</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="platform"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-24">
|
||||||
|
<FieldLabel>支付平台</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="1">电脑网站</SelectItem>
|
||||||
|
<SelectItem value="2">手机网站</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="status"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field data-invalid={fieldState.invalid} className="w-24">
|
||||||
|
<FieldLabel>支付状态</FieldLabel>
|
||||||
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
|
<SelectTrigger>
|
||||||
|
<SelectValue placeholder="全部" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="all">全部</SelectItem>
|
||||||
|
<SelectItem value="0">待支付</SelectItem>
|
||||||
|
<SelectItem value="1">支付成功</SelectItem>
|
||||||
|
<SelectItem value="2">取消支付</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="created_at_start"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>开始时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="created_at_end"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>结束时间</FieldLabel>
|
||||||
|
<Input type="date" {...field} />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
|
<Button type="submit">筛选</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
reset()
|
||||||
|
setFilters({})
|
||||||
|
table.pagination.onPageChange(1)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<Suspense>
|
||||||
|
<DataTable<Trade>
|
||||||
|
{...table}
|
||||||
|
columns={[
|
||||||
|
{ header: "ID", accessorKey: "id" },
|
||||||
|
{
|
||||||
|
header: "会员号",
|
||||||
|
accessorFn: row => row.user?.phone || "-",
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{ header: "购买套餐", accessorKey: "subject" },
|
header: "订单号",
|
||||||
{ header: "类型", accessorKey: "type" },
|
accessorKey: "inner_no",
|
||||||
{
|
},
|
||||||
header: "创建时间",
|
{
|
||||||
accessorKey: "created_at",
|
header: "渠道订单号",
|
||||||
cell: ({ row }) =>
|
accessorKey: "outer_no",
|
||||||
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
},
|
||||||
},
|
{
|
||||||
{
|
header: "支付渠道",
|
||||||
header: "更新时间",
|
accessorKey: "method",
|
||||||
accessorKey: "updated_at",
|
cell: ({ row }) => {
|
||||||
cell: ({ row }) =>
|
const methodMap: Record<number, string> = {
|
||||||
format(new Date(row.original.updated_at), "yyyy-MM-dd HH:mm"),
|
1: "支付宝",
|
||||||
},
|
2: "微信",
|
||||||
]}
|
3: "商福通",
|
||||||
/>
|
4: "商福通渠道支付宝",
|
||||||
</Suspense>
|
5: "商福通渠道微信",
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{methodMap[row.original.method as number] || "未知"}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "支付金额",
|
||||||
|
accessorKey: "payment",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const payment =
|
||||||
|
typeof row.original.payment === "string"
|
||||||
|
? parseFloat(row.original.payment)
|
||||||
|
: row.original.payment || 0
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1">
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
payment > 0 ? "text-green-500" : "text-orange-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
¥{payment.toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "支付平台",
|
||||||
|
accessorKey: "platform",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const platform = row.original.platform
|
||||||
|
if (!platform) return <span>-</span>
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
{platform === 1 ? (
|
||||||
|
<span>电脑网站</span>
|
||||||
|
) : platform === 2 ? (
|
||||||
|
<span>手机网站</span>
|
||||||
|
) : (
|
||||||
|
<span>-</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "支付状态",
|
||||||
|
accessorKey: "status",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const status = row.original.status
|
||||||
|
|
||||||
|
switch (status) {
|
||||||
|
case 0:
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 text-yellow-600">
|
||||||
|
<Clock className="h-4 w-4" />
|
||||||
|
<span>待支付</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
case 1:
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 text-green-600">
|
||||||
|
<CheckCircle className="h-4 w-4" />
|
||||||
|
<span>支付成功</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
case 2:
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 text-gray-500">
|
||||||
|
<XCircle className="h-4 w-4" />
|
||||||
|
<span>取消支付</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
return <span className="text-gray-400">-</span>
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ header: "购买套餐", accessorKey: "subject" },
|
||||||
|
{
|
||||||
|
header: "创建时间",
|
||||||
|
accessorKey: "created_at",
|
||||||
|
cell: ({ row }) =>
|
||||||
|
format(new Date(row.original.created_at), "yyyy-MM-dd HH:mm"),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,156 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
import { Suspense } from "react"
|
import { Suspense, useCallback, useState } from "react"
|
||||||
import { bindAdmin, getPageUsers } from "@/actions/user"
|
import { Controller, useForm } from "react-hook-form"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { toast } from "sonner"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { bindAdmin, getPageUser } from "@/actions/user"
|
||||||
|
import { DataTable } from "@/components/data-table"
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { useFetch } from "@/hooks/data"
|
import {
|
||||||
|
Field,
|
||||||
|
FieldError,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from "@/components/ui/field"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
import type { User } from "@/models/user"
|
import type { User } from "@/models/user"
|
||||||
|
|
||||||
|
interface UserQueryParams {
|
||||||
|
account?: string
|
||||||
|
name?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterSchema = z.object({
|
||||||
|
account: z.string().optional(),
|
||||||
|
name: z.string().optional(),
|
||||||
|
})
|
||||||
|
|
||||||
|
type FormValues = z.infer<typeof filterSchema>
|
||||||
|
|
||||||
export default function UserPage() {
|
export default function UserPage() {
|
||||||
const table = useDataTable<User>((page, size) => getPageUsers({ page, size }))
|
const [userList, setUserList] = useState<User[]>([])
|
||||||
const bind = useFetch(table, (id: number) => bindAdmin({ id }), {
|
const [loading, setLoading] = useState(false)
|
||||||
done: "用户已认领",
|
|
||||||
fail: "用户认领失败",
|
const { control, handleSubmit, reset } = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(filterSchema),
|
||||||
|
defaultValues: {
|
||||||
|
account: "",
|
||||||
|
name: "",
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const fetchUsers = useCallback(async (filters: UserQueryParams = {}) => {
|
||||||
|
setLoading(true)
|
||||||
|
try {
|
||||||
|
const res = await getPageUser(filters)
|
||||||
|
if (res.success) {
|
||||||
|
const req = [{ ...res.data }]
|
||||||
|
setUserList(req)
|
||||||
|
} else {
|
||||||
|
toast.error(res.message || "获取用户失败")
|
||||||
|
setUserList([])
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`获取管理员失败: ${message}`)
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const bind = useCallback(
|
||||||
|
async (id: number) => {
|
||||||
|
try {
|
||||||
|
const res = await bindAdmin({ id })
|
||||||
|
if (res.success) {
|
||||||
|
toast.success("用户已认领")
|
||||||
|
fetchUsers()
|
||||||
|
} else {
|
||||||
|
toast.error(res.message || "认领失败")
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`认领请求失败: ${message}`)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[fetchUsers],
|
||||||
|
)
|
||||||
|
|
||||||
|
const onFilter = handleSubmit((data: FormValues) => {
|
||||||
|
const params: UserQueryParams = {}
|
||||||
|
|
||||||
|
if (data.account?.trim()) params.account = data.account.trim()
|
||||||
|
if (data.name?.trim()) params.name = data.name.trim()
|
||||||
|
const hasValidFilter = Object.keys(params).length > 0
|
||||||
|
if (hasValidFilter) {
|
||||||
|
fetchUsers(params)
|
||||||
|
} else {
|
||||||
|
setUserList([])
|
||||||
|
setLoading(false)
|
||||||
|
toast.info("请输入筛选条件后再查询")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="space-y-3">
|
||||||
|
<form onSubmit={onFilter} className="bg-white p-4">
|
||||||
|
<div className="flex flex-wrap items-end gap-4">
|
||||||
|
<Controller
|
||||||
|
name="account"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-80 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>账号/手机号/邮箱</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入账号/手机号/邮箱" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Controller
|
||||||
|
name="name"
|
||||||
|
control={control}
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field
|
||||||
|
data-invalid={fieldState.invalid}
|
||||||
|
className="w-40 flex-none"
|
||||||
|
>
|
||||||
|
<FieldLabel>姓名</FieldLabel>
|
||||||
|
<Input {...field} placeholder="请输入姓名" />
|
||||||
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FieldGroup className="flex-row justify-start mt-4 gap-2">
|
||||||
|
<Button type="submit">筛选</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
reset()
|
||||||
|
setUserList([])
|
||||||
|
setLoading(false)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
重置
|
||||||
|
</Button>
|
||||||
|
</FieldGroup>
|
||||||
|
</form>
|
||||||
|
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<DataTable<User>
|
<DataTable<User>
|
||||||
{...table}
|
data={userList || []}
|
||||||
|
status={loading ? "load" : "done"}
|
||||||
columns={[
|
columns={[
|
||||||
|
{ header: "ID", accessorKey: "id" },
|
||||||
{ header: "账号", accessorKey: "username" },
|
{ header: "账号", accessorKey: "username" },
|
||||||
{ header: "手机", accessorKey: "phone" },
|
{ header: "手机", accessorKey: "phone" },
|
||||||
{ header: "邮箱", accessorKey: "email" },
|
{ header: "邮箱", accessorKey: "email" },
|
||||||
@@ -28,60 +159,80 @@ export default function UserPage() {
|
|||||||
header: "余额",
|
header: "余额",
|
||||||
accessorKey: "balance",
|
accessorKey: "balance",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const balance =
|
const balance = Number(row.original.balance) || 0
|
||||||
typeof row.original.balance === "string"
|
|
||||||
? parseFloat(row.original.balance)
|
|
||||||
: row.original.balance || 0
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-1">
|
<span
|
||||||
<span
|
className={
|
||||||
className={
|
balance > 0 ? "text-green-500" : "text-orange-500"
|
||||||
balance > 0 ? "text-green-500" : "text-orange-500"
|
}
|
||||||
}
|
>
|
||||||
>
|
¥{balance.toFixed(2)}
|
||||||
¥{balance.toFixed(2)}
|
</span>
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "认证状态",
|
header: "实名状态",
|
||||||
accessorKey: "id_type",
|
accessorKey: "id_type",
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<Badge
|
||||||
|
variant={row.original.id_type === 1 ? "default" : "secondary"}
|
||||||
|
className={
|
||||||
|
row.original.id_type === 1
|
||||||
|
? "bg-green-100 text-green-800"
|
||||||
|
: "bg-gray-100 text-gray-800"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{row.original.id_type === 1 ? "已认证" : "未认证"}
|
||||||
|
</Badge>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "身份证号",
|
||||||
|
accessorKey: "id_no",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const status = row.original.id_type
|
const idNo = row.original.id_no
|
||||||
return (
|
return idNo ? `${idNo.slice(0, 6)}****${idNo.slice(-4)}` : "-"
|
||||||
<Badge
|
},
|
||||||
variant={status === 1 ? "default" : "secondary"}
|
},
|
||||||
className={
|
{
|
||||||
status === 1
|
header: "客户来源",
|
||||||
? "bg-green-100 text-green-800"
|
accessorKey: "source",
|
||||||
: "bg-gray-100 text-gray-800"
|
cell: ({ row }) => {
|
||||||
}
|
const sourceMap: Record<number, string> = {
|
||||||
>
|
0: "官网注册",
|
||||||
{status === 1 ? "已认证" : "未认证"}
|
1: "管理员添加",
|
||||||
</Badge>
|
2: "代理商注册",
|
||||||
)
|
3: "代理商添加",
|
||||||
|
}
|
||||||
|
return sourceMap[row.original.source] ?? "未知"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "账号状态",
|
header: "账号状态",
|
||||||
accessorKey: "status",
|
accessorKey: "status",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => (row.original.status === 1 ? "正常" : "禁用"),
|
||||||
const status = row.original.status
|
|
||||||
return status === 1 ? "正常" : ""
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{ header: "联系方式", accessorKey: "contact_wechat" },
|
{ header: "联系方式", accessorKey: "contact_wechat" },
|
||||||
{
|
{
|
||||||
header: "管理员",
|
header: "客户经理",
|
||||||
cell: ({ row }) => row.original.admin?.name,
|
cell: ({ row }) => row.original.admin?.name || "-",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "最后登录时间",
|
header: "最后登录时间",
|
||||||
accessorKey: "last_login",
|
accessorKey: "last_login",
|
||||||
cell: ({ row }) =>
|
cell: ({ row }) =>
|
||||||
format(new Date(row.original.last_login), "yyyy-MM-dd HH:mm"),
|
row.original.last_login
|
||||||
|
? format(
|
||||||
|
new Date(row.original.last_login),
|
||||||
|
"yyyy-MM-dd HH:mm",
|
||||||
|
)
|
||||||
|
: "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "最后登录IP",
|
||||||
|
accessorKey: "last_login_ip",
|
||||||
|
cell: ({ row }) => row.original.last_login_ip || "-",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "创建时间",
|
header: "创建时间",
|
||||||
@@ -95,7 +246,7 @@ export default function UserPage() {
|
|||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ctx => (
|
cell: ctx => (
|
||||||
<Button
|
<Button
|
||||||
size={"sm"}
|
size="sm"
|
||||||
onClick={() => bind(ctx.row.original.id)}
|
onClick={() => bind(ctx.row.original.id)}
|
||||||
disabled={!!ctx.row.original.admin_id}
|
disabled={!!ctx.row.original.admin_id}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -3,122 +3,122 @@
|
|||||||
@custom-variant dark (&:is(.dark *));
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
@theme inline {
|
@theme inline {
|
||||||
--color-background: var(--background);
|
--color-background: var(--background);
|
||||||
--color-foreground: var(--foreground);
|
--color-foreground: var(--foreground);
|
||||||
--font-sans: var(--font-geist-sans);
|
--font-sans: var(--font-geist-sans);
|
||||||
--font-mono: var(--font-geist-mono);
|
--font-mono: var(--font-geist-mono);
|
||||||
--color-sidebar-ring: var(--sidebar-ring);
|
--color-sidebar-ring: var(--sidebar-ring);
|
||||||
--color-sidebar-border: var(--sidebar-border);
|
--color-sidebar-border: var(--sidebar-border);
|
||||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||||
--color-sidebar-accent: var(--sidebar-accent);
|
--color-sidebar-accent: var(--sidebar-accent);
|
||||||
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
||||||
--color-sidebar-primary: var(--sidebar-primary);
|
--color-sidebar-primary: var(--sidebar-primary);
|
||||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||||
--color-sidebar: var(--sidebar);
|
--color-sidebar: var(--sidebar);
|
||||||
--color-chart-5: var(--chart-5);
|
--color-chart-5: var(--chart-5);
|
||||||
--color-chart-4: var(--chart-4);
|
--color-chart-4: var(--chart-4);
|
||||||
--color-chart-3: var(--chart-3);
|
--color-chart-3: var(--chart-3);
|
||||||
--color-chart-2: var(--chart-2);
|
--color-chart-2: var(--chart-2);
|
||||||
--color-chart-1: var(--chart-1);
|
--color-chart-1: var(--chart-1);
|
||||||
--color-ring: var(--ring);
|
--color-ring: var(--ring);
|
||||||
--color-input: var(--input);
|
--color-input: var(--input);
|
||||||
--color-border: var(--border);
|
--color-border: var(--border);
|
||||||
--color-destructive: var(--destructive);
|
--color-destructive: var(--destructive);
|
||||||
--color-accent-foreground: var(--accent-foreground);
|
--color-accent-foreground: var(--accent-foreground);
|
||||||
--color-accent: var(--accent);
|
--color-accent: var(--accent);
|
||||||
--color-muted-foreground: var(--muted-foreground);
|
--color-muted-foreground: var(--muted-foreground);
|
||||||
--color-muted: var(--muted);
|
--color-muted: var(--muted);
|
||||||
--color-secondary-foreground: var(--secondary-foreground);
|
--color-secondary-foreground: var(--secondary-foreground);
|
||||||
--color-secondary: var(--secondary);
|
--color-secondary: var(--secondary);
|
||||||
--color-primary-foreground: var(--primary-foreground);
|
--color-primary-foreground: var(--primary-foreground);
|
||||||
--color-primary: var(--primary);
|
--color-primary: var(--primary);
|
||||||
--color-popover-foreground: var(--popover-foreground);
|
--color-popover-foreground: var(--popover-foreground);
|
||||||
--color-popover: var(--popover);
|
--color-popover: var(--popover);
|
||||||
--color-card-foreground: var(--card-foreground);
|
--color-card-foreground: var(--card-foreground);
|
||||||
--color-card: var(--card);
|
--color-card: var(--card);
|
||||||
--radius-sm: calc(var(--radius) - 4px);
|
--radius-sm: calc(var(--radius) - 4px);
|
||||||
--radius-md: calc(var(--radius) - 2px);
|
--radius-md: calc(var(--radius) - 2px);
|
||||||
--radius-lg: var(--radius);
|
--radius-lg: var(--radius);
|
||||||
--radius-xl: calc(var(--radius) + 4px);
|
--radius-xl: calc(var(--radius) + 4px);
|
||||||
--radius-2xl: calc(var(--radius) + 8px);
|
--radius-2xl: calc(var(--radius) + 8px);
|
||||||
--radius-3xl: calc(var(--radius) + 12px);
|
--radius-3xl: calc(var(--radius) + 12px);
|
||||||
--radius-4xl: calc(var(--radius) + 16px);
|
--radius-4xl: calc(var(--radius) + 16px);
|
||||||
}
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--radius: 0.625rem;
|
--radius: 0.625rem;
|
||||||
--background: oklch(1 0 0);
|
--background: oklch(1 0 0);
|
||||||
--foreground: oklch(0.13 0.028 261.692);
|
--foreground: oklch(0.13 0.028 261.692);
|
||||||
--card: oklch(1 0 0);
|
--card: oklch(1 0 0);
|
||||||
--card-foreground: oklch(0.13 0.028 261.692);
|
--card-foreground: oklch(0.13 0.028 261.692);
|
||||||
--popover: oklch(1 0 0);
|
--popover: oklch(1 0 0);
|
||||||
--popover-foreground: oklch(0.13 0.028 261.692);
|
--popover-foreground: oklch(0.13 0.028 261.692);
|
||||||
--primary: oklch(0.7 0.12 265);
|
--primary: oklch(0.7 0.12 265);
|
||||||
--primary-foreground: oklch(0.985 0.002 247.839);
|
--primary-foreground: oklch(0.985 0.002 247.839);
|
||||||
--secondary: oklch(0.967 0.003 264.542);
|
--secondary: oklch(0.967 0.003 264.542);
|
||||||
--secondary-foreground: oklch(0.21 0.034 264.665);
|
--secondary-foreground: oklch(0.21 0.034 264.665);
|
||||||
--muted: oklch(0.967 0.003 264.542);
|
--muted: oklch(0.967 0.003 264.542);
|
||||||
--muted-foreground: oklch(0.551 0.027 264.364);
|
--muted-foreground: oklch(0.551 0.027 264.364);
|
||||||
--accent: oklch(0.967 0.003 264.542);
|
--accent: oklch(0.967 0.003 264.542);
|
||||||
--accent-foreground: oklch(0.21 0.034 264.665);
|
--accent-foreground: oklch(0.21 0.034 264.665);
|
||||||
--destructive: oklch(0.577 0.245 27.325);
|
--destructive: oklch(0.577 0.245 27.325);
|
||||||
--border: oklch(0.928 0.006 264.531);
|
--border: oklch(0.928 0.006 264.531);
|
||||||
--input: oklch(0.928 0.006 264.531);
|
--input: oklch(0.928 0.006 264.531);
|
||||||
--ring: oklch(0.7 0.12 265);
|
--ring: oklch(0.7 0.12 265);
|
||||||
--chart-1: oklch(0.646 0.222 41.116);
|
--chart-1: oklch(0.646 0.222 41.116);
|
||||||
--chart-2: oklch(0.6 0.118 184.704);
|
--chart-2: oklch(0.6 0.118 184.704);
|
||||||
--chart-3: oklch(0.398 0.07 227.392);
|
--chart-3: oklch(0.398 0.07 227.392);
|
||||||
--chart-4: oklch(0.828 0.189 84.429);
|
--chart-4: oklch(0.828 0.189 84.429);
|
||||||
--chart-5: oklch(0.769 0.188 70.08);
|
--chart-5: oklch(0.769 0.188 70.08);
|
||||||
--sidebar: oklch(0.985 0.002 247.839);
|
--sidebar: oklch(0.985 0.002 247.839);
|
||||||
--sidebar-foreground: oklch(0.13 0.028 261.692);
|
--sidebar-foreground: oklch(0.13 0.028 261.692);
|
||||||
--sidebar-primary: oklch(0.21 0.034 264.665);
|
--sidebar-primary: oklch(0.21 0.034 264.665);
|
||||||
--sidebar-primary-foreground: oklch(0.985 0.002 247.839);
|
--sidebar-primary-foreground: oklch(0.985 0.002 247.839);
|
||||||
--sidebar-accent: oklch(0.967 0.003 264.542);
|
--sidebar-accent: oklch(0.967 0.003 264.542);
|
||||||
--sidebar-accent-foreground: oklch(0.21 0.034 264.665);
|
--sidebar-accent-foreground: oklch(0.21 0.034 264.665);
|
||||||
--sidebar-border: oklch(0.928 0.006 264.531);
|
--sidebar-border: oklch(0.928 0.006 264.531);
|
||||||
--sidebar-ring: oklch(0.707 0.022 261.325);
|
--sidebar-ring: oklch(0.707 0.022 261.325);
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
--background: oklch(0.13 0.028 261.692);
|
--background: oklch(0.13 0.028 261.692);
|
||||||
--foreground: oklch(0.985 0.002 247.839);
|
--foreground: oklch(0.985 0.002 247.839);
|
||||||
--card: oklch(0.21 0.034 264.665);
|
--card: oklch(0.21 0.034 264.665);
|
||||||
--card-foreground: oklch(0.985 0.002 247.839);
|
--card-foreground: oklch(0.985 0.002 247.839);
|
||||||
--popover: oklch(0.21 0.034 264.665);
|
--popover: oklch(0.21 0.034 264.665);
|
||||||
--popover-foreground: oklch(0.985 0.002 247.839);
|
--popover-foreground: oklch(0.985 0.002 247.839);
|
||||||
--primary: oklch(0.928 0.006 264.531);
|
--primary: oklch(0.928 0.006 264.531);
|
||||||
--primary-foreground: oklch(0.21 0.034 264.665);
|
--primary-foreground: oklch(0.21 0.034 264.665);
|
||||||
--secondary: oklch(0.278 0.033 256.848);
|
--secondary: oklch(0.278 0.033 256.848);
|
||||||
--secondary-foreground: oklch(0.985 0.002 247.839);
|
--secondary-foreground: oklch(0.985 0.002 247.839);
|
||||||
--muted: oklch(0.278 0.033 256.848);
|
--muted: oklch(0.278 0.033 256.848);
|
||||||
--muted-foreground: oklch(0.707 0.022 261.325);
|
--muted-foreground: oklch(0.707 0.022 261.325);
|
||||||
--accent: oklch(0.278 0.033 256.848);
|
--accent: oklch(0.278 0.033 256.848);
|
||||||
--accent-foreground: oklch(0.985 0.002 247.839);
|
--accent-foreground: oklch(0.985 0.002 247.839);
|
||||||
--destructive: oklch(0.704 0.191 22.216);
|
--destructive: oklch(0.704 0.191 22.216);
|
||||||
--border: oklch(1 0 0 / 10%);
|
--border: oklch(1 0 0 / 10%);
|
||||||
--input: oklch(1 0 0 / 15%);
|
--input: oklch(1 0 0 / 15%);
|
||||||
--ring: oklch(0.551 0.027 264.364);
|
--ring: oklch(0.551 0.027 264.364);
|
||||||
--chart-1: oklch(0.488 0.243 264.376);
|
--chart-1: oklch(0.488 0.243 264.376);
|
||||||
--chart-2: oklch(0.696 0.17 162.48);
|
--chart-2: oklch(0.696 0.17 162.48);
|
||||||
--chart-3: oklch(0.769 0.188 70.08);
|
--chart-3: oklch(0.769 0.188 70.08);
|
||||||
--chart-4: oklch(0.627 0.265 303.9);
|
--chart-4: oklch(0.627 0.265 303.9);
|
||||||
--chart-5: oklch(0.645 0.246 16.439);
|
--chart-5: oklch(0.645 0.246 16.439);
|
||||||
--sidebar: oklch(0.21 0.034 264.665);
|
--sidebar: oklch(0.21 0.034 264.665);
|
||||||
--sidebar-foreground: oklch(0.985 0.002 247.839);
|
--sidebar-foreground: oklch(0.985 0.002 247.839);
|
||||||
--sidebar-primary: oklch(0.488 0.243 264.376);
|
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||||
--sidebar-primary-foreground: oklch(0.985 0.002 247.839);
|
--sidebar-primary-foreground: oklch(0.985 0.002 247.839);
|
||||||
--sidebar-accent: oklch(0.278 0.033 256.848);
|
--sidebar-accent: oklch(0.278 0.033 256.848);
|
||||||
--sidebar-accent-foreground: oklch(0.985 0.002 247.839);
|
--sidebar-accent-foreground: oklch(0.985 0.002 247.839);
|
||||||
--sidebar-border: oklch(1 0 0 / 10%);
|
--sidebar-border: oklch(1 0 0 / 10%);
|
||||||
--sidebar-ring: oklch(0.551 0.027 264.364);
|
--sidebar-ring: oklch(0.551 0.027 264.364);
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
* {
|
* {
|
||||||
@apply border-border outline-ring/50;
|
@apply border-border outline-ring/50;
|
||||||
}
|
}
|
||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,10 @@ import {
|
|||||||
type ColumnDef,
|
type ColumnDef,
|
||||||
flexRender,
|
flexRender,
|
||||||
getCoreRowModel,
|
getCoreRowModel,
|
||||||
getExpandedRowModel,
|
|
||||||
useReactTable,
|
useReactTable,
|
||||||
} from "@tanstack/react-table"
|
} from "@tanstack/react-table"
|
||||||
import { Loader } from "lucide-react"
|
import { Loader } from "lucide-react"
|
||||||
import { type CSSProperties, useCallback, useMemo } from "react"
|
import type { CSSProperties } from "react"
|
||||||
import { Pagination, type PaginationProps } from "@/components/ui/pagination"
|
import { Pagination, type PaginationProps } from "@/components/ui/pagination"
|
||||||
import {
|
import {
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -23,7 +22,7 @@ export type DataTableProps<T> = {
|
|||||||
data: T[]
|
data: T[]
|
||||||
status: "load" | "done" | "fail"
|
status: "load" | "done" | "fail"
|
||||||
columns: ColumnDef<T>[]
|
columns: ColumnDef<T>[]
|
||||||
pagination: PaginationProps
|
pagination?: PaginationProps
|
||||||
classNames?: {
|
classNames?: {
|
||||||
root?: string
|
root?: string
|
||||||
headRow?: string
|
headRow?: string
|
||||||
@@ -39,9 +38,9 @@ export function DataTable<T extends Record<string, unknown>>(
|
|||||||
columns: props.columns,
|
columns: props.columns,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
manualPagination: true,
|
manualPagination: true,
|
||||||
rowCount: props.pagination.total,
|
rowCount: props.pagination?.total,
|
||||||
state: {
|
state: {
|
||||||
pagination: {
|
pagination: props.pagination && {
|
||||||
pageIndex: props.pagination.page,
|
pageIndex: props.pagination.page,
|
||||||
pageSize: props.pagination.size,
|
pageSize: props.pagination.size,
|
||||||
},
|
},
|
||||||
@@ -160,7 +159,7 @@ export function DataTable<T extends Record<string, unknown>>(
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 分页器 */}
|
{/* 分页器 */}
|
||||||
<Pagination {...props.pagination} />
|
{props.pagination && <Pagination {...props.pagination} />}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ export function useDataTable<T>(
|
|||||||
const [size, setSize] = useState(10)
|
const [size, setSize] = useState(10)
|
||||||
const [total, setTotal] = useState(0)
|
const [total, setTotal] = useState(0)
|
||||||
|
|
||||||
const refresh = useCallback(
|
const _refresh = useCallback(
|
||||||
async (_page?: number, _size?: number) => {
|
async (_page: number, _size: number) => {
|
||||||
setStatus("load")
|
setStatus("load")
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(_page ?? page, _size ?? size)
|
const resp = await fetch(_page, _size)
|
||||||
if (!resp.success) {
|
if (!resp.success) {
|
||||||
throw new Error("获取数据失败")
|
throw new Error("获取数据失败")
|
||||||
}
|
}
|
||||||
@@ -34,21 +34,22 @@ export function useDataTable<T>(
|
|||||||
setStatus("fail")
|
setStatus("fail")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[fetch, page, size, setStatus],
|
[fetch, setStatus],
|
||||||
)
|
)
|
||||||
|
|
||||||
const onPageChange = (page: number) => {
|
const onPageChange = useCallback(
|
||||||
setPage(page)
|
(page: number) => _refresh(page, size),
|
||||||
}
|
[_refresh, size],
|
||||||
|
)
|
||||||
|
|
||||||
const onSizeChange = (size: number) => {
|
const onSizeChange = useCallback(
|
||||||
setPage(1)
|
(size: number) => _refresh(1, size),
|
||||||
setSize(size)
|
[_refresh],
|
||||||
}
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refresh(page, size).then()
|
_refresh(1, size)
|
||||||
}, [refresh, page, size])
|
}, [_refresh, size])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
@@ -61,6 +62,8 @@ export function useDataTable<T>(
|
|||||||
onPageChange,
|
onPageChange,
|
||||||
onSizeChange,
|
onSizeChange,
|
||||||
},
|
},
|
||||||
refresh,
|
refresh: (_page?: number, _size?: number) => {
|
||||||
|
_refresh(_page ?? page, _size ?? size)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import { AlertDialog as AlertDialogPrimitive } from "radix-ui"
|
import { AlertDialog as AlertDialogPrimitive } from "radix-ui"
|
||||||
|
import type * as React from "react"
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
function AlertDialog({
|
function AlertDialog({
|
||||||
...props
|
...props
|
||||||
@@ -37,7 +36,7 @@ function AlertDialogOverlay({
|
|||||||
data-slot="alert-dialog-overlay"
|
data-slot="alert-dialog-overlay"
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
"fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -59,7 +58,7 @@ function AlertDialogContent({
|
|||||||
data-size={size}
|
data-size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/alert-dialog-content fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[size=sm]:max-w-xs data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[size=default]:sm:max-w-lg",
|
"group/alert-dialog-content fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[size=sm]:max-w-xs data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[size=default]:sm:max-w-lg",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -76,7 +75,7 @@ function AlertDialogHeader({
|
|||||||
data-slot="alert-dialog-header"
|
data-slot="alert-dialog-header"
|
||||||
className={cn(
|
className={cn(
|
||||||
"grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
|
"grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -92,7 +91,7 @@ function AlertDialogFooter({
|
|||||||
data-slot="alert-dialog-footer"
|
data-slot="alert-dialog-footer"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
|
"flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -108,7 +107,7 @@ function AlertDialogTitle({
|
|||||||
data-slot="alert-dialog-title"
|
data-slot="alert-dialog-title"
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-lg font-semibold sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
|
"text-lg font-semibold sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -137,7 +136,7 @@ function AlertDialogMedia({
|
|||||||
data-slot="alert-dialog-media"
|
data-slot="alert-dialog-media"
|
||||||
className={cn(
|
className={cn(
|
||||||
"mb-2 inline-flex size-16 items-center justify-center rounded-md bg-muted sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-8",
|
"mb-2 inline-flex size-16 items-center justify-center rounded-md bg-muted sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-8",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as React from "react"
|
|
||||||
import { Slot } from "@radix-ui/react-slot"
|
import { Slot } from "@radix-ui/react-slot"
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ const badgeVariants = cva(
|
|||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
variant: "default",
|
variant: "default",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
function Badge({
|
function Badge({
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import { XIcon } from "lucide-react"
|
import { XIcon } from "lucide-react"
|
||||||
import { Dialog as DialogPrimitive } from "radix-ui"
|
import { Dialog as DialogPrimitive } from "radix-ui"
|
||||||
|
import type * as React from "react"
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
function Dialog({
|
function Dialog({
|
||||||
...props
|
...props
|
||||||
@@ -40,7 +39,7 @@ function DialogOverlay({
|
|||||||
data-slot="dialog-overlay"
|
data-slot="dialog-overlay"
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
"fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -62,7 +61,7 @@ function DialogContent({
|
|||||||
data-slot="dialog-content"
|
data-slot="dialog-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",
|
"fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -104,7 +103,7 @@ function DialogFooter({
|
|||||||
data-slot="dialog-footer"
|
data-slot="dialog-footer"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useMemo } from "react"
|
|
||||||
import { cva, type VariantProps } from "class-variance-authority"
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
import { useMemo } from "react"
|
||||||
import { cn } from "@/lib/utils"
|
|
||||||
import { Label } from "@/components/ui/label"
|
import { Label } from "@/components/ui/label"
|
||||||
import { Separator } from "@/components/ui/separator"
|
import { Separator } from "@/components/ui/separator"
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
||||||
return (
|
return (
|
||||||
@@ -14,7 +13,7 @@ function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
|||||||
className={cn(
|
className={cn(
|
||||||
"flex flex-col gap-6",
|
"flex flex-col gap-6",
|
||||||
"has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
|
"has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -34,7 +33,7 @@ function FieldLegend({
|
|||||||
"mb-3 font-medium",
|
"mb-3 font-medium",
|
||||||
"data-[variant=legend]:text-base",
|
"data-[variant=legend]:text-base",
|
||||||
"data-[variant=label]:text-sm",
|
"data-[variant=label]:text-sm",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -47,7 +46,7 @@ function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="field-group"
|
data-slot="field-group"
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
|
"group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -75,7 +74,7 @@ const fieldVariants = cva(
|
|||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
orientation: "vertical",
|
orientation: "vertical",
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
function Field({
|
function Field({
|
||||||
@@ -100,7 +99,7 @@ function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="field-content"
|
data-slot="field-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
|
"group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -118,7 +117,7 @@ function FieldLabel({
|
|||||||
"group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50",
|
"group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50",
|
||||||
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4",
|
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4",
|
||||||
"has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10",
|
"has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -131,7 +130,7 @@ function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|||||||
data-slot="field-label"
|
data-slot="field-label"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex w-fit items-center gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50",
|
"flex w-fit items-center gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -146,7 +145,7 @@ function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
|
|||||||
"text-muted-foreground text-sm leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance",
|
"text-muted-foreground text-sm leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance",
|
||||||
"last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5",
|
"last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5",
|
||||||
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -166,7 +165,7 @@ function FieldSeparator({
|
|||||||
data-content={!!children}
|
data-content={!!children}
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
|
"relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -201,10 +200,10 @@ function FieldError({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const uniqueErrors = [
|
const uniqueErrors = [
|
||||||
...new Map(errors.map((error) => [error?.message, error])).values(),
|
...new Map(errors.map(error => [error?.message, error])).values(),
|
||||||
]
|
]
|
||||||
|
|
||||||
if (uniqueErrors?.length == 1) {
|
if (uniqueErrors?.length === 1) {
|
||||||
return uniqueErrors[0]?.message
|
return uniqueErrors[0]?.message
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +211,7 @@ function FieldError({
|
|||||||
<ul className="ml-4 flex list-disc flex-col gap-1">
|
<ul className="ml-4 flex list-disc flex-col gap-1">
|
||||||
{uniqueErrors.map(
|
{uniqueErrors.map(
|
||||||
(error, index) =>
|
(error, index) =>
|
||||||
error?.message && <li key={index}>{error.message}</li>
|
error?.message && <li key={index}>{error.message}</li>,
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import { HoverCard as HoverCardPrimitive } from "radix-ui"
|
import { HoverCard as HoverCardPrimitive } from "radix-ui"
|
||||||
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ function HoverCardContent({
|
|||||||
sideOffset={sideOffset}
|
sideOffset={sideOffset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"z-50 w-64 origin-(--radix-hover-card-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
"z-50 w-64 origin-(--radix-hover-card-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as React from "react"
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
|||||||
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
|
||||||
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
|
||||||
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import * as LabelPrimitive from "@radix-ui/react-label"
|
import * as LabelPrimitive from "@radix-ui/react-label"
|
||||||
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ function Label({
|
|||||||
data-slot="label"
|
data-slot="label"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -121,13 +121,11 @@ function Pagination({
|
|||||||
const paginationItems = generatePaginationItems()
|
const paginationItems = generatePaginationItems()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={`flex flex-wrap items-center gap-4 ${className || ""}`}>
|
||||||
className={`flex flex-wrap items-center justify-end gap-4 ${className || ""}`}
|
|
||||||
>
|
|
||||||
<div className="flex-none flex items-center gap-2 text-sm text-muted-foreground">
|
<div className="flex-none flex items-center gap-2 text-sm text-muted-foreground">
|
||||||
共 {total} 条记录,每页
|
共 {total} 条记录,每页
|
||||||
<Select value={size.toString()} onValueChange={handlePageSizeChange}>
|
<Select value={size.toString()} onValueChange={handlePageSizeChange}>
|
||||||
<SelectTrigger className="h-8 w-20 bg-card">
|
<SelectTrigger className="h-8 w-20">
|
||||||
<SelectValue />
|
<SelectValue />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
@@ -195,7 +193,6 @@ function PaginationLayout({
|
|||||||
}: React.ComponentProps<"nav">) {
|
}: React.ComponentProps<"nav">) {
|
||||||
return (
|
return (
|
||||||
<nav
|
<nav
|
||||||
role="navigation"
|
|
||||||
aria-label="pagination"
|
aria-label="pagination"
|
||||||
data-slot="pagination"
|
data-slot="pagination"
|
||||||
className={cn("flex-none", className)}
|
className={cn("flex-none", className)}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import * as SelectPrimitive from "@radix-ui/react-select"
|
import * as SelectPrimitive from "@radix-ui/react-select"
|
||||||
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||||
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ function SelectTrigger({
|
|||||||
data-size={size}
|
data-size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -65,7 +65,7 @@ function SelectContent({
|
|||||||
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
|
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
|
||||||
position === "popper" &&
|
position === "popper" &&
|
||||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
position={position}
|
position={position}
|
||||||
align={align}
|
align={align}
|
||||||
@@ -76,7 +76,7 @@ function SelectContent({
|
|||||||
className={cn(
|
className={cn(
|
||||||
"p-1",
|
"p-1",
|
||||||
position === "popper" &&
|
position === "popper" &&
|
||||||
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
|
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@@ -110,7 +110,7 @@ function SelectItem({
|
|||||||
data-slot="select-item"
|
data-slot="select-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -149,7 +149,7 @@ function SelectScrollUpButton({
|
|||||||
data-slot="select-scroll-up-button"
|
data-slot="select-scroll-up-button"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex cursor-default items-center justify-center py-1",
|
"flex cursor-default items-center justify-center py-1",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -167,7 +167,7 @@ function SelectScrollDownButton({
|
|||||||
data-slot="select-scroll-down-button"
|
data-slot="select-scroll-down-button"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex cursor-default items-center justify-center py-1",
|
"flex cursor-default items-center justify-center py-1",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
import * as SeparatorPrimitive from "@radix-ui/react-separator"
|
||||||
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ function Separator({
|
|||||||
orientation={orientation}
|
orientation={orientation}
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
|||||||
data-slot="table-footer"
|
data-slot="table-footer"
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
|
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -58,7 +58,7 @@ function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
|||||||
data-slot="table-row"
|
data-slot="table-row"
|
||||||
className={cn(
|
className={cn(
|
||||||
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -71,7 +71,7 @@ function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
|||||||
data-slot="table-head"
|
data-slot="table-head"
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -84,7 +84,7 @@ function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
|||||||
data-slot="table-cell"
|
data-slot="table-cell"
|
||||||
className={cn(
|
className={cn(
|
||||||
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||||
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ function TabsList({
|
|||||||
data-slot="tabs-list"
|
data-slot="tabs-list"
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@@ -43,7 +43,7 @@ function TabsTrigger({
|
|||||||
data-slot="tabs-trigger"
|
data-slot="tabs-trigger"
|
||||||
className={cn(
|
className={cn(
|
||||||
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import * as React from "react"
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
|||||||
data-slot="textarea"
|
data-slot="textarea"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:ring-destructive/40",
|
"flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:ring-destructive/40",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import * as React from "react"
|
|
||||||
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
||||||
|
import type * as React from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ function TooltipContent({
|
|||||||
sideOffset={sideOffset}
|
sideOffset={sideOffset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
|
"bg-foreground text-background animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-md px-3 py-1.5 text-xs text-balance",
|
||||||
className
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
import {
|
import { useCallback, useState } from "react"
|
||||||
type Dispatch,
|
|
||||||
type SetStateAction,
|
|
||||||
useCallback,
|
|
||||||
useEffect,
|
|
||||||
useState,
|
|
||||||
} from "react"
|
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import type { useDataTable } from "@/components/data-table"
|
import type { useDataTable } from "@/components/data-table"
|
||||||
import type { ApiResponse } from "@/lib/api"
|
import type { ApiResponse } from "@/lib/api"
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
export const BASE_URL = process.env.API_BASE_URL
|
export const BASE_URL = process.env.API_BASE_URL
|
||||||
export const CLIENT_ID = process.env.CLIENT_ID
|
export const CLIENT_ID = process.env.CLIENT_ID
|
||||||
export const CLIENT_SECRET = process.env.CLIENT_SECRET
|
export const CLIENT_SECRET = process.env.CLIENT_SECRET
|
||||||
|
|
||||||
|
// 产品代码枚举
|
||||||
|
export enum ProductCode {
|
||||||
|
All = "all",
|
||||||
|
Short = "short",
|
||||||
|
Long = "long",
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,65 +1,67 @@
|
|||||||
// 权限
|
// 权限
|
||||||
export const ScopePermission = "permission";
|
export const ScopePermission = "permission"
|
||||||
export const ScopePermissionRead = "permission:read"; // 读取权限列表
|
export const ScopePermissionRead = "permission:read" // 读取权限列表
|
||||||
export const ScopePermissionWrite = "permission:write"; // 写入权限
|
export const ScopePermissionWrite = "permission:write" // 写入权限
|
||||||
|
|
||||||
// 管理员角色
|
// 管理员角色
|
||||||
export const ScopeAdminRole = "admin_role";
|
export const ScopeAdminRole = "admin_role"
|
||||||
export const ScopeAdminRoleRead = "admin_role:read"; // 读取管理员角色列表
|
export const ScopeAdminRoleRead = "admin_role:read" // 读取管理员角色列表
|
||||||
export const ScopeAdminRoleWrite = "admin_role:write"; // 写入管理员角色
|
export const ScopeAdminRoleWrite = "admin_role:write" // 写入管理员角色
|
||||||
|
|
||||||
// 管理员
|
// 管理员
|
||||||
export const ScopeAdmin = "admin";
|
export const ScopeAdmin = "admin"
|
||||||
export const ScopeAdminRead = "admin:read"; // 读取管理员列表
|
export const ScopeAdminRead = "admin:read" // 读取管理员列表
|
||||||
export const ScopeAdminWrite = "admin:write"; // 写入管理员
|
export const ScopeAdminWrite = "admin:write" // 写入管理员
|
||||||
|
|
||||||
// 产品
|
// 产品
|
||||||
export const ScopeProduct = "product";
|
export const ScopeProduct = "product"
|
||||||
export const ScopeProductRead = "product:read"; // 读取产品列表
|
export const ScopeProductRead = "product:read" // 读取产品列表
|
||||||
export const ScopeProductWrite = "product:write"; // 写入产品
|
export const ScopeProductWrite = "product:write" // 写入产品
|
||||||
|
|
||||||
// 产品套餐
|
// 产品套餐
|
||||||
export const ScopeProductSku = "product_sku";
|
export const ScopeProductSku = "product_sku"
|
||||||
export const ScopeProductSkuRead = "product_sku:read"; // 读取产品套餐列表
|
export const ScopeProductSkuRead = "product_sku:read" // 读取产品套餐列表
|
||||||
export const ScopeProductSkuWrite = "product_sku:write"; // 写入产品套餐
|
export const ScopeProductSkuWrite = "product_sku:write" // 写入产品套餐
|
||||||
|
|
||||||
// 折扣
|
// 折扣
|
||||||
export const ScopeDiscount = "discount";
|
export const ScopeDiscount = "discount"
|
||||||
export const ScopeDiscountRead = "discount:read"; // 读取折扣列表
|
export const ScopeDiscountRead = "discount:read" // 读取折扣列表
|
||||||
export const ScopeDiscountWrite = "discount:write"; // 写入折扣
|
export const ScopeDiscountWrite = "discount:write" // 写入折扣
|
||||||
|
|
||||||
// 用户套餐
|
// 用户套餐
|
||||||
export const ScopeResource = "resource";
|
export const ScopeResource = "resource"
|
||||||
export const ScopeResourceRead = "resource:read"; // 读取用户套餐列表
|
export const ScopeResourceRead = "resource:read" // 读取用户套餐列表
|
||||||
export const ScopeResourceWrite = "resource:write"; // 写入用户套餐
|
export const ScopeResourceWrite = "resource:write" // 写入用户套餐
|
||||||
|
|
||||||
// 用户
|
// 用户
|
||||||
export const ScopeUser = "user";
|
export const ScopeUser = "user"
|
||||||
export const ScopeUserRead = "user:read"; // 读取用户列表
|
export const ScopeUserRead = "user:read" // 读取用户列表
|
||||||
export const ScopeUserWrite = "user:write"; // 写入用户
|
export const ScopeUserWrite = "user:write" // 写入用户
|
||||||
export const ScopeUserWriteBalance = "user:write:balance"; // 写入用户余额
|
export const ScopeUserWriteBalance = "user:write:balance" // 写入用户余额
|
||||||
|
export const ScopeUserReadOne = "user:read:one" // 读取单个用户
|
||||||
|
export const ScopeUserWriteBind = "user:write:bind" // 认领用户
|
||||||
|
|
||||||
// 优惠券
|
// 优惠券
|
||||||
export const ScopeCoupon = "coupon";
|
export const ScopeCoupon = "coupon"
|
||||||
export const ScopeCouponRead = "coupon:read"; // 读取优惠券列表
|
export const ScopeCouponRead = "coupon:read" // 读取优惠券列表
|
||||||
export const ScopeCouponWrite = "coupon:write"; // 写入优惠券
|
export const ScopeCouponWrite = "coupon:write" // 写入优惠券
|
||||||
|
|
||||||
// 批次
|
// 批次
|
||||||
export const ScopeBatch = "batch";
|
export const ScopeBatch = "batch"
|
||||||
export const ScopeBatchRead = "batch:read"; // 读取批次列表
|
export const ScopeBatchRead = "batch:read" // 读取批次列表
|
||||||
export const ScopeBatchWrite = "batch:write"; // 写入批次
|
export const ScopeBatchWrite = "batch:write" // 写入批次
|
||||||
|
|
||||||
// IP
|
// IP
|
||||||
export const ScopeChannel = "channel";
|
export const ScopeChannel = "channel"
|
||||||
export const ScopeChannelRead = "channel:read"; // 读取 IP 列表
|
export const ScopeChannelRead = "channel:read" // 读取 IP 列表
|
||||||
export const ScopeChannelWrite = "channel:write"; // 写入 IP
|
export const ScopeChannelWrite = "channel:write" // 写入 IP
|
||||||
|
|
||||||
// 交易
|
// 交易
|
||||||
export const ScopeTrade = "trade";
|
export const ScopeTrade = "trade"
|
||||||
export const ScopeTradeRead = "trade:read"; // 读取交易列表
|
export const ScopeTradeRead = "trade:read" // 读取交易列表
|
||||||
export const ScopeTradeWrite = "trade:write"; // 写入交易
|
export const ScopeTradeWrite = "trade:write" // 写入交易
|
||||||
|
|
||||||
// 账单
|
// 账单
|
||||||
export const ScopeBill = "bill";
|
export const ScopeBill = "bill"
|
||||||
export const ScopeBillRead = "bill:read"; // 读取账单列表
|
export const ScopeBillRead = "bill:read" // 读取账单列表
|
||||||
export const ScopeBillWrite = "bill:write"; // 写入账单
|
export const ScopeBillWrite = "bill:write" // 写入账单
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import type { Resource } from "./resources"
|
||||||
|
import type { User } from "./user"
|
||||||
|
|
||||||
export type Batch = {
|
export type Batch = {
|
||||||
id: number
|
id: number
|
||||||
batch_no: string
|
batch_no: string
|
||||||
@@ -8,4 +11,6 @@ export type Batch = {
|
|||||||
count: string
|
count: string
|
||||||
resource_id: string
|
resource_id: string
|
||||||
time: string
|
time: string
|
||||||
|
user?: User
|
||||||
|
resource?: Resource
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
|
import type { Resource } from "./resources"
|
||||||
|
import type { Trade } from "./trade"
|
||||||
|
import type { User } from "./user"
|
||||||
|
|
||||||
export type Billing = {
|
export type Billing = {
|
||||||
|
id: string
|
||||||
|
bill_no: string
|
||||||
type: number
|
type: number
|
||||||
info: string
|
info: string
|
||||||
amount: number
|
amount: number
|
||||||
|
actual: number
|
||||||
|
inner_no: string
|
||||||
created_at: Date
|
created_at: Date
|
||||||
updated_at: Date
|
updated_at: Date
|
||||||
|
user: User
|
||||||
|
resource?: Resource
|
||||||
|
trade?: Trade
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import type { Resource } from "./resources"
|
||||||
|
import type { User } from "./user"
|
||||||
|
|
||||||
export type Channel = {
|
export type Channel = {
|
||||||
id: number
|
id: number
|
||||||
batch_no: string
|
batch_no: string
|
||||||
@@ -12,4 +15,9 @@ export type Channel = {
|
|||||||
created_at: Date
|
created_at: Date
|
||||||
updated_at: Date
|
updated_at: Date
|
||||||
expired_at: Date
|
expired_at: Date
|
||||||
|
edge_id: number
|
||||||
|
edge_ref: string
|
||||||
|
ip: string
|
||||||
|
user?: User
|
||||||
|
resource?: Resource
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/models/coupon.ts
Normal file
12
src/models/coupon.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export type Coupon = {
|
||||||
|
id: number
|
||||||
|
created_at: Date
|
||||||
|
updated_at: Date
|
||||||
|
user_id: number
|
||||||
|
code: string
|
||||||
|
remark: string
|
||||||
|
amount: number
|
||||||
|
min_amount: number
|
||||||
|
status: number
|
||||||
|
expire_at: Date
|
||||||
|
}
|
||||||
34
src/models/cust.ts
Normal file
34
src/models/cust.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import type { ProductDiscount } from "./product_discount"
|
||||||
|
|
||||||
|
export type Cust = {
|
||||||
|
id: number
|
||||||
|
admin_id?: number
|
||||||
|
phone: string
|
||||||
|
admin?: Admin
|
||||||
|
password: string
|
||||||
|
source: number
|
||||||
|
discount_id: string
|
||||||
|
has_password: boolean
|
||||||
|
username: string
|
||||||
|
email: string
|
||||||
|
name: string
|
||||||
|
avatar: string
|
||||||
|
status: number
|
||||||
|
balance: number
|
||||||
|
id_type: number
|
||||||
|
id_no: string
|
||||||
|
id_token: string
|
||||||
|
contact_qq: string
|
||||||
|
contact_wechat: string
|
||||||
|
last_login: Date
|
||||||
|
last_login_host: string
|
||||||
|
last_login_agent: string
|
||||||
|
last_login_ip: string
|
||||||
|
created_at: Date
|
||||||
|
updated_at: Date
|
||||||
|
discount: ProductDiscount
|
||||||
|
}
|
||||||
|
export type Admin = {
|
||||||
|
name: string
|
||||||
|
password: string
|
||||||
|
}
|
||||||
@@ -1,8 +1,56 @@
|
|||||||
export type Resources = {
|
import type { ProductSku } from "./product_sku"
|
||||||
|
import type { User } from "./user"
|
||||||
|
|
||||||
|
type ResourceBase = {
|
||||||
id: number
|
id: number
|
||||||
|
user_id: number
|
||||||
resource_no: string
|
resource_no: string
|
||||||
active: string
|
active: boolean
|
||||||
type: string
|
|
||||||
created_at: Date
|
created_at: Date
|
||||||
updated_at: Date
|
updated_at: Date
|
||||||
|
deleted_at: Date | null
|
||||||
|
user: User
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResourceShort = {
|
||||||
|
id: number
|
||||||
|
resource_id: number
|
||||||
|
type: number
|
||||||
|
live: number
|
||||||
|
quota: number
|
||||||
|
used: number
|
||||||
|
daily: number
|
||||||
|
last_at: Date | null
|
||||||
|
expire_at: Date
|
||||||
|
sku?: ProductSku
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResourceLong = {
|
||||||
|
id: number
|
||||||
|
resource_id: number
|
||||||
|
type: number
|
||||||
|
live: number
|
||||||
|
quota: number
|
||||||
|
used: number
|
||||||
|
daily: number
|
||||||
|
last_at: Date | null
|
||||||
|
expire_at: Date
|
||||||
|
sku?: ProductSku
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Resource<T extends 1 | 2 = 1 | 2> = ResourceBase &
|
||||||
|
(T extends 1
|
||||||
|
? {
|
||||||
|
type: 1
|
||||||
|
short: ResourceShort
|
||||||
|
}
|
||||||
|
: T extends 2
|
||||||
|
? {
|
||||||
|
type: 2
|
||||||
|
long: ResourceLong
|
||||||
|
}
|
||||||
|
: {})
|
||||||
|
|
||||||
|
export type Resources = Resource<1> | Resource<2>
|
||||||
|
export type ResourcesShort = ResourceShort
|
||||||
|
export type ResourcesLong = ResourceLong
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
|
import type { User } from "./user"
|
||||||
|
|
||||||
export type Trade = {
|
export type Trade = {
|
||||||
id: number
|
id: number
|
||||||
inner_no: string
|
inner_no: string
|
||||||
method: number
|
method: number // 支付方式:1-支付宝,2-微信,3-商福通,4-商福通渠道支付宝,5-商福通渠道微信
|
||||||
payment: string
|
payment: string
|
||||||
|
acquirer: number //收单机构:1-支付宝,2-微信,3-银联
|
||||||
platform: number
|
platform: number
|
||||||
|
type: number
|
||||||
|
subject: string
|
||||||
status: number
|
status: number
|
||||||
created_at: Date
|
created_at: Date
|
||||||
|
canceled_at: Date
|
||||||
updated_at: Date
|
updated_at: Date
|
||||||
|
user?: User
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export type User = {
|
|||||||
admin_id?: number
|
admin_id?: number
|
||||||
admin?: Admin
|
admin?: Admin
|
||||||
phone: string
|
phone: string
|
||||||
|
source: number
|
||||||
has_password: boolean
|
has_password: boolean
|
||||||
username: string
|
username: string
|
||||||
email: string
|
email: string
|
||||||
@@ -20,6 +21,7 @@ export type User = {
|
|||||||
last_login: Date
|
last_login: Date
|
||||||
last_login_host: string
|
last_login_host: string
|
||||||
last_login_agent: string
|
last_login_agent: string
|
||||||
|
last_login_ip: string
|
||||||
created_at: Date
|
created_at: Date
|
||||||
updated_at: Date
|
updated_at: Date
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { useSetAtom } from "jotai"
|
|
||||||
import { type NextRequest, NextResponse, type ProxyConfig } from "next/server"
|
import { type NextRequest, NextResponse, type ProxyConfig } from "next/server"
|
||||||
import { refreshAuth } from "@/actions/auth"
|
import { refreshAuth } from "@/actions/auth"
|
||||||
|
|
||||||
|
|||||||
@@ -15,19 +15,19 @@
|
|||||||
"incremental": true,
|
"incremental": true,
|
||||||
"plugins": [
|
"plugins": [
|
||||||
{
|
{
|
||||||
"name": "next",
|
"name": "next"
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"],
|
"@/*": ["./src/*"]
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"next-env.d.ts",
|
"next-env.d.ts",
|
||||||
"**/*.ts",
|
"**/*.ts",
|
||||||
"**/*.tsx",
|
"**/*.tsx",
|
||||||
".next/types/**/*.ts",
|
".next/types/**/*.ts",
|
||||||
".next/dev/types/**/*.ts",
|
".next/dev/types/**/*.ts"
|
||||||
],
|
],
|
||||||
"exclude": ["node_modules"],
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user