feat(ui): 适配手机端布局与触控交互
窄屏改用抽屉导航和卡片列表,加大触控区域并处理安全区,避免表格横向溢出。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Generated
+1
@@ -7,6 +7,7 @@
|
||||
"": {
|
||||
"name": "crm-new",
|
||||
"version": "0.1.0",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@prisma/client": "^6.11.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
|
||||
@@ -22,17 +22,19 @@ export function BirthdayControl({
|
||||
}
|
||||
|
||||
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">
|
||||
<button
|
||||
type="button"
|
||||
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
|
||||
type="button"
|
||||
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 天
|
||||
</button>
|
||||
@@ -41,7 +43,7 @@ export function BirthdayControl({
|
||||
type="date"
|
||||
defaultValue={date}
|
||||
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)]">
|
||||
(不填默认今天)
|
||||
|
||||
@@ -76,14 +76,14 @@ export default async function BirthdayPage({
|
||||
|
||||
return (
|
||||
<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} />
|
||||
<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> 位商户
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card className="overflow-hidden">
|
||||
<Card className="hidden overflow-hidden md:block">
|
||||
<Table>
|
||||
<THead>
|
||||
<tr>
|
||||
@@ -131,6 +131,50 @@ export default async function BirthdayPage({
|
||||
</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((c) => {
|
||||
const ownerName = c.birthdayOwner === 1 ? c.balanceUser : c.contacts;
|
||||
const ownerPhone =
|
||||
(c.birthdayOwner === 1 ? c.balanceUserPhone : c.contactsPhone) || c.phone;
|
||||
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>
|
||||
<div className="mt-1 text-xs text-[var(--color-muted-foreground)]">
|
||||
{c.salesman || "—"}
|
||||
</div>
|
||||
</div>
|
||||
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="shrink-0">
|
||||
{c.birthdayType === 2 ? "农历" : "阳历"}
|
||||
</Badge>
|
||||
</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>{ownerName || "—"}</dd>
|
||||
<dd className="text-xs tabular-nums text-[var(--color-muted-foreground)]">
|
||||
{superAdmin ? ownerPhone : maskPhone(ownerPhone)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="text-xs text-[var(--color-muted-foreground)]">生日</dt>
|
||||
<dd className="tabular-nums">{fmtDate(c.birthday)}</dd>
|
||||
<dd className="text-xs text-[var(--color-muted-foreground)]">
|
||||
{c.birthdayOwner === 1 ? "结算人" : "联系人"}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ export function CustomerForm({
|
||||
</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 ? "保存中…" : submitLabel}
|
||||
</Button>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useRef, useState, useTransition } from "react";
|
||||
import { useRef, useTransition } from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Plus, Upload, Download, Search, RotateCcw } from "lucide-react";
|
||||
@@ -78,50 +78,54 @@ export function CustomerToolbar({
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="flex flex-wrap items-center justify-between gap-3 p-3">
|
||||
<form onSubmit={onSearch} className="flex flex-wrap items-center gap-2">
|
||||
<div className="relative">
|
||||
<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 w-full min-w-0 flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center md:w-auto">
|
||||
<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)]" />
|
||||
<Input
|
||||
name="keyword"
|
||||
placeholder="商户 / 联系人 / 联系电话 / 业务员"
|
||||
defaultValue={defaultKeyword}
|
||||
className="w-64 pl-8"
|
||||
className="w-full pl-8 sm:w-64"
|
||||
/>
|
||||
</div>
|
||||
<Input name="start" type="date" defaultValue={defaultStart} className="w-[150px]" />
|
||||
<span className="text-[var(--color-muted-foreground)]">~</span>
|
||||
<Input name="end" type="date" defaultValue={defaultEnd} className="w-[150px]" />
|
||||
<Button type="submit" variant="soft" disabled={pending}>
|
||||
查询
|
||||
</Button>
|
||||
<Button type="button" variant="ghost" size="icon" title="重置" onClick={() => router.push("/customers")}>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
</Button>
|
||||
<div className="flex min-w-0 flex-col gap-2 sm:flex-row sm:items-center">
|
||||
<Input name="start" type="date" defaultValue={defaultStart} className="w-full sm:w-[150px]" />
|
||||
<span className="hidden shrink-0 text-[var(--color-muted-foreground)] sm:inline">~</span>
|
||||
<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 type="button" variant="ghost" size="icon" title="重置" onClick={() => router.push("/customers")}>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</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} />
|
||||
<Button variant="outline" disabled={importing} onClick={() => fileRef.current?.click()}>
|
||||
<Upload className="h-4 w-4" />
|
||||
{importing ? "导入中…" : "导入"}
|
||||
</Button>
|
||||
<a href="/customers/template">
|
||||
<Button variant="outline">
|
||||
<a href="/customers/template" className="contents sm:block">
|
||||
<Button variant="outline" className="w-full">
|
||||
<Download className="h-4 w-4" />
|
||||
下载模板
|
||||
</Button>
|
||||
</a>
|
||||
{canExport && (
|
||||
<a href={exportHref}>
|
||||
<Button variant="outline">
|
||||
<a href={exportHref} className="contents sm:block">
|
||||
<Button variant="outline" className="w-full">
|
||||
<Download className="h-4 w-4" />
|
||||
导出
|
||||
</Button>
|
||||
</a>
|
||||
)}
|
||||
<Link href="/customers/new">
|
||||
<Button>
|
||||
<Link href="/customers/new" className="col-span-2 sm:col-span-1">
|
||||
<Button className="w-full">
|
||||
<Plus className="h-4 w-4" />
|
||||
新增商户
|
||||
</Button>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useEffect, useState, type ReactNode } from "react";
|
||||
import { Eye, X } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { fmtDate } from "@/lib/utils";
|
||||
import { fmtDate, cn } from "@/lib/utils";
|
||||
|
||||
type CustomerViewProps = {
|
||||
customer: {
|
||||
@@ -35,7 +35,12 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
||||
if (e.key === "Escape") setOpen(false);
|
||||
};
|
||||
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]);
|
||||
|
||||
const birthdayLabel = customer.birthdayType === 2 ? "阴历" : "阳历";
|
||||
@@ -56,11 +61,11 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
||||
|
||||
{open && (
|
||||
<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)}
|
||||
>
|
||||
<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()}
|
||||
>
|
||||
<CardHeader>
|
||||
@@ -69,7 +74,7 @@ export function CustomerView({ customer }: CustomerViewProps) {
|
||||
<button
|
||||
type="button"
|
||||
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="关闭"
|
||||
>
|
||||
<X className="h-5 w-5" />
|
||||
@@ -147,8 +152,8 @@ function InfoRow({
|
||||
if (!value) return null;
|
||||
return (
|
||||
<div className="flex gap-3 text-sm">
|
||||
<span className="w-24 text-[var(--color-muted-foreground)] flex-shrink-0">{label}</span>
|
||||
<span className={className}>{value}</span>
|
||||
<span className="w-20 shrink-0 text-[var(--color-muted-foreground)] sm:w-24">{label}</span>
|
||||
<span className={cn("min-w-0 break-words", className)}>{value}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export default async function CustomersPage({
|
||||
canExport={superAdmin}
|
||||
/>
|
||||
|
||||
<Card className="overflow-hidden">
|
||||
<Card className="hidden overflow-hidden md:block">
|
||||
<Table striped bordered>
|
||||
<THead>
|
||||
<tr>
|
||||
@@ -124,7 +124,7 @@ export default async function CustomersPage({
|
||||
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
|
||||
<TD className="max-w-[280px] whitespace-normal break-words">{c.remark}</TD>
|
||||
<TD>
|
||||
<div className="flex justify-end gap-1.5">
|
||||
<div className="flex flex-wrap justify-end gap-1.5">
|
||||
{/* 弹窗展示用的手机号在服务端预处理:超管和业务员看明文,其余角色脱敏 */}
|
||||
<CustomerView
|
||||
customer={{
|
||||
@@ -146,8 +146,72 @@ export default async function CustomersPage({
|
||||
</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((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>
|
||||
<div className="mt-1 text-xs text-[var(--color-muted-foreground)]">
|
||||
{c.salesman}
|
||||
{c.reportDate ? ` · ${fmtDate(c.reportDate)}` : ""}
|
||||
</div>
|
||||
</div>
|
||||
{c.birthday && (
|
||||
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="shrink-0">
|
||||
{c.birthdayType === 2 ? "农历" : "阳历"} {fmtDate(c.birthday)}
|
||||
</Badge>
|
||||
)}
|
||||
</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>
|
||||
<div className="flex items-center gap-2">
|
||||
<PageLink page={page - 1} disabled={page <= 1} sp={sp} label="上一页" />
|
||||
@@ -172,7 +236,7 @@ function PageLink({
|
||||
}) {
|
||||
if (disabled) {
|
||||
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();
|
||||
@@ -183,7 +247,7 @@ function PageLink({
|
||||
return (
|
||||
<Link
|
||||
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}
|
||||
</Link>
|
||||
|
||||
@@ -18,7 +18,7 @@ export default async function DashboardLayout({
|
||||
|
||||
return (
|
||||
<SidebarProvider>
|
||||
<div className="flex h-screen overflow-hidden">
|
||||
<div className="flex h-dvh overflow-hidden overscroll-none">
|
||||
<Sidebar isSuperAdmin={superAdmin} />
|
||||
<div className="flex min-w-0 flex-1 flex-col">
|
||||
<Topbar
|
||||
@@ -29,9 +29,9 @@ export default async function DashboardLayout({
|
||||
image: null, // 旧 face 为老站点相对路径,统一用文字头像
|
||||
}}
|
||||
/>
|
||||
<main className="flex-1 overflow-y-auto">
|
||||
<div className="p-6">{children}</div>
|
||||
<footer className="flex items-center justify-between border-t px-6 py-4 text-xs text-[var(--color-muted-foreground)]">
|
||||
<main className="flex-1 overflow-y-auto overflow-x-hidden overscroll-y-contain">
|
||||
<div className="p-4 md:p-6">{children}</div>
|
||||
<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>{brand.name} · {brand.tagline}</span>
|
||||
</footer>
|
||||
|
||||
@@ -27,7 +27,7 @@ export function ProfileForm({ nickname, username }: { nickname: string; username
|
||||
<Label htmlFor="nickname">昵称</Label>
|
||||
<Input id="nickname" name="nickname" defaultValue={nickname} />
|
||||
</div>
|
||||
<Button type="submit" disabled={pending}>{pending ? "保存中…" : "保存资料"}</Button>
|
||||
<Button type="submit" disabled={pending} className="w-full sm:w-auto">{pending ? "保存中…" : "保存资料"}</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ export function PasswordForm() {
|
||||
<Label htmlFor="confirmPassword">确认新密码</Label>
|
||||
<Input id="confirmPassword" name="confirmPassword" type="password" autoComplete="new-password" />
|
||||
</div>
|
||||
<Button type="submit" disabled={pending}>{pending ? "提交中…" : "修改密码"}</Button>
|
||||
<Button type="submit" disabled={pending} className="w-full sm:w-auto">{pending ? "提交中…" : "修改密码"}</Button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ export default async function MePage() {
|
||||
<Card>
|
||||
<CardContent className="flex items-center gap-4">
|
||||
<Avatar name={admin.nickname} size={56} />
|
||||
<div>
|
||||
<div className="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="min-w-0">
|
||||
<div className="truncate text-lg font-semibold">{admin.nickname}</div>
|
||||
<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>
|
||||
<Badge tone="primary">{roleLabel}</Badge>
|
||||
</div>
|
||||
|
||||
@@ -80,21 +80,21 @@ export default async function DashboardPage() {
|
||||
return (
|
||||
<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) => {
|
||||
const Icon = s.icon;
|
||||
return (
|
||||
<Card key={s.label}>
|
||||
<CardContent className="flex items-center gap-4">
|
||||
<CardContent className="flex items-center gap-2.5 md:gap-4">
|
||||
<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] }}
|
||||
>
|
||||
<Icon className="h-6 w-6" />
|
||||
<Icon className="h-5 w-5 md:h-6 md:w-6" />
|
||||
</span>
|
||||
<div>
|
||||
<div className="text-sm text-[var(--color-muted-foreground)]">{s.label}</div>
|
||||
<div className="mt-0.5 text-2xl font-semibold tabular-nums">{s.value}</div>
|
||||
<div className="min-w-0">
|
||||
<div className="text-xs text-[var(--color-muted-foreground)] md:text-sm">{s.label}</div>
|
||||
<div className="mt-0.5 text-xl font-semibold tabular-nums md:text-2xl">{s.value}</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -121,40 +121,70 @@ export default async function DashboardPage() {
|
||||
<CardTitle>最近报单商户</CardTitle>
|
||||
<Link
|
||||
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" />
|
||||
</Link>
|
||||
</CardHeader>
|
||||
<Table>
|
||||
<THead>
|
||||
<tr>
|
||||
<TH>商户名称</TH>
|
||||
<TH>联系人</TH>
|
||||
<TH>业务员</TH>
|
||||
<TH>报单时间</TH>
|
||||
<TH>生日</TH>
|
||||
</tr>
|
||||
</THead>
|
||||
<tbody>
|
||||
{recent.map((c) => (
|
||||
<TR key={c.id}>
|
||||
<TD className="font-medium">{c.customerName}</TD>
|
||||
<TD>{c.contacts}</TD>
|
||||
<TD>{c.salesman}</TD>
|
||||
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
|
||||
<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>
|
||||
))}
|
||||
</tbody>
|
||||
</Table>
|
||||
<div className="hidden md:block">
|
||||
<Table>
|
||||
<THead>
|
||||
<tr>
|
||||
<TH>商户名称</TH>
|
||||
<TH>联系人</TH>
|
||||
<TH>业务员</TH>
|
||||
<TH>报单时间</TH>
|
||||
<TH>生日</TH>
|
||||
</tr>
|
||||
</THead>
|
||||
<tbody>
|
||||
{recent.map((c) => (
|
||||
<TR key={c.id}>
|
||||
<TD className="font-medium">{c.customerName}</TD>
|
||||
<TD>{c.contacts}</TD>
|
||||
<TD>{c.salesman}</TD>
|
||||
<TD className="tabular-nums">{fmtDate(c.reportDate)}</TD>
|
||||
<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>
|
||||
))}
|
||||
</tbody>
|
||||
</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>
|
||||
<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 && (
|
||||
<Badge tone={c.birthdayType === 2 ? "warning" : "info"} className="mt-1">
|
||||
{c.birthdayType === 2 ? "农历" : "阳历"} {fmtDate(c.birthday)}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -61,7 +61,7 @@ export function AdminForm({
|
||||
</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>
|
||||
|
||||
@@ -26,12 +26,12 @@ export default async function AdminsPage() {
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex justify-end">
|
||||
<Link href="/rbac/admins/new">
|
||||
<Button><Plus className="h-4 w-4" />新增管理员</Button>
|
||||
<div className="flex">
|
||||
<Link href="/rbac/admins/new" className="w-full sm:ml-auto sm:w-auto">
|
||||
<Button className="w-full"><Plus className="h-4 w-4" />新增管理员</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<Card className="overflow-hidden">
|
||||
<Card className="hidden overflow-hidden md:block">
|
||||
<Table>
|
||||
<THead>
|
||||
<tr>
|
||||
@@ -75,6 +75,39 @@ export default async function AdminsPage() {
|
||||
</tbody>
|
||||
</Table>
|
||||
</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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ export default async function PermissionsPage() {
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex justify-end">
|
||||
<Link href="/rbac/permissions/new">
|
||||
<Button><Plus className="h-4 w-4" />新增权限</Button>
|
||||
<div className="flex">
|
||||
<Link href="/rbac/permissions/new" className="w-full sm:ml-auto sm:w-auto">
|
||||
<Button className="w-full"><Plus className="h-4 w-4" />新增权限</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<Card className="overflow-hidden">
|
||||
<Card className="hidden overflow-hidden md:block">
|
||||
<Table>
|
||||
<THead>
|
||||
<tr>
|
||||
@@ -85,6 +85,26 @@ export default async function PermissionsPage() {
|
||||
</tbody>
|
||||
</Table>
|
||||
</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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export function PermissionForm({
|
||||
const v = defaultValues ?? {};
|
||||
return (
|
||||
<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">
|
||||
<Label htmlFor="title">权限名称<span className="ml-0.5 text-[var(--color-danger)]">*</span></Label>
|
||||
<Input id="title" name="title" defaultValue={v.title} placeholder="如:商户列表" />
|
||||
@@ -53,12 +53,12 @@ export function PermissionForm({
|
||||
<Label htmlFor="sort">排序</Label>
|
||||
<Input id="sort" name="sort" type="number" defaultValue={String(v.sort ?? 0)} />
|
||||
</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
|
||||
type="checkbox"
|
||||
name="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>
|
||||
</label>
|
||||
@@ -68,7 +68,7 @@ export function PermissionForm({
|
||||
{state.error}
|
||||
</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>
|
||||
<Link href="/rbac/permissions"><Button type="button" variant="outline">取消</Button></Link>
|
||||
</div>
|
||||
|
||||
@@ -52,17 +52,21 @@ export function AssignPermissions({
|
||||
const renderNode = (node: PermNode, depth: number) => (
|
||||
<div key={node.id}>
|
||||
<label
|
||||
className="flex items-center gap-2.5 rounded-md px-2 py-1.5 hover:bg-[var(--color-muted)]"
|
||||
style={{ paddingLeft: depth * 20 + 8 }}
|
||||
className="flex min-h-11 items-center gap-2.5 rounded-md py-2 pr-2 hover:bg-[var(--color-muted)]"
|
||||
style={{ paddingLeft: 8 + depth * 14 }}
|
||||
>
|
||||
<input
|
||||
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)}
|
||||
onChange={(e) => toggle(node, e.target.checked)}
|
||||
/>
|
||||
<span className="text-sm">{node.title}</span>
|
||||
<span className="text-xs text-[var(--color-muted-foreground)]">{node.name}</span>
|
||||
<span className="min-w-0">
|
||||
<span className="text-sm">{node.title}</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>
|
||||
{node.children.map((c) => renderNode(c, depth + 1))}
|
||||
</div>
|
||||
@@ -73,8 +77,8 @@ export function AssignPermissions({
|
||||
<div className="rounded-[var(--radius)] border p-2">
|
||||
{tree.map((n) => renderNode(n, 0))}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button onClick={save} disabled={pending}>
|
||||
<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} className="flex-1 sm:flex-none">
|
||||
{pending ? "保存中…" : `保存(已选 ${checked.size} 项)`}
|
||||
</Button>
|
||||
<Link href="/rbac/roles"><Button variant="outline">取消</Button></Link>
|
||||
|
||||
@@ -18,12 +18,12 @@ export default async function RolesPage() {
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex justify-end">
|
||||
<Link href="/rbac/roles/new">
|
||||
<Button><Plus className="h-4 w-4" />新增角色</Button>
|
||||
<div className="flex">
|
||||
<Link href="/rbac/roles/new" className="w-full sm:ml-auto sm:w-auto">
|
||||
<Button className="w-full"><Plus className="h-4 w-4" />新增角色</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<Card className="overflow-hidden">
|
||||
<Card className="hidden overflow-hidden md:block">
|
||||
<Table>
|
||||
<THead>
|
||||
<tr>
|
||||
@@ -62,6 +62,35 @@ export default async function RolesPage() {
|
||||
</tbody>
|
||||
</Table>
|
||||
</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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export function RoleForm({
|
||||
{state.error}
|
||||
</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>
|
||||
<Link href="/rbac/roles"><Button type="button" variant="outline">取消</Button></Link>
|
||||
</div>
|
||||
|
||||
@@ -17,20 +17,21 @@ export function MonthlyReportChart({ data }: { data: MonthPoint[] }) {
|
||||
const max = Math.max(1, ...data.map((d) => d.count));
|
||||
|
||||
return (
|
||||
<div className="h-72 w-full">
|
||||
<div className="h-52 w-full md:h-72">
|
||||
<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} />
|
||||
<XAxis
|
||||
dataKey="label"
|
||||
tick={{ fontSize: 12, fill: "#64748b" }}
|
||||
tick={{ fontSize: 10, fill: "#64748b" }}
|
||||
tickLine={false}
|
||||
axisLine={{ stroke: "#e8eaed" }}
|
||||
interval="preserveStartEnd"
|
||||
/>
|
||||
<YAxis
|
||||
allowDecimals={false}
|
||||
width={40}
|
||||
tick={{ fontSize: 12, fill: "#64748b" }}
|
||||
width={32}
|
||||
tick={{ fontSize: 11, fill: "#64748b" }}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
/>
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
@@ -52,6 +54,16 @@ body {
|
||||
color: var(--color-foreground);
|
||||
font-family: var(--font-sans);
|
||||
-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 { brand } from "@/lib/brand";
|
||||
import "./globals.css";
|
||||
@@ -8,6 +8,13 @@ export const metadata: Metadata = {
|
||||
description: `${brand.company} ${brand.tagline}`,
|
||||
};
|
||||
|
||||
export const viewport: Viewport = {
|
||||
width: "device-width",
|
||||
initialScale: 1,
|
||||
viewportFit: "cover",
|
||||
themeColor: "#4f46e5",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{ children: React.ReactNode }>) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { LoginForm } from "./login-form";
|
||||
|
||||
export default function LoginPage() {
|
||||
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%)]" />
|
||||
<Suspense>
|
||||
|
||||
@@ -1,25 +1,61 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext, useState } from "react";
|
||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
||||
|
||||
type SidebarCtx = {
|
||||
collapsed: boolean;
|
||||
toggle: () => void;
|
||||
setCollapsed: (v: boolean) => void;
|
||||
mobileOpen: boolean;
|
||||
openMobile: () => void;
|
||||
closeMobile: () => void;
|
||||
toggleMobile: () => void;
|
||||
};
|
||||
|
||||
const Ctx = createContext<SidebarCtx | null>(null);
|
||||
|
||||
/** 折叠状态提供者:包裹侧边栏 + 主区,供二者共享 collapsed */
|
||||
/** 折叠状态提供者:包裹侧边栏 + 主区,供二者共享 collapsed / 手机抽屉 */
|
||||
export function SidebarProvider({ children }: { children: React.ReactNode }) {
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
return (
|
||||
<Ctx.Provider
|
||||
value={{ collapsed, toggle: () => setCollapsed((v) => !v), setCollapsed }}
|
||||
>
|
||||
{children}
|
||||
</Ctx.Provider>
|
||||
const [mobileOpen, setMobileOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const mq = window.matchMedia("(min-width: 768px)");
|
||||
const onChange = () => {
|
||||
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() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { cn } from "@/lib/utils";
|
||||
@@ -11,60 +12,76 @@ import { useSidebar } from "./sidebar-context";
|
||||
export function Sidebar({ isSuperAdmin }: { isSuperAdmin: boolean }) {
|
||||
const pathname = usePathname();
|
||||
const active = activeHref(pathname);
|
||||
const { collapsed } = useSidebar();
|
||||
const { collapsed, mobileOpen, closeMobile } = useSidebar();
|
||||
const sections = navSections.filter((s) => !s.superAdminOnly || isSuperAdmin);
|
||||
|
||||
useEffect(() => {
|
||||
closeMobile();
|
||||
}, [pathname, closeMobile]);
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={cn(
|
||||
"shrink-0 overflow-hidden transition-[width] duration-200 ease-in-out",
|
||||
collapsed ? "w-0" : "w-60"
|
||||
<>
|
||||
{mobileOpen && (
|
||||
<button
|
||||
type="button"
|
||||
aria-label="关闭菜单"
|
||||
className="fixed inset-0 z-30 bg-black/40 md:hidden"
|
||||
onClick={closeMobile}
|
||||
/>
|
||||
)}
|
||||
>
|
||||
{/* 固定宽度内容容器:折叠时被外层裁剪,形成平滑滑动而非挤压 */}
|
||||
<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">
|
||||
<Link href="/">
|
||||
<BrandLogo size={36} invert />
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 space-y-6 overflow-y-auto px-3 py-4">
|
||||
{sections.map((section) => (
|
||||
<div key={section.title}>
|
||||
<div className="px-3 pb-2 text-[11px] font-medium uppercase tracking-wider text-[var(--color-sidebar-muted)]">
|
||||
{section.title}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
{section.items.map((item) => {
|
||||
const Icon = item.icon;
|
||||
const isActive = active === item.href;
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={cn(
|
||||
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm transition-colors",
|
||||
isActive
|
||||
? "bg-[var(--color-primary)] text-white shadow-sm"
|
||||
: "text-[var(--color-sidebar-muted)] hover:bg-[var(--color-sidebar-hover)] hover:text-white"
|
||||
)}
|
||||
>
|
||||
<Icon className="h-[18px] w-[18px]" />
|
||||
{item.label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<aside
|
||||
className={cn(
|
||||
"z-40 overflow-hidden bg-[var(--color-sidebar)] text-[var(--color-sidebar-foreground)]",
|
||||
"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-16 items-center px-5">
|
||||
<Link href="/" onClick={closeMobile}>
|
||||
<BrandLogo size={36} invert />
|
||||
</Link>
|
||||
</div>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<div className="px-5 py-4 text-[11px] text-[var(--color-sidebar-muted)]">
|
||||
{copyright()}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
<nav className="flex-1 space-y-6 overflow-y-auto overscroll-contain px-3 py-4">
|
||||
{sections.map((section) => (
|
||||
<div key={section.title}>
|
||||
<div className="px-3 pb-2 text-[11px] font-medium uppercase tracking-wider text-[var(--color-sidebar-muted)]">
|
||||
{section.title}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
{section.items.map((item) => {
|
||||
const Icon = item.icon;
|
||||
const isActive = active === item.href;
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
onClick={closeMobile}
|
||||
className={cn(
|
||||
"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
|
||||
? "bg-[var(--color-primary)] text-white shadow-sm"
|
||||
: "text-[var(--color-sidebar-muted)] hover:bg-[var(--color-sidebar-hover)] hover:text-white"
|
||||
)}
|
||||
>
|
||||
<Icon className="h-[18px] w-[18px]" />
|
||||
{item.label}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<div className="px-5 py-4 text-[11px] text-[var(--color-sidebar-muted)]">
|
||||
{copyright()}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,36 +29,44 @@ export function Topbar({
|
||||
const pathname = usePathname();
|
||||
const [open, setOpen] = useState(false);
|
||||
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(() => {
|
||||
function onClick(e: MouseEvent) {
|
||||
function onClick(e: Event) {
|
||||
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
||||
}
|
||||
document.addEventListener("mousedown", onClick);
|
||||
return () => document.removeEventListener("mousedown", onClick);
|
||||
document.addEventListener("pointerdown", onClick);
|
||||
return () => document.removeEventListener("pointerdown", onClick);
|
||||
}, []);
|
||||
|
||||
const roleLabel = user.roles.includes("super admin") ? "超级管理员" : "业务员";
|
||||
|
||||
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">
|
||||
<div className="flex items-center gap-3">
|
||||
<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 min-w-0 items-center gap-2 md:gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggle}
|
||||
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)]"
|
||||
onClick={onMenu}
|
||||
aria-label="打开/关闭菜单"
|
||||
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]" />
|
||||
</button>
|
||||
<h1 className="text-base font-semibold">{pageTitle(pathname)}</h1>
|
||||
<h1 className="truncate text-base font-semibold">{pageTitle(pathname)}</h1>
|
||||
</div>
|
||||
|
||||
<div className="relative" ref={ref}>
|
||||
<button
|
||||
type="button"
|
||||
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} />
|
||||
<div className="hidden text-left leading-tight sm:block">
|
||||
@@ -73,7 +81,7 @@ export function Topbar({
|
||||
<Link
|
||||
href="/me"
|
||||
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" /> 个人中心
|
||||
</Link>
|
||||
@@ -85,7 +93,7 @@ export function Topbar({
|
||||
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" /> 退出登录
|
||||
</button>
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as React from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
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 = {
|
||||
primary:
|
||||
@@ -18,10 +18,10 @@ const variants = {
|
||||
} as const;
|
||||
|
||||
const sizes = {
|
||||
default: "h-9 px-4",
|
||||
sm: "h-8 px-3 text-[13px]",
|
||||
lg: "h-10 px-5",
|
||||
icon: "h-9 w-9",
|
||||
default: "h-11 px-4 md:h-9",
|
||||
sm: "h-9 px-3 text-[13px] md:h-8",
|
||||
lg: "h-12 px-5 md:h-10",
|
||||
icon: "h-11 w-11 md:h-9 md:w-9",
|
||||
} as const;
|
||||
|
||||
export interface ButtonProps
|
||||
|
||||
@@ -19,7 +19,7 @@ export function CardHeader({
|
||||
}: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return (
|
||||
<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}
|
||||
/>
|
||||
);
|
||||
@@ -29,12 +29,12 @@ export function CardTitle({
|
||||
className,
|
||||
...props
|
||||
}: 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({
|
||||
className,
|
||||
...props
|
||||
}: 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";
|
||||
|
||||
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<
|
||||
HTMLInputElement,
|
||||
|
||||
@@ -14,8 +14,8 @@ export function Table({
|
||||
return (
|
||||
<div className="w-full overflow-x-auto">
|
||||
<table
|
||||
className={cn(
|
||||
"w-full text-sm",
|
||||
className={cn(
|
||||
"w-full min-w-max text-sm",
|
||||
bordered &&
|
||||
"border border-[var(--color-border)] [&_tr]:divide-x [&_tr]:divide-[var(--color-border)]",
|
||||
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>) {
|
||||
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>) {
|
||||
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} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user