import type { ColumnDef } from '@tanstack/react-table' import { MenuIcon } from '@/components/menu-icon' import { menuTypeDict, statusDict, type MenuTypeValues, type StatusValues } from '@/enum' import { formatDate } from '@/lib' import type { SysMenuTree } from '@/schemas' import { RowActions } from './row-actions.tsx' export const createColumns = (): ColumnDef[] => { return [ { accessorKey: 'name', header: '菜单名称', meta: { className: 'min-w-36 max-w-36' }, cell: ({ row }) => (
{row.original.icon && ( )} {row.getValue('name')}
), }, { accessorKey: 'path', header: '菜单路径', meta: { className: ' max-w-36' }, cell: ({ row }) =>
{row.getValue('path')}
, }, { accessorKey: 'type', header: '菜单类型', meta: { className: 'max-w-20' }, cell: ({ row }) => { const menuType = menuTypeDict[row.getValue('type') as MenuTypeValues] return
{menuType}
}, }, { accessorKey: 'permission_code', header: '权限字符', meta: { className: ' max-w-36' }, cell: ({ row }) =>
{row.getValue('permission_code')}
, }, { accessorKey: 'status', header: '菜单状态', meta: { className: ' max-w-36' }, cell: ({ row }) => { const status = statusDict[row.getValue('status') as StatusValues] return
{status}
}, }, { accessorKey: 'hidden', header: '是否隐藏', meta: { className: ' max-w-36' }, cell: ({ row }) =>
{row.getValue('hidden') ? '是' : '否'}
, }, { accessorKey: 'sort', header: '菜单排序', meta: { className: ' max-w-36' }, cell: ({ row }) =>
{row.getValue('sort')}
, }, { accessorKey: 'created_at', header: '创建时间', meta: { className: ' max-w-36' }, cell: ({ row }) => { const rawDate = row.getValue('created_at') as string return
{formatDate(rawDate)}
}, }, { accessorKey: 'updated_at', header: '修改时间', meta: { className: ' max-w-36' }, cell: ({ row }) => { const rawDate = row.getValue('updated_at') as string return
{formatDate(rawDate)}
}, }, { id: 'actions', enableHiding: false, meta: { className: ' max-w-36 sticky right-0' }, cell: RowActions, }, ] }