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.
Files changed (101) hide show
  1. package/README.md +87 -278
  2. package/dist/components/common/subform/package.json +48 -0
  3. package/dist/components/common/subform/src/component.jsx +75 -0
  4. package/dist/components/common/subform/src/index.js +3 -0
  5. package/dist/components/common/wangeditor/package-lock.json +114 -0
  6. package/dist/components/common/wangeditor/package.json +52 -0
  7. package/dist/components/common/wangeditor/src/component.jsx +74 -0
  8. package/dist/components/common/wangeditor/src/index.js +3 -0
  9. package/dist/core/babel.config.js +13 -0
  10. package/dist/core/bili.config.js +34 -0
  11. package/dist/core/package-lock.json +13 -0
  12. package/dist/core/package.json +61 -0
  13. package/dist/core/src/components/formCreate.js +287 -0
  14. package/dist/core/src/components/fragment.js +12 -0
  15. package/dist/core/src/factory/context.js +264 -0
  16. package/dist/core/src/factory/creator.js +63 -0
  17. package/dist/core/src/factory/maker.js +17 -0
  18. package/dist/core/src/factory/manager.js +87 -0
  19. package/dist/core/src/factory/node.js +89 -0
  20. package/dist/core/src/factory/parser.js +28 -0
  21. package/dist/core/src/frame/api.js +691 -0
  22. package/dist/core/src/frame/attrs.js +12 -0
  23. package/dist/core/src/frame/dataDriver.js +76 -0
  24. package/dist/core/src/frame/fetch.js +128 -0
  25. package/dist/core/src/frame/index.js +792 -0
  26. package/dist/core/src/frame/language.js +50 -0
  27. package/dist/core/src/frame/provider.js +297 -0
  28. package/dist/core/src/frame/util.js +311 -0
  29. package/dist/core/src/handler/context.js +573 -0
  30. package/dist/core/src/handler/effect.js +122 -0
  31. package/dist/core/src/handler/index.js +143 -0
  32. package/dist/core/src/handler/inject.js +199 -0
  33. package/dist/core/src/handler/input.js +199 -0
  34. package/dist/core/src/handler/lifecycle.js +55 -0
  35. package/dist/core/src/handler/loader.js +375 -0
  36. package/dist/core/src/handler/page.js +46 -0
  37. package/dist/core/src/handler/render.js +29 -0
  38. package/dist/core/src/index.js +12 -0
  39. package/dist/core/src/parser/html.js +17 -0
  40. package/dist/core/src/render/cache.js +47 -0
  41. package/dist/core/src/render/index.js +33 -0
  42. package/dist/core/src/render/render.js +418 -0
  43. package/dist/core/types/index.d.ts +842 -0
  44. package/dist/icarys-fc-vant.umd.js +17 -0
  45. package/dist/index.d.ts +27 -0
  46. package/dist/index.esm.js +39 -0
  47. package/dist/index.js +46 -0
  48. package/dist/utils/lib/console.js +16 -0
  49. package/dist/utils/lib/debounce.js +9 -0
  50. package/dist/utils/lib/deepextend.js +51 -0
  51. package/dist/utils/lib/deepset.js +14 -0
  52. package/dist/utils/lib/extend.js +20 -0
  53. package/dist/utils/lib/index.js +14 -0
  54. package/dist/utils/lib/json.js +90 -0
  55. package/dist/utils/lib/mergeprops.js +62 -0
  56. package/dist/utils/lib/mitt.js +43 -0
  57. package/dist/utils/lib/modify.js +8 -0
  58. package/dist/utils/lib/slot.js +8 -0
  59. package/dist/utils/lib/toarray.js +5 -0
  60. package/dist/utils/lib/tocase.js +11 -0
  61. package/dist/utils/lib/todate.js +10 -0
  62. package/dist/utils/lib/toline.js +10 -0
  63. package/dist/utils/lib/topromise.js +10 -0
  64. package/dist/utils/lib/tostring.js +7 -0
  65. package/dist/utils/lib/type.js +45 -0
  66. package/dist/utils/lib/unique.js +6 -0
  67. package/dist/utils/package.json +32 -0
  68. package/dist/vant/auto-import.d.ts +5 -0
  69. package/dist/vant/auto-import.js +50 -0
  70. package/dist/vant/babel.config.js +10 -0
  71. package/dist/vant/bili.config.js +40 -0
  72. package/dist/vant/examples/main.js +13 -0
  73. package/dist/vant/examples/rule.js +366 -0
  74. package/dist/vant/package.json +83 -0
  75. package/dist/vant/src/components/calendar.jsx +128 -0
  76. package/dist/vant/src/components/cascader.jsx +120 -0
  77. package/dist/vant/src/components/checkbox.jsx +38 -0
  78. package/dist/vant/src/components/datePicker.jsx +87 -0
  79. package/dist/vant/src/components/group.jsx +384 -0
  80. package/dist/vant/src/components/index.js +26 -0
  81. package/dist/vant/src/components/radio.jsx +38 -0
  82. package/dist/vant/src/components/select.jsx +81 -0
  83. package/dist/vant/src/components/timePicker.jsx +76 -0
  84. package/dist/vant/src/components/uploader.jsx +99 -0
  85. package/dist/vant/src/core/alias.js +31 -0
  86. package/dist/vant/src/core/api.js +135 -0
  87. package/dist/vant/src/core/config.js +35 -0
  88. package/dist/vant/src/core/index.js +45 -0
  89. package/dist/vant/src/core/manager.js +282 -0
  90. package/dist/vant/src/core/provider.js +63 -0
  91. package/dist/vant/src/core/utils.js +15 -0
  92. package/dist/vant/src/index.js +13 -0
  93. package/dist/vant/src/parsers/hidden.js +12 -0
  94. package/dist/vant/src/parsers/index.js +59 -0
  95. package/dist/vant/src/parsers/row.js +10 -0
  96. package/dist/vant/src/style/index.css +495 -0
  97. package/dist/vant/types/config.d.ts +99 -0
  98. package/dist/vant/types/index.d.ts +27 -0
  99. package/dist/vant/vue.config.js +21 -0
  100. package/package.json +29 -52
  101. package/dist/index.min.js +0 -7411
@@ -0,0 +1,143 @@
1
+ import Api from '../frame/api';
2
+ import Render from '../render';
3
+ import extend from '../../../utils/lib/extend';
4
+ import {funcProxy, invoke} from '../frame/util';
5
+ import useInject from './inject';
6
+ import usePage from './page';
7
+ import useRender from './render';
8
+ import useLoader from './loader';
9
+ import useInput from './input';
10
+ import useContext from './context';
11
+ import useLifecycle from './lifecycle';
12
+ import useEffect from './effect';
13
+ import {reactive} from 'vue';
14
+ import is from '../../../utils/lib/type';
15
+ import {deepCopy} from '../../../utils/lib/deepextend';
16
+
17
+
18
+ export default function Handler(fc) {
19
+ funcProxy(this, {
20
+ options() {
21
+ return fc.options.value || {};
22
+ },
23
+ bus() {
24
+ return fc.bus;
25
+ },
26
+ preview() {
27
+ if (fc.vm.props.preview != null) {
28
+ return fc.vm.props.preview;
29
+ } else if (fc.vm.setupState.parent && fc.vm.setupState.parent.props.preview != null) {
30
+ return fc.vm.setupState.parent.props.preview;
31
+ }
32
+ return fc.options.value.preview || false;
33
+ }
34
+ })
35
+ extend(this, {
36
+ fc,
37
+ vm: fc.vm,
38
+ watching: false,
39
+ loading: false,
40
+ reloading: false,
41
+ noWatchFn: null,
42
+ deferSyncFn: null,
43
+ isMounted: false,
44
+ formData: reactive({}),
45
+ subRuleData: reactive({}),
46
+ subForm: {},
47
+ form: reactive({}),
48
+ appendData: {},
49
+ ignoreFields: [],
50
+ providers: {},
51
+ cycleLoad: null,
52
+ loadedId: 1,
53
+ nextTick: null,
54
+ changeStatus: false,
55
+ pageEnd: true,
56
+ nextReload: () => {
57
+ this.lifecycle('reload');
58
+ }
59
+ });
60
+
61
+ this.initData(fc.rules);
62
+
63
+ this.$manager = new fc.manager(this);
64
+ this.$render = new Render(this);
65
+ this.api = fc.extendApiFn.reduce((api, fn) => {
66
+ const extendApi = invoke(() => fn(api, this));
67
+ if (extendApi && extendApi !== api) {
68
+ extend(api, extendApi);
69
+ }
70
+ return api;
71
+ }, Api(this));
72
+ }
73
+
74
+ extend(Handler.prototype, {
75
+ initData(rules) {
76
+ extend(this, {
77
+ ctxs: {},
78
+ fieldCtx: {},
79
+ nameCtx: {},
80
+ sort: [],
81
+ rules,
82
+ });
83
+ },
84
+ init() {
85
+ this.updateAppendData();
86
+ this.useProvider();
87
+ this.usePage();
88
+ this.loadRule();
89
+ this.$manager.__init();
90
+ this.lifecycle('created');
91
+ },
92
+ updateAppendData() {
93
+ this.appendData = {...deepCopy(this.options.formData || {}), ...(this.fc.vm.props.modelValue || {}), ...this.appendData};
94
+ },
95
+ isBreakWatch() {
96
+ return this.loading || this.noWatchFn || this.reloading;
97
+ },
98
+ globalBeforeFetch(opt) {
99
+ return new Promise((resolve, reject) => {
100
+ const source = this.options.beforeFetch && invoke(() => this.options.beforeFetch(opt, {api: this.api}));
101
+ if (source && is.Function(source.then)) {
102
+ source.then(resolve).catch(reject);
103
+ } else {
104
+ resolve();
105
+ }
106
+ });
107
+ },
108
+ beforeFetch(opt) {
109
+ return new Promise((resolve, reject) => {
110
+ const res = opt && opt.beforeFetch && invoke(() => opt.beforeFetch(opt, {api: this.api}));
111
+ if (res && is.Function(res.then)) {
112
+ res.then(resolve).catch(reject);
113
+ } else if (res === false) {
114
+ reject();
115
+ } else {
116
+ resolve();
117
+ }
118
+ }).then(() => {
119
+ return this.globalBeforeFetch(opt);
120
+ });
121
+ },
122
+ beforeSubmit(formData) {
123
+ return new Promise((resolve, reject) => {
124
+ const res = this.options.beforeSubmit && invoke(() => this.options.beforeSubmit(formData, {api: this.api}));
125
+ if (res && is.Function(res.then)) {
126
+ res.then(resolve).catch(reject);
127
+ } else if (res === false) {
128
+ reject();
129
+ } else {
130
+ resolve();
131
+ }
132
+ });
133
+ }
134
+ })
135
+
136
+ useInject(Handler);
137
+ usePage(Handler);
138
+ useRender(Handler);
139
+ useLoader(Handler);
140
+ useInput(Handler);
141
+ useContext(Handler);
142
+ useLifecycle(Handler);
143
+ useEffect(Handler);
@@ -0,0 +1,199 @@
1
+ import extend from '../../../utils/lib/extend';
2
+ import is, {hasProperty} from '../../../utils/lib/type';
3
+ import toLine from '../../../utils/lib/toline';
4
+ import {deepGet, extractVar, invoke, parseFn, parseTemplateToTree} from '../frame/util';
5
+ import toCase from '../../../utils/lib/tocase';
6
+
7
+
8
+ export default function useInject(Handler) {
9
+ extend(Handler.prototype, {
10
+ parseInjectEvent(rule, on) {
11
+ const inject = rule.inject || this.options.injectEvent;
12
+ return this.parseEventLst(rule, on, inject);
13
+ },
14
+ parseEventLst(rule, data, inject, deep) {
15
+ Object.keys(data).forEach(k => {
16
+ const fn = this.parseEvent(rule, data[k], inject, deep);
17
+ if (fn) {
18
+ data[k] = fn;
19
+ }
20
+ });
21
+ return data;
22
+ },
23
+ parseEvent(rule, fn, inject, deep) {
24
+ if (is.Function(fn) && ((inject !== false && !is.Undef(inject)) || fn.__inject)) {
25
+ return this.inject(rule, fn, inject)
26
+ } else if (!deep && Array.isArray(fn) && fn[0] && (is.String(fn[0]) || is.Function(fn[0]))) {
27
+ return this.parseEventLst(rule, fn, inject, true);
28
+ } else if (is.String(fn)) {
29
+ const val = parseFn(fn);
30
+ if (val && fn !== val) {
31
+ return val.__inject ? this.parseEvent(rule, val, inject, true) : val;
32
+ }
33
+ }
34
+ },
35
+ parseEmit(ctx) {
36
+ let event = {}, rule = ctx.rule, {emitPrefix, field, name, inject} = rule;
37
+ let emit = rule.emit || [];
38
+ if (is.trueArray(emit)) {
39
+ emit.forEach(eventName => {
40
+ if (!eventName) return;
41
+ let eventInject;
42
+ let emitKey = emitPrefix || field || name;
43
+ if (is.Object(eventName)) {
44
+ eventInject = eventName.inject;
45
+ eventName = eventName.name;
46
+ emitKey = eventName.prefix || emitKey;
47
+ }
48
+ if (emitKey) {
49
+ const fieldKey = toLine(`${emitKey}-${eventName}`);
50
+ const fn = (...arg) => {
51
+ if (this.vm.emitsOptions && !this.vm.emitsOptions[fieldKey]) {
52
+ this.vm.emitsOptions[fieldKey] = null;
53
+ }
54
+ this.vm.emit(fieldKey, ...arg);
55
+ this.vm.emit('emit-event', fieldKey, ...arg);
56
+ this.bus.$emit(fieldKey, ...arg);
57
+ };
58
+ fn.__emit = true;
59
+
60
+ if (!eventInject && inject === false) {
61
+ event[toCase(eventName)] = fn;
62
+ } else {
63
+ let _inject = eventInject || inject || this.options.injectEvent;
64
+ event[toCase(eventName)] = is.Undef(_inject) ? fn : this.inject(rule, fn, _inject);
65
+ }
66
+ }
67
+
68
+ });
69
+ }
70
+ ctx.computed.on = event;
71
+ return event;
72
+ },
73
+ getInjectData(self, inject) {
74
+ const $api = self.__fc__ && self.__fc__.$api;
75
+ const vm = (self.__fc__ && self.__fc__.$handle.vm) || this.vm;
76
+ const {option, rule} = vm.props;
77
+ return {
78
+ $f: $api || this.api,
79
+ api: $api || this.api,
80
+ rule,
81
+ self: self.__origin__,
82
+ option,
83
+ inject
84
+ };
85
+ },
86
+ inject(self, _fn, inject) {
87
+ if (_fn.__origin) {
88
+ if (this.watching && !this.loading)
89
+ return _fn;
90
+ _fn = _fn.__origin;
91
+ }
92
+
93
+ const h = this;
94
+
95
+ const fn = function (...args) {
96
+ const data = h.getInjectData(self, inject);
97
+ data.args = [...args];
98
+ args.unshift(data);
99
+ return _fn.apply(this, args);
100
+ };
101
+ fn.__origin = _fn;
102
+ fn.__json = _fn.__json;
103
+ return fn;
104
+ },
105
+ loadStrVar(str, get, group) {
106
+ if (str && typeof str === 'string' && str.indexOf('{{') > -1 && str.indexOf('}}') > -1) {
107
+ const tmp = str;
108
+ const vars = extractVar(str);
109
+
110
+ const getValue = (field) => {
111
+ let flag = false;
112
+ let val;
113
+ if (group && field.indexOf('$form.') === 0) {
114
+ const _split = field.split('.');
115
+ _split.shift();
116
+ if (hasProperty(group.value, _split[0])) {
117
+ flag = true;
118
+ val = get ? get({
119
+ id: '$form.' + _split[0] + '_' + group.rule.__fc__.id,
120
+ getValue: () => {
121
+ return deepGet(group.value, _split);
122
+ }
123
+ }) : deepGet(group.value, _split);
124
+ }
125
+ }
126
+ if (!flag) {
127
+ val = get ? get(field) : this.fc.getLoadData(field)
128
+ }
129
+ return val;
130
+ }
131
+
132
+ const treeToVal = (tree) => {
133
+ const fields = [];
134
+ tree.forEach(item => {
135
+ if (item.key) {
136
+ fields.push(item.key);
137
+ } else if (item.children) {
138
+ fields.push(treeToVal(item.children));
139
+ }
140
+ })
141
+ let flag = false;
142
+ fields.forEach((field, idx) => {
143
+ if (field != null && (field.indexOf('\'') === 0 || field.indexOf('"') === 0)) {
144
+ fields[idx] = field.slice(1, -1)
145
+ flag = true;
146
+ }
147
+ })
148
+ if (fields.length === 1 && (flag || !isNaN(Number(fields[0])))) {
149
+ return fields[0];
150
+ }
151
+ return getValue(fields.join('.'));
152
+ }
153
+
154
+ let lastVal;
155
+ vars.forEach(v => {
156
+ const split = v.split('||');
157
+ const field = split[0].trim();
158
+ if (field) {
159
+ const def = (split[1] || '').trim();
160
+ const tree = parseTemplateToTree(field);
161
+ let val = invoke(() => treeToVal(tree));
162
+ if ((val == null || val === '') && split.length > 1) {
163
+ val = def;
164
+ }
165
+ lastVal = val;
166
+ str = str.replaceAll(`{{${v}}}`, val == null ? '' : val);
167
+ }
168
+ })
169
+ if (vars.length === 1 && tmp === `{{${vars[0]}}}`) {
170
+ return lastVal;
171
+ }
172
+ }
173
+ return str;
174
+ },
175
+ loadFetchVar(options, get, rule) {
176
+ let group;
177
+ if (rule && rule.__fc__) {
178
+ group = rule.__fc__.getParentGroup();
179
+ }
180
+ const loadVal = str => {
181
+ return this.loadStrVar(str, get, group ? {rule, value: (this.subRuleData[group.id] || {})} : null);
182
+ }
183
+
184
+ options.action = loadVal(options.action || '');
185
+
186
+ ['headers', 'data', 'query'].forEach(key => {
187
+ if (options[key]) {
188
+ const data = Array.isArray(options[key]) ? [] : {};
189
+ Object.keys(options[key]).forEach(k => {
190
+ data[loadVal(k)] = loadVal(options[key][k]);
191
+ });
192
+ options[key] = data;
193
+ }
194
+ });
195
+
196
+ return options;
197
+ }
198
+ })
199
+ }
@@ -0,0 +1,199 @@
1
+ import extend from '../../../utils/lib/extend';
2
+ import {$set} from '../../../utils/lib/modify';
3
+ import is, {hasProperty} from '../../../utils/lib/type';
4
+ import {invoke} from '../frame/util';
5
+ import {nextTick, reactive, toRef} from 'vue';
6
+
7
+ export default function useInput(Handler) {
8
+ extend(Handler.prototype, {
9
+ setValue(ctx, value, formValue, setFlag) {
10
+ if (ctx.deleted) return;
11
+ ctx.rule.value = value;
12
+ this.changeStatus = true;
13
+ this.nextRefresh();
14
+ this.$render.clearCache(ctx);
15
+ this.setFormData(ctx, formValue);
16
+ this.syncValue();
17
+ this.valueChange(ctx, value);
18
+ this.vm.emit('change', ctx.field, value, ctx.origin, this.api, setFlag || false);
19
+ this.effect(ctx, 'value');
20
+ this.targetHook(ctx, 'value', {value});
21
+ this.emitEvent('change', ctx.field, value, {
22
+ rule: ctx.origin,
23
+ api: this.api,
24
+ setFlag: setFlag || false
25
+ })
26
+ if (setFlag) {
27
+ nextTick(() => {
28
+ nextTick(() => {
29
+ nextTick(() => {
30
+ this.api.clearValidateState(ctx.id);
31
+ });
32
+ });
33
+ });
34
+ }
35
+ this.$manager.fieldChange(ctx, value, formValue, setFlag);
36
+ },
37
+ onInput(ctx, value) {
38
+ let val;
39
+ if (ctx.input && (this.isQuote(ctx, val = ctx.parser.toValue(value, ctx)) || this.isChange(ctx, value))) {
40
+ this.setValue(ctx, val, value);
41
+ }
42
+ },
43
+ onUpdateValue(ctx, data) {
44
+ this.deferSyncValue(() => {
45
+ const group = ctx.getParentGroup();
46
+ const subForm = group ? this.subRuleData[group.id] : null;
47
+ const subData = {};
48
+ Object.keys(data || {}).forEach(k => {
49
+ if (subForm && hasProperty(subForm, k)) {
50
+ subData[k] = data[k];
51
+ } else if (hasProperty(this.api.form, k)) {
52
+ this.api.form[k] = data[k];
53
+ } else if (this.api.top !== this.api && hasProperty(this.api.top.form, k)) {
54
+ this.api.top.form[k] = data[k];
55
+ }
56
+ });
57
+ if (Object.keys(subData).length) {
58
+ this.api.setChildrenFormData(group.rule, subData);
59
+ }
60
+ })
61
+ },
62
+ onBaseInput(ctx, value) {
63
+ this.setFormData(ctx, value);
64
+ ctx.modelValue = value;
65
+ this.nextRefresh();
66
+ this.$render.clearCache(ctx);
67
+ },
68
+ setFormData(ctx, value) {
69
+ ctx.modelValue = value;
70
+ const group = ctx.getParentGroup();
71
+ if (group) {
72
+ if (!this.subRuleData[group.id]) {
73
+ this.subRuleData[group.id] = {};
74
+ }
75
+ this.subRuleData[group.id][ctx.field] = ctx.rule.value;
76
+ }
77
+ $set(this.formData, ctx.id, value);
78
+ },
79
+ rmSubRuleData(ctx) {
80
+ const group = ctx.getParentGroup();
81
+ if (group && this.subRuleData[group.id]) {
82
+ delete this.subRuleData[group.id][ctx.field];
83
+ }
84
+ },
85
+ getFormData(ctx) {
86
+ return this.formData[ctx.id];
87
+ },
88
+ syncForm() {
89
+ const data = reactive({});
90
+ const fields = this.fields();
91
+ const ignoreFields = [];
92
+ if (this.options.appendValue !== false) {
93
+ Object.keys(this.appendData).reduce((initial, field) => {
94
+ if (fields.indexOf(field) === -1) {
95
+ initial[field] = toRef(this.appendData, field);
96
+ }
97
+ return initial;
98
+ }, data);
99
+ }
100
+ fields.reduce((initial, field) => {
101
+ let ctx = (this.fieldCtx[field] || []).filter(ctx => !this.isIgnore(ctx))[0];
102
+ if (!ctx) {
103
+ ctx = this.fieldCtx[field][0];
104
+ ignoreFields.push(field);
105
+ }
106
+ initial[field] = toRef(ctx.rule, 'value');
107
+ return initial;
108
+ }, data);
109
+ this.form = data;
110
+ this.ignoreFields = ignoreFields;
111
+ this.syncValue();
112
+ },
113
+ isIgnore(ctx) {
114
+ return ctx.rule.ignore === true || ((ctx.rule.ignore === 'hidden' || this.options.ignoreHiddenFields) && ctx.hasHidden());
115
+ },
116
+ appendValue(rule) {
117
+ if ((!rule.field || !hasProperty(this.appendData, rule.field)) && (!is.Undef(rule.value) || !this.options.forceCoverValue)) {
118
+ return;
119
+ }
120
+ rule.value = this.appendData[rule.field];
121
+ delete this.appendData[rule.field];
122
+ },
123
+ addSubForm(ctx, subForm) {
124
+ this.subForm[ctx.id] = subForm;
125
+ },
126
+ deferSyncValue(fn, sync) {
127
+ if (!this.deferSyncFn) {
128
+ this.deferSyncFn = fn;
129
+ }
130
+ if (!this.deferSyncFn.sync) {
131
+ this.deferSyncFn.sync = sync;
132
+ }
133
+ invoke(fn);
134
+ if (this.deferSyncFn === fn) {
135
+ this.deferSyncFn = null;
136
+ if (fn.sync) {
137
+ this.syncForm();
138
+ }
139
+ }
140
+ },
141
+ syncValue() {
142
+ if (this.deferSyncFn) {
143
+ return this.deferSyncFn.sync = true;
144
+ }
145
+ const data = {};
146
+ Object.keys(this.form).forEach(k => {
147
+ if (this.ignoreFields.indexOf(k) === -1) {
148
+ data[k] = this.form[k];
149
+ }
150
+ });
151
+ this.vm.setupState.updateValue(data);
152
+ },
153
+ isChange(ctx, value) {
154
+ return JSON.stringify(this.getFormData(ctx), strFn) !== JSON.stringify(value, strFn);
155
+ },
156
+ isQuote(ctx, value) {
157
+ return (value instanceof Function || is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
158
+ },
159
+ refreshUpdate(ctx, val, origin, field) {
160
+ if (is.Function(ctx.rule.update)) {
161
+ const state = invoke(() => ctx.rule.update(val, ctx.origin, this.api, {
162
+ origin: origin || 'change',
163
+ linkField: field
164
+ }));
165
+ if (state === undefined) return;
166
+ ctx.rule.hidden = state === true;
167
+ }
168
+ },
169
+ valueChange(ctx, val) {
170
+ this.refreshRule(ctx, val);
171
+ this.bus.$emit('change-' + ctx.field, val);
172
+ },
173
+ refreshRule(ctx, val, origin, field) {
174
+ if (this.refreshControl(ctx)) {
175
+ this.$render.clearCacheAll();
176
+ this.loadRule();
177
+ this.bus.$emit('update', this.api);
178
+ this.refresh();
179
+ }
180
+ this.refreshUpdate(ctx, val, origin, field);
181
+ },
182
+ appendLink(ctx) {
183
+ const link = ctx.rule.link;
184
+ is.trueArray(link) && link.forEach(field => {
185
+ const fn = () => this.refreshRule(ctx, ctx.rule.value, 'link', field);
186
+
187
+ this.bus.$on('change-' + field, fn);
188
+ ctx.linkOn.push(() => this.bus.$off('change-' + field, fn));
189
+ });
190
+ },
191
+ fields() {
192
+ return Object.keys(this.fieldCtx);
193
+ },
194
+ });
195
+ }
196
+
197
+ function strFn(key, val) {
198
+ return typeof val === 'function' ? '' + val : val;
199
+ }
@@ -0,0 +1,55 @@
1
+ import extend from '../../../utils/lib/extend';
2
+ import is from '../../../utils/lib/type';
3
+ import {invoke, parseFn} from '../frame/util';
4
+ import toCase from '../../../utils/lib/tocase';
5
+ import {upper} from '../../../utils/lib/toline';
6
+
7
+
8
+ export default function useLifecycle(Handler) {
9
+ extend(Handler.prototype, {
10
+ mounted() {
11
+ const _mounted = () => {
12
+ this.isMounted = true;
13
+ this.lifecycle('mounted');
14
+ }
15
+ if (this.pageEnd) {
16
+ _mounted();
17
+ } else {
18
+ this.bus.$once('page-end', _mounted);
19
+ }
20
+ },
21
+ lifecycle(name) {
22
+ this.fc.targetFormDriver(name, this.api, this.fc);
23
+ this.vm.emit(name, this.api);
24
+ this.emitEvent(name, this.api);
25
+ },
26
+ emitEvent(name, ...args) {
27
+ const _fn = this.options[name] || this.options[toCase('on-' + name)];
28
+ if (_fn) {
29
+ const fn = parseFn(_fn);
30
+ is.Function(fn) && invoke(() => fn(...args));
31
+ }
32
+ this.bus.$emit(name, ...args);
33
+ },
34
+ targetHook(ctx, name, args) {
35
+ let hook = ctx.prop?.hook?.[name];
36
+
37
+ let run = (on, p) => {
38
+ if (on) {
39
+ on = Array.isArray(on) ? on : [on];
40
+ on.forEach(fn => {
41
+ invoke(() => fn({args: Object.values(args || {}), ...args || {}, self: ctx.rule, rule: ctx.rule, parent: p?.rule, $f: this.api, api: this.api, option: this.vm.props.option}));
42
+ });
43
+ }
44
+ }
45
+ run(hook);
46
+ let deepName = 'deep' + upper(name);
47
+ let parent = ctx.parent;
48
+ while (parent) {
49
+ let deepHook = parent.prop?.hook?.[deepName];
50
+ run(deepHook, parent);
51
+ parent = parent.parent;
52
+ }
53
+ }
54
+ })
55
+ }