feat: 联动支付 CRM 后台(Next.js + TS + Prisma 重构)
从旧 Laravel 5.7 重构为现代技术栈,对接现有 MySQL。 - 技术栈: Next.js 15 App Router + TypeScript + Prisma + Auth.js + Tailwind v4 - 认证: 复用旧库 admins 的 bcrypt 密码,Auth.js Credentials - 客户管理: 列表(搜索/报单区间/分页)、增改删、Excel 导入导出 - 生日提醒: 阴阳历(lunar-typescript),口径对齐旧 overtrue 库 - RBAC: 管理员/角色/权限(菜单树) 完整 CRUD + 分配 - 控制台: 统计卡 + 月度新增报单柱状图 - 个人中心: 改昵称/改密码 - 现代 CMS 界面 + 联动支付品牌(logo/登录/底部/icon) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useTransition } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Link from "next/link";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { assignPermissions } from "../../../actions";
|
||||
|
||||
export type PermNode = {
|
||||
id: number;
|
||||
title: string;
|
||||
name: string;
|
||||
children: PermNode[];
|
||||
};
|
||||
|
||||
export function AssignPermissions({
|
||||
roleId,
|
||||
tree,
|
||||
checkedIds,
|
||||
}: {
|
||||
roleId: number;
|
||||
tree: PermNode[];
|
||||
checkedIds: number[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [checked, setChecked] = useState<Set<number>>(new Set(checkedIds));
|
||||
const [pending, start] = useTransition();
|
||||
|
||||
function toggle(node: PermNode, on: boolean) {
|
||||
const next = new Set(checked);
|
||||
const walk = (n: PermNode) => {
|
||||
if (on) next.add(n.id);
|
||||
else next.delete(n.id);
|
||||
n.children.forEach(walk);
|
||||
};
|
||||
walk(node);
|
||||
setChecked(next);
|
||||
}
|
||||
|
||||
function save() {
|
||||
start(async () => {
|
||||
const res = await assignPermissions(roleId, [...checked]);
|
||||
if (res.ok) {
|
||||
toast.success("权限已保存");
|
||||
router.push("/rbac/roles");
|
||||
router.refresh();
|
||||
} else toast.error(res.error ?? "保存失败");
|
||||
});
|
||||
}
|
||||
|
||||
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 }}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
className="h-4 w-4 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>
|
||||
</label>
|
||||
{node.children.map((c) => renderNode(c, depth + 1))}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<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}>
|
||||
{pending ? "保存中…" : `保存(已选 ${checked.size} 项)`}
|
||||
</Button>
|
||||
<Link href="/rbac/roles"><Button variant="outline">取消</Button></Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user