aldehyde 0.2.73 → 0.2.75

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 (87) hide show
  1. package/lib/custom-page/custom-page-router.d.ts.map +1 -1
  2. package/lib/custom-page/custom-page-router.js +0 -1
  3. package/lib/custom-page/custom-page-router.js.map +1 -1
  4. package/lib/detail/view/act-dtmpl-view.d.ts +1 -0
  5. package/lib/detail/view/act-dtmpl-view.d.ts.map +1 -1
  6. package/lib/detail/view/act-dtmpl-view.js +2 -2
  7. package/lib/detail/view/act-dtmpl-view.js.map +1 -1
  8. package/lib/detail/view/modal-dtmpl-view.d.ts +4 -3
  9. package/lib/detail/view/modal-dtmpl-view.d.ts.map +1 -1
  10. package/lib/detail/view/modal-dtmpl-view.js +2 -6
  11. package/lib/detail/view/modal-dtmpl-view.js.map +1 -1
  12. package/lib/form/dtmpl-form.d.ts.map +1 -1
  13. package/lib/form/dtmpl-form.js.map +1 -1
  14. package/lib/import/excel-import.d.ts.map +1 -1
  15. package/lib/import/excel-import.js +45 -37
  16. package/lib/import/excel-import.js.map +1 -1
  17. package/lib/index.d.ts +2 -1
  18. package/lib/index.d.ts.map +1 -1
  19. package/lib/index.js +2 -1
  20. package/lib/index.js.map +1 -1
  21. package/lib/layout/menu/menu-render.d.ts.map +1 -1
  22. package/lib/layout/menu/menu-render.js +3 -0
  23. package/lib/layout/menu/menu-render.js.map +1 -1
  24. package/lib/layout/menu/userinfo-bar.js +1 -1
  25. package/lib/layout/menu/userinfo-bar.js.map +1 -1
  26. package/lib/module/dtmpl-view-card.d.ts +1 -0
  27. package/lib/module/dtmpl-view-card.d.ts.map +1 -1
  28. package/lib/module/dtmpl-view-card.js +2 -2
  29. package/lib/module/dtmpl-view-card.js.map +1 -1
  30. package/lib/module/dtmpl-view-drawer.js +1 -1
  31. package/lib/module/dtmpl-view-drawer.js.map +1 -1
  32. package/lib/routable/ttmpl-route.d.ts +10 -0
  33. package/lib/routable/ttmpl-route.d.ts.map +1 -0
  34. package/lib/routable/ttmpl-route.js +79 -0
  35. package/lib/routable/ttmpl-route.js.map +1 -0
  36. package/lib/table/query-table.js +1 -1
  37. package/lib/table/query-table.js.map +1 -1
  38. package/lib/tmpl/hc-data-source.d.ts +2 -1
  39. package/lib/tmpl/hc-data-source.d.ts.map +1 -1
  40. package/lib/tmpl/hc-data-source.js +11 -0
  41. package/lib/tmpl/hc-data-source.js.map +1 -1
  42. package/lib/tmpl/hcservice-v3.d.ts +2 -0
  43. package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
  44. package/lib/tmpl/hcservice-v3.js +30 -7
  45. package/lib/tmpl/hcservice-v3.js.map +1 -1
  46. package/lib/tmpl/interface.d.ts +14 -1
  47. package/lib/tmpl/interface.d.ts.map +1 -1
  48. package/lib/tmpl/interface.js.map +1 -1
  49. package/lib/tree/act-tree.d.ts +41 -0
  50. package/lib/tree/act-tree.d.ts.map +1 -0
  51. package/lib/tree/act-tree.js +120 -0
  52. package/lib/tree/act-tree.js.map +1 -0
  53. package/lib/tree/index.css +21 -0
  54. package/lib/tree/tmpl-tree.d.ts +62 -0
  55. package/lib/tree/tmpl-tree.d.ts.map +1 -0
  56. package/lib/tree/tmpl-tree.js +342 -0
  57. package/lib/tree/tmpl-tree.js.map +1 -0
  58. package/lib/tree/tree-node.d.ts +22 -0
  59. package/lib/tree/tree-node.d.ts.map +1 -0
  60. package/lib/tree/tree-node.js +62 -0
  61. package/lib/tree/tree-node.js.map +1 -0
  62. package/lib/tree/tree-utils.d.ts +55 -0
  63. package/lib/tree/tree-utils.d.ts.map +1 -0
  64. package/lib/tree/tree-utils.js +142 -0
  65. package/lib/tree/tree-utils.js.map +1 -0
  66. package/package.json +1 -1
  67. package/src/aldehyde/controls/entity-select/entity-select.tsx +1 -1
  68. package/src/aldehyde/custom-page/custom-page-router.tsx +0 -1
  69. package/src/aldehyde/detail/view/act-dtmpl-view.tsx +3 -2
  70. package/src/aldehyde/detail/view/modal-dtmpl-view.tsx +6 -6
  71. package/src/aldehyde/form/dtmpl-form.tsx +0 -1
  72. package/src/aldehyde/import/excel-import.tsx +42 -35
  73. package/src/aldehyde/index.tsx +2 -1
  74. package/src/aldehyde/layout/menu/menu-render.tsx +3 -0
  75. package/src/aldehyde/layout/menu/userinfo-bar.tsx +1 -1
  76. package/src/aldehyde/module/dtmpl-view-card.tsx +3 -2
  77. package/src/aldehyde/module/dtmpl-view-drawer.tsx +2 -2
  78. package/src/aldehyde/routable/ttmpl-route.tsx +77 -0
  79. package/src/aldehyde/table/query-table.tsx +1 -1
  80. package/src/aldehyde/tmpl/hc-data-source.tsx +11 -1
  81. package/src/aldehyde/tmpl/hcservice-v3.tsx +29 -7
  82. package/src/aldehyde/tmpl/interface.tsx +16 -1
  83. package/src/aldehyde/tree/act-tree.tsx +149 -0
  84. package/src/aldehyde/tree/index.css +21 -0
  85. package/src/aldehyde/tree/tmpl-tree.tsx +397 -0
  86. package/src/aldehyde/tree/tree-node.tsx +78 -0
  87. package/src/aldehyde/tree/tree-utils.tsx +166 -0
@@ -8,7 +8,7 @@ import {
8
8
  Level2Menu,
9
9
  LtmplConfig,
10
10
  LtmplConfigRes,
11
- SelectConfig
11
+ SelectConfig, TtmplConfig
12
12
  } from "./interface";
13
13
  import HcserviceV3 from './hcservice-v3';
14
14
  import ControlTypeSupportor from './control-type-supportor'
@@ -25,6 +25,7 @@ const selectConfigMap: Map<string, SelectConfig> = new Map<string, SelectConfig>
25
25
  const ltmplConfigMap: Map<string, LtmplConfigRes> = new Map<string, LtmplConfigRes>();
26
26
  const l2LtmplConfigMap: Map<string, LtmplConfigRes> = new Map<string, LtmplConfigRes>();
27
27
  const dtmplConfigMap: Map<string, DtmplConfig> = new Map<string, DtmplConfig>();
28
+ const ttmplConfigMap: Map<string, TtmplConfig> = new Map<string, TtmplConfig>();
28
29
  const viewDtmplConfigMap: Map<string, DtmplConfig> = new Map<string, DtmplConfig>();
29
30
  const addDtmplConfigMap: Map<string, DtmplConfig> = new Map<string, DtmplConfig>();
30
31
  const objctCacheMap: Map<string, DtmplData> = new Map<string, DtmplData>();
@@ -195,6 +196,15 @@ HCDataSource.requestDtmplConfig = async function (serverKey:string,sourceId: str
195
196
  return dtmplConfigMap.get(sourceId);
196
197
  };
197
198
 
199
+ HCDataSource.requestTtmplConfig = async function (serverKey:string,sourceId: string) {
200
+ if (!ttmplConfigMap.has(sourceId)) {
201
+ let res= await HcserviceV3.requestTtmplConfig(serverKey,sourceId);
202
+ ttmplConfigMap.set(sourceId, res);
203
+ ttmplConfigMap.set(res.id, res);
204
+ }
205
+ return ttmplConfigMap.get(sourceId);
206
+ };
207
+
198
208
  HCDataSource.requestViewDtmplConfig = async function (serverKey:string,sourceId: string) {
199
209
  if (!viewDtmplConfigMap.has(sourceId)) {
200
210
  viewDtmplConfigMap.set(sourceId, await HcserviceV3.requestViewDtmplConfig(serverKey,sourceId));
@@ -48,6 +48,18 @@ export default class HcserviceV3 {
48
48
  return res.dtmplConfig;
49
49
  }
50
50
 
51
+ static async requestTtmplConfig(serverKey:string,sourceId: string) {
52
+
53
+ let url = `/v3/ttmpl/config`
54
+ let res = await Super.super({
55
+ url,
56
+ serverKey,
57
+ method: "GET",
58
+ query: {sourceId}
59
+ });
60
+ return res.ttmplConfig;
61
+ }
62
+
51
63
  static async requestViewDtmplConfig(serverKey:string,sourceId: string) {
52
64
 
53
65
  let url = `/v3/view-dtmpl/config`
@@ -122,6 +134,11 @@ export default class HcserviceV3 {
122
134
  return await this.requestCommonLtmplQueryTop(serverKey,sourceId, condition, url);
123
135
  }
124
136
 
137
+ static async requestTtmplRootData(serverKey:string,sourceId:string, condition) {
138
+ let url = `/v3/ttmpl/root-data`
139
+ return await this.requestCommonLtmplQueryTop(serverKey,sourceId, condition, url);
140
+ }
141
+
125
142
  static async requestMstrucLtmplQueryTop(serverKey:string,sourceId:string, condition) {
126
143
  //console.log('condition:',condition);
127
144
  let url = `/v3/mstruc/ltmpl/top-data`
@@ -139,13 +156,18 @@ export default class HcserviceV3 {
139
156
 
140
157
  static async requestCommonLtmplQueryTop(serverKey:string,sourceId:string, condition, url) {
141
158
 
142
- let res = await Super.super({
143
- url: url,
144
- serverKey,
145
- method: 'GET',
146
- query: {...condition, sourceId}
147
- });
148
- return res;
159
+ if(!sourceId){
160
+ message.error("SourceId is undefined!");
161
+ }else{
162
+ let res = await Super.super({
163
+ url: url,
164
+ serverKey,
165
+ method: 'GET',
166
+ query: {...condition, sourceId}
167
+ });
168
+ return res;
169
+ }
170
+
149
171
  }
150
172
 
151
173
  static async requestSelectedData(serverKey:string,sourceId:string, codes) {
@@ -84,7 +84,7 @@ export interface Level2Menu extends MenuBase {
84
84
  displayTotal?: boolean;
85
85
  count?:number;
86
86
  defaultCriteriaValue?:object,
87
- pageType:'列表'|'详情'|'编辑'|'添加'|'编辑或添加'
87
+ pageType:'列表'|'详情'|'编辑'|'添加'|'编辑或添加'|'树'
88
88
  }
89
89
 
90
90
  export interface Level1Menu extends MenuBase {
@@ -188,6 +188,12 @@ export interface SelectConfig extends TmplBase {
188
188
  orderColumn:ColumnConfig;
189
189
  }
190
190
 
191
+ export interface TtmplConfigRes {
192
+ sourceId: string;
193
+ ltmplConfig?: LtmplConfig;
194
+ parentLtmplConfig?: LtmplConfig;
195
+ }
196
+
191
197
  export interface RActionConfig extends OrderableTmplBase {
192
198
 
193
199
  }
@@ -200,6 +206,15 @@ export interface LtmplConfigRes {
200
206
  ltmplConfig?: LtmplConfig;
201
207
  }
202
208
 
209
+ export interface TtmplConfig extends TmplBase {
210
+ type:"2M"|'1M'|'2MR',
211
+ leafTitle:string,
212
+ branchTitle:string,
213
+ rootGtmplId:string,
214
+ branchRatmplId:string,
215
+ leafRatmplId:string,
216
+ }
217
+
203
218
  // export interface StatViewConfig extends SelectConfig {
204
219
  //
205
220
  // // reStat query analysis
@@ -0,0 +1,149 @@
1
+ import React from 'react'
2
+ import {Card, Layout, Typography} from 'antd';
3
+ import TmplTree from "./tmpl-tree";
4
+ import TreeUtils, {TtmplNodeConfig} from "./tree-utils";
5
+ import {TtmplConfig} from "../tmpl/interface";
6
+ import {DtmplEditCard, DtmplViewCard} from "../index";
7
+ import HcserviceV3 from "../tmpl/hcservice-v3";
8
+
9
+ const {Content, Sider} = Layout;
10
+ const {Text, Title} = Typography
11
+
12
+ interface ActTreeProps {
13
+ ttmplConfig: TtmplConfig,
14
+ }
15
+
16
+ interface ActTreeState {
17
+ ttmplNodeConfig?: TtmplNodeConfig,
18
+ showEdit?: boolean,
19
+ showView?:boolean,
20
+ recordCode?: string,
21
+ mainCode?: string,
22
+ sourceId?: string,
23
+ cardtitle?:string,
24
+ }
25
+
26
+ export default class ActTree extends React.PureComponent<ActTreeProps, ActTreeState> {
27
+
28
+ static defaultProps = {}
29
+ state = {
30
+ ttmplNodeConfig: undefined,
31
+ recordCode: undefined,
32
+ showEdit: false,
33
+ showView:false,
34
+ mainCode: undefined,
35
+ sourceId: undefined,
36
+ cardtitle:undefined,
37
+ }
38
+
39
+ refTmplTree: any = React.createRef();
40
+
41
+ async componentDidMount() {
42
+
43
+ await this.loadData();
44
+ }
45
+
46
+ loadData=async ()=>{
47
+ const {ttmplConfig} = this.props;
48
+ let ttmplNodeConfig = await TreeUtils.initTtmplNodeConfig(ttmplConfig);
49
+ this.setState({
50
+ ttmplNodeConfig,
51
+ showEdit:false,
52
+ showView:false,
53
+ })
54
+ }
55
+
56
+ async componentDidUpdate(prevProps) {
57
+ let {ttmplConfig: prettmplConfig} = prevProps;
58
+ let {ttmplConfig} = this.props;
59
+
60
+ if (ttmplConfig && prettmplConfig && ttmplConfig.id==prettmplConfig.id) {
61
+ return;
62
+ }
63
+ await this.loadData();
64
+ }
65
+
66
+ onEditRoot = (title:string,code?: string) => {
67
+ const {ttmplConfig} = this.props;
68
+ this.showCard(title,ttmplConfig.rootGtmplId,null,code,true,false);
69
+ };
70
+ showCard=(cardtitle,sourceId,mainCode,recordCode,showEdit,showView)=>{
71
+ this.setState({
72
+ mainCode,
73
+ cardtitle,
74
+ recordCode,
75
+ showEdit,
76
+ showView,
77
+ sourceId,
78
+ })
79
+ }
80
+ onViewRoot = (title:string,code?: string) => {
81
+ const {ttmplConfig} = this.props;
82
+ this.showCard(title,ttmplConfig.rootGtmplId,null,code,false,true);
83
+ };
84
+
85
+ onEditSub = (title:string,sourceId:string,mainCode:string,recordCode?: string) => {
86
+ this.showCard(title,sourceId,mainCode,recordCode,true,false);
87
+ };
88
+
89
+ onViewSub = (title:string,sourceId:string,mainCode:string,recordCode?: string) => {
90
+
91
+ this.showCard(title,sourceId,mainCode,recordCode,false,true);
92
+ };
93
+
94
+ onDelete=(sourceId:string,recordCode?: string) => {
95
+ HcserviceV3.deleteByCode(null,sourceId, [recordCode]);
96
+ };
97
+ onAddSub=(title:string,sourceId:string,mainCode: string) => {
98
+
99
+ this.showCard(title,sourceId,mainCode,null,true,false);
100
+ };
101
+
102
+ render() {
103
+ const {} = this.props;
104
+
105
+ const {ttmplNodeConfig,showView, showEdit, recordCode, mainCode, sourceId,cardtitle} = this.state;
106
+ if (!ttmplNodeConfig) {
107
+ return <Card loading={true}></Card>
108
+ }
109
+ return (<Layout hasSider style={{backgroundColor: '#fff'}}>
110
+ <Sider width={360} theme={'light'}
111
+ style={{
112
+ height: '90vh',
113
+ position: 'fixed',
114
+ left: 0,
115
+ top: 66,
116
+ bottom: 0,
117
+ marginLeft: 210
118
+ }}
119
+ ><TmplTree doEditRoot={this.onEditRoot}
120
+ doEditSub={this.onEditSub}
121
+ doDelete={this.onDelete}
122
+ doViewRoot={this.onViewRoot}
123
+ doViewSub={this.onViewSub}
124
+ doAddSub={this.onAddSub}
125
+ ttmplNodeConfig={ttmplNodeConfig}
126
+ ref={this.refTmplTree}
127
+ ></TmplTree>
128
+ </Sider>
129
+ <Layout style={{marginLeft: 382, backgroundColor: '#fff'}}>
130
+ <Content style={{overflow: 'initial'}}>
131
+ {showEdit ? <DtmplEditCard title={<>{recordCode ? <>编辑 {cardtitle?cardtitle:""}</> : <>添加 {cardtitle?cardtitle:""}</>} </>}
132
+ mainCode={mainCode}
133
+ sourceId={sourceId}
134
+ code={recordCode}
135
+ onOk={(recordCode) => {
136
+ let a=this.refTmplTree?.current?.reloadData(mainCode);
137
+ this.setState({recordCode})
138
+ }}
139
+ /> : null}
140
+ {showView ? <DtmplViewCard
141
+ mainCode={mainCode}
142
+ sourceId={sourceId}
143
+ code={recordCode}
144
+ /> : null}
145
+ </Content>
146
+ </Layout>
147
+ </Layout>)
148
+ }
149
+ }
@@ -0,0 +1,21 @@
1
+ .tree-container {
2
+ box-shadow:1px 0 0px 1px rgba(0,0,0,0.3) ;
3
+ }
4
+
5
+ .tree-node{
6
+ box-shadow:0.4px 0px 0px 0.4px rgba(0,0,0,0.2) ;
7
+ margin-bottom: 2px;
8
+ }
9
+
10
+
11
+
12
+ .tree-card-title-body {
13
+ padding:2px;
14
+ min-width: 280px;
15
+ }
16
+ .ant-tree-node-selected{
17
+ background-color: white !important;
18
+ }
19
+ .ant-avatar-string{
20
+ transform: scale(0.8) translateX(-50%) !important;
21
+ }
@@ -0,0 +1,397 @@
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