index.tsx 5.22 KB
// 工作台 = 欢迎页。
// 业务概览(KPI / 趋势 / 分布)暂无规划,故不做任何假数据看板:
// 只保留「问候 + 账号信息 + 真实快捷入口 + 账号安全入口」,入口全部按当前权限过滤。
import { useNavigate } from 'react-router-dom';
import {
  UploadOutlined,
  AuditOutlined,
  ShopOutlined,
  TeamOutlined,
  UserOutlined,
  ArrowRightOutlined,
  SafetyOutlined,
} from '@ant-design/icons';
import type { ReactNode } from 'react';
import { UCard, UButton, UText } from '@uj/ui';
import { useAppStore } from '@/store/useAppStore';
import { useAccess, roleLabels, type ResourceKey } from '@/access';

/** 按时段给问候语 */
function greeting(): string {
  const h = new Date().getHours();
  if (h < 6) return '凌晨好';
  if (h < 12) return '上午好';
  if (h < 14) return '中午好';
  if (h < 18) return '下午好';
  return '晚上好';
}

interface QuickLink {
  path: string;
  label: string;
  desc: string;
  icon: ReactNode;
  resource: ResourceKey;
}

// 快捷入口:与后端菜单一一对应,展示与否由当前账号权限决定(can)
const QUICK_LINKS: QuickLink[] = [
  {
    path: '/store/import',
    label: '导入门店信息',
    desc: '下载模板、上传并校验,确认后提交审批',
    icon: <UploadOutlined />,
    resource: 'store:import',
  },
  {
    path: '/store/approval',
    label: '门店审批',
    desc: '审核待上架门店,通过或打回',
    icon: <AuditOutlined />,
    resource: 'store:approve',
  },
  {
    path: '/store/listing',
    label: '门店列表',
    desc: '查看、筛选与维护已上架门店',
    icon: <ShopOutlined />,
    resource: 'store:list',
  },
  {
    path: '/system/role',
    label: '角色管理',
    desc: '配置角色权限与菜单可见范围',
    icon: <TeamOutlined />,
    resource: 'system:role',
  },
  {
    path: '/system/user',
    label: '账号管理',
    desc: '维护系统账号、重置密码与启停',
    icon: <UserOutlined />,
    resource: 'system:user',
  },
];

export default function Dashboard() {
  const navigate = useNavigate();
  const { currentUser } = useAppStore();
  const { can, role, roleCodes } = useAccess();

  const dateText = new Date().toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    weekday: 'long',
  });
  const roleText = roleCodes.length ? roleCodes.join(' / ') : roleLabels[role];
  const links = QUICK_LINKS.filter((l) => can(l.resource));

  return (
    <div className="uj-dash">
      {/* 品牌欢迎条:浅色卡片 + 品牌色点睛(不再大面积铺深色,避免压抑) */}
      <div className="uj-dash-hero">
        <div className="uj-dash-hero-id">
          <div className="uj-dash-hero-brand">
            <span className="uj-dash-hero-mark" />
            STORE LAUNCH PLATFORM
          </div>
          <h1 className="uj-dash-hero-title">
            {greeting()},{currentUser.name || '欢迎回来'}
          </h1>
          <p className="uj-dash-hero-sub">{dateText} · 欢迎回到优加门店上架系统</p>
        </div>
        <div className="uj-dash-hero-meta">
          <div className="uj-dash-meta-item">
            <span className="uj-dash-meta-label">账号</span>
            <span className="uj-dash-meta-value">{currentUser.account || '-'}</span>
          </div>
          <div className="uj-dash-meta-item">
            <span className="uj-dash-meta-label">角色</span>
            <span className="uj-dash-meta-value">{roleText}</span>
          </div>
        </div>
      </div>

      {/* 快捷入口:按权限过滤,无权限的不出现 */}
      <div>
        <div className="uj-welcome-title">快捷开始</div>
        {links.length ? (
          <div className="uj-welcome-quick">
            {links.map((l) => (
              <UCard
                key={l.path}
                hoverable
                className="uj-quick-card"
                onClick={() => navigate(l.path)}
                styles={{ body: { padding: 18 } }}
              >
                <div className="uj-quick-icon">{l.icon}</div>
                <div className="uj-quick-label">{l.label}</div>
                <div className="uj-quick-desc">{l.desc}</div>
                <div className="uj-quick-go">
                  进入 <ArrowRightOutlined />
                </div>
              </UCard>
            ))}
          </div>
        ) : (
          <UCard styles={{ body: { padding: 20 } }}>
            <UText type="secondary">暂无可用功能,请联系管理员分配权限。</UText>
          </UCard>
        )}
      </div>

      {/* 账号与安全 */}
      <UCard styles={{ body: { padding: '14px 18px' } }}>
        <div className="uj-welcome-sec">
          <div className="uj-welcome-sec-icon">
            <SafetyOutlined />
          </div>
          <div style={{ flex: 1, minWidth: 0 }}>
            <div style={{ fontSize: 14, fontWeight: 600, color: '#1D2533' }}>账号与安全</div>
            <UText type="secondary" style={{ fontSize: 12 }}>
              建议定期更新密码;如使用初始密码登录,请尽快修改。
            </UText>
          </div>
          <UButton onClick={() => navigate('/profile')}>前往修改</UButton>
        </div>
      </UCard>
    </div>
  );
}