columns.tsx
2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import type { ColumnsType } from 'antd/es/table';
import { UButton, UTag } from '@uj/ui';
import { P, Perm } from '@/access';
import type { ListingPageParams, StoreListingRow } from '@/api';
import type { StoreDictionaries } from '@/features/store/dictionaries';
import { dictionaryLabel, formatDateTime } from '@/features/store/formatters';
import { COLUMN_LABELS, type ListingColumn } from '../tools/listing';
export function buildColumns({
visible,
params,
spec,
onDetail,
onHistory,
}: {
visible: ListingColumn[];
params: ListingPageParams;
spec?: StoreDictionaries;
onDetail: (row: StoreListingRow) => void;
onHistory: (row: StoreListingRow) => void;
}): ColumnsType<StoreListingRow> {
const sortOrder = params.sortOrder === 'asc' ? 'ascend' : 'descend';
const definitions: Record<ListingColumn, ColumnsType<StoreListingRow>[number]> = {
storeName: {
title: COLUMN_LABELS.storeName,
dataIndex: 'storeName',
key: 'storeName',
width: 230,
fixed: 'left',
render: (value: string, row) => (
<UButton type="link" className="store-listing-name" onClick={() => onDetail(row)}>
{value || '—'}
</UButton>
),
},
merchantNo: {
title: COLUMN_LABELS.merchantNo,
dataIndex: 'merchantNo',
key: 'merchantNo',
width: 170,
render: (value: string) => <span className="store-code">{value || '—'}</span>,
},
businessScene: {
title: COLUMN_LABELS.businessScene,
dataIndex: 'businessScene',
key: 'businessScene',
width: 210,
render: (value: string) => (
<UTag color="blue">{dictionaryLabel(spec?.businessScenes, value)}</UTag>
),
},
effectiveTime: {
title: COLUMN_LABELS.effectiveTime,
dataIndex: 'effectiveTime',
key: 'effectiveTime',
width: 150,
sorter: true,
sortOrder: params.sortField === 'effectiveDate' ? sortOrder : null,
render: (value: string | null) => formatDateTime(value).split(' ')[0],
},
changeCount: {
title: COLUMN_LABELS.changeCount,
dataIndex: 'changeCount',
key: 'changeCount',
width: 120,
align: 'right',
sorter: true,
sortOrder: params.sortField === 'changeCount' ? sortOrder : null,
render: (value: number | null | undefined, row) => (
<Perm permission={P.STORE_LISTING_VIEW} fallback={value ?? '—'}>
<UButton
type="link"
aria-label={`查看${row.storeName}变更历史`}
onClick={() => onHistory(row)}
>
{value ?? '—'}
</UButton>
</Perm>
),
},
};
return visible.map((column) => definitions[column]);
}