Compare commits
10
Commits
d00de04c27
...
7c7ede7d49
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c7ede7d49 | ||
|
|
e8d4df463e | ||
|
|
9c24ab95c5 | ||
|
|
7e7044ceb0 | ||
|
|
4b2334fb70 | ||
|
|
6a63e404f1 | ||
|
|
c81962b732 | ||
|
|
d981e53330 | ||
|
|
3535f56702 | ||
|
|
f0254f20bd |
+1
-1
@@ -4,7 +4,7 @@ DATABASE_URL="mysql://crm_dev:PASSWORD@124.223.187.95:3306/crm_dev"
|
|||||||
# Auth.js 会话加密密钥:openssl rand -base64 32
|
# Auth.js 会话加密密钥:openssl rand -base64 32
|
||||||
AUTH_SECRET="please-run-openssl-rand-base64-32"
|
AUTH_SECRET="please-run-openssl-rand-base64-32"
|
||||||
|
|
||||||
# 开发环境不需要 AUTH_URL(trustHost:true 自动识别 host/端口)。
|
# 本地开发不要设置 AUTH_URL,否则打开 localhost 会被跳到该地址。
|
||||||
# 生产必须设为浏览器可访问的地址(真实域名或公网 IP),
|
# 生产必须设为浏览器可访问的地址(真实域名或公网 IP),
|
||||||
# 切勿写成监听地址 0.0.0.0,否则登录/退出会跳到 http://0.0.0.0:端口
|
# 切勿写成监听地址 0.0.0.0,否则登录/退出会跳到 http://0.0.0.0:端口
|
||||||
# AUTH_URL="https://crm.yourdomain.com"
|
# AUTH_URL="https://crm.yourdomain.com"
|
||||||
|
|||||||
Generated
+1
@@ -7,6 +7,7 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "crm-new",
|
"name": "crm-new",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "^6.11.0",
|
"@prisma/client": "^6.11.0",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
|
|||||||
Generated
+2111
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
|||||||
|
allowBuilds:
|
||||||
|
'@prisma/client': true
|
||||||
|
'@prisma/engines': true
|
||||||
|
esbuild: true
|
||||||
|
prisma: true
|
||||||
@@ -16,7 +16,9 @@ datasource db {
|
|||||||
/// 客户(系统核心,~1.4 万行)
|
/// 客户(系统核心,~1.4 万行)
|
||||||
model Customer {
|
model Customer {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
customerName String? @default("") @map("customer_name")
|
customerName String? @default("") @map("customer_name") // 商户注册名称
|
||||||
|
businessName String? @map("business_name") // 商户经营名称
|
||||||
|
customerNo String? @map("customer_no") @db.Text // 商户编号,数字与字母,区分大小写,不限位数
|
||||||
contacts String? // 联系人
|
contacts String? // 联系人
|
||||||
contactsPhone String? @default("") @map("contacts_phone") // 联系人手机号
|
contactsPhone String? @default("") @map("contacts_phone") // 联系人手机号
|
||||||
balanceUser String? @map("balance_user") // 结算人
|
balanceUser String? @map("balance_user") // 结算人
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- 商户表增加商户经营名称
|
||||||
|
-- 执行:本地与生产库均需执行;执行后运行 npm run prisma:generate
|
||||||
|
-- 历史行保持 NULL,新录入/导入必填
|
||||||
|
|
||||||
|
ALTER TABLE customers
|
||||||
|
ADD COLUMN business_name VARCHAR(500) NULL COMMENT '商户经营名称' AFTER customer_name;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- 商户表增加商户编号(数字+字母,区分大小写,不限位数)
|
||||||
|
-- 执行:本地与生产库均需执行;执行后运行 npm run prisma:generate
|
||||||
|
-- 历史行保持 NULL,新录入/导入必填
|
||||||
|
|
||||||
|
ALTER TABLE customers
|
||||||
|
ADD COLUMN customer_no TEXT NULL COMMENT '商户编号' AFTER customer_name;
|
||||||
@@ -11,8 +11,17 @@ import { isSuperAdmin } from "@/lib/acl";
|
|||||||
import { fmtDate, parseDate } from "@/lib/utils";
|
import { fmtDate, parseDate } from "@/lib/utils";
|
||||||
|
|
||||||
// 校验规则对齐老系统必填项(customer_name/contacts/balance_user/detail/salesman/report_date)
|
// 校验规则对齐老系统必填项(customer_name/contacts/balance_user/detail/salesman/report_date)
|
||||||
|
// 商户编号非必填;有值时仅允许数字和字母
|
||||||
|
const customerNoSchema = z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.default("")
|
||||||
|
.refine((s) => s === "" || /^[A-Za-z0-9]+$/.test(s), "商户编号只能包含数字和字母,区分大小写");
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
customerName: z.string().trim().min(1, "商户名称必填").max(500),
|
customerName: z.string().trim().min(1, "商户注册名称必填").max(500),
|
||||||
|
businessName: z.string().trim().min(1, "商户经营名称必填").max(500),
|
||||||
|
customerNo: customerNoSchema,
|
||||||
contacts: z.string().trim().min(1, "联系人必填").max(500),
|
contacts: z.string().trim().min(1, "联系人必填").max(500),
|
||||||
balanceUser: z.string().trim().min(1, "结算人必填").max(500),
|
balanceUser: z.string().trim().min(1, "结算人必填").max(500),
|
||||||
detail: z.string().trim().min(1, "产品明细必填"),
|
detail: z.string().trim().min(1, "产品明细必填"),
|
||||||
@@ -26,20 +35,20 @@ const schema = z.object({
|
|||||||
balanceUserPhone: z.string().trim().optional().default(""),
|
balanceUserPhone: z.string().trim().optional().default(""),
|
||||||
deposit: z.string().trim().optional().default(""),
|
deposit: z.string().trim().optional().default(""),
|
||||||
buy: z.string().trim().optional().default(""),
|
buy: z.string().trim().optional().default(""),
|
||||||
birthdayType: z.coerce.number().int().min(1).max(2).default(1),
|
birthdayType: z.coerce.number().refine((n) => n === 1, "生日类型只能是阳历"),
|
||||||
birthdayOwner: z.coerce.number().int().min(1).max(2).default(2),
|
birthdayOwner: z.coerce.number().refine((n) => n === 1, "生日归属只能是结算人"),
|
||||||
birthday: z.string().trim().optional().default(""),
|
birthday: z.string().trim().optional().default(""),
|
||||||
remark: z.string().trim().optional().default(""),
|
remark: z.string().trim().optional().default(""),
|
||||||
});
|
});
|
||||||
|
|
||||||
// 新增商户更严格:名称无空格、联系人/结算人手机号必填 11 位、押金/买断/生日必填(仅用于创建,编辑仍用 schema)
|
// 新增商户更严格:注册名称无空格、联系人/结算人手机号必填 11 位、押金/买断/生日必填(仅用于 create,编辑仍用 schema)
|
||||||
const createSchema = schema.extend({
|
const createSchema = schema.extend({
|
||||||
customerName: z
|
customerName: z
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.min(1, "商户名称必填")
|
.min(1, "商户注册名称必填")
|
||||||
.max(500)
|
.max(500)
|
||||||
.refine((s) => !/\s/.test(s), "商户名称不能包含空格"),
|
.refine((s) => !/\s/.test(s), "商户注册名称不能包含空格"),
|
||||||
contactsPhone: z.string().trim().regex(/^1\d{10}$/, "联系人手机号必须为 11 位数字"),
|
contactsPhone: z.string().trim().regex(/^1\d{10}$/, "联系人手机号必须为 11 位数字"),
|
||||||
balanceUserPhone: z.string().trim().regex(/^1\d{10}$/, "结算人手机号必须为 11 位数字"),
|
balanceUserPhone: z.string().trim().regex(/^1\d{10}$/, "结算人手机号必须为 11 位数字"),
|
||||||
deposit: z.string().trim().min(1, "押金必填"),
|
deposit: z.string().trim().min(1, "押金必填"),
|
||||||
@@ -57,6 +66,8 @@ export type ActionState = { error?: string };
|
|||||||
function pickForm(formData: FormData) {
|
function pickForm(formData: FormData) {
|
||||||
return {
|
return {
|
||||||
customerName: formData.get("customerName"),
|
customerName: formData.get("customerName"),
|
||||||
|
businessName: formData.get("businessName"),
|
||||||
|
customerNo: formData.get("customerNo") ?? "",
|
||||||
contacts: formData.get("contacts"),
|
contacts: formData.get("contacts"),
|
||||||
balanceUser: formData.get("balanceUser"),
|
balanceUser: formData.get("balanceUser"),
|
||||||
detail: formData.get("detail"),
|
detail: formData.get("detail"),
|
||||||
@@ -66,8 +77,8 @@ function pickForm(formData: FormData) {
|
|||||||
balanceUserPhone: formData.get("balanceUserPhone") ?? "",
|
balanceUserPhone: formData.get("balanceUserPhone") ?? "",
|
||||||
deposit: formData.get("deposit") ?? "",
|
deposit: formData.get("deposit") ?? "",
|
||||||
buy: formData.get("buy") ?? "",
|
buy: formData.get("buy") ?? "",
|
||||||
birthdayType: formData.get("birthdayType") ?? 1,
|
birthdayType: 1,
|
||||||
birthdayOwner: formData.get("birthdayOwner") ?? 2,
|
birthdayOwner: 1,
|
||||||
birthday: formData.get("birthday") ?? "",
|
birthday: formData.get("birthday") ?? "",
|
||||||
remark: formData.get("remark") ?? "",
|
remark: formData.get("remark") ?? "",
|
||||||
};
|
};
|
||||||
@@ -75,9 +86,10 @@ function pickForm(formData: FormData) {
|
|||||||
|
|
||||||
/** 把校验后的表单值转成 Prisma 写入数据(日期字段转 Date) */
|
/** 把校验后的表单值转成 Prisma 写入数据(日期字段转 Date) */
|
||||||
function toData(v: z.infer<typeof schema>) {
|
function toData(v: z.infer<typeof schema>) {
|
||||||
const { reportDate, birthday, ...rest } = v;
|
const { reportDate, birthday, customerNo, ...rest } = v;
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
|
customerNo: customerNo || null,
|
||||||
reportDate: parseDate(reportDate),
|
reportDate: parseDate(reportDate),
|
||||||
birthday: parseDate(birthday),
|
birthday: parseDate(birthday),
|
||||||
};
|
};
|
||||||
@@ -105,7 +117,18 @@ export async function updateCustomer(
|
|||||||
const r = schema.safeParse(pickForm(formData));
|
const r = schema.safeParse(pickForm(formData));
|
||||||
if (!r.success) return { error: r.error.issues[0].message };
|
if (!r.success) return { error: r.error.issues[0].message };
|
||||||
|
|
||||||
await prisma.customer.update({ where: { id }, data: toData(r.data) });
|
const existing = await prisma.customer.findUnique({
|
||||||
|
where: { id },
|
||||||
|
select: { birthdayType: true },
|
||||||
|
});
|
||||||
|
const parsed = toData(r.data);
|
||||||
|
// 改版前的阴历生日不能在保存其它字段时改成阳历,否则明年提醒日会错
|
||||||
|
const data = {
|
||||||
|
...parsed,
|
||||||
|
birthdayType: existing?.birthdayType === 2 ? 2 : parsed.birthdayType,
|
||||||
|
};
|
||||||
|
|
||||||
|
await prisma.customer.update({ where: { id }, data });
|
||||||
revalidatePath("/customers");
|
revalidatePath("/customers");
|
||||||
redirect("/customers");
|
redirect("/customers");
|
||||||
}
|
}
|
||||||
@@ -124,7 +147,12 @@ export async function deleteCustomer(id: number): Promise<void> {
|
|||||||
// ============ Excel 导入 ============
|
// ============ Excel 导入 ============
|
||||||
|
|
||||||
const HEADER_MAP: Record<string, string> = {
|
const HEADER_MAP: Record<string, string> = {
|
||||||
|
商户注册名称: "customerName",
|
||||||
|
// 兼容旧版导入模板表头
|
||||||
|
商户注名称: "customerName",
|
||||||
商户名称: "customerName",
|
商户名称: "customerName",
|
||||||
|
商户经营名称: "businessName",
|
||||||
|
商户编号: "customerNo",
|
||||||
联系人: "contacts",
|
联系人: "contacts",
|
||||||
联系人电话: "contactsPhone",
|
联系人电话: "contactsPhone",
|
||||||
结算人: "balanceUser",
|
结算人: "balanceUser",
|
||||||
@@ -134,8 +162,6 @@ const HEADER_MAP: Record<string, string> = {
|
|||||||
产品明细: "detail",
|
产品明细: "detail",
|
||||||
押金: "deposit",
|
押金: "deposit",
|
||||||
买断: "buy",
|
买断: "buy",
|
||||||
生日类型: "birthdayType",
|
|
||||||
生日归属: "birthdayOwner",
|
|
||||||
生日: "birthday",
|
生日: "birthday",
|
||||||
业务员: "salesman",
|
业务员: "salesman",
|
||||||
报单日期: "reportDate",
|
报单日期: "reportDate",
|
||||||
@@ -169,7 +195,11 @@ export async function importCustomers(formData: FormData): Promise<ImportResult>
|
|||||||
}
|
}
|
||||||
|
|
||||||
const errors: string[] = [];
|
const errors: string[] = [];
|
||||||
if (!rec.customerName) errors.push("商户名称必填");
|
if (!rec.customerName) errors.push("商户注册名称必填");
|
||||||
|
if (!rec.businessName) errors.push("商户经营名称必填");
|
||||||
|
if (rec.customerNo && !/^[A-Za-z0-9]+$/.test(rec.customerNo)) {
|
||||||
|
errors.push("商户编号只能包含数字和字母");
|
||||||
|
}
|
||||||
const reportDate = parseDate(rec.reportDate);
|
const reportDate = parseDate(rec.reportDate);
|
||||||
if (!rec.reportDate || !reportDate) errors.push("报单日期必填且格式为 YYYY-MM-DD");
|
if (!rec.reportDate || !reportDate) errors.push("报单日期必填且格式为 YYYY-MM-DD");
|
||||||
if (rec.birthday && !parseDate(rec.birthday)) errors.push("生日格式应为 YYYY-MM-DD");
|
if (rec.birthday && !parseDate(rec.birthday)) errors.push("生日格式应为 YYYY-MM-DD");
|
||||||
@@ -179,6 +209,8 @@ export async function importCustomers(formData: FormData): Promise<ImportResult>
|
|||||||
} else {
|
} else {
|
||||||
validData.push({
|
validData.push({
|
||||||
customerName: rec.customerName,
|
customerName: rec.customerName,
|
||||||
|
businessName: rec.businessName,
|
||||||
|
customerNo: rec.customerNo || null,
|
||||||
contacts: rec.contacts || null,
|
contacts: rec.contacts || null,
|
||||||
contactsPhone: rec.contactsPhone || null,
|
contactsPhone: rec.contactsPhone || null,
|
||||||
balanceUser: rec.balanceUser || null,
|
balanceUser: rec.balanceUser || null,
|
||||||
@@ -189,8 +221,8 @@ export async function importCustomers(formData: FormData): Promise<ImportResult>
|
|||||||
buy: rec.buy || null,
|
buy: rec.buy || null,
|
||||||
salesman: rec.salesman || null,
|
salesman: rec.salesman || null,
|
||||||
remark: rec.remark || null,
|
remark: rec.remark || null,
|
||||||
birthdayType: rec.birthdayType === "阴历" || rec.birthdayType === "2" ? 2 : 1,
|
birthdayType: 1,
|
||||||
birthdayOwner: rec.birthdayOwner === "结算人" || rec.birthdayOwner === "1" ? 1 : 2,
|
birthdayOwner: 1,
|
||||||
birthday: parseDate(rec.birthday),
|
birthday: parseDate(rec.birthday),
|
||||||
reportDate,
|
reportDate,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
export const BIRTHDAY_COLUMN_STORAGE_KEY = "crm-birthday-columns-v2";
|
||||||
|
|
||||||
|
export type BirthdayColumnKey =
|
||||||
|
| "customerName"
|
||||||
|
| "businessName"
|
||||||
|
| "customerNo"
|
||||||
|
| "contacts"
|
||||||
|
| "balanceUser"
|
||||||
|
| "birthday"
|
||||||
|
| "salesman"
|
||||||
|
| "reportDate"
|
||||||
|
| "deposit"
|
||||||
|
| "buy"
|
||||||
|
| "detail"
|
||||||
|
| "remark";
|
||||||
|
|
||||||
|
export type BirthdayColumnDef = {
|
||||||
|
key: BirthdayColumnKey;
|
||||||
|
label: string;
|
||||||
|
/** 默认展示:打电话常用信息 */
|
||||||
|
defaultVisible: boolean;
|
||||||
|
/** 表头/单元格宽度,避免名称列被表格拉得很宽 */
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const BIRTHDAY_COLUMNS: BirthdayColumnDef[] = [
|
||||||
|
{ key: "customerName", label: "商户注册名称", defaultVisible: true, className: "w-[11%]" },
|
||||||
|
{ key: "businessName", label: "商户经营名称", defaultVisible: true, className: "w-[11%]" },
|
||||||
|
{ key: "customerNo", label: "商户编号", defaultVisible: true, className: "w-[9%]" },
|
||||||
|
{ key: "balanceUser", label: "结算人", defaultVisible: true, className: "w-[11%]" },
|
||||||
|
{ key: "contacts", label: "联系人", defaultVisible: true, className: "w-[11%]" },
|
||||||
|
{ key: "birthday", label: "生日", defaultVisible: true, className: "w-[13%]" },
|
||||||
|
{ key: "salesman", label: "业务员", defaultVisible: true, className: "w-[7%]" },
|
||||||
|
{ key: "remark", label: "备注", defaultVisible: true, className: "w-[16%]" },
|
||||||
|
{ key: "reportDate", label: "报单日期", defaultVisible: false, className: "w-[10%]" },
|
||||||
|
{ key: "deposit", label: "押金", defaultVisible: false, className: "w-[8%]" },
|
||||||
|
{ key: "buy", label: "买断", defaultVisible: false, className: "w-[8%]" },
|
||||||
|
{ key: "detail", label: "产品明细", defaultVisible: false, className: "w-[18%]" },
|
||||||
|
];
|
||||||
|
|
||||||
|
export function defaultBirthdayColumns(): BirthdayColumnKey[] {
|
||||||
|
return BIRTHDAY_COLUMNS.filter((c) => c.defaultVisible).map((c) => c.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeBirthdayColumns(raw: unknown): BirthdayColumnKey[] {
|
||||||
|
const allowed = new Set(BIRTHDAY_COLUMNS.map((c) => c.key));
|
||||||
|
if (!Array.isArray(raw)) return defaultBirthdayColumns();
|
||||||
|
const next = raw.filter((k): k is BirthdayColumnKey => typeof k === "string" && allowed.has(k as BirthdayColumnKey));
|
||||||
|
return next.length > 0 ? next : defaultBirthdayColumns();
|
||||||
|
}
|
||||||
@@ -22,17 +22,19 @@ export function BirthdayControl({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<div className="flex w-full flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center">
|
||||||
<div className="flex overflow-hidden rounded-md border">
|
<div className="flex overflow-hidden rounded-md border">
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
onClick={() => go({ mode: "today" })}
|
onClick={() => go({ mode: "today" })}
|
||||||
className={`px-3 py-1.5 text-sm ${mode === "today" ? "bg-[var(--color-primary)] text-white" : "bg-white hover:bg-[var(--color-accent)]"}`}
|
className={`min-h-11 flex-1 touch-manipulation px-3 py-1.5 text-sm sm:min-h-0 sm:flex-none ${mode === "today" ? "bg-[var(--color-primary)] text-white" : "bg-white hover:bg-[var(--color-muted)]"}`}
|
||||||
>
|
>
|
||||||
当天
|
当天
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
onClick={() => go({ mode: "week" })}
|
onClick={() => go({ mode: "week" })}
|
||||||
className={`border-l px-3 py-1.5 text-sm ${mode === "week" ? "bg-[var(--color-primary)] text-white" : "bg-white hover:bg-[var(--color-accent)]"}`}
|
className={`min-h-11 flex-1 touch-manipulation border-l px-3 py-1.5 text-sm sm:min-h-0 sm:flex-none ${mode === "week" ? "bg-[var(--color-primary)] text-white" : "bg-white hover:bg-[var(--color-muted)]"}`}
|
||||||
>
|
>
|
||||||
未来 7 天
|
未来 7 天
|
||||||
</button>
|
</button>
|
||||||
@@ -41,7 +43,7 @@ export function BirthdayControl({
|
|||||||
type="date"
|
type="date"
|
||||||
defaultValue={date}
|
defaultValue={date}
|
||||||
onChange={(e) => go({ date: e.target.value })}
|
onChange={(e) => go({ date: e.target.value })}
|
||||||
className="w-40"
|
className="w-full sm:w-40"
|
||||||
/>
|
/>
|
||||||
<span className="text-sm text-[var(--color-muted-foreground)]">
|
<span className="text-sm text-[var(--color-muted-foreground)]">
|
||||||
(不填默认今天)
|
(不填默认今天)
|
||||||
|
|||||||
@@ -0,0 +1,346 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||||
|
import { Columns3, RotateCcw } from "lucide-react";
|
||||||
|
import { fmtDate } from "@/lib/utils";
|
||||||
|
import { lunarBirthdaySolarThisYear } from "@/lib/lunar";
|
||||||
|
import { Card } from "@/components/ui/card";
|
||||||
|
import { Table, THead, TR, TH, TD } from "@/components/ui/table";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
BIRTHDAY_COLUMNS,
|
||||||
|
BIRTHDAY_COLUMN_STORAGE_KEY,
|
||||||
|
defaultBirthdayColumns,
|
||||||
|
normalizeBirthdayColumns,
|
||||||
|
type BirthdayColumnKey,
|
||||||
|
} from "./birthday-columns";
|
||||||
|
|
||||||
|
export type BirthdayRow = {
|
||||||
|
id: number;
|
||||||
|
customerName: string | null;
|
||||||
|
businessName: string | null;
|
||||||
|
customerNo: string | null;
|
||||||
|
contacts: string | null;
|
||||||
|
contactsPhone: string | null;
|
||||||
|
balanceUser: string | null;
|
||||||
|
balanceUserPhone: string | null;
|
||||||
|
detail: string | null;
|
||||||
|
deposit: string | null;
|
||||||
|
buy: string | null;
|
||||||
|
salesman: string | null;
|
||||||
|
reportDate: Date | string | null;
|
||||||
|
birthday: Date | string | null;
|
||||||
|
birthdayType: number | null;
|
||||||
|
remark: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
function asDate(v: Date | string | null | undefined): Date | null {
|
||||||
|
if (!v) return null;
|
||||||
|
if (v instanceof Date) return v;
|
||||||
|
const d = new Date(v);
|
||||||
|
return isNaN(d.getTime()) ? null : d;
|
||||||
|
}
|
||||||
|
|
||||||
|
function text(v?: string | null) {
|
||||||
|
return v?.trim() ? v : "—";
|
||||||
|
}
|
||||||
|
|
||||||
|
function PersonCell({
|
||||||
|
name,
|
||||||
|
phone,
|
||||||
|
callable,
|
||||||
|
}: {
|
||||||
|
name?: string | null;
|
||||||
|
phone?: string | null;
|
||||||
|
callable?: boolean;
|
||||||
|
}) {
|
||||||
|
const p = phone?.trim() || "";
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div>{text(name)}</div>
|
||||||
|
{p ? (
|
||||||
|
callable ? (
|
||||||
|
<a
|
||||||
|
href={`tel:${p}`}
|
||||||
|
className="text-xs tabular-nums text-[var(--color-primary)] hover:underline"
|
||||||
|
>
|
||||||
|
{p}
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">{p}</div>
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<div className="text-xs text-[var(--color-muted-foreground)]">—</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function BirthdayCell({ row }: { row: BirthdayRow }) {
|
||||||
|
const birthday = asDate(row.birthday);
|
||||||
|
const lunar = Number(row.birthdayType) === 2;
|
||||||
|
const iso = fmtDate(birthday);
|
||||||
|
const solarThisYear = lunar ? lunarBirthdaySolarThisYear(iso) : null;
|
||||||
|
if (!birthday) return <span>—</span>;
|
||||||
|
if (!lunar) return <span className="tabular-nums">{iso}</span>;
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="tabular-nums">农历 {iso.slice(5) || "—"}</div>
|
||||||
|
<div className="text-xs text-[var(--color-warning)]">
|
||||||
|
按农历过生日{solarThisYear ? `,今年是 ${solarThisYear}` : ""}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderCell(key: BirthdayColumnKey, row: BirthdayRow): ReactNode {
|
||||||
|
switch (key) {
|
||||||
|
case "customerName":
|
||||||
|
return <span className="block break-words font-medium whitespace-normal">{text(row.customerName)}</span>;
|
||||||
|
case "businessName":
|
||||||
|
return <span className="block break-words font-medium whitespace-normal">{text(row.businessName)}</span>;
|
||||||
|
case "customerNo":
|
||||||
|
return <span className="block break-all whitespace-normal">{text(row.customerNo)}</span>;
|
||||||
|
case "contacts":
|
||||||
|
return <PersonCell name={row.contacts} phone={row.contactsPhone} />;
|
||||||
|
case "balanceUser":
|
||||||
|
return <PersonCell name={row.balanceUser} phone={row.balanceUserPhone} />;
|
||||||
|
case "birthday":
|
||||||
|
return <BirthdayCell row={row} />;
|
||||||
|
case "salesman":
|
||||||
|
return text(row.salesman);
|
||||||
|
case "reportDate":
|
||||||
|
return <span className="tabular-nums">{fmtDate(asDate(row.reportDate)) || "—"}</span>;
|
||||||
|
case "deposit":
|
||||||
|
return text(row.deposit);
|
||||||
|
case "buy":
|
||||||
|
return text(row.buy);
|
||||||
|
case "detail":
|
||||||
|
return <span className="break-words whitespace-normal">{text(row.detail)}</span>;
|
||||||
|
case "remark":
|
||||||
|
return <span className="break-words whitespace-normal">{text(row.remark)}</span>;
|
||||||
|
default:
|
||||||
|
return "—";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ColumnPicker({
|
||||||
|
visible,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
visible: BirthdayColumnKey[];
|
||||||
|
onChange: (next: BirthdayColumnKey[]) => void;
|
||||||
|
}) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function onClick(e: Event) {
|
||||||
|
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
||||||
|
}
|
||||||
|
document.addEventListener("pointerdown", onClick);
|
||||||
|
return () => document.removeEventListener("pointerdown", onClick);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
function toggle(key: BirthdayColumnKey) {
|
||||||
|
if (visible.includes(key)) {
|
||||||
|
if (visible.length <= 1) return;
|
||||||
|
onChange(visible.filter((k) => k !== key));
|
||||||
|
} else {
|
||||||
|
onChange([...visible, key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="relative" ref={ref}>
|
||||||
|
<Button type="button" variant="outline" size="sm" onClick={() => setOpen((v) => !v)}>
|
||||||
|
<Columns3 className="h-4 w-4" />
|
||||||
|
自定义字段
|
||||||
|
</Button>
|
||||||
|
{open && (
|
||||||
|
<div className="absolute right-0 z-30 mt-2 w-56 overflow-hidden rounded-[var(--radius)] border bg-[var(--color-surface)] py-2 shadow-lg">
|
||||||
|
<div className="px-3 pb-2 text-xs text-[var(--color-muted-foreground)]">勾选要显示的列</div>
|
||||||
|
<div className="max-h-72 space-y-0.5 overflow-y-auto px-1">
|
||||||
|
{BIRTHDAY_COLUMNS.map((col) => {
|
||||||
|
const checked = visible.includes(col.key);
|
||||||
|
return (
|
||||||
|
<label
|
||||||
|
key={col.key}
|
||||||
|
className="flex min-h-10 cursor-pointer items-center gap-2.5 rounded-md px-2 hover:bg-[var(--color-muted)]"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="h-4 w-4 accent-[var(--color-primary)]"
|
||||||
|
checked={checked}
|
||||||
|
onChange={() => toggle(col.key)}
|
||||||
|
/>
|
||||||
|
<span className="text-sm">{col.label}</span>
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
<div className="mt-2 border-t px-2 pt-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="flex min-h-10 w-full items-center gap-2 rounded-md px-2 text-sm text-[var(--color-muted-foreground)] hover:bg-[var(--color-muted)] hover:text-[var(--color-foreground)]"
|
||||||
|
onClick={() => onChange(defaultBirthdayColumns())}
|
||||||
|
>
|
||||||
|
<RotateCcw className="h-3.5 w-3.5" />
|
||||||
|
恢复默认
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function BirthdayList({ rows }: { rows: BirthdayRow[] }) {
|
||||||
|
const [visible, setVisible] = useState<BirthdayColumnKey[]>(defaultBirthdayColumns);
|
||||||
|
const [ready, setReady] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(BIRTHDAY_COLUMN_STORAGE_KEY);
|
||||||
|
if (raw) setVisible(normalizeBirthdayColumns(JSON.parse(raw)));
|
||||||
|
} catch {
|
||||||
|
// ignore bad local data
|
||||||
|
}
|
||||||
|
setReady(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
function save(next: BirthdayColumnKey[]) {
|
||||||
|
const normalized = normalizeBirthdayColumns(next);
|
||||||
|
setVisible(normalized);
|
||||||
|
localStorage.setItem(BIRTHDAY_COLUMN_STORAGE_KEY, JSON.stringify(normalized));
|
||||||
|
}
|
||||||
|
|
||||||
|
const ordered = BIRTHDAY_COLUMNS.filter((c) => visible.includes(c.key));
|
||||||
|
const colSpan = Math.max(1, ordered.length);
|
||||||
|
|
||||||
|
function phoneFor(v?: string | null) {
|
||||||
|
return v?.trim() || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<ColumnPicker visible={visible} onChange={save} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!ready ? (
|
||||||
|
<Card className="py-14 text-center text-sm text-[var(--color-muted-foreground)]">加载中…</Card>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Card className="hidden overflow-hidden md:block">
|
||||||
|
<Table striped bordered className="min-w-0 table-fixed">
|
||||||
|
<THead>
|
||||||
|
<tr>
|
||||||
|
{ordered.map((col) => (
|
||||||
|
<TH key={col.key} className={col.className}>
|
||||||
|
{col.label}
|
||||||
|
</TH>
|
||||||
|
))}
|
||||||
|
</tr>
|
||||||
|
</THead>
|
||||||
|
<tbody>
|
||||||
|
{rows.length === 0 && (
|
||||||
|
<tr>
|
||||||
|
<TD colSpan={colSpan} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
||||||
|
没有过生日的商户
|
||||||
|
</TD>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
{rows.map((row) => (
|
||||||
|
<TR key={row.id}>
|
||||||
|
{ordered.map((col) => (
|
||||||
|
<TD key={col.key} className={col.className}>
|
||||||
|
{col.key === "contacts" ? (
|
||||||
|
<PersonCell
|
||||||
|
name={row.contacts}
|
||||||
|
phone={phoneFor(row.contactsPhone)}
|
||||||
|
callable
|
||||||
|
/>
|
||||||
|
) : col.key === "balanceUser" ? (
|
||||||
|
<PersonCell
|
||||||
|
name={row.balanceUser}
|
||||||
|
phone={phoneFor(row.balanceUserPhone)}
|
||||||
|
callable
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
renderCell(col.key, row)
|
||||||
|
)}
|
||||||
|
</TD>
|
||||||
|
))}
|
||||||
|
</TR>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</Table>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<div className="space-y-3 md:hidden">
|
||||||
|
{rows.length === 0 && (
|
||||||
|
<Card className="py-14 text-center text-sm text-[var(--color-muted-foreground)]">
|
||||||
|
没有过生日的商户
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
{rows.map((row) => (
|
||||||
|
<Card key={row.id} className="p-4">
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="break-words font-medium whitespace-normal">{text(row.customerName)}</div>
|
||||||
|
{visible.includes("businessName") && row.businessName ? (
|
||||||
|
<div className="mt-0.5 break-words text-xs text-[var(--color-muted-foreground)]">
|
||||||
|
经营名称 {text(row.businessName)}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{visible.includes("customerNo") && (
|
||||||
|
<div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
|
||||||
|
编号 {text(row.customerNo)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{visible.includes("birthday") && (
|
||||||
|
<div className="shrink-0 text-right text-xs">{renderCell("birthday", row)}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<dl className="mt-3 grid grid-cols-2 gap-x-3 gap-y-2 text-sm">
|
||||||
|
{ordered
|
||||||
|
.filter(
|
||||||
|
(c) =>
|
||||||
|
c.key !== "customerName" &&
|
||||||
|
c.key !== "businessName" &&
|
||||||
|
c.key !== "customerNo" &&
|
||||||
|
c.key !== "birthday"
|
||||||
|
)
|
||||||
|
.map((col) => (
|
||||||
|
<div key={col.key} className={col.key === "detail" || col.key === "remark" ? "col-span-2" : undefined}>
|
||||||
|
<dt className="text-xs text-[var(--color-muted-foreground)]">{col.label}</dt>
|
||||||
|
<dd>
|
||||||
|
{col.key === "contacts" ? (
|
||||||
|
<PersonCell
|
||||||
|
name={row.contacts}
|
||||||
|
phone={phoneFor(row.contactsPhone)}
|
||||||
|
callable
|
||||||
|
/>
|
||||||
|
) : col.key === "balanceUser" ? (
|
||||||
|
<PersonCell
|
||||||
|
name={row.balanceUser}
|
||||||
|
phone={phoneFor(row.balanceUserPhone)}
|
||||||
|
callable
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
renderCell(col.key, row)
|
||||||
|
)}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,29 +1,9 @@
|
|||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
import { auth } from "@/lib/auth";
|
|
||||||
import { isSuperAdmin } from "@/lib/acl";
|
|
||||||
import { birthdayMatchLists } from "@/lib/lunar";
|
import { birthdayMatchLists } from "@/lib/lunar";
|
||||||
import { fmtDate, maskPhone } from "@/lib/utils";
|
|
||||||
import { Card } from "@/components/ui/card";
|
import { Card } from "@/components/ui/card";
|
||||||
import { Table, THead, TR, TH, TD } from "@/components/ui/table";
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import { BirthdayControl } from "./birthday-control";
|
import { BirthdayControl } from "./birthday-control";
|
||||||
|
import { BirthdayList, type BirthdayRow } from "./birthday-list";
|
||||||
type Row = {
|
|
||||||
id: number;
|
|
||||||
customerName: string | null;
|
|
||||||
contacts: string | null;
|
|
||||||
contactsPhone: string | null;
|
|
||||||
balanceUser: string | null;
|
|
||||||
balanceUserPhone: string | null;
|
|
||||||
phone: string | null; // 旧公共电话,仅作新字段为空时的回退
|
|
||||||
salesman: string | null;
|
|
||||||
reportDate: Date | null;
|
|
||||||
birthday: Date | null;
|
|
||||||
birthdayType: number | null;
|
|
||||||
birthdayOwner: number | null;
|
|
||||||
remark: string | null;
|
|
||||||
};
|
|
||||||
|
|
||||||
function baseDate(s?: string): Date {
|
function baseDate(s?: string): Date {
|
||||||
if (s) {
|
if (s) {
|
||||||
@@ -38,8 +18,6 @@ export default async function BirthdayPage({
|
|||||||
}: {
|
}: {
|
||||||
searchParams: Promise<{ mode?: string; date?: string }>;
|
searchParams: Promise<{ mode?: string; date?: string }>;
|
||||||
}) {
|
}) {
|
||||||
const session = await auth();
|
|
||||||
const superAdmin = isSuperAdmin(session?.user?.roles);
|
|
||||||
const sp = await searchParams;
|
const sp = await searchParams;
|
||||||
const mode = sp.mode === "week" ? "week" : "today";
|
const mode = sp.mode === "week" ? "week" : "today";
|
||||||
const dateStr = sp.date ?? "";
|
const dateStr = sp.date ?? "";
|
||||||
@@ -50,20 +28,23 @@ export default async function BirthdayPage({
|
|||||||
? birthdayMatchLists(base, 7, false)
|
? birthdayMatchLists(base, 7, false)
|
||||||
: birthdayMatchLists(base, 1, true);
|
: birthdayMatchLists(base, 1, true);
|
||||||
|
|
||||||
const rows = await prisma.$queryRaw<Row[]>(Prisma.sql`
|
const rows = await prisma.$queryRaw<BirthdayRow[]>(Prisma.sql`
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
customer_name AS customerName,
|
customer_name AS customerName,
|
||||||
|
business_name AS businessName,
|
||||||
|
customer_no AS customerNo,
|
||||||
contacts,
|
contacts,
|
||||||
contacts_phone AS contactsPhone,
|
contacts_phone AS contactsPhone,
|
||||||
balance_user AS balanceUser,
|
balance_user AS balanceUser,
|
||||||
balance_user_phone AS balanceUserPhone,
|
COALESCE(NULLIF(balance_user_phone, ''), phone) AS balanceUserPhone,
|
||||||
phone,
|
detail,
|
||||||
|
deposit,
|
||||||
|
buy,
|
||||||
salesman,
|
salesman,
|
||||||
report_date AS reportDate,
|
report_date AS reportDate,
|
||||||
birthday,
|
birthday,
|
||||||
birthday_type AS birthdayType,
|
birthday_type AS birthdayType,
|
||||||
birthday_owner AS birthdayOwner,
|
|
||||||
remark
|
remark
|
||||||
FROM customers
|
FROM customers
|
||||||
WHERE deleted_at IS NULL AND (
|
WHERE deleted_at IS NULL AND (
|
||||||
@@ -76,61 +57,14 @@ export default async function BirthdayPage({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<Card className="flex flex-wrap items-center justify-between gap-3 p-3">
|
<Card className="flex flex-col gap-3 p-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between">
|
||||||
<BirthdayControl mode={mode} date={dateStr} />
|
<BirthdayControl mode={mode} date={dateStr} />
|
||||||
<div className="pr-1 text-sm text-[var(--color-muted-foreground)]">
|
<div className="text-sm text-[var(--color-muted-foreground)] sm:pr-1">
|
||||||
命中 <span className="font-semibold text-[var(--color-foreground)]">{rows.length}</span> 位商户
|
共 <span className="font-semibold text-[var(--color-foreground)]">{rows.length}</span> 位商户过生日
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card className="overflow-hidden">
|
<BirthdayList rows={rows} />
|
||||||
<Table>
|
|
||||||
<THead>
|
|
||||||
<tr>
|
|
||||||
<TH>商户名称</TH>
|
|
||||||
<TH>归属人</TH>
|
|
||||||
<TH>业务员</TH>
|
|
||||||
<TH>生日</TH>
|
|
||||||
<TH>历法</TH>
|
|
||||||
<TH>归属</TH>
|
|
||||||
</tr>
|
|
||||||
</THead>
|
|
||||||
<tbody>
|
|
||||||
{rows.length === 0 && (
|
|
||||||
<tr>
|
|
||||||
<TD colSpan={6} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
|
||||||
该时段暂无生日商户
|
|
||||||
</TD>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
{rows.map((c) => {
|
|
||||||
// 生日归属人的姓名和手机号;新手机号为空时回退旧公共 phone(历史数据)
|
|
||||||
const ownerName = c.birthdayOwner === 1 ? c.balanceUser : c.contacts;
|
|
||||||
const ownerPhone =
|
|
||||||
(c.birthdayOwner === 1 ? c.balanceUserPhone : c.contactsPhone) || c.phone;
|
|
||||||
return (
|
|
||||||
<TR key={c.id}>
|
|
||||||
<TD className="font-medium">{c.customerName}</TD>
|
|
||||||
<TD>
|
|
||||||
<div>{ownerName}</div>
|
|
||||||
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
|
||||||
{superAdmin ? ownerPhone : maskPhone(ownerPhone)}
|
|
||||||
</div>
|
|
||||||
</TD>
|
|
||||||
<TD>{c.salesman}</TD>
|
|
||||||
<TD className="tabular-nums">{fmtDate(c.birthday)}</TD>
|
|
||||||
<TD>
|
|
||||||
<Badge tone={c.birthdayType === 2 ? "warning" : "info"}>
|
|
||||||
{c.birthdayType === 2 ? "农历" : "阳历"}
|
|
||||||
</Badge>
|
|
||||||
</TD>
|
|
||||||
<TD>{c.birthdayOwner === 1 ? "结算人" : "联系人"}</TD>
|
|
||||||
</TR>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
</Table>
|
|
||||||
</Card>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,15 @@
|
|||||||
import { useActionState } from "react";
|
import { useActionState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input, Textarea, Select } from "@/components/ui/input";
|
import { Input, Textarea } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { fmtDate } from "@/lib/utils";
|
import { fmtDate } from "@/lib/utils";
|
||||||
import type { ActionState } from "./actions";
|
import type { ActionState } from "./actions";
|
||||||
|
|
||||||
type CustomerValues = {
|
type CustomerValues = {
|
||||||
customerName?: string | null;
|
customerName?: string | null;
|
||||||
|
businessName?: string | null;
|
||||||
|
customerNo?: string | null;
|
||||||
contacts?: string | null;
|
contacts?: string | null;
|
||||||
contactsPhone?: string | null;
|
contactsPhone?: string | null;
|
||||||
balanceUser?: string | null;
|
balanceUser?: string | null;
|
||||||
@@ -17,9 +19,8 @@ type CustomerValues = {
|
|||||||
detail?: string | null;
|
detail?: string | null;
|
||||||
deposit?: string | null;
|
deposit?: string | null;
|
||||||
buy?: string | null;
|
buy?: string | null;
|
||||||
birthdayType?: number | null;
|
|
||||||
birthdayOwner?: number | null;
|
|
||||||
birthday?: Date | null;
|
birthday?: Date | null;
|
||||||
|
birthdayType?: number | null;
|
||||||
salesman?: string | null;
|
salesman?: string | null;
|
||||||
reportDate?: Date | null;
|
reportDate?: Date | null;
|
||||||
remark?: string | null;
|
remark?: string | null;
|
||||||
@@ -101,12 +102,25 @@ export function CustomerForm({
|
|||||||
<FormSection title="基本">
|
<FormSection title="基本">
|
||||||
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
<Field
|
<Field
|
||||||
label="商户名称"
|
label="商户注册名称"
|
||||||
name="customerName"
|
name="customerName"
|
||||||
defaultValue={v.customerName}
|
defaultValue={v.customerName}
|
||||||
required
|
required
|
||||||
pattern={requireAll ? "\\S+" : undefined}
|
pattern={requireAll ? "\\S+" : undefined}
|
||||||
title={requireAll ? "商户名称不能包含空格" : undefined}
|
title={requireAll ? "商户注册名称不能包含空格" : undefined}
|
||||||
|
/>
|
||||||
|
<Field
|
||||||
|
label="商户经营名称"
|
||||||
|
name="businessName"
|
||||||
|
defaultValue={v.businessName}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<Field
|
||||||
|
label="商户编号"
|
||||||
|
name="customerNo"
|
||||||
|
defaultValue={v.customerNo}
|
||||||
|
pattern="[A-Za-z0-9]+"
|
||||||
|
title="只能填写数字和字母,区分大小写,位数不限;可不填"
|
||||||
/>
|
/>
|
||||||
<Field label="业务员" name="salesman" defaultValue={v.salesman} required />
|
<Field label="业务员" name="salesman" defaultValue={v.salesman} required />
|
||||||
<Field
|
<Field
|
||||||
@@ -151,20 +165,6 @@ export function CustomerForm({
|
|||||||
|
|
||||||
<FormSection title="生日">
|
<FormSection title="生日">
|
||||||
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
<div className="grid grid-cols-1 gap-x-5 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Label htmlFor="birthdayType">生日类型</Label>
|
|
||||||
<Select id="birthdayType" name="birthdayType" defaultValue={String(v.birthdayType ?? 1)}>
|
|
||||||
<option value="1">阳历</option>
|
|
||||||
<option value="2">阴历</option>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-1.5">
|
|
||||||
<Label htmlFor="birthdayOwner">生日归属</Label>
|
|
||||||
<Select id="birthdayOwner" name="birthdayOwner" defaultValue={String(v.birthdayOwner ?? 2)}>
|
|
||||||
<option value="1">结算人</option>
|
|
||||||
<option value="2">联系人</option>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
<Field
|
<Field
|
||||||
label="生日"
|
label="生日"
|
||||||
name="birthday"
|
name="birthday"
|
||||||
@@ -173,6 +173,11 @@ export function CustomerForm({
|
|||||||
required={requireAll}
|
required={requireAll}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{v.birthdayType === 2 && (
|
||||||
|
<p className="text-sm text-[var(--color-warning)]">
|
||||||
|
这个生日是按农历记的。
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</FormSection>
|
</FormSection>
|
||||||
|
|
||||||
<FormSection title="其它">
|
<FormSection title="其它">
|
||||||
@@ -198,7 +203,7 @@ export function CustomerForm({
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex gap-2 border-t pt-4">
|
<div className="sticky bottom-0 z-10 -mx-4 flex gap-2 border-t bg-[var(--color-surface)] px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] md:static md:mx-0 md:px-0 md:pb-0 md:pt-4">
|
||||||
<Button type="submit" disabled={pending}>
|
<Button type="submit" disabled={pending}>
|
||||||
{pending ? "保存中…" : submitLabel}
|
{pending ? "保存中…" : submitLabel}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useRef, useState, useTransition } from "react";
|
import { useRef, useTransition } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Plus, Upload, Download, Search, RotateCcw } from "lucide-react";
|
import { Plus, Upload, Download, Search, RotateCcw } from "lucide-react";
|
||||||
@@ -78,50 +78,54 @@ export function CustomerToolbar({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="flex flex-wrap items-center justify-between gap-3 p-3">
|
<Card className="flex flex-col gap-3 p-3 md:flex-row md:flex-wrap md:items-center md:justify-between">
|
||||||
<form onSubmit={onSearch} className="flex flex-wrap items-center gap-2">
|
<form onSubmit={onSearch} className="flex w-full min-w-0 flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center md:w-auto">
|
||||||
<div className="relative">
|
<div className="relative min-w-0 flex-1 sm:flex-none">
|
||||||
<Search className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--color-muted-foreground)]" />
|
<Search className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--color-muted-foreground)]" />
|
||||||
<Input
|
<Input
|
||||||
name="keyword"
|
name="keyword"
|
||||||
placeholder="商户 / 联系人 / 联系电话 / 业务员"
|
placeholder="商户 / 编号 / 联系人 / 电话 / 业务员"
|
||||||
defaultValue={defaultKeyword}
|
defaultValue={defaultKeyword}
|
||||||
className="w-64 pl-8"
|
className="w-full pl-8 sm:w-64"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Input name="start" type="date" defaultValue={defaultStart} className="w-[150px]" />
|
<div className="flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center">
|
||||||
<span className="text-[var(--color-muted-foreground)]">~</span>
|
<Input name="start" type="date" defaultValue={defaultStart} className="w-full sm:w-[150px]" />
|
||||||
<Input name="end" type="date" defaultValue={defaultEnd} className="w-[150px]" />
|
<span className="hidden shrink-0 text-[var(--color-muted-foreground)] sm:inline">~</span>
|
||||||
<Button type="submit" variant="soft" disabled={pending}>
|
<Input name="end" type="date" defaultValue={defaultEnd} className="w-full sm:w-[150px]" />
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button type="submit" variant="soft" disabled={pending} className="flex-1 sm:flex-none">
|
||||||
查询
|
查询
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="button" variant="ghost" size="icon" title="重置" onClick={() => router.push("/customers")}>
|
<Button type="button" variant="ghost" size="icon" title="重置" onClick={() => router.push("/customers")}>
|
||||||
<RotateCcw className="h-4 w-4" />
|
<RotateCcw className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
<div className="grid grid-cols-2 gap-2 sm:flex sm:flex-wrap sm:items-center">
|
||||||
<input ref={fileRef} type="file" accept=".xlsx,.xls" hidden onChange={onFile} />
|
<input ref={fileRef} type="file" accept=".xlsx,.xls" hidden onChange={onFile} />
|
||||||
<Button variant="outline" disabled={importing} onClick={() => fileRef.current?.click()}>
|
<Button variant="outline" disabled={importing} onClick={() => fileRef.current?.click()}>
|
||||||
<Upload className="h-4 w-4" />
|
<Upload className="h-4 w-4" />
|
||||||
{importing ? "导入中…" : "导入"}
|
{importing ? "导入中…" : "导入"}
|
||||||
</Button>
|
</Button>
|
||||||
<a href="/customers/template">
|
<a href="/customers/template" className="contents sm:block">
|
||||||
<Button variant="outline">
|
<Button variant="outline" className="w-full">
|
||||||
<Download className="h-4 w-4" />
|
<Download className="h-4 w-4" />
|
||||||
下载模板
|
下载模板
|
||||||
</Button>
|
</Button>
|
||||||
</a>
|
</a>
|
||||||
{canExport && (
|
{canExport && (
|
||||||
<a href={exportHref}>
|
<a href={exportHref} className="contents sm:block">
|
||||||
<Button variant="outline">
|
<Button variant="outline" className="w-full">
|
||||||
<Download className="h-4 w-4" />
|
<Download className="h-4 w-4" />
|
||||||
导出
|
导出
|
||||||
</Button>
|
</Button>
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
<Link href="/customers/new">
|
<Link href="/customers/new" className="col-span-2 sm:col-span-1">
|
||||||
<Button>
|
<Button className="w-full">
|
||||||
<Plus className="h-4 w-4" />
|
<Plus className="h-4 w-4" />
|
||||||
新增商户
|
新增商户
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import { useEffect, useState, type ReactNode } from "react";
|
|||||||
import { Eye, X } from "lucide-react";
|
import { Eye, X } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { fmtDate } from "@/lib/utils";
|
import { fmtDate, cn } from "@/lib/utils";
|
||||||
|
|
||||||
type CustomerViewProps = {
|
type CustomerViewProps = {
|
||||||
customer: {
|
customer: {
|
||||||
customerName?: string | null;
|
customerName?: string | null;
|
||||||
|
businessName?: string | null;
|
||||||
|
customerNo?: string | null;
|
||||||
contacts?: string | null;
|
contacts?: string | null;
|
||||||
contactsPhone?: string | null;
|
contactsPhone?: string | null;
|
||||||
balanceUser?: string | null;
|
balanceUser?: string | null;
|
||||||
@@ -16,8 +18,6 @@ type CustomerViewProps = {
|
|||||||
detail?: string | null;
|
detail?: string | null;
|
||||||
deposit?: string | null;
|
deposit?: string | null;
|
||||||
buy?: string | null;
|
buy?: string | null;
|
||||||
birthdayType?: number | null;
|
|
||||||
birthdayOwner?: number | null;
|
|
||||||
birthday?: Date | null;
|
birthday?: Date | null;
|
||||||
salesman?: string | null;
|
salesman?: string | null;
|
||||||
reportDate?: Date | null;
|
reportDate?: Date | null;
|
||||||
@@ -35,14 +35,16 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
|||||||
if (e.key === "Escape") setOpen(false);
|
if (e.key === "Escape") setOpen(false);
|
||||||
};
|
};
|
||||||
window.addEventListener("keydown", handleEsc);
|
window.addEventListener("keydown", handleEsc);
|
||||||
return () => window.removeEventListener("keydown", handleEsc);
|
const prev = document.body.style.overflow;
|
||||||
|
document.body.style.overflow = "hidden";
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("keydown", handleEsc);
|
||||||
|
document.body.style.overflow = prev;
|
||||||
|
};
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
const birthdayLabel = customer.birthdayType === 2 ? "阴历" : "阳历";
|
|
||||||
const birthdayOwnerLabel = customer.birthdayOwner === 1 ? "结算人" : "联系人";
|
|
||||||
|
|
||||||
// 各分区是否至少有一个字段,用于隐藏整块为空的小标题
|
// 各分区是否至少有一个字段,用于隐藏整块为空的小标题
|
||||||
const hasBasic = !!(customer.customerName || customer.detail);
|
const hasBasic = !!(customer.customerName || customer.businessName || customer.customerNo || customer.detail);
|
||||||
const hasContacts = !!(customer.contacts || customer.contactsPhone);
|
const hasContacts = !!(customer.contacts || customer.contactsPhone);
|
||||||
const hasBalanceUser = !!(customer.balanceUser || customer.balanceUserPhone);
|
const hasBalanceUser = !!(customer.balanceUser || customer.balanceUserPhone);
|
||||||
const hasBusiness = !!(customer.deposit || customer.buy || customer.salesman || customer.reportDate);
|
const hasBusiness = !!(customer.deposit || customer.buy || customer.salesman || customer.reportDate);
|
||||||
@@ -56,11 +58,11 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
|||||||
|
|
||||||
{open && (
|
{open && (
|
||||||
<div
|
<div
|
||||||
className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4"
|
className="fixed inset-0 z-50 flex items-end justify-center bg-black/40 p-0 overscroll-contain sm:items-center sm:p-4"
|
||||||
onClick={() => setOpen(false)}
|
onClick={() => setOpen(false)}
|
||||||
>
|
>
|
||||||
<Card
|
<Card
|
||||||
className="w-full max-w-lg max-h-[85vh] overflow-y-auto"
|
className="max-h-[min(92dvh,100%)] w-full max-w-lg overflow-y-auto rounded-b-none rounded-t-2xl pb-[env(safe-area-inset-bottom)] sm:rounded-[var(--radius)] sm:pb-0"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@@ -69,7 +71,7 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setOpen(false)}
|
onClick={() => setOpen(false)}
|
||||||
className="text-[var(--color-muted-foreground)] hover:text-[var(--color-foreground)] transition-colors"
|
className="-mr-2 flex h-11 w-11 items-center justify-center text-[var(--color-muted-foreground)] hover:text-[var(--color-foreground)] transition-colors"
|
||||||
aria-label="关闭"
|
aria-label="关闭"
|
||||||
>
|
>
|
||||||
<X className="h-5 w-5" />
|
<X className="h-5 w-5" />
|
||||||
@@ -79,7 +81,9 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
|||||||
<CardContent>
|
<CardContent>
|
||||||
{hasBasic && (
|
{hasBasic && (
|
||||||
<Section title="基本">
|
<Section title="基本">
|
||||||
<InfoRow label="商户名称" value={customer.customerName} />
|
<InfoRow label="商户注册名称" value={customer.customerName} />
|
||||||
|
<InfoRow label="商户经营名称" value={customer.businessName} />
|
||||||
|
<InfoRow label="商户编号" value={customer.customerNo} />
|
||||||
<InfoRow label="产品明细" value={customer.detail} className="whitespace-pre-wrap" />
|
<InfoRow label="产品明细" value={customer.detail} className="whitespace-pre-wrap" />
|
||||||
</Section>
|
</Section>
|
||||||
)}
|
)}
|
||||||
@@ -97,8 +101,6 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
|||||||
)}
|
)}
|
||||||
{customer.birthday && (
|
{customer.birthday && (
|
||||||
<Section title="生日">
|
<Section title="生日">
|
||||||
<InfoRow label="生日类型" value={birthdayLabel} />
|
|
||||||
<InfoRow label="生日归属" value={birthdayOwnerLabel} />
|
|
||||||
<InfoRow label="生日" value={fmtDate(customer.birthday)} />
|
<InfoRow label="生日" value={fmtDate(customer.birthday)} />
|
||||||
</Section>
|
</Section>
|
||||||
)}
|
)}
|
||||||
@@ -147,8 +149,8 @@ function InfoRow({
|
|||||||
if (!value) return null;
|
if (!value) return null;
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-3 text-sm">
|
<div className="flex gap-3 text-sm">
|
||||||
<span className="w-24 text-[var(--color-muted-foreground)] flex-shrink-0">{label}</span>
|
<span className="w-20 shrink-0 text-[var(--color-muted-foreground)] sm:w-24">{label}</span>
|
||||||
<span className={className}>{value}</span>
|
<span className={cn("min-w-0 break-words", className)}>{value}</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ export async function GET(req: NextRequest) {
|
|||||||
for (const c of rows) {
|
for (const c of rows) {
|
||||||
aoa.push([
|
aoa.push([
|
||||||
c.customerName ?? "",
|
c.customerName ?? "",
|
||||||
|
c.businessName ?? "",
|
||||||
|
c.customerNo ?? "",
|
||||||
c.contacts ?? "",
|
c.contacts ?? "",
|
||||||
c.contactsPhone ?? "",
|
c.contactsPhone ?? "",
|
||||||
c.balanceUser ?? "",
|
c.balanceUser ?? "",
|
||||||
@@ -39,8 +41,6 @@ export async function GET(req: NextRequest) {
|
|||||||
c.detail ?? "",
|
c.detail ?? "",
|
||||||
c.deposit ?? "",
|
c.deposit ?? "",
|
||||||
c.buy ?? "",
|
c.buy ?? "",
|
||||||
c.birthdayType === 2 ? "阴历" : "阳历",
|
|
||||||
c.birthdayOwner === 1 ? "结算人" : "联系人",
|
|
||||||
fmtDate(c.birthday),
|
fmtDate(c.birthday),
|
||||||
c.salesman ?? "",
|
c.salesman ?? "",
|
||||||
fmtDate(c.reportDate),
|
fmtDate(c.reportDate),
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { prisma } from "@/lib/prisma";
|
import { prisma } from "@/lib/prisma";
|
||||||
import { auth } from "@/lib/auth";
|
import { auth } from "@/lib/auth";
|
||||||
import { isSuperAdmin } from "@/lib/acl";
|
import { isStaff, isSuperAdmin } from "@/lib/acl";
|
||||||
import { fmtDate, maskPhone } from "@/lib/utils";
|
import { fmtDate, maskPhone } from "@/lib/utils";
|
||||||
import { Card } from "@/components/ui/card";
|
import { Card } from "@/components/ui/card";
|
||||||
import { Table, THead, TR, TH, TD } from "@/components/ui/table";
|
import { Table, THead, TR, TH, TD } from "@/components/ui/table";
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { CustomerToolbar } from "./customer-toolbar";
|
import { CustomerToolbar } from "./customer-toolbar";
|
||||||
import { DeleteButton } from "./delete-button";
|
import { DeleteButton } from "./delete-button";
|
||||||
@@ -28,6 +27,8 @@ export default async function CustomersPage({
|
|||||||
}) {
|
}) {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
const superAdmin = isSuperAdmin(session?.user?.roles);
|
const superAdmin = isSuperAdmin(session?.user?.roles);
|
||||||
|
// 查看弹窗:业务员角色也展示明文手机号(列表仍脱敏)
|
||||||
|
const viewFullPhone = superAdmin || isStaff(session?.user?.roles);
|
||||||
const sp = await searchParams;
|
const sp = await searchParams;
|
||||||
const keyword = (sp.keyword ?? "").trim();
|
const keyword = (sp.keyword ?? "").trim();
|
||||||
const page = Math.max(1, Number(sp.page) || 1);
|
const page = Math.max(1, Number(sp.page) || 1);
|
||||||
@@ -59,11 +60,13 @@ export default async function CustomersPage({
|
|||||||
canExport={superAdmin}
|
canExport={superAdmin}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Card className="overflow-hidden">
|
<Card className="hidden overflow-hidden md:block">
|
||||||
<Table striped bordered>
|
<Table striped bordered>
|
||||||
<THead>
|
<THead>
|
||||||
<tr>
|
<tr>
|
||||||
<TH>商户名称</TH>
|
<TH>商户注册名称</TH>
|
||||||
|
<TH>商户经营名称</TH>
|
||||||
|
<TH>商户编号</TH>
|
||||||
<TH>联系人</TH>
|
<TH>联系人</TH>
|
||||||
<TH>结算人</TH>
|
<TH>结算人</TH>
|
||||||
<TH>产品明细</TH>
|
<TH>产品明细</TH>
|
||||||
@@ -79,7 +82,7 @@ export default async function CustomersPage({
|
|||||||
<tbody>
|
<tbody>
|
||||||
{rows.length === 0 && (
|
{rows.length === 0 && (
|
||||||
<tr>
|
<tr>
|
||||||
<TD colSpan={11} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
<TD colSpan={13} className="py-14 text-center text-[var(--color-muted-foreground)]">
|
||||||
暂无数据
|
暂无数据
|
||||||
</TD>
|
</TD>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -90,6 +93,8 @@ export default async function CustomersPage({
|
|||||||
return (
|
return (
|
||||||
<TR key={c.id}>
|
<TR key={c.id}>
|
||||||
<TD className="font-medium">{c.customerName}</TD>
|
<TD className="font-medium">{c.customerName}</TD>
|
||||||
|
<TD className="font-medium">{c.businessName || "—"}</TD>
|
||||||
|
<TD className="font-medium break-all">{c.customerNo || "—"}</TD>
|
||||||
<TD>
|
<TD>
|
||||||
<div>{c.contacts}</div>
|
<div>{c.contacts}</div>
|
||||||
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||||
@@ -105,30 +110,18 @@ export default async function CustomersPage({
|
|||||||
<TD className="max-w-[280px] whitespace-normal break-words">{c.detail}</TD>
|
<TD className="max-w-[280px] whitespace-normal break-words">{c.detail}</TD>
|
||||||
<TD>{c.deposit}</TD>
|
<TD>{c.deposit}</TD>
|
||||||
<TD>{c.buy}</TD>
|
<TD>{c.buy}</TD>
|
||||||
<TD>
|
<TD className="tabular-nums">{fmtDate(c.birthday)}</TD>
|
||||||
<span className="tabular-nums">{fmtDate(c.birthday)}</span>
|
|
||||||
{c.birthday && (
|
|
||||||
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="ml-2">
|
|
||||||
{c.birthdayType === 2 ? "农历" : "阳历"}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
{c.birthday && (
|
|
||||||
<Badge tone="neutral" className="ml-2">
|
|
||||||
{c.birthdayOwner === 1 ? "结算人" : "联系人"}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</TD>
|
|
||||||
<TD>{c.salesman}</TD>
|
<TD>{c.salesman}</TD>
|
||||||
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
|
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
|
||||||
<TD className="max-w-[280px] whitespace-normal break-words">{c.remark}</TD>
|
<TD className="max-w-[280px] whitespace-normal break-words">{c.remark}</TD>
|
||||||
<TD>
|
<TD>
|
||||||
<div className="flex justify-end gap-1.5">
|
<div className="flex flex-wrap justify-end gap-1.5">
|
||||||
{/* 弹窗展示用的手机号在服务端预脱敏,业务员拿不到明文 */}
|
{/* 弹窗展示用的手机号在服务端预处理:超管和业务员看明文,其余角色脱敏 */}
|
||||||
<CustomerView
|
<CustomerView
|
||||||
customer={{
|
customer={{
|
||||||
...rest,
|
...rest,
|
||||||
contactsPhone: superAdmin ? c.contactsPhone : maskPhone(c.contactsPhone),
|
contactsPhone: viewFullPhone ? c.contactsPhone : maskPhone(c.contactsPhone),
|
||||||
balanceUserPhone: superAdmin ? c.balanceUserPhone : maskPhone(c.balanceUserPhone),
|
balanceUserPhone: viewFullPhone ? c.balanceUserPhone : maskPhone(c.balanceUserPhone),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Link href={`/customers/${c.id}/edit`}>
|
<Link href={`/customers/${c.id}/edit`}>
|
||||||
@@ -144,8 +137,80 @@ export default async function CustomersPage({
|
|||||||
</Table>
|
</Table>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<div className="space-y-3 md:hidden">
|
||||||
|
{rows.length === 0 && (
|
||||||
|
<Card className="py-14 text-center text-sm text-[var(--color-muted-foreground)]">
|
||||||
|
暂无数据
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
{rows.map((c) => {
|
||||||
|
const { phone: _legacyPhone, ...rest } = c;
|
||||||
|
return (
|
||||||
|
<Card key={c.id} className="p-4">
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="truncate font-medium">{c.customerName}</div>
|
||||||
|
{c.businessName ? (
|
||||||
|
<div className="mt-0.5 truncate text-xs text-[var(--color-muted-foreground)]">
|
||||||
|
经营名称 {c.businessName}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
|
||||||
|
编号 {c.customerNo || "—"}
|
||||||
|
</div>
|
||||||
|
<div className="mt-1 text-xs text-[var(--color-muted-foreground)]">
|
||||||
|
{c.salesman}
|
||||||
|
{c.reportDate ? ` · ${fmtDate(c.reportDate)}` : ""}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{c.birthday ? (
|
||||||
|
<span className="shrink-0 text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||||
|
{fmtDate(c.birthday)}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<dl className="mt-3 grid grid-cols-2 gap-x-3 gap-y-2 text-sm">
|
||||||
|
<div>
|
||||||
|
<dt className="text-xs text-[var(--color-muted-foreground)]">联系人</dt>
|
||||||
|
<dd>{c.contacts || "—"}</dd>
|
||||||
|
<dd className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||||
|
{superAdmin ? c.contactsPhone : maskPhone(c.contactsPhone)}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<dt className="text-xs text-[var(--color-muted-foreground)]">结算人</dt>
|
||||||
|
<dd>{c.balanceUser || "—"}</dd>
|
||||||
|
<dd className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||||
|
{superAdmin ? c.balanceUserPhone : maskPhone(c.balanceUserPhone)}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
{c.detail && (
|
||||||
|
<div className="col-span-2">
|
||||||
|
<dt className="text-xs text-[var(--color-muted-foreground)]">产品明细</dt>
|
||||||
|
<dd className="break-words">{c.detail}</dd>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</dl>
|
||||||
|
<div className="mt-3 flex flex-wrap gap-1.5 border-t pt-3">
|
||||||
|
<CustomerView
|
||||||
|
customer={{
|
||||||
|
...rest,
|
||||||
|
contactsPhone: viewFullPhone ? c.contactsPhone : maskPhone(c.contactsPhone),
|
||||||
|
balanceUserPhone: viewFullPhone ? c.balanceUserPhone : maskPhone(c.balanceUserPhone),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Link href={`/customers/${c.id}/edit`}>
|
||||||
|
<Button variant="outline" size="sm">编辑</Button>
|
||||||
|
</Link>
|
||||||
|
{superAdmin && <DeleteButton id={c.id} name={c.customerName ?? ""} />}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* 分页 */}
|
{/* 分页 */}
|
||||||
<div className="flex items-center justify-between text-sm text-[var(--color-muted-foreground)]">
|
<div className="flex flex-wrap items-center justify-between gap-2 text-sm text-[var(--color-muted-foreground)]">
|
||||||
<span>共 <span className="font-medium text-[var(--color-foreground)]">{total.toLocaleString()}</span> 条</span>
|
<span>共 <span className="font-medium text-[var(--color-foreground)]">{total.toLocaleString()}</span> 条</span>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<PageLink page={page - 1} disabled={page <= 1} sp={sp} label="上一页" />
|
<PageLink page={page - 1} disabled={page <= 1} sp={sp} label="上一页" />
|
||||||
@@ -170,7 +235,7 @@ function PageLink({
|
|||||||
}) {
|
}) {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
return (
|
return (
|
||||||
<span className="rounded-md border px-3 py-1.5 opacity-40">{label}</span>
|
<span className="inline-flex min-h-11 items-center rounded-md border px-3 opacity-40 md:min-h-0 md:py-1.5">{label}</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
@@ -181,7 +246,7 @@ function PageLink({
|
|||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
href={`/customers?${params.toString()}`}
|
href={`/customers?${params.toString()}`}
|
||||||
className="rounded-md border bg-[var(--color-surface)] px-3 py-1.5 hover:bg-[var(--color-muted)]"
|
className="inline-flex min-h-11 items-center rounded-md border bg-[var(--color-surface)] px-3 hover:bg-[var(--color-muted)] md:min-h-0 md:py-1.5"
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ export function buildCustomerWhere(sp: CustomerSearch): Prisma.CustomerWhereInpu
|
|||||||
if (keyword) {
|
if (keyword) {
|
||||||
where.OR = [
|
where.OR = [
|
||||||
{ customerName: { contains: keyword } },
|
{ customerName: { contains: keyword } },
|
||||||
|
{ businessName: { contains: keyword } },
|
||||||
|
{ customerNo: { contains: keyword } },
|
||||||
{ contacts: { contains: keyword } },
|
{ contacts: { contains: keyword } },
|
||||||
{ contactsPhone: { contains: keyword } },
|
{ contactsPhone: { contains: keyword } },
|
||||||
{ balanceUser: { contains: keyword } },
|
{ balanceUser: { contains: keyword } },
|
||||||
@@ -31,7 +33,9 @@ export function buildCustomerWhere(sp: CustomerSearch): Prisma.CustomerWhereInpu
|
|||||||
|
|
||||||
/** 导出/导入的列定义(表头 ↔ 字段) */
|
/** 导出/导入的列定义(表头 ↔ 字段) */
|
||||||
export const EXCEL_COLUMNS: { header: string; key: string }[] = [
|
export const EXCEL_COLUMNS: { header: string; key: string }[] = [
|
||||||
{ header: "商户名称", key: "customerName" },
|
{ header: "商户注册名称", key: "customerName" },
|
||||||
|
{ header: "商户经营名称", key: "businessName" },
|
||||||
|
{ header: "商户编号", key: "customerNo" },
|
||||||
{ header: "联系人", key: "contacts" },
|
{ header: "联系人", key: "contacts" },
|
||||||
{ header: "联系人电话", key: "contactsPhone" },
|
{ header: "联系人电话", key: "contactsPhone" },
|
||||||
{ header: "结算人", key: "balanceUser" },
|
{ header: "结算人", key: "balanceUser" },
|
||||||
@@ -39,8 +43,6 @@ export const EXCEL_COLUMNS: { header: string; key: string }[] = [
|
|||||||
{ header: "产品明细", key: "detail" },
|
{ header: "产品明细", key: "detail" },
|
||||||
{ header: "押金", key: "deposit" },
|
{ header: "押金", key: "deposit" },
|
||||||
{ header: "买断", key: "buy" },
|
{ header: "买断", key: "buy" },
|
||||||
{ header: "生日类型", key: "birthdayType" },
|
|
||||||
{ header: "生日归属", key: "birthdayOwner" },
|
|
||||||
{ header: "生日", key: "birthday" },
|
{ header: "生日", key: "birthday" },
|
||||||
{ header: "业务员", key: "salesman" },
|
{ header: "业务员", key: "salesman" },
|
||||||
{ header: "报单日期", key: "reportDate" },
|
{ header: "报单日期", key: "reportDate" },
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ export async function GET() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const headers = [
|
const headers = [
|
||||||
"商户名称",
|
"商户注册名称",
|
||||||
|
"商户经营名称",
|
||||||
|
"商户编号",
|
||||||
"联系人",
|
"联系人",
|
||||||
"联系人电话",
|
"联系人电话",
|
||||||
"结算人",
|
"结算人",
|
||||||
@@ -17,8 +19,6 @@ export async function GET() {
|
|||||||
"产品明细",
|
"产品明细",
|
||||||
"押金",
|
"押金",
|
||||||
"买断",
|
"买断",
|
||||||
"生日类型",
|
|
||||||
"生日归属",
|
|
||||||
"生日",
|
"生日",
|
||||||
"业务员",
|
"业务员",
|
||||||
"报单日期",
|
"报单日期",
|
||||||
@@ -27,7 +27,9 @@ export async function GET() {
|
|||||||
|
|
||||||
// 示例行(用户导入前需删除此行)
|
// 示例行(用户导入前需删除此行)
|
||||||
const example = [
|
const example = [
|
||||||
"模板名称_此行删除",
|
"模板注册名称_此行删除",
|
||||||
|
"模板经营名称",
|
||||||
|
"Ab12Cd",
|
||||||
"侯磊",
|
"侯磊",
|
||||||
"13813855555",
|
"13813855555",
|
||||||
"张三",
|
"张三",
|
||||||
@@ -35,8 +37,6 @@ export async function GET() {
|
|||||||
"POS+CRM",
|
"POS+CRM",
|
||||||
"100",
|
"100",
|
||||||
"100",
|
"100",
|
||||||
"阴历",
|
|
||||||
"联系人",
|
|
||||||
"生日格式要求:2022-06-21",
|
"生日格式要求:2022-06-21",
|
||||||
"A",
|
"A",
|
||||||
"报单日期格式要求:2022-06-21",
|
"报单日期格式要求:2022-06-21",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export default async function DashboardLayout({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarProvider>
|
<SidebarProvider>
|
||||||
<div className="flex h-screen overflow-hidden">
|
<div className="flex h-dvh overflow-hidden overscroll-none">
|
||||||
<Sidebar isSuperAdmin={superAdmin} />
|
<Sidebar isSuperAdmin={superAdmin} />
|
||||||
<div className="flex min-w-0 flex-1 flex-col">
|
<div className="flex min-w-0 flex-1 flex-col">
|
||||||
<Topbar
|
<Topbar
|
||||||
@@ -29,9 +29,9 @@ export default async function DashboardLayout({
|
|||||||
image: null, // 旧 face 为老站点相对路径,统一用文字头像
|
image: null, // 旧 face 为老站点相对路径,统一用文字头像
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<main className="flex-1 overflow-y-auto">
|
<main className="flex-1 overflow-y-auto overflow-x-hidden overscroll-y-contain">
|
||||||
<div className="p-6">{children}</div>
|
<div className="p-4 md:p-6">{children}</div>
|
||||||
<footer className="flex items-center justify-between border-t px-6 py-4 text-xs text-[var(--color-muted-foreground)]">
|
<footer className="flex flex-col gap-1 border-t px-4 py-4 text-xs text-[var(--color-muted-foreground)] pb-[max(1rem,env(safe-area-inset-bottom))] md:flex-row md:items-center md:justify-between md:px-6">
|
||||||
<span>{copyright()}</span>
|
<span>{copyright()}</span>
|
||||||
<span>{brand.name} · {brand.tagline}</span>
|
<span>{brand.name} · {brand.tagline}</span>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export function ProfileForm({ nickname, username }: { nickname: string; username
|
|||||||
<Label htmlFor="nickname">昵称</Label>
|
<Label htmlFor="nickname">昵称</Label>
|
||||||
<Input id="nickname" name="nickname" defaultValue={nickname} />
|
<Input id="nickname" name="nickname" defaultValue={nickname} />
|
||||||
</div>
|
</div>
|
||||||
<Button type="submit" disabled={pending}>{pending ? "保存中…" : "保存资料"}</Button>
|
<Button type="submit" disabled={pending} className="w-full sm:w-auto">{pending ? "保存中…" : "保存资料"}</Button>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ export function PasswordForm() {
|
|||||||
<Label htmlFor="confirmPassword">确认新密码</Label>
|
<Label htmlFor="confirmPassword">确认新密码</Label>
|
||||||
<Input id="confirmPassword" name="confirmPassword" type="password" autoComplete="new-password" />
|
<Input id="confirmPassword" name="confirmPassword" type="password" autoComplete="new-password" />
|
||||||
</div>
|
</div>
|
||||||
<Button type="submit" disabled={pending}>{pending ? "提交中…" : "修改密码"}</Button>
|
<Button type="submit" disabled={pending} className="w-full sm:w-auto">{pending ? "提交中…" : "修改密码"}</Button>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ export default async function MePage() {
|
|||||||
<Card>
|
<Card>
|
||||||
<CardContent className="flex items-center gap-4">
|
<CardContent className="flex items-center gap-4">
|
||||||
<Avatar name={admin.nickname} size={56} />
|
<Avatar name={admin.nickname} size={56} />
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<div className="text-lg font-semibold">{admin.nickname}</div>
|
<div className="truncate text-lg font-semibold">{admin.nickname}</div>
|
||||||
<div className="mt-1 flex items-center gap-2 text-sm text-[var(--color-muted-foreground)]">
|
<div className="mt-1 flex flex-wrap items-center gap-2 text-sm text-[var(--color-muted-foreground)]">
|
||||||
<span className="tabular-nums">{admin.username}</span>
|
<span className="tabular-nums">{admin.username}</span>
|
||||||
<Badge tone="primary">{roleLabel}</Badge>
|
<Badge tone="primary">{roleLabel}</Badge>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { birthdayMatchLists } from "@/lib/lunar";
|
|||||||
import { fmtDate } from "@/lib/utils";
|
import { fmtDate } from "@/lib/utils";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Table, THead, TR, TH, TD } from "@/components/ui/table";
|
import { Table, THead, TR, TH, TD } from "@/components/ui/table";
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import { MonthlyReportChart, type MonthPoint } from "./report-chart";
|
import { MonthlyReportChart, type MonthPoint } from "./report-chart";
|
||||||
|
|
||||||
export default async function DashboardPage() {
|
export default async function DashboardPage() {
|
||||||
@@ -80,21 +79,21 @@ export default async function DashboardPage() {
|
|||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
{/* 统计卡片 */}
|
{/* 统计卡片 */}
|
||||||
<div className="grid grid-cols-2 gap-4 lg:grid-cols-4">
|
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
|
||||||
{stats.map((s) => {
|
{stats.map((s) => {
|
||||||
const Icon = s.icon;
|
const Icon = s.icon;
|
||||||
return (
|
return (
|
||||||
<Card key={s.label}>
|
<Card key={s.label}>
|
||||||
<CardContent className="flex items-center gap-4">
|
<CardContent className="flex items-center gap-2.5 md:gap-4">
|
||||||
<span
|
<span
|
||||||
className="flex h-12 w-12 items-center justify-center rounded-xl"
|
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl md:h-12 md:w-12"
|
||||||
style={{ background: toneBg[s.tone], color: toneFg[s.tone] }}
|
style={{ background: toneBg[s.tone], color: toneFg[s.tone] }}
|
||||||
>
|
>
|
||||||
<Icon className="h-6 w-6" />
|
<Icon className="h-5 w-5 md:h-6 md:w-6" />
|
||||||
</span>
|
</span>
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<div className="text-sm text-[var(--color-muted-foreground)]">{s.label}</div>
|
<div className="text-xs text-[var(--color-muted-foreground)] md:text-sm">{s.label}</div>
|
||||||
<div className="mt-0.5 text-2xl font-semibold tabular-nums">{s.value}</div>
|
<div className="mt-0.5 text-xl font-semibold tabular-nums md:text-2xl">{s.value}</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -121,15 +120,18 @@ export default async function DashboardPage() {
|
|||||||
<CardTitle>最近报单商户</CardTitle>
|
<CardTitle>最近报单商户</CardTitle>
|
||||||
<Link
|
<Link
|
||||||
href="/customers"
|
href="/customers"
|
||||||
className="flex items-center gap-1 text-[13px] font-medium text-[var(--color-primary)] hover:underline"
|
className="flex min-h-11 items-center gap-1 text-[13px] font-medium text-[var(--color-primary)] hover:underline md:min-h-0"
|
||||||
>
|
>
|
||||||
查看全部 <ArrowUpRight className="h-3.5 w-3.5" />
|
查看全部 <ArrowUpRight className="h-3.5 w-3.5" />
|
||||||
</Link>
|
</Link>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
<div className="hidden md:block">
|
||||||
<Table>
|
<Table>
|
||||||
<THead>
|
<THead>
|
||||||
<tr>
|
<tr>
|
||||||
<TH>商户名称</TH>
|
<TH>商户注册名称</TH>
|
||||||
|
<TH>商户经营名称</TH>
|
||||||
|
<TH>商户编号</TH>
|
||||||
<TH>联系人</TH>
|
<TH>联系人</TH>
|
||||||
<TH>业务员</TH>
|
<TH>业务员</TH>
|
||||||
<TH>报单时间</TH>
|
<TH>报单时间</TH>
|
||||||
@@ -140,21 +142,55 @@ export default async function DashboardPage() {
|
|||||||
{recent.map((c) => (
|
{recent.map((c) => (
|
||||||
<TR key={c.id}>
|
<TR key={c.id}>
|
||||||
<TD className="font-medium">{c.customerName}</TD>
|
<TD className="font-medium">{c.customerName}</TD>
|
||||||
|
<TD className="font-medium">{c.businessName || "—"}</TD>
|
||||||
|
<TD className="break-all">{c.customerNo || "—"}</TD>
|
||||||
<TD>{c.contacts}</TD>
|
<TD>{c.contacts}</TD>
|
||||||
<TD>{c.salesman}</TD>
|
<TD>{c.salesman}</TD>
|
||||||
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
|
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
|
||||||
<TD>
|
<TD className="tabular-nums">{fmtDate(c.birthday)}</TD>
|
||||||
<span className="tabular-nums">{fmtDate(c.birthday)}</span>
|
|
||||||
{c.birthday && (
|
|
||||||
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="ml-2">
|
|
||||||
{c.birthdayType === 2 ? "农历" : "阳历"}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</TD>
|
|
||||||
</TR>
|
</TR>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
|
</div>
|
||||||
|
<div className="divide-y md:hidden">
|
||||||
|
{recent.length === 0 && (
|
||||||
|
<div className="px-4 py-10 text-center text-sm text-[var(--color-muted-foreground)]">
|
||||||
|
暂无报单
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{recent.map((c) => (
|
||||||
|
<div key={c.id} className="flex items-start justify-between gap-3 px-4 py-3">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="truncate font-medium">{c.customerName}</div>
|
||||||
|
{c.businessName ? (
|
||||||
|
<div className="mt-0.5 truncate text-xs text-[var(--color-muted-foreground)]">
|
||||||
|
经营名称 {c.businessName}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{c.customerNo ? (
|
||||||
|
<div className="mt-0.5 break-all text-xs text-[var(--color-muted-foreground)]">
|
||||||
|
编号 {c.customerNo}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<div className="mt-1 text-xs text-[var(--color-muted-foreground)]">
|
||||||
|
{c.contacts || "—"}
|
||||||
|
{c.salesman ? ` · ${c.salesman}` : ""}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="shrink-0 text-right">
|
||||||
|
<div className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||||
|
{fmtDate(c.reportDate)}
|
||||||
|
</div>
|
||||||
|
{c.birthday ? (
|
||||||
|
<div className="mt-1 text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||||
|
{fmtDate(c.birthday)}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export function AdminForm({
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex gap-2 border-t pt-4">
|
<div className="sticky bottom-0 z-10 -mx-4 flex gap-2 border-t bg-[var(--color-surface)] px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] md:static md:mx-0 md:px-0 md:pb-0 md:pt-4">
|
||||||
<Button type="submit" disabled={pending}>
|
<Button type="submit" disabled={pending}>
|
||||||
{pending ? "保存中…" : "保存"}
|
{pending ? "保存中…" : "保存"}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ export default async function AdminsPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex justify-end">
|
<div className="flex">
|
||||||
<Link href="/rbac/admins/new">
|
<Link href="/rbac/admins/new" className="w-full sm:ml-auto sm:w-auto">
|
||||||
<Button><Plus className="h-4 w-4" />新增管理员</Button>
|
<Button className="w-full"><Plus className="h-4 w-4" />新增管理员</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<Card className="overflow-hidden">
|
<Card className="hidden overflow-hidden md:block">
|
||||||
<Table>
|
<Table>
|
||||||
<THead>
|
<THead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -75,6 +75,39 @@ export default async function AdminsPage() {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<div className="space-y-3 md:hidden">
|
||||||
|
{admins.map((a) => (
|
||||||
|
<Card key={a.id} className="p-4">
|
||||||
|
<div className="flex items-start gap-3">
|
||||||
|
<Avatar name={a.nickname} size={36} />
|
||||||
|
<div className="min-w-0 flex-1">
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<span className="truncate font-medium">{a.nickname}</span>
|
||||||
|
{adminRole.get(a.id) ? (
|
||||||
|
<Badge tone="primary" className="shrink-0">{adminRole.get(a.id)}</Badge>
|
||||||
|
) : (
|
||||||
|
<span className="shrink-0 text-xs text-[var(--color-muted-foreground)]">未分配</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="mt-0.5 text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||||
|
{a.username}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 flex flex-wrap gap-1.5 border-t pt-3">
|
||||||
|
<Link href={`/rbac/admins/${a.id}/edit`}>
|
||||||
|
<Button variant="outline" size="sm">编辑</Button>
|
||||||
|
</Link>
|
||||||
|
<ConfirmDelete
|
||||||
|
action={deleteAdmin.bind(null, a.id)}
|
||||||
|
name={a.nickname}
|
||||||
|
disabled={a.id === 1}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,12 +44,12 @@ export default async function PermissionsPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex justify-end">
|
<div className="flex">
|
||||||
<Link href="/rbac/permissions/new">
|
<Link href="/rbac/permissions/new" className="w-full sm:ml-auto sm:w-auto">
|
||||||
<Button><Plus className="h-4 w-4" />新增权限</Button>
|
<Button className="w-full"><Plus className="h-4 w-4" />新增权限</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<Card className="overflow-hidden">
|
<Card className="hidden overflow-hidden md:block">
|
||||||
<Table>
|
<Table>
|
||||||
<THead>
|
<THead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -85,6 +85,26 @@ export default async function PermissionsPage() {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<div className="space-y-3 md:hidden">
|
||||||
|
{rows.map(({ p, depth }) => (
|
||||||
|
<Card key={p.id} className="p-4" style={{ marginLeft: depth * 12 }}>
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="font-medium">{p.title || p.name}</div>
|
||||||
|
<div className="mt-1 truncate text-xs text-[var(--color-muted-foreground)]">{p.name}</div>
|
||||||
|
</div>
|
||||||
|
{p.isMenu ? <Badge tone="primary" className="shrink-0">菜单</Badge> : <Badge className="shrink-0">操作</Badge>}
|
||||||
|
</div>
|
||||||
|
<div className="mt-3 flex flex-wrap gap-1.5 border-t pt-3">
|
||||||
|
<Link href={`/rbac/permissions/${p.id}/edit`}>
|
||||||
|
<Button variant="outline" size="sm">编辑</Button>
|
||||||
|
</Link>
|
||||||
|
<ConfirmDelete action={deletePermission.bind(null, p.id)} name={p.title || p.name} />
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export function PermissionForm({
|
|||||||
const v = defaultValues ?? {};
|
const v = defaultValues ?? {};
|
||||||
return (
|
return (
|
||||||
<form action={formAction} className="max-w-lg space-y-4">
|
<form action={formAction} className="max-w-lg space-y-4">
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<Label htmlFor="title">权限名称<span className="ml-0.5 text-[var(--color-danger)]">*</span></Label>
|
<Label htmlFor="title">权限名称<span className="ml-0.5 text-[var(--color-danger)]">*</span></Label>
|
||||||
<Input id="title" name="title" defaultValue={v.title} placeholder="如:商户列表" />
|
<Input id="title" name="title" defaultValue={v.title} placeholder="如:商户列表" />
|
||||||
@@ -53,12 +53,12 @@ export function PermissionForm({
|
|||||||
<Label htmlFor="sort">排序</Label>
|
<Label htmlFor="sort">排序</Label>
|
||||||
<Input id="sort" name="sort" type="number" defaultValue={String(v.sort ?? 0)} />
|
<Input id="sort" name="sort" type="number" defaultValue={String(v.sort ?? 0)} />
|
||||||
</div>
|
</div>
|
||||||
<label className="flex items-center gap-2 self-end pb-2">
|
<label className="flex min-h-11 items-center gap-2 sm:self-end sm:pb-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="isMenu"
|
name="isMenu"
|
||||||
defaultChecked={v.isMenu}
|
defaultChecked={v.isMenu}
|
||||||
className="h-4 w-4 accent-[var(--color-primary)]"
|
className="h-5 w-5 accent-[var(--color-primary)]"
|
||||||
/>
|
/>
|
||||||
<span className="text-sm">显示为菜单</span>
|
<span className="text-sm">显示为菜单</span>
|
||||||
</label>
|
</label>
|
||||||
@@ -68,7 +68,7 @@ export function PermissionForm({
|
|||||||
{state.error}
|
{state.error}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<div className="flex gap-2 border-t pt-4">
|
<div className="sticky bottom-0 z-10 -mx-4 flex gap-2 border-t bg-[var(--color-surface)] px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] md:static md:mx-0 md:px-0 md:pb-0 md:pt-4">
|
||||||
<Button type="submit" disabled={pending}>{pending ? "保存中…" : "保存"}</Button>
|
<Button type="submit" disabled={pending}>{pending ? "保存中…" : "保存"}</Button>
|
||||||
<Link href="/rbac/permissions"><Button type="button" variant="outline">取消</Button></Link>
|
<Link href="/rbac/permissions"><Button type="button" variant="outline">取消</Button></Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -52,17 +52,21 @@ export function AssignPermissions({
|
|||||||
const renderNode = (node: PermNode, depth: number) => (
|
const renderNode = (node: PermNode, depth: number) => (
|
||||||
<div key={node.id}>
|
<div key={node.id}>
|
||||||
<label
|
<label
|
||||||
className="flex items-center gap-2.5 rounded-md px-2 py-1.5 hover:bg-[var(--color-muted)]"
|
className="flex min-h-11 items-center gap-2.5 rounded-md py-2 pr-2 hover:bg-[var(--color-muted)]"
|
||||||
style={{ paddingLeft: depth * 20 + 8 }}
|
style={{ paddingLeft: 8 + depth * 14 }}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="h-4 w-4 accent-[var(--color-primary)]"
|
className="h-5 w-5 shrink-0 accent-[var(--color-primary)]"
|
||||||
checked={checked.has(node.id)}
|
checked={checked.has(node.id)}
|
||||||
onChange={(e) => toggle(node, e.target.checked)}
|
onChange={(e) => toggle(node, e.target.checked)}
|
||||||
/>
|
/>
|
||||||
|
<span className="min-w-0">
|
||||||
<span className="text-sm">{node.title}</span>
|
<span className="text-sm">{node.title}</span>
|
||||||
<span className="text-xs text-[var(--color-muted-foreground)]">{node.name}</span>
|
<span className="mt-0.5 block truncate text-xs text-[var(--color-muted-foreground)] sm:ml-1.5 sm:mt-0 sm:inline">
|
||||||
|
{node.name}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
</label>
|
</label>
|
||||||
{node.children.map((c) => renderNode(c, depth + 1))}
|
{node.children.map((c) => renderNode(c, depth + 1))}
|
||||||
</div>
|
</div>
|
||||||
@@ -73,8 +77,8 @@ export function AssignPermissions({
|
|||||||
<div className="rounded-[var(--radius)] border p-2">
|
<div className="rounded-[var(--radius)] border p-2">
|
||||||
{tree.map((n) => renderNode(n, 0))}
|
{tree.map((n) => renderNode(n, 0))}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="sticky bottom-0 z-10 -mx-4 flex gap-2 border-t bg-[var(--color-surface)] px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] md:static md:mx-0 md:px-0 md:pb-0 md:pt-4">
|
||||||
<Button onClick={save} disabled={pending}>
|
<Button onClick={save} disabled={pending} className="flex-1 sm:flex-none">
|
||||||
{pending ? "保存中…" : `保存(已选 ${checked.size} 项)`}
|
{pending ? "保存中…" : `保存(已选 ${checked.size} 项)`}
|
||||||
</Button>
|
</Button>
|
||||||
<Link href="/rbac/roles"><Button variant="outline">取消</Button></Link>
|
<Link href="/rbac/roles"><Button variant="outline">取消</Button></Link>
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ export default async function RolesPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="flex justify-end">
|
<div className="flex">
|
||||||
<Link href="/rbac/roles/new">
|
<Link href="/rbac/roles/new" className="w-full sm:ml-auto sm:w-auto">
|
||||||
<Button><Plus className="h-4 w-4" />新增角色</Button>
|
<Button className="w-full"><Plus className="h-4 w-4" />新增角色</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<Card className="overflow-hidden">
|
<Card className="hidden overflow-hidden md:block">
|
||||||
<Table>
|
<Table>
|
||||||
<THead>
|
<THead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -62,6 +62,35 @@ export default async function RolesPage() {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
<div className="space-y-3 md:hidden">
|
||||||
|
{roles.map((r) => (
|
||||||
|
<Card key={r.id} className="p-4">
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="flex items-center gap-2 font-medium">
|
||||||
|
<ShieldCheck className="h-4 w-4 shrink-0 text-[var(--color-primary)]" />
|
||||||
|
<span className="truncate">{r.title || r.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className="mt-1 text-xs text-[var(--color-muted-foreground)]">{r.name}</div>
|
||||||
|
</div>
|
||||||
|
<Badge tone="info" className="shrink-0">{countMap.get(r.id) ?? 0} 项权限</Badge>
|
||||||
|
</div>
|
||||||
|
{r.remark && (
|
||||||
|
<p className="mt-2 text-sm text-[var(--color-muted-foreground)]">{r.remark}</p>
|
||||||
|
)}
|
||||||
|
<div className="mt-3 flex flex-wrap gap-1.5 border-t pt-3">
|
||||||
|
<Link href={`/rbac/roles/${r.id}/permissions`}>
|
||||||
|
<Button variant="soft" size="sm">分配权限</Button>
|
||||||
|
</Link>
|
||||||
|
<Link href={`/rbac/roles/${r.id}/edit`}>
|
||||||
|
<Button variant="outline" size="sm">编辑</Button>
|
||||||
|
</Link>
|
||||||
|
<ConfirmDelete action={deleteRole.bind(null, r.id)} name={r.title || r.name} disabled={r.id === 1} />
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export function RoleForm({
|
|||||||
{state.error}
|
{state.error}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<div className="flex gap-2 border-t pt-4">
|
<div className="sticky bottom-0 z-10 -mx-4 flex gap-2 border-t bg-[var(--color-surface)] px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] md:static md:mx-0 md:px-0 md:pb-0 md:pt-4">
|
||||||
<Button type="submit" disabled={pending}>{pending ? "保存中…" : "保存"}</Button>
|
<Button type="submit" disabled={pending}>{pending ? "保存中…" : "保存"}</Button>
|
||||||
<Link href="/rbac/roles"><Button type="button" variant="outline">取消</Button></Link>
|
<Link href="/rbac/roles"><Button type="button" variant="outline">取消</Button></Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,20 +17,21 @@ export function MonthlyReportChart({ data }: { data: MonthPoint[] }) {
|
|||||||
const max = Math.max(1, ...data.map((d) => d.count));
|
const max = Math.max(1, ...data.map((d) => d.count));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-72 w-full">
|
<div className="h-52 w-full md:h-72">
|
||||||
<ResponsiveContainer width="100%" height="100%">
|
<ResponsiveContainer width="100%" height="100%">
|
||||||
<BarChart data={data} margin={{ top: 8, right: 8, left: -12, bottom: 0 }}>
|
<BarChart data={data} margin={{ top: 8, right: 4, left: -18, bottom: 0 }}>
|
||||||
<CartesianGrid strokeDasharray="3 3" stroke="#eef0f3" vertical={false} />
|
<CartesianGrid strokeDasharray="3 3" stroke="#eef0f3" vertical={false} />
|
||||||
<XAxis
|
<XAxis
|
||||||
dataKey="label"
|
dataKey="label"
|
||||||
tick={{ fontSize: 12, fill: "#64748b" }}
|
tick={{ fontSize: 10, fill: "#64748b" }}
|
||||||
tickLine={false}
|
tickLine={false}
|
||||||
axisLine={{ stroke: "#e8eaed" }}
|
axisLine={{ stroke: "#e8eaed" }}
|
||||||
|
interval="preserveStartEnd"
|
||||||
/>
|
/>
|
||||||
<YAxis
|
<YAxis
|
||||||
allowDecimals={false}
|
allowDecimals={false}
|
||||||
width={40}
|
width={32}
|
||||||
tick={{ fontSize: 12, fill: "#64748b" }}
|
tick={{ fontSize: 11, fill: "#64748b" }}
|
||||||
tickLine={false}
|
tickLine={false}
|
||||||
axisLine={false}
|
axisLine={false}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -45,6 +45,8 @@
|
|||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
-webkit-text-size-adjust: 100%;
|
||||||
|
text-size-adjust: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@@ -52,6 +54,16 @@ body {
|
|||||||
color: var(--color-foreground);
|
color: var(--color-foreground);
|
||||||
font-family: var(--font-sans);
|
font-family: var(--font-sans);
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 避免 iOS 聚焦输入框时自动放大(需 ≥16px) */
|
||||||
|
@media (max-width: 767px) {
|
||||||
|
input,
|
||||||
|
select,
|
||||||
|
textarea {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 细滚动条 */
|
/* 细滚动条 */
|
||||||
|
|||||||
+8
-1
@@ -1,4 +1,4 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata, Viewport } from "next";
|
||||||
import { Toaster } from "sonner";
|
import { Toaster } from "sonner";
|
||||||
import { brand } from "@/lib/brand";
|
import { brand } from "@/lib/brand";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
@@ -8,6 +8,13 @@ export const metadata: Metadata = {
|
|||||||
description: `${brand.company} ${brand.tagline}`,
|
description: `${brand.company} ${brand.tagline}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const viewport: Viewport = {
|
||||||
|
width: "device-width",
|
||||||
|
initialScale: 1,
|
||||||
|
viewportFit: "cover",
|
||||||
|
themeColor: "#4f46e5",
|
||||||
|
};
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
children,
|
children,
|
||||||
}: Readonly<{ children: React.ReactNode }>) {
|
}: Readonly<{ children: React.ReactNode }>) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { LoginForm } from "./login-form";
|
|||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
return (
|
return (
|
||||||
<div className="relative flex min-h-screen items-center justify-center overflow-hidden px-4">
|
<div className="relative flex min-h-dvh items-center justify-center overflow-hidden px-4 py-[max(1rem,env(safe-area-inset-top))] pb-[max(1rem,env(safe-area-inset-bottom))]">
|
||||||
{/* 背景装饰 */}
|
{/* 背景装饰 */}
|
||||||
<div className="pointer-events-none absolute inset-0 -z-10 bg-[radial-gradient(60%_50%_at_50%_0%,#e0e7ff_0%,transparent_60%)]" />
|
<div className="pointer-events-none absolute inset-0 -z-10 bg-[radial-gradient(60%_50%_at_50%_0%,#e0e7ff_0%,transparent_60%)]" />
|
||||||
<Suspense>
|
<Suspense>
|
||||||
|
|||||||
@@ -1,25 +1,61 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { createContext, useContext, useState } from "react";
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
type SidebarCtx = {
|
type SidebarCtx = {
|
||||||
collapsed: boolean;
|
collapsed: boolean;
|
||||||
toggle: () => void;
|
toggle: () => void;
|
||||||
setCollapsed: (v: boolean) => void;
|
setCollapsed: (v: boolean) => void;
|
||||||
|
mobileOpen: boolean;
|
||||||
|
openMobile: () => void;
|
||||||
|
closeMobile: () => void;
|
||||||
|
toggleMobile: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Ctx = createContext<SidebarCtx | null>(null);
|
const Ctx = createContext<SidebarCtx | null>(null);
|
||||||
|
|
||||||
/** 折叠状态提供者:包裹侧边栏 + 主区,供二者共享 collapsed */
|
/** 折叠状态提供者:包裹侧边栏 + 主区,供二者共享 collapsed / 手机抽屉 */
|
||||||
export function SidebarProvider({ children }: { children: React.ReactNode }) {
|
export function SidebarProvider({ children }: { children: React.ReactNode }) {
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
return (
|
const [mobileOpen, setMobileOpen] = useState(false);
|
||||||
<Ctx.Provider
|
|
||||||
value={{ collapsed, toggle: () => setCollapsed((v) => !v), setCollapsed }}
|
useEffect(() => {
|
||||||
>
|
const mq = window.matchMedia("(min-width: 768px)");
|
||||||
{children}
|
const onChange = () => {
|
||||||
</Ctx.Provider>
|
if (mq.matches) setMobileOpen(false);
|
||||||
|
};
|
||||||
|
mq.addEventListener("change", onChange);
|
||||||
|
return () => mq.removeEventListener("change", onChange);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!mobileOpen) return;
|
||||||
|
const prev = document.body.style.overflow;
|
||||||
|
document.body.style.overflow = "hidden";
|
||||||
|
return () => {
|
||||||
|
document.body.style.overflow = prev;
|
||||||
|
};
|
||||||
|
}, [mobileOpen]);
|
||||||
|
|
||||||
|
const toggle = useCallback(() => setCollapsed((v) => !v), []);
|
||||||
|
const openMobile = useCallback(() => setMobileOpen(true), []);
|
||||||
|
const closeMobile = useCallback(() => setMobileOpen(false), []);
|
||||||
|
const toggleMobile = useCallback(() => setMobileOpen((v) => !v), []);
|
||||||
|
|
||||||
|
const value = useMemo(
|
||||||
|
() => ({
|
||||||
|
collapsed,
|
||||||
|
toggle,
|
||||||
|
setCollapsed,
|
||||||
|
mobileOpen,
|
||||||
|
openMobile,
|
||||||
|
closeMobile,
|
||||||
|
toggleMobile,
|
||||||
|
}),
|
||||||
|
[collapsed, toggle, mobileOpen, openMobile, closeMobile, toggleMobile]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return <Ctx.Provider value={value}>{children}</Ctx.Provider>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSidebar() {
|
export function useSidebar() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useEffect } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
@@ -11,26 +12,40 @@ import { useSidebar } from "./sidebar-context";
|
|||||||
export function Sidebar({ isSuperAdmin }: { isSuperAdmin: boolean }) {
|
export function Sidebar({ isSuperAdmin }: { isSuperAdmin: boolean }) {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const active = activeHref(pathname);
|
const active = activeHref(pathname);
|
||||||
const { collapsed } = useSidebar();
|
const { collapsed, mobileOpen, closeMobile } = useSidebar();
|
||||||
const sections = navSections.filter((s) => !s.superAdminOnly || isSuperAdmin);
|
const sections = navSections.filter((s) => !s.superAdminOnly || isSuperAdmin);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
closeMobile();
|
||||||
|
}, [pathname, closeMobile]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{mobileOpen && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="关闭菜单"
|
||||||
|
className="fixed inset-0 z-30 bg-black/40 md:hidden"
|
||||||
|
onClick={closeMobile}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<aside
|
<aside
|
||||||
className={cn(
|
className={cn(
|
||||||
"shrink-0 overflow-hidden transition-[width] duration-200 ease-in-out",
|
"z-40 overflow-hidden bg-[var(--color-sidebar)] text-[var(--color-sidebar-foreground)]",
|
||||||
collapsed ? "w-0" : "w-60"
|
"fixed inset-y-0 left-0 w-60 transition-transform duration-200 ease-in-out",
|
||||||
|
mobileOpen ? "translate-x-0" : "-translate-x-full",
|
||||||
|
"md:static md:translate-x-0 md:shrink-0 md:transition-[width]",
|
||||||
|
collapsed ? "md:w-0" : "md:w-60"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{/* 固定宽度内容容器:折叠时被外层裁剪,形成平滑滑动而非挤压 */}
|
<div className="flex h-full w-60 flex-col pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]">
|
||||||
<div className="flex h-full w-60 flex-col bg-[var(--color-sidebar)] text-[var(--color-sidebar-foreground)]">
|
|
||||||
{/* 品牌 */}
|
|
||||||
<div className="flex h-16 items-center px-5">
|
<div className="flex h-16 items-center px-5">
|
||||||
<Link href="/">
|
<Link href="/" onClick={closeMobile}>
|
||||||
<BrandLogo size={36} invert />
|
<BrandLogo size={36} invert />
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<nav className="flex-1 space-y-6 overflow-y-auto px-3 py-4">
|
<nav className="flex-1 space-y-6 overflow-y-auto overscroll-contain px-3 py-4">
|
||||||
{sections.map((section) => (
|
{sections.map((section) => (
|
||||||
<div key={section.title}>
|
<div key={section.title}>
|
||||||
<div className="px-3 pb-2 text-[11px] font-medium uppercase tracking-wider text-[var(--color-sidebar-muted)]">
|
<div className="px-3 pb-2 text-[11px] font-medium uppercase tracking-wider text-[var(--color-sidebar-muted)]">
|
||||||
@@ -44,8 +59,9 @@ export function Sidebar({ isSuperAdmin }: { isSuperAdmin: boolean }) {
|
|||||||
<Link
|
<Link
|
||||||
key={item.href}
|
key={item.href}
|
||||||
href={item.href}
|
href={item.href}
|
||||||
|
onClick={closeMobile}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm transition-colors",
|
"flex min-h-11 items-center gap-3 rounded-lg px-3 py-2.5 text-sm transition-colors md:min-h-0 md:py-2",
|
||||||
isActive
|
isActive
|
||||||
? "bg-[var(--color-primary)] text-white shadow-sm"
|
? "bg-[var(--color-primary)] text-white shadow-sm"
|
||||||
: "text-[var(--color-sidebar-muted)] hover:bg-[var(--color-sidebar-hover)] hover:text-white"
|
: "text-[var(--color-sidebar-muted)] hover:bg-[var(--color-sidebar-hover)] hover:text-white"
|
||||||
@@ -66,5 +82,6 @@ export function Sidebar({ isSuperAdmin }: { isSuperAdmin: boolean }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,36 +29,44 @@ export function Topbar({
|
|||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
const { toggle } = useSidebar();
|
const { toggle, toggleMobile, mobileOpen } = useSidebar();
|
||||||
|
|
||||||
|
function onMenu() {
|
||||||
|
if (window.matchMedia("(min-width: 768px)").matches) toggle();
|
||||||
|
else toggleMobile();
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function onClick(e: MouseEvent) {
|
function onClick(e: Event) {
|
||||||
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
||||||
}
|
}
|
||||||
document.addEventListener("mousedown", onClick);
|
document.addEventListener("pointerdown", onClick);
|
||||||
return () => document.removeEventListener("mousedown", onClick);
|
return () => document.removeEventListener("pointerdown", onClick);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const roleLabel = user.roles.includes("super admin") ? "超级管理员" : "业务员";
|
const roleLabel = user.roles.includes("super admin") ? "超级管理员" : "业务员";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="sticky top-0 z-20 flex h-16 items-center justify-between border-b bg-[var(--color-surface)]/90 px-6 backdrop-blur">
|
<header className="sticky top-0 z-20 flex h-[calc(4rem+env(safe-area-inset-top))] items-center justify-between border-b bg-[var(--color-surface)]/90 px-3 pt-[env(safe-area-inset-top)] backdrop-blur md:px-6">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex min-w-0 items-center gap-2 md:gap-3">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={toggle}
|
onClick={onMenu}
|
||||||
aria-label="收起/展开菜单"
|
aria-label="打开/关闭菜单"
|
||||||
className="-ml-1.5 rounded-md p-1.5 text-[var(--color-muted-foreground)] transition-colors hover:bg-[var(--color-muted)] hover:text-[var(--color-foreground)]"
|
aria-expanded={mobileOpen}
|
||||||
|
className="-ml-1 flex h-11 w-11 items-center justify-center rounded-md text-[var(--color-muted-foreground)] transition-colors hover:bg-[var(--color-muted)] hover:text-[var(--color-foreground)] md:h-auto md:w-auto md:p-1.5"
|
||||||
>
|
>
|
||||||
<PanelLeft className="h-[18px] w-[18px]" />
|
<PanelLeft className="h-[18px] w-[18px]" />
|
||||||
</button>
|
</button>
|
||||||
<h1 className="text-base font-semibold">{pageTitle(pathname)}</h1>
|
<h1 className="truncate text-base font-semibold">{pageTitle(pathname)}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative" ref={ref}>
|
<div className="relative" ref={ref}>
|
||||||
<button
|
<button
|
||||||
|
type="button"
|
||||||
onClick={() => setOpen((v) => !v)}
|
onClick={() => setOpen((v) => !v)}
|
||||||
className="flex items-center gap-2.5 rounded-full py-1 pl-1 pr-2.5 transition-colors hover:bg-[var(--color-muted)]"
|
className="flex min-h-11 items-center gap-2.5 rounded-full py-1 pl-1 pr-2.5 transition-colors hover:bg-[var(--color-muted)]"
|
||||||
|
aria-expanded={open}
|
||||||
>
|
>
|
||||||
<Avatar name={user.name ?? user.username} src={user.image} size={32} />
|
<Avatar name={user.name ?? user.username} src={user.image} size={32} />
|
||||||
<div className="hidden text-left leading-tight sm:block">
|
<div className="hidden text-left leading-tight sm:block">
|
||||||
@@ -73,7 +81,7 @@ export function Topbar({
|
|||||||
<Link
|
<Link
|
||||||
href="/me"
|
href="/me"
|
||||||
onClick={() => setOpen(false)}
|
onClick={() => setOpen(false)}
|
||||||
className="flex items-center gap-2.5 px-4 py-2 text-sm hover:bg-[var(--color-muted)]"
|
className="flex min-h-11 items-center gap-2.5 px-4 py-2 text-sm hover:bg-[var(--color-muted)] md:min-h-0"
|
||||||
>
|
>
|
||||||
<User className="h-4 w-4" /> 个人中心
|
<User className="h-4 w-4" /> 个人中心
|
||||||
</Link>
|
</Link>
|
||||||
@@ -85,7 +93,7 @@ export function Topbar({
|
|||||||
window.location.assign("/login");
|
window.location.assign("/login");
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
className="flex w-full items-center gap-2.5 px-4 py-2 text-sm text-[var(--color-danger)] hover:bg-[var(--color-danger-soft)]"
|
className="flex min-h-11 w-full items-center gap-2.5 px-4 py-2 text-sm text-[var(--color-danger)] hover:bg-[var(--color-danger-soft)] md:min-h-0"
|
||||||
>
|
>
|
||||||
<LogOut className="h-4 w-4" /> 退出登录
|
<LogOut className="h-4 w-4" /> 退出登录
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import * as React from "react";
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const base =
|
const base =
|
||||||
"inline-flex items-center justify-center gap-2 rounded-[var(--radius)] text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-ring)] disabled:pointer-events-none disabled:opacity-50 whitespace-nowrap active:scale-[0.98]";
|
"inline-flex items-center justify-center gap-2 rounded-[var(--radius)] text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-ring)] disabled:pointer-events-none disabled:opacity-50 whitespace-nowrap active:scale-[0.98] touch-manipulation";
|
||||||
|
|
||||||
const variants = {
|
const variants = {
|
||||||
primary:
|
primary:
|
||||||
@@ -18,10 +18,10 @@ const variants = {
|
|||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const sizes = {
|
const sizes = {
|
||||||
default: "h-9 px-4",
|
default: "h-11 px-4 md:h-9",
|
||||||
sm: "h-8 px-3 text-[13px]",
|
sm: "h-9 px-3 text-[13px] md:h-8",
|
||||||
lg: "h-10 px-5",
|
lg: "h-12 px-5 md:h-10",
|
||||||
icon: "h-9 w-9",
|
icon: "h-11 w-11 md:h-9 md:w-9",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export interface ButtonProps
|
export interface ButtonProps
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export function CardHeader({
|
|||||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn("flex items-center justify-between border-b px-5 py-4", className)}
|
className={cn("flex flex-wrap items-center justify-between gap-2 border-b px-4 py-3 md:px-5 md:py-4", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -29,12 +29,12 @@ export function CardTitle({
|
|||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: React.HTMLAttributes<HTMLHeadingElement>) {
|
}: React.HTMLAttributes<HTMLHeadingElement>) {
|
||||||
return <h3 className={cn("text-sm font-semibold", className)} {...props} />;
|
return <h3 className={cn("min-w-0 text-sm font-semibold break-words", className)} {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CardContent({
|
export function CardContent({
|
||||||
className,
|
className,
|
||||||
...props
|
...props
|
||||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
return <div className={cn("p-5", className)} {...props} />;
|
return <div className={cn("p-4 md:p-5", className)} {...props} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import * as React from "react";
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const fieldCls =
|
const fieldCls =
|
||||||
"flex h-9 w-full rounded-[var(--radius)] border bg-[var(--color-surface)] px-3 text-sm shadow-sm transition-colors placeholder:text-[var(--color-muted-foreground)] focus-visible:outline-none focus-visible:border-[var(--color-primary)] focus-visible:ring-2 focus-visible:ring-[var(--color-ring)] disabled:cursor-not-allowed disabled:opacity-50";
|
"flex h-11 w-full rounded-[var(--radius)] border bg-[var(--color-surface)] px-3 text-base shadow-sm transition-colors placeholder:text-[var(--color-muted-foreground)] focus-visible:outline-none focus-visible:border-[var(--color-primary)] focus-visible:ring-2 focus-visible:ring-[var(--color-ring)] disabled:cursor-not-allowed disabled:opacity-50 md:h-9 md:text-sm";
|
||||||
|
|
||||||
export const Input = React.forwardRef<
|
export const Input = React.forwardRef<
|
||||||
HTMLInputElement,
|
HTMLInputElement,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function Table({
|
|||||||
<div className="w-full overflow-x-auto">
|
<div className="w-full overflow-x-auto">
|
||||||
<table
|
<table
|
||||||
className={cn(
|
className={cn(
|
||||||
"w-full text-sm",
|
"w-full min-w-max text-sm",
|
||||||
bordered &&
|
bordered &&
|
||||||
"border border-[var(--color-border)] [&_tr]:divide-x [&_tr]:divide-[var(--color-border)]",
|
"border border-[var(--color-border)] [&_tr]:divide-x [&_tr]:divide-[var(--color-border)]",
|
||||||
striped && "[&_tbody_tr:nth-child(even)]:bg-[var(--color-muted)]/50",
|
striped && "[&_tbody_tr:nth-child(even)]:bg-[var(--color-muted)]/50",
|
||||||
@@ -46,9 +46,9 @@ export function TR({ className, ...props }: React.HTMLAttributes<HTMLTableRowEle
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function TH({ className, ...props }: React.ThHTMLAttributes<HTMLTableCellElement>) {
|
export function TH({ className, ...props }: React.ThHTMLAttributes<HTMLTableCellElement>) {
|
||||||
return <th className={cn("px-4 py-3 font-medium", className)} {...props} />;
|
return <th className={cn("px-3 py-2.5 font-medium md:px-4 md:py-3", className)} {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TD({ className, ...props }: React.TdHTMLAttributes<HTMLTableCellElement>) {
|
export function TD({ className, ...props }: React.TdHTMLAttributes<HTMLTableCellElement>) {
|
||||||
return <td className={cn("px-4 py-3 align-middle", className)} {...props} />;
|
return <td className={cn("px-3 py-2.5 align-middle md:px-4 md:py-3", className)} {...props} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,19 @@ import type { Session } from "next-auth";
|
|||||||
/** 超级管理员角色名称(与数据库 Role.name 对应) */
|
/** 超级管理员角色名称(与数据库 Role.name 对应) */
|
||||||
export const SUPER_ADMIN = "super admin";
|
export const SUPER_ADMIN = "super admin";
|
||||||
|
|
||||||
|
/** 业务员角色名称(与数据库 Role.name 对应) */
|
||||||
|
export const STAFF = "staff";
|
||||||
|
|
||||||
/** 判断是否为超级管理员(基于 session.user.roles) */
|
/** 判断是否为超级管理员(基于 session.user.roles) */
|
||||||
export function isSuperAdmin(roles?: string[] | null): boolean {
|
export function isSuperAdmin(roles?: string[] | null): boolean {
|
||||||
return !!roles?.includes(SUPER_ADMIN);
|
return !!roles?.includes(SUPER_ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 判断是否为业务员(基于 session.user.roles) */
|
||||||
|
export function isStaff(roles?: string[] | null): boolean {
|
||||||
|
return !!roles?.includes(STAFF);
|
||||||
|
}
|
||||||
|
|
||||||
/** 从 Session 提取 roles 并判断(便捷版) */
|
/** 从 Session 提取 roles 并判断(便捷版) */
|
||||||
export function sessionIsSuperAdmin(session: Session | null): boolean {
|
export function sessionIsSuperAdmin(session: Session | null): boolean {
|
||||||
return isSuperAdmin(session?.user?.roles);
|
return isSuperAdmin(session?.user?.roles);
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import type { NextAuthConfig, DefaultSession } from "next-auth";
|
import type { NextAuthConfig, DefaultSession } from "next-auth";
|
||||||
|
|
||||||
|
// 本地 `next dev` 忽略 .env 里的生产 AUTH_URL,避免 localhost 被跳到公网机。
|
||||||
|
if (process.env.NODE_ENV === "development") {
|
||||||
|
delete process.env.AUTH_URL;
|
||||||
|
}
|
||||||
|
|
||||||
// Edge 安全的基础配置:不引入 Prisma / bcrypt,供 middleware 使用。
|
// Edge 安全的基础配置:不引入 Prisma / bcrypt,供 middleware 使用。
|
||||||
// 真正带数据库校验的 Credentials provider 在 auth.ts 里注入。
|
// 真正带数据库校验的 Credentials provider 在 auth.ts 里注入。
|
||||||
|
|
||||||
|
|||||||
+19
-1
@@ -1,4 +1,4 @@
|
|||||||
import { Solar } from "lunar-typescript";
|
import { Lunar, Solar } from "lunar-typescript";
|
||||||
|
|
||||||
function pad2(n: number): string {
|
function pad2(n: number): string {
|
||||||
return String(Math.abs(n)).padStart(2, "0");
|
return String(Math.abs(n)).padStart(2, "0");
|
||||||
@@ -39,3 +39,21 @@ export function birthdayMatchLists(
|
|||||||
|
|
||||||
return { solar: [...solar], lunar: [...lunar] };
|
return { solar: [...solar], lunar: [...lunar] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 历史阴历生日存的是农历月日(年份占位)。换成今年对应的公历日期,供提醒页对照。
|
||||||
|
* 闰月等无法换算时返回 null,不猜日期。
|
||||||
|
*/
|
||||||
|
export function lunarBirthdaySolarThisYear(
|
||||||
|
isoDate: string,
|
||||||
|
year = new Date().getFullYear()
|
||||||
|
): string | null {
|
||||||
|
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(isoDate);
|
||||||
|
if (!m) return null;
|
||||||
|
try {
|
||||||
|
const solar = Lunar.fromYmd(year, Number(m[2]), Number(m[3])).getSolar();
|
||||||
|
return `${solar.getYear()}-${pad2(solar.getMonth())}-${pad2(solar.getDay())}`;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user