ApprovalChainPreview.tsx
6.17 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import { InfoCircleFilled, CheckCircleFilled } from '@ant-design/icons';
import { UCard } from '@uj/ui';
import { useAppStore } from '@/store/useAppStore';
export type ChainNodeStatus = 'done' | 'active' | 'pending';
export interface ChainNode {
status: ChainNodeStatus;
title: string;
subtitle: string;
time?: string;
}
const DEFAULT_SUBMIT_TIME = '2026-09-20 15:12';
interface NodeIconProps {
status: ChainNodeStatus;
index: number;
}
function NodeIcon({ status, index }: NodeIconProps) {
if (status === 'done') {
return (
<div
style={{
width: 32,
height: 32,
borderRadius: '50%',
background: '#16A34A',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
color: '#fff',
flex: 'none',
}}
>
<CheckCircleFilled style={{ fontSize: 18 }} />
</div>
);
}
if (status === 'active') {
return (
<div
style={{
width: 32,
height: 32,
borderRadius: '50%',
background: '#2B5CE6',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
color: '#fff',
fontWeight: 600,
fontSize: 13,
flex: 'none',
boxShadow: '0 0 0 4px #EEF2FF',
}}
>
{index + 1}
</div>
);
}
return (
<div
style={{
width: 32,
height: 32,
borderRadius: '50%',
background: '#fff',
border: '2px solid #D1D5DB',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
color: '#9CA3AF',
flex: 'none',
}}
>
<CheckCircleFilled style={{ fontSize: 16 }} />
</div>
);
}
const lineColor = (status: ChainNodeStatus) => (status === 'done' ? '#16A34A' : '#E5E7EB');
function NodeLine({ status }: { status: ChainNodeStatus }) {
return (
<div
style={{
flex: 1,
height: 2,
background: lineColor(status),
alignSelf: 'flex-start',
marginTop: 15,
}}
/>
);
}
export interface ApprovalChainPreviewProps {
nodes?: ChainNode[];
/** (可选)覆盖默认的提交人名称。不传则取当前登录用户名 */
submitterName?: string;
/** (可选)覆盖默认的提交时间,格式 YYYY-MM-DD HH:mm */
submitTime?: string;
}
/**
* 生成默认 4 节点审批链:
* - 第 1 个节点「提交」:副标题 = 当前登录用户名(外部 prop 覆盖优先);时间 = submitTime 或 DEFAULT_SUBMIT_TIME
* - 第 2 个节点「优加商务经理」:当前审批节点(active)
* - 第 3 个节点「优加财务经理」:下一审批节点(pending)
* - 第 4 个节点「生效」:写入门店列表
*/
function buildDefaultNodes(submitter: string, time: string): ChainNode[] {
return [
{
status: 'done',
title: '提交',
subtitle: submitter,
time,
},
{
status: 'active',
title: '优加商务经理',
subtitle: '当前审批节点',
},
{
status: 'pending',
title: '优加财务经理',
subtitle: '下一审批节点',
},
{
status: 'pending',
title: '生效',
subtitle: '写入门店列表',
},
];
}
export function ApprovalChainPreview({
nodes,
submitterName,
submitTime,
}: ApprovalChainPreviewProps) {
const { currentUser } = useAppStore();
const finalSubmitter = submitterName ?? currentUser.name ?? '管理员';
const finalTime = submitTime ?? DEFAULT_SUBMIT_TIME;
const finalNodes: ChainNode[] = nodes ?? buildDefaultNodes(finalSubmitter, finalTime);
return (
<UCard
styles={{ body: { padding: '20px 24px 24px' } }}
style={{ marginBottom: 20, border: '1px solid #E5E7EB', borderRadius: 10 }}
title={
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<InfoCircleFilled style={{ color: '#2B5CE6', fontSize: 14 }} />
<span style={{ fontSize: 15, fontWeight: 600 }}>审批链预览</span>
</div>
}
>
<div style={{ display: 'flex', padding: '20px 8px 8px' }}>
{finalNodes.map((n, i) => {
const prev = finalNodes[i - 1];
const hasLeft = i > 0;
const hasRight = i < finalNodes.length - 1;
return (
<div
key={i}
style={{
flex: 1,
display: 'flex',
alignItems: 'flex-start',
}}
>
<div style={{ flex: 1 }}>{hasLeft && <NodeLine status={prev.status} />}</div>
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
flex: 'none',
}}
>
<NodeIcon status={n.status} index={i} />
<div
style={{
marginTop: 14,
fontSize: 14,
fontWeight: 600,
color:
n.status === 'active'
? '#2B5CE6'
: n.status === 'done'
? '#16A34A'
: '#6B7280',
textAlign: 'center',
}}
>
{n.title}
</div>
<div
style={{
marginTop: 4,
fontSize: 12,
color: '#9CA3AF',
textAlign: 'center',
}}
>
{n.subtitle}
</div>
{n.time && (
<div
style={{
marginTop: 4,
fontSize: 11,
color: '#C7CDD6',
textAlign: 'center',
}}
>
{n.time}
</div>
)}
</div>
<div style={{ flex: 1 }}>{hasRight && <NodeLine status={n.status} />}</div>
</div>
);
})}
</div>
</UCard>
);
}