icarys-form-create-vant 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +21 -17787
  3. package/dist/index.min.js +3 -3
  4. package/dist/index.min.js.map +1 -1
  5. package/package.json +5 -2
  6. package/src/components/common/subform/LICENSE +21 -0
  7. package/src/components/common/subform/README.md +6 -0
  8. package/src/components/common/subform/package.json +48 -0
  9. package/src/components/common/subform/src/component.jsx +75 -0
  10. package/src/components/common/subform/src/index.js +3 -0
  11. package/src/components/common/wangeditor/LICENSE +21 -0
  12. package/src/components/common/wangeditor/README.md +14 -0
  13. package/src/components/common/wangeditor/package-lock.json +114 -0
  14. package/src/components/common/wangeditor/package.json +52 -0
  15. package/src/components/common/wangeditor/src/component.jsx +74 -0
  16. package/src/components/common/wangeditor/src/index.js +3 -0
  17. package/src/core/LICENSE +21 -0
  18. package/src/core/README.md +120 -0
  19. package/src/core/babel.config.js +13 -0
  20. package/src/core/bili.config.js +34 -0
  21. package/src/core/package-lock.json +13 -0
  22. package/src/core/package.json +61 -0
  23. package/src/core/src/components/formCreate.js +287 -0
  24. package/src/core/src/components/fragment.js +12 -0
  25. package/src/core/src/factory/context.js +264 -0
  26. package/src/core/src/factory/creator.js +63 -0
  27. package/src/core/src/factory/maker.js +17 -0
  28. package/src/core/src/factory/manager.js +87 -0
  29. package/src/core/src/factory/node.js +89 -0
  30. package/src/core/src/factory/parser.js +28 -0
  31. package/src/core/src/frame/api.js +691 -0
  32. package/src/core/src/frame/attrs.js +12 -0
  33. package/src/core/src/frame/dataDriver.js +76 -0
  34. package/src/core/src/frame/fetch.js +128 -0
  35. package/src/core/src/frame/index.js +792 -0
  36. package/src/core/src/frame/language.js +50 -0
  37. package/src/core/src/frame/provider.js +297 -0
  38. package/src/core/src/frame/util.js +311 -0
  39. package/src/core/src/handler/context.js +573 -0
  40. package/src/core/src/handler/effect.js +122 -0
  41. package/src/core/src/handler/index.js +143 -0
  42. package/src/core/src/handler/inject.js +199 -0
  43. package/src/core/src/handler/input.js +199 -0
  44. package/src/core/src/handler/lifecycle.js +55 -0
  45. package/src/core/src/handler/loader.js +375 -0
  46. package/src/core/src/handler/page.js +46 -0
  47. package/src/core/src/handler/render.js +29 -0
  48. package/src/core/src/index.js +12 -0
  49. package/src/core/src/parser/html.js +17 -0
  50. package/src/core/src/render/cache.js +47 -0
  51. package/src/core/src/render/index.js +33 -0
  52. package/src/core/src/render/render.js +418 -0
  53. package/src/core/types/index.d.ts +842 -0
  54. package/src/index.js +5 -0
  55. package/src/utils/LICENSE +21 -0
  56. package/src/utils/README.md +24 -0
  57. package/src/utils/lib/console.js +16 -0
  58. package/src/utils/lib/debounce.js +9 -0
  59. package/src/utils/lib/deepextend.js +51 -0
  60. package/src/utils/lib/deepset.js +14 -0
  61. package/src/utils/lib/extend.js +20 -0
  62. package/src/utils/lib/index.js +14 -0
  63. package/src/utils/lib/json.js +90 -0
  64. package/src/utils/lib/mergeprops.js +62 -0
  65. package/src/utils/lib/mitt.js +43 -0
  66. package/src/utils/lib/modify.js +8 -0
  67. package/src/utils/lib/slot.js +8 -0
  68. package/src/utils/lib/toarray.js +5 -0
  69. package/src/utils/lib/tocase.js +11 -0
  70. package/src/utils/lib/todate.js +10 -0
  71. package/src/utils/lib/toline.js +10 -0
  72. package/src/utils/lib/topromise.js +10 -0
  73. package/src/utils/lib/tostring.js +7 -0
  74. package/src/utils/lib/type.js +45 -0
  75. package/src/utils/lib/unique.js +6 -0
  76. package/src/utils/package.json +32 -0
  77. package/src/vant/LICENSE +21 -0
  78. package/src/vant/README.md +137 -0
  79. package/src/vant/auto-import.d.ts +5 -0
  80. package/src/vant/auto-import.js +50 -0
  81. package/src/vant/babel.config.js +10 -0
  82. package/src/vant/bili.config.js +40 -0
  83. package/src/vant/examples/App.vue +96 -0
  84. package/src/vant/examples/main.js +13 -0
  85. package/src/vant/examples/rule.js +366 -0
  86. package/src/vant/package-lock.json +11367 -0
  87. package/src/vant/package.json +83 -0
  88. package/src/vant/public/index.html +14 -0
  89. package/src/vant/src/components/calendar.jsx +128 -0
  90. package/src/vant/src/components/cascader.jsx +120 -0
  91. package/src/vant/src/components/checkbox.jsx +38 -0
  92. package/src/vant/src/components/datePicker.jsx +87 -0
  93. package/src/vant/src/components/group.jsx +384 -0
  94. package/src/vant/src/components/icon/IconWarning.vue +12 -0
  95. package/src/vant/src/components/index.js +26 -0
  96. package/src/vant/src/components/radio.jsx +38 -0
  97. package/src/vant/src/components/select.jsx +81 -0
  98. package/src/vant/src/components/timePicker.jsx +76 -0
  99. package/src/vant/src/components/uploader.jsx +99 -0
  100. package/src/vant/src/core/alias.js +31 -0
  101. package/src/vant/src/core/api.js +135 -0
  102. package/src/vant/src/core/config.js +35 -0
  103. package/src/vant/src/core/index.js +45 -0
  104. package/src/vant/src/core/manager.js +282 -0
  105. package/src/vant/src/core/provider.js +63 -0
  106. package/src/vant/src/core/utils.js +15 -0
  107. package/src/vant/src/index.js +13 -0
  108. package/src/vant/src/parsers/hidden.js +12 -0
  109. package/src/vant/src/parsers/index.js +59 -0
  110. package/src/vant/src/parsers/row.js +10 -0
  111. package/src/vant/src/style/index.css +495 -0
  112. package/src/vant/types/config.d.ts +99 -0
  113. package/src/vant/types/index.d.ts +27 -0
  114. package/src/vant/vue.config.js +21 -0
@@ -0,0 +1,792 @@
1
+ import $FormCreate from '../components/formCreate';
2
+ import {computed, createApp, h, nextTick, reactive, ref, watch} from 'vue';
3
+ import makerFactory from '../factory/maker';
4
+ import Handle from '../handler';
5
+ import fetch from './fetch';
6
+ import {creatorFactory, mergeRule} from '..';
7
+ import BaseParser from '../factory/parser';
8
+ import {copyRule, copyRules, deepGet, invoke, mergeGlobal, parseFn, parseJson, setPrototypeOf, toJson} from './util';
9
+ import fragment from '../components/fragment';
10
+ import is, {hasProperty} from '@form-create/utils/lib/type';
11
+ import toCase from '@form-create/utils/lib/tocase';
12
+ import extend, {copy} from '@form-create/utils/lib/extend';
13
+ import {CreateNodeFactory} from '../factory/node';
14
+ import {createManager} from '../factory/manager';
15
+ import {arrayAttrs, keyAttrs, normalAttrs} from './attrs';
16
+ import {appendProto} from '../factory/creator';
17
+ import $provider from './provider';
18
+ import {deepCopy} from '@form-create/utils/lib/deepextend';
19
+ import Mitt from '@form-create/utils/lib/mitt';
20
+ import html from '../parser/html';
21
+ import uniqueId from '@form-create/utils/lib/unique';
22
+ import {cookieDriver, localStorageDriver, sessionStorageDriver} from './dataDriver';
23
+ import debounce from '@form-create/utils/lib/debounce';
24
+ import {deepSet} from '@form-create/utils';
25
+ import baseLanguage from './language';
26
+
27
+ function parseProp(name, id) {
28
+ let prop;
29
+ if (arguments.length === 2) {
30
+ prop = arguments[1];
31
+ id = prop[name];
32
+ } else {
33
+ prop = arguments[2];
34
+ }
35
+ return {id, prop};
36
+ }
37
+
38
+ function nameProp() {
39
+ return parseProp('name', ...arguments);
40
+ }
41
+
42
+ function exportAttrs(attrs) {
43
+ const key = attrs.key || [];
44
+ const array = attrs.array || [];
45
+ const normal = attrs.normal || [];
46
+ keyAttrs.push(...key);
47
+ arrayAttrs.push(...array);
48
+ normalAttrs.push(...normal);
49
+
50
+ appendProto([...key, ...array, ...normal]);
51
+ }
52
+
53
+ let id = 1;
54
+ const instance = {};
55
+ const defValueTag = Symbol('defValue');
56
+
57
+ //todo 表单嵌套
58
+ export default function FormCreateFactory(config) {
59
+
60
+ const components = {
61
+ [fragment.name]: fragment
62
+ };
63
+ const parsers = {};
64
+ const directives = {};
65
+ const modelFields = {};
66
+ const drivers = {};
67
+ const useApps = [];
68
+ const listener = [];
69
+ const extendApiFn = [
70
+ config.extendApi
71
+ ];
72
+ const providers = {
73
+ ...$provider
74
+ };
75
+ const maker = makerFactory();
76
+ let globalConfig = {global: {}};
77
+ const isMobile = config.isMobile === true;
78
+ const loadData = reactive({
79
+ $mobile: isMobile,
80
+ });
81
+ const CreateNode = CreateNodeFactory();
82
+ const formulas = {};
83
+ const prototype = {};
84
+
85
+ exportAttrs(config.attrs || {});
86
+
87
+ function getApi(name) {
88
+ const val = instance[name];
89
+ if (Array.isArray(val)) {
90
+ return val.map(v => {
91
+ return v.api();
92
+ });
93
+ } else if (val) {
94
+ return val.api();
95
+ }
96
+ }
97
+
98
+ function useApp(fn) {
99
+ useApps.push(fn);
100
+ }
101
+
102
+ function directive() {
103
+ const data = nameProp(...arguments);
104
+ if (data.id && data.prop) directives[data.id] = data.prop;
105
+ }
106
+
107
+ function register() {
108
+ const data = nameProp(...arguments);
109
+ if (data.id && data.prop) providers[data.id] = is.Function(data.prop) ? data.prop : {
110
+ ...data.prop,
111
+ name: data.id
112
+ };
113
+ }
114
+
115
+ function componentAlias(alias) {
116
+ CreateNode.use(alias);
117
+ }
118
+
119
+ function parser(key) {
120
+ if (arguments.length === 0) {
121
+ return BaseParser;
122
+ } else if (typeof key === 'string' && arguments.length === 1) {
123
+ return parsers[toCase(key)];
124
+ }
125
+ const data = nameProp(...arguments);
126
+ if (!data.id || !data.prop) return BaseParser;
127
+ const name = toCase(data.id);
128
+ const parser = data.prop;
129
+ const base = parser.merge === true ? parsers[name] : undefined;
130
+ parsers[name] = setPrototypeOf(parser, base || BaseParser);
131
+ maker[name] = creatorFactory(name);
132
+ parser.maker && extend(maker, parser.maker);
133
+ }
134
+
135
+ function component(id, component) {
136
+ let name;
137
+ if (is.String(id)) {
138
+ name = id;
139
+ if (component === undefined) {
140
+ return components[name];
141
+ }
142
+ } else {
143
+ name = id.displayName || id.name;
144
+ component = id;
145
+ }
146
+ if (!name || !component) return;
147
+ const nameAlias = toCase(name);
148
+ components[name] = component;
149
+ components[nameAlias] = component;
150
+ delete CreateNode.aliasMap[name];
151
+ delete CreateNode.aliasMap[nameAlias];
152
+ delete parsers[name];
153
+ delete parsers[nameAlias];
154
+ if (component.formCreateParser) parser(name, component.formCreateParser);
155
+ }
156
+
157
+ function $form() {
158
+ return $FormCreate(FormCreate, components, directives);
159
+ }
160
+
161
+ function createFormApp(rule, option) {
162
+ const Type = $form();
163
+ return createApp({
164
+ data() {
165
+ return reactive({
166
+ rule, option
167
+ });
168
+ },
169
+ render() {
170
+ return h(Type, {ref: 'fc', ...this.$data});
171
+ }
172
+ });
173
+ }
174
+
175
+ function $vnode() {
176
+ return fragment;
177
+ }
178
+
179
+ //todo 检查回调函数作用域
180
+ function use(fn, opt) {
181
+ if (is.Function(fn.install)) fn.install(create, opt);
182
+ else if (is.Function(fn)) fn(create, opt);
183
+ return this;
184
+ }
185
+
186
+ function create(rules, option) {
187
+ let app = createFormApp(rules, option || {});
188
+ useApps.forEach(v => {
189
+ invoke(() => v(create, app));
190
+ })
191
+ const div = document.createElement('div');
192
+ (option?.el || document.body).appendChild(div);
193
+ const vm = app.mount(div);
194
+ return vm.$refs.fc.fapi;
195
+ }
196
+
197
+ setPrototypeOf(create, prototype);
198
+
199
+ function factory(inherit) {
200
+ let _config = {...config};
201
+ if (inherit) {
202
+ _config.inherit = {
203
+ components,
204
+ parsers,
205
+ directives,
206
+ modelFields,
207
+ providers,
208
+ useApps,
209
+ maker,
210
+ formulas,
211
+ loadData
212
+ }
213
+ } else {
214
+ delete _config.inherit;
215
+ }
216
+ return FormCreateFactory(_config);
217
+ }
218
+
219
+ function setModelField(name, field) {
220
+ modelFields[name] = field;
221
+ }
222
+
223
+ function setFormula(name, fn) {
224
+ formulas[name] = fn;
225
+ }
226
+
227
+ function setDriver(name, driver) {
228
+ const parent = drivers[name] || {};
229
+ const parsers = parent.parsers || {};
230
+ if (driver.parsers) {
231
+ Object.keys(driver.parsers).forEach(k => {
232
+ parsers[k] = setPrototypeOf(driver.parsers[k], BaseParser);
233
+ });
234
+ }
235
+ driver.name = name;
236
+ drivers[name] = {...parent, ...driver, parsers};
237
+ }
238
+
239
+ function refreshData(id) {
240
+ if (id) {
241
+ Object.keys(instance).forEach(v => {
242
+ const apis = Array.isArray(instance[v]) ? instance[v] : [instance[v]];
243
+ apis.forEach(that => {
244
+ that.bus.$emit('$loadData.' + id);
245
+ })
246
+ })
247
+ }
248
+ }
249
+
250
+ function setData(id, data) {
251
+ deepSet(loadData, id, data);
252
+ refreshData(id);
253
+ }
254
+
255
+ function setDataDriver(id, data) {
256
+ const callback = (...args) => {
257
+ return invoke(() => data(...args));
258
+ }
259
+ callback._driver = true;
260
+ setData(id, callback);
261
+ }
262
+
263
+ function getData(id, def) {
264
+ const split = (id || '').split('.');
265
+ id = split.shift();
266
+ const field = split.join('.');
267
+ if (!hasProperty(loadData, id)) {
268
+ loadData[id] = defValueTag;
269
+ }
270
+ if (loadData[id] !== defValueTag) {
271
+ let val = loadData[id];
272
+ if (val && val._driver) {
273
+ val = val(field);
274
+ } else if (split.length) {
275
+ val = deepGet(val, split);
276
+ }
277
+ return (val == null || val === '') ? def : val;
278
+ } else {
279
+ return def;
280
+ }
281
+ }
282
+
283
+ function extendApi(fn) {
284
+ extendApiFn.push(fn);
285
+ }
286
+
287
+ function removeData(id) {
288
+ delete loadData[id];
289
+ refreshData(id);
290
+ }
291
+
292
+ function on(name, callback) {
293
+ listener.push({name, callback});
294
+ }
295
+
296
+ function FormCreate(vm) {
297
+ extend(this, {
298
+ id: id++,
299
+ create,
300
+ vm,
301
+ manager: createManager(config.manager),
302
+ parsers,
303
+ providers,
304
+ modelFields,
305
+ formulas,
306
+ isMobile,
307
+ rules: vm.props.rule,
308
+ name: vm.props.name || uniqueId(),
309
+ inFor: vm.props.inFor,
310
+ prop: {
311
+ components,
312
+ directives,
313
+ },
314
+ get: null,
315
+ drivers,
316
+ renderDriver: null,
317
+ refreshData,
318
+ loadData,
319
+ CreateNode,
320
+ bus: new Mitt(),
321
+ unwatch: [],
322
+ options: ref({}),
323
+ extendApiFn,
324
+ fetchCache: new WeakMap(),
325
+ tmpData: reactive({}),
326
+ })
327
+ listener.forEach(item => {
328
+ this.bus.$on(item.name, item.callback);
329
+ });
330
+ nextTick(() => {
331
+ watch(this.options, () => {
332
+ this.$handle.$manager.updateOptions(this.options.value);
333
+ this.api().refresh();
334
+ }, {deep: true})
335
+ });
336
+ extend(vm.appContext.components, components);
337
+ extend(vm.appContext.directives, directives);
338
+ this.$handle = new Handle(this)
339
+ if (this.name) {
340
+ if (this.inFor) {
341
+ if (!instance[this.name]) instance[this.name] = [];
342
+ instance[this.name].push(this);
343
+ } else {
344
+ instance[this.name] = this;
345
+ }
346
+ }
347
+ }
348
+
349
+ FormCreate.isMobile = isMobile;
350
+
351
+ extend(FormCreate.prototype, {
352
+ init() {
353
+ if (this.isSub()) {
354
+ this.unwatch.push(watch(() => this.vm.setupState.parent.setupState.fc.options.value, () => {
355
+ this.initOptions();
356
+ this.$handle.api.refresh();
357
+ }, {deep: true, flush: 'sync'}));
358
+ }
359
+ if (this.vm.props.driver) {
360
+ this.renderDriver = typeof this.vm.props.driver === 'object' ? this.vm.props.driver : this.drivers[this.vm.props.driver];
361
+ }
362
+ if (!this.renderDriver && this.vm.setupState.parent) {
363
+ this.renderDriver = this.vm.setupState.parent.setupState.fc.renderDriver;
364
+ }
365
+ if (!this.renderDriver) {
366
+ this.renderDriver = this.drivers.default;
367
+ }
368
+ this.initOptions();
369
+ this.$handle.init();
370
+ },
371
+ targetFormDriver(method, ...args) {
372
+ this.bus.$emit(method, ...args);
373
+ if (this.renderDriver && this.renderDriver[method]) {
374
+ return invoke(() => this.renderDriver[method](...args));
375
+ }
376
+ },
377
+ t(id, params, get) {
378
+ let value = get ? get('$t.' + id) : this.globalLanguageDriver(id);
379
+ if (value == null) {
380
+ value = '';
381
+ }
382
+ if (value && params) {
383
+ Object.keys(params).forEach(param => {
384
+ const regex = new RegExp(`{${param}}`, 'g');
385
+ value = value.replace(regex, params[param]);
386
+ });
387
+ }
388
+ return value;
389
+ },
390
+ globalDataDriver(id) {
391
+ let split = id.split('.');
392
+ const key = split.shift();
393
+ const option = this.options.value.globalData && this.options.value.globalData[key];
394
+ if (option) {
395
+ if (option.type === 'static') {
396
+ return deepGet(option.data, split);
397
+ } else {
398
+ let val;
399
+ const res = this.fetchCache.get(option);
400
+ if (res) {
401
+ if (res.status) {
402
+ val = deepGet(res.data, split);
403
+ }
404
+ if (!res.loading) {
405
+ return val;
406
+ }
407
+ res.loading = false;
408
+ this.fetchCache.set(option, res);
409
+ } else {
410
+ this.fetchCache.set(option, {status: false});
411
+ }
412
+ const reload = debounce(() => {
413
+ unwatch();
414
+ const res = this.fetchCache.get(option);
415
+ if ((this.options.value.globalData && Object.values(this.options.value.globalData).indexOf(option) !== -1)) {
416
+ if (res) {
417
+ res.loading = true;
418
+ this.fetchCache.set(option, res);
419
+ }
420
+ this.bus.$emit('$loadData.$globalData.' + key);
421
+ } else {
422
+ this.fetchCache.delete(option);
423
+ }
424
+ }, option.wait || 600)
425
+
426
+ const _emit = (data) => {
427
+ this.fetchCache.set(option, {status: true, data});
428
+ this.bus.$emit('$loadData.$globalData.' + key);
429
+ };
430
+
431
+ const callback = (get, change) => {
432
+ if (change && option.watch === false) {
433
+ return unwatch();
434
+ }
435
+ if (change) {
436
+ reload();
437
+ return;
438
+ }
439
+ const options = this.$handle.loadFetchVar(copy(option), get);
440
+ options.targetRule = this.targetRule;
441
+ this.$handle.api.fetch(options).then(res => {
442
+ _emit(res);
443
+ }).catch(e => {
444
+ _emit(null);
445
+ });
446
+ };
447
+ const unwatch = this.watchLoadData(callback);
448
+ if(option.watch === false) {
449
+ unwatch();
450
+ }
451
+ this.unwatch.push(unwatch);
452
+ return val;
453
+ }
454
+ }
455
+ },
456
+ getLocale() {
457
+ let locale = this.vm.setupState.top.props.locale;
458
+ if (locale && typeof locale === 'object') {
459
+ return locale.name;
460
+ }
461
+ if (typeof locale === 'string') {
462
+ return locale;
463
+ }
464
+ return 'zh-cn';
465
+ },
466
+ globalLanguageDriver(id) {
467
+ let t = this.vm.setupState.top.props.t;
468
+ let locale = this.vm.setupState.top.props.locale;
469
+ let value = undefined;
470
+ if (t) {
471
+ value = invoke(() => t(id));
472
+ }
473
+ if (value == null && locale && typeof locale === 'object') {
474
+ value = deepGet(locale, id);
475
+ }
476
+ if (value == null) {
477
+ const language = this.options.value.language || {};
478
+ const locale = this.getLocale();
479
+ value = deepGet(language[locale] || {}, id);
480
+ if (value == null) {
481
+ value = deepGet(baseLanguage[locale] || {}, id);
482
+ }
483
+ }
484
+ return value;
485
+ },
486
+ globalVarDriver(id) {
487
+ let split = id.split('.');
488
+ const key = split.shift();
489
+ const option = this.options.value.globalVariable && this.options.value.globalVariable[key];
490
+ if (option) {
491
+ const handle = is.Function(option) ? option : parseFn(option.handle);
492
+ if (handle) {
493
+ let val = handle((...args) => this.$handle.api.getData(...args), this.$handle.api);
494
+ return deepGet(val, split);
495
+ }
496
+ }
497
+ },
498
+ setData(id, data, isGlobal) {
499
+ if (!isGlobal) {
500
+ deepSet(this.vm.setupState.top.setupState.fc.tmpData, id, data);
501
+ this.bus.$emit('$loadData.' + id);
502
+ } else {
503
+ setData(id, data);
504
+ }
505
+ },
506
+ getLoadData(id, def) {
507
+ let val = null;
508
+ if (id != null) {
509
+ let split = id.split('.');
510
+ const key = split.shift();
511
+ val = deepGet(this.vm.setupState.top.setupState.fc.tmpData, id);
512
+ if (val != null) {
513
+ return val;
514
+ } else if (key === '$topForm') {
515
+ val = this.$handle.api.top.formData(true);
516
+ } else if (key === '$scopeForm') {
517
+ val = this.$handle.api.scope.formData(true);
518
+ } else if (key === '$form') {
519
+ val = this.$handle.api.formData(true);
520
+ } else if (key === '$options') {
521
+ val = this.options.value;
522
+ } else if (key === '$globalData') {
523
+ val = this.globalDataDriver(split.join('.'));
524
+ split = [];
525
+ } else if (key === '$var') {
526
+ val = this.globalVarDriver(split.join('.'));
527
+ split = [];
528
+ } else if (key === '$locale') {
529
+ val = this.getLocale();
530
+ split = [];
531
+ } else if (key === '$t') {
532
+ val = this.globalLanguageDriver(split.join('.'));
533
+ split = [];
534
+ } else if (key === '$preview') {
535
+ return this.$handle.preview;
536
+ } else {
537
+ val = getData(id);
538
+ split = [];
539
+ }
540
+ if (val && split.length) {
541
+ val = deepGet(val, split);
542
+ }
543
+ }
544
+ return (val == null || val === '') ? def : val;
545
+ },
546
+ watchLoadData(fn, wait) {
547
+ let unwatch = {};
548
+
549
+ const run = (flag) => {
550
+ if (!this.get) {
551
+ this.get = get;
552
+ }
553
+ invoke(() => {
554
+ fn(get, flag);
555
+ });
556
+ if (this.get === get) {
557
+ this.get = undefined;
558
+ }
559
+ };
560
+
561
+ const get = (id, def) => {
562
+ let getValue;
563
+ if (typeof id === 'object') {
564
+ getValue = id.getValue;
565
+ id = id.id;
566
+ }
567
+ if (unwatch[id]) {
568
+ return unwatch[id].val;
569
+ }
570
+ const data = computed(() => {
571
+ return getValue ? getValue() : this.getLoadData(id, def);
572
+ })
573
+ const split = id.split('.');
574
+ const key = split.shift();
575
+ const key2 = split.shift() || '';
576
+ const callback = debounce(() => {
577
+ const temp = getValue ? getValue() : this.getLoadData(id, def);
578
+ if (!unwatch[id]) {
579
+ return;
580
+ } else if (((temp instanceof Function || is.Object(temp) || Array.isArray(temp)) && temp === unwatch[id].val) || JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
581
+ unwatch[id].val = temp;
582
+ run(true);
583
+ }
584
+ }, wait || 0);
585
+ const un = watch(data, (n) => {
586
+ callback();
587
+ });
588
+ this.bus.$on('$loadData.' + key, callback);
589
+ if (key2) {
590
+ this.bus.$on('$loadData.' + key + '.' + key2, callback);
591
+ }
592
+ unwatch[id] = {
593
+ fn: (() => {
594
+ this.bus.$off('$loadData.' + key, callback);
595
+ if (key2) {
596
+ this.bus.$off('$loadData.' + key + '.' + key2, callback);
597
+ }
598
+ un();
599
+ }),
600
+ val: data.value,
601
+ }
602
+ return data.value;
603
+ }
604
+ run(false);
605
+ const un = () => {
606
+ Object.keys(unwatch).forEach(k => unwatch[k].fn());
607
+ unwatch = {};
608
+ }
609
+ this.unwatch.push(un);
610
+ return un;
611
+ },
612
+ isSub() {
613
+ return this.vm.setupState.parent && this.vm.props.extendOption;
614
+ },
615
+ initOptions() {
616
+ this.options.value = {};
617
+ let options = {
618
+ formData: {},
619
+ submitBtn: {},
620
+ resetBtn: {},
621
+ globalEvent: {},
622
+ globalData: {}, ...deepCopy(globalConfig)
623
+ };
624
+ const isSubForm = this.isSub();
625
+ if (isSubForm) {
626
+ options = this.mergeOptions(options, this.vm.setupState.parent.setupState.fc.options.value || {}, true);
627
+ }
628
+ options = this.mergeOptions(options, this.vm.props.option);
629
+ const api = this.api();
630
+ this.targetFormDriver('initOptions', options, {api, isSubForm});
631
+ this.updateOptions(options);
632
+ },
633
+ mergeOptions(target, opt, parent) {
634
+ opt = {...opt || {}};
635
+ parent && ['page', 'onSubmit', 'onReset', 'onCreated', 'onChange', 'onMounted', 'mounted', 'onReload', 'reload', 'formData', 'el', 'globalClass', 'style'].forEach((n) => {
636
+ delete opt[n];
637
+ });
638
+ if (opt.global) {
639
+ target.global = mergeGlobal(target.global, opt.global);
640
+ delete opt.global;
641
+ }
642
+ this.$handle.$manager.mergeOptions([opt], target);
643
+ return target;
644
+ },
645
+ updateOptions(options) {
646
+ this.options.value = this.mergeOptions(this.options.value, options);
647
+ this.$handle.$manager.updateOptions(this.options.value);
648
+ this.bus.$emit('$loadData.$options');
649
+ },
650
+ api() {
651
+ return this.$handle.api;
652
+ },
653
+ render() {
654
+ return this.$handle.render();
655
+ },
656
+ mounted() {
657
+ this.$handle.mounted();
658
+ },
659
+ unmount() {
660
+ if (this.name) {
661
+ if (this.inFor) {
662
+ const idx = instance[this.name].indexOf(this);
663
+ instance[this.name].splice(idx, 1);
664
+ } else {
665
+ delete instance[this.name];
666
+ }
667
+ }
668
+ listener.forEach(item => {
669
+ this.bus.$off(item.name, item.callback);
670
+ });
671
+ this.tmpData = {};
672
+ this.unwatch.forEach(fn => fn());
673
+ this.unwatch = [];
674
+ this.$handle.reloadRule([]);
675
+ },
676
+ updated() {
677
+ this.$handle.bindNextTick(() => this.bus.$emit('next-tick', this.$handle.api));
678
+ }
679
+ })
680
+
681
+
682
+ function useAttr(formCreate) {
683
+ extend(formCreate, {
684
+ version: config.version,
685
+ ui: config.ui,
686
+ isMobile,
687
+ extendApi,
688
+ getData,
689
+ setDataDriver,
690
+ setData,
691
+ removeData,
692
+ refreshData,
693
+ maker,
694
+ component,
695
+ directive,
696
+ setModelField,
697
+ setFormula,
698
+ setDriver,
699
+ register,
700
+ $vnode,
701
+ parser,
702
+ use,
703
+ factory,
704
+ componentAlias,
705
+ copyRule,
706
+ copyRules,
707
+ mergeRule,
708
+ fetch,
709
+ $form,
710
+ parseFn,
711
+ parseJson,
712
+ toJson,
713
+ useApp,
714
+ getApi,
715
+ on,
716
+ });
717
+ }
718
+
719
+ function useStatic(formCreate) {
720
+ extend(formCreate, {
721
+ create,
722
+ install(app, options) {
723
+ globalConfig = {...globalConfig, ...(options || {})}
724
+ const key = `_installedFormCreate${isMobile ? 'Mobile' : ''}_${config.ui}`;
725
+ if (app[key] === true) return;
726
+ app[key] = true;
727
+
728
+ const $formCreate = function (rules, opt = {}) {
729
+ return create(rules, opt, this);
730
+ };
731
+
732
+ useAttr($formCreate);
733
+
734
+ app.config.globalProperties.$formCreate = $formCreate;
735
+ const $component = $form();
736
+ app.component($component.name, $component);
737
+ useApps.forEach(v => {
738
+ invoke(() => v(formCreate, app));
739
+ })
740
+ }
741
+ })
742
+ }
743
+
744
+ useAttr(prototype);
745
+ useStatic(prototype);
746
+
747
+ setDataDriver('$cookie', cookieDriver);
748
+ setDataDriver('$localStorage', localStorageDriver);
749
+ setDataDriver('$sessionStorage', sessionStorageDriver);
750
+
751
+ CreateNode.use({fragment: 'fcFragment'});
752
+
753
+ config.install && create.use(config);
754
+
755
+ useApp((_, app) => {
756
+ app.mixin({
757
+ props: ['formCreateInject'],
758
+ })
759
+ })
760
+
761
+ parser(html);
762
+
763
+ if (config.inherit) {
764
+ const inherit = config.inherit;
765
+ inherit.components && extend(components, inherit.components);
766
+ inherit.parsers && extend(parsers, inherit.parsers);
767
+ inherit.directives && extend(directives, inherit.directives);
768
+ inherit.modelFields && extend(modelFields, inherit.modelFields);
769
+ inherit.providers && extend(providers, inherit.providers);
770
+ inherit.useApps && extend(useApps, inherit.useApps);
771
+ inherit.maker && extend(maker, inherit.maker);
772
+ inherit.loadData && extend(loadData, inherit.loadData);
773
+ inherit.formulas && extend(formulas, inherit.formulas);
774
+ }
775
+
776
+ const FcComponent = $form();
777
+ setPrototypeOf(FcComponent, prototype);
778
+ Object.defineProperties(FcComponent, {
779
+ fetch: {
780
+ get() {
781
+ return prototype.fetch;
782
+ },
783
+ set(val) {
784
+ prototype.fetch = val;
785
+ }
786
+ }
787
+ })
788
+
789
+ FcComponent.util = prototype;
790
+
791
+ return FcComponent;
792
+ }