feat(customers): 业务员角色查看弹窗展示明文手机号(列表仍脱敏)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import Link from "next/link";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { isSuperAdmin } from "@/lib/acl";
|
||||
import { isStaff, isSuperAdmin } from "@/lib/acl";
|
||||
import { fmtDate, maskPhone } from "@/lib/utils";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Table, THead, TR, TH, TD } from "@/components/ui/table";
|
||||
@@ -28,6 +28,8 @@ export default async function CustomersPage({
|
||||
}) {
|
||||
const session = await auth();
|
||||
const superAdmin = isSuperAdmin(session?.user?.roles);
|
||||
// 查看弹窗:业务员角色也展示明文手机号(列表仍脱敏)
|
||||
const viewFullPhone = superAdmin || isStaff(session?.user?.roles);
|
||||
const sp = await searchParams;
|
||||
const keyword = (sp.keyword ?? "").trim();
|
||||
const page = Math.max(1, Number(sp.page) || 1);
|
||||
@@ -123,12 +125,12 @@ export default async function CustomersPage({
|
||||
<TD className="max-w-[280px] whitespace-normal break-words">{c.remark}</TD>
|
||||
<TD>
|
||||
<div className="flex justify-end gap-1.5">
|
||||
{/* 弹窗展示用的手机号在服务端预脱敏,业务员拿不到明文 */}
|
||||
{/* 弹窗展示用的手机号在服务端预处理:超管和业务员看明文,其余角色脱敏 */}
|
||||
<CustomerView
|
||||
customer={{
|
||||
...rest,
|
||||
contactsPhone: superAdmin ? c.contactsPhone : maskPhone(c.contactsPhone),
|
||||
balanceUserPhone: superAdmin ? c.balanceUserPhone : maskPhone(c.balanceUserPhone),
|
||||
contactsPhone: viewFullPhone ? c.contactsPhone : maskPhone(c.contactsPhone),
|
||||
balanceUserPhone: viewFullPhone ? c.balanceUserPhone : maskPhone(c.balanceUserPhone),
|
||||
}}
|
||||
/>
|
||||
<Link href={`/customers/${c.id}/edit`}>
|
||||
|
||||
@@ -3,11 +3,19 @@ import type { Session } from "next-auth";
|
||||
/** 超级管理员角色名称(与数据库 Role.name 对应) */
|
||||
export const SUPER_ADMIN = "super admin";
|
||||
|
||||
/** 业务员角色名称(与数据库 Role.name 对应) */
|
||||
export const STAFF = "staff";
|
||||
|
||||
/** 判断是否为超级管理员(基于 session.user.roles) */
|
||||
export function isSuperAdmin(roles?: string[] | null): boolean {
|
||||
return !!roles?.includes(SUPER_ADMIN);
|
||||
}
|
||||
|
||||
/** 判断是否为业务员(基于 session.user.roles) */
|
||||
export function isStaff(roles?: string[] | null): boolean {
|
||||
return !!roles?.includes(STAFF);
|
||||
}
|
||||
|
||||
/** 从 Session 提取 roles 并判断(便捷版) */
|
||||
export function sessionIsSuperAdmin(session: Session | null): boolean {
|
||||
return isSuperAdmin(session?.user?.roles);
|
||||
|
||||
Reference in New Issue
Block a user