@kp-ui/lowcode-pc-v2 0.0.1 → 0.0.2
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/core/src/components/common/render/LowcodeRenderProvider.vue_vue_type_script_setup_true_lang.js +3 -5
- package/core/src/components/common/render/RenderWidgetList.vue_vue_type_script_setup_true_lang.js +3 -5
- package/core/src/components/common/render/usePageContext.js +25 -30
- package/core/src/hooks/useAppRef.js +5 -4
- package/core/src/hooks/useFactoryRender.js +4 -2
- package/core/src/hooks/useField.js +497 -424
- package/core/src/hooks/useLowcode.js +64 -89
- package/core/src/hooks/useRemoteData.js +35 -41
- package/core/src/hooks/useSelect.js +4 -2
- package/core/src/utils/i18n.js +1 -15
- package/core/src/utils/smart-vue-i18n/index.js +38 -39
- package/package.json +36 -36
- package/src/components/public/ActionButtonListRender.vue_vue_type_script_lang.js +26 -32
- package/src/components/public/ConfigView/CustomPageRender.vue_vue_type_script_setup_true_lang.js +7 -7
- package/src/components/public/CustomerModal/CustomerModal.vue_vue_type_script_setup_true_lang.js +13 -24
- package/src/components/public/CustomerModal/useCustomerModal.js +6 -7
- package/src/components/public/DataTableColumnDialog.vue_vue_type_script_setup_true_name_DataTableColumnDialog_lang.js +36 -38
- package/src/hooks/useTableWidget.js +39 -44
- package/src/render/index.vue_vue_type_script_setup_true_lang.js +9 -6
- package/src/widgets/advanced/code-editor/index.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/advanced/code-editor/schema.js +8 -8
- package/src/widgets/advanced/custom-render/index.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/advanced/custom-render/schema.js +7 -5
- package/src/widgets/advanced/data-table/index.vue_vue_type_script_setup_true_lang.js +7 -7
- package/src/widgets/advanced/data-table/schema.js +3 -3
- package/src/widgets/advanced/file-upload/index.vue_vue_type_script_setup_true_lang.js +35 -37
- package/src/widgets/advanced/file-upload/schema.js +11 -8
- package/src/widgets/advanced/rich-editor/index.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/advanced/rich-editor/schema.js +10 -9
- package/src/widgets/advanced/tree/index.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/advanced/tree/schema.js +11 -8
- package/src/widgets/advanced/tree-select/index.vue_vue_type_script_setup_true_lang.js +6 -7
- package/src/widgets/advanced/tree-select/schema.js +11 -10
- package/src/widgets/base/button/index.vue_vue_type_script_setup_true_lang.js +7 -6
- package/src/widgets/base/button/schema.js +0 -1
- package/src/widgets/base/button-list/index.vue_vue_type_script_setup_true_lang.js +3 -5
- package/src/widgets/base/button-list/schema.js +0 -1
- package/src/widgets/base/cascader/index.vue_vue_type_script_setup_true_lang.js +8 -8
- package/src/widgets/base/cascader/schema.js +9 -9
- package/src/widgets/base/checkbox/index.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/base/checkbox/schema.js +9 -9
- package/src/widgets/base/color/index.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/base/color/schema.js +7 -7
- package/src/widgets/base/date/index.vue_vue_type_script_setup_true_lang.js +5 -7
- package/src/widgets/base/date/schema.js +8 -8
- package/src/widgets/base/date-range/index.vue_vue_type_script_setup_true_lang.js +5 -7
- package/src/widgets/base/date-range/schema.js +8 -8
- package/src/widgets/base/divider/index.vue_vue_type_script_setup_true_lang.js +3 -5
- package/src/widgets/base/divider/schema.js +0 -1
- package/src/widgets/base/html/index.vue_vue_type_script_setup_true_lang.js +3 -5
- package/src/widgets/base/html/schema.js +6 -6
- package/src/widgets/base/input/index.vue_vue_type_script_setup_true_lang.js +12 -18
- package/src/widgets/base/input/schema.js +11 -8
- package/src/widgets/base/number/index.vue_vue_type_script_setup_true_lang.js +8 -7
- package/src/widgets/base/number/schema.js +8 -8
- package/src/widgets/base/radio/index.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/base/radio/schema.js +9 -9
- package/src/widgets/base/rate/index.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/base/rate/schema.js +8 -8
- package/src/widgets/base/select/index.vue_vue_type_script_setup_true_lang.js +17 -20
- package/src/widgets/base/select/schema.js +12 -9
- package/src/widgets/base/slider/index.vue_vue_type_script_setup_true_lang.js +5 -7
- package/src/widgets/base/slider/schema.js +7 -7
- package/src/widgets/base/static-text/index.vue_vue_type_script_setup_true_lang.js +3 -5
- package/src/widgets/base/static-text/schema.js +0 -1
- package/src/widgets/base/switch/index.vue_vue_type_script_setup_true_lang.js +5 -7
- package/src/widgets/base/switch/schema.js +7 -7
- package/src/widgets/base/textarea/index.vue_vue_type_script_setup_true_lang.js +8 -7
- package/src/widgets/base/textarea/schema.js +8 -8
- package/src/widgets/base/time/index.vue_vue_type_script_setup_true_lang.js +7 -8
- package/src/widgets/base/time/schema.js +8 -8
- package/src/widgets/base/time-range/index.vue_vue_type_script_setup_true_lang.js +8 -7
- package/src/widgets/base/time-range/schema.js +8 -8
- package/src/widgets/containers/box/index-render.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/containers/box/schema.js +0 -1
- package/src/widgets/containers/collapse/index-render.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/containers/collapse/schema.js +0 -1
- package/src/widgets/containers/dialog/index-render.vue_vue_type_script_setup_true_lang.js +19 -35
- package/src/widgets/containers/dialog/schema.js +0 -1
- package/src/widgets/containers/form/index-render.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/containers/form/schema.js +6 -6
- package/src/widgets/containers/grid/index-render.vue_vue_type_script_setup_true_lang.js +3 -5
- package/src/widgets/containers/grid/schema.js +0 -1
- package/src/widgets/containers/grid-col/index-render.vue_vue_type_script_setup_true_lang.js +3 -5
- package/src/widgets/containers/grid-col/schema.js +0 -1
- package/src/widgets/containers/list/index-render.vue_vue_type_script_setup_true_lang.js +36 -53
- package/src/widgets/containers/list/schema.js +3 -3
- package/src/widgets/containers/space/index-render.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/containers/tab/index-render.vue_vue_type_script_setup_true_lang.js +11 -19
- package/src/widgets/containers/tab/schema.js +0 -1
- package/src/widgets/containers/tab-pane/index-render.vue_vue_type_script_setup_true_lang.js +3 -5
- package/src/widgets/containers/tab-pane/schema.js +0 -1
- package/src/widgets/template/SecondaryPage/index-render.vue_vue_type_script_setup_true_lang.js +4 -6
- package/src/widgets/template/SecondaryPage/schema.js +0 -1
- package/src/widgets/wrapper/form-item-wrapper.vue_vue_type_script_setup_true_lang.js +3 -3
- package/stats.html +1 -1
|
@@ -1,430 +1,503 @@
|
|
|
1
|
-
import { EVENT_TYPE, useEmitter } from
|
|
2
|
-
import { useI18n } from
|
|
3
|
-
import { deepClone } from
|
|
4
|
-
import { getEventParams } from
|
|
5
|
-
import { useAppRef } from
|
|
6
|
-
import { useFieldRules } from
|
|
7
|
-
import { computed, inject, onBeforeUnmount, onMounted, ref, toRaw, watch } from
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import { eq, get, isArray } from "lodash-es";
|
|
11
|
-
import _asyncToGenerator from "@oxc-project/runtime/helpers/asyncToGenerator";
|
|
1
|
+
import { EVENT_TYPE, useEmitter } from '../utils/useEmitter.js';
|
|
2
|
+
import { useI18n } from '../utils/i18n.js';
|
|
3
|
+
import { deepClone } from '../utils/util.js';
|
|
4
|
+
import { getEventParams } from '../components/property-editor/propertyRegister.js';
|
|
5
|
+
import { useAppRef } from './useAppRef.js';
|
|
6
|
+
import { useFieldRules } from './useFieldRules.js';
|
|
7
|
+
import { computed, inject, onBeforeUnmount, onMounted, ref, toRaw, watch } from 'vue';
|
|
8
|
+
import { useExecFunction } from 'tmgc2-share';
|
|
9
|
+
import { eq, get, isArray } from 'lodash-es';
|
|
12
10
|
//#region ../core/src/hooks/useField.ts
|
|
13
11
|
/**
|
|
14
|
-
* 表单字段 Hook,提供表单字段的通用功能
|
|
15
|
-
*/
|
|
12
|
+
* 表单字段 Hook,提供表单字段的通用功能
|
|
13
|
+
*/
|
|
16
14
|
function useField(widget) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
15
|
+
const formConfig = inject('formConfig', ref({}));
|
|
16
|
+
const formModel = inject('formData', ref({}));
|
|
17
|
+
const getReadMode = inject('getReadMode', () => false);
|
|
18
|
+
const isSubFormField = inject('isSubFormField', false);
|
|
19
|
+
const subFormRowIndex = inject('subFormRowIndex', ref(0));
|
|
20
|
+
const getSubFormName = inject('getSubFormName', () => '');
|
|
21
|
+
const designState = inject('designState', false);
|
|
22
|
+
const { registerToRefList, getInstance, getPageInstance, unregisterFromRefList } = useAppRef();
|
|
23
|
+
const { context, executeFunction, asyncExecuteFunction } = useExecFunction();
|
|
24
|
+
const { i18nt, i18n2t } = useI18n();
|
|
25
|
+
const { emitter } = useEmitter();
|
|
26
|
+
const fieldEditor = ref(null);
|
|
27
|
+
const oldFieldValue = ref(null);
|
|
28
|
+
const fieldReadonlyFlag = ref(false);
|
|
29
|
+
const loading = ref(false);
|
|
30
|
+
/** 获取属性名称 */
|
|
31
|
+
const getPropName = computed(() => {
|
|
32
|
+
var _widget$props2;
|
|
33
|
+
if (isSubFormField && !designState) {
|
|
34
|
+
var _widget$props;
|
|
35
|
+
return `${getSubFormName()}.${subFormRowIndex.value}.${
|
|
36
|
+
((_widget$props = widget.props) === null || _widget$props === void 0
|
|
37
|
+
? void 0
|
|
38
|
+
: _widget$props.name) || ''
|
|
39
|
+
}`;
|
|
40
|
+
}
|
|
41
|
+
return (
|
|
42
|
+
((_widget$props2 = widget.props) === null || _widget$props2 === void 0
|
|
43
|
+
? void 0
|
|
44
|
+
: _widget$props2.name) || ''
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
/** 标签文本 */
|
|
48
|
+
const label = computed(() => {
|
|
49
|
+
var _widget$props$label, _widget$props3;
|
|
50
|
+
return (_widget$props$label =
|
|
51
|
+
(_widget$props3 = widget.props) === null || _widget$props3 === void 0
|
|
52
|
+
? void 0
|
|
53
|
+
: _widget$props3.label) !== null && _widget$props$label !== void 0
|
|
54
|
+
? _widget$props$label
|
|
55
|
+
: '';
|
|
56
|
+
});
|
|
57
|
+
/** 字段值 */
|
|
58
|
+
const fieldModel = computed({
|
|
59
|
+
get() {
|
|
60
|
+
return get(
|
|
61
|
+
(formModel === null || formModel === void 0 ? void 0 : formModel.value) || {},
|
|
62
|
+
getPropName.value
|
|
63
|
+
);
|
|
64
|
+
},
|
|
65
|
+
set(value) {
|
|
66
|
+
syncUpdateFormModel(value);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const { rules, buildFieldRules, clearFieldRules, clearValidate } = useFieldRules({
|
|
70
|
+
widget,
|
|
71
|
+
getPropName,
|
|
72
|
+
getPageInstance,
|
|
73
|
+
designState
|
|
74
|
+
});
|
|
75
|
+
/** 子表单名称 */
|
|
76
|
+
const subFormName = computed(() => (getSubFormName ? getSubFormName() : ''));
|
|
77
|
+
/** 子表单数据 */
|
|
78
|
+
const subFormData = computed(() => formModel.value[subFormName.value]);
|
|
79
|
+
const isFieldWidget = computed(() => widget.category === 'field');
|
|
80
|
+
/** 组件尺寸 */
|
|
81
|
+
const size = computed(() => {
|
|
82
|
+
var _widget$props4;
|
|
83
|
+
return (
|
|
84
|
+
((_widget$props4 = widget.props) === null || _widget$props4 === void 0
|
|
85
|
+
? void 0
|
|
86
|
+
: _widget$props4.size) ||
|
|
87
|
+
formConfig.value.size ||
|
|
88
|
+
'middle'
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
/** 是否只读模式 */
|
|
92
|
+
const isReadMode = computed(() => {
|
|
93
|
+
return getReadMode() || fieldReadonlyFlag.value;
|
|
94
|
+
});
|
|
95
|
+
/** 自定义类名 */
|
|
96
|
+
const customClass = computed(() => {
|
|
97
|
+
var _widget$props5;
|
|
98
|
+
return (
|
|
99
|
+
((_widget$props5 = widget.props) === null || _widget$props5 === void 0
|
|
100
|
+
? void 0
|
|
101
|
+
: _widget$props5.customClass) || []
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
const dataSource = computed(() => {
|
|
105
|
+
return widget.dataSource;
|
|
106
|
+
});
|
|
107
|
+
/** 处理字段隐藏逻辑 */
|
|
108
|
+
const handleHidden = computed(() => {
|
|
109
|
+
var _widget$props$hidden, _widget$props6, _widget$events;
|
|
110
|
+
if (designState) return false;
|
|
111
|
+
const hidden =
|
|
112
|
+
(_widget$props$hidden =
|
|
113
|
+
(_widget$props6 = widget.props) === null || _widget$props6 === void 0
|
|
114
|
+
? void 0
|
|
115
|
+
: _widget$props6.hidden) !== null && _widget$props$hidden !== void 0
|
|
116
|
+
? _widget$props$hidden
|
|
117
|
+
: false;
|
|
118
|
+
const onHidden =
|
|
119
|
+
(_widget$events = widget.events) === null || _widget$events === void 0
|
|
120
|
+
? void 0
|
|
121
|
+
: _widget$events.onHidden;
|
|
122
|
+
if (hidden) return true;
|
|
123
|
+
if (onHidden)
|
|
124
|
+
try {
|
|
125
|
+
const result = executeFunction({ functionBody: onHidden });
|
|
126
|
+
return typeof result === 'boolean' ? result : false;
|
|
127
|
+
} catch (_unused) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
});
|
|
132
|
+
/** 处理字段禁用逻辑 */
|
|
133
|
+
const handleDisabled = computed(() => {
|
|
134
|
+
var _widget$events2;
|
|
135
|
+
const { disabled } = widget.props || {};
|
|
136
|
+
const onDisabled =
|
|
137
|
+
(_widget$events2 = widget.events) === null || _widget$events2 === void 0
|
|
138
|
+
? void 0
|
|
139
|
+
: _widget$events2.onDisabled;
|
|
140
|
+
if (disabled) return true;
|
|
141
|
+
if (designState) return;
|
|
142
|
+
if (onDisabled)
|
|
143
|
+
try {
|
|
144
|
+
const result = executeFunction({ functionBody: onDisabled });
|
|
145
|
+
return typeof result === 'boolean' ? result : false;
|
|
146
|
+
} catch (_unused2) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
});
|
|
151
|
+
/** 执行组件事件函数 */
|
|
152
|
+
const executeWidgetEvent = async (eventName, params = {}) => {
|
|
153
|
+
var _widget$events3;
|
|
154
|
+
if (designState) return;
|
|
155
|
+
const eventParams = getEventParams(eventName, widget.type);
|
|
156
|
+
const eventCode =
|
|
157
|
+
(_widget$events3 = widget.events) === null || _widget$events3 === void 0
|
|
158
|
+
? void 0
|
|
159
|
+
: _widget$events3[eventName];
|
|
160
|
+
if (eventCode)
|
|
161
|
+
await asyncExecuteFunction({
|
|
162
|
+
functionBody: eventCode,
|
|
163
|
+
params,
|
|
164
|
+
keys: eventParams
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
/** 处理挂载事件 */
|
|
168
|
+
const handleOnMounted = async () => {
|
|
169
|
+
if (designState) return;
|
|
170
|
+
await executeWidgetEvent('onMounted');
|
|
171
|
+
};
|
|
172
|
+
/** 处理变更事件 */
|
|
173
|
+
const handleOnChange = (val, oldVal, item = {}) => {
|
|
174
|
+
var _widget$events4;
|
|
175
|
+
if (designState) return;
|
|
176
|
+
executeFunction({
|
|
177
|
+
functionBody:
|
|
178
|
+
((_widget$events4 = widget.events) === null || _widget$events4 === void 0
|
|
179
|
+
? void 0
|
|
180
|
+
: _widget$events4.onChange) || '',
|
|
181
|
+
params: {
|
|
182
|
+
value: val,
|
|
183
|
+
oldValue: oldVal,
|
|
184
|
+
subFormData: subFormData.value,
|
|
185
|
+
rowId: subFormRowIndex.value,
|
|
186
|
+
item
|
|
187
|
+
},
|
|
188
|
+
keys: ['value', 'oldValue', 'subFormData', 'rowId', 'item']
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
/** 处理焦点事件 */
|
|
192
|
+
const handleFocusCustomEvent = event => {
|
|
193
|
+
var _widget$events5;
|
|
194
|
+
if (designState) return;
|
|
195
|
+
executeFunction({
|
|
196
|
+
functionBody:
|
|
197
|
+
((_widget$events5 = widget.events) === null || _widget$events5 === void 0
|
|
198
|
+
? void 0
|
|
199
|
+
: _widget$events5.onFocus) || '',
|
|
200
|
+
params: { event },
|
|
201
|
+
keys: ['event']
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
/** 处理失焦事件 */
|
|
205
|
+
const handleBlurCustomEvent = event => {
|
|
206
|
+
var _widget$events6;
|
|
207
|
+
if (designState) return;
|
|
208
|
+
executeFunction({
|
|
209
|
+
functionBody:
|
|
210
|
+
((_widget$events6 = widget.events) === null || _widget$events6 === void 0
|
|
211
|
+
? void 0
|
|
212
|
+
: _widget$events6.onBlur) || '',
|
|
213
|
+
params: { event },
|
|
214
|
+
keys: ['event']
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
/** 处理点击事件 */
|
|
218
|
+
const onClick = async () => {
|
|
219
|
+
if (designState || handleDisabled.value) return;
|
|
220
|
+
await executeWidgetEvent('onClick');
|
|
221
|
+
};
|
|
222
|
+
/** 发送字段数据变更事件 */
|
|
223
|
+
const emitFieldDataChange = (newValue, oldValue) => {
|
|
224
|
+
if (newValue === null || newValue === void 0 ? void 0 : newValue.target)
|
|
225
|
+
newValue = newValue.target.value;
|
|
226
|
+
if (!context.value) return;
|
|
227
|
+
emitter.emit(EVENT_TYPE.ON_FIELD_DATA_CHANGE, {
|
|
228
|
+
fieldName: widget.props.name,
|
|
229
|
+
value: newValue,
|
|
230
|
+
oldValue,
|
|
231
|
+
field: widget,
|
|
232
|
+
subFormName: subFormName.value,
|
|
233
|
+
subFormRowIndex: subFormRowIndex.value
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
/** 同步更新表单模型 */
|
|
237
|
+
const syncUpdateFormModel = value => {
|
|
238
|
+
if (designState) {
|
|
239
|
+
emitFieldDataChange(value, fieldModel.value);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
emitter.emit(EVENT_TYPE.ON_FIELD_VALIDATION, [getPropName.value]);
|
|
243
|
+
const oldValue = toRaw(fieldModel.value);
|
|
244
|
+
emitFieldDataChange(value, oldValue);
|
|
245
|
+
handleOnChange(value, oldValue);
|
|
246
|
+
};
|
|
247
|
+
/** 设置值 */
|
|
248
|
+
const setValue = (newValue, disableChangeEvent = false) => {
|
|
249
|
+
if (newValue === null || newValue === void 0 ? void 0 : newValue.target)
|
|
250
|
+
newValue = newValue.target.value;
|
|
251
|
+
if (eq(fieldModel.value, newValue)) return;
|
|
252
|
+
const oldValue = deepClone(fieldModel.value);
|
|
253
|
+
if (widget.type === 'file-upload') newValue = showFileList(newValue || []);
|
|
254
|
+
else if (widget.type === 'code-editor') {
|
|
255
|
+
var _getFieldEditor;
|
|
256
|
+
(_getFieldEditor = getFieldEditor()) === null ||
|
|
257
|
+
_getFieldEditor === void 0 ||
|
|
258
|
+
_getFieldEditor.setValue(newValue);
|
|
259
|
+
}
|
|
260
|
+
fieldModel.value = newValue;
|
|
261
|
+
if (!disableChangeEvent) emitFieldDataChange(newValue, oldValue);
|
|
262
|
+
};
|
|
263
|
+
/** 获取值 */
|
|
264
|
+
const getValue = () => fieldModel.value;
|
|
265
|
+
/** 重置字段 */
|
|
266
|
+
const resetField = () => {
|
|
267
|
+
var _widget$props7;
|
|
268
|
+
setValue(
|
|
269
|
+
(_widget$props7 = widget.props) === null || _widget$props7 === void 0
|
|
270
|
+
? void 0
|
|
271
|
+
: _widget$props7.defaultValue
|
|
272
|
+
);
|
|
273
|
+
};
|
|
274
|
+
/** 刷新默认值 */
|
|
275
|
+
const refreshDefaultValue = () => {
|
|
276
|
+
var _widget$props8;
|
|
277
|
+
fieldModel.value =
|
|
278
|
+
(_widget$props8 = widget.props) === null || _widget$props8 === void 0
|
|
279
|
+
? void 0
|
|
280
|
+
: _widget$props8.defaultValue;
|
|
281
|
+
};
|
|
282
|
+
const setReadonly = flag => {
|
|
283
|
+
if (widget.props) widget.props.readonly = flag;
|
|
284
|
+
};
|
|
285
|
+
/** 设置禁用 */
|
|
286
|
+
const setDisabled = flag => {
|
|
287
|
+
if (widget.props) widget.props.disabled = flag;
|
|
288
|
+
};
|
|
289
|
+
/** 设置隐藏 */
|
|
290
|
+
const setHidden = flag => {
|
|
291
|
+
if (widget.props) widget.props.hidden = flag;
|
|
292
|
+
flag ? clearFieldRules() : buildFieldRules();
|
|
293
|
+
};
|
|
294
|
+
/** 设置必填 */
|
|
295
|
+
const setRequired = flag => {
|
|
296
|
+
if ('validation' in widget && widget.validation) widget.validation.required = flag;
|
|
297
|
+
buildFieldRules();
|
|
298
|
+
if (!designState && !flag) clearValidate();
|
|
299
|
+
};
|
|
300
|
+
/** 设置标签 */
|
|
301
|
+
const setLabel = newLabel => {
|
|
302
|
+
if (widget.props) widget.props.label = newLabel;
|
|
303
|
+
};
|
|
304
|
+
/** 设置只读模式 */
|
|
305
|
+
const setReadMode = (flag = true) => {
|
|
306
|
+
fieldReadonlyFlag.value = flag;
|
|
307
|
+
};
|
|
308
|
+
/** 添加 CSS 类 */
|
|
309
|
+
const addCssClass = className => {
|
|
310
|
+
if (!widget.props) widget.props = {};
|
|
311
|
+
if (!widget.props.customClass) widget.props.customClass = [className];
|
|
312
|
+
else widget.props.customClass.push(className);
|
|
313
|
+
};
|
|
314
|
+
/** 移除 CSS 类 */
|
|
315
|
+
const removeCssClass = className => {
|
|
316
|
+
var _widget$props9;
|
|
317
|
+
if (
|
|
318
|
+
!((_widget$props9 = widget.props) === null || _widget$props9 === void 0
|
|
319
|
+
? void 0
|
|
320
|
+
: _widget$props9.customClass)
|
|
321
|
+
)
|
|
322
|
+
return;
|
|
323
|
+
const idx = widget.props.customClass.indexOf(className);
|
|
324
|
+
if (idx > -1) widget.props.customClass.splice(idx, 1);
|
|
325
|
+
};
|
|
326
|
+
/** 获取字段编辑器 */
|
|
327
|
+
const getFieldEditor = () => fieldEditor.value;
|
|
328
|
+
/** 获取 DOM 元素 */
|
|
329
|
+
const getEl = () => {
|
|
330
|
+
var _fieldEditor$value;
|
|
331
|
+
return (_fieldEditor$value = fieldEditor.value) === null || _fieldEditor$value === void 0
|
|
332
|
+
? void 0
|
|
333
|
+
: _fieldEditor$value.$el;
|
|
334
|
+
};
|
|
335
|
+
/** 获取 VForm 上下文 */
|
|
336
|
+
const getVfCtx = () => {
|
|
337
|
+
var _getPageInstance;
|
|
338
|
+
return (
|
|
339
|
+
((_getPageInstance = getPageInstance()) === null || _getPageInstance === void 0
|
|
340
|
+
? void 0
|
|
341
|
+
: _getPageInstance.vfCtx) || {}
|
|
342
|
+
);
|
|
343
|
+
};
|
|
344
|
+
/** 聚焦 */
|
|
345
|
+
const focus = () => {
|
|
346
|
+
var _fieldEditor$value2, _fieldEditor$value2$f;
|
|
347
|
+
(_fieldEditor$value2 = fieldEditor.value) === null ||
|
|
348
|
+
_fieldEditor$value2 === void 0 ||
|
|
349
|
+
(_fieldEditor$value2$f = _fieldEditor$value2.focus) === null ||
|
|
350
|
+
_fieldEditor$value2$f === void 0 ||
|
|
351
|
+
_fieldEditor$value2$f.call(_fieldEditor$value2);
|
|
352
|
+
};
|
|
353
|
+
/** 显示文件列表 */
|
|
354
|
+
const showFileList = list => {
|
|
355
|
+
if (typeof list === 'string')
|
|
356
|
+
try {
|
|
357
|
+
list = JSON.parse(list);
|
|
358
|
+
} catch (_unused3) {
|
|
359
|
+
return [];
|
|
360
|
+
}
|
|
361
|
+
if (!isArray(list)) return [];
|
|
362
|
+
return list.map((item, uid) => ({
|
|
363
|
+
...item,
|
|
364
|
+
name: item.fileName,
|
|
365
|
+
uid
|
|
366
|
+
}));
|
|
367
|
+
};
|
|
368
|
+
/** 初始化字段模型 */
|
|
369
|
+
const initFieldModel = () => {
|
|
370
|
+
let value;
|
|
371
|
+
if (isSubFormField) value = fieldModel.value;
|
|
372
|
+
else {
|
|
373
|
+
var _widget$props$default, _widget$props10;
|
|
374
|
+
value =
|
|
375
|
+
(_widget$props$default =
|
|
376
|
+
(_widget$props10 = widget.props) === null || _widget$props10 === void 0
|
|
377
|
+
? void 0
|
|
378
|
+
: _widget$props10.defaultValue) !== null && _widget$props$default !== void 0
|
|
379
|
+
? _widget$props$default
|
|
380
|
+
: '';
|
|
381
|
+
}
|
|
382
|
+
emitFieldDataChange(toRaw(value), toRaw(fieldModel.value));
|
|
383
|
+
};
|
|
384
|
+
const getSubFormRowIndex = () => {
|
|
385
|
+
return subFormRowIndex.value;
|
|
386
|
+
};
|
|
387
|
+
watch(
|
|
388
|
+
() => widget.validation,
|
|
389
|
+
() => {
|
|
390
|
+
buildFieldRules();
|
|
391
|
+
},
|
|
392
|
+
{ deep: true }
|
|
393
|
+
);
|
|
394
|
+
watch(
|
|
395
|
+
() => {
|
|
396
|
+
var _widget$props11;
|
|
397
|
+
return (_widget$props11 = widget.props) === null || _widget$props11 === void 0
|
|
398
|
+
? void 0
|
|
399
|
+
: _widget$props11.defaultValue;
|
|
400
|
+
},
|
|
401
|
+
val => {
|
|
402
|
+
syncUpdateFormModel(val);
|
|
403
|
+
}
|
|
404
|
+
);
|
|
405
|
+
onMounted(async () => {
|
|
406
|
+
if (isFieldWidget.value) initFieldModel();
|
|
407
|
+
await registerToRefList();
|
|
408
|
+
await handleOnMounted();
|
|
409
|
+
buildFieldRules();
|
|
410
|
+
});
|
|
411
|
+
onBeforeUnmount(() => {
|
|
412
|
+
unregisterFromRefList();
|
|
413
|
+
});
|
|
414
|
+
return {
|
|
415
|
+
formModel,
|
|
416
|
+
context,
|
|
417
|
+
fieldEditor,
|
|
418
|
+
fieldModel,
|
|
419
|
+
oldFieldValue,
|
|
420
|
+
fieldReadonlyFlag,
|
|
421
|
+
loading,
|
|
422
|
+
rules,
|
|
423
|
+
customClass,
|
|
424
|
+
label,
|
|
425
|
+
size,
|
|
426
|
+
isReadMode,
|
|
427
|
+
handleHidden,
|
|
428
|
+
handleDisabled,
|
|
429
|
+
getPropName,
|
|
430
|
+
formConfig,
|
|
431
|
+
subFormName,
|
|
432
|
+
subFormData,
|
|
433
|
+
field: widget,
|
|
434
|
+
widget,
|
|
435
|
+
dataSource,
|
|
436
|
+
handleOnMounted,
|
|
437
|
+
handleOnChange,
|
|
438
|
+
handleFocusCustomEvent,
|
|
439
|
+
handleBlurCustomEvent,
|
|
440
|
+
onClick,
|
|
441
|
+
executeWidgetEvent,
|
|
442
|
+
executeFunction,
|
|
443
|
+
asyncExecuteFunction,
|
|
444
|
+
setValue,
|
|
445
|
+
getValue,
|
|
446
|
+
resetField,
|
|
447
|
+
refreshDefaultValue,
|
|
448
|
+
emitFieldDataChange,
|
|
449
|
+
syncUpdateFormModel,
|
|
450
|
+
buildFieldRules,
|
|
451
|
+
clearFieldRules,
|
|
452
|
+
clearValidate,
|
|
453
|
+
setReadonly,
|
|
454
|
+
setDisabled,
|
|
455
|
+
setHidden,
|
|
456
|
+
setRequired,
|
|
457
|
+
setLabel,
|
|
458
|
+
setReadMode,
|
|
459
|
+
addCssClass,
|
|
460
|
+
removeCssClass,
|
|
461
|
+
getPageInstance,
|
|
462
|
+
getFieldEditor,
|
|
463
|
+
getEl,
|
|
464
|
+
getVfCtx,
|
|
465
|
+
focus,
|
|
466
|
+
showFileList,
|
|
467
|
+
i18nt,
|
|
468
|
+
i18n2t,
|
|
469
|
+
designState,
|
|
470
|
+
isSubFormField,
|
|
471
|
+
subFormRowIndex,
|
|
472
|
+
defineExposed: {
|
|
473
|
+
widget,
|
|
474
|
+
field: widget,
|
|
475
|
+
fieldModel,
|
|
476
|
+
fieldEditor,
|
|
477
|
+
isReadMode,
|
|
478
|
+
formModel,
|
|
479
|
+
getSubFormRowIndex,
|
|
480
|
+
setValue,
|
|
481
|
+
getValue,
|
|
482
|
+
resetField,
|
|
483
|
+
setReadonly,
|
|
484
|
+
setDisabled,
|
|
485
|
+
setHidden,
|
|
486
|
+
setRequired,
|
|
487
|
+
setLabel,
|
|
488
|
+
setReadMode,
|
|
489
|
+
addCssClass,
|
|
490
|
+
removeCssClass,
|
|
491
|
+
clearValidate,
|
|
492
|
+
focus,
|
|
493
|
+
getEl,
|
|
494
|
+
getFieldEditor,
|
|
495
|
+
getPageInstance,
|
|
496
|
+
getInstance,
|
|
497
|
+
getVfCtx,
|
|
498
|
+
i18nt
|
|
499
|
+
}
|
|
500
|
+
};
|
|
428
501
|
}
|
|
429
502
|
//#endregion
|
|
430
503
|
export { useField };
|