@lcap/nasl 3.5.0-beta.4 → 3.6.0-alpha.1
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.
- package/out/bak/translator.js +39 -119
- package/out/bak/translator.js.map +1 -1
- package/out/breakpoint/generator/BreakpointNode.d.ts +0 -3
- package/out/breakpoint/generator/BreakpointNode.js +0 -9
- package/out/breakpoint/generator/BreakpointNode.js.map +1 -1
- package/out/breakpoint/shared/constants.js +0 -1
- package/out/breakpoint/shared/constants.js.map +1 -1
- package/out/breakpoint/shared/utils.js +7 -31
- package/out/breakpoint/shared/utils.js.map +1 -1
- package/out/common/BaseNode.d.ts +13 -1
- package/out/common/BaseNode.js +52 -23
- package/out/common/BaseNode.js.map +1 -1
- package/out/common/Command.js +1 -0
- package/out/common/Command.js.map +1 -1
- package/out/common/EventEmitter.d.ts +1 -1
- package/out/common/EventEmitter.js +0 -4
- package/out/common/EventEmitter.js.map +1 -1
- package/out/concepts/App__.d.ts +76 -51
- package/out/concepts/App__.js +190 -87
- package/out/concepts/App__.js.map +1 -1
- package/out/concepts/BackendVariable__.js +2 -10
- package/out/concepts/BackendVariable__.js.map +1 -1
- package/out/concepts/BindAttribute__.js +6 -16
- package/out/concepts/BindAttribute__.js.map +1 -1
- package/out/concepts/BindDirective__.d.ts +0 -1
- package/out/concepts/BindDirective__.js +4 -19
- package/out/concepts/BindDirective__.js.map +1 -1
- package/out/concepts/BindEvent__.d.ts +1 -3
- package/out/concepts/BindEvent__.js +13 -38
- package/out/concepts/BindEvent__.js.map +1 -1
- package/out/concepts/CallFunction__.js +2 -10
- package/out/concepts/CallFunction__.js.map +1 -1
- package/out/concepts/CallLogic__.d.ts +0 -2
- package/out/concepts/CallLogic__.js +27 -38
- package/out/concepts/CallLogic__.js.map +1 -1
- package/out/concepts/Constant__.js +6 -7
- package/out/concepts/Constant__.js.map +1 -1
- package/out/concepts/Destination__.d.ts +1 -1
- package/out/concepts/Destination__.js +4 -6
- package/out/concepts/Destination__.js.map +1 -1
- package/out/concepts/End__.js +1 -2
- package/out/concepts/End__.js.map +1 -1
- package/out/concepts/Entity__.d.ts +1 -1
- package/out/concepts/Entity__.js +2 -0
- package/out/concepts/Entity__.js.map +1 -1
- package/out/concepts/Event__.d.ts +0 -14
- package/out/concepts/Event__.js +0 -61
- package/out/concepts/Event__.js.map +1 -1
- package/out/concepts/Frontend__.d.ts +88 -0
- package/out/concepts/Frontend__.js +143 -1
- package/out/concepts/Frontend__.js.map +1 -1
- package/out/concepts/Identifier__.d.ts +0 -5
- package/out/concepts/Identifier__.js +9 -19
- package/out/concepts/Identifier__.js.map +1 -1
- package/out/concepts/LogicItem__.d.ts +1 -1
- package/out/concepts/LogicItem__.js.map +1 -1
- package/out/concepts/Logic__.d.ts +1 -3
- package/out/concepts/Logic__.js +13 -16
- package/out/concepts/Logic__.js.map +1 -1
- package/out/concepts/MemberExpression__.d.ts +1 -1
- package/out/concepts/MemberExpression__.js +3 -3
- package/out/concepts/MemberExpression__.js.map +1 -1
- package/out/concepts/NewComposite__.js.map +1 -1
- package/out/concepts/Param__.js +3 -11
- package/out/concepts/Param__.js.map +1 -1
- package/out/concepts/ProcessElement__.js +1 -9
- package/out/concepts/ProcessElement__.js.map +1 -1
- package/out/concepts/Return__.js +9 -17
- package/out/concepts/Return__.js.map +1 -1
- package/out/concepts/Variable__.js +8 -17
- package/out/concepts/Variable__.js.map +1 -1
- package/out/concepts/ViewElement__.d.ts +2 -17
- package/out/concepts/ViewElement__.js +31 -143
- package/out/concepts/ViewElement__.js.map +1 -1
- package/out/concepts/View__.js +6 -6
- package/out/concepts/View__.js.map +1 -1
- package/out/concepts/index__.d.ts +0 -5
- package/out/concepts/index__.js +0 -5
- package/out/concepts/index__.js.map +1 -1
- package/out/concepts/utils/asserts.d.ts +3 -258
- package/out/concepts/utils/asserts.js +13 -351
- package/out/concepts/utils/asserts.js.map +1 -1
- package/out/concepts/utils/types.d.ts +3 -20
- package/out/generator/genBundleFiles.js +11 -25
- package/out/generator/genBundleFiles.js.map +1 -1
- package/out/generator/genReleaseBody.js +3 -12
- package/out/generator/genReleaseBody.js.map +1 -1
- package/out/generator/permission.js +3 -3
- package/out/generator/permission.js.map +1 -1
- package/out/natural/transformTSCode.js +1 -1
- package/out/natural/transformTSCode.js.map +1 -1
- package/out/server/extendBaseNode.js +22 -6
- package/out/server/extendBaseNode.js.map +1 -1
- package/out/server/getLogics.js +27 -62
- package/out/server/getLogics.js.map +1 -1
- package/out/server/getMemberIdentifier.js +1 -6
- package/out/server/getMemberIdentifier.js.map +1 -1
- package/out/server/naslServer.js +11 -28
- package/out/server/naslServer.js.map +1 -1
- package/out/server/translator.js +1 -6
- package/out/server/translator.js.map +1 -1
- package/out/service/storage/init.js +26 -2
- package/out/service/storage/init.js.map +1 -1
- package/out/templator/genCreateBlock.js +6 -6
- package/out/templator/genCreateBlock.js.map +1 -1
- package/out/templator/genCurdEditMultipleKeyBlock.js +16 -16
- package/out/templator/genCurdEditMultipleKeyBlock.js.map +1 -1
- package/out/templator/genCurdMultipleKeyBlock.d.ts +27 -0
- package/out/templator/genCurdMultipleKeyBlock.js +709 -37
- package/out/templator/genCurdMultipleKeyBlock.js.map +1 -1
- package/out/templator/genGetBlock.js +4 -4
- package/out/templator/genGetBlock.js.map +1 -1
- package/out/templator/genGridViewBlock.js +12 -12
- package/out/templator/genGridViewBlock.js.map +1 -1
- package/out/templator/genListViewBlock.js +4 -4
- package/out/templator/genListViewBlock.js.map +1 -1
- package/out/templator/genSelectBlock.js +3 -3
- package/out/templator/genSelectBlock.js.map +1 -1
- package/out/templator/genTableBlock.d.ts +2 -0
- package/out/templator/genTableBlock.js +124 -11
- package/out/templator/genTableBlock.js.map +1 -1
- package/out/templator/genUpdateBlock.js +8 -8
- package/out/templator/genUpdateBlock.js.map +1 -1
- package/out/templator/utils.d.ts +2 -2
- package/out/templator/utils.js.map +1 -1
- package/out/translator/utils.js +18 -0
- package/out/translator/utils.js.map +1 -1
- package/out/utils/i18nInfo.js +2 -7
- package/out/utils/i18nInfo.js.map +1 -1
- package/package.json +2 -2
- package/src/bak/translator.js +43 -121
- package/src/breakpoint/generator/BreakpointNode.ts +0 -12
- package/src/breakpoint/shared/constants.ts +0 -1
- package/src/breakpoint/shared/utils.ts +10 -37
- package/src/common/BaseNode.ts +60 -22
- package/src/common/Command.ts +1 -0
- package/src/common/EventEmitter.ts +1 -6
- package/src/concepts/App__.ts +251 -139
- package/src/concepts/BackendVariable__.ts +2 -10
- package/src/concepts/BindAttribute__.ts +6 -15
- package/src/concepts/BindDirective__.ts +4 -19
- package/src/concepts/BindEvent__.ts +12 -40
- package/src/concepts/CallFunction__.ts +2 -10
- package/src/concepts/CallLogic__.ts +32 -45
- package/src/concepts/Constant__.ts +7 -5
- package/src/concepts/Destination__.ts +4 -6
- package/src/concepts/End__.ts +0 -1
- package/src/concepts/Entity__.ts +3 -1
- package/src/concepts/Event__.ts +0 -70
- package/src/concepts/Frontend__.ts +251 -3
- package/src/concepts/Identifier__.ts +13 -29
- package/src/concepts/LogicItem__.ts +0 -1
- package/src/concepts/Logic__.ts +14 -21
- package/src/concepts/MemberExpression__.ts +3 -3
- package/src/concepts/NewComposite__.ts +6 -4
- package/src/concepts/Param__.ts +3 -11
- package/src/concepts/ProcessElement__.ts +1 -8
- package/src/concepts/Return__.ts +12 -15
- package/src/concepts/Variable__.ts +9 -17
- package/src/concepts/ViewElement__.ts +54 -166
- package/src/concepts/View__.ts +6 -8
- package/src/concepts/index__.ts +0 -5
- package/src/concepts/utils/asserts.ts +4 -367
- package/src/concepts/utils/types.ts +0 -28
- package/src/generator/genBundleFiles.ts +15 -33
- package/src/generator/genReleaseBody.ts +3 -14
- package/src/generator/permission.ts +6 -8
- package/src/natural/transformTSCode.ts +1 -1
- package/src/server/extendBaseNode.ts +41 -22
- package/src/server/getLogics.ts +41 -79
- package/src/server/getMemberIdentifier.ts +1 -7
- package/src/server/naslServer.ts +12 -30
- package/src/server/translator.ts +1 -7
- package/src/service/storage/init.ts +33 -2
- package/src/templator/genCreateBlock.ts +6 -6
- package/src/templator/genCurdEditMultipleKeyBlock.ts +16 -16
- package/src/templator/genCurdMultipleKeyBlock.ts +817 -93
- package/src/templator/genGetBlock.ts +4 -4
- package/src/templator/genGridViewBlock.ts +12 -12
- package/src/templator/genListViewBlock.ts +4 -4
- package/src/templator/genSelectBlock.ts +3 -3
- package/src/templator/genTableBlock.ts +137 -12
- package/src/templator/genUpdateBlock.ts +8 -8
- package/src/templator/utils.ts +2 -2
- package/src/translator/utils.ts +20 -0
- package/src/utils/i18nInfo.ts +2 -7
- package/test/concepts/call-function/fixtures/from-string.json +59 -68
- package/test/concepts/call-function/fixtures/to-string-global-tz.json +58 -67
- package/test/concepts/call-function/fixtures/to-string-no-tz.json +48 -57
- package/test/concepts/call-function/fixtures/to-string-user-tz.json +60 -69
- package/test/concepts/call-function/fixtures/to-string-utc-tz.json +60 -69
- package/test/concepts/call-interface/fixtures/only-interface.json +72 -81
- package/test/concepts/call-interface/fixtures/with-body-complex-argument.json +214 -223
- package/test/concepts/call-interface/fixtures/with-body-no-argument.json +76 -85
- package/test/concepts/call-interface/fixtures/with-body-simple-argument.json +91 -100
- package/test/concepts/call-interface/fixtures/with-headers-no-argument.json +79 -88
- package/test/concepts/call-interface/fixtures/with-headers.json +81 -90
- package/test/concepts/call-interface/fixtures/with-query-no-argument.json +79 -88
- package/test/concepts/call-interface/fixtures/with-query.json +81 -90
- package/test/concepts/call-logic/__snapshots__/getQuickInfoOffset.spec.ts.snap +2 -4
- package/test/concepts/call-logic/fixtures/entries-get-with-arguments.json +95 -104
- package/test/concepts/call-logic/fixtures/entries-update-with-arguments.json +200 -209
- package/test/concepts/call-logic/fixtures/global-logic-argument-no-expression.json +88 -97
- package/test/concepts/call-logic/fixtures/global-logic-argument-some-expression.json +115 -124
- package/test/concepts/call-logic/fixtures/json-deserialize.json +111 -120
- package/test/concepts/call-logic/fixtures/json-serialize-with-string.json +115 -124
- package/test/concepts/call-logic/fixtures/json-serialize.json +115 -124
- package/test/concepts/call-logic/fixtures/view-buildin-logic-with-argument.json +82 -91
- package/test/concepts/call-logic/fixtures/view-component-logic-no-argument.json +79 -88
- package/test/concepts/call-logic/fixtures/view-component-with-validation.json +135 -144
- package/test/concepts/identifier/fixtures/view-variable.json +136 -145
- package/test/concepts/view-element/__snapshots__/toVue.spec.ts.snap +1 -1
- package/test/concepts/view-element/fixtures/default-login.json +212 -221
- package/test/concepts/view-element/fixtures/default-not-found.json +174 -183
- package/test/concepts/view-element/fixtures/with-role-auth.json +82 -91
- package/test/concepts/view-element/fixtures/with-table.json +1834 -1843
- package/test/concepts/view-element/toVue.spec.ts +0 -1
- package/ts-worker/package.json +1 -1
- package/out/concepts/BusinessComponent__.d.ts +0 -641
- package/out/concepts/BusinessComponent__.js +0 -1901
- package/out/concepts/BusinessComponent__.js.map +0 -1
- package/out/concepts/BusinessLogic__.d.ts +0 -38
- package/out/concepts/BusinessLogic__.js +0 -358
- package/out/concepts/BusinessLogic__.js.map +0 -1
- package/out/concepts/CallEvent__.d.ts +0 -97
- package/out/concepts/CallEvent__.js +0 -263
- package/out/concepts/CallEvent__.js.map +0 -1
- package/out/concepts/FrontendType__.d.ts +0 -308
- package/out/concepts/FrontendType__.js +0 -605
- package/out/concepts/FrontendType__.js.map +0 -1
- package/out/concepts/ParamWithGroup__.d.ts +0 -39
- package/out/concepts/ParamWithGroup__.js +0 -85
- package/out/concepts/ParamWithGroup__.js.map +0 -1
- package/src/concepts/BusinessComponent__.ts +0 -2669
- package/src/concepts/BusinessLogic__.ts +0 -376
- package/src/concepts/CallEvent__.ts +0 -334
- package/src/concepts/FrontendType__.ts +0 -919
- package/src/concepts/ParamWithGroup__.ts +0 -101
|
@@ -1,2669 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
wrapForEachToGenerator as wrapForEach,
|
|
3
|
-
wrapIteratorToGenerator as wrapIterator,
|
|
4
|
-
returnOrigin,
|
|
5
|
-
} from '../utils/time-slicing';
|
|
6
|
-
import type { EmbeddedTSFileGenerator } from '../utils';
|
|
7
|
-
import { shiftState, indent, createCompilerState, withSourceMapGenerator, TranslatorGenerator } from '../translator';
|
|
8
|
-
import type Assignment from './Assignment__';
|
|
9
|
-
import type BatchAssignment from './BatchAssignment__';
|
|
10
|
-
import type Interface from './Interface__';
|
|
11
|
-
import type App from './App__';
|
|
12
|
-
import type FrontendType from './FrontendType__';
|
|
13
|
-
import type Match from './Match__';
|
|
14
|
-
import { ElementToVueOptions } from './ViewElement__';
|
|
15
|
-
import translator from '../bak/translator';
|
|
16
|
-
|
|
17
|
-
type AttrObject = {
|
|
18
|
-
value: string;
|
|
19
|
-
label: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const PAGE_COMPONENT_INCLUDE_TAG_MAP: Record<string, Record<string, AttrObject>> = {
|
|
23
|
-
'u-list-view': {
|
|
24
|
-
'page-size': {
|
|
25
|
-
value: 'size',
|
|
26
|
-
label: '分页大小',
|
|
27
|
-
},
|
|
28
|
-
'page-number': {
|
|
29
|
-
value: 'page',
|
|
30
|
-
label: '当前页数',
|
|
31
|
-
},
|
|
32
|
-
'data-source': {
|
|
33
|
-
value: 'data',
|
|
34
|
-
label: '数据',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
'u-grid-view': {
|
|
38
|
-
'page-size': {
|
|
39
|
-
value: 'size',
|
|
40
|
-
label: '分页大小',
|
|
41
|
-
},
|
|
42
|
-
'page-number': {
|
|
43
|
-
value: 'page',
|
|
44
|
-
label: '当前页数',
|
|
45
|
-
},
|
|
46
|
-
'data-source': {
|
|
47
|
-
value: 'data',
|
|
48
|
-
label: '数据',
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
'u-list-components': {
|
|
52
|
-
'data-source': {
|
|
53
|
-
value: 'data',
|
|
54
|
-
label: '数据',
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
'u-table-view': {
|
|
58
|
-
'page-size': {
|
|
59
|
-
value: 'size',
|
|
60
|
-
label: '分页大小',
|
|
61
|
-
},
|
|
62
|
-
'page-number': {
|
|
63
|
-
value: 'page',
|
|
64
|
-
label: '当前页数',
|
|
65
|
-
},
|
|
66
|
-
sorting: {
|
|
67
|
-
value: 'sort',
|
|
68
|
-
label: '排序属性',
|
|
69
|
-
},
|
|
70
|
-
value: {
|
|
71
|
-
value: 'value',
|
|
72
|
-
label: '单选选中值',
|
|
73
|
-
},
|
|
74
|
-
values: {
|
|
75
|
-
value: 'values',
|
|
76
|
-
label: '多选选中值',
|
|
77
|
-
},
|
|
78
|
-
'data-source': {
|
|
79
|
-
value: 'data',
|
|
80
|
-
label: '数据',
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
'u-radios': {
|
|
84
|
-
value: {
|
|
85
|
-
value: 'value',
|
|
86
|
-
label: '选中值',
|
|
87
|
-
},
|
|
88
|
-
'data-source': {
|
|
89
|
-
value: 'data',
|
|
90
|
-
label: '数据',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
'u-checkboxes': {
|
|
94
|
-
value: {
|
|
95
|
-
value: 'value',
|
|
96
|
-
label: '选中值',
|
|
97
|
-
},
|
|
98
|
-
'data-source': {
|
|
99
|
-
value: 'data',
|
|
100
|
-
label: '数据',
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
'u-select': {
|
|
104
|
-
value: {
|
|
105
|
-
value: 'value',
|
|
106
|
-
label: '选中值',
|
|
107
|
-
},
|
|
108
|
-
'data-source': {
|
|
109
|
-
value: 'data',
|
|
110
|
-
label: '数据',
|
|
111
|
-
},
|
|
112
|
-
opened: {
|
|
113
|
-
value: 'opened',
|
|
114
|
-
label: '弹出状态',
|
|
115
|
-
},
|
|
116
|
-
'page-size': {
|
|
117
|
-
value: 'size',
|
|
118
|
-
label: '分页大小',
|
|
119
|
-
},
|
|
120
|
-
'page-number': {
|
|
121
|
-
value: 'page',
|
|
122
|
-
label: '当前页数',
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
'u-cascader': {
|
|
126
|
-
value: {
|
|
127
|
-
value: 'value',
|
|
128
|
-
label: '选中值',
|
|
129
|
-
},
|
|
130
|
-
'data-source': {
|
|
131
|
-
value: 'data',
|
|
132
|
-
label: '数据',
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
'u-tree-select-new': {
|
|
136
|
-
value: {
|
|
137
|
-
value: 'value',
|
|
138
|
-
label: '选中值',
|
|
139
|
-
},
|
|
140
|
-
'data-source': {
|
|
141
|
-
value: 'data',
|
|
142
|
-
label: '数据',
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
'van-radio-group': {
|
|
146
|
-
value: {
|
|
147
|
-
value: 'value',
|
|
148
|
-
label: '选中值',
|
|
149
|
-
},
|
|
150
|
-
'data-source': {
|
|
151
|
-
value: 'data',
|
|
152
|
-
label: '数据',
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
'van-checkbox-group': {
|
|
156
|
-
value: {
|
|
157
|
-
value: 'value',
|
|
158
|
-
label: '选中值',
|
|
159
|
-
},
|
|
160
|
-
'data-source': {
|
|
161
|
-
value: 'data',
|
|
162
|
-
label: '数据',
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
'van-pickerson': {
|
|
166
|
-
pvalue: {
|
|
167
|
-
value: 'value',
|
|
168
|
-
label: '选中值',
|
|
169
|
-
},
|
|
170
|
-
'data-source': {
|
|
171
|
-
value: 'data',
|
|
172
|
-
label: '数据',
|
|
173
|
-
},
|
|
174
|
-
'page-size': {
|
|
175
|
-
value: 'size',
|
|
176
|
-
label: '分页大小',
|
|
177
|
-
},
|
|
178
|
-
'page-number': {
|
|
179
|
-
value: 'page',
|
|
180
|
-
label: '当前页数',
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
'van-cascader': {
|
|
184
|
-
value: {
|
|
185
|
-
value: 'value',
|
|
186
|
-
label: '选中值',
|
|
187
|
-
},
|
|
188
|
-
'data-source': {
|
|
189
|
-
value: 'data',
|
|
190
|
-
label: '数据',
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
'van-list-view': {
|
|
194
|
-
'page-size': {
|
|
195
|
-
value: 'size',
|
|
196
|
-
label: '分页大小',
|
|
197
|
-
},
|
|
198
|
-
'page-number': {
|
|
199
|
-
value: 'page',
|
|
200
|
-
label: '当前页数',
|
|
201
|
-
},
|
|
202
|
-
'data-source': {
|
|
203
|
-
value: 'data',
|
|
204
|
-
label: '数据',
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
'van-grid-view': {
|
|
208
|
-
'page-size': {
|
|
209
|
-
value: 'size',
|
|
210
|
-
label: '分页大小',
|
|
211
|
-
},
|
|
212
|
-
'page-number': {
|
|
213
|
-
value: 'page',
|
|
214
|
-
label: '当前页数',
|
|
215
|
-
},
|
|
216
|
-
'data-source': {
|
|
217
|
-
value: 'data',
|
|
218
|
-
label: '数据',
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
'van-for-components': {
|
|
222
|
-
'data-source': {
|
|
223
|
-
value: 'data',
|
|
224
|
-
label: '数据',
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const getBranchCopyUniCode = () => (window as any)?.BranchCopyUniCode;
|
|
230
|
-
const removedViewElementCache: {
|
|
231
|
-
[key: string]: number | bigint;
|
|
232
|
-
} = {}; // 临时记录删除的页面元素计数的最大值
|
|
233
|
-
|
|
234
|
-
//================================================================================
|
|
235
|
-
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
236
|
-
// ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
237
|
-
//================================================================================
|
|
238
|
-
import { EventPayload, Params } from '../common/EventEmitter';
|
|
239
|
-
import { concept, excludedInJSON, property, getConceptConstructor, getBaseNode } from '../decorators';
|
|
240
|
-
|
|
241
|
-
import * as utils from '../utils';
|
|
242
|
-
import * as types from './utils/types';
|
|
243
|
-
import * as asserts from './utils/asserts';
|
|
244
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
245
|
-
import BaseNode from '../common/BaseNode';
|
|
246
|
-
import type Event from './Event__';
|
|
247
|
-
import type ParamWithGroup from './ParamWithGroup__';
|
|
248
|
-
import type Variable from './Variable__';
|
|
249
|
-
import type BindEvent from './BindEvent__';
|
|
250
|
-
import type BusinessLogic from './BusinessLogic__';
|
|
251
|
-
import type ViewElement from './ViewElement__';
|
|
252
|
-
import type Param from './Param__';
|
|
253
|
-
import type Logic from './Logic__';
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* 业务组件
|
|
257
|
-
*/
|
|
258
|
-
@concept('业务组件')
|
|
259
|
-
export class BusinessComponent extends BaseNode {
|
|
260
|
-
/** 类名 */
|
|
261
|
-
static readonly ConceptName: string = 'BusinessComponent';
|
|
262
|
-
|
|
263
|
-
/** 继承链 */
|
|
264
|
-
static readonly inheritanceChain: string[] = ['BaseNode'];
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* 产品概念
|
|
268
|
-
*/
|
|
269
|
-
@property('concept')
|
|
270
|
-
// @ts-ignore
|
|
271
|
-
readonly concept!: 'BusinessComponent';
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* 业务组件名称
|
|
275
|
-
*/
|
|
276
|
-
@property()
|
|
277
|
-
name!: string;
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* 业务组件标题
|
|
281
|
-
*/
|
|
282
|
-
@property()
|
|
283
|
-
title!: string;
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* 业务组件描述
|
|
287
|
-
*/
|
|
288
|
-
@property()
|
|
289
|
-
description!: string;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* 组件事件列表
|
|
293
|
-
*/
|
|
294
|
-
@property({
|
|
295
|
-
objectRef: 'Event',
|
|
296
|
-
isArray: true,
|
|
297
|
-
defaultValue: [],
|
|
298
|
-
})
|
|
299
|
-
events: Array<Event> = [];
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* 参数分组列表
|
|
303
|
-
*/
|
|
304
|
-
@property({
|
|
305
|
-
objectRef: 'ParamWithGroup',
|
|
306
|
-
isArray: true,
|
|
307
|
-
defaultValue: [],
|
|
308
|
-
})
|
|
309
|
-
params: Array<ParamWithGroup> = [];
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* 变量列表
|
|
313
|
-
*/
|
|
314
|
-
@property({
|
|
315
|
-
objectRef: 'Variable',
|
|
316
|
-
isArray: true,
|
|
317
|
-
defaultValue: [],
|
|
318
|
-
})
|
|
319
|
-
variables: Array<Variable> = [];
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* 元素绑定事件列表
|
|
323
|
-
*/
|
|
324
|
-
@property({
|
|
325
|
-
objectRef: 'BindEvent',
|
|
326
|
-
isArray: true,
|
|
327
|
-
defaultValue: [],
|
|
328
|
-
})
|
|
329
|
-
bindEvents: Array<BindEvent> = [];
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* 业务组件逻辑列表
|
|
333
|
-
*/
|
|
334
|
-
@property({
|
|
335
|
-
objectRef: 'BusinessLogic',
|
|
336
|
-
isArray: true,
|
|
337
|
-
defaultValue: [],
|
|
338
|
-
})
|
|
339
|
-
logics: Array<BusinessLogic> = [];
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* 页面元素列表
|
|
343
|
-
*/
|
|
344
|
-
@property({
|
|
345
|
-
objectRef: 'ViewElement',
|
|
346
|
-
isArray: true,
|
|
347
|
-
defaultValue: [],
|
|
348
|
-
})
|
|
349
|
-
elements: Array<ViewElement> = [];
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* icon
|
|
353
|
-
*/
|
|
354
|
-
@property()
|
|
355
|
-
icon!: string;
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* @param source 需要合并的部分参数
|
|
359
|
-
*/
|
|
360
|
-
constructor(source?: Partial<BusinessComponent>) {
|
|
361
|
-
source = Object.assign({}, BusinessComponent.getDefaultOptions(), source);
|
|
362
|
-
super(source);
|
|
363
|
-
super.subConstructor(source);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
static from(source: any, parentNode?: any, parentKey?: string): BusinessComponent {
|
|
367
|
-
return super.from(source, parentNode, parentKey) as BusinessComponent;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* 从父级删除该节点
|
|
372
|
-
* @internal
|
|
373
|
-
*/
|
|
374
|
-
_delete() {
|
|
375
|
-
let params: Params = null;
|
|
376
|
-
if (this.parentNode) {
|
|
377
|
-
params = (this.parentNode as any)?.__removeBusinessComponent?.(this);
|
|
378
|
-
}
|
|
379
|
-
return params;
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* 设置业务组件名称
|
|
383
|
-
*/
|
|
384
|
-
setName(name: string) {
|
|
385
|
-
const object = {
|
|
386
|
-
name,
|
|
387
|
-
};
|
|
388
|
-
this.update({
|
|
389
|
-
...object,
|
|
390
|
-
field: 'name',
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* 设置业务组件标题
|
|
396
|
-
*/
|
|
397
|
-
setTitle(title: string) {
|
|
398
|
-
const object = {
|
|
399
|
-
title,
|
|
400
|
-
};
|
|
401
|
-
this.update({
|
|
402
|
-
...object,
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* 设置业务组件描述
|
|
408
|
-
*/
|
|
409
|
-
setDescription(description: string) {
|
|
410
|
-
const object = {
|
|
411
|
-
description,
|
|
412
|
-
};
|
|
413
|
-
this.update({
|
|
414
|
-
...object,
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* 设置icon
|
|
420
|
-
*/
|
|
421
|
-
setIcon(icon: string) {
|
|
422
|
-
const object = {
|
|
423
|
-
icon,
|
|
424
|
-
};
|
|
425
|
-
this.update({
|
|
426
|
-
...object,
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
getEventExistingNames(excludedList: Array<Event> = []) {
|
|
431
|
-
const excludedSet = new Set(excludedList);
|
|
432
|
-
return ((this.events as Event[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
|
|
433
|
-
}
|
|
434
|
-
getEventUniqueName(name = 'event1') {
|
|
435
|
-
return utils.unique(name, this.getEventExistingNames(), undefined, false);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* 插入组件事件
|
|
440
|
-
* @internal
|
|
441
|
-
* @param name 组件事件名称,如果不填会自动生成一个唯一名称
|
|
442
|
-
*/
|
|
443
|
-
_insertEventAt(name: string, index: number): Event;
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* 插入组件事件
|
|
447
|
-
* @internal
|
|
448
|
-
* @param eventOptions 组件事件参数
|
|
449
|
-
*/
|
|
450
|
-
_insertEventAt(eventOptions: Partial<Event>, index: number): Event;
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* 插入组件事件
|
|
454
|
-
* @internal
|
|
455
|
-
* @param event 已有的组件事件实例
|
|
456
|
-
*/
|
|
457
|
-
_insertEventAt(event: Event, index: number): Event;
|
|
458
|
-
|
|
459
|
-
_insertEventAt(options: string | Partial<Event> | Event, index: number) {
|
|
460
|
-
const eventOptions: any = {};
|
|
461
|
-
const relationOptions = { parentNode: this, parentKey: 'events' };
|
|
462
|
-
const Event = getConceptConstructor('Event');
|
|
463
|
-
let event: Event;
|
|
464
|
-
if (!options) {
|
|
465
|
-
event = Event.from(
|
|
466
|
-
{
|
|
467
|
-
...eventOptions,
|
|
468
|
-
name: this.getEventUniqueName(),
|
|
469
|
-
},
|
|
470
|
-
this,
|
|
471
|
-
'events',
|
|
472
|
-
);
|
|
473
|
-
} else if (typeof options === 'string') {
|
|
474
|
-
event = Event.from(
|
|
475
|
-
{
|
|
476
|
-
...eventOptions,
|
|
477
|
-
name: options,
|
|
478
|
-
},
|
|
479
|
-
this,
|
|
480
|
-
'events',
|
|
481
|
-
);
|
|
482
|
-
} else if (asserts.isEvent(options)) {
|
|
483
|
-
options.ensureDelete(); // 同一实例不支持多处存在
|
|
484
|
-
event = options;
|
|
485
|
-
Object.assign(event, relationOptions);
|
|
486
|
-
} else {
|
|
487
|
-
event = Event.from(
|
|
488
|
-
{
|
|
489
|
-
...eventOptions,
|
|
490
|
-
...options,
|
|
491
|
-
},
|
|
492
|
-
this,
|
|
493
|
-
'events',
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
this.events.splice(index, 0, event);
|
|
497
|
-
return event;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* 插入组件事件
|
|
502
|
-
* @param name 组件事件名称,如果不填会自动生成一个唯一名称
|
|
503
|
-
*/
|
|
504
|
-
insertEventAt(name: string, index: number): Event;
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* 插入组件事件
|
|
508
|
-
* @param eventOptions 组件事件参数
|
|
509
|
-
*/
|
|
510
|
-
insertEventAt(eventOptions: Partial<Event>, index: number): Event;
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* 插入组件事件
|
|
514
|
-
* @param event 已有的组件事件实例
|
|
515
|
-
*/
|
|
516
|
-
insertEventAt(event: Event, index: number): Event;
|
|
517
|
-
|
|
518
|
-
insertEventAt(options: string | Partial<Event> | Event, index: number) {
|
|
519
|
-
const node = this._insertEventAt(options as any, index);
|
|
520
|
-
node.create({
|
|
521
|
-
index,
|
|
522
|
-
parentNode: this,
|
|
523
|
-
parentKey: 'events',
|
|
524
|
-
});
|
|
525
|
-
return node;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* 添加组件事件
|
|
530
|
-
* @internal
|
|
531
|
-
* @param name 组件事件名称,如果不填会自动生成一个唯一名称
|
|
532
|
-
*/
|
|
533
|
-
_addEvent(name?: string): Event;
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* 添加组件事件
|
|
537
|
-
* @internal
|
|
538
|
-
* @param eventOptions 组件事件参数
|
|
539
|
-
*/
|
|
540
|
-
_addEvent(eventOptions: Partial<Event>): Event;
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* 添加组件事件
|
|
544
|
-
* @internal
|
|
545
|
-
* @param event 已有的组件事件实例
|
|
546
|
-
*/
|
|
547
|
-
_addEvent(event: Event): Event;
|
|
548
|
-
|
|
549
|
-
_addEvent(options?: string | Partial<Event> | Event) {
|
|
550
|
-
const index = this.events.length;
|
|
551
|
-
return this._insertEventAt(options as any, index);
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* 添加组件事件
|
|
556
|
-
* @internal
|
|
557
|
-
* @param name 组件事件名称,如果不填会自动生成一个唯一名称
|
|
558
|
-
*/
|
|
559
|
-
addEvent(name?: string): Event;
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
* 添加组件事件
|
|
563
|
-
* @param eventOptions 组件事件参数
|
|
564
|
-
*/
|
|
565
|
-
addEvent(eventOptions: Partial<Event>): Event;
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* 添加组件事件
|
|
569
|
-
* @param event 已有的组件事件实例
|
|
570
|
-
*/
|
|
571
|
-
addEvent(event: Event): Event;
|
|
572
|
-
|
|
573
|
-
addEvent(options?: string | Partial<Event> | Event) {
|
|
574
|
-
const node = this._addEvent(options as any);
|
|
575
|
-
const index = this.events.indexOf(node);
|
|
576
|
-
node.create({
|
|
577
|
-
index,
|
|
578
|
-
parentNode: this,
|
|
579
|
-
parentKey: 'events',
|
|
580
|
-
});
|
|
581
|
-
return node;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
getParamUniqueName(name = 'param1') {
|
|
585
|
-
return utils.unique(name, this.getVarExistingNames(), undefined, false);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
* 插入参数分组
|
|
590
|
-
* @internal
|
|
591
|
-
* @param name 参数分组名称,如果不填会自动生成一个唯一名称
|
|
592
|
-
*/
|
|
593
|
-
_insertParamAt(name: string, index: number): ParamWithGroup;
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* 插入参数分组
|
|
597
|
-
* @internal
|
|
598
|
-
* @param paramOptions 参数分组参数
|
|
599
|
-
*/
|
|
600
|
-
_insertParamAt(paramOptions: Partial<ParamWithGroup>, index: number): ParamWithGroup;
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* 插入参数分组
|
|
604
|
-
* @internal
|
|
605
|
-
* @param param 已有的参数分组实例
|
|
606
|
-
*/
|
|
607
|
-
_insertParamAt(param: ParamWithGroup, index: number): ParamWithGroup;
|
|
608
|
-
|
|
609
|
-
_insertParamAt(options: string | Partial<ParamWithGroup> | ParamWithGroup, index: number) {
|
|
610
|
-
const paramOptions: any = {};
|
|
611
|
-
const relationOptions = { parentNode: this, parentKey: 'params' };
|
|
612
|
-
const ParamWithGroup = getConceptConstructor('ParamWithGroup');
|
|
613
|
-
let param: ParamWithGroup;
|
|
614
|
-
if (!options) {
|
|
615
|
-
param = ParamWithGroup.from(
|
|
616
|
-
{
|
|
617
|
-
...paramOptions,
|
|
618
|
-
name: this.getParamUniqueName(),
|
|
619
|
-
},
|
|
620
|
-
this,
|
|
621
|
-
'params',
|
|
622
|
-
);
|
|
623
|
-
} else if (typeof options === 'string') {
|
|
624
|
-
param = ParamWithGroup.from(
|
|
625
|
-
{
|
|
626
|
-
...paramOptions,
|
|
627
|
-
name: options,
|
|
628
|
-
},
|
|
629
|
-
this,
|
|
630
|
-
'params',
|
|
631
|
-
);
|
|
632
|
-
} else if (asserts.isParamWithGroup(options)) {
|
|
633
|
-
options.ensureDelete(); // 同一实例不支持多处存在
|
|
634
|
-
param = options;
|
|
635
|
-
Object.assign(param, relationOptions);
|
|
636
|
-
} else {
|
|
637
|
-
param = ParamWithGroup.from(
|
|
638
|
-
{
|
|
639
|
-
...paramOptions,
|
|
640
|
-
...options,
|
|
641
|
-
},
|
|
642
|
-
this,
|
|
643
|
-
'params',
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
this.params.splice(index, 0, param);
|
|
647
|
-
return param;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* 插入参数分组
|
|
652
|
-
* @param name 参数分组名称,如果不填会自动生成一个唯一名称
|
|
653
|
-
*/
|
|
654
|
-
insertParamAt(name: string, index: number): ParamWithGroup;
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* 插入参数分组
|
|
658
|
-
* @param paramOptions 参数分组参数
|
|
659
|
-
*/
|
|
660
|
-
insertParamAt(paramOptions: Partial<ParamWithGroup>, index: number): ParamWithGroup;
|
|
661
|
-
|
|
662
|
-
/**
|
|
663
|
-
* 插入参数分组
|
|
664
|
-
* @param param 已有的参数分组实例
|
|
665
|
-
*/
|
|
666
|
-
insertParamAt(param: ParamWithGroup, index: number): ParamWithGroup;
|
|
667
|
-
|
|
668
|
-
insertParamAt(options: string | Partial<ParamWithGroup> | ParamWithGroup, index: number) {
|
|
669
|
-
const node = this._insertParamAt(options as any, index);
|
|
670
|
-
node.create({
|
|
671
|
-
index,
|
|
672
|
-
parentNode: this,
|
|
673
|
-
parentKey: 'params',
|
|
674
|
-
});
|
|
675
|
-
return node;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
/**
|
|
679
|
-
* 添加参数分组
|
|
680
|
-
* @internal
|
|
681
|
-
* @param name 参数分组名称,如果不填会自动生成一个唯一名称
|
|
682
|
-
*/
|
|
683
|
-
_addParam(name?: string): ParamWithGroup;
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* 添加参数分组
|
|
687
|
-
* @internal
|
|
688
|
-
* @param paramOptions 参数分组参数
|
|
689
|
-
*/
|
|
690
|
-
_addParam(paramOptions: Partial<ParamWithGroup>): ParamWithGroup;
|
|
691
|
-
|
|
692
|
-
/**
|
|
693
|
-
* 添加参数分组
|
|
694
|
-
* @internal
|
|
695
|
-
* @param param 已有的参数分组实例
|
|
696
|
-
*/
|
|
697
|
-
_addParam(param: ParamWithGroup): ParamWithGroup;
|
|
698
|
-
|
|
699
|
-
_addParam(options?: string | Partial<ParamWithGroup> | ParamWithGroup) {
|
|
700
|
-
const index = this.params.length;
|
|
701
|
-
return this._insertParamAt(options as any, index);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
/**
|
|
705
|
-
* 添加参数分组
|
|
706
|
-
* @internal
|
|
707
|
-
* @param name 参数分组名称,如果不填会自动生成一个唯一名称
|
|
708
|
-
*/
|
|
709
|
-
addParam(name?: string): ParamWithGroup;
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* 添加参数分组
|
|
713
|
-
* @param paramOptions 参数分组参数
|
|
714
|
-
*/
|
|
715
|
-
addParam(paramOptions: Partial<ParamWithGroup>): ParamWithGroup;
|
|
716
|
-
|
|
717
|
-
/**
|
|
718
|
-
* 添加参数分组
|
|
719
|
-
* @param param 已有的参数分组实例
|
|
720
|
-
*/
|
|
721
|
-
addParam(param: ParamWithGroup): ParamWithGroup;
|
|
722
|
-
|
|
723
|
-
addParam(options?: string | Partial<ParamWithGroup> | ParamWithGroup) {
|
|
724
|
-
const node = this._addParam(options as any);
|
|
725
|
-
const index = this.params.indexOf(node);
|
|
726
|
-
node.create({
|
|
727
|
-
index,
|
|
728
|
-
parentNode: this,
|
|
729
|
-
parentKey: 'params',
|
|
730
|
-
});
|
|
731
|
-
return node;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
getVariableUniqueName(name = 'variable1') {
|
|
735
|
-
return utils.unique(name, this.getVarExistingNames(), undefined, false);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
/**
|
|
739
|
-
* 插入变量
|
|
740
|
-
* @internal
|
|
741
|
-
* @param name 变量名称,如果不填会自动生成一个唯一名称
|
|
742
|
-
*/
|
|
743
|
-
_insertVariableAt(name: string, index: number): Variable;
|
|
744
|
-
|
|
745
|
-
/**
|
|
746
|
-
* 插入变量
|
|
747
|
-
* @internal
|
|
748
|
-
* @param variableOptions 变量参数
|
|
749
|
-
*/
|
|
750
|
-
_insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
|
|
751
|
-
|
|
752
|
-
/**
|
|
753
|
-
* 插入变量
|
|
754
|
-
* @internal
|
|
755
|
-
* @param variable 已有的变量实例
|
|
756
|
-
*/
|
|
757
|
-
_insertVariableAt(variable: Variable, index: number): Variable;
|
|
758
|
-
|
|
759
|
-
_insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
|
|
760
|
-
const variableOptions: any = {};
|
|
761
|
-
const relationOptions = { parentNode: this, parentKey: 'variables' };
|
|
762
|
-
const Variable = getConceptConstructor('Variable');
|
|
763
|
-
let variable: Variable;
|
|
764
|
-
if (!options) {
|
|
765
|
-
variable = Variable.from(
|
|
766
|
-
{
|
|
767
|
-
...variableOptions,
|
|
768
|
-
name: this.getVariableUniqueName(),
|
|
769
|
-
},
|
|
770
|
-
this,
|
|
771
|
-
'variables',
|
|
772
|
-
);
|
|
773
|
-
} else if (typeof options === 'string') {
|
|
774
|
-
variable = Variable.from(
|
|
775
|
-
{
|
|
776
|
-
...variableOptions,
|
|
777
|
-
name: options,
|
|
778
|
-
},
|
|
779
|
-
this,
|
|
780
|
-
'variables',
|
|
781
|
-
);
|
|
782
|
-
} else if (asserts.isVariable(options)) {
|
|
783
|
-
options.ensureDelete(); // 同一实例不支持多处存在
|
|
784
|
-
variable = options;
|
|
785
|
-
Object.assign(variable, relationOptions);
|
|
786
|
-
} else {
|
|
787
|
-
variable = Variable.from(
|
|
788
|
-
{
|
|
789
|
-
...variableOptions,
|
|
790
|
-
...options,
|
|
791
|
-
},
|
|
792
|
-
this,
|
|
793
|
-
'variables',
|
|
794
|
-
);
|
|
795
|
-
}
|
|
796
|
-
this.variables.splice(index, 0, variable);
|
|
797
|
-
return variable;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
/**
|
|
801
|
-
* 插入变量
|
|
802
|
-
* @param name 变量名称,如果不填会自动生成一个唯一名称
|
|
803
|
-
*/
|
|
804
|
-
insertVariableAt(name: string, index: number): Variable;
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* 插入变量
|
|
808
|
-
* @param variableOptions 变量参数
|
|
809
|
-
*/
|
|
810
|
-
insertVariableAt(variableOptions: Partial<Variable>, index: number): Variable;
|
|
811
|
-
|
|
812
|
-
/**
|
|
813
|
-
* 插入变量
|
|
814
|
-
* @param variable 已有的变量实例
|
|
815
|
-
*/
|
|
816
|
-
insertVariableAt(variable: Variable, index: number): Variable;
|
|
817
|
-
|
|
818
|
-
insertVariableAt(options: string | Partial<Variable> | Variable, index: number) {
|
|
819
|
-
const node = this._insertVariableAt(options as any, index);
|
|
820
|
-
node.create({
|
|
821
|
-
index,
|
|
822
|
-
parentNode: this,
|
|
823
|
-
parentKey: 'variables',
|
|
824
|
-
});
|
|
825
|
-
return node;
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
/**
|
|
829
|
-
* 添加变量
|
|
830
|
-
* @internal
|
|
831
|
-
* @param name 变量名称,如果不填会自动生成一个唯一名称
|
|
832
|
-
*/
|
|
833
|
-
_addVariable(name?: string): Variable;
|
|
834
|
-
|
|
835
|
-
/**
|
|
836
|
-
* 添加变量
|
|
837
|
-
* @internal
|
|
838
|
-
* @param variableOptions 变量参数
|
|
839
|
-
*/
|
|
840
|
-
_addVariable(variableOptions: Partial<Variable>): Variable;
|
|
841
|
-
|
|
842
|
-
/**
|
|
843
|
-
* 添加变量
|
|
844
|
-
* @internal
|
|
845
|
-
* @param variable 已有的变量实例
|
|
846
|
-
*/
|
|
847
|
-
_addVariable(variable: Variable): Variable;
|
|
848
|
-
|
|
849
|
-
_addVariable(options?: string | Partial<Variable> | Variable) {
|
|
850
|
-
const index = this.variables.length;
|
|
851
|
-
return this._insertVariableAt(options as any, index);
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
/**
|
|
855
|
-
* 添加变量
|
|
856
|
-
* @internal
|
|
857
|
-
* @param name 变量名称,如果不填会自动生成一个唯一名称
|
|
858
|
-
*/
|
|
859
|
-
addVariable(name?: string): Variable;
|
|
860
|
-
|
|
861
|
-
/**
|
|
862
|
-
* 添加变量
|
|
863
|
-
* @param variableOptions 变量参数
|
|
864
|
-
*/
|
|
865
|
-
addVariable(variableOptions: Partial<Variable>): Variable;
|
|
866
|
-
|
|
867
|
-
/**
|
|
868
|
-
* 添加变量
|
|
869
|
-
* @param variable 已有的变量实例
|
|
870
|
-
*/
|
|
871
|
-
addVariable(variable: Variable): Variable;
|
|
872
|
-
|
|
873
|
-
addVariable(options?: string | Partial<Variable> | Variable) {
|
|
874
|
-
const node = this._addVariable(options as any);
|
|
875
|
-
const index = this.variables.indexOf(node);
|
|
876
|
-
node.create({
|
|
877
|
-
index,
|
|
878
|
-
parentNode: this,
|
|
879
|
-
parentKey: 'variables',
|
|
880
|
-
});
|
|
881
|
-
return node;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
getBindEventExistingNames(excludedList: Array<BindEvent> = []) {
|
|
885
|
-
const excludedSet = new Set(excludedList);
|
|
886
|
-
return ((this.bindEvents as BindEvent[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
|
|
887
|
-
}
|
|
888
|
-
getBindEventUniqueName(name = 'bindEvent1') {
|
|
889
|
-
return utils.unique(name, this.getBindEventExistingNames(), undefined, false);
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
* 插入元素绑定事件
|
|
894
|
-
* @internal
|
|
895
|
-
* @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
|
|
896
|
-
*/
|
|
897
|
-
_insertBindEventAt(name: string, index: number): BindEvent;
|
|
898
|
-
|
|
899
|
-
/**
|
|
900
|
-
* 插入元素绑定事件
|
|
901
|
-
* @internal
|
|
902
|
-
* @param bindEventOptions 元素绑定事件参数
|
|
903
|
-
*/
|
|
904
|
-
_insertBindEventAt(bindEventOptions: Partial<BindEvent>, index: number): BindEvent;
|
|
905
|
-
|
|
906
|
-
/**
|
|
907
|
-
* 插入元素绑定事件
|
|
908
|
-
* @internal
|
|
909
|
-
* @param bindEvent 已有的元素绑定事件实例
|
|
910
|
-
*/
|
|
911
|
-
_insertBindEventAt(bindEvent: BindEvent, index: number): BindEvent;
|
|
912
|
-
|
|
913
|
-
_insertBindEventAt(options: string | Partial<BindEvent> | BindEvent, index: number) {
|
|
914
|
-
const bindEventOptions: any = {};
|
|
915
|
-
const relationOptions = { parentNode: this, parentKey: 'bindEvents' };
|
|
916
|
-
const BindEvent = getConceptConstructor('BindEvent');
|
|
917
|
-
let bindEvent: BindEvent;
|
|
918
|
-
if (!options) {
|
|
919
|
-
bindEvent = BindEvent.from(
|
|
920
|
-
{
|
|
921
|
-
...bindEventOptions,
|
|
922
|
-
name: this.getBindEventUniqueName(),
|
|
923
|
-
},
|
|
924
|
-
this,
|
|
925
|
-
'bindEvents',
|
|
926
|
-
);
|
|
927
|
-
} else if (typeof options === 'string') {
|
|
928
|
-
bindEvent = BindEvent.from(
|
|
929
|
-
{
|
|
930
|
-
...bindEventOptions,
|
|
931
|
-
name: options,
|
|
932
|
-
},
|
|
933
|
-
this,
|
|
934
|
-
'bindEvents',
|
|
935
|
-
);
|
|
936
|
-
} else if (asserts.isBindEvent(options)) {
|
|
937
|
-
options.ensureDelete(); // 同一实例不支持多处存在
|
|
938
|
-
bindEvent = options;
|
|
939
|
-
Object.assign(bindEvent, relationOptions);
|
|
940
|
-
} else {
|
|
941
|
-
bindEvent = BindEvent.from(
|
|
942
|
-
{
|
|
943
|
-
...bindEventOptions,
|
|
944
|
-
...options,
|
|
945
|
-
},
|
|
946
|
-
this,
|
|
947
|
-
'bindEvents',
|
|
948
|
-
);
|
|
949
|
-
}
|
|
950
|
-
this.bindEvents.splice(index, 0, bindEvent);
|
|
951
|
-
return bindEvent;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
/**
|
|
955
|
-
* 插入元素绑定事件
|
|
956
|
-
* @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
|
|
957
|
-
*/
|
|
958
|
-
insertBindEventAt(name: string, index: number): BindEvent;
|
|
959
|
-
|
|
960
|
-
/**
|
|
961
|
-
* 插入元素绑定事件
|
|
962
|
-
* @param bindEventOptions 元素绑定事件参数
|
|
963
|
-
*/
|
|
964
|
-
insertBindEventAt(bindEventOptions: Partial<BindEvent>, index: number): BindEvent;
|
|
965
|
-
|
|
966
|
-
/**
|
|
967
|
-
* 插入元素绑定事件
|
|
968
|
-
* @param bindEvent 已有的元素绑定事件实例
|
|
969
|
-
*/
|
|
970
|
-
insertBindEventAt(bindEvent: BindEvent, index: number): BindEvent;
|
|
971
|
-
|
|
972
|
-
insertBindEventAt(options: string | Partial<BindEvent> | BindEvent, index: number) {
|
|
973
|
-
const node = this._insertBindEventAt(options as any, index);
|
|
974
|
-
node.create({
|
|
975
|
-
index,
|
|
976
|
-
parentNode: this,
|
|
977
|
-
parentKey: 'bindEvents',
|
|
978
|
-
});
|
|
979
|
-
return node;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
/**
|
|
983
|
-
* 添加元素绑定事件
|
|
984
|
-
* @internal
|
|
985
|
-
* @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
|
|
986
|
-
*/
|
|
987
|
-
_addBindEvent(name?: string): BindEvent;
|
|
988
|
-
|
|
989
|
-
/**
|
|
990
|
-
* 添加元素绑定事件
|
|
991
|
-
* @internal
|
|
992
|
-
* @param bindEventOptions 元素绑定事件参数
|
|
993
|
-
*/
|
|
994
|
-
_addBindEvent(bindEventOptions: Partial<BindEvent>): BindEvent;
|
|
995
|
-
|
|
996
|
-
/**
|
|
997
|
-
* 添加元素绑定事件
|
|
998
|
-
* @internal
|
|
999
|
-
* @param bindEvent 已有的元素绑定事件实例
|
|
1000
|
-
*/
|
|
1001
|
-
_addBindEvent(bindEvent: BindEvent): BindEvent;
|
|
1002
|
-
|
|
1003
|
-
_addBindEvent(options?: string | Partial<BindEvent> | BindEvent) {
|
|
1004
|
-
const index = this.bindEvents.length;
|
|
1005
|
-
return this._insertBindEventAt(options as any, index);
|
|
1006
|
-
}
|
|
1007
|
-
|
|
1008
|
-
/**
|
|
1009
|
-
* 添加元素绑定事件
|
|
1010
|
-
* @internal
|
|
1011
|
-
* @param name 元素绑定事件名称,如果不填会自动生成一个唯一名称
|
|
1012
|
-
*/
|
|
1013
|
-
addBindEvent(name?: string): BindEvent;
|
|
1014
|
-
|
|
1015
|
-
/**
|
|
1016
|
-
* 添加元素绑定事件
|
|
1017
|
-
* @param bindEventOptions 元素绑定事件参数
|
|
1018
|
-
*/
|
|
1019
|
-
addBindEvent(bindEventOptions: Partial<BindEvent>): BindEvent;
|
|
1020
|
-
|
|
1021
|
-
/**
|
|
1022
|
-
* 添加元素绑定事件
|
|
1023
|
-
* @param bindEvent 已有的元素绑定事件实例
|
|
1024
|
-
*/
|
|
1025
|
-
addBindEvent(bindEvent: BindEvent): BindEvent;
|
|
1026
|
-
|
|
1027
|
-
addBindEvent(options?: string | Partial<BindEvent> | BindEvent) {
|
|
1028
|
-
const node = this._addBindEvent(options as any);
|
|
1029
|
-
const index = this.bindEvents.indexOf(node);
|
|
1030
|
-
node.create({
|
|
1031
|
-
index,
|
|
1032
|
-
parentNode: this,
|
|
1033
|
-
parentKey: 'bindEvents',
|
|
1034
|
-
});
|
|
1035
|
-
return node;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
getLogicExistingNames(excludedList: Array<BusinessLogic> = []) {
|
|
1039
|
-
const excludedSet = new Set(excludedList);
|
|
1040
|
-
return ((this.logics as BusinessLogic[]) || []).filter((item) => !excludedSet.has(item)).map((item) => item?.name);
|
|
1041
|
-
}
|
|
1042
|
-
getLogicUniqueName(name = 'logic1') {
|
|
1043
|
-
return utils.unique(name, this.getLogicExistingNames(), undefined, false);
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
/**
|
|
1047
|
-
* 插入业务组件逻辑
|
|
1048
|
-
* @internal
|
|
1049
|
-
* @param name 业务组件逻辑名称,如果不填会自动生成一个唯一名称
|
|
1050
|
-
*/
|
|
1051
|
-
_insertLogicAt(name: string, index: number): BusinessLogic;
|
|
1052
|
-
|
|
1053
|
-
/**
|
|
1054
|
-
* 插入业务组件逻辑
|
|
1055
|
-
* @internal
|
|
1056
|
-
* @param logicOptions 业务组件逻辑参数
|
|
1057
|
-
*/
|
|
1058
|
-
_insertLogicAt(logicOptions: Partial<BusinessLogic>, index: number): BusinessLogic;
|
|
1059
|
-
|
|
1060
|
-
/**
|
|
1061
|
-
* 插入业务组件逻辑
|
|
1062
|
-
* @internal
|
|
1063
|
-
* @param logic 已有的业务组件逻辑实例
|
|
1064
|
-
*/
|
|
1065
|
-
_insertLogicAt(logic: BusinessLogic, index: number): BusinessLogic;
|
|
1066
|
-
|
|
1067
|
-
_insertLogicAt(options: string | Partial<BusinessLogic> | BusinessLogic, index: number) {
|
|
1068
|
-
const logicOptions: any = {};
|
|
1069
|
-
const relationOptions = { parentNode: this, parentKey: 'logics' };
|
|
1070
|
-
const BusinessLogic = getConceptConstructor('BusinessLogic');
|
|
1071
|
-
let logic: BusinessLogic;
|
|
1072
|
-
if (!options) {
|
|
1073
|
-
logic = BusinessLogic.from(
|
|
1074
|
-
{
|
|
1075
|
-
...logicOptions,
|
|
1076
|
-
name: this.getLogicUniqueName(),
|
|
1077
|
-
},
|
|
1078
|
-
this,
|
|
1079
|
-
'logics',
|
|
1080
|
-
);
|
|
1081
|
-
} else if (typeof options === 'string') {
|
|
1082
|
-
logic = BusinessLogic.from(
|
|
1083
|
-
{
|
|
1084
|
-
...logicOptions,
|
|
1085
|
-
name: options,
|
|
1086
|
-
},
|
|
1087
|
-
this,
|
|
1088
|
-
'logics',
|
|
1089
|
-
);
|
|
1090
|
-
} else if (asserts.isBusinessLogic(options)) {
|
|
1091
|
-
options.ensureDelete(); // 同一实例不支持多处存在
|
|
1092
|
-
logic = options;
|
|
1093
|
-
Object.assign(logic, relationOptions);
|
|
1094
|
-
} else {
|
|
1095
|
-
logic = BusinessLogic.from(
|
|
1096
|
-
{
|
|
1097
|
-
...logicOptions,
|
|
1098
|
-
...options,
|
|
1099
|
-
},
|
|
1100
|
-
this,
|
|
1101
|
-
'logics',
|
|
1102
|
-
);
|
|
1103
|
-
}
|
|
1104
|
-
this.logics.splice(index, 0, logic);
|
|
1105
|
-
return logic;
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
/**
|
|
1109
|
-
* 插入业务组件逻辑
|
|
1110
|
-
* @param name 业务组件逻辑名称,如果不填会自动生成一个唯一名称
|
|
1111
|
-
*/
|
|
1112
|
-
insertLogicAt(name: string, index: number): BusinessLogic;
|
|
1113
|
-
|
|
1114
|
-
/**
|
|
1115
|
-
* 插入业务组件逻辑
|
|
1116
|
-
* @param logicOptions 业务组件逻辑参数
|
|
1117
|
-
*/
|
|
1118
|
-
insertLogicAt(logicOptions: Partial<BusinessLogic>, index: number): BusinessLogic;
|
|
1119
|
-
|
|
1120
|
-
/**
|
|
1121
|
-
* 插入业务组件逻辑
|
|
1122
|
-
* @param logic 已有的业务组件逻辑实例
|
|
1123
|
-
*/
|
|
1124
|
-
insertLogicAt(logic: BusinessLogic, index: number): BusinessLogic;
|
|
1125
|
-
|
|
1126
|
-
insertLogicAt(options: string | Partial<BusinessLogic> | BusinessLogic, index: number) {
|
|
1127
|
-
const node = this._insertLogicAt(options as any, index);
|
|
1128
|
-
node.create({
|
|
1129
|
-
index,
|
|
1130
|
-
parentNode: this,
|
|
1131
|
-
parentKey: 'logics',
|
|
1132
|
-
});
|
|
1133
|
-
return node;
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
/**
|
|
1137
|
-
* 添加业务组件逻辑
|
|
1138
|
-
* @internal
|
|
1139
|
-
* @param name 业务组件逻辑名称,如果不填会自动生成一个唯一名称
|
|
1140
|
-
*/
|
|
1141
|
-
_addLogic(name?: string): BusinessLogic;
|
|
1142
|
-
|
|
1143
|
-
/**
|
|
1144
|
-
* 添加业务组件逻辑
|
|
1145
|
-
* @internal
|
|
1146
|
-
* @param logicOptions 业务组件逻辑参数
|
|
1147
|
-
*/
|
|
1148
|
-
_addLogic(logicOptions: Partial<BusinessLogic>): BusinessLogic;
|
|
1149
|
-
|
|
1150
|
-
/**
|
|
1151
|
-
* 添加业务组件逻辑
|
|
1152
|
-
* @internal
|
|
1153
|
-
* @param logic 已有的业务组件逻辑实例
|
|
1154
|
-
*/
|
|
1155
|
-
_addLogic(logic: BusinessLogic): BusinessLogic;
|
|
1156
|
-
|
|
1157
|
-
_addLogic(options?: string | Partial<BusinessLogic> | BusinessLogic) {
|
|
1158
|
-
const index = this.logics.length;
|
|
1159
|
-
return this._insertLogicAt(options as any, index);
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
/**
|
|
1163
|
-
* 添加业务组件逻辑
|
|
1164
|
-
* @internal
|
|
1165
|
-
* @param name 业务组件逻辑名称,如果不填会自动生成一个唯一名称
|
|
1166
|
-
*/
|
|
1167
|
-
addLogic(name?: string): BusinessLogic;
|
|
1168
|
-
|
|
1169
|
-
/**
|
|
1170
|
-
* 添加业务组件逻辑
|
|
1171
|
-
* @param logicOptions 业务组件逻辑参数
|
|
1172
|
-
*/
|
|
1173
|
-
addLogic(logicOptions: Partial<BusinessLogic>): BusinessLogic;
|
|
1174
|
-
|
|
1175
|
-
/**
|
|
1176
|
-
* 添加业务组件逻辑
|
|
1177
|
-
* @param logic 已有的业务组件逻辑实例
|
|
1178
|
-
*/
|
|
1179
|
-
addLogic(logic: BusinessLogic): BusinessLogic;
|
|
1180
|
-
|
|
1181
|
-
addLogic(options?: string | Partial<BusinessLogic> | BusinessLogic) {
|
|
1182
|
-
const node = this._addLogic(options as any);
|
|
1183
|
-
const index = this.logics.indexOf(node);
|
|
1184
|
-
node.create({
|
|
1185
|
-
index,
|
|
1186
|
-
parentNode: this,
|
|
1187
|
-
parentKey: 'logics',
|
|
1188
|
-
});
|
|
1189
|
-
return node;
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
/**
|
|
1193
|
-
* 插入页面元素
|
|
1194
|
-
* @internal
|
|
1195
|
-
* @param name 页面元素名称,如果不填会自动生成一个唯一名称
|
|
1196
|
-
*/
|
|
1197
|
-
_insertViewElementAt(name: string, index: number): ViewElement;
|
|
1198
|
-
|
|
1199
|
-
/**
|
|
1200
|
-
* 插入页面元素
|
|
1201
|
-
* @internal
|
|
1202
|
-
* @param viewElementOptions 页面元素参数
|
|
1203
|
-
*/
|
|
1204
|
-
_insertViewElementAt(viewElementOptions: Partial<ViewElement>, index: number): ViewElement;
|
|
1205
|
-
|
|
1206
|
-
/**
|
|
1207
|
-
* 插入页面元素
|
|
1208
|
-
* @internal
|
|
1209
|
-
* @param viewElement 已有的页面元素实例
|
|
1210
|
-
*/
|
|
1211
|
-
_insertViewElementAt(viewElement: ViewElement, index: number): ViewElement;
|
|
1212
|
-
|
|
1213
|
-
_insertViewElementAt(options: string | Partial<ViewElement> | ViewElement, index: number) {
|
|
1214
|
-
const viewElementOptions: any = {};
|
|
1215
|
-
const relationOptions = { parentNode: this, parentKey: 'elements' };
|
|
1216
|
-
const ViewElement = getConceptConstructor('ViewElement');
|
|
1217
|
-
let viewElement: ViewElement;
|
|
1218
|
-
if (!options) {
|
|
1219
|
-
viewElement = ViewElement.from(
|
|
1220
|
-
{
|
|
1221
|
-
...viewElementOptions,
|
|
1222
|
-
name: this.getViewElementUniqueName(),
|
|
1223
|
-
},
|
|
1224
|
-
this,
|
|
1225
|
-
'elements',
|
|
1226
|
-
);
|
|
1227
|
-
} else if (typeof options === 'string') {
|
|
1228
|
-
viewElement = ViewElement.from(
|
|
1229
|
-
{
|
|
1230
|
-
...viewElementOptions,
|
|
1231
|
-
name: options,
|
|
1232
|
-
},
|
|
1233
|
-
this,
|
|
1234
|
-
'elements',
|
|
1235
|
-
);
|
|
1236
|
-
} else if (asserts.isViewElement(options)) {
|
|
1237
|
-
options.ensureDelete(); // 同一实例不支持多处存在
|
|
1238
|
-
viewElement = options;
|
|
1239
|
-
Object.assign(viewElement, relationOptions);
|
|
1240
|
-
} else {
|
|
1241
|
-
viewElement = ViewElement.from(
|
|
1242
|
-
{
|
|
1243
|
-
...viewElementOptions,
|
|
1244
|
-
...options,
|
|
1245
|
-
},
|
|
1246
|
-
this,
|
|
1247
|
-
'elements',
|
|
1248
|
-
);
|
|
1249
|
-
}
|
|
1250
|
-
this.elements.splice(index, 0, viewElement);
|
|
1251
|
-
return viewElement;
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
/**
|
|
1255
|
-
* 插入页面元素
|
|
1256
|
-
* @param name 页面元素名称,如果不填会自动生成一个唯一名称
|
|
1257
|
-
*/
|
|
1258
|
-
insertViewElementAt(name: string, index: number): ViewElement;
|
|
1259
|
-
|
|
1260
|
-
/**
|
|
1261
|
-
* 插入页面元素
|
|
1262
|
-
* @param viewElementOptions 页面元素参数
|
|
1263
|
-
*/
|
|
1264
|
-
insertViewElementAt(viewElementOptions: Partial<ViewElement>, index: number): ViewElement;
|
|
1265
|
-
|
|
1266
|
-
/**
|
|
1267
|
-
* 插入页面元素
|
|
1268
|
-
* @param viewElement 已有的页面元素实例
|
|
1269
|
-
*/
|
|
1270
|
-
insertViewElementAt(viewElement: ViewElement, index: number): ViewElement;
|
|
1271
|
-
|
|
1272
|
-
insertViewElementAt(options: string | Partial<ViewElement> | ViewElement, index: number) {
|
|
1273
|
-
const node = this._insertViewElementAt(options as any, index);
|
|
1274
|
-
node.create({
|
|
1275
|
-
index,
|
|
1276
|
-
parentNode: this,
|
|
1277
|
-
parentKey: 'elements',
|
|
1278
|
-
});
|
|
1279
|
-
return node;
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
/**
|
|
1283
|
-
* 添加页面元素
|
|
1284
|
-
* @internal
|
|
1285
|
-
* @param name 页面元素名称,如果不填会自动生成一个唯一名称
|
|
1286
|
-
*/
|
|
1287
|
-
_addViewElement(name?: string): ViewElement;
|
|
1288
|
-
|
|
1289
|
-
/**
|
|
1290
|
-
* 添加页面元素
|
|
1291
|
-
* @internal
|
|
1292
|
-
* @param viewElementOptions 页面元素参数
|
|
1293
|
-
*/
|
|
1294
|
-
_addViewElement(viewElementOptions: Partial<ViewElement>): ViewElement;
|
|
1295
|
-
|
|
1296
|
-
/**
|
|
1297
|
-
* 添加页面元素
|
|
1298
|
-
* @internal
|
|
1299
|
-
* @param viewElement 已有的页面元素实例
|
|
1300
|
-
*/
|
|
1301
|
-
_addViewElement(viewElement: ViewElement): ViewElement;
|
|
1302
|
-
|
|
1303
|
-
_addViewElement(options?: string | Partial<ViewElement> | ViewElement) {
|
|
1304
|
-
const index = this.elements.length;
|
|
1305
|
-
return this._insertViewElementAt(options as any, index);
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
/**
|
|
1309
|
-
* 添加页面元素
|
|
1310
|
-
* @internal
|
|
1311
|
-
* @param name 页面元素名称,如果不填会自动生成一个唯一名称
|
|
1312
|
-
*/
|
|
1313
|
-
addViewElement(name?: string): ViewElement;
|
|
1314
|
-
|
|
1315
|
-
/**
|
|
1316
|
-
* 添加页面元素
|
|
1317
|
-
* @param viewElementOptions 页面元素参数
|
|
1318
|
-
*/
|
|
1319
|
-
addViewElement(viewElementOptions: Partial<ViewElement>): ViewElement;
|
|
1320
|
-
|
|
1321
|
-
/**
|
|
1322
|
-
* 添加页面元素
|
|
1323
|
-
* @param viewElement 已有的页面元素实例
|
|
1324
|
-
*/
|
|
1325
|
-
addViewElement(viewElement: ViewElement): ViewElement;
|
|
1326
|
-
|
|
1327
|
-
addViewElement(options?: string | Partial<ViewElement> | ViewElement) {
|
|
1328
|
-
const node = this._addViewElement(options as any);
|
|
1329
|
-
const index = this.elements.indexOf(node);
|
|
1330
|
-
node.create({
|
|
1331
|
-
index,
|
|
1332
|
-
parentNode: this,
|
|
1333
|
-
parentKey: 'elements',
|
|
1334
|
-
});
|
|
1335
|
-
return node;
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
/**
|
|
1339
|
-
* 删除组件事件
|
|
1340
|
-
* @param name 组件事件名称
|
|
1341
|
-
*/
|
|
1342
|
-
removeEvent(name: string): void;
|
|
1343
|
-
|
|
1344
|
-
/**
|
|
1345
|
-
* 删除组件事件
|
|
1346
|
-
* @param event 已有的组件事件实例
|
|
1347
|
-
*/
|
|
1348
|
-
removeEvent(event: Event): void;
|
|
1349
|
-
|
|
1350
|
-
removeEvent(options: string | Event) {
|
|
1351
|
-
let event: Event;
|
|
1352
|
-
if (typeof options === 'string') {
|
|
1353
|
-
event = (this.events as Event[]).find((item) => item.name === options);
|
|
1354
|
-
if (!event) {
|
|
1355
|
-
throw new Error('找不到组件事件 ' + options);
|
|
1356
|
-
}
|
|
1357
|
-
} else {
|
|
1358
|
-
event = options;
|
|
1359
|
-
}
|
|
1360
|
-
return event.delete();
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
|
-
__removeEvent(event: Event) {
|
|
1364
|
-
const parentKey = event.parentKey;
|
|
1365
|
-
const params: Params = {
|
|
1366
|
-
parentNode: this,
|
|
1367
|
-
parentKey,
|
|
1368
|
-
index: -1,
|
|
1369
|
-
object: null,
|
|
1370
|
-
oldObject: event,
|
|
1371
|
-
};
|
|
1372
|
-
if (parentKey) {
|
|
1373
|
-
params.parentKey = parentKey;
|
|
1374
|
-
// @ts-ignore
|
|
1375
|
-
const t = this.__v_raw || this;
|
|
1376
|
-
// @ts-ignore
|
|
1377
|
-
const n = event.__v_raw || event;
|
|
1378
|
-
if (Array.isArray((t as any)[parentKey])) {
|
|
1379
|
-
// @ts-ignore
|
|
1380
|
-
const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
|
|
1381
|
-
~index && (this as any)[parentKey].splice(index, 1);
|
|
1382
|
-
params.index = index;
|
|
1383
|
-
} else {
|
|
1384
|
-
const q = (t as any)[parentKey];
|
|
1385
|
-
if ((q.__v_raw || q) === n) {
|
|
1386
|
-
params.index = 0;
|
|
1387
|
-
(this as any)[parentKey] = undefined;
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
return params;
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
/**
|
|
1395
|
-
* 删除参数分组
|
|
1396
|
-
* @param name 参数分组名称
|
|
1397
|
-
*/
|
|
1398
|
-
removeParam(name: string): void;
|
|
1399
|
-
|
|
1400
|
-
/**
|
|
1401
|
-
* 删除参数分组
|
|
1402
|
-
* @param param 已有的参数分组实例
|
|
1403
|
-
*/
|
|
1404
|
-
removeParam(param: ParamWithGroup): void;
|
|
1405
|
-
|
|
1406
|
-
removeParam(options: string | ParamWithGroup) {
|
|
1407
|
-
let param: ParamWithGroup;
|
|
1408
|
-
if (typeof options === 'string') {
|
|
1409
|
-
param = (this.params as ParamWithGroup[]).find((item) => item.name === options);
|
|
1410
|
-
if (!param) {
|
|
1411
|
-
throw new Error('找不到参数分组 ' + options);
|
|
1412
|
-
}
|
|
1413
|
-
} else {
|
|
1414
|
-
param = options;
|
|
1415
|
-
}
|
|
1416
|
-
return param.delete();
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
__removeParam(param: Param) {
|
|
1420
|
-
const parentKey = param.parentKey;
|
|
1421
|
-
const params: Params = {
|
|
1422
|
-
parentNode: this,
|
|
1423
|
-
parentKey,
|
|
1424
|
-
index: -1,
|
|
1425
|
-
object: null,
|
|
1426
|
-
oldObject: param,
|
|
1427
|
-
};
|
|
1428
|
-
if (parentKey) {
|
|
1429
|
-
params.parentKey = parentKey;
|
|
1430
|
-
// @ts-ignore
|
|
1431
|
-
const t = this.__v_raw || this;
|
|
1432
|
-
// @ts-ignore
|
|
1433
|
-
const n = param.__v_raw || param;
|
|
1434
|
-
if (Array.isArray((t as any)[parentKey])) {
|
|
1435
|
-
// @ts-ignore
|
|
1436
|
-
const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
|
|
1437
|
-
~index && (this as any)[parentKey].splice(index, 1);
|
|
1438
|
-
params.index = index;
|
|
1439
|
-
} else {
|
|
1440
|
-
const q = (t as any)[parentKey];
|
|
1441
|
-
if ((q.__v_raw || q) === n) {
|
|
1442
|
-
params.index = 0;
|
|
1443
|
-
(this as any)[parentKey] = undefined;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
return params;
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
/**
|
|
1451
|
-
* 删除变量
|
|
1452
|
-
* @param name 变量名称
|
|
1453
|
-
*/
|
|
1454
|
-
removeVariable(name: string): void;
|
|
1455
|
-
|
|
1456
|
-
/**
|
|
1457
|
-
* 删除变量
|
|
1458
|
-
* @param variable 已有的变量实例
|
|
1459
|
-
*/
|
|
1460
|
-
removeVariable(variable: Variable): void;
|
|
1461
|
-
|
|
1462
|
-
removeVariable(options: string | Variable) {
|
|
1463
|
-
let variable: Variable;
|
|
1464
|
-
if (typeof options === 'string') {
|
|
1465
|
-
variable = (this.variables as Variable[]).find((item) => item.name === options);
|
|
1466
|
-
if (!variable) {
|
|
1467
|
-
throw new Error('找不到变量 ' + options);
|
|
1468
|
-
}
|
|
1469
|
-
} else {
|
|
1470
|
-
variable = options;
|
|
1471
|
-
}
|
|
1472
|
-
return variable.delete();
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
__removeVariable(variable: Variable) {
|
|
1476
|
-
const parentKey = variable.parentKey;
|
|
1477
|
-
const params: Params = {
|
|
1478
|
-
parentNode: this,
|
|
1479
|
-
parentKey,
|
|
1480
|
-
index: -1,
|
|
1481
|
-
object: null,
|
|
1482
|
-
oldObject: variable,
|
|
1483
|
-
};
|
|
1484
|
-
if (parentKey) {
|
|
1485
|
-
params.parentKey = parentKey;
|
|
1486
|
-
// @ts-ignore
|
|
1487
|
-
const t = this.__v_raw || this;
|
|
1488
|
-
// @ts-ignore
|
|
1489
|
-
const n = variable.__v_raw || variable;
|
|
1490
|
-
if (Array.isArray((t as any)[parentKey])) {
|
|
1491
|
-
// @ts-ignore
|
|
1492
|
-
const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
|
|
1493
|
-
~index && (this as any)[parentKey].splice(index, 1);
|
|
1494
|
-
params.index = index;
|
|
1495
|
-
} else {
|
|
1496
|
-
const q = (t as any)[parentKey];
|
|
1497
|
-
if ((q.__v_raw || q) === n) {
|
|
1498
|
-
params.index = 0;
|
|
1499
|
-
(this as any)[parentKey] = undefined;
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
}
|
|
1503
|
-
return params;
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
/**
|
|
1507
|
-
* 删除元素绑定事件
|
|
1508
|
-
* @param name 元素绑定事件名称
|
|
1509
|
-
*/
|
|
1510
|
-
removeBindEvent(name: string): void;
|
|
1511
|
-
|
|
1512
|
-
/**
|
|
1513
|
-
* 删除元素绑定事件
|
|
1514
|
-
* @param bindEvent 已有的元素绑定事件实例
|
|
1515
|
-
*/
|
|
1516
|
-
removeBindEvent(bindEvent: BindEvent): void;
|
|
1517
|
-
|
|
1518
|
-
removeBindEvent(options: string | BindEvent) {
|
|
1519
|
-
let bindEvent: BindEvent;
|
|
1520
|
-
if (typeof options === 'string') {
|
|
1521
|
-
bindEvent = (this.bindEvents as BindEvent[]).find((item) => item.name === options);
|
|
1522
|
-
if (!bindEvent) {
|
|
1523
|
-
throw new Error('找不到元素绑定事件 ' + options);
|
|
1524
|
-
}
|
|
1525
|
-
} else {
|
|
1526
|
-
bindEvent = options;
|
|
1527
|
-
}
|
|
1528
|
-
return bindEvent.delete();
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
__removeBindEvent(bindEvent: BindEvent) {
|
|
1532
|
-
const parentKey = bindEvent.parentKey;
|
|
1533
|
-
const params: Params = {
|
|
1534
|
-
parentNode: this,
|
|
1535
|
-
parentKey,
|
|
1536
|
-
index: -1,
|
|
1537
|
-
object: null,
|
|
1538
|
-
oldObject: bindEvent,
|
|
1539
|
-
};
|
|
1540
|
-
if (parentKey) {
|
|
1541
|
-
params.parentKey = parentKey;
|
|
1542
|
-
// @ts-ignore
|
|
1543
|
-
const t = this.__v_raw || this;
|
|
1544
|
-
// @ts-ignore
|
|
1545
|
-
const n = bindEvent.__v_raw || bindEvent;
|
|
1546
|
-
if (Array.isArray((t as any)[parentKey])) {
|
|
1547
|
-
// @ts-ignore
|
|
1548
|
-
const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
|
|
1549
|
-
~index && (this as any)[parentKey].splice(index, 1);
|
|
1550
|
-
params.index = index;
|
|
1551
|
-
} else {
|
|
1552
|
-
const q = (t as any)[parentKey];
|
|
1553
|
-
if ((q.__v_raw || q) === n) {
|
|
1554
|
-
params.index = 0;
|
|
1555
|
-
(this as any)[parentKey] = undefined;
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
return params;
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
/**
|
|
1563
|
-
* 删除业务组件逻辑
|
|
1564
|
-
* @param name 业务组件逻辑名称
|
|
1565
|
-
*/
|
|
1566
|
-
removeLogic(name: string): void;
|
|
1567
|
-
|
|
1568
|
-
/**
|
|
1569
|
-
* 删除业务组件逻辑
|
|
1570
|
-
* @param logic 已有的业务组件逻辑实例
|
|
1571
|
-
*/
|
|
1572
|
-
removeLogic(logic: BusinessLogic): void;
|
|
1573
|
-
|
|
1574
|
-
removeLogic(options: string | BusinessLogic) {
|
|
1575
|
-
let logic: BusinessLogic;
|
|
1576
|
-
if (typeof options === 'string') {
|
|
1577
|
-
logic = (this.logics as BusinessLogic[]).find((item) => item.name === options);
|
|
1578
|
-
if (!logic) {
|
|
1579
|
-
throw new Error('找不到业务组件逻辑 ' + options);
|
|
1580
|
-
}
|
|
1581
|
-
} else {
|
|
1582
|
-
logic = options;
|
|
1583
|
-
}
|
|
1584
|
-
return logic.delete();
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
__removeLogic(logic: Logic) {
|
|
1588
|
-
const parentKey = logic.parentKey;
|
|
1589
|
-
const params: Params = {
|
|
1590
|
-
parentNode: this,
|
|
1591
|
-
parentKey,
|
|
1592
|
-
index: -1,
|
|
1593
|
-
object: null,
|
|
1594
|
-
oldObject: logic,
|
|
1595
|
-
};
|
|
1596
|
-
if (parentKey) {
|
|
1597
|
-
params.parentKey = parentKey;
|
|
1598
|
-
// @ts-ignore
|
|
1599
|
-
const t = this.__v_raw || this;
|
|
1600
|
-
// @ts-ignore
|
|
1601
|
-
const n = logic.__v_raw || logic;
|
|
1602
|
-
if (Array.isArray((t as any)[parentKey])) {
|
|
1603
|
-
// @ts-ignore
|
|
1604
|
-
const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
|
|
1605
|
-
~index && (this as any)[parentKey].splice(index, 1);
|
|
1606
|
-
params.index = index;
|
|
1607
|
-
} else {
|
|
1608
|
-
const q = (t as any)[parentKey];
|
|
1609
|
-
if ((q.__v_raw || q) === n) {
|
|
1610
|
-
params.index = 0;
|
|
1611
|
-
(this as any)[parentKey] = undefined;
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
return params;
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
/**
|
|
1619
|
-
* 删除页面元素
|
|
1620
|
-
* @param name 页面元素名称
|
|
1621
|
-
*/
|
|
1622
|
-
removeViewElement(name: string): void;
|
|
1623
|
-
|
|
1624
|
-
/**
|
|
1625
|
-
* 删除页面元素
|
|
1626
|
-
* @param viewElement 已有的页面元素实例
|
|
1627
|
-
*/
|
|
1628
|
-
removeViewElement(viewElement: ViewElement): void;
|
|
1629
|
-
|
|
1630
|
-
removeViewElement(options: string | ViewElement) {
|
|
1631
|
-
let viewElement: ViewElement;
|
|
1632
|
-
if (typeof options === 'string') {
|
|
1633
|
-
viewElement = (this.elements as ViewElement[]).find((item) => item.name === options);
|
|
1634
|
-
if (!viewElement) {
|
|
1635
|
-
throw new Error('找不到页面元素 ' + options);
|
|
1636
|
-
}
|
|
1637
|
-
} else {
|
|
1638
|
-
viewElement = options;
|
|
1639
|
-
}
|
|
1640
|
-
return viewElement.delete();
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
__removeViewElement(viewElement: ViewElement) {
|
|
1644
|
-
const parentKey = viewElement.parentKey;
|
|
1645
|
-
const params: Params = {
|
|
1646
|
-
parentNode: this,
|
|
1647
|
-
parentKey,
|
|
1648
|
-
index: -1,
|
|
1649
|
-
object: null,
|
|
1650
|
-
oldObject: viewElement,
|
|
1651
|
-
};
|
|
1652
|
-
if (parentKey) {
|
|
1653
|
-
params.parentKey = parentKey;
|
|
1654
|
-
// @ts-ignore
|
|
1655
|
-
const t = this.__v_raw || this;
|
|
1656
|
-
// @ts-ignore
|
|
1657
|
-
const n = viewElement.__v_raw || viewElement;
|
|
1658
|
-
if (Array.isArray((t as any)[parentKey])) {
|
|
1659
|
-
// @ts-ignore
|
|
1660
|
-
const index = (t as any)[parentKey].findIndex((el) => (el.__v_raw || el) === n);
|
|
1661
|
-
~index && (this as any)[parentKey].splice(index, 1);
|
|
1662
|
-
params.index = index;
|
|
1663
|
-
} else {
|
|
1664
|
-
const q = (t as any)[parentKey];
|
|
1665
|
-
if ((q.__v_raw || q) === n) {
|
|
1666
|
-
params.index = 0;
|
|
1667
|
-
(this as any)[parentKey] = undefined;
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
return params;
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
//================================================================================
|
|
1675
|
-
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|
|
1676
|
-
// 自动生成的代码已结束。下面可以手动编写。
|
|
1677
|
-
//================================================================================
|
|
1678
|
-
static getDefaultOptions() {
|
|
1679
|
-
return {
|
|
1680
|
-
title: '业务组件',
|
|
1681
|
-
};
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
getNamespace(): string {
|
|
1685
|
-
if (this.parentNode && (this.parentNode as FrontendType).getNamespace) {
|
|
1686
|
-
const parentNamespace = (this.parentNode as FrontendType).getNamespace();
|
|
1687
|
-
const parentName = this.parentNode.name;
|
|
1688
|
-
const arr = [parentNamespace];
|
|
1689
|
-
if (this.parentNode.concept !== 'App' && parentName) {
|
|
1690
|
-
arr.push(parentName);
|
|
1691
|
-
}
|
|
1692
|
-
return `${arr.join('.')}.businessComponents`;
|
|
1693
|
-
}
|
|
1694
|
-
throw new Error('无法获取命名空间,请设置 parentNode!');
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
getTsNamespace() {
|
|
1698
|
-
const parentNodeNamespace = this.getNamespace();
|
|
1699
|
-
let tsCalleeNamespace = parentNodeNamespace.replace(/\.[0-9]/g, (m) => m.replace('.', '.$'));
|
|
1700
|
-
tsCalleeNamespace = tsCalleeNamespace.replace(/-/g, '_');
|
|
1701
|
-
return tsCalleeNamespace;
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
|
-
/**
|
|
1705
|
-
* 获取当前业务组件下所有elements上bindEvents下的logic
|
|
1706
|
-
*/
|
|
1707
|
-
elementLogicRoot: any[] = [];
|
|
1708
|
-
|
|
1709
|
-
getElementLogicRoot() {
|
|
1710
|
-
const Param = getConceptConstructor('Param');
|
|
1711
|
-
const logics: Array<Logic> = [];
|
|
1712
|
-
// 页面上的绑定的事件
|
|
1713
|
-
this.bindEvents.forEach((bindEvent) => {
|
|
1714
|
-
bindEvent.logics.forEach((logic) => {
|
|
1715
|
-
// 键盘事件
|
|
1716
|
-
if (['keydown', 'keyup'].includes(bindEvent.name)) {
|
|
1717
|
-
logic.virtualParams = [
|
|
1718
|
-
Param.from(
|
|
1719
|
-
{
|
|
1720
|
-
name: 'event',
|
|
1721
|
-
typeAnnotation: null,
|
|
1722
|
-
},
|
|
1723
|
-
logic,
|
|
1724
|
-
'virtualParams',
|
|
1725
|
-
),
|
|
1726
|
-
];
|
|
1727
|
-
}
|
|
1728
|
-
// 生命周期没有event
|
|
1729
|
-
logics.push(logic);
|
|
1730
|
-
});
|
|
1731
|
-
});
|
|
1732
|
-
this.elements.forEach((item) => {
|
|
1733
|
-
utils.traverse(
|
|
1734
|
-
(current) => {
|
|
1735
|
-
current.node.bindEvents.forEach((bindEvent) => {
|
|
1736
|
-
bindEvent.logics.forEach((logic) => {
|
|
1737
|
-
if (logic.name.startsWith('__')) {
|
|
1738
|
-
return;
|
|
1739
|
-
}
|
|
1740
|
-
// 绑定参数才有 event 的 current
|
|
1741
|
-
logic.virtualParams = bindEvent.getContextRenderLogicParams(logic);
|
|
1742
|
-
logics.push(logic);
|
|
1743
|
-
});
|
|
1744
|
-
});
|
|
1745
|
-
},
|
|
1746
|
-
{ node: item },
|
|
1747
|
-
);
|
|
1748
|
-
});
|
|
1749
|
-
if (logics.length) {
|
|
1750
|
-
const expanded = (this.elementLogicRoot.length && this.elementLogicRoot[0].expanded) || false;
|
|
1751
|
-
this.elementLogicRoot = [
|
|
1752
|
-
{
|
|
1753
|
-
concept: 'elementLogicRoot',
|
|
1754
|
-
expanded,
|
|
1755
|
-
children: logics,
|
|
1756
|
-
},
|
|
1757
|
-
];
|
|
1758
|
-
} else {
|
|
1759
|
-
this.elementLogicRoot = [];
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
getVarExistingNames(excludedList: Array<Param | Variable> = []) {
|
|
1764
|
-
const excludedSet = new Set(excludedList);
|
|
1765
|
-
const varList: any[] = [];
|
|
1766
|
-
if (Array.isArray(this.params)) {
|
|
1767
|
-
varList.push(...this.params);
|
|
1768
|
-
}
|
|
1769
|
-
if (Array.isArray(this.variables)) {
|
|
1770
|
-
varList.push(...this.variables);
|
|
1771
|
-
}
|
|
1772
|
-
if (Array.isArray(this.logics)) {
|
|
1773
|
-
this.logics.forEach((logic) => {
|
|
1774
|
-
varList.push(logic);
|
|
1775
|
-
if (Array.isArray(logic.params)) {
|
|
1776
|
-
varList.push(...logic.params);
|
|
1777
|
-
}
|
|
1778
|
-
if (Array.isArray(logic.returns)) {
|
|
1779
|
-
varList.push(...logic.returns);
|
|
1780
|
-
}
|
|
1781
|
-
if (Array.isArray(logic.variables)) {
|
|
1782
|
-
varList.push(...logic.variables);
|
|
1783
|
-
}
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
// 事件逻辑的变量不允许和页面逻辑下的重复
|
|
1787
|
-
if (Array.isArray(this.elementLogicRoot) && this.elementLogicRoot.length) {
|
|
1788
|
-
this.elementLogicRoot[0]?.children.forEach((logic: Logic) => {
|
|
1789
|
-
if (Array.isArray(logic.variables)) {
|
|
1790
|
-
varList.push(...logic.variables);
|
|
1791
|
-
}
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
return varList.filter((item) => !excludedSet.has(item)).map((item) => item.name);
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
|
-
existingViewElement: Set<string> = new Set<string>();
|
|
1798
|
-
|
|
1799
|
-
// 收集已经存在的ViewElement
|
|
1800
|
-
collectExistingViewElementName(excludedList: Array<ViewElement> = []) {
|
|
1801
|
-
const excludedSet = new Set(excludedList);
|
|
1802
|
-
this.elements.forEach((element) => {
|
|
1803
|
-
utils.traverse(
|
|
1804
|
-
({ node }) => {
|
|
1805
|
-
if (!excludedSet.has(node)) {
|
|
1806
|
-
this.existingViewElement.add(node.name);
|
|
1807
|
-
}
|
|
1808
|
-
},
|
|
1809
|
-
{
|
|
1810
|
-
node: element,
|
|
1811
|
-
},
|
|
1812
|
-
);
|
|
1813
|
-
});
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1816
|
-
// 获取当前业务组件的所有组件的名字
|
|
1817
|
-
getViewElementExistingNames(excludedList: Array<ViewElement> = []) {
|
|
1818
|
-
if (!this.existingViewElement.size) {
|
|
1819
|
-
this.collectExistingViewElementName();
|
|
1820
|
-
}
|
|
1821
|
-
return Array.from(this.existingViewElement);
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
getViewElementUniqueNameOld(name = 'viewElement1') {
|
|
1825
|
-
this.collectExistingViewElementName();
|
|
1826
|
-
const viewElementUniqueName = utils.unique(name, this.existingViewElement);
|
|
1827
|
-
this.existingViewElement.add(viewElementUniqueName);
|
|
1828
|
-
return viewElementUniqueName;
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
getViewElementUniqueName(name = 'viewElement_1') {
|
|
1832
|
-
this.collectExistingViewElementName();
|
|
1833
|
-
const BranchCopyUniCode = getBranchCopyUniCode();
|
|
1834
|
-
let newName = name;
|
|
1835
|
-
const prefix = name.replace(/\d*$/, '');
|
|
1836
|
-
if (BranchCopyUniCode && prefix.indexOf(`_${BranchCopyUniCode}_`) === -1) {
|
|
1837
|
-
newName = name.replace(/\d*$/, (m) => `_${BranchCopyUniCode}_${m}`);
|
|
1838
|
-
}
|
|
1839
|
-
// 主分支无 BranchCopyUniCode
|
|
1840
|
-
if (!BranchCopyUniCode && prefix.at(-1) !== '_') {
|
|
1841
|
-
newName = name.replace(/\d*$/, (m) => `_${m}`);
|
|
1842
|
-
}
|
|
1843
|
-
const newPrefix = newName.replace(/\d*$/, '');
|
|
1844
|
-
const newPrefixNum = removedViewElementCache?.[newPrefix] ? removedViewElementCache[newPrefix] : 1;
|
|
1845
|
-
const startNum =
|
|
1846
|
-
newPrefixNum < Number.MAX_SAFE_INTEGER ? (newPrefixNum as number) + 1 : BigInt(newPrefixNum) + BigInt(1);
|
|
1847
|
-
const viewElementUniqueName = utils.uniqueMax(
|
|
1848
|
-
newName,
|
|
1849
|
-
this.existingViewElement,
|
|
1850
|
-
removedViewElementCache?.[newPrefix] ? startNum : newPrefixNum,
|
|
1851
|
-
);
|
|
1852
|
-
this.existingViewElement.add(viewElementUniqueName);
|
|
1853
|
-
return viewElementUniqueName;
|
|
1854
|
-
}
|
|
1855
|
-
|
|
1856
|
-
// 获取当前element,铺平
|
|
1857
|
-
elementsMethods(elements: Array<ViewElement>, allMethods: Array<ViewElement>, parentNodeNames: Array<string>) {
|
|
1858
|
-
if (elements) {
|
|
1859
|
-
elements.forEach((item: ViewElement) => {
|
|
1860
|
-
const { bindAttrs = [], name } = item;
|
|
1861
|
-
const isDataSource = bindAttrs.some((attr) => attr.name === 'data-source');
|
|
1862
|
-
const isInclude = parentNodeNames.includes(name);
|
|
1863
|
-
|
|
1864
|
-
allMethods.push(item);
|
|
1865
|
-
if (item.children) {
|
|
1866
|
-
if (isDataSource) {
|
|
1867
|
-
if (isInclude) {
|
|
1868
|
-
this.elementsMethods(item.children, allMethods, parentNodeNames);
|
|
1869
|
-
}
|
|
1870
|
-
} else {
|
|
1871
|
-
this.elementsMethods(item.children, allMethods, parentNodeNames);
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
});
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
mergeBlock({ code, nodePath, position, cb }: { code: string; nodePath: string; position: string; cb?: Function }) {
|
|
1879
|
-
const ViewElement = getConceptConstructor('ViewElement');
|
|
1880
|
-
const Logic = getConceptConstructor('Logic');
|
|
1881
|
-
const ParamWithGroup = getConceptConstructor('ParamWithGroup');
|
|
1882
|
-
const Variable = getConceptConstructor('Variable');
|
|
1883
|
-
const BindEvent = getConceptConstructor('BindEvent');
|
|
1884
|
-
const Structure = getConceptConstructor('Structure');
|
|
1885
|
-
const template = utils.sliceTagContent(code, 'template');
|
|
1886
|
-
let targetNode = (this.getAncestor('App') as App)?.findNodeByPath(nodePath);
|
|
1887
|
-
let parentNode = position === 'append' ? targetNode : targetNode.parentNode;
|
|
1888
|
-
const definitionStr = utils.sliceTagContent(code, 'definition') || '{}';
|
|
1889
|
-
const definition: any = JSON.parse(definitionStr);
|
|
1890
|
-
let node = null;
|
|
1891
|
-
if (template) {
|
|
1892
|
-
node = ViewElement.fromHTML(template, {
|
|
1893
|
-
view: this,
|
|
1894
|
-
definition,
|
|
1895
|
-
});
|
|
1896
|
-
if (!parentNode) {
|
|
1897
|
-
return;
|
|
1898
|
-
}
|
|
1899
|
-
if (position === 'append') {
|
|
1900
|
-
parentNode.addViewElement(node);
|
|
1901
|
-
cb && cb(parentNode, node);
|
|
1902
|
-
} else {
|
|
1903
|
-
const index = targetNode.getIndexOfParent();
|
|
1904
|
-
if (position === 'insertBefore') {
|
|
1905
|
-
parentNode.insertViewElementAt(node, index);
|
|
1906
|
-
} else if (position === 'insertAfter') {
|
|
1907
|
-
parentNode.insertViewElementAt(node, index + 1);
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
// 服务端逻辑
|
|
1913
|
-
if (Array.isArray(definition.logics)) {
|
|
1914
|
-
definition.logics.forEach((logicOption: any) => {
|
|
1915
|
-
const logic = Logic.from(
|
|
1916
|
-
{
|
|
1917
|
-
...logicOption,
|
|
1918
|
-
},
|
|
1919
|
-
this.rootNode,
|
|
1920
|
-
'logics',
|
|
1921
|
-
);
|
|
1922
|
-
(this.rootNode as App).addLogic(logic);
|
|
1923
|
-
});
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
// 全局结构体
|
|
1927
|
-
if (Array.isArray(definition.structures)) {
|
|
1928
|
-
definition.structures.forEach((structureOption: any) => {
|
|
1929
|
-
const structure = Structure.from(
|
|
1930
|
-
{
|
|
1931
|
-
...structureOption,
|
|
1932
|
-
},
|
|
1933
|
-
this.rootNode,
|
|
1934
|
-
'structures',
|
|
1935
|
-
);
|
|
1936
|
-
(this.rootNode as App).addStructure(structure);
|
|
1937
|
-
});
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
// 页面入参
|
|
1941
|
-
if (Array.isArray(definition.viewParams)) {
|
|
1942
|
-
definition.viewParams.forEach((paramsOption: any) => {
|
|
1943
|
-
const param = ParamWithGroup.from(
|
|
1944
|
-
{
|
|
1945
|
-
...paramsOption,
|
|
1946
|
-
},
|
|
1947
|
-
this,
|
|
1948
|
-
'params',
|
|
1949
|
-
);
|
|
1950
|
-
this._addParam(param);
|
|
1951
|
-
param.addParamsPrepare();
|
|
1952
|
-
});
|
|
1953
|
-
}
|
|
1954
|
-
// 页面变量
|
|
1955
|
-
if (Array.isArray(definition.viewVariables)) {
|
|
1956
|
-
definition.viewVariables.forEach((variableOption: any) => {
|
|
1957
|
-
const variable = Variable.from(
|
|
1958
|
-
{
|
|
1959
|
-
...variableOption,
|
|
1960
|
-
},
|
|
1961
|
-
this,
|
|
1962
|
-
'variables',
|
|
1963
|
-
);
|
|
1964
|
-
this.addVariable(variable);
|
|
1965
|
-
});
|
|
1966
|
-
}
|
|
1967
|
-
|
|
1968
|
-
// 页面事件
|
|
1969
|
-
if (Array.isArray(definition.viewBindEvents)) {
|
|
1970
|
-
definition.viewBindEvents.forEach((eventOption: any) => {
|
|
1971
|
-
const newLogic = definition.viewLogics.find((logic: Logic) => eventOption.calleeName === logic.name);
|
|
1972
|
-
const bindEvent = this.bindEvents.find((currentEventItem) => currentEventItem.name === eventOption.name);
|
|
1973
|
-
|
|
1974
|
-
// 如果没有event对象就先新增一个,如果已经有了就在内部添加logic
|
|
1975
|
-
if (!bindEvent) {
|
|
1976
|
-
const event = BindEvent.from(
|
|
1977
|
-
{
|
|
1978
|
-
...eventOption,
|
|
1979
|
-
calleeName: '',
|
|
1980
|
-
logics: [newLogic],
|
|
1981
|
-
},
|
|
1982
|
-
this,
|
|
1983
|
-
'events',
|
|
1984
|
-
);
|
|
1985
|
-
this.addBindEvent(event);
|
|
1986
|
-
} else {
|
|
1987
|
-
bindEvent.addLogic(newLogic);
|
|
1988
|
-
}
|
|
1989
|
-
});
|
|
1990
|
-
}
|
|
1991
|
-
return node;
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
onChange($event?: EventPayload): void {
|
|
1995
|
-
this.emit('change', $event);
|
|
1996
|
-
}
|
|
1997
|
-
|
|
1998
|
-
/**
|
|
1999
|
-
* 转换成设计器中使用的 Vue template 内容
|
|
2000
|
-
* @param options
|
|
2001
|
-
*/
|
|
2002
|
-
genDesignerVueTemplate(options?: { asCompontent?: boolean }) {
|
|
2003
|
-
return this.elements
|
|
2004
|
-
.map(
|
|
2005
|
-
(element) =>
|
|
2006
|
-
`${element.toDesignerVue({
|
|
2007
|
-
isRoot: true,
|
|
2008
|
-
asCompontent: options?.asCompontent,
|
|
2009
|
-
})}\n`,
|
|
2010
|
-
)
|
|
2011
|
-
.join('');
|
|
2012
|
-
}
|
|
2013
|
-
|
|
2014
|
-
get frontendType() {
|
|
2015
|
-
return this.getAncestor('FrontendType') as FrontendType;
|
|
2016
|
-
}
|
|
2017
|
-
|
|
2018
|
-
get path() {
|
|
2019
|
-
return `/${this.frontendType?.kind}/${this.name}`;
|
|
2020
|
-
}
|
|
2021
|
-
|
|
2022
|
-
get slotElems() {
|
|
2023
|
-
const slotElems: ViewElement[] = [];
|
|
2024
|
-
this.elements.forEach((element) => {
|
|
2025
|
-
utils.traverse(
|
|
2026
|
-
({ node }) => {
|
|
2027
|
-
if (node.tag === 'slot') {
|
|
2028
|
-
slotElems.push(node);
|
|
2029
|
-
}
|
|
2030
|
-
},
|
|
2031
|
-
{
|
|
2032
|
-
node: element,
|
|
2033
|
-
},
|
|
2034
|
-
);
|
|
2035
|
-
});
|
|
2036
|
-
return slotElems;
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
/**
|
|
2040
|
-
* 转换成 Vue 文件
|
|
2041
|
-
*/
|
|
2042
|
-
toVue(options?: ElementToVueOptions) {
|
|
2043
|
-
let result = '';
|
|
2044
|
-
result += `<template>\n${this.genVueTemplate(options)}\n</template>\n`;
|
|
2045
|
-
result += `<script>\n${this.genScript()}\n</script>\n`;
|
|
2046
|
-
return result;
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
/**
|
|
2050
|
-
* 生成宿主语言的文件路径
|
|
2051
|
-
* @param name 一般不用传,用于 rename
|
|
2052
|
-
*/
|
|
2053
|
-
getEmbeddedFilePath(name = this.name) {
|
|
2054
|
-
return `/embedded/${this.rootNode?.name || this.parentNode.name}/frontendTypes/${this.getAncestor('FrontendType')?.name
|
|
2055
|
-
}/${name}.ts`;
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
*toEmbeddedTSFile(): EmbeddedTSFileGenerator {
|
|
2059
|
-
let code = `namespace ${this.getTsNamespace()} {\n`;
|
|
2060
|
-
const state = createCompilerState(code, {
|
|
2061
|
-
tabSize: 1,
|
|
2062
|
-
});
|
|
2063
|
-
|
|
2064
|
-
try {
|
|
2065
|
-
code += yield* this.toEmbeddedTS(state);
|
|
2066
|
-
} catch (err) {
|
|
2067
|
-
code += '';
|
|
2068
|
-
console.log(err);
|
|
2069
|
-
}
|
|
2070
|
-
|
|
2071
|
-
code += '}\n';
|
|
2072
|
-
|
|
2073
|
-
return {
|
|
2074
|
-
code,
|
|
2075
|
-
filePath: this.getEmbeddedFilePath(),
|
|
2076
|
-
sourceMap: state.sourceMap,
|
|
2077
|
-
};
|
|
2078
|
-
}
|
|
2079
|
-
|
|
2080
|
-
getAncestorViewElementsWithDataSource(logic: Logic): ViewElement[] {
|
|
2081
|
-
let element: types.SyntaxNode = logic;
|
|
2082
|
-
const viewElements: ViewElement[] = [];
|
|
2083
|
-
while (element) {
|
|
2084
|
-
if (
|
|
2085
|
-
element.concept &&
|
|
2086
|
-
element.concept === 'ViewElement' &&
|
|
2087
|
-
(element as ViewElement).bindAttrs.find((bAttr) => bAttr.name === 'data-source')
|
|
2088
|
-
) {
|
|
2089
|
-
viewElements.push(element as ViewElement);
|
|
2090
|
-
}
|
|
2091
|
-
element = element.parentNode;
|
|
2092
|
-
}
|
|
2093
|
-
return viewElements;
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
|
-
*handleCurrentItemCode(code: string, logic: Logic) {
|
|
2097
|
-
const viewElementsWithDataSource: ViewElement[] = this.getAncestorViewElementsWithDataSource(logic);
|
|
2098
|
-
yield* wrapForEach(viewElementsWithDataSource, function* wrapForEach(viewElement, index) {
|
|
2099
|
-
const currentIndex = viewElementsWithDataSource.length - 1 - index;
|
|
2100
|
-
const currentItemCode = `current${currentIndex === 0 ? '' : currentIndex}.item`;
|
|
2101
|
-
if (code.includes(currentItemCode)) {
|
|
2102
|
-
const dataSource = viewElement.bindAttrs.find((bAttr) => bAttr.name === 'data-source');
|
|
2103
|
-
if (dataSource) {
|
|
2104
|
-
const businessComponent = viewElement.getAncestor('BusinessComponent') as BusinessComponent;
|
|
2105
|
-
const dataSourceTS = yield* dataSource.expression.toEmbeddedTS();
|
|
2106
|
-
const logic = businessComponent.logics.find((logic) => logic.name === dataSourceTS);
|
|
2107
|
-
if (logic) {
|
|
2108
|
-
code = code.replaceAll(
|
|
2109
|
-
currentItemCode,
|
|
2110
|
-
`nasl.ui.getCurrentItemType(${dataSourceTS}(${logic.params.map(() => 'null').join(',')}))`,
|
|
2111
|
-
);
|
|
2112
|
-
} else {
|
|
2113
|
-
const variable = businessComponent.variables.find((variable) => variable.name === dataSourceTS);
|
|
2114
|
-
code = code.replaceAll(
|
|
2115
|
-
currentItemCode,
|
|
2116
|
-
`nasl.ui.getCurrentItemType(${variable ? variable.name : dataSourceTS})`,
|
|
2117
|
-
);
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
});
|
|
2122
|
-
return code;
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
removeExistingViewElement(viewElement: ViewElement) {
|
|
2126
|
-
if (this.existingViewElement.has(viewElement.name)) {
|
|
2127
|
-
this.existingViewElement.delete(viewElement.name);
|
|
2128
|
-
}
|
|
2129
|
-
|
|
2130
|
-
const prefix = viewElement?.name.replace(/\d*$/, '');
|
|
2131
|
-
let lastDigit = viewElement?.name.match(/\d+$/)?.[0];
|
|
2132
|
-
if (lastDigit === undefined) return;
|
|
2133
|
-
|
|
2134
|
-
//@ts-ignore
|
|
2135
|
-
lastDigit = lastDigit < Number.MAX_SAFE_INTEGER ? parseInt(lastDigit) : BigInt(lastDigit);
|
|
2136
|
-
|
|
2137
|
-
if (removedViewElementCache?.[prefix]) {
|
|
2138
|
-
//@ts-ignore
|
|
2139
|
-
if (lastDigit > removedViewElementCache[prefix])
|
|
2140
|
-
//@ts-ignore
|
|
2141
|
-
removedViewElementCache[prefix] = lastDigit;
|
|
2142
|
-
} else {
|
|
2143
|
-
//@ts-ignore
|
|
2144
|
-
removedViewElementCache[prefix] = lastDigit;
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
|
|
2148
|
-
*getRightCode(code: string, assignment: Assignment | BatchAssignment, rightNode: any) {
|
|
2149
|
-
code = code.replaceAll('\n', ' ');
|
|
2150
|
-
const logic = assignment.logic;
|
|
2151
|
-
const logicRtn = logic?.returns[0];
|
|
2152
|
-
// 调用接口,参数替换成 null
|
|
2153
|
-
if (asserts.isCallInterface(rightNode)) {
|
|
2154
|
-
const { _interface } = rightNode.getModuleInterface();
|
|
2155
|
-
return _interface
|
|
2156
|
-
? `${rightNode.tsCalleeKey}(${(_interface as Interface).params.map(() => 'null').join(',')})`
|
|
2157
|
-
: null;
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
// 调用服务端逻辑,参数替换成 null
|
|
2161
|
-
if (asserts.isCallLogic(rightNode) && rightNode.calleeNamespace === 'app.logics') {
|
|
2162
|
-
const calleeName = rightNode?.calleeName;
|
|
2163
|
-
const calleeLogic = (this.getAncestor('App') as App).logics.find((l) => l.name === calleeName);
|
|
2164
|
-
return calleeLogic ? `app.logics.${calleeName}(${calleeLogic.params.map(() => 'null').join(',')})` : null;
|
|
2165
|
-
}
|
|
2166
|
-
|
|
2167
|
-
// view 局部变量,申明提升前增加判断,使用 logic 内的 result 直接替换成对应 logic,logic 内部变量替换成 null
|
|
2168
|
-
if (logicRtn && code.includes(logicRtn.name)) {
|
|
2169
|
-
if (code === logicRtn.name) return `${logic.name}(${logic.params.map(() => 'null').join(',')})`;
|
|
2170
|
-
|
|
2171
|
-
code = this.handleReplaceCode(code, logicRtn.name, `${logic.name}(${logic.params.map(() => 'null').join(',')})`);
|
|
2172
|
-
logic.params.forEach((param) => {
|
|
2173
|
-
if (code.includes(param.name)) code = this.handleReplaceCode(code, param.name, 'null');
|
|
2174
|
-
});
|
|
2175
|
-
logic.variables.forEach((variable) => {
|
|
2176
|
-
if (code.includes(variable.name)) code = this.handleReplaceCode(code, variable.name, 'null');
|
|
2177
|
-
});
|
|
2178
|
-
return code;
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
|
-
// 处理 current.item、current1.item 等数据
|
|
2182
|
-
if (/current(\d)*\.item/.test(code)) {
|
|
2183
|
-
code = yield* this.handleCurrentItemCode(code, logic);
|
|
2184
|
-
return code;
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
|
-
// 直接赋值 logic 内局部变量、输入参数直接提示系统无法推断类型
|
|
2188
|
-
const useLogicVar =
|
|
2189
|
-
logic.params.find((param) => code.includes(param.name)) ||
|
|
2190
|
-
logic.variables.find((variable) => code.includes(variable.name));
|
|
2191
|
-
return useLogicVar ? 'null' : code;
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
|
-
handleReplaceCode(code: string, variable: string, replaceCode: string) {
|
|
2195
|
-
return code.replace(/\S+/g, ($1) => {
|
|
2196
|
-
if ($1 === `${variable},`) return `${replaceCode},`;
|
|
2197
|
-
if ($1 === variable) return replaceCode;
|
|
2198
|
-
|
|
2199
|
-
let fnCode = $1;
|
|
2200
|
-
if ($1.startsWith(`${variable}.`)) fnCode = $1.replaceAll(`${variable}.`, `${replaceCode}.`);
|
|
2201
|
-
if ($1.startsWith(`${variable},`)) fnCode = $1.replaceAll(`${variable},`, `${replaceCode},`);
|
|
2202
|
-
if ($1.includes(`(${variable},`)) fnCode = $1.replaceAll(`(${variable},`, `(${replaceCode},`);
|
|
2203
|
-
if ($1.includes(`(${variable}.`)) fnCode = $1.replaceAll(`(${variable}.`, `(${replaceCode}.`);
|
|
2204
|
-
if ($1.includes(`(${variable})`)) fnCode = $1.replaceAll(`(${variable})`, `(${replaceCode})`);
|
|
2205
|
-
if ($1.includes(`,${variable},`)) fnCode = $1.replaceAll(`,${variable},`, `,${replaceCode},`);
|
|
2206
|
-
if ($1.includes(`,${variable}.`)) fnCode = $1.replaceAll(`,${variable}.`, `,${replaceCode}.`);
|
|
2207
|
-
if ($1.includes(`,${variable})`)) fnCode = $1.replaceAll(`,${variable})`, `,${replaceCode})`);
|
|
2208
|
-
return fnCode;
|
|
2209
|
-
});
|
|
2210
|
-
}
|
|
2211
|
-
|
|
2212
|
-
// 获取当前element,铺平
|
|
2213
|
-
elementsAttrs(elements: Array<ViewElement>, componentList: Array<ViewElement>) {
|
|
2214
|
-
if (elements) {
|
|
2215
|
-
elements.forEach((item: ViewElement) => {
|
|
2216
|
-
if (PAGE_COMPONENT_INCLUDE_TAG_MAP?.[item.tag]) {
|
|
2217
|
-
componentList.push(item);
|
|
2218
|
-
}
|
|
2219
|
-
if (item.children.length > 0) {
|
|
2220
|
-
this.elementsAttrs(item.children, componentList);
|
|
2221
|
-
}
|
|
2222
|
-
});
|
|
2223
|
-
}
|
|
2224
|
-
}
|
|
2225
|
-
|
|
2226
|
-
elementsAttrsAll(elements: Array<ViewElement>, componentListExtra: Array<ViewElement>) {
|
|
2227
|
-
if (elements) {
|
|
2228
|
-
elements.forEach((item: ViewElement) => {
|
|
2229
|
-
if (!PAGE_COMPONENT_INCLUDE_TAG_MAP?.[item.tag]) {
|
|
2230
|
-
componentListExtra.push(item);
|
|
2231
|
-
}
|
|
2232
|
-
if (item.children.length > 0) {
|
|
2233
|
-
this.elementsAttrsAll(item.children, componentListExtra);
|
|
2234
|
-
}
|
|
2235
|
-
});
|
|
2236
|
-
}
|
|
2237
|
-
}
|
|
2238
|
-
|
|
2239
|
-
@withSourceMapGenerator
|
|
2240
|
-
*toEmbeddedTS(state = createCompilerState()): TranslatorGenerator {
|
|
2241
|
-
const self = this;
|
|
2242
|
-
// 获取虚拟logic的参数和内容
|
|
2243
|
-
// 用作展示和tots查找引用
|
|
2244
|
-
self.getElementLogicRoot();
|
|
2245
|
-
let code = `export class ${self.tsName} extends nasl.ui.VueComponent {\n`;
|
|
2246
|
-
// 需要类型推导的局部变量/返回值需要调整申明顺序
|
|
2247
|
-
code += `constructor(
|
|
2248
|
-
options?: {
|
|
2249
|
-
[propname: string]: any,
|
|
2250
|
-
bindAttr?: {
|
|
2251
|
-
__NASLIF?: nasl.core.Boolean,
|
|
2252
|
-
`;
|
|
2253
|
-
if (Array.isArray(self.params)) {
|
|
2254
|
-
yield* wrapForEach(self.params, function* warpForEachGenerator(param, index) {
|
|
2255
|
-
code += `${param.name}?: `;
|
|
2256
|
-
code += yield* param.typeAnnotation.toEmbeddedTS(shiftState(state, code));
|
|
2257
|
-
code += ',\n';
|
|
2258
|
-
});
|
|
2259
|
-
}
|
|
2260
|
-
code += `
|
|
2261
|
-
},
|
|
2262
|
-
slotDefault?: () => Array<any>,
|
|
2263
|
-
}) {
|
|
2264
|
-
super();\n`;
|
|
2265
|
-
|
|
2266
|
-
// 绑定事件
|
|
2267
|
-
if (Array.isArray(self.bindEvents)) {
|
|
2268
|
-
yield* wrapForEach(self.bindEvents, function* warpForEachGenerator(event) {
|
|
2269
|
-
code += yield* event.toEmbeddedTS(
|
|
2270
|
-
shiftState(state, code, {
|
|
2271
|
-
tabSize: state?.tabSize || 0,
|
|
2272
|
-
}),
|
|
2273
|
-
true,
|
|
2274
|
-
);
|
|
2275
|
-
code += '\n';
|
|
2276
|
-
});
|
|
2277
|
-
}
|
|
2278
|
-
code += `\n}`;
|
|
2279
|
-
// 自定义事件的定义
|
|
2280
|
-
if (Array.isArray(self.events) && self.events.length) {
|
|
2281
|
-
code += indent((state?.tabSize || 0) + 1);
|
|
2282
|
-
yield* wrapForEach(self.events, function* warpForEachGenerator(event) {
|
|
2283
|
-
code += yield* event.toEmbeddedTS(
|
|
2284
|
-
shiftState(state, code, {
|
|
2285
|
-
tabSize: (state?.tabSize || 0) + 2,
|
|
2286
|
-
}),
|
|
2287
|
-
);
|
|
2288
|
-
code += '\n';
|
|
2289
|
-
});
|
|
2290
|
-
code += indent((state?.tabSize || 0) + 1);
|
|
2291
|
-
}
|
|
2292
|
-
// 逻辑
|
|
2293
|
-
if (Array.isArray(self.logics) && self.logics.length) {
|
|
2294
|
-
code += indent((state?.tabSize || 0) + 1);
|
|
2295
|
-
yield* wrapForEach(self.logics, function* warpForEachGenerator(logic) {
|
|
2296
|
-
code += yield* logic.toEmbeddedTS(
|
|
2297
|
-
shiftState(state, code, {
|
|
2298
|
-
tabSize: (state?.tabSize || 0) + 2,
|
|
2299
|
-
}),
|
|
2300
|
-
'noExport',
|
|
2301
|
-
);
|
|
2302
|
-
code += '\n';
|
|
2303
|
-
});
|
|
2304
|
-
code += indent((state?.tabSize || 0) + 1);
|
|
2305
|
-
}
|
|
2306
|
-
// render函数
|
|
2307
|
-
code += `\n${indent((state?.tabSize || 0) + 1)}`;
|
|
2308
|
-
code += `__render(`;
|
|
2309
|
-
code += `){\n`;
|
|
2310
|
-
code += indent(state?.tabSize || 0);
|
|
2311
|
-
// elements 元素
|
|
2312
|
-
if (Array.isArray(self.elements)) {
|
|
2313
|
-
// 生成嵌套式的内容
|
|
2314
|
-
yield* wrapForEach(self.elements, function* warpForEachGenerator(element) {
|
|
2315
|
-
code += yield* element.toEmbeddedTS(
|
|
2316
|
-
shiftState(state, code, {
|
|
2317
|
-
tabSize: (state?.tabSize || 0) + 3,
|
|
2318
|
-
}),
|
|
2319
|
-
);
|
|
2320
|
-
code += '\n';
|
|
2321
|
-
});
|
|
2322
|
-
}
|
|
2323
|
-
code += `\n${indent((state?.tabSize || 0) + 1)}}\n`;
|
|
2324
|
-
if (Array.isArray(self.params)) {
|
|
2325
|
-
code += `${indent((state?.tabSize || 0) + 1)}$destination(options: {`;
|
|
2326
|
-
yield* wrapForEach(self.params, function* warpForEachGenerator(param, index) {
|
|
2327
|
-
code += `${param.name}?: `;
|
|
2328
|
-
code += yield* param.typeAnnotation.toEmbeddedTS(shiftState(state, code));
|
|
2329
|
-
code += ', ';
|
|
2330
|
-
});
|
|
2331
|
-
// 锚点
|
|
2332
|
-
code += `_anchor?: nasl.core.String`;
|
|
2333
|
-
code += '}){}\n';
|
|
2334
|
-
}
|
|
2335
|
-
code += `${indent(state?.tabSize || 0)}}\n`;
|
|
2336
|
-
|
|
2337
|
-
// elements类型声明定义
|
|
2338
|
-
code += `interface __elements {\n`;
|
|
2339
|
-
// 生成所有的name和类型定义
|
|
2340
|
-
yield* wrapForEach(self.elements, function* warpForEachGenerator(element) {
|
|
2341
|
-
code += yield* element.toEmbeddedTSDefinition(
|
|
2342
|
-
shiftState(state, code, {
|
|
2343
|
-
tabSize: (state?.tabSize || 0) + 1,
|
|
2344
|
-
}),
|
|
2345
|
-
);
|
|
2346
|
-
});
|
|
2347
|
-
code += `${indent((state?.tabSize || 0) + 1)}}\n`;
|
|
2348
|
-
code += `let __elements: __elements;\n`;
|
|
2349
|
-
|
|
2350
|
-
if (Array.isArray(self.elements)) {
|
|
2351
|
-
code += `${indent((state?.tabSize || 0) + 1)}interface `;
|
|
2352
|
-
code += `__elements_completionProperty {\n`;
|
|
2353
|
-
const componentList: Array<ViewElement> = [];
|
|
2354
|
-
self.elementsAttrs(self.elements, componentList);
|
|
2355
|
-
const variableList: string[] = [];
|
|
2356
|
-
yield* wrapForEach(self.elements, function* warpForEachGenerator(item) {
|
|
2357
|
-
code += yield* item.toEmbeddedTSVariableDefinition(shiftState(state, code, { inline: true }), variableList);
|
|
2358
|
-
});
|
|
2359
|
-
code += indent((state?.tabSize || 0) + 1) + `}\n`;
|
|
2360
|
-
code += indent((state?.tabSize || 0) + 1);
|
|
2361
|
-
code += `let __elements_completionProperty: __elements_completionProperty;\n`;
|
|
2362
|
-
code += indent((state?.tabSize || 0) + 1);
|
|
2363
|
-
code += `let __elements_variable_function = {\n`;
|
|
2364
|
-
yield* wrapForEach(self.elements, function* warpForEachGenerator(item) {
|
|
2365
|
-
code += yield* item.toEmbeddedTSVariableFunctionDefinition(shiftState(state, code, { inline: true }));
|
|
2366
|
-
});
|
|
2367
|
-
code += indent((state?.tabSize || 0) + 1) + `}\n`;
|
|
2368
|
-
code += indent((state?.tabSize || 0) + 1);
|
|
2369
|
-
code += `let __elements_stashFunctionVariable = {\n`;
|
|
2370
|
-
yield* wrapForEach(variableList, function* warpForEachGenerator(item) {
|
|
2371
|
-
code += indent((state?.tabSize || 0) + 2);
|
|
2372
|
-
code += `${item}`;
|
|
2373
|
-
});
|
|
2374
|
-
code += indent((state?.tabSize || 0) + 1) + `}\n`;
|
|
2375
|
-
}
|
|
2376
|
-
|
|
2377
|
-
const advanceMap: Map<Variable, Assignment | BatchAssignment> = new Map();
|
|
2378
|
-
yield* self.traverseChildrenGenerator(function* traverseChildrenGenerator(el) {
|
|
2379
|
-
if (el && (asserts.isBatchAssignment(el) || (asserts.isAssignment(el) && el.left?.name))) {
|
|
2380
|
-
if (asserts.isAssignment(el)) {
|
|
2381
|
-
const advanceVar = self.variables?.find(
|
|
2382
|
-
(variable) => !variable.typeAnnotation && el.left?.name === variable.name,
|
|
2383
|
-
);
|
|
2384
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
2385
|
-
advanceMap.set(advanceVar, el);
|
|
2386
|
-
}
|
|
2387
|
-
} else if (asserts.isBatchAssignment(el)) {
|
|
2388
|
-
yield* wrapForEach(el.assignmentLines, function* warpForEachGenerator({ leftIndex }) {
|
|
2389
|
-
const leftCode =
|
|
2390
|
-
leftIndex.length === 1
|
|
2391
|
-
? yield* el.left?.expression?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
2392
|
-
returnOrigin('')
|
|
2393
|
-
: yield* el.left?.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
2394
|
-
returnOrigin('');
|
|
2395
|
-
const advanceVar = self.variables?.find(
|
|
2396
|
-
(variable) => !variable.typeAnnotation && leftCode === variable.name,
|
|
2397
|
-
);
|
|
2398
|
-
if (advanceVar && !advanceMap.get(advanceVar)) {
|
|
2399
|
-
advanceMap.set(advanceVar, el);
|
|
2400
|
-
}
|
|
2401
|
-
});
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
});
|
|
2405
|
-
|
|
2406
|
-
// 用来储存默认值翻译结构是__IDENTIFIER__或者__IDENTIFIER__()的节点
|
|
2407
|
-
const IDENTIFIERMAP = new Set<Variable>();
|
|
2408
|
-
if (Array.isArray(self.params)) {
|
|
2409
|
-
yield* wrapForEach(self.params, function* warpForEachGenerator(param) {
|
|
2410
|
-
code += `let ${indent((state?.tabSize || 0) + 1)}`;
|
|
2411
|
-
code += yield* param.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
2412
|
-
code += ';\n';
|
|
2413
|
-
});
|
|
2414
|
-
}
|
|
2415
|
-
if (Array.isArray(self.variables)) {
|
|
2416
|
-
yield* wrapForEach(self.variables, function* warpForEachGenerator(variable) {
|
|
2417
|
-
const ts = yield* variable.defaultValue?.toEmbeddedTS?.() ?? returnOrigin('');
|
|
2418
|
-
if (['__IDENTIFIER__', '__IDENTIFIER__()'].includes(ts)) {
|
|
2419
|
-
IDENTIFIERMAP.add(variable);
|
|
2420
|
-
}
|
|
2421
|
-
if (!advanceMap.get(variable)) {
|
|
2422
|
-
code += `let ${indent((state?.tabSize || 0) + 1)}`;
|
|
2423
|
-
code += yield* variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
2424
|
-
code += ';\n';
|
|
2425
|
-
}
|
|
2426
|
-
});
|
|
2427
|
-
}
|
|
2428
|
-
yield* wrapIterator(advanceMap.entries(), function* warpForEachGenerator([variable, assignment]) {
|
|
2429
|
-
// 有默认值的用默认值来推导类型, 但是如果是__IDENTIFIER__或者__IDENTIFIER__(),就不需要默认值来推导了
|
|
2430
|
-
if (variable.defaultValue?.expression && !IDENTIFIERMAP.has(variable)) {
|
|
2431
|
-
code += `let ${indent((state?.tabSize || 0) + 1)}`;
|
|
2432
|
-
code += yield* variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
2433
|
-
return;
|
|
2434
|
-
}
|
|
2435
|
-
code += `${indent((state?.tabSize || 0) + 1)}// @ts-ignore\n`;
|
|
2436
|
-
code += `let ${indent((state?.tabSize || 0) + 1)}`;
|
|
2437
|
-
code += yield* variable.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
2438
|
-
code += ' = ';
|
|
2439
|
-
if (asserts.isBatchAssignment(assignment)) {
|
|
2440
|
-
yield* wrapForEach(assignment.assignmentLines, function* warpForEachGenerator({ leftIndex, rightIndex }) {
|
|
2441
|
-
const leftCode =
|
|
2442
|
-
leftIndex.length === 1
|
|
2443
|
-
? yield* assignment.left.expression.toEmbeddedTS(shiftState(state, code, { inline: true }))
|
|
2444
|
-
: yield* assignment.left.members[leftIndex[1]]?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
2445
|
-
returnOrigin('');
|
|
2446
|
-
if (leftCode === variable.name) {
|
|
2447
|
-
const rightNode =
|
|
2448
|
-
rightIndex.length === 1
|
|
2449
|
-
? assignment.rights[rightIndex[0]]?.expression
|
|
2450
|
-
: assignment.rights[rightIndex[0]]?.members[rightIndex[1]];
|
|
2451
|
-
const rightCode = yield* rightNode?.toEmbeddedTS(shiftState(state, code, { inline: true })) ??
|
|
2452
|
-
returnOrigin('');
|
|
2453
|
-
code += yield* self.getRightCode(rightCode, assignment, rightNode);
|
|
2454
|
-
}
|
|
2455
|
-
});
|
|
2456
|
-
} else {
|
|
2457
|
-
let rightCode = '';
|
|
2458
|
-
// 因为右侧枚举要赋值就得new 一下;
|
|
2459
|
-
if (
|
|
2460
|
-
assignment.right &&
|
|
2461
|
-
asserts.isIdentifier(assignment.right) &&
|
|
2462
|
-
assignment.right.namespace &&
|
|
2463
|
-
assignment.right.namespace.endsWith('enums')
|
|
2464
|
-
) {
|
|
2465
|
-
rightCode += 'new ';
|
|
2466
|
-
}
|
|
2467
|
-
rightCode +=
|
|
2468
|
-
assignment.right && assignment.right.toEmbeddedTS
|
|
2469
|
-
? yield* assignment.right.toEmbeddedTS(shiftState(state, code, { inline: true }))
|
|
2470
|
-
: '__RIGHT__';
|
|
2471
|
-
code += yield* self.getRightCode(rightCode, assignment, assignment.right);
|
|
2472
|
-
}
|
|
2473
|
-
code += ';\n';
|
|
2474
|
-
});
|
|
2475
|
-
|
|
2476
|
-
/* 默认值草稿区 ---------------------------*/
|
|
2477
|
-
code += `${indent((state?.tabSize || 0) + 1)}function __playground(){\n`;
|
|
2478
|
-
|
|
2479
|
-
/* 参数的默认值是__IDENTIFIER__或者__IDENTIFIER__()时不赋默认值,但是需要ts翻译出来进行报错校验 */
|
|
2480
|
-
for (const node of IDENTIFIERMAP.values()) {
|
|
2481
|
-
code += `${indent((state?.tabSize || 0) + 2)}`;
|
|
2482
|
-
code += yield* node.defaultValue.toEmbeddedTS(shiftState(state, code, { inline: true }));
|
|
2483
|
-
code += '; ';
|
|
2484
|
-
}
|
|
2485
|
-
|
|
2486
|
-
code += '\n';
|
|
2487
|
-
code += `${indent((state?.tabSize || 0) + 2)}return\n`;
|
|
2488
|
-
|
|
2489
|
-
function* setPlaygroundCode(arr: Variable[] | ParamWithGroup[], name: string) {
|
|
2490
|
-
if (arr.length) {
|
|
2491
|
-
code += `${indent((state?.tabSize || 0) + 1)}/* -----以下是 ${name} 的默认值草稿------ */\n`;
|
|
2492
|
-
}
|
|
2493
|
-
|
|
2494
|
-
for (const item1 of arr) {
|
|
2495
|
-
for (const item of item1.defaultValue?.playground ?? []) {
|
|
2496
|
-
code += yield* item.toEmbeddedTS(shiftState(state, code, { tabSize: (state?.tabSize || 0) + 1 }));
|
|
2497
|
-
code += ';\n';
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
}
|
|
2501
|
-
yield* setPlaygroundCode(self.variables, 'variables');
|
|
2502
|
-
yield* setPlaygroundCode(self.params, 'params');
|
|
2503
|
-
|
|
2504
|
-
code += `${indent((state?.tabSize || 0) + 1)}}\n`;
|
|
2505
|
-
return code;
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
/**
|
|
2509
|
-
* 转换成 VueOptions
|
|
2510
|
-
* @TODO 后面 template 可以优化成 render 函数
|
|
2511
|
-
*/
|
|
2512
|
-
toVueOptions(options?: ElementToVueOptions) {
|
|
2513
|
-
return {
|
|
2514
|
-
template: this.genVueTemplate(options),
|
|
2515
|
-
script: this.genScript(),
|
|
2516
|
-
};
|
|
2517
|
-
}
|
|
2518
|
-
|
|
2519
|
-
genVueTemplate(options?: ElementToVueOptions) {
|
|
2520
|
-
return this.elements?.map((element) => `${element?.toVue(options)}\n`).join('');
|
|
2521
|
-
}
|
|
2522
|
-
|
|
2523
|
-
getViewBindEvents() {
|
|
2524
|
-
const bindEvents: Array<BindEvent> = [];
|
|
2525
|
-
// 页面上的绑定的事件
|
|
2526
|
-
this.bindEvents.forEach((bindEvent) => {
|
|
2527
|
-
bindEvents.push(bindEvent);
|
|
2528
|
-
});
|
|
2529
|
-
this.elements.forEach((item) => {
|
|
2530
|
-
utils.traverse(
|
|
2531
|
-
(current) => {
|
|
2532
|
-
current.node.bindEvents.forEach((bindEvent) => {
|
|
2533
|
-
bindEvents.push(bindEvent);
|
|
2534
|
-
});
|
|
2535
|
-
},
|
|
2536
|
-
{ node: item },
|
|
2537
|
-
);
|
|
2538
|
-
});
|
|
2539
|
-
return bindEvents;
|
|
2540
|
-
}
|
|
2541
|
-
|
|
2542
|
-
// 获取页面上需要替换的表达式
|
|
2543
|
-
getViewExpressions() {
|
|
2544
|
-
const bindExpressions: any[] = [];
|
|
2545
|
-
this.elements.forEach((item) => {
|
|
2546
|
-
utils.traverse(
|
|
2547
|
-
(current) => {
|
|
2548
|
-
const { node } = current as any;
|
|
2549
|
-
const playgroundNodePath = (node?.nodePath || '').split('.').find((nodePathNode: string) => {
|
|
2550
|
-
return nodePathNode.match(/(.+)\[.+\]/)?.[1] === 'playground';
|
|
2551
|
-
});
|
|
2552
|
-
if (!playgroundNodePath) {
|
|
2553
|
-
//// 处理三种情况
|
|
2554
|
-
//if (
|
|
2555
|
-
// ['BindAttribute', 'BindDirective', 'BindStyle'].includes(node.concept)
|
|
2556
|
-
// && node.needReplaceWithIdentifier
|
|
2557
|
-
//) {
|
|
2558
|
-
// bindExpressions.push(node);
|
|
2559
|
-
//}
|
|
2560
|
-
if (node?.concept === 'Match') {
|
|
2561
|
-
bindExpressions.push(node as Match);
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2564
|
-
},
|
|
2565
|
-
{
|
|
2566
|
-
node: item,
|
|
2567
|
-
},
|
|
2568
|
-
{
|
|
2569
|
-
mode: 'anyObject',
|
|
2570
|
-
depthFirst: true,
|
|
2571
|
-
excludedKeySet: new Set([
|
|
2572
|
-
'bindEvents',
|
|
2573
|
-
'parentNode',
|
|
2574
|
-
'sourceMap',
|
|
2575
|
-
'storageJSON',
|
|
2576
|
-
'tsErrorDetail',
|
|
2577
|
-
'NaslAnnotatedJSON',
|
|
2578
|
-
'calledFrom',
|
|
2579
|
-
'_events',
|
|
2580
|
-
'_collectingList',
|
|
2581
|
-
'_historyList',
|
|
2582
|
-
]),
|
|
2583
|
-
},
|
|
2584
|
-
);
|
|
2585
|
-
});
|
|
2586
|
-
return bindExpressions;
|
|
2587
|
-
}
|
|
2588
|
-
|
|
2589
|
-
/**
|
|
2590
|
-
* 生成 Vue 中需要的 JS 代码
|
|
2591
|
-
* @TODO 这一版先做成 componentOptions 式的,后面再美化
|
|
2592
|
-
*/
|
|
2593
|
-
genScript() {
|
|
2594
|
-
const componentList: Array<ViewElement> = [];
|
|
2595
|
-
const componentListExtra: Array<ViewElement> = [];
|
|
2596
|
-
this.elementsAttrs(this.elements, componentList);
|
|
2597
|
-
this.elementsAttrsAll(this.elements, componentListExtra);
|
|
2598
|
-
const definition = {
|
|
2599
|
-
params: this.params,
|
|
2600
|
-
variables: this.variables,
|
|
2601
|
-
logics: this.logics,
|
|
2602
|
-
events: this.bindEvents,
|
|
2603
|
-
title: this.title,
|
|
2604
|
-
viewBindEvents: this.getViewBindEvents(),
|
|
2605
|
-
viewExpressions: this.getViewExpressions(),
|
|
2606
|
-
elements: componentList,
|
|
2607
|
-
elementsAll: componentListExtra,
|
|
2608
|
-
};
|
|
2609
|
-
let code = '';
|
|
2610
|
-
const keyboardEventMixinCode = `const keyboardEventMixin = {
|
|
2611
|
-
mounted() {
|
|
2612
|
-
document.addEventListener('keydown', this.onKeyDown);
|
|
2613
|
-
document.addEventListener('keyup', this.onKeyUp);
|
|
2614
|
-
},
|
|
2615
|
-
beforeDestory() {
|
|
2616
|
-
document.removeEventListener('keydown', this.onKeyDown);
|
|
2617
|
-
document.removeEventListener('keyup', this.onKeyUp);
|
|
2618
|
-
},
|
|
2619
|
-
methods: {
|
|
2620
|
-
async onKeyDown(e) {
|
|
2621
|
-
${this.bindEvents
|
|
2622
|
-
.filter((event) => ['keydown'].includes(event.name))
|
|
2623
|
-
.map((event) => `await this.${event.view.name}_${event.name}(e);`)
|
|
2624
|
-
.join('\n')}
|
|
2625
|
-
},
|
|
2626
|
-
async onKeyUp(e) {
|
|
2627
|
-
${this.bindEvents
|
|
2628
|
-
.filter((event) => ['keyup'].includes(event.name))
|
|
2629
|
-
.map((event) => `await this.${event.view.name}_${event.name}(e);`)
|
|
2630
|
-
.join('\n')}
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
};\n`;
|
|
2634
|
-
code += keyboardEventMixinCode;
|
|
2635
|
-
code += 'export default {\n';
|
|
2636
|
-
code += 'mixins: [';
|
|
2637
|
-
const mixins = [];
|
|
2638
|
-
// 键盘事件mixin
|
|
2639
|
-
mixins.push('keyboardEventMixin');
|
|
2640
|
-
code += mixins.join(',');
|
|
2641
|
-
code += '],';
|
|
2642
|
-
code += translator(definition, this);
|
|
2643
|
-
code += '};\n';
|
|
2644
|
-
return code;
|
|
2645
|
-
}
|
|
2646
|
-
|
|
2647
|
-
// 生成预览的模板
|
|
2648
|
-
genPreviewTemplate() {
|
|
2649
|
-
return `<template>
|
|
2650
|
-
<bs-${this.name}>
|
|
2651
|
-
${this.slotElems.map((slotElem) => {
|
|
2652
|
-
const slotName = slotElem.name;
|
|
2653
|
-
return `<template #${slotName}></template>`;
|
|
2654
|
-
}).join('')}
|
|
2655
|
-
</bs-${this.name}>
|
|
2656
|
-
</template>`;
|
|
2657
|
-
}
|
|
2658
|
-
|
|
2659
|
-
//================================================================================
|
|
2660
|
-
// 从这里开始到结尾注释之间的代码由 NASL Workbench 自动生成,请不手动修改!
|
|
2661
|
-
// ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
|
2662
|
-
//================================================================================
|
|
2663
|
-
}
|
|
2664
|
-
|
|
2665
|
-
export default BusinessComponent;
|
|
2666
|
-
//================================================================================
|
|
2667
|
-
// ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
|
|
2668
|
-
// 自动生成的代码已结束。下面可以手动编写。
|
|
2669
|
-
//================================================================================
|