aldehyde 0.2.74 → 0.2.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/lib/controls/action/index.d.ts.map +1 -1
  2. package/lib/controls/action/index.js.map +1 -1
  3. package/lib/controls/action/utils.d.ts.map +1 -1
  4. package/lib/controls/action/utils.js +13 -20
  5. package/lib/controls/action/utils.js.map +1 -1
  6. package/lib/custom-page/custom-page-router.d.ts.map +1 -1
  7. package/lib/custom-page/custom-page-router.js +0 -1
  8. package/lib/custom-page/custom-page-router.js.map +1 -1
  9. package/lib/form/dtmpl-form.d.ts.map +1 -1
  10. package/lib/form/dtmpl-form.js.map +1 -1
  11. package/lib/import/excel-import.d.ts.map +1 -1
  12. package/lib/import/excel-import.js +45 -37
  13. package/lib/import/excel-import.js.map +1 -1
  14. package/lib/module/dtmpl-view-card.js +1 -1
  15. package/lib/module/dtmpl-view-card.js.map +1 -1
  16. package/lib/routable/ttmpl-route.d.ts +2 -4
  17. package/lib/routable/ttmpl-route.d.ts.map +1 -1
  18. package/lib/routable/ttmpl-route.js +20 -128
  19. package/lib/routable/ttmpl-route.js.map +1 -1
  20. package/lib/table/act-table.d.ts.map +1 -1
  21. package/lib/table/act-table.js.map +1 -1
  22. package/lib/table/query-table.js +1 -1
  23. package/lib/table/query-table.js.map +1 -1
  24. package/lib/tmpl/hc-data-source.d.ts +2 -1
  25. package/lib/tmpl/hc-data-source.d.ts.map +1 -1
  26. package/lib/tmpl/hc-data-source.js +11 -0
  27. package/lib/tmpl/hc-data-source.js.map +1 -1
  28. package/lib/tmpl/hcservice-v3.d.ts +2 -0
  29. package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
  30. package/lib/tmpl/hcservice-v3.js +30 -7
  31. package/lib/tmpl/hcservice-v3.js.map +1 -1
  32. package/lib/tmpl/interface.d.ts +13 -5
  33. package/lib/tmpl/interface.d.ts.map +1 -1
  34. package/lib/tmpl/interface.js.map +1 -1
  35. package/lib/tree/act-tree.d.ts +40 -0
  36. package/lib/tree/act-tree.d.ts.map +1 -1
  37. package/lib/tree/act-tree.js +119 -112
  38. package/lib/tree/act-tree.js.map +1 -1
  39. package/lib/tree/index.css +21 -0
  40. package/lib/tree/tmpl-tree.d.ts +61 -0
  41. package/lib/tree/tmpl-tree.d.ts.map +1 -1
  42. package/lib/tree/tmpl-tree.js +341 -481
  43. package/lib/tree/tmpl-tree.js.map +1 -1
  44. package/lib/tree/tree-node.d.ts +22 -0
  45. package/lib/tree/tree-node.d.ts.map +1 -0
  46. package/lib/tree/tree-node.js +62 -0
  47. package/lib/tree/tree-node.js.map +1 -0
  48. package/lib/tree/tree-utils.d.ts +55 -0
  49. package/lib/tree/tree-utils.d.ts.map +1 -0
  50. package/lib/tree/tree-utils.js +142 -0
  51. package/lib/tree/tree-utils.js.map +1 -0
  52. package/package.json +1 -1
  53. package/src/aldehyde/controls/action/index.tsx +1 -0
  54. package/src/aldehyde/controls/action/utils.tsx +14 -20
  55. package/src/aldehyde/custom-page/custom-page-router.tsx +0 -1
  56. package/src/aldehyde/form/dtmpl-form.tsx +0 -1
  57. package/src/aldehyde/import/excel-import.tsx +42 -35
  58. package/src/aldehyde/module/dtmpl-view-card.tsx +1 -1
  59. package/src/aldehyde/routable/ttmpl-route.tsx +24 -154
  60. package/src/aldehyde/table/act-table.tsx +1 -0
  61. package/src/aldehyde/table/query-table.tsx +1 -1
  62. package/src/aldehyde/tmpl/hc-data-source.tsx +11 -1
  63. package/src/aldehyde/tmpl/hcservice-v3.tsx +29 -7
  64. package/src/aldehyde/tmpl/interface.tsx +14 -5
  65. package/src/aldehyde/tree/act-tree.tsx +149 -111
  66. package/src/aldehyde/tree/index.css +21 -0
  67. package/src/aldehyde/tree/tmpl-tree.tsx +397 -480
  68. package/src/aldehyde/tree/tree-node.tsx +78 -0
  69. package/src/aldehyde/tree/tree-utils.tsx +166 -0
@@ -1,480 +1,397 @@
1
- // import React from 'react'
2
- // import {Avatar, Button, Card, Col, Input, Popconfirm, Popover, Row, Space, Tooltip, Tree, Typography} from 'antd';
3
- // import {DtmplEditPage, HydrocarbonService} from "aldehyde";
4
- // import './index.css'
5
- // import {
6
- // ReloadOutlined,
7
- // BlockOutlined,
8
- // DeleteOutlined,
9
- // DeleteTwoTone,
10
- // DeploymentUnitOutlined,
11
- // DownOutlined,
12
- // EditOutlined,
13
- // FileSyncOutlined,
14
- // PlusOutlined,HolderOutlined,CopyOutlined
15
- // } from '@ant-design/icons';
16
- // import {DataNode, TmplField} from "../tmpl-interface";
17
- // import TreeNode from "./tree-node";
18
- // import {TmplGroupDragTreeNode} from './../utils/dnd-service'
19
- // import TreeUtils from "./tree-utils";
20
- // import HydrogenConstant from "../hydrogen-constant";
21
- // import {TrtmplNodeConfig} from "../mstruc-interface";
22
- // import Hcservice from "../utils/hcservice";
23
- // import Scrollbars from 'react-custom-scrollbars';
24
- // import ModelStrucV3 from "../utils/model-struc-v3";
25
- //
26
- // const {Text, Title} = Typography
27
- //
28
- // interface ModuleGroupTreeProps {
29
- // readOnly:boolean,
30
- // titleClickedKey?: string,
31
- // onEditPage?:(moduleCode:string,moduleName:string,moduleType:string,pageCode?:string)=>void,
32
- // onPageChange?: () => void,
33
- // draggable?: boolean,
34
- // searchValue: string,
35
- // onChangeSearchValue: (string) => void,
36
- // onClickPageTmpl?: (title: string, code: string) => void,
37
- // }
38
- //
39
- // interface ModuleGroupTreeState {
40
- // data?: DataNode[],
41
- // expandedKeys: string[],
42
- // loadedKeys: string[],
43
- // loading: boolean,
44
- // drawSourceId: string,
45
- // showDraw: boolean,
46
- // drawTitle: string,
47
- // drawCode: string,
48
- // drawMainCode: string,
49
- // parentNodeData: DataNode,
50
- // currentNodeData: DataNode,
51
- // anyValue: boolean,
52
- // currentModelKey: string | number,
53
- // currentPageKey: string | number,
54
- // }
55
- //
56
- //
57
- // class TmplTree extends React.PureComponent<ModuleGroupTreeProps, ModuleGroupTreeState> {
58
- //
59
- // state = {
60
- // data: [],
61
- // expandedKeys: [],
62
- // loadedKeys: [],
63
- // loading: false,
64
- // drawSourceId: undefined,
65
- // showDraw: false,
66
- // drawTitle: undefined,
67
- // currentEditKey: undefined,
68
- // drawCode: undefined,
69
- // drawMainCode: undefined,
70
- // parentNodeData: undefined,
71
- // currentNodeData:undefined,
72
- // anyValue: false,
73
- // currentModelKey: undefined,
74
- // currentPageKey: undefined,
75
- // }
76
- //
77
- // static gtmplModuleCode = "7JXJelyRv2";
78
- // static moduleModuleCode = "5uLpK3DwJi";
79
- //
80
- // static defaultProps = {
81
- // draggable: false,
82
- // readOnly:false
83
- // }
84
- //
85
- //
86
- // doAdd = (parent: DataNode,moduleType:string) => {
87
- // const {onEditPage}=this.props;
88
- // onEditPage?onEditPage(parent.code,parent.name,moduleType,undefined):
89
- // this.setState({
90
- // showDraw: true,
91
- // drawMainCode: parent.code,
92
- // drawSourceId: this.getGtmplRatmplSourceId(moduleType),
93
- // parentNodeData: parent,
94
- // currentNodeData:undefined,
95
- // drawCode: undefined,
96
- // drawTitle: `添加-模块【${parent.name}】的页面`,
97
- // currentModelKey: parent.key,
98
- // })
99
- // }
100
- //
101
- // getGtmplRatmplSourceId=(moduleType:string)=>{
102
- // return moduleType=='SQL统计模型'?HydrogenConstant.moduleGstmplRatmpl.sourceId:moduleType=='SQL查询模型'?HydrogenConstant.moduleGqtmplRatmpl.sourceId: HydrogenConstant.moduleGtmplRatmpl.sourceId;
103
- // }
104
- //
105
- // doEdit = (current: DataNode, parent: DataNode,moduleType:string) => {
106
- // const {onEditPage}=this.props;
107
- // onEditPage?onEditPage(parent.code,parent.name,moduleType,current.code):
108
- // this.setState({
109
- // showDraw: true,
110
- // drawSourceId:this.getGtmplRatmplSourceId(moduleType),
111
- // drawMainCode: parent.code,
112
- // drawCode: current.code,
113
- // parentNodeData: parent,
114
- // currentNodeData:current,
115
- // drawTitle: `编辑-页面【${current.name}】`,
116
- // currentPageKey: current.key,
117
- // })
118
- // }
119
- //
120
- // doDelete = async (node: DataNode) => {
121
- // let res = await HydrocarbonService.deleteByCode(null, HydrogenConstant.moduleGtmplRatmpl.sourceId, [node.code]);
122
- // await this.onChange(node);
123
- // }
124
- //
125
- // drawSubmited = async () => {
126
- // this.onChange();
127
- // this.doClose();
128
- // }
129
- //
130
- // doClose = () => {
131
- // this.setState({
132
- // showDraw: false,
133
- // drawSourceId: undefined,
134
- // parentNodeData: undefined,
135
- // })
136
- // }
137
- //
138
- //
139
- // node = {
140
- // key: 'a0001',
141
- // title: "版块",
142
- // isLeaf: false,
143
- // level: 0,
144
- // ratmplSourceId: undefined,
145
- // children: [],
146
- // code: null
147
- // };
148
- // completeModuleAvatar = (res: object) => {
149
- // let mtype = res['模型类型'];
150
- // let astring = null;
151
- // let modelType = undefined;
152
- // let backgroundColor = null;
153
- // switch (mtype) {
154
- // case '普通模型':
155
- // modelType = '普通模型';
156
- // //astring = <DeploymentUnitOutlined style={{fontSize: '20px', color: 'green'}}/>
157
- // //backgroundColor = '#fff';
158
- // // astring='o';
159
- // backgroundColor = '#85a5ff';
160
- // break;
161
- // case 'SQL统计模型':
162
- // modelType = 'SQL统计模型';
163
- // // astring = <DeploymentUnitOutlined style={{fontSize: '20px', color: '#2f54eb'}}/>
164
- // // backgroundColor = '#fff';
165
- // // astring='C';
166
- // backgroundColor = "#2f54eb";
167
- // break;
168
- // case 'SQL查询模型':
169
- // modelType = 'SQL查询模型';
170
- //
171
- // //astring = <DeploymentUnitOutlined style={{fontSize: '20px', color: '#2f54eb'}}/>
172
- // //backgroundColor = '#fff';
173
- // //astring='Q';
174
- // backgroundColor = "#2f54eb";
175
- //
176
- // break;
177
- // case '文档模型':
178
- // modelType = '文档模型';
179
- // //astring = <DeploymentUnitOutlined style={{fontSize: '20px', color: '#52c41a'}}/>
180
- // //backgroundColor = '#fff';
181
- // backgroundColor = "#52c41a";
182
- // //astring='D';
183
- // break;
184
- // case '服务模型':
185
- // modelType = '服务模型';
186
- // // astring = <DeploymentUnitOutlined style={{fontSize: '20px', color: '#722ed1'}}/>
187
- // //backgroundColor = '#fff';
188
- // //astring='S';
189
- // backgroundColor = "#722ed1";
190
- // break;
191
- // default:
192
- // // astring='A';
193
- // astring = <DeploymentUnitOutlined style={{fontSize: '20px', color: 'red'}}/>
194
- // backgroundColor = '#fff';
195
- // backgroundColor = "red";
196
- // break;
197
- // }
198
- //
199
- // return <Tooltip placement={'topLeft'} title={modelType}>
200
- // <Avatar shape="square" size={10} style={{
201
- // backgroundColor,
202
- // height: 22,
203
- // width: 6,
204
- // // paddingTop:6
205
- // }}>{astring}</Avatar></Tooltip>
206
- //
207
- //
208
- // }
209
- //
210
- // completeGtmplAvatar(res: object) {
211
- //
212
- // let content = null;
213
- // let avatarBackgroundColor = null;
214
- // let hasMenu = res['二级菜单'];
215
- //
216
- // return <Popover content={content}> <Avatar shape="square" size={10} style={{
217
- // backgroundColor: '#fff',
218
- // height: 20,
219
- // width: 20
220
- // }}><BlockOutlined style={{fontSize: '20px', color: hasMenu ? "#389e0d" : '#ffc53d'}}/></Avatar></Popover>
221
- //
222
- // }
223
- //
224
- // async componentDidMount() {
225
- // const {} = this.props
226
- // this.setState({
227
- // loading: true
228
- // })
229
- // //模块
230
- // await this.refresh();
231
- // }
232
- //
233
- // toModuleNode = (e: object, loadedKeys: (string | number)[], gtmplRes: object[]) => {
234
- // const {onClickPageTmpl,readOnly} = this.props
235
- // let moduleCode = e['唯一编码'];
236
- //
237
- // let module: DataNode = {
238
- // key: moduleCode,
239
- // code: moduleCode,
240
- // name: e['名称'],
241
- // config: null,
242
- // level: 1,
243
- // order: e['所属模块排序']
244
- // }
245
- // let moduleType=e['模型类型'];
246
- // module.title =<>{readOnly?module.name:<Popover placement="topLeft" zIndex={100} content={<><Space>
247
- // <Button size={'small'} onClick={() => {
248
- // this.doSync(moduleCode);
249
- // }}><FileSyncOutlined
250
- // style={{color: 'green'}}/>同步默认页面</Button>
251
- // <Button onClick={() => {
252
- // this.doAdd(module,moduleType);
253
- // }
254
- // } size={'small'}><PlusOutlined/>创建页面</Button>
255
- // </Space></>} arrow={false}>{module.name}
256
- // {/*<HolderOutlined style={{color:'#bfbfbf'}} />*/}
257
- // </Popover>}</>;
258
- // module.children = [];
259
- //
260
- // module.avatar = this.completeModuleAvatar(e);
261
- // if (gtmplRes) {
262
- // for (let res of gtmplRes) {
263
- // if (moduleCode != res['所属模块编码']) {
264
- // continue;
265
- // }
266
- // let gtmpl: DataNode = {
267
- // key: res['唯一编码'],
268
- // code: res['唯一编码'],
269
- // name: res['名称'],
270
- // config: null,
271
- // level: 2,
272
- // isLeaf: true
273
- // };
274
- //
275
- // let hasMenu = res['二级菜单'] ? true : false;
276
- // gtmpl.title = <>{readOnly?gtmpl.name:<Popover zIndex={100} content={<><Space>
277
- // {/*<Button onClick={() => {*/}
278
- // {/* onClickPageTmpl(gtmpl.name, gtmpl.code);*/}
279
- // {/* this.setState({*/}
280
- // {/* currentPageKey: gtmpl.key*/}
281
- // {/* })*/}
282
- // {/*}} size={'small'}>查看菜单项</Button>*/}
283
- // <Button onClick={() => {
284
- // this.doEdit(gtmpl, {...module},moduleType);
285
- // this.setState({
286
- // currentPageKey: gtmpl.key
287
- // })
288
- // }} size={'small'}><EditOutlined style={{color: 'blue'}}/>编辑</Button>
289
- //
290
- // <Popconfirm placement="topLeft" title={'确认复制吗?'}
291
- // onConfirm={() => this.doCopy(gtmpl.code)}
292
- // okText="确定" cancelText="取消">
293
- // <Button size={'small'}><CopyOutlined
294
- // style={{color: 'blue'}}/>复制</Button>
295
- // </Popconfirm>
296
- // < Popconfirm placement="topLeft" title={hasMenu ? `页面模板会连同二级菜单一起删除` : `删除页面模板【${e['名称']}】吗?`}
297
- // onConfirm={() => {
298
- // this.doDelete(gtmpl);
299
- // this.setState({currentModelKey: moduleCode})
300
- // }
301
- // }
302
- // okText="确定" cancelText="取消">
303
- // <Tooltip>
304
- // <Button size={'small'} danger={true}>{hasMenu ?
305
- // <DeleteTwoTone twoToneColor={'#a8071a'}/> : <DeleteOutlined/>}</Button>
306
- // </Tooltip>
307
- // </Popconfirm>
308
- // </Space></>} arrow={false}>{gtmpl.name}
309
- // {/*<HolderOutlined style={{color:'#bfbfbf'}} />*/}
310
- // </Popover>}</>;
311
- //
312
- // gtmpl.avatar = this.completeGtmplAvatar(res);
313
- // gtmpl['hasMenu']=hasMenu;
314
- // module.children.push(gtmpl);
315
- // }
316
- //
317
- // }
318
- // return module;
319
- //
320
- // }
321
- //
322
- // async refresh() {
323
- // const {moduleTreeSttmpl} = this.props;
324
- // this.setState({
325
- // loading: true,
326
- // })
327
- // let loadedKeys = [];
328
- // let res = await ModelStrucV3.get(TmplTree.moduleModuleCode, {depth: 1},);
329
- // let gtmplRes = await ModelStrucV3.get(TmplTree.gtmplModuleCode, {depth: 1},);
330
- //
331
- // let data: DataNode[] = [];
332
- // if (res.entities) {
333
- // for (let e of res.entities) {
334
- // data.push(this.toModuleNode(e, loadedKeys, gtmplRes ? gtmplRes.entities : []));
335
- // }
336
- // }
337
- // //完善 avatar
338
- // //this.completeAvatar(data);
339
- // this.setState({
340
- // data,
341
- // loading: false,
342
- // loadedKeys
343
- // })
344
- // }
345
- //
346
- // async componentWillUnmount() {
347
- //
348
- // }
349
- //
350
- // onChange = async (node?:DataNode) => {
351
- // const {expandedKeys,parentNodeData,currentNodeData} = this.state;
352
- // const {onPageChange}=this.props;
353
- // let nood=node?node:currentNodeData;
354
- // if(nood && nood['hasMenu'] && onPageChange ){
355
- // onPageChange();
356
- // }
357
- // await this.refresh();
358
- // this.setState({expandedKeys: [parentNodeData.key, ...expandedKeys]})
359
- // }
360
- //
361
- // onExpand = (expandedKeys) => {
362
- // this.setState({
363
- // expandedKeys
364
- // })
365
- // }
366
- //
367
- //
368
- // doSync = async (moduleCode: string) => {
369
- // this.setState({
370
- // loading: true,
371
- // })
372
- // await Hcservice.doSync(moduleCode);
373
- // await this.refresh();
374
- // this.setState({
375
- // currentModelKey: moduleCode
376
- // })
377
- // }
378
- //
379
- // doCopy = async (code: string) => {
380
- // this.setState({
381
- // loading: true,
382
- // })
383
- // await Hcservice.doCopy(HydrogenConstant.groupTmpl.sourceId, code);
384
- // await this.refresh();
385
- // this.setState({
386
- // currentPageKey: code
387
- // })
388
- // }
389
- //
390
- //
391
- // render() {
392
- // const {draggable, searchValue, onChangeSearchValue,readOnly} = this.props;
393
- // const {
394
- // data, loadedKeys, loading, showDraw,
395
- // drawSourceId,
396
- // drawCode,
397
- // drawMainCode, drawTitle, currentModelKey, currentPageKey
398
- // } = this.state;
399
- // let treeData = data;
400
- // if (searchValue) {
401
- // treeData = TreeUtils.filterTree(data, searchValue);
402
- // }
403
- // return <>
404
- // <Row>
405
- // <Col span={24}>
406
- // <Card style={{marginBottom: 0, width: '100%'}} bordered={false}
407
- // bodyStyle={{padding: '4px 2px 4px 8px'}}>
408
- // <Row align="middle">
409
- // <Col span={6}>
410
- // <Avatar shape="square" size={10}
411
- // icon={<BlockOutlined style={{fontSize: '18px', color: '#389e0d'}}/>}
412
- // style={{backgroundColor: '#fff', height: 24, width: 20, paddingLeft: '10'}}/>
413
- // <span style={{fontSize: 18, fontWeight: 560}}>页面</span>
414
- // </Col>
415
- // <Col span={18}>
416
- // <Input.Search value={searchValue} allowClear placeholder="输入名称查找" onChange={(e) => {
417
- // onChangeSearchValue(e.target.value)
418
- // }} onSearch={(value) => {
419
- // this.refresh()
420
- // }} enterButton={<ReloadOutlined />}/>
421
- // </Col>
422
- // </Row>
423
- // </Card>
424
- // </Col>
425
- // </Row>
426
- // <Row>
427
- // <Col span={24}>
428
- // {treeData && treeData.length>0 ?
429
- // <Card bodyStyle={{padding: '4px 4px 4px 16px', height: '80vh', minWidth: '320px'}}
430
- // loading={loading}>
431
- // <Scrollbars style={{height: '80vh'}} autoHide autoHideTimeout={1000}>
432
- // <Tree defaultExpandAll={true} switcherIcon={<DownOutlined/>}
433
- // checkable={false}
434
- // loadedKeys={loadedKeys}
435
- // onExpand={this.onExpand}
436
- // showLine={false}
437
- // titleRender={(nodeData) => {
438
- // return draggable ?
439
- // <TmplGroupDragTreeNode currentActiveKey={[currentModelKey, currentPageKey]}
440
- // syncButtonTip={'更新默认页面'}
441
- // nodeData={nodeData}/> :
442
- // <TreeNode currentActiveKey={[currentModelKey, currentPageKey]}
443
- // syncButtonTip={'更新默认页面'}
444
- // nodeData={nodeData}></TreeNode>
445
- //
446
- // }}
447
- // treeData={treeData}
448
- // />
449
- // {/*{readOnly?null:*/}
450
- // {/*<Card style={{marginTop:24}} bodyStyle={{padding: '12px 6px 6px 6px'}}>*/}
451
- // {/* <Space direction="vertical">*/}
452
- // {/* <Title level={5}>【页面定义】使用说明</Title>*/}
453
- // {/* <span><Text*/}
454
- // {/* type="danger">1.模型生成页面:</Text><Text>鼠标悬停在【模型节点】的【名称】上,点击气泡卡片的【同步默认页面】按钮。</Text></span>*/}
455
- // {/* <span><Text*/}
456
- // {/* type="danger">2.创建页面:</Text><Text>鼠标悬停在【模型节点】的【名称】上,点击气泡卡片的【+创建页面】按钮,填写并保存右边弹出的抽屉页面。</Text></span>*/}
457
- // {/* <span><Text*/}
458
- // {/* type="danger">3.复制页面:</Text><Text>鼠标悬停在【页面节点】的【名称】上,点击气泡卡片的【复制】按钮。</Text></span>*/}
459
- // {/* </Space>*/}
460
- // {/*</Card>}*/}
461
- // </Scrollbars>
462
- // </Card>: <Card><Space><Text type={'danger'}>* 页面配置需基于模型。请先创建一个或多个模型。</Text>
463
- // <Button href={'#/application-workbench/carbon-model-def'} type={'primary'}><DeploymentUnitOutlined />模 型</Button></Space>
464
- // </Card>}
465
- // </Col>
466
- // </Row>
467
- //
468
- // {drawSourceId ? <DtmplEditPage title={drawTitle} maxColsOnRow={1} pageType={"drawer"} placement={'right'}
469
- // open={showDraw}
470
- // onCancel={this.doClose}
471
- // width={640} mainCode={drawMainCode}
472
- // sourceId={drawSourceId}
473
- // code={drawCode}
474
- // onOk={this.drawSubmited}/> : null}
475
- //
476
- // </>
477
- // }
478
- // }
479
- //
480
- // export default TmplTree
1
+ import React from 'react'
2
+ import {Button, Card, Col, Input, Popconfirm, Popover, Row, Space, Tooltip, Tree, Typography} from 'antd';
3
+ import {
4
+ AlignLeftOutlined,
5
+ DeleteOutlined,
6
+ EditOutlined,
7
+ PlusOutlined,
8
+ PlusSquareOutlined,
9
+ ReloadOutlined
10
+ } from '@ant-design/icons';
11
+ // import './index.css';
12
+ import Scrollbars from 'react-custom-scrollbars';
13
+ import {HydrocarbonService} from "../index";
14
+ import TreeUtils, {TtmplNodeConfig} from "./tree-utils";
15
+ import {TreeDataNode} from './tree-utils'
16
+
17
+ const {Text, Title} = Typography
18
+
19
+ interface TmplTreeProps {
20
+ ttmplNodeConfig: TtmplNodeConfig,
21
+ currentId?: string,
22
+ doEditSub?: (title:string,ratmplId: string, mainCode: string, code?: string) => void,
23
+ doViewSub?: (title:string,ratmplId: string, mainCode: string, code?: string) => void,
24
+ doEditRoot?: (title:string,code?: string) => void,
25
+ doViewRoot?: (title:string,code?: string) => void,
26
+ doDelete?: (ratmplId: string, code?: string) => void,
27
+ doAddSub?: (title:string,ratmplId: string, mainCode: string) => void,
28
+ }
29
+
30
+ interface TmplTreeState {
31
+ data?: TreeDataNode[],
32
+ expandedKeys?: string[],
33
+ loadedKeys?: string[],
34
+ loading?: boolean,
35
+ drawMainCode?: string,
36
+ parentNodeData?: TreeDataNode,
37
+ currentNodeData?: TreeDataNode,
38
+ rootAddable?: boolean,
39
+ searchValue?: string,
40
+ }
41
+
42
+
43
+ class TmplTree extends React.PureComponent<TmplTreeProps, TmplTreeState> {
44
+
45
+ state = {
46
+ data: [],
47
+ expandedKeys: [],
48
+ loadedKeys: [],
49
+ loading: false,
50
+ currentEditKey: undefined,
51
+ parentNodeData: undefined,
52
+ currentNodeData: undefined,
53
+ rootAddable: false,
54
+ searchValue: undefined,
55
+ }
56
+
57
+ static defaultProps = {
58
+ draggable: false,
59
+ readOnly: false
60
+ }
61
+
62
+ doDelete = async (node: TreeDataNode) => {
63
+ let {ttmplNodeConfig} = this.props;
64
+ let sourceId;
65
+ if (node.isLeaf) {
66
+ sourceId = ttmplNodeConfig.leafRatmplId;
67
+ } else {
68
+ sourceId = ttmplNodeConfig.branchRatmplId;
69
+ }
70
+ let res = await HydrocarbonService.deleteByCode(null, sourceId, [node.code]);
71
+ if(node.parent){
72
+ await this.reloadData(node.parent.code);
73
+ }
74
+
75
+ }
76
+
77
+ async componentDidMount() {
78
+ await this.refresh();
79
+ }
80
+
81
+ async componentDidUpdate(prevProps) {
82
+ debugger
83
+ let {ttmplNodeConfig: preTtmplNodeConfig} = prevProps;
84
+ let {ttmplNodeConfig} = this.props;
85
+ debugger
86
+ if (!ttmplNodeConfig || (preTtmplNodeConfig && ttmplNodeConfig.id == preTtmplNodeConfig.id)) {
87
+ return;
88
+ }
89
+ await this.refresh();
90
+ }
91
+
92
+ async refresh() {
93
+ debugger
94
+ const {ttmplNodeConfig} = this.props;
95
+ if (!ttmplNodeConfig) {
96
+ return;
97
+ }
98
+ this.setState({
99
+ loading: true,
100
+ })
101
+ //let loadedKeys = [];
102
+ let data = await this.loadRootNodeData();
103
+ this.setState({
104
+ searchValue: null,
105
+ data,
106
+ rootAddable: ttmplNodeConfig.rootLTmplConfig.buttons.indexOf("dtmplAdd") > 0,
107
+ loading: false,
108
+ })
109
+ }
110
+
111
+ loadRootNodeData = async () => {
112
+ const {ttmplNodeConfig} = this.props;
113
+ let data = await TreeUtils.loadRootNodeData(ttmplNodeConfig);
114
+ return data;
115
+ }
116
+
117
+ async componentWillUnmount() {
118
+
119
+ }
120
+
121
+ onExpand = async (expandedKeys, current: { expanded: boolean, node: TreeDataNode }) => {
122
+ const {ttmplNodeConfig} = this.props;
123
+ const {data} = this.state;
124
+ if (current.expanded) {
125
+ await TreeUtils.pushSameCodeNodeData([current.node], ttmplNodeConfig);
126
+ }
127
+ this.setState({
128
+ data: [...data],
129
+ expandedKeys
130
+ })
131
+ }
132
+
133
+ onClickNode = (dataNode: TreeDataNode) => {
134
+ const {doEditRoot, doViewRoot, doViewSub, doEditSub, ttmplNodeConfig} = this.props;
135
+ if (dataNode.parent) {//说明是sub
136
+ if (dataNode.isLeaf) {
137
+ if (ttmplNodeConfig.leafLTmplConfig.buttons.indexOf("dtmplEdit") > 0) {
138
+ doEditSub(ttmplNodeConfig.leafTitle,ttmplNodeConfig.leafRatmplId, dataNode.parent.code, dataNode.code);
139
+ } else if (ttmplNodeConfig.leafLTmplConfig.buttons.indexOf("detail") > 0) {
140
+ doViewSub(ttmplNodeConfig.leafTitle,ttmplNodeConfig.leafRatmplId, dataNode.parent.code, dataNode.code);
141
+ }
142
+ } else {
143
+ if (ttmplNodeConfig.branchLTmplConfig.buttons.indexOf("dtmplEdit") > 0) {
144
+ doEditSub(ttmplNodeConfig.branchTitle,ttmplNodeConfig.branchRatmplId, dataNode.parent.code, dataNode.code);
145
+ } else if (ttmplNodeConfig.branchLTmplConfig.buttons.indexOf("detail") > 0) {
146
+ doViewSub(ttmplNodeConfig.branchTitle,ttmplNodeConfig.branchRatmplId, dataNode.parent.code, dataNode.code);
147
+ }
148
+ }
149
+ } else {//说明是root
150
+ //判断是否允许编辑
151
+ if (ttmplNodeConfig.rootLTmplConfig.buttons.indexOf("dtmplEdit") > 0) {
152
+ doEditRoot(ttmplNodeConfig.branchTitle,dataNode.code);
153
+ } else if (ttmplNodeConfig.rootLTmplConfig.buttons.indexOf("detail") > 0) {
154
+ doViewRoot(ttmplNodeConfig.branchTitle,dataNode.code);
155
+ }
156
+ }
157
+ }
158
+
159
+ stopPropagation = (e) => {
160
+ if (e.stopPropagation) { //如果提供了事件对象,则这是一个非IE浏览器
161
+ e.stopPropagation();
162
+ } else {//兼容IE的方式来取消事件冒泡
163
+ window.event.cancelBubble = true;
164
+ }
165
+ }
166
+
167
+ reloadData = async (branchCode: string) => {
168
+ const {ttmplNodeConfig} = this.props;
169
+ const {data, expandedKeys} = this.state;
170
+ let newData;
171
+ if (branchCode == null) {//加载根
172
+ newData = await this.loadRootNodeData();
173
+ this.mergeRootData(data, newData);
174
+ this.setState({
175
+ data: newData
176
+ })
177
+ } else {//重新加载 await
178
+ //先找到树节点
179
+ let rdatas = [];
180
+ this.searchNode(data, branchCode, rdatas);
181
+ await TreeUtils.pushSameCodeNodeData(rdatas, ttmplNodeConfig);
182
+ let newExpandeds = [];
183
+ for (let d of rdatas) {
184
+ newExpandeds.push(d.key)
185
+ }
186
+ this.setState({
187
+ expandedKeys: [...expandedKeys, ...newExpandeds],
188
+ data: [...data]
189
+ })
190
+ }
191
+ }
192
+
193
+ mergeRootData = (data, newData) => {
194
+ if (newData && data) {
195
+ for (let nd of newData) {
196
+ for (let d of data) {
197
+ if (nd.code == d.code) {
198
+ nd.children = d.children;
199
+ break;
200
+ }
201
+ }
202
+ }
203
+ }
204
+ };
205
+
206
+ searchNode = (data: TreeDataNode[], brachCode: string, result: TreeDataNode[]) => {
207
+ if (!data) {
208
+ return;
209
+ }
210
+ for (let d of data) {
211
+ if (d.code == brachCode) {
212
+ result.push(d);
213
+ break;
214
+ } else if (d.children.length > 0) {//继续寻找
215
+ this.searchNode(d.children, brachCode, result);
216
+ }
217
+ }
218
+ }
219
+
220
+ getDeleteButton = (sourceId, code) => {
221
+ const {doDelete} = this.props;
222
+ return <div onClick={(e) => {
223
+ this.stopPropagation(e)
224
+ }}>< Popconfirm placement="topLeft" title={`确定要删除吗?`}
225
+ onConfirm={() => {
226
+ doDelete(sourceId, code);
227
+ }}
228
+ okText="确定" cancelText="取消">
229
+ <Tooltip>
230
+ <Button size={'small'} danger={true}>
231
+ <DeleteOutlined/></Button>
232
+ </Tooltip>
233
+ </Popconfirm></div>
234
+ }
235
+
236
+ getAddButton = (title: string, icon: any, ratmplId: string, mainCode: any) => {
237
+ const {doAddSub} = this.props;
238
+ return <Button onClick={(e) => {
239
+ this.stopPropagation(e)
240
+ doAddSub(title,ratmplId, mainCode);
241
+ }} size={'small'}>{icon}{title}</Button>
242
+ }
243
+
244
+ packageTitle = (dataNode) => {
245
+ const {doEditRoot, doViewRoot, doViewSub, doEditSub, ttmplNodeConfig} = this.props;
246
+ let buttons = [];
247
+ if (dataNode.parent) {//说明是sub
248
+ if (dataNode.isLeaf) {
249
+ if (ttmplNodeConfig.leafLTmplConfig.buttons.indexOf("dtmplEdit") > 0) {
250
+ buttons.push(<Button onClick={(e) => {
251
+ this.stopPropagation(e)
252
+ doEditSub(ttmplNodeConfig.leafTitle,ttmplNodeConfig.leafRatmplId, dataNode.parent.code, dataNode.code);
253
+ }} size={'small'}><EditOutlined/>编辑</Button>);
254
+ }
255
+ if (ttmplNodeConfig.leafLTmplConfig.buttons.indexOf("detail") > 0) {
256
+ buttons.push(<Button onClick={(e) => {
257
+ this.stopPropagation(e)
258
+ doViewSub(ttmplNodeConfig.leafTitle,ttmplNodeConfig.leafRatmplId, dataNode.parent.code, dataNode.code);
259
+ }} size={'small'}><AlignLeftOutlined/>查看</Button>);
260
+ }
261
+ if (ttmplNodeConfig.leafLTmplConfig.buttons.indexOf("singleDelete") > 0) {
262
+ buttons.push(this.getDeleteButton(ttmplNodeConfig.leafRatmplId, dataNode.code)
263
+ );
264
+ }
265
+
266
+ } else if (ttmplNodeConfig.branchLTmplConfig) {
267
+ if (ttmplNodeConfig.branchLTmplConfig.buttons.indexOf("dtmplEdit") > 0) {
268
+ buttons.push(<Button onClick={(e) => {
269
+ this.stopPropagation(e)
270
+ doEditSub(ttmplNodeConfig.branchTitle,ttmplNodeConfig.branchRatmplId, dataNode.parent.code, dataNode.code);
271
+ }} size={'small'}><EditOutlined/>编辑</Button>);
272
+ }
273
+ if (ttmplNodeConfig.branchLTmplConfig.buttons.indexOf("detail") > 0) {
274
+ buttons.push(<Button onClick={(e) => {
275
+ this.stopPropagation(e)
276
+ doViewSub(ttmplNodeConfig.branchTitle,ttmplNodeConfig.branchRatmplId, dataNode.parent.code, dataNode.code);
277
+ }} size={'small'}><AlignLeftOutlined/>查看</Button>);
278
+
279
+ }
280
+
281
+ if (ttmplNodeConfig.branchLTmplConfig.buttons.indexOf("dtmplAdd") > 0) {
282
+ buttons.push(this.getAddButton(ttmplNodeConfig.branchTitle,
283
+ <PlusSquareOutlined/>, ttmplNodeConfig.branchRatmplId, dataNode.code)
284
+ );
285
+ }
286
+
287
+ if (ttmplNodeConfig.leafLTmplConfig.buttons.indexOf("dtmplAdd") > 0) {
288
+ buttons.push(this.getAddButton(ttmplNodeConfig.leafTitle,
289
+ <PlusOutlined/>, ttmplNodeConfig.leafRatmplId, dataNode.code)
290
+ );
291
+ }
292
+ if (ttmplNodeConfig.branchLTmplConfig.buttons.indexOf("singleDelete") > 0) {
293
+ buttons.push(this.getDeleteButton(ttmplNodeConfig.branchRatmplId, dataNode.code));
294
+ }
295
+ }
296
+ } else {//说明是root
297
+ //判断是否允许编辑
298
+ if (ttmplNodeConfig.rootLTmplConfig.buttons.indexOf("dtmplEdit") > 0) {
299
+ buttons.push(<Button onClick={(e) => {
300
+ this.stopPropagation(e)
301
+ doEditRoot(ttmplNodeConfig.branchTitle,dataNode.code);
302
+ }} size={'small'}><EditOutlined style={{color: 'blue'}}/>编辑</Button>);
303
+ }
304
+ if (ttmplNodeConfig.rootLTmplConfig.buttons.indexOf("detail") > 0) {
305
+ buttons.push(<Button onClick={(e) => {
306
+ this.stopPropagation(e)
307
+ doViewRoot(ttmplNodeConfig.branchTitle,dataNode.code);
308
+ }} size={'small'}><AlignLeftOutlined/>查看</Button>);
309
+ }
310
+ if (ttmplNodeConfig.branchLTmplConfig) {
311
+ if (ttmplNodeConfig.rootLTmplConfig.buttons.indexOf("dtmplAdd") > 0) {
312
+ buttons.push(this.getAddButton(ttmplNodeConfig.branchTitle,
313
+ <PlusSquareOutlined/>, ttmplNodeConfig.branchRatmplId, dataNode.code)
314
+ );
315
+ }
316
+ }
317
+ if (ttmplNodeConfig.leafLTmplConfig.buttons.indexOf("dtmplAdd") > 0) {
318
+ buttons.push(this.getAddButton(ttmplNodeConfig.leafTitle,
319
+ <PlusOutlined/>, ttmplNodeConfig.leafRatmplId, dataNode.code)
320
+ );
321
+ }
322
+
323
+ if (ttmplNodeConfig.rootLTmplConfig.buttons.indexOf("singleDelete") > 0) {
324
+ buttons.push(this.getDeleteButton(ttmplNodeConfig.branchRatmplId, dataNode.code));
325
+ }
326
+ }
327
+
328
+ if (buttons.length == 0) {
329
+ return dataNode.title;
330
+ } else {
331
+ return <Popover
332
+ zIndex={100} content={<><Space>{buttons}</Space></>} arrow={false}>
333
+ {dataNode.title}
334
+ </Popover>
335
+ }
336
+
337
+ }
338
+
339
+ render() {
340
+ const {doEditRoot,ttmplNodeConfig} = this.props;
341
+ const {
342
+ data, loading, expandedKeys, rootAddable, searchValue
343
+ } = this.state;
344
+ let treeData = data;
345
+ if (searchValue) {
346
+ treeData = TreeUtils.filterTree(data, searchValue);
347
+ }
348
+ return <>
349
+ <Row>
350
+ <Col span={24}>
351
+ <Card style={{marginBottom: 0, width: '100%'}} bordered={false}
352
+ bodyStyle={{padding: '4px 2px 4px 8px'}}>
353
+ <Row align="middle">
354
+ <Col span={8}>
355
+ {rootAddable && doEditRoot ?
356
+ <Button type={'link'} onClick={() => doEditRoot(ttmplNodeConfig.branchTitle)}>添加</Button> : null}
357
+ </Col>
358
+ <Col span={16}>
359
+ <Input.Search value={searchValue} allowClear placeholder="输入查找内容" onChange={(e) => {
360
+ this.setState({
361
+ searchValue: e.target.value
362
+ })
363
+ }} onSearch={(value) => {
364
+ this.refresh()
365
+ }} enterButton={<ReloadOutlined/>}/>
366
+ </Col>
367
+ </Row>
368
+ </Card>
369
+ </Col>
370
+ </Row>
371
+ <Row>
372
+ <Col span={24}>
373
+ <Card bodyStyle={{padding: '4px 4px 4px 16px', height: '80vh', minWidth: '320px'}}
374
+ loading={loading}>
375
+ {treeData.length == 0 ? '没有找到数据' :
376
+ <Scrollbars style={{height: '80vh'}} autoHide autoHideTimeout={1000}>
377
+ <Tree blockNode
378
+ checkable={false}
379
+ expandedKeys={expandedKeys}
380
+ onExpand={this.onExpand}
381
+ titleRender={(nodeData) => {
382
+ return <div
383
+ onClick={() => this.onClickNode(nodeData)}>{this.packageTitle(nodeData)}</div>
384
+ }}
385
+ treeData={treeData}
386
+ />
387
+ </Scrollbars>}
388
+ </Card>
389
+ </Col>
390
+ </Row>
391
+ </>
392
+ }
393
+
394
+
395
+ }
396
+
397
+ export default TmplTree