icarys-fc-vant 1.0.14 → 1.0.16
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/README.md +87 -278
- package/dist/components/common/subform/package.json +48 -0
- package/dist/components/common/subform/src/component.jsx +75 -0
- package/dist/components/common/subform/src/index.js +3 -0
- package/dist/components/common/wangeditor/package-lock.json +114 -0
- package/dist/components/common/wangeditor/package.json +52 -0
- package/dist/components/common/wangeditor/src/component.jsx +74 -0
- package/dist/components/common/wangeditor/src/index.js +3 -0
- package/dist/core/babel.config.js +13 -0
- package/dist/core/bili.config.js +34 -0
- package/dist/core/package-lock.json +13 -0
- package/dist/core/package.json +61 -0
- package/dist/core/src/components/formCreate.js +287 -0
- package/dist/core/src/components/fragment.js +12 -0
- package/dist/core/src/factory/context.js +264 -0
- package/dist/core/src/factory/creator.js +63 -0
- package/dist/core/src/factory/maker.js +17 -0
- package/dist/core/src/factory/manager.js +87 -0
- package/dist/core/src/factory/node.js +89 -0
- package/dist/core/src/factory/parser.js +28 -0
- package/dist/core/src/frame/api.js +691 -0
- package/dist/core/src/frame/attrs.js +12 -0
- package/dist/core/src/frame/dataDriver.js +76 -0
- package/dist/core/src/frame/fetch.js +128 -0
- package/dist/core/src/frame/index.js +792 -0
- package/dist/core/src/frame/language.js +50 -0
- package/dist/core/src/frame/provider.js +297 -0
- package/dist/core/src/frame/util.js +311 -0
- package/dist/core/src/handler/context.js +573 -0
- package/dist/core/src/handler/effect.js +122 -0
- package/dist/core/src/handler/index.js +143 -0
- package/dist/core/src/handler/inject.js +199 -0
- package/dist/core/src/handler/input.js +199 -0
- package/dist/core/src/handler/lifecycle.js +55 -0
- package/dist/core/src/handler/loader.js +375 -0
- package/dist/core/src/handler/page.js +46 -0
- package/dist/core/src/handler/render.js +29 -0
- package/dist/core/src/index.js +12 -0
- package/dist/core/src/parser/html.js +17 -0
- package/dist/core/src/render/cache.js +47 -0
- package/dist/core/src/render/index.js +33 -0
- package/dist/core/src/render/render.js +418 -0
- package/dist/core/types/index.d.ts +842 -0
- package/dist/icarys-fc-vant.umd.js +17 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.esm.js +39 -0
- package/dist/index.js +46 -0
- package/dist/utils/lib/console.js +16 -0
- package/dist/utils/lib/debounce.js +9 -0
- package/dist/utils/lib/deepextend.js +51 -0
- package/dist/utils/lib/deepset.js +14 -0
- package/dist/utils/lib/extend.js +20 -0
- package/dist/utils/lib/index.js +14 -0
- package/dist/utils/lib/json.js +90 -0
- package/dist/utils/lib/mergeprops.js +62 -0
- package/dist/utils/lib/mitt.js +43 -0
- package/dist/utils/lib/modify.js +8 -0
- package/dist/utils/lib/slot.js +8 -0
- package/dist/utils/lib/toarray.js +5 -0
- package/dist/utils/lib/tocase.js +11 -0
- package/dist/utils/lib/todate.js +10 -0
- package/dist/utils/lib/toline.js +10 -0
- package/dist/utils/lib/topromise.js +10 -0
- package/dist/utils/lib/tostring.js +7 -0
- package/dist/utils/lib/type.js +45 -0
- package/dist/utils/lib/unique.js +6 -0
- package/dist/utils/package.json +32 -0
- package/dist/vant/auto-import.d.ts +5 -0
- package/dist/vant/auto-import.js +50 -0
- package/dist/vant/babel.config.js +10 -0
- package/dist/vant/bili.config.js +40 -0
- package/dist/vant/examples/main.js +13 -0
- package/dist/vant/examples/rule.js +366 -0
- package/dist/vant/package.json +83 -0
- package/dist/vant/src/components/calendar.jsx +128 -0
- package/dist/vant/src/components/cascader.jsx +120 -0
- package/dist/vant/src/components/checkbox.jsx +38 -0
- package/dist/vant/src/components/datePicker.jsx +87 -0
- package/dist/vant/src/components/group.jsx +384 -0
- package/dist/vant/src/components/index.js +26 -0
- package/dist/vant/src/components/radio.jsx +38 -0
- package/dist/vant/src/components/select.jsx +81 -0
- package/dist/vant/src/components/timePicker.jsx +76 -0
- package/dist/vant/src/components/uploader.jsx +99 -0
- package/dist/vant/src/core/alias.js +31 -0
- package/dist/vant/src/core/api.js +135 -0
- package/dist/vant/src/core/config.js +35 -0
- package/dist/vant/src/core/index.js +45 -0
- package/dist/vant/src/core/manager.js +282 -0
- package/dist/vant/src/core/provider.js +63 -0
- package/dist/vant/src/core/utils.js +15 -0
- package/dist/vant/src/index.js +13 -0
- package/dist/vant/src/parsers/hidden.js +12 -0
- package/dist/vant/src/parsers/index.js +59 -0
- package/dist/vant/src/parsers/row.js +10 -0
- package/dist/vant/src/style/index.css +495 -0
- package/dist/vant/types/config.d.ts +99 -0
- package/dist/vant/types/index.d.ts +27 -0
- package/dist/vant/vue.config.js +21 -0
- package/package.json +29 -52
- package/dist/index.min.js +0 -7411
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import extend from '../../../utils/lib/extend';
|
|
2
|
+
import toCase from '../../../utils/lib/tocase';
|
|
3
|
+
import BaseParser from '../factory/parser';
|
|
4
|
+
import {$del} from '../../../utils/lib/modify';
|
|
5
|
+
import is, {hasProperty} from '../../../utils/lib/type';
|
|
6
|
+
import {condition, deepGet, invoke, convertFieldToConditions} from '../frame/util';
|
|
7
|
+
import {computed, nextTick, toRef, watch} from 'vue';
|
|
8
|
+
import {attrs} from '../frame/attrs';
|
|
9
|
+
import {deepSet} from '@form-create/utils';
|
|
10
|
+
import toArray from '../../../utils/lib/toarray';
|
|
11
|
+
|
|
12
|
+
const noneKey = ['field', 'value', 'vm', 'template', 'name', 'config', 'control', 'inject', 'sync', 'payload', 'optionsTo', 'update', 'slotUpdate', 'computed', 'component', 'cache'];
|
|
13
|
+
const oldValueTag = Symbol('oldValue');
|
|
14
|
+
|
|
15
|
+
export default function useContext(Handler) {
|
|
16
|
+
extend(Handler.prototype, {
|
|
17
|
+
getCtx(id) {
|
|
18
|
+
return this.getFieldCtx(id) || this.getNameCtx(id)[0] || this.ctxs[id];
|
|
19
|
+
},
|
|
20
|
+
getCtxs(id) {
|
|
21
|
+
return this.fieldCtx[id] || this.nameCtx[id] || (this.ctxs[id] ? [this.ctxs[id]] : []);
|
|
22
|
+
},
|
|
23
|
+
setIdCtx(ctx, key, type) {
|
|
24
|
+
const field = `${type}Ctx`;
|
|
25
|
+
if (!this[field][key]) {
|
|
26
|
+
this[field][key] = [ctx];
|
|
27
|
+
} else {
|
|
28
|
+
this[field][key].push(ctx);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
rmIdCtx(ctx, key, type) {
|
|
32
|
+
const field = `${type}Ctx`;
|
|
33
|
+
const lst = this[field][key];
|
|
34
|
+
if (!lst) return false;
|
|
35
|
+
const flag = lst.splice(lst.indexOf(ctx) >>> 0, 1).length > 0;
|
|
36
|
+
if (!lst.length) {
|
|
37
|
+
delete this[field][key];
|
|
38
|
+
}
|
|
39
|
+
return flag;
|
|
40
|
+
},
|
|
41
|
+
getFieldCtx(field) {
|
|
42
|
+
return (this.fieldCtx[field] || [])[0];
|
|
43
|
+
},
|
|
44
|
+
getNameCtx(name) {
|
|
45
|
+
return this.nameCtx[name] || [];
|
|
46
|
+
},
|
|
47
|
+
setCtx(ctx) {
|
|
48
|
+
let {id, field, name, rule} = ctx;
|
|
49
|
+
this.ctxs[id] = ctx;
|
|
50
|
+
name && this.setIdCtx(ctx, name, 'name');
|
|
51
|
+
if (!ctx.input) return;
|
|
52
|
+
this.setIdCtx(ctx, field, 'field');
|
|
53
|
+
this.setFormData(ctx, ctx.parser.toFormValue(rule.value, ctx));
|
|
54
|
+
if (this.isMounted && !this.reloading) {
|
|
55
|
+
this.vm.emit('change', ctx.field, rule.value, ctx.origin, this.api, false, true);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
getParser(ctx) {
|
|
59
|
+
const list = this.fc.parsers;
|
|
60
|
+
const renderDriver = this.fc.renderDriver;
|
|
61
|
+
if (renderDriver) {
|
|
62
|
+
const parsers = renderDriver.parsers || {};
|
|
63
|
+
const parser = parsers[ctx.originType] || parsers[toCase(ctx.type)] || parsers[ctx.trueType];
|
|
64
|
+
if (parser) {
|
|
65
|
+
return parser;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return list[ctx.originType] || list[toCase(ctx.type)] || list[ctx.trueType] || BaseParser;
|
|
69
|
+
},
|
|
70
|
+
bindParser(ctx) {
|
|
71
|
+
ctx.setParser(this.getParser(ctx));
|
|
72
|
+
},
|
|
73
|
+
getType(alias) {
|
|
74
|
+
const map = this.fc.CreateNode.aliasMap;
|
|
75
|
+
const type = map[alias] || map[toCase(alias)] || alias;
|
|
76
|
+
return toCase(type);
|
|
77
|
+
},
|
|
78
|
+
noWatch(fn) {
|
|
79
|
+
if (!this.noWatchFn) {
|
|
80
|
+
this.noWatchFn = fn;
|
|
81
|
+
}
|
|
82
|
+
invoke(fn);
|
|
83
|
+
if (this.noWatchFn === fn) {
|
|
84
|
+
this.noWatchFn = null;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
watchCtx(ctx) {
|
|
88
|
+
const all = attrs();
|
|
89
|
+
all.filter(k => k[0] !== '_' && k[0] !== '$' && noneKey.indexOf(k) === -1).forEach((key) => {
|
|
90
|
+
const ref = toRef(ctx.rule, key);
|
|
91
|
+
const flag = key === 'children';
|
|
92
|
+
ctx.refRule[key] = ref;
|
|
93
|
+
ctx.watch.push(watch(flag ? () => is.Function(ref.value) ? ref.value : [...(ref.value || [])] : () => ref.value, (_, o) => {
|
|
94
|
+
let n = ref.value;
|
|
95
|
+
if (this.isBreakWatch()) return;
|
|
96
|
+
if (flag && ctx.parser.loadChildren === false) {
|
|
97
|
+
this.$render.clearCache(ctx);
|
|
98
|
+
this.nextRefresh();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.watching = true;
|
|
102
|
+
nextTick(() => {
|
|
103
|
+
this.targetHook(ctx, 'watch', {key, oldValue: o, newValue: n});
|
|
104
|
+
});
|
|
105
|
+
if (key === 'hidden' && Boolean(n) !== Boolean(o)) {
|
|
106
|
+
this.$render.clearCacheAll();
|
|
107
|
+
nextTick(() => {
|
|
108
|
+
this.targetHook(ctx, 'hidden', {value: n});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
if ((key === 'ignore' && ctx.input) || (key === 'hidden' && (ctx.rule.ignore === 'hidden' || this.options.ignoreHiddenFields))) {
|
|
112
|
+
this.syncForm();
|
|
113
|
+
} else if (key === 'link') {
|
|
114
|
+
ctx.link();
|
|
115
|
+
return;
|
|
116
|
+
} else if (['props', 'on', 'deep'].indexOf(key) > -1) {
|
|
117
|
+
this.parseInjectEvent(ctx.rule, n || {});
|
|
118
|
+
if (key === 'props' && ctx.input) {
|
|
119
|
+
this.setFormData(ctx, ctx.parser.toFormValue(ctx.rule.value, ctx));
|
|
120
|
+
}
|
|
121
|
+
} else if (key === 'emit') {
|
|
122
|
+
this.parseEmit(ctx);
|
|
123
|
+
} else if (['prefix', 'suffix'].indexOf(key) > -1)
|
|
124
|
+
n && this.loadFn(n, ctx.rule);
|
|
125
|
+
else if (key === 'type') {
|
|
126
|
+
ctx.updateType();
|
|
127
|
+
this.bindParser(ctx);
|
|
128
|
+
} else if (flag) {
|
|
129
|
+
if (is.Function(o)) {
|
|
130
|
+
o = ctx.getPending('children', []);
|
|
131
|
+
}
|
|
132
|
+
if (is.Function(n)) {
|
|
133
|
+
n = ctx.loadChildrenPending();
|
|
134
|
+
}
|
|
135
|
+
this.updateChildren(ctx, n, o);
|
|
136
|
+
}
|
|
137
|
+
this.$render.clearCache(ctx);
|
|
138
|
+
this.refresh();
|
|
139
|
+
this.watching = false;
|
|
140
|
+
}, {deep: !flag, sync: flag}));
|
|
141
|
+
});
|
|
142
|
+
ctx.refRule['__$title'] = computed(() => {
|
|
143
|
+
let title = (typeof ctx.rule.title === 'object' ? ctx.rule.title.title : ctx.rule.title) || '';
|
|
144
|
+
if (title) {
|
|
145
|
+
const match = title.match(/^\{\{\s*\$t\.(.+)\s*\}\}$/);
|
|
146
|
+
if (match) {
|
|
147
|
+
title = this.api.t(match[1]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return title;
|
|
151
|
+
});
|
|
152
|
+
ctx.refRule['__$info'] = computed(() => {
|
|
153
|
+
let info = (typeof ctx.rule.info === 'object' ? ctx.rule.info.info : ctx.rule.info) || '';
|
|
154
|
+
if (info) {
|
|
155
|
+
const match = info.match(/^\{\{\s*\$t\.(.+)\s*\}\}$/);
|
|
156
|
+
if (match) {
|
|
157
|
+
info = this.api.t(match[1]);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return info;
|
|
161
|
+
});
|
|
162
|
+
ctx.refRule['__$validate'] = computed(() => {
|
|
163
|
+
const t = (msg) => {
|
|
164
|
+
const match = msg.match(/^\{\{\s*\$t\.(.+)\s*\}\}$/);
|
|
165
|
+
if (match) {
|
|
166
|
+
return this.api.t(match[1], {title: ctx.refRule?.__$title?.value});
|
|
167
|
+
}
|
|
168
|
+
return msg;
|
|
169
|
+
}
|
|
170
|
+
return toArray(ctx.rule.validate).map(item => {
|
|
171
|
+
const temp = {...item};
|
|
172
|
+
if (temp.message) {
|
|
173
|
+
temp.message = t(temp.message);
|
|
174
|
+
}
|
|
175
|
+
if (is.Function(temp.validator)) {
|
|
176
|
+
const that = ctx;
|
|
177
|
+
temp.validator = function (...args) {
|
|
178
|
+
return item.validator.call({
|
|
179
|
+
that: this,
|
|
180
|
+
id: that.id,
|
|
181
|
+
field: that.field,
|
|
182
|
+
rule: that.rule,
|
|
183
|
+
api: that.$handle.api,
|
|
184
|
+
}, ...args)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (temp.adapter) {
|
|
188
|
+
if (typeof temp.error === 'object') {
|
|
189
|
+
const msg = {...temp.error};
|
|
190
|
+
Object.keys(msg).forEach((key) => {
|
|
191
|
+
msg[key] = t(msg[key]);
|
|
192
|
+
})
|
|
193
|
+
temp.error = msg;
|
|
194
|
+
}
|
|
195
|
+
return this.adapterValidate(temp, ctx);
|
|
196
|
+
}
|
|
197
|
+
return temp;
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
if (ctx.input) {
|
|
201
|
+
const val = toRef(ctx.rule, 'value');
|
|
202
|
+
ctx.watch.push(watch(() => val.value, () => {
|
|
203
|
+
let formValue = ctx.parser.toFormValue(val.value, ctx);
|
|
204
|
+
if (this.isChange(ctx, formValue)) {
|
|
205
|
+
this.setValue(ctx, val.value, formValue, true);
|
|
206
|
+
}
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
this.bus.$once('load-end', () => {
|
|
210
|
+
let computedRule = ctx.rule.computed;
|
|
211
|
+
if (!computedRule) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (typeof computedRule !== 'object') {
|
|
215
|
+
computedRule = {value: computedRule}
|
|
216
|
+
}
|
|
217
|
+
Object.keys(computedRule).forEach(k => {
|
|
218
|
+
const computedValue = computed(() => {
|
|
219
|
+
const item = computedRule[k];
|
|
220
|
+
if (!item) return undefined;
|
|
221
|
+
const value = this.compute(ctx, item);
|
|
222
|
+
if ((item.linkage || item.linkageVariable) && value === oldValueTag) {
|
|
223
|
+
return oldValueTag;
|
|
224
|
+
}
|
|
225
|
+
return value;
|
|
226
|
+
});
|
|
227
|
+
const callback = (n) => {
|
|
228
|
+
if (k === 'value') {
|
|
229
|
+
this.onInput(ctx, n);
|
|
230
|
+
} else if (k[0] === '$') {
|
|
231
|
+
this.api.setEffect(ctx.id, k, n);
|
|
232
|
+
} else {
|
|
233
|
+
deepSet(ctx.rule, k, n);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
if (k === 'value' ? [undefined, null, ''].indexOf(ctx.rule.value) > -1 : computedValue.value !== deepGet(ctx.rule, k)) {
|
|
237
|
+
callback(computedValue.value);
|
|
238
|
+
}
|
|
239
|
+
ctx.watch.push(watch(computedValue, (n) => {
|
|
240
|
+
if(n === oldValueTag) {
|
|
241
|
+
return ;
|
|
242
|
+
}
|
|
243
|
+
setTimeout(() => {
|
|
244
|
+
callback(n);
|
|
245
|
+
});
|
|
246
|
+
}, {deep: true}));
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
});
|
|
250
|
+
this.watchEffect(ctx);
|
|
251
|
+
},
|
|
252
|
+
adapterValidate(validate, ctx) {
|
|
253
|
+
const validator = (value, callback) => {
|
|
254
|
+
const before = validate.beforeValidate && invoke(() => validate.beforeValidate({
|
|
255
|
+
value,
|
|
256
|
+
api: this.api,
|
|
257
|
+
validate,
|
|
258
|
+
rule: ctx.rule
|
|
259
|
+
}));
|
|
260
|
+
if (before === false) {
|
|
261
|
+
callback();
|
|
262
|
+
} else {
|
|
263
|
+
const key = this.validator(ctx, value, validate);
|
|
264
|
+
if (!key) {
|
|
265
|
+
if (validate.validator) {
|
|
266
|
+
const res = validate.validator && invoke(() => validate.validator(value, callback));
|
|
267
|
+
if (res && is.Function(res.then)) {
|
|
268
|
+
res.then(() => callback()).catch((e) => callback(e));
|
|
269
|
+
}
|
|
270
|
+
} else {
|
|
271
|
+
callback();
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
let message = '';
|
|
275
|
+
if (typeof validate.error === 'object') {
|
|
276
|
+
message = validate.error[key] || validate.error.default;
|
|
277
|
+
}
|
|
278
|
+
if (!message && typeof validate.message === 'string') {
|
|
279
|
+
message = validate.message;
|
|
280
|
+
}
|
|
281
|
+
if (!message) {
|
|
282
|
+
message = this.getValidateMessage(ctx, {key, rule: validate[key]});
|
|
283
|
+
}
|
|
284
|
+
callback(message);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return this.$manager.adapterValidate({
|
|
289
|
+
required: validate.required,
|
|
290
|
+
message: validate.message,
|
|
291
|
+
trigger: validate.trigger,
|
|
292
|
+
}, validator);
|
|
293
|
+
},
|
|
294
|
+
getValidateMessage(ctx, invalid) {
|
|
295
|
+
const formatRule = Array.isArray(invalid.rule) ? invalid.rule.join(',') : ('' + invalid.rule);
|
|
296
|
+
return this.api.t(invalid.key === 'required' ? invalid.key : ('validate.' + invalid.key), {
|
|
297
|
+
[invalid.key]: formatRule,
|
|
298
|
+
title: ctx.refRule?.__$title?.value
|
|
299
|
+
});
|
|
300
|
+
},
|
|
301
|
+
validator(ctx, value, validate) {
|
|
302
|
+
const isEmpty = is.empty(value);
|
|
303
|
+
if (isEmpty) {
|
|
304
|
+
if (validate.required) {
|
|
305
|
+
return 'required'
|
|
306
|
+
}
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
for (const [key, rule] of Object.entries(validate)) {
|
|
310
|
+
switch (key) {
|
|
311
|
+
case 'len':
|
|
312
|
+
case 'maxLen':
|
|
313
|
+
case 'minLen':
|
|
314
|
+
const check = (val) => {
|
|
315
|
+
if (key === 'len') {
|
|
316
|
+
return val === rule;
|
|
317
|
+
} else if (key === 'maxLen') {
|
|
318
|
+
return val <= rule;
|
|
319
|
+
} else {
|
|
320
|
+
return val >= rule;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (Array.isArray(value)) {
|
|
324
|
+
if (!check(value.length)) {
|
|
325
|
+
return key;
|
|
326
|
+
}
|
|
327
|
+
} else if (typeof value === 'object') {
|
|
328
|
+
return key;
|
|
329
|
+
} else if (!check(('' + value).length)) {
|
|
330
|
+
return key;
|
|
331
|
+
}
|
|
332
|
+
break;
|
|
333
|
+
case 'pattern':
|
|
334
|
+
const reg = typeof rule === 'string' ? new RegExp(rule) : rule;
|
|
335
|
+
if (!reg.test('' + value)) {
|
|
336
|
+
return key;
|
|
337
|
+
}
|
|
338
|
+
break;
|
|
339
|
+
case 'uppercase':
|
|
340
|
+
if (rule && (typeof value !== 'string' || !/^[A-Z]*$/.test(value))) {
|
|
341
|
+
return key;
|
|
342
|
+
}
|
|
343
|
+
break;
|
|
344
|
+
case 'lowercase':
|
|
345
|
+
if (rule && (typeof value !== 'string' || !/^[a-z]*$/.test(value))) {
|
|
346
|
+
return key;
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
case 'min':
|
|
350
|
+
case 'max':
|
|
351
|
+
case 'positive':
|
|
352
|
+
case 'negative':
|
|
353
|
+
case 'integer':
|
|
354
|
+
case 'number':
|
|
355
|
+
const num = Number(value);
|
|
356
|
+
if (Number.isNaN(num)) {
|
|
357
|
+
return key;
|
|
358
|
+
}
|
|
359
|
+
if (key === 'min' && num < rule) {
|
|
360
|
+
return key;
|
|
361
|
+
}
|
|
362
|
+
if (key === 'max' && num > rule) {
|
|
363
|
+
return key;
|
|
364
|
+
}
|
|
365
|
+
if (key === 'positive' && num <= 0) {
|
|
366
|
+
return key;
|
|
367
|
+
}
|
|
368
|
+
if (key === 'negative' && num >= 0) {
|
|
369
|
+
return key;
|
|
370
|
+
}
|
|
371
|
+
if (key === 'integer' && !Number.isInteger(num)) {
|
|
372
|
+
return key;
|
|
373
|
+
}
|
|
374
|
+
break;
|
|
375
|
+
case 'equal':
|
|
376
|
+
if (value !== rule) {
|
|
377
|
+
return key;
|
|
378
|
+
}
|
|
379
|
+
break;
|
|
380
|
+
case 'enum':
|
|
381
|
+
if (Array.isArray(rule) && !rule.includes(value)) {
|
|
382
|
+
return key;
|
|
383
|
+
}
|
|
384
|
+
break;
|
|
385
|
+
case 'hasKeys':
|
|
386
|
+
if (typeof value !== 'object' || Array.isArray(rule) && rule.some(key => !(key in value))) {
|
|
387
|
+
return key;
|
|
388
|
+
}
|
|
389
|
+
break;
|
|
390
|
+
case 'email':
|
|
391
|
+
const regexEmail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
392
|
+
if (!regexEmail.test('' + value)) {
|
|
393
|
+
return key;
|
|
394
|
+
}
|
|
395
|
+
break;
|
|
396
|
+
case 'url':
|
|
397
|
+
const regexUrl = new RegExp(
|
|
398
|
+
'^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
|
|
399
|
+
'i'
|
|
400
|
+
);
|
|
401
|
+
if (!regexUrl.test('' + value)) {
|
|
402
|
+
return key;
|
|
403
|
+
}
|
|
404
|
+
break;
|
|
405
|
+
case 'ip':
|
|
406
|
+
const regexIp =
|
|
407
|
+
/^(2(5[0-5]{1}|[0-4]\d{1})|[0-1]?\d{1,2})(\.(2(5[0-5]{1}|[0-4]\d{1})|[0-1]?\d{1,2})){3}$/;
|
|
408
|
+
if (!regexIp.test('' + value)) {
|
|
409
|
+
return key;
|
|
410
|
+
}
|
|
411
|
+
break;
|
|
412
|
+
case 'phone':
|
|
413
|
+
const regexPhone = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
|
|
414
|
+
if (!regexPhone.test('' + value)) {
|
|
415
|
+
return key;
|
|
416
|
+
}
|
|
417
|
+
break;
|
|
418
|
+
case 'computed':
|
|
419
|
+
if (!this.compute(ctx, rule)) {
|
|
420
|
+
return key;
|
|
421
|
+
}
|
|
422
|
+
break;
|
|
423
|
+
default:
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
compute(ctx, item) {
|
|
429
|
+
let fn;
|
|
430
|
+
if (typeof item === 'object') {
|
|
431
|
+
const group = ctx.getParentGroup();
|
|
432
|
+
const checkCondition = (item) => {
|
|
433
|
+
item = Array.isArray(item) ? {mode: 'AND', group: item} : item;
|
|
434
|
+
if (!is.trueArray(item.group)) {
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
const or = item.mode === 'OR';
|
|
438
|
+
let valid = true;
|
|
439
|
+
for (let i = 0; i < item.group.length; i++) {
|
|
440
|
+
const one = item.group[i];
|
|
441
|
+
let flag;
|
|
442
|
+
let field = null;
|
|
443
|
+
let variableVal = null;
|
|
444
|
+
if (one.variable) {
|
|
445
|
+
variableVal = this.fc.getLoadData(one.variable);
|
|
446
|
+
} else if (one.field) {
|
|
447
|
+
field = convertFieldToConditions(one.field || '');
|
|
448
|
+
} else if (!one.mode) {
|
|
449
|
+
return true;
|
|
450
|
+
}
|
|
451
|
+
let compare = one.compare;
|
|
452
|
+
if (compare) {
|
|
453
|
+
compare = convertFieldToConditions(compare || '');
|
|
454
|
+
}
|
|
455
|
+
if (one.mode) {
|
|
456
|
+
flag = checkCondition(one);
|
|
457
|
+
} else if (!condition[one.condition]) {
|
|
458
|
+
flag = false;
|
|
459
|
+
} else if (is.Function(one.handler)) {
|
|
460
|
+
flag = invoke(() => one.handler(this.api, ctx.rule));
|
|
461
|
+
} else {
|
|
462
|
+
flag = invoke(() => (new Function('$condition', '$variableVal', '$val', '$form', '$scope', '$group', '$rule', `with($form){with($scope){with(this){with($group){ return $condition['${one.condition}'](${one.variable ? '$variableVal' : field}, ${compare ? compare : '$val'}); }}}}`)).call(this.api.form, condition, variableVal, one.value, this.api.top.form, this.api.top === this.api.scope ? {} : this.api.scope.form, group ? (this.subRuleData[group.id] || {}) : {}, ctx.rule));
|
|
463
|
+
}
|
|
464
|
+
if (or && flag) {
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
if (!or) {
|
|
468
|
+
valid = valid && flag;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return or ? false : valid;
|
|
472
|
+
}
|
|
473
|
+
let val = checkCondition(item);
|
|
474
|
+
val = item.invert === true ? !val : val;
|
|
475
|
+
if (item.linkage) {
|
|
476
|
+
return val ? invoke(() => this.computeValue(item.linkage, ctx, group), undefined) : oldValueTag;
|
|
477
|
+
} else if(item.linkageVariable) {
|
|
478
|
+
return val ? invoke(() => this.fc.getLoadData(item.linkageVariable), undefined) : oldValueTag;
|
|
479
|
+
}
|
|
480
|
+
return val;
|
|
481
|
+
} else if (is.Function(item)) {
|
|
482
|
+
fn = () => item(this.api.form, this.api, ctx.rule);
|
|
483
|
+
} else {
|
|
484
|
+
const group = ctx.getParentGroup();
|
|
485
|
+
fn = () => this.computeValue(item, ctx, group);
|
|
486
|
+
}
|
|
487
|
+
return invoke(fn, undefined);
|
|
488
|
+
},
|
|
489
|
+
computeValue(str, ctx, group) {
|
|
490
|
+
const that = this;
|
|
491
|
+
const formulas = Object.keys(this.fc.formulas).reduce((obj, k) => {
|
|
492
|
+
obj[k] = function (...args) {
|
|
493
|
+
return that.fc.formulas[k].call({
|
|
494
|
+
that: this,
|
|
495
|
+
rule: ctx.rule,
|
|
496
|
+
api: that.api,
|
|
497
|
+
fc: that.fc
|
|
498
|
+
}, ...args);
|
|
499
|
+
}
|
|
500
|
+
return obj;
|
|
501
|
+
}, {})
|
|
502
|
+
return invoke(() => (new Function('$formulas', '$form', '$scope', '$group', '$rule', '$api', `with($form){with($scope){with(this){with($group){with($formulas){ return ${str} }}}}}`)).call(this.api.form, formulas, this.api.top.form, this.api.top === this.api.scope ? {} : this.api.scope.form, group ? (this.subRuleData[group.id] || {}) : {}, ctx.rule, this.api), undefined);
|
|
503
|
+
},
|
|
504
|
+
updateChildren(ctx, n, o) {
|
|
505
|
+
this.deferSyncValue(() => {
|
|
506
|
+
o && o.forEach((child) => {
|
|
507
|
+
if ((n || []).indexOf(child) === -1 && child && !is.String(child) && child.__fc__ && child.__fc__.parent === ctx) {
|
|
508
|
+
this.rmCtx(child.__fc__);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
if (is.trueArray(n)) {
|
|
512
|
+
this.loadChildren(n, ctx);
|
|
513
|
+
this.bus.$emit('update', this.api);
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
},
|
|
517
|
+
rmSub(sub) {
|
|
518
|
+
is.trueArray(sub) && sub.forEach(r => {
|
|
519
|
+
r && r.__fc__ && this.rmCtx(r.__fc__);
|
|
520
|
+
})
|
|
521
|
+
},
|
|
522
|
+
rmCtx(ctx) {
|
|
523
|
+
if (ctx.deleted) return;
|
|
524
|
+
const {id, field, input, name} = ctx;
|
|
525
|
+
|
|
526
|
+
$del(this.ctxs, id);
|
|
527
|
+
$del(this.formData, id);
|
|
528
|
+
$del(this.subForm, id);
|
|
529
|
+
$del(this.vm.setupState.ctxInject, id);
|
|
530
|
+
const group = ctx.getParentGroup();
|
|
531
|
+
if (group && this.subRuleData[group.id]) {
|
|
532
|
+
$del(this.subRuleData[group.id], field);
|
|
533
|
+
}
|
|
534
|
+
if (ctx.group) {
|
|
535
|
+
$del(this.subRuleData, id);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
input && this.rmIdCtx(ctx, field, 'field');
|
|
539
|
+
name && this.rmIdCtx(ctx, name, 'name');
|
|
540
|
+
|
|
541
|
+
if (input && !hasProperty(this.fieldCtx, field)) {
|
|
542
|
+
$del(this.form, field);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
this.deferSyncValue(() => {
|
|
546
|
+
if (!this.reloading) {
|
|
547
|
+
if (ctx.parser.loadChildren !== false) {
|
|
548
|
+
const children = ctx.getPending('children', ctx.rule.children);
|
|
549
|
+
if (is.trueArray(children)) {
|
|
550
|
+
children.forEach(h => h && h.__fc__ && this.rmCtx(h.__fc__));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (ctx.root === this.rules) {
|
|
554
|
+
this.vm.setupState.renderRule();
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}, input);
|
|
558
|
+
|
|
559
|
+
const index = this.sort.indexOf(id);
|
|
560
|
+
if (index > -1) {
|
|
561
|
+
this.sort.splice(index, 1);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
this.$render.clearCache(ctx);
|
|
565
|
+
ctx.delete();
|
|
566
|
+
this.effect(ctx, 'deleted');
|
|
567
|
+
this.targetHook(ctx, 'deleted');
|
|
568
|
+
input && !this.fieldCtx[field] && this.vm.emit('remove-field', field, ctx.rule, this.api);
|
|
569
|
+
ctx.rule.__ctrl || this.vm.emit('remove-rule', ctx.rule, this.api);
|
|
570
|
+
return ctx;
|
|
571
|
+
},
|
|
572
|
+
})
|
|
573
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import extend from '../../../utils/lib/extend';
|
|
2
|
+
import is, {hasProperty} from '../../../utils/lib/type';
|
|
3
|
+
import {mergeRule} from '../frame/util';
|
|
4
|
+
import {watch} from 'vue';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export default function useEffect(Handler) {
|
|
8
|
+
extend(Handler.prototype, {
|
|
9
|
+
useProvider() {
|
|
10
|
+
const ps = this.fc.providers;
|
|
11
|
+
Object.keys(ps).forEach(k => {
|
|
12
|
+
let prop = ps[k];
|
|
13
|
+
if (is.Function(prop)) {
|
|
14
|
+
prop = prop(this.fc);
|
|
15
|
+
}
|
|
16
|
+
prop._c = getComponent(prop);
|
|
17
|
+
this.onEffect(prop, k);
|
|
18
|
+
this.providers[k] = prop;
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
onEffect(provider, key) {
|
|
22
|
+
const used = [];
|
|
23
|
+
(provider._c || ['*']).forEach(name => {
|
|
24
|
+
const type = name === '*' ? '*' : this.getType(name);
|
|
25
|
+
if (used.indexOf(type) > -1) return;
|
|
26
|
+
used.push(type);
|
|
27
|
+
this.bus.$on(`p:${key || provider.name}:${type}:${provider.input ? 1 : 0}`, (event, args) => {
|
|
28
|
+
provider[event] && provider[event](...args);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
provider._used = used;
|
|
32
|
+
},
|
|
33
|
+
watchEffect(ctx) {
|
|
34
|
+
let effect = {
|
|
35
|
+
required: () => {
|
|
36
|
+
return (hasProperty(ctx.rule, '$required') ? ctx.rule['$required'] : ctx.rule?.effect?.required) || false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
Object.keys(ctx.rule.effect || {}).forEach(k => {
|
|
40
|
+
effect[k] = () => ctx.rule.effect[k];
|
|
41
|
+
})
|
|
42
|
+
Object.keys(ctx.rule).forEach(k => {
|
|
43
|
+
if (k[0] === '$') {
|
|
44
|
+
effect[k.substr(1)] = () => ctx.rule[k];
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
Object.keys(effect).forEach(k => {
|
|
48
|
+
ctx.watch.push(watch(effect[k], (n) => {
|
|
49
|
+
this.effect(ctx, 'watch', {[k]: n});
|
|
50
|
+
}, {deep: true}));
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
ruleEffect(rule, event, append) {
|
|
54
|
+
this.emitEffect({
|
|
55
|
+
rule,
|
|
56
|
+
input: !!rule.field,
|
|
57
|
+
type: this.getType(rule.type)
|
|
58
|
+
}, event, append);
|
|
59
|
+
},
|
|
60
|
+
effect(ctx, event, custom) {
|
|
61
|
+
this.emitEffect({
|
|
62
|
+
rule: ctx.rule,
|
|
63
|
+
input: ctx.input,
|
|
64
|
+
type: ctx.trueType,
|
|
65
|
+
ctx,
|
|
66
|
+
custom
|
|
67
|
+
}, event);
|
|
68
|
+
},
|
|
69
|
+
getEffect(rule, name) {
|
|
70
|
+
if (hasProperty(rule, '$' + name)) {
|
|
71
|
+
return rule['$' + name];
|
|
72
|
+
}
|
|
73
|
+
if (hasProperty(rule, 'effect') && hasProperty(rule.effect, name))
|
|
74
|
+
return rule.effect[name];
|
|
75
|
+
return undefined;
|
|
76
|
+
},
|
|
77
|
+
emitEffect({ctx, rule, input, type, custom}, event, append) {
|
|
78
|
+
if (!type || ['fcFragment', 'fragment'].indexOf(type) > -1) return;
|
|
79
|
+
const effect = custom ? custom : (Object.keys(rule).reduce((i, k) => {
|
|
80
|
+
if (k[0] === '$') {
|
|
81
|
+
i[k.substr(1)] = rule[k];
|
|
82
|
+
}
|
|
83
|
+
return i;
|
|
84
|
+
}, {...rule.effect || {}}));
|
|
85
|
+
Object.keys(effect).forEach(attr => {
|
|
86
|
+
const p = this.providers[attr];
|
|
87
|
+
if (!p || (p.input && !input)) return;
|
|
88
|
+
let _type;
|
|
89
|
+
if (!p._c) {
|
|
90
|
+
_type = '*';
|
|
91
|
+
} else if (p._used.indexOf(type) > -1) {
|
|
92
|
+
_type = type;
|
|
93
|
+
} else {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const data = {value: effect[attr], getValue: () => this.getEffect(rule, attr), ...(append || {})};
|
|
97
|
+
if (ctx) {
|
|
98
|
+
data.getProp = () => ctx.effectData(attr);
|
|
99
|
+
data.clearProp = () => ctx.clearEffectData(attr);
|
|
100
|
+
data.mergeProp = (prop) => mergeRule(data.getProp(), [prop]);
|
|
101
|
+
data.id = ctx.id;
|
|
102
|
+
}
|
|
103
|
+
this.bus.$emit(`p:${attr}:${_type}:${p.input ? 1 : 0}`, event, [data, rule, this.api]);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function unique(arr) {
|
|
110
|
+
return arr.filter(function (item, index, arr) {
|
|
111
|
+
return arr.indexOf(item, 0) === index;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getComponent(p) {
|
|
116
|
+
const c = p.components;
|
|
117
|
+
if (Array.isArray(c)) {
|
|
118
|
+
const arr = unique(c.filter(v => v !== '*'));
|
|
119
|
+
return arr.length ? arr : false;
|
|
120
|
+
} else if (is.String(c)) return [c];
|
|
121
|
+
else return false;
|
|
122
|
+
}
|