更新客户管理模块

This commit is contained in:
Eamon
2026-03-28 14:28:32 +08:00
parent 76d2d480ed
commit f72b6bddd0
7 changed files with 543 additions and 210 deletions

View File

@@ -4,6 +4,10 @@ import type { PageRecord } from "@/lib/api"
import type { Admin } from "@/models/admin"
import { callByUser } from "./base"
export async function getAllAdmin() {
return callByUser<Admin[]>("/api/admin/admin/all")
}
export async function getPageAdmin(params: { page: number; size: number }) {
return callByUser<PageRecord<Admin>>("/api/admin/admin/page", params)
}

View File

@@ -10,15 +10,20 @@ export async function updateCust(data: {
phone: string
email: string
}) {
return callByUser<PageRecord<Cust>>("/api/admin/user/updateCust", data)
return callByUser<PageRecord<Cust>>("/api/admin/user/update", data)
}
export async function createCust(data: {
username: string
password: string
username: string
phone: 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)

View File

@@ -0,0 +1,417 @@
"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().min(1, "账号不能为空"),
password: z.string().min(6, "密码至少6位"),
confirmPassword: z.string().min(1, "请确认密码"),
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 => data.password === data.confirmPassword, {
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()
console.log("折扣res", res)
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()
console.log(res, "管理员res")
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 = {
username: data.username,
password: data.password,
phone: data.phone,
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></FieldLabel>
<Input
{...field}
type="password"
placeholder="请输入密码至少6位"
autoComplete="off"
/>
<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="请再次输入密码"
autoComplete="off"
/>
<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>
)
}

View File

@@ -1,20 +1,15 @@
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import { format } from "date-fns"
import { Suspense, useCallback, useState } from "react"
import { Suspense, useCallback, useRef, useState } from "react"
import { Controller, useForm } from "react-hook-form"
import { toast } from "sonner"
import { z } from "zod"
import { createCust, getPageCusts, updateCust } from "@/actions/cust"
import { getPageCusts, updateCust } from "@/actions/cust"
import { DataTable, useDataTable } from "@/components/data-table"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import {
Field,
FieldError,
@@ -30,9 +25,10 @@ import {
SelectValue,
} from "@/components/ui/select"
import type { Cust } from "@/models/cust"
import { AddUserDialog } from "./create"
type FilterValues = {
phone?: string
account?: string
name?: string
identified?: boolean
enabled?: boolean
@@ -42,7 +38,7 @@ type FilterValues = {
const filterSchema = z
.object({
phone: z.string().optional(),
account: z.string().optional(),
name: z.string().optional(),
identified: z.string().optional(),
enabled: z.string().optional(),
@@ -64,17 +60,6 @@ const filterSchema = z
}
})
const addUserSchema = z.object({
username: z.string().min(1, "账号不能为空"),
password: z.string().min(6, "密码至少6位"),
phone: z.string().regex(/^1[3-9]\d{9}$/, "请输入正确的手机号格式"),
email: z.string().email("请输入正确的邮箱格式").optional().or(z.literal("")),
name: z.string().optional(),
contact_wechat: z.string().optional(),
})
type AddUserFormValues = z.infer<typeof addUserSchema>
type FormValues = z.infer<typeof filterSchema>
export default function UserPage() {
@@ -84,12 +69,13 @@ export default function UserPage() {
const [editEmail, setEditEmail] = useState("")
const [isSaving, setIsSaving] = useState(false)
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false)
const [isAdding, setIsAdding] = useState(false)
const editingRowRef = useRef<Cust | null>(null)
const { control, handleSubmit, reset } = useForm<FormValues>({
resolver: zodResolver(filterSchema),
defaultValues: {
phone: "",
account: "",
name: "",
identified: "all",
enabled: "all",
@@ -98,75 +84,55 @@ export default function UserPage() {
},
})
// 添加用户表单
const {
control: addControl,
handleSubmit: handleAddSubmit,
reset: resetAddForm,
formState: { errors: addErrors },
} = useForm<AddUserFormValues>({
resolver: zodResolver(addUserSchema),
defaultValues: {
username: "",
password: "",
phone: "",
email: "",
name: "",
contact_wechat: "",
},
})
const fetchUsers = useCallback(
(page: number, size: number) => getPageCusts({ page, size, ...filters }),
[filters],
)
const table = useDataTable<Cust>(fetchUsers)
console.log(table, "table")
const onFilter = handleSubmit(data => {
const result: FilterValues = {}
if (data.phone) result.phone = data.phone
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.pagination.onPageChange(table.pagination.page)
}, [table.pagination])
table.refresh()
}, [table])
// 开始编辑行
const startEdit = (row: Cust) => {
setEditingRowId(row.id)
setEditPhone(row.phone || "")
setEditEmail(row.email || "")
editingRowRef.current = row
}
// 取消编辑
const cancelEdit = () => {
setEditingRowId(null)
setEditPhone("")
setEditEmail("")
editingRowRef.current = null
}
// 保存编辑
const saveEdit = async (row: Cust) => {
const phoneRegex = /^1[3-9]\d{9}$/
if (editPhone && !phoneRegex.test(editPhone)) {
toast.error("请输入正确的手机号格式")
return
return false
}
const emailRegex = /^[^\s@]+@([^\s@]+\.)+[^\s@]+$/
if (editEmail && !emailRegex.test(editEmail)) {
toast.error("请输入正确的邮箱格式")
return
return false
}
setIsSaving(true)
@@ -178,52 +144,24 @@ export default function UserPage() {
})
if (result.success) {
toast.success("更新成功")
table.pagination.onPageChange(table.pagination.page)
refreshTable()
cancelEdit()
return true
} else {
toast.error(result.message || "更新失败")
return false
}
} catch (error) {
toast.error("更新失败,请稍后重试")
console.error(error)
return false
} finally {
setIsSaving(false)
}
}
const onAddUser = handleAddSubmit(async data => {
const payload = {
username: data.username,
password: data.password,
phone: data.phone || "",
email: data.email || "",
name: data.name || "",
contact_wechat: data.contact_wechat || "",
}
setIsAdding(true)
try {
const result = await createCust(payload)
if (result?.success) {
toast.success("添加用户成功")
setIsAddDialogOpen(false)
resetAddForm()
refreshTable()
} else {
toast.error(result?.message || "添加失败")
}
} catch (error) {
toast.error("添加失败,请稍后重试")
console.error(error)
} finally {
setIsAdding(false)
}
})
// 打开添加对话框时重置表单
const openAddDialog = () => {
resetAddForm()
setIsAddDialogOpen(true)
const handleAddUserSuccess = () => {
refreshTable()
}
return (
@@ -231,15 +169,15 @@ export default function UserPage() {
<form onSubmit={onFilter} className="bg-white p-4">
<div className="flex flex-wrap items-end gap-4">
<Controller
name="phone"
name="account"
control={control}
render={({ field, fieldState }) => (
<Field
data-invalid={fieldState.invalid}
className="w-40 flex-none"
className="w-80 flex-none"
>
<FieldLabel></FieldLabel>
<Input {...field} placeholder="请输入手机号" />
<FieldLabel>//</FieldLabel>
<Input {...field} placeholder="请输入账号/手机号/邮箱" />
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
@@ -253,8 +191,8 @@ export default function UserPage() {
data-invalid={fieldState.invalid}
className="w-40 flex-none"
>
<FieldLabel></FieldLabel>
<Input {...field} placeholder="请输入账户" />
<FieldLabel></FieldLabel>
<Input {...field} placeholder="请输入姓名" />
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
@@ -267,7 +205,7 @@ export default function UserPage() {
<Field data-invalid={fieldState.invalid} className="w-24">
<FieldLabel></FieldLabel>
<Select value={field.value} onValueChange={field.onChange}>
<SelectTrigger>
<SelectTrigger className="w-24">
<SelectValue placeholder="全部" />
</SelectTrigger>
<SelectContent>
@@ -339,11 +277,12 @@ export default function UserPage() {
variant="outline"
onClick={() => {
reset({
phone: "",
account: "",
name: "",
identified: "all",
enabled: "all",
created_at_start: "",
created_at_end: "",
})
setFilters({})
table.pagination.onPageChange(1)
@@ -351,7 +290,7 @@ export default function UserPage() {
>
</Button>
<Button type="button" onClick={openAddDialog}>
<Button type="button" onClick={() => setIsAddDialogOpen(true)}>
</Button>
</FieldGroup>
@@ -363,7 +302,6 @@ export default function UserPage() {
columns={[
{ header: "ID", accessorKey: "id" },
{ header: "账号", accessorKey: "username" },
{ header: "密码", accessorKey: "admin.password" },
{
header: "手机",
accessorKey: "phone",
@@ -374,8 +312,26 @@ export default function UserPage() {
<Input
value={editPhone}
onChange={e => setEditPhone(e.target.value)}
onBlur={() => {
if (editingRowRef.current) {
saveEdit(editingRowRef.current)
}
}}
onKeyDown={e => {
if (e.key === "Enter") {
e.preventDefault()
if (editingRowRef.current) {
saveEdit(editingRowRef.current)
}
}
if (e.key === "Escape") {
e.preventDefault()
cancelEdit()
}
}}
placeholder="手机号"
className="w-32"
autoFocus
/>
)
}
@@ -392,6 +348,23 @@ export default function UserPage() {
<Input
value={editEmail}
onChange={e => setEditEmail(e.target.value)}
onBlur={() => {
if (editingRowRef.current) {
saveEdit(editingRowRef.current)
}
}}
onKeyDown={e => {
if (e.key === "Enter") {
e.preventDefault()
if (editingRowRef.current) {
saveEdit(editingRowRef.current)
}
}
if (e.key === "Escape") {
e.preventDefault()
cancelEdit()
}
}}
placeholder="邮箱"
className="w-40"
/>
@@ -401,6 +374,19 @@ export default function UserPage() {
},
},
{ 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",
@@ -417,6 +403,7 @@ export default function UserPage() {
)
},
},
{ header: "折扣", accessorKey: "discount.name" },
{
header: "实名状态",
accessorKey: "id_type",
@@ -447,7 +434,6 @@ export default function UserPage() {
cell: ({ row }) => (row.original.status === 1 ? "正常" : "禁用"),
},
{ header: "联系方式", accessorKey: "contact_wechat" },
{ header: "客户来源", accessorKey: "" },
{ header: "客户经理", accessorKey: "admin.name" },
{
header: "最后登录时间",
@@ -506,103 +492,12 @@ export default function UserPage() {
]}
/>
</Suspense>
{/* 添加用户对话框 */}
<Dialog open={isAddDialogOpen} onOpenChange={setIsAddDialogOpen}>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
<DialogTitle></DialogTitle>
</DialogHeader>
<form onSubmit={onAddUser} className="space-y-4">
<Controller
name="username"
control={addControl}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel> *</FieldLabel>
<Input
{...field}
placeholder="请输入账号"
autoComplete="off"
/>
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
/>
<Controller
name="password"
control={addControl}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel> *</FieldLabel>
<Input
{...field}
type="password"
placeholder="请输入密码至少6位"
autoComplete="off"
/>
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
/>
<Controller
name="phone"
control={addControl}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel> *</FieldLabel>
<Input {...field} placeholder="请输入手机号" />
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
/>
<Controller
name="name"
control={addControl}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel></FieldLabel>
<Input {...field} placeholder="请输入姓名" />
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
/>
<Controller
name="email"
control={addControl}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel></FieldLabel>
<Input {...field} placeholder="请输入邮箱" />
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
/>
<Controller
name="contact_wechat"
control={addControl}
render={({ field, fieldState }) => (
<Field data-invalid={fieldState.invalid}>
<FieldLabel>/</FieldLabel>
<Input {...field} placeholder="请输入微信或联系方式" />
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
/>
<FieldGroup className="flex-row justify-end gap-2 pt-2">
<Button
type="button"
variant="outline"
onClick={() => setIsAddDialogOpen(false)}
>
</Button>
<Button type="submit" disabled={isAdding}>
{isAdding ? "添加中..." : "确定添加"}
</Button>
</FieldGroup>
</form>
</DialogContent>
</Dialog>
<AddUserDialog
open={isAddDialogOpen}
onOpenChange={setIsAddDialogOpen}
onSuccess={handleAddUserSuccess}
/>
</div>
)
}

View File

@@ -15,13 +15,6 @@ import {
FieldLabel,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { useFetch } from "@/hooks/data"
import type { User } from "@/models/user"
@@ -67,6 +60,7 @@ export default function UserPage() {
done: "用户已认领",
fail: "用户认领失败",
})
console.log(table, "table")
const onFilter = handleSubmit(data => {
const result: FilterValues = {}
@@ -94,10 +88,10 @@ export default function UserPage() {
render={({ field, fieldState }) => (
<Field
data-invalid={fieldState.invalid}
className="w-40 flex-none"
className="w-80 flex-none"
>
<FieldLabel></FieldLabel>
<Input {...field} placeholder="请输入账号" />
<FieldLabel>//</FieldLabel>
<Input {...field} placeholder="请输入账号/手机号/邮箱" />
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
@@ -111,14 +105,14 @@ export default function UserPage() {
data-invalid={fieldState.invalid}
className="w-40 flex-none"
>
<FieldLabel>--</FieldLabel>
<Input {...field} placeholder="请输入用户名-手机号-邮箱" />
<FieldLabel></FieldLabel>
<Input {...field} placeholder="请输入姓名" />
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
/>
<Controller
{/* <Controller
name="identified"
control={control}
render={({ field, fieldState }) => (
@@ -179,7 +173,7 @@ export default function UserPage() {
<FieldError>{fieldState.error?.message}</FieldError>
</Field>
)}
/>
/> */}
</div>
<FieldGroup className="flex-row justify-start mt-4 gap-2">
@@ -253,6 +247,19 @@ export default function UserPage() {
return idNo ? `${idNo.slice(0, 6)}****${idNo.slice(-4)}` : "-"
},
},
{
header: "客户来源",
accessorKey: "source",
cell: ({ row }) => {
const sourceMap: Record<number, string> = {
0: "官网注册",
1: "管理员添加",
2: "代理商注册",
3: "代理商添加",
}
return sourceMap[row.original.source] ?? "未知"
},
},
{
header: "账号状态",
accessorKey: "status",

View File

@@ -1,8 +1,11 @@
import type { ProductDiscount } from "./product_discount"
export type Cust = {
id: number
admin_id?: number
phone: string
admin?: Admin
source: number
has_password: boolean
username: string
email: string
@@ -21,6 +24,7 @@ export type Cust = {
last_login_ip: string
created_at: Date
updated_at: Date
discount: ProductDiscount
}
export type Admin = {
name: string

View File

@@ -4,7 +4,8 @@ export type User = {
id: number
admin_id?: number
admin?: Admin
phone: string
account: string
source: number
has_password: boolean
username: string
email: string