1
|
-// import { QIXIAO_TOKEN } from '@/libs/token';
|
|
|
2
|
-import { SYSTEM_WIDGETS } from '@/packages/qx-form-generator/src/utils/common';
|
|
|
3
|
-import QxIcon from '@/packages/qx-icon';
|
|
|
4
|
-import { RelMoreModal, RelSingleModal } from '@/pages/app-view/form';
|
|
|
5
|
-import { EllipsisOutlined, SearchOutlined } from '@ant-design/icons';
|
|
|
6
|
import { QxSearch, QxTable } from '@qx/view-render';
|
1
|
import { QxSearch, QxTable } from '@qx/view-render';
|
7
|
-import type { QxTableCellAPISchema } from '@qx/view-render/dist/table';
|
|
|
8
|
-import {
|
|
|
9
|
- Button,
|
|
|
10
|
- Dropdown,
|
|
|
11
|
- Empty,
|
|
|
12
|
- Input,
|
|
|
13
|
- Menu,
|
|
|
14
|
- message,
|
|
|
15
|
- Popover,
|
|
|
16
|
- Tooltip,
|
|
|
17
|
- Tree,
|
|
|
18
|
-} from 'antd';
|
|
|
19
|
import _ from 'lodash';
|
2
|
import _ from 'lodash';
|
20
|
-import { customAlphabet } from 'nanoid';
|
|
|
21
|
-import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
22
|
-import { QxButton } from '@qx/view-render';
|
|
|
23
|
-import './index.less';
|
|
|
24
|
-
|
|
|
25
|
export * from '@qx/view-render';
|
3
|
export * from '@qx/view-render';
|
26
|
-
|
|
|
27
|
-/*TODO 待细化*/
|
|
|
28
|
-interface QxRuntimeTableProps {
|
|
|
29
|
- appCode?: string;
|
|
|
30
|
- funCode?: string;
|
|
|
31
|
- viewCode?: string;
|
|
|
32
|
- tableRef?: any;
|
|
|
33
|
- tableLoading?: boolean;
|
|
|
34
|
- dataSource: any[];
|
|
|
35
|
- onClickBtn?: (code: any, data: any) => void;
|
|
|
36
|
- total?: number;
|
|
|
37
|
- searchApi?: any;
|
|
|
38
|
- onSelect?: () => void;
|
|
|
39
|
- onSelectAll?: () => void;
|
|
|
40
|
- selectKeys?: string[];
|
|
|
41
|
- mode?: any;
|
|
|
42
|
- max?: number;
|
|
|
43
|
- sort?: any[];
|
|
|
44
|
- onChange?: (pagination: any, filters: any, sorter: any) => void;
|
|
|
45
|
- [propName: string]: any;
|
|
|
46
|
- bodyHeight?: number;
|
|
|
47
|
-}
|
|
|
48
|
-
|
|
|
49
|
-const QxRuntimeTable: React.FC<QxRuntimeTableProps> = (props) => {
|
|
|
50
|
- const {
|
|
|
51
|
- appCode,
|
|
|
52
|
- funCode,
|
|
|
53
|
- viewCode,
|
|
|
54
|
- tableRef,
|
|
|
55
|
- tableLoading,
|
|
|
56
|
- dataSource,
|
|
|
57
|
- onChange = () => {},
|
|
|
58
|
- onClickBtn = () => {},
|
|
|
59
|
- total,
|
|
|
60
|
- searchApi,
|
|
|
61
|
- ...otherProps
|
|
|
62
|
- } = props;
|
|
|
63
|
-
|
|
|
64
|
- const [rowData, setRowData] = useState<any>();
|
|
|
65
|
- const [cellSchema, setCellSchema] = useState<any>();
|
|
|
66
|
- const [clickInfo, setClickInfo] = useState<any>();
|
|
|
67
|
- const [random, setRandom] = useState<string>(); //随机数
|
|
|
68
|
-
|
|
|
69
|
- const relMoreModalRef = useRef({
|
|
|
70
|
- open: (values: any) => {
|
|
|
71
|
- console.log(values);
|
|
|
72
|
- },
|
|
|
73
|
- close: () => {},
|
|
|
74
|
- });
|
|
|
75
|
-
|
|
|
76
|
- const relSingleModalRef = useRef({
|
|
|
77
|
- open: (values: any) => {
|
|
|
78
|
- console.log(values);
|
|
|
79
|
- },
|
|
|
80
|
- close: () => {},
|
|
|
81
|
- });
|
|
|
82
|
-
|
|
|
83
|
- function getId() {
|
|
|
84
|
- return customAlphabet('abcdefghijklmnopqistuvwxyz', 6)();
|
|
|
85
|
- }
|
|
|
86
|
-
|
|
|
87
|
- const handleCellClick = (
|
|
|
88
|
- record: any,
|
|
|
89
|
- schemaData: QxTableCellAPISchema,
|
|
|
90
|
- info?: any,
|
|
|
91
|
- ) => {
|
|
|
92
|
- // console.log(record,schemaData,info)
|
|
|
93
|
- setRowData(record); //点击行的数据
|
|
|
94
|
- setCellSchema(schemaData); //列的schema
|
|
|
95
|
- setClickInfo(info || ''); // 点击标签的data_title id
|
|
|
96
|
- setRandom(getId());
|
|
|
97
|
- };
|
|
|
98
|
-
|
|
|
99
|
- useEffect(() => {
|
|
|
100
|
- if (cellSchema?.link) {
|
|
|
101
|
- //详情链接 标题、描述
|
|
|
102
|
- onClickBtn({ code: 'VIEW' }, rowData);
|
|
|
103
|
- } else {
|
|
|
104
|
- //1、关联记录以标签显示的时候,直接弹出该条数据详情
|
|
|
105
|
- //2、关联记录以表格显示的时候,弹出关联记录表格
|
|
|
106
|
- if (cellSchema?.widget === 'relSelector') {
|
|
|
107
|
- if (
|
|
|
108
|
- cellSchema?.mode === 'TABLE' &&
|
|
|
109
|
- (rowData[cellSchema?.dataIndex] || []).length
|
|
|
110
|
- ) {
|
|
|
111
|
- //关联记录 表格形式
|
|
|
112
|
- relMoreModalRef.current.open({
|
|
|
113
|
- appCode: appCode,
|
|
|
114
|
- funCode: funCode,
|
|
|
115
|
- viewCode: viewCode,
|
|
|
116
|
- fieldName: cellSchema?.dataIndex,
|
|
|
117
|
- dataId: rowData?.id, //当前行的id
|
|
|
118
|
- idArr: rowData[cellSchema?.dataIndex], //当前行 用户所点击列的关联记录id数组
|
|
|
119
|
- modalTitle: cellSchema?.title,
|
|
|
120
|
- widget: cellSchema?.widget, //关联表的标识
|
|
|
121
|
- });
|
|
|
122
|
- } else {
|
|
|
123
|
- //关联记录 标签形式
|
|
|
124
|
- // const info = dataSource.filter((o: any) => o.id === rowData?.id)[0][
|
|
|
125
|
- // cellSchema?.dataIndex + '_info_'
|
|
|
126
|
- // ];
|
|
|
127
|
- relSingleModalRef.current.open({
|
|
|
128
|
- // 后端数据结构调整 这里去掉了relAppCode和relFuncode 改为在获取详情schema时返回
|
|
|
129
|
- // appCode: cellSchema.relAppCode,
|
|
|
130
|
- // funCode: cellSchema.relFunCode,
|
|
|
131
|
- params: { appCode, funCode, fieldName: cellSchema?.dataIndex },
|
|
|
132
|
- fieldName: cellSchema?.dataIndex,
|
|
|
133
|
- dataId: rowData?.id, //当前行的id
|
|
|
134
|
- relFormId: clickInfo?.id, //表的id
|
|
|
135
|
- modalTitle: clickInfo?.data_title, //表名
|
|
|
136
|
- });
|
|
|
137
|
- }
|
|
|
138
|
- } else if (
|
|
|
139
|
- cellSchema?.widget === 'subform' &&
|
|
|
140
|
- cellSchema?.type === 'TABLE'
|
|
|
141
|
- ) {
|
|
|
142
|
- //子表
|
|
|
143
|
- relMoreModalRef.current.open({
|
|
|
144
|
- appCode: appCode,
|
|
|
145
|
- funCode: funCode,
|
|
|
146
|
- viewCode: viewCode,
|
|
|
147
|
- fieldName: cellSchema?.dataIndex,
|
|
|
148
|
- dataId: rowData?.id, //当前行的id
|
|
|
149
|
- modalTitle: cellSchema?.title,
|
|
|
150
|
- widget: cellSchema?.widget, //子表的标识
|
|
|
151
|
- });
|
|
|
152
|
- }
|
|
|
153
|
- }
|
|
|
154
|
- }, [rowData, cellSchema, random]);
|
|
|
155
|
-
|
|
|
156
|
- return (
|
|
|
157
|
- <>
|
|
|
158
|
- <QxTable
|
|
|
159
|
- cRef={tableRef}
|
|
|
160
|
- {...otherProps}
|
|
|
161
|
- loading={tableLoading}
|
|
|
162
|
- dataSource={dataSource}
|
|
|
163
|
- onClickBtn={onClickBtn}
|
|
|
164
|
- onCellClick={handleCellClick}
|
|
|
165
|
- onChange={onChange}
|
|
|
166
|
- onSelect={props.onSelect}
|
|
|
167
|
- onSelectAll={props.onSelectAll}
|
|
|
168
|
- selectKeys={props.selectKeys}
|
|
|
169
|
- total={total}
|
|
|
170
|
- mode={props.mode}
|
|
|
171
|
- max={props.max}
|
|
|
172
|
- sort={props?.sort}
|
|
|
173
|
- onPage={props?.onPage}
|
|
|
174
|
- // QIXIAO_TOKEN={QIXIAO_TOKEN}
|
|
|
175
|
- />
|
|
|
176
|
- <RelMoreModal cRef={relMoreModalRef} />
|
|
|
177
|
- <RelSingleModal cRef={relSingleModalRef} />
|
|
|
178
|
- </>
|
|
|
179
|
- );
|
|
|
180
|
-};
|
|
|
181
|
-
|
|
|
182
|
-interface QxRuntimeTreeProps {
|
|
|
183
|
- appCode?: string;
|
|
|
184
|
- funCode?: string;
|
|
|
185
|
- viewCode?: string;
|
|
|
186
|
- tableLoading?: boolean;
|
|
|
187
|
- dataSource: any;
|
|
|
188
|
- onClickBtn: (code: object, data: any) => {};
|
|
|
189
|
- searchApi: any;
|
|
|
190
|
- onSelect?: () => {};
|
|
|
191
|
- onChange?: (pagination: any, filters: any, sorter: any) => void;
|
|
|
192
|
- [propName: string]: any;
|
|
|
193
|
- treeSchema: any;
|
|
|
194
|
- onTreeDrop: (nodeId: string, parent: string, next: string) => void;
|
|
|
195
|
-}
|
|
|
196
|
-
|
|
|
197
|
-const QxRuntimeTree: React.FC<QxRuntimeTreeProps> = (props) => {
|
|
|
198
|
- const { treeSchema, dataSource, onClickBtn, onTreeDrop } = props;
|
|
|
199
|
-
|
|
|
200
|
- const [expandedKeys, setExpandedKeys] = useState<any[]>([]); //默认展开的节点
|
|
|
201
|
- const [keyword, setKeyword] = useState<string>('');
|
|
|
202
|
- const [treeData, setTreeData] = useState<any[]>([]);
|
|
|
203
|
- const [data, setData] = useState<any>([]);
|
|
|
204
|
-
|
|
|
205
|
- // 拖拽节点 相关代码
|
|
|
206
|
- // 根据parentNodeId得到parentNodeType
|
|
|
207
|
- const parentNode = (parentNodeData: any, parentNodeId: string) => {
|
|
|
208
|
- for (let i = 0; i < parentNodeData.length; i++) {
|
|
|
209
|
- if (parentNodeId == parentNodeData[i].code) {
|
|
|
210
|
- return parentNodeData[i].type;
|
|
|
211
|
- }
|
|
|
212
|
- if (parentNodeData[i].children) {
|
|
|
213
|
- const res: any = parentNode(parentNodeData[i].children, parentNodeId);
|
|
|
214
|
- if (res) {
|
|
|
215
|
- return res;
|
|
|
216
|
- }
|
|
|
217
|
- }
|
|
|
218
|
- }
|
|
|
219
|
- };
|
|
|
220
|
- const handleDrop = (val: any) => {
|
|
|
221
|
- const { node, dragNode, dropToGap } = val;
|
|
|
222
|
- const dragNodeId = dragNode.code;
|
|
|
223
|
- let nextNodeId = node.__next;
|
|
|
224
|
- let parentNodeId = node.__pId ? node.__pId : '*';
|
|
|
225
|
- if (!dropToGap) {
|
|
|
226
|
- parentNodeId = node.code ? node.code : '*';
|
|
|
227
|
- nextNodeId = (node.children[0] && node.children[0].code) || null;
|
|
|
228
|
- }
|
|
|
229
|
- const parentNodeType = parentNode(dataSource, parentNodeId); // 根据parentNodeId得到parentNodeType
|
|
|
230
|
- if (parentNodeType === 'PAGE') {
|
|
|
231
|
- message.warning('不能移动至页面下');
|
|
|
232
|
- return;
|
|
|
233
|
- }
|
|
|
234
|
- if (parentNodeId === '*' || dragNodeId === nextNodeId) {
|
|
|
235
|
- return;
|
|
|
236
|
- }
|
|
|
237
|
- onTreeDrop(dragNodeId, parentNodeId, nextNodeId);
|
|
|
238
|
- };
|
|
|
239
|
-
|
|
|
240
|
- let codeArr: any = [];
|
|
|
241
|
-
|
|
|
242
|
- /**
|
|
|
243
|
- * 获取需要展开的节点
|
|
|
244
|
- * @param arr nodesData
|
|
|
245
|
- * @param expandLevel 需要展开的级别默认二级
|
|
|
246
|
- * @param pId
|
|
|
247
|
- */
|
|
|
248
|
- const loopTreeNode = (nodesData: any[], expandLevel: number) => {
|
|
|
249
|
- let nextExpendLevel = expandLevel;
|
|
|
250
|
- // if (expandLevel > 0) {
|
|
|
251
|
- nextExpendLevel -= 1;
|
|
|
252
|
- // }
|
|
|
253
|
- // @ts-ignore
|
|
|
254
|
- nodesData.forEach((item, index) => {
|
|
|
255
|
- if (nextExpendLevel >= 0) {
|
|
|
256
|
- codeArr.push(item.code);
|
|
|
257
|
- }
|
|
|
258
|
- item.key = item.code;
|
|
|
259
|
- item.__next = nodesData[index + 1] ? nodesData[index + 1].code : null;
|
|
|
260
|
-
|
|
|
261
|
- if (!item.children) {
|
|
|
262
|
- item.isLeaf = true;
|
|
|
263
|
- } else {
|
|
|
264
|
- loopTreeNode(item.children, nextExpendLevel);
|
|
|
265
|
- }
|
|
|
266
|
- });
|
|
|
267
|
- };
|
|
|
268
|
- const getExpandedArr = (nodesData: any[]) => {
|
|
|
269
|
- nodesData.forEach((item) => {
|
|
|
270
|
- codeArr.push(item.code);
|
|
|
271
|
- if (item.children) {
|
|
|
272
|
- getExpandedArr(item.children);
|
|
|
273
|
- }
|
|
|
274
|
- });
|
|
|
275
|
- };
|
|
|
276
|
-
|
|
|
277
|
- const generateTreeData = useCallback(
|
|
|
278
|
- (_data: any[], _keywords?: string): any[] => {
|
|
|
279
|
- const _treeNode: any[] = [];
|
|
|
280
|
- _data.map((item) => {
|
|
|
281
|
- if (typeof item.visible === 'boolean' && !item.visible) {
|
|
|
282
|
- return;
|
|
|
283
|
- }
|
|
|
284
|
- const _item: any = {
|
|
|
285
|
- ...item,
|
|
|
286
|
- children: [],
|
|
|
287
|
- };
|
|
|
288
|
- if (item.children) {
|
|
|
289
|
- _item.children = generateTreeData(item.children, _keywords);
|
|
|
290
|
- }
|
|
|
291
|
- _treeNode.push(_item);
|
|
|
292
|
- });
|
|
|
293
|
- return _treeNode;
|
|
|
294
|
- },
|
|
|
295
|
- [],
|
|
|
296
|
- );
|
|
|
297
|
-
|
|
|
298
|
- const filter = (word: string) => {
|
|
|
299
|
- setKeyword(word);
|
|
|
300
|
- const traverse = function (node: any) {
|
|
|
301
|
- const childNodes = node.children || [];
|
|
|
302
|
- node.visible = node.name.indexOf(word) > -1;
|
|
|
303
|
-
|
|
|
304
|
- childNodes.forEach((child: any) => {
|
|
|
305
|
- child.visible = child.name.indexOf(word) > -1;
|
|
|
306
|
- traverse(child);
|
|
|
307
|
- });
|
|
|
308
|
-
|
|
|
309
|
- if (!node.visible && childNodes.length) {
|
|
|
310
|
- node.visible = childNodes.some((child: any) => child.visible);
|
|
|
311
|
- }
|
|
|
312
|
- };
|
|
|
313
|
- if (data) {
|
|
|
314
|
- const _data = _.cloneDeep(data);
|
|
|
315
|
- if (word != '') {
|
|
|
316
|
- // @ts-ignore
|
|
|
317
|
- _data.forEach((item) => {
|
|
|
318
|
- traverse(item);
|
|
|
319
|
- });
|
|
|
320
|
- }
|
|
|
321
|
- setTreeData(generateTreeData(_data, word));
|
|
|
322
|
- }
|
|
|
323
|
- };
|
|
|
324
|
- // 搜索框事件
|
|
|
325
|
- const handleChange = (e: { type: string; target: { value: string } }) => {
|
|
|
326
|
- const keywordText = e.target.value.replace(/(^\s*)|(\s*$)/g, '');
|
|
|
327
|
-
|
|
|
328
|
- if (e.type === 'click' && e.target.value === '' && keyword !== '') {
|
|
|
329
|
- // 清空
|
|
|
330
|
- setData(dataSource);
|
|
|
331
|
- setTreeData(dataSource);
|
|
|
332
|
- } else {
|
|
|
333
|
- if (keywordText) {
|
|
|
334
|
- filter(keywordText);
|
|
|
335
|
- } else {
|
|
|
336
|
- setData(dataSource);
|
|
|
337
|
- setTreeData(dataSource);
|
|
|
338
|
- }
|
|
|
339
|
- }
|
|
|
340
|
- };
|
|
|
341
|
- const handleSearch = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
|
342
|
- // @ts-ignore
|
|
|
343
|
- const keywordText = e.target.value.replace(/(^\s*)|(\s*$)/g, '');
|
|
|
344
|
- if (keywordText) {
|
|
|
345
|
- filter(keywordText);
|
|
|
346
|
- } else {
|
|
|
347
|
- setData(dataSource);
|
|
|
348
|
- setTreeData(dataSource);
|
|
|
349
|
- }
|
|
|
350
|
- };
|
|
|
351
|
-
|
|
|
352
|
- useEffect(() => {
|
|
|
353
|
- if (!dataSource || !treeSchema || !dataSource.length) {
|
|
|
354
|
- return;
|
|
|
355
|
- }
|
|
|
356
|
- setData(dataSource);
|
|
|
357
|
- setTreeData(dataSource);
|
|
|
358
|
- const config = treeSchema?.tree || {};
|
|
|
359
|
- if (!config?.expandLevel && config?.expandLevel === 0) {
|
|
|
360
|
- codeArr = [];
|
|
|
361
|
- getExpandedArr(dataSource || []);
|
|
|
362
|
- setExpandedKeys(codeArr);
|
|
|
363
|
- } else {
|
|
|
364
|
- codeArr = [];
|
|
|
365
|
- loopTreeNode(dataSource || [], config?.expandLevel);
|
|
|
366
|
- setExpandedKeys(codeArr);
|
|
|
367
|
- }
|
|
|
368
|
- }, [dataSource, treeSchema]);
|
|
|
369
|
-
|
|
|
370
|
- const getBtnDom = (val: any, filterData: any, schema: any) => {
|
|
|
371
|
- if (!filterData?.extract?.[val.flag]) {
|
|
|
372
|
- return null;
|
|
|
373
|
- }
|
|
|
374
|
- let icon = val.icon;
|
|
|
375
|
- let name = val.name;
|
|
|
376
|
- if (schema?.tree?.style === 'text') {
|
|
|
377
|
- icon = '';
|
|
|
378
|
- }
|
|
|
379
|
- if (icon && (schema?.tree?.style === 'icon' || !schema?.tree?.style)) {
|
|
|
380
|
- name = '';
|
|
|
381
|
- }
|
|
|
382
|
- let btnElem;
|
|
|
383
|
- if (val.name.length > 4) {
|
|
|
384
|
- btnElem = (
|
|
|
385
|
- <QxButton
|
|
|
386
|
- key={val.code}
|
|
|
387
|
- color={val.color}
|
|
|
388
|
- icon={icon}
|
|
|
389
|
- type={'link'}
|
|
|
390
|
- size={'small'}
|
|
|
391
|
- disabled={val.disabled}
|
|
|
392
|
- tooltip={val.tooltip || (name && val.name)}
|
|
|
393
|
- onClick={() => {
|
|
|
394
|
- onClickBtn({ code: val.code, ...val }, filterData);
|
|
|
395
|
- }}
|
|
|
396
|
- >
|
|
|
397
|
- {name ? name.substring(0, 4) + '...' : name}
|
|
|
398
|
- </QxButton>
|
|
|
399
|
- );
|
|
|
400
|
- } else {
|
|
|
401
|
- btnElem = (
|
|
|
402
|
- <QxButton
|
|
|
403
|
- key={val.code}
|
|
|
404
|
- color={val.color}
|
|
|
405
|
- icon={icon}
|
|
|
406
|
- type={'link'}
|
|
|
407
|
- size={'small'}
|
|
|
408
|
- disabled={val.disabled}
|
|
|
409
|
- tooltip={val.tooltip}
|
|
|
410
|
- onClick={() => {
|
|
|
411
|
- onClickBtn({ code: val.code, ...val }, filterData);
|
|
|
412
|
- }}
|
|
|
413
|
- >
|
|
|
414
|
- {name}
|
|
|
415
|
- </QxButton>
|
|
|
416
|
- );
|
|
|
417
|
- }
|
|
|
418
|
-
|
|
|
419
|
- if (schema?.tree?.style === 'icon' || !schema?.tree?.style) {
|
|
|
420
|
- return (
|
|
|
421
|
- <Tooltip key={val.code} title={val.name}>
|
|
|
422
|
- {btnElem}
|
|
|
423
|
- </Tooltip>
|
|
|
424
|
- );
|
|
|
425
|
- } else {
|
|
|
426
|
- return btnElem;
|
|
|
427
|
- }
|
|
|
428
|
- };
|
|
|
429
|
-
|
|
|
430
|
- // 渲染节点
|
|
|
431
|
- const renderTitle = (nodeData: any) => {
|
|
|
432
|
- const btnList = (
|
|
|
433
|
- treeSchema?.tree?.action?.renderData?.buttons || []
|
|
|
434
|
- ).filter((item: any) => {
|
|
|
435
|
- if (!!nodeData?.extract?.[item.flag]) {
|
|
|
436
|
- return item;
|
|
|
437
|
- }
|
|
|
438
|
- });
|
|
|
439
|
- // 超过 6 个则放入更多操作
|
|
|
440
|
- const MAX = 6;
|
|
|
441
|
- const isOverMax = btnList?.length > MAX + 1;
|
|
|
442
|
- const isEqualMax = btnList?.length === MAX + 1;
|
|
|
443
|
-
|
|
|
444
|
- return (
|
|
|
445
|
- <>
|
|
|
446
|
- {nodeData?.level > 1 && (
|
|
|
447
|
- <QxIcon
|
|
|
448
|
- type={'icon-pailie'}
|
|
|
449
|
- style={{
|
|
|
450
|
- fontSize: 18,
|
|
|
451
|
- color: '#999',
|
|
|
452
|
- marginRight: '8px',
|
|
|
453
|
- }}
|
|
|
454
|
- />
|
|
|
455
|
- )}
|
|
|
456
|
- {nodeData.name && nodeData.name.length > 30 ? (
|
|
|
457
|
- <Tooltip key={nodeData.code} title={nodeData.name}>
|
|
|
458
|
- <span>{nodeData.name.substring(0, 30) + '...'}</span>
|
|
|
459
|
- </Tooltip>
|
|
|
460
|
- ) : (
|
|
|
461
|
- <span>{nodeData.name}</span>
|
|
|
462
|
- )}
|
|
|
463
|
- <div className={'qx-tree-btn-list'}>
|
|
|
464
|
- {_.take(btnList, isEqualMax ? MAX + 1 : MAX).map((val: any) => {
|
|
|
465
|
- return getBtnDom(val, nodeData, treeSchema);
|
|
|
466
|
- })}
|
|
|
467
|
- {isOverMax && (
|
|
|
468
|
- <Dropdown
|
|
|
469
|
- overlayClassName="qx-tree-drop-down"
|
|
|
470
|
- placement="bottomRight"
|
|
|
471
|
- overlay={
|
|
|
472
|
- <Menu>
|
|
|
473
|
- {_.drop(btnList, MAX).map((val: any) => {
|
|
|
474
|
- return (
|
|
|
475
|
- <Menu.Item key={val.code}>
|
|
|
476
|
- {getBtnDom(val, nodeData, treeSchema)}
|
|
|
477
|
- </Menu.Item>
|
|
|
478
|
- );
|
|
|
479
|
- })}
|
|
|
480
|
- </Menu>
|
|
|
481
|
- }
|
|
|
482
|
- getPopupContainer={(trigger: any) => trigger.parentNode}
|
|
|
483
|
- >
|
|
|
484
|
- <Button className={'qx-tree-drop-down-btn'} type="text">
|
|
|
485
|
- <EllipsisOutlined />
|
|
|
486
|
- </Button>
|
|
|
487
|
- </Dropdown>
|
|
|
488
|
- )}
|
|
|
489
|
- </div>
|
|
|
490
|
- </>
|
|
|
491
|
- );
|
|
|
492
|
- };
|
|
|
493
|
-
|
|
|
494
|
- return (
|
|
|
495
|
- <div
|
|
|
496
|
- className={'qx-tree-list'}
|
|
|
497
|
- style={{ padding: '20px', backgroundColor: '#fff' }}
|
|
|
498
|
- >
|
|
|
499
|
- {data && data.length > 0 && treeSchema?.tree?.searchSwitch && (
|
|
|
500
|
- <Input
|
|
|
501
|
- className={'qx-selector-sub-search'}
|
|
|
502
|
- style={{
|
|
|
503
|
- borderBottom: '1px solid #f0f0f0',
|
|
|
504
|
- }}
|
|
|
505
|
- placeholder={'请输入关键字,按回车键搜索'}
|
|
|
506
|
- allowClear
|
|
|
507
|
- prefix={<SearchOutlined style={{ marginTop: '4px' }} />}
|
|
|
508
|
- onChange={(e) => {
|
|
|
509
|
- handleChange(e);
|
|
|
510
|
- }}
|
|
|
511
|
- onPressEnter={(e) => {
|
|
|
512
|
- handleSearch(e);
|
|
|
513
|
- }}
|
|
|
514
|
- />
|
|
|
515
|
- )}
|
|
|
516
|
- <>
|
|
|
517
|
- {treeData && treeData.length > 0 ? (
|
|
|
518
|
- <Tree
|
|
|
519
|
- treeData={treeData}
|
|
|
520
|
- fieldNames={{
|
|
|
521
|
- title: 'name',
|
|
|
522
|
- key: 'code',
|
|
|
523
|
- children: 'children',
|
|
|
524
|
- }}
|
|
|
525
|
- titleRender={(nodeData) => renderTitle(nodeData)}
|
|
|
526
|
- blockNode={true}
|
|
|
527
|
- onDrop={handleDrop}
|
|
|
528
|
- draggable={
|
|
|
529
|
- treeSchema?.tree?.dragSwitch
|
|
|
530
|
- ? {
|
|
|
531
|
- nodeDraggable: (node: any) => {
|
|
|
532
|
- if (node.pid === '*') {
|
|
|
533
|
- return false;
|
|
|
534
|
- }
|
|
|
535
|
- return true;
|
|
|
536
|
- },
|
|
|
537
|
- }
|
|
|
538
|
- : false
|
|
|
539
|
- }
|
|
|
540
|
- selectable
|
|
|
541
|
- defaultExpandedKeys={expandedKeys}
|
|
|
542
|
- expandedKeys={expandedKeys}
|
|
|
543
|
- checkStrictly={true}
|
|
|
544
|
- // @ts-ignore
|
|
|
545
|
- onExpand={(keys) => setExpandedKeys(keys)}
|
|
|
546
|
- />
|
|
|
547
|
- ) : (
|
|
|
548
|
- <Empty
|
|
|
549
|
- className={'qx-tree-list__empty'}
|
|
|
550
|
- image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
|
551
|
- />
|
|
|
552
|
- )}
|
|
|
553
|
- </>
|
|
|
554
|
- </div>
|
|
|
555
|
- );
|
|
|
556
|
-};
|
4
|
+import './index.less';
|
557
|
|
5
|
|
558
|
const QxSearchForm = (props: any) => {
|
6
|
const QxSearchForm = (props: any) => {
|
|
|
7
|
+ const SYSTEM_WIDGETS = qx.getModuleData()?.systemWidgets;
|
559
|
const widgets = { ...SYSTEM_WIDGETS, ...(props.widgets || {}) };
|
8
|
const widgets = { ...SYSTEM_WIDGETS, ...(props.widgets || {}) };
|
560
|
return <QxSearch {...props} widgets={widgets} />;
|
9
|
return <QxSearch {...props} widgets={widgets} />;
|
561
|
};
|
10
|
};
|
562
|
|
11
|
|
563
|
-// 快捷查询 功能相关代码
|
|
|
564
|
-interface QxQuickSearchTabsProps {
|
|
|
565
|
- list: any[];
|
|
|
566
|
- tabActiveCode: string | undefined;
|
|
|
567
|
- onChange: (value: any) => void;
|
|
|
568
|
-}
|
|
|
569
|
-
|
|
|
570
|
-// scroll状态
|
|
|
571
|
-export enum SCROLL {
|
|
|
572
|
- start,
|
|
|
573
|
- middle,
|
|
|
574
|
- end,
|
|
|
575
|
-}
|
|
|
576
|
-
|
|
|
577
|
-const QxQuickSearchTabs: React.FC<QxQuickSearchTabsProps> = (props: any) => {
|
|
|
578
|
- const { list, tabActiveCode, onChange } = props;
|
|
|
579
|
- const [tabsIcon, setTabsIcon] = useState<boolean>(false);
|
|
|
580
|
- const [scroll, setScroll] = useState<SCROLL>(SCROLL.start);
|
|
|
581
|
-
|
|
|
582
|
- /* useEffect(() => {
|
|
|
583
|
- if (!list || !list.length) {
|
|
|
584
|
- return;
|
|
|
585
|
- }
|
|
|
586
|
- onChange(list[0].code);
|
|
|
587
|
- }, [list]);*/
|
|
|
588
|
-
|
|
|
589
|
- const getQuickSearchScroll = () => {
|
|
|
590
|
- const tabsDom: any = document?.getElementById('quickSearchTabs');
|
|
|
591
|
- if (tabsDom?.offsetWidth - tabsDom?.scrollWidth < 0) {
|
|
|
592
|
- setTabsIcon(true);
|
|
|
593
|
- const translate = tabsDom.style?.transform;
|
|
|
594
|
- const translateNum = translate.split('(').pop().split('p').shift();
|
|
|
595
|
- if (Number(translateNum) == 0) {
|
|
|
596
|
- setScroll(SCROLL.start);
|
|
|
597
|
- } else if (Math.abs(Number(translateNum)) > 0) {
|
|
|
598
|
- if (
|
|
|
599
|
- Math.abs(Number(translateNum)) ==
|
|
|
600
|
- Math.abs(tabsDom?.offsetWidth - tabsDom?.scrollWidth)
|
|
|
601
|
- ) {
|
|
|
602
|
- setScroll(SCROLL.end);
|
|
|
603
|
- } else {
|
|
|
604
|
- setScroll(SCROLL.middle);
|
|
|
605
|
- }
|
|
|
606
|
- }
|
|
|
607
|
- } else {
|
|
|
608
|
- setTabsIcon(false);
|
|
|
609
|
- }
|
|
|
610
|
- };
|
|
|
611
|
-
|
|
|
612
|
- const handleClick = (changedCode: any, index: number, e: any) => {
|
|
|
613
|
- const tabItemLeft = e.currentTarget.offsetLeft - 20;
|
|
|
614
|
- const tabItemWidth = e.currentTarget.clientWidth;
|
|
|
615
|
- const tabsDom: any = document?.getElementById('quickSearchTabs');
|
|
|
616
|
- const translate = tabsDom.style?.transform;
|
|
|
617
|
- const translateNum = Math.abs(
|
|
|
618
|
- Number(translate.split('(').pop().split('p').shift() || 0),
|
|
|
619
|
- );
|
|
|
620
|
- let widget =
|
|
|
621
|
- translateNum + tabsDom.clientWidth - (tabItemLeft + tabItemWidth);
|
|
|
622
|
- if (widget > 0) {
|
|
|
623
|
- if (translateNum === 0) {
|
|
|
624
|
- tabsDom.style.cssText = 'transform: translate(0px,0px);';
|
|
|
625
|
- } else {
|
|
|
626
|
- widget = index > 0 ? tabItemLeft + 20 : tabItemLeft;
|
|
|
627
|
- if (translateNum > tabItemLeft) {
|
|
|
628
|
- tabsDom.style.cssText =
|
|
|
629
|
- 'transform: translate(' + -widget + 'px,0px);';
|
|
|
630
|
- }
|
|
|
631
|
- }
|
|
|
632
|
- } else if (widget < 0) {
|
|
|
633
|
- widget = translateNum + Math.abs(widget);
|
|
|
634
|
- tabsDom.style.cssText = 'transform: translate(' + -widget + 'px,0px);';
|
|
|
635
|
- }
|
|
|
636
|
-
|
|
|
637
|
- if (changedCode === tabActiveCode) return;
|
|
|
638
|
- onChange(changedCode);
|
|
|
639
|
- };
|
|
|
640
|
-
|
|
|
641
|
- const scrollPrev = () => {
|
|
|
642
|
- const tabsDom: any = document?.getElementById('quickSearchTabs');
|
|
|
643
|
- const translate = tabsDom.style?.transform;
|
|
|
644
|
- const translateNum = Math.abs(
|
|
|
645
|
- Number(translate.split('(').pop().split('p').shift() || 0),
|
|
|
646
|
- );
|
|
|
647
|
- let widget = translateNum - tabsDom?.offsetWidth;
|
|
|
648
|
- if (widget < 0) {
|
|
|
649
|
- widget = 0;
|
|
|
650
|
- setScroll(SCROLL.start);
|
|
|
651
|
- } else {
|
|
|
652
|
- setScroll(SCROLL.middle);
|
|
|
653
|
- }
|
|
|
654
|
- tabsDom.style.cssText = 'transform: translate(' + -widget + 'px,0px);';
|
|
|
655
|
- };
|
|
|
656
|
-
|
|
|
657
|
- const scrollNext = () => {
|
|
|
658
|
- const tabsDom: any = document?.getElementById('quickSearchTabs');
|
|
|
659
|
- const translate = tabsDom.style?.transform;
|
|
|
660
|
- const translateNum = Math.abs(
|
|
|
661
|
- Number(translate.split('(').pop().split('p').shift() || 0),
|
|
|
662
|
- );
|
|
|
663
|
- let widget = translateNum + tabsDom?.offsetWidth;
|
|
|
664
|
- if (widget > Math.abs(tabsDom?.offsetWidth - tabsDom?.scrollWidth)) {
|
|
|
665
|
- widget = Math.abs(tabsDom?.offsetWidth - tabsDom?.scrollWidth);
|
|
|
666
|
- setScroll(SCROLL.end);
|
|
|
667
|
- } else {
|
|
|
668
|
- setScroll(SCROLL.middle);
|
|
|
669
|
- }
|
|
|
670
|
- tabsDom.style.cssText = 'transform: translate(' + -widget + 'px,0px);';
|
|
|
671
|
- };
|
|
|
672
|
-
|
|
|
673
|
- useEffect(() => {
|
|
|
674
|
- getQuickSearchScroll();
|
|
|
675
|
- });
|
|
|
676
|
-
|
|
|
677
|
- useEffect(() => {
|
|
|
678
|
- if (!tabActiveCode) {
|
|
|
679
|
- return;
|
|
|
680
|
- }
|
|
|
681
|
- const idx = list.findIndex((val: any) => val.code === tabActiveCode);
|
|
|
682
|
- const tabsDom: any = document?.getElementById('quickSearchTabs');
|
|
|
683
|
- if (idx === 0) {
|
|
|
684
|
- tabsDom.style.cssText = 'transform: translate(0px,0px);';
|
|
|
685
|
- }
|
|
|
686
|
- }, [tabActiveCode]);
|
|
|
687
|
-
|
|
|
688
|
- return (
|
|
|
689
|
- <div
|
|
|
690
|
- className={'qx-view-quick-search-container'}
|
|
|
691
|
- style={{
|
|
|
692
|
- padding: tabsIcon ? '0 20px' : 0,
|
|
|
693
|
- }}
|
|
|
694
|
- >
|
|
|
695
|
- {tabsIcon && (
|
|
|
696
|
- <Button
|
|
|
697
|
- className={'left-button'}
|
|
|
698
|
- type="text"
|
|
|
699
|
- icon={
|
|
|
700
|
- <QxIcon type={'icon-tag-left-translate'} style={{ fontSize: 10 }} />
|
|
|
701
|
- }
|
|
|
702
|
- disabled={scroll == SCROLL.start}
|
|
|
703
|
- onClick={scrollPrev}
|
|
|
704
|
- />
|
|
|
705
|
- )}
|
|
|
706
|
- <div id="quickSearchTabs" className="qx-view-quick-search">
|
|
|
707
|
- {list.map((pane: any, index: number) =>
|
|
|
708
|
- pane.title && pane.title.length > 6 ? (
|
|
|
709
|
- <Popover key={pane.code} content={pane.title} title={null}>
|
|
|
710
|
- <div
|
|
|
711
|
- key={pane.code}
|
|
|
712
|
- className={`qx-view-quick-search__item ${
|
|
|
713
|
- tabActiveCode === pane.code ? 'selected' : null
|
|
|
714
|
- }`}
|
|
|
715
|
- onClick={(e) => handleClick(pane.code, index, e)}
|
|
|
716
|
- >
|
|
|
717
|
- {pane.title.substring(0, 5) + '...'}
|
|
|
718
|
- </div>
|
|
|
719
|
- </Popover>
|
|
|
720
|
- ) : (
|
|
|
721
|
- <div
|
|
|
722
|
- key={pane.code}
|
|
|
723
|
- className={`qx-view-quick-search__item ${
|
|
|
724
|
- tabActiveCode === pane.code ? 'selected' : null
|
|
|
725
|
- }`}
|
|
|
726
|
- onClick={(e) => handleClick(pane.code, index, e)}
|
|
|
727
|
- >
|
|
|
728
|
- {pane.title}
|
|
|
729
|
- </div>
|
|
|
730
|
- ),
|
|
|
731
|
- )}
|
|
|
732
|
- </div>
|
|
|
733
|
- {tabsIcon && (
|
|
|
734
|
- <Button
|
|
|
735
|
- className={'right-button'}
|
|
|
736
|
- type="text"
|
|
|
737
|
- icon={
|
|
|
738
|
- <QxIcon
|
|
|
739
|
- type={'icon-tag-right-translate'}
|
|
|
740
|
- style={{ fontSize: 10 }}
|
|
|
741
|
- />
|
|
|
742
|
- }
|
|
|
743
|
- disabled={scroll == SCROLL.end}
|
|
|
744
|
- onClick={scrollNext}
|
|
|
745
|
- />
|
|
|
746
|
- )}
|
|
|
747
|
- </div>
|
|
|
748
|
- );
|
|
|
749
|
-};
|
|
|
750
|
-
|
|
|
751
|
-export { QxSearchForm, QxRuntimeTable, QxRuntimeTree, QxQuickSearchTabs }; |
12
|
+export { QxSearchForm }; |