index.tsx
8.87 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import React, { useEffect, useMemo, useState } from 'react';
import {
Button,
Input,
message,
Modal,
Space,
Table,
Tooltip,
Typography,
Avatar,
} from 'antd';
import { SettingOutlined } from '@ant-design/icons/lib';
import { useSearchParams } from 'react-router-dom';
import { useTitle } from 'ahooks';
import { QxIcon } from '@/components';
import { handleWindowOpen } from '@qx/utils';
import { FlowHeader, FlowVersion } from '@/components';
import { useFlowTableScrollY } from '@/utils';
import actions from '@/utils/actions';
import { isEmpty, cloneDeep } from 'lodash-es';
const { Text } = Typography;
// 样式
import cls from 'classnames';
import styles from '../index.module.less';
import { getProcessVersions } from '@/services';
import { FlowVersionStatusEnums } from '@/interface';
const prefix = 'qx-flow-setting';
const DataFlowVersion: React.FC = ({}) => {
// @ts-ignore
const [searchParams] = useSearchParams();
const {
processId, // 流程ID
name, // 流程名称
returnUrl, // 来自页面跳转返回可跳转
} = {
processId: searchParams.get('processId'),
name: searchParams.get('name'),
returnUrl: searchParams.get('returnUrl'),
};
const [pageData, setPageData] = useState<any[]>([]);
const [tableLoading, setTableLoading] = useState<boolean>(true); // 表格loading
// 表格是否添加scroll 属性
const [isScrollY, setIsScrollY] = useState<boolean>(false);
// 添加标题
useTitle(name || '未命名流程');
const handleClick = (
type: string,
data?: any,
e?: React.MouseEvent<HTMLElement, MouseEvent>,
) => {
const { host, pathname, protocol, hash } = location;
if (!!e) {
e.stopPropagation();
}
switch (type) {
case 'RETURN':
// 返回上一页
if (!!returnUrl) {
// 返回上一页
handleWindowOpen(
`${protocol}//${host}${pathname}${returnUrl}`,
'_self',
);
} else {
// history.goBack();
window.history.back();
}
break;
case 'VIEW':
// 查看
console.log('VIEW === ', data);
break;
case 'RESTORE':
// 恢复
console.log('RESTORE === ', data);
break;
default:
break;
}
};
const cols = useMemo(() => {
return [
{
title: () => {
return (
<span className={cls(styles[`${prefix}__col-title`])}>
流程版本
</span>
);
},
dataIndex: 'version',
render: (text: any, row: any) => {
return (
<span
className={cls(styles[`${prefix}__colspan`])}
style={{ width: '100%' }}
>
<FlowVersion versionText={text} />
</span>
);
},
width: 170,
className: 'qx-flow-table-cell',
},
{
title: () => {
return (
<span className={cls(styles[`${prefix}__col-title`])}>状态</span>
);
},
dataIndex: 'status',
className: 'qx-flow-table-cell',
render: (text: any) => {
return (
<span
className={cls(styles[`${prefix}__colspan`])}
style={{ width: '100%' }}
>
<FlowVersion status={text} statusEnums={FlowVersionStatusEnums} />
</span>
);
},
width: 170,
},
{
title: () => {
return (
<span className={cls(styles[`${prefix}__col-title`])}>
更新时间
</span>
);
},
dataIndex: 'updatedAt',
width: 200,
className: 'qx-flow-table-cell',
render: (text: any) => {
return (
<span
className={cls(styles[`${prefix}__colspan`])}
style={{ width: '100%' }}
>
{text}
</span>
);
},
onCell: (record: any) => {
return {
colSpan: ['APP', 'FUN'].includes(record?.type || '') ? 0 : 1,
};
},
},
{
title: () => {
return (
<span className={cls(styles[`${prefix}__col-title`])}>更新人</span>
);
},
dataIndex: 'updatedByUser',
className: 'qx-flow-table-cell qx-flow-table-cell-user',
render: (text: any, row: any) => {
if (isEmpty(text)) {
return '--';
}
let _imgError = false;
return (
<span
className={cls(styles[`${prefix}__colspan-user`])}
style={{ width: '100%' }}
>
<Avatar
className={'qx-flow-table-cell__avatar'}
size={24}
alt="avatar"
src={row?.updatedByUser?.faceUrl || ''}
onError={() => {
_imgError = true;
return true;
}}
>
{(!!row?.updatedByUser?.faceUrl && _imgError) ||
!row?.updatedByUser?.faceUrl
? !!row?.updatedByUser?.name?.length
? row?.updatedByUser?.name[
row?.updatedByUser?.name?.length - 1
]
: null
: null}
</Avatar>
<Text
className={'qx-flow-table-cell__avatar-name'}
ellipsis={{ tooltip: row?.updatedByUser?.name || '' }}
>
{row?.updatedByUser?.name || ''}
</Text>
</span>
);
},
width: 200,
},
{
title: () => {
return (
<span className={cls(styles[`${prefix}__col-title`])}>操作</span>
);
},
dataIndex: 'control',
render: (text: any, row: any) => (
<Space
size={8}
className={cls(styles[`${prefix}__colspan`])}
style={{ width: '100%' }}
>
<Button
type="link"
size="small"
onClick={(e: React.MouseEvent<HTMLElement, MouseEvent>) => {
e.stopPropagation();
handleClick('VIEW', row);
}}
>
查看
</Button>
<Button
type="link"
size="small"
onClick={(e: React.MouseEvent<HTMLElement, MouseEvent>) =>
handleClick('RESTORE', row, e)
}
>
恢复
</Button>
</Space>
),
width: 140,
className: 'qx-flow-table-cell',
},
];
}, [JSON.stringify(pageData)]);
// 查询list
const handleSearch = () => {
setTableLoading(true);
actions.cancelToken(); // 多次请求 取最新请求 其他取消
getProcessVersions('')
.then((res: any) => {
// 处理数据 符合表格渲染格式
const _cloneList: any[] = [];
const getColumnList = (data: any[]) => {
data.forEach((item: any) => {
_cloneList.push(cloneDeep(item));
if (!!item?.processes?.length) {
getColumnList(item?.processes);
}
});
};
getColumnList(cloneDeep(res || []));
setPageData(cloneDeep(_cloneList));
// setExpandedKeys(_cloneList.map((item: any) => item.key));
setTableLoading(false);
})
.catch(() => {
console.warn('数据列表获取失败');
setPageData([]);
setTableLoading(false);
});
};
// 表格滚动高度获取
const [scrollY] = useFlowTableScrollY({
columns: cols,
listProps: {
pageData,
},
}) as any[];
return (
<div className={cls(styles['qx-data-flow'])}>
<FlowHeader
title={name || '未命名流程'}
handleClick={handleClick}
type={'VERSION'}
/>
<section className={cls(styles['qx-data-flow__main'])}>
<section className={cls(styles['main-content'])}>
<div
className={cls(styles[`${prefix}-container`], 'qx-data-flow-table')}
>
<Table
loading={tableLoading}
columns={cols}
dataSource={pageData}
scroll={
isScrollY
? {
x: '100%',
y: scrollY,
}
: { x: '100%' }
}
pagination={false}
size={'small'}
bordered
rowKey={(record: any) => {
return `${record?.type || ''}${record?.id || ''}${Math.random()
.toString(36)
.replaceAll(/[0-9]/g, '')
.slice(2, 4)}`;
}}
/>
</div>
</section>
</section>
</div>
);
};
export default DataFlowVersion;