icarys-form-create-vant 1.0.2 → 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.
- package/README.md +3 -3
- package/dist/index.js +3 -3
- package/dist/index.min.js +3 -3
- package/package.json +8 -5
- package/src/components/common/subform/LICENSE +21 -0
- package/src/components/common/subform/README.md +6 -0
- package/src/components/common/subform/package.json +48 -0
- package/src/components/common/subform/src/component.jsx +75 -0
- package/src/components/common/subform/src/index.js +3 -0
- package/src/components/common/wangeditor/LICENSE +21 -0
- package/src/components/common/wangeditor/README.md +14 -0
- package/src/components/common/wangeditor/package-lock.json +114 -0
- package/src/components/common/wangeditor/package.json +52 -0
- package/src/components/common/wangeditor/src/component.jsx +74 -0
- package/src/components/common/wangeditor/src/index.js +3 -0
- package/src/core/LICENSE +21 -0
- package/src/core/README.md +120 -0
- package/src/core/babel.config.js +13 -0
- package/src/core/bili.config.js +34 -0
- package/src/core/package-lock.json +13 -0
- package/src/core/package.json +61 -0
- package/src/core/src/components/formCreate.js +287 -0
- package/src/core/src/components/fragment.js +12 -0
- package/src/core/src/factory/context.js +264 -0
- package/src/core/src/factory/creator.js +63 -0
- package/src/core/src/factory/maker.js +17 -0
- package/src/core/src/factory/manager.js +87 -0
- package/src/core/src/factory/node.js +89 -0
- package/src/core/src/factory/parser.js +28 -0
- package/src/core/src/frame/api.js +691 -0
- package/src/core/src/frame/attrs.js +12 -0
- package/src/core/src/frame/dataDriver.js +76 -0
- package/src/core/src/frame/fetch.js +128 -0
- package/src/core/src/frame/index.js +792 -0
- package/src/core/src/frame/language.js +50 -0
- package/src/core/src/frame/provider.js +297 -0
- package/src/core/src/frame/util.js +311 -0
- package/src/core/src/handler/context.js +573 -0
- package/src/core/src/handler/effect.js +122 -0
- package/src/core/src/handler/index.js +143 -0
- package/src/core/src/handler/inject.js +199 -0
- package/src/core/src/handler/input.js +199 -0
- package/src/core/src/handler/lifecycle.js +55 -0
- package/src/core/src/handler/loader.js +375 -0
- package/src/core/src/handler/page.js +46 -0
- package/src/core/src/handler/render.js +29 -0
- package/src/core/src/index.js +12 -0
- package/src/core/src/parser/html.js +17 -0
- package/src/core/src/render/cache.js +47 -0
- package/src/core/src/render/index.js +33 -0
- package/src/core/src/render/render.js +418 -0
- package/src/core/types/index.d.ts +842 -0
- package/src/index.js +5 -0
- package/src/utils/LICENSE +21 -0
- package/src/utils/README.md +24 -0
- package/src/utils/lib/console.js +16 -0
- package/src/utils/lib/debounce.js +9 -0
- package/src/utils/lib/deepextend.js +51 -0
- package/src/utils/lib/deepset.js +14 -0
- package/src/utils/lib/extend.js +20 -0
- package/src/utils/lib/index.js +14 -0
- package/src/utils/lib/json.js +90 -0
- package/src/utils/lib/mergeprops.js +62 -0
- package/src/utils/lib/mitt.js +43 -0
- package/src/utils/lib/modify.js +8 -0
- package/src/utils/lib/slot.js +8 -0
- package/src/utils/lib/toarray.js +5 -0
- package/src/utils/lib/tocase.js +11 -0
- package/src/utils/lib/todate.js +10 -0
- package/src/utils/lib/toline.js +10 -0
- package/src/utils/lib/topromise.js +10 -0
- package/src/utils/lib/tostring.js +7 -0
- package/src/utils/lib/type.js +45 -0
- package/src/utils/lib/unique.js +6 -0
- package/src/utils/package.json +32 -0
- package/src/vant/LICENSE +21 -0
- package/src/vant/README.md +137 -0
- package/src/vant/auto-import.d.ts +5 -0
- package/src/vant/auto-import.js +50 -0
- package/src/vant/babel.config.js +10 -0
- package/src/vant/bili.config.js +40 -0
- package/src/vant/examples/App.vue +96 -0
- package/src/vant/examples/main.js +13 -0
- package/src/vant/examples/rule.js +366 -0
- package/src/vant/package-lock.json +11367 -0
- package/src/vant/package.json +83 -0
- package/src/vant/public/index.html +14 -0
- package/src/vant/src/components/calendar.jsx +128 -0
- package/src/vant/src/components/cascader.jsx +120 -0
- package/src/vant/src/components/checkbox.jsx +38 -0
- package/src/vant/src/components/datePicker.jsx +87 -0
- package/src/vant/src/components/group.jsx +384 -0
- package/src/vant/src/components/icon/IconWarning.vue +12 -0
- package/src/vant/src/components/index.js +26 -0
- package/src/vant/src/components/radio.jsx +38 -0
- package/src/vant/src/components/select.jsx +81 -0
- package/src/vant/src/components/timePicker.jsx +76 -0
- package/src/vant/src/components/uploader.jsx +99 -0
- package/src/vant/src/core/alias.js +31 -0
- package/src/vant/src/core/api.js +135 -0
- package/src/vant/src/core/config.js +35 -0
- package/src/vant/src/core/index.js +45 -0
- package/src/vant/src/core/manager.js +282 -0
- package/src/vant/src/core/provider.js +63 -0
- package/src/vant/src/core/utils.js +15 -0
- package/src/vant/src/index.js +13 -0
- package/src/vant/src/parsers/hidden.js +12 -0
- package/src/vant/src/parsers/index.js +59 -0
- package/src/vant/src/parsers/row.js +10 -0
- package/src/vant/src/style/index.css +495 -0
- package/src/vant/types/config.d.ts +99 -0
- package/src/vant/types/index.d.ts +27 -0
- package/src/vant/vue.config.js +21 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const {join} = require('path');
|
|
2
|
+
const {author, license, name, version} = require('./package.json');
|
|
3
|
+
const cwd = __dirname;
|
|
4
|
+
|
|
5
|
+
const {UI_LIB} = process.env;
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
plugins: {
|
|
9
|
+
commonjs: true,
|
|
10
|
+
},
|
|
11
|
+
banner: {
|
|
12
|
+
author: `2018-${new Date().getFullYear()} ${author}\n * Github https://github.com/xaboy/form-create`,
|
|
13
|
+
license,
|
|
14
|
+
name,
|
|
15
|
+
version
|
|
16
|
+
},
|
|
17
|
+
globals: {
|
|
18
|
+
vue: 'Vue'
|
|
19
|
+
},
|
|
20
|
+
externals: ['vue', 'Vue'],
|
|
21
|
+
output: {
|
|
22
|
+
format: ['esm','esm-min'],
|
|
23
|
+
moduleName: 'formCreateFactory',
|
|
24
|
+
fileName: 'index[min].js',
|
|
25
|
+
target: 'browser',
|
|
26
|
+
extractCSS: false,
|
|
27
|
+
},
|
|
28
|
+
input: join(cwd, '/src/index.js'),
|
|
29
|
+
env: {
|
|
30
|
+
'NODE_ENV': 'production',
|
|
31
|
+
'VERSION': version,
|
|
32
|
+
'UI': UI_LIB,
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@form-create/core",
|
|
3
|
+
"version": "3.2.37",
|
|
4
|
+
"lockfileVersion": 1,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"mitt": {
|
|
8
|
+
"version": "2.1.0",
|
|
9
|
+
"resolved": "https://registry.npmjs.org/mitt/-/mitt-2.1.0.tgz",
|
|
10
|
+
"integrity": "sha512-ILj2TpLiysu2wkBbWjAmww7TkZb65aiQO+DkVdUTBpBXq+MHYiETENkKFMtsJZX1Lf4pe4QOrTSjIfUwN5lRdg=="
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@form-create/core",
|
|
3
|
+
"version": "3.2.37",
|
|
4
|
+
"description": "FormCreate低代码表单渲染引擎,可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。",
|
|
5
|
+
"main": "./dist/index.min.js",
|
|
6
|
+
"module": "./dist/index.esm.js",
|
|
7
|
+
"unpkg": "./dist/form-create.min.js",
|
|
8
|
+
"jsdelivr": "./dist/form-create.min.js",
|
|
9
|
+
"typings": "./types/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"clean": "rimraf dist/",
|
|
12
|
+
"bili": "cross-env UI_LIB=core bili",
|
|
13
|
+
"build": "npm-run-all clean bili"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/xaboy/form-create.git"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"动态表单",
|
|
21
|
+
"@form-create",
|
|
22
|
+
"form-builder",
|
|
23
|
+
"form",
|
|
24
|
+
"components",
|
|
25
|
+
"vue3",
|
|
26
|
+
"json-form",
|
|
27
|
+
"dynamic-form"
|
|
28
|
+
],
|
|
29
|
+
"files": [
|
|
30
|
+
"README.md",
|
|
31
|
+
"package.json",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"src",
|
|
34
|
+
"types",
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"author": "xaboy",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/xaboy/form-create/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "http://www.form-create.com/v3/",
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"vue": "^3.1.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@form-create/utils": "^3.2.31"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"buildFormCreateOptions": {
|
|
53
|
+
"name": "@form-create/core",
|
|
54
|
+
"exportName": "formCreateFactory",
|
|
55
|
+
"fileName": "index",
|
|
56
|
+
"formats": [
|
|
57
|
+
"esm"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "3d024534b3ee103a96da1d3629582c0cdf19d9a8"
|
|
61
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineComponent,
|
|
3
|
+
getCurrentInstance,
|
|
4
|
+
inject,
|
|
5
|
+
markRaw,
|
|
6
|
+
nextTick,
|
|
7
|
+
onBeforeMount,
|
|
8
|
+
onBeforeUnmount,
|
|
9
|
+
onMounted,
|
|
10
|
+
onUpdated,
|
|
11
|
+
provide,
|
|
12
|
+
reactive,
|
|
13
|
+
toRefs,
|
|
14
|
+
watch, watchEffect
|
|
15
|
+
} from 'vue';
|
|
16
|
+
import toArray from '@form-create/utils/lib/toarray';
|
|
17
|
+
import debounce from '@form-create/utils/lib/debounce';
|
|
18
|
+
import toLine from '@form-create/utils/lib/toline';
|
|
19
|
+
import {toJson} from '../frame/util';
|
|
20
|
+
|
|
21
|
+
const getGroupInject = (vm, parent) => {
|
|
22
|
+
if (!vm || vm === parent) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (vm.props.formCreateInject) {
|
|
26
|
+
return vm.props.formCreateInject
|
|
27
|
+
}
|
|
28
|
+
if (vm.parent) {
|
|
29
|
+
return getGroupInject(vm.parent, parent);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default function $FormCreate(FormCreate, components, directives) {
|
|
34
|
+
return defineComponent({
|
|
35
|
+
name: 'FormCreate' + (FormCreate.isMobile ? 'Mobile' : ''),
|
|
36
|
+
components,
|
|
37
|
+
directives,
|
|
38
|
+
props: {
|
|
39
|
+
rule: {
|
|
40
|
+
type: Array,
|
|
41
|
+
required: true,
|
|
42
|
+
default: () => []
|
|
43
|
+
},
|
|
44
|
+
option: {
|
|
45
|
+
type: Object,
|
|
46
|
+
default: () => ({})
|
|
47
|
+
},
|
|
48
|
+
extendOption: Boolean,
|
|
49
|
+
driver: [String, Object],
|
|
50
|
+
modelValue: Object,
|
|
51
|
+
disabled: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: undefined,
|
|
54
|
+
},
|
|
55
|
+
preview: {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
default: undefined,
|
|
58
|
+
},
|
|
59
|
+
index: [String, Number],
|
|
60
|
+
api: Object,
|
|
61
|
+
locale: [String, Object],
|
|
62
|
+
t: Function,
|
|
63
|
+
name: String,
|
|
64
|
+
subForm: {
|
|
65
|
+
type: Boolean,
|
|
66
|
+
default: true
|
|
67
|
+
},
|
|
68
|
+
inFor: Boolean,
|
|
69
|
+
},
|
|
70
|
+
emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'reset', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync', 'reload', 'repeat-field', 'update', 'validate-field-fail', 'validate-fail', 'created'],
|
|
71
|
+
render() {
|
|
72
|
+
return this.fc.render();
|
|
73
|
+
},
|
|
74
|
+
setup(props) {
|
|
75
|
+
const vm = getCurrentInstance();
|
|
76
|
+
provide('parentFC', vm);
|
|
77
|
+
const parent = inject('parentFC', null);
|
|
78
|
+
let top = parent;
|
|
79
|
+
|
|
80
|
+
if (parent) {
|
|
81
|
+
while (top.setupState.parent) {
|
|
82
|
+
top = top.setupState.parent;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
top = vm;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const {rule, modelValue, subForm, inFor} = toRefs(props);
|
|
89
|
+
|
|
90
|
+
const data = reactive({
|
|
91
|
+
ctxInject: {},
|
|
92
|
+
destroyed: false,
|
|
93
|
+
isShow: true,
|
|
94
|
+
unique: 1,
|
|
95
|
+
renderRule: [...rule.value || []],
|
|
96
|
+
updateValue: JSON.stringify(modelValue.value || {}),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const fc = new FormCreate(vm);
|
|
100
|
+
const fapi = fc.api();
|
|
101
|
+
|
|
102
|
+
const isMore = inFor.value;
|
|
103
|
+
|
|
104
|
+
const addSubForm = () => {
|
|
105
|
+
if (parent) {
|
|
106
|
+
const inject = getGroupInject(vm, parent);
|
|
107
|
+
if (inject) {
|
|
108
|
+
let sub;
|
|
109
|
+
if (isMore) {
|
|
110
|
+
sub = toArray(inject.getSubForm());
|
|
111
|
+
sub.push(fapi);
|
|
112
|
+
|
|
113
|
+
} else {
|
|
114
|
+
sub = fapi;
|
|
115
|
+
}
|
|
116
|
+
inject.subForm(sub);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const rmSubForm = () => {
|
|
122
|
+
const inject = getGroupInject(vm, parent);
|
|
123
|
+
if (inject) {
|
|
124
|
+
if (isMore) {
|
|
125
|
+
const sub = toArray(inject.getSubForm());
|
|
126
|
+
const idx = sub.indexOf(fapi);
|
|
127
|
+
if (idx > -1) {
|
|
128
|
+
sub.splice(idx, 1);
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
inject.subForm();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
let styleEl = null;
|
|
137
|
+
|
|
138
|
+
onBeforeMount(() => {
|
|
139
|
+
watchEffect(() => {
|
|
140
|
+
let content = '';
|
|
141
|
+
const globalClass = (props.option && props.option.globalClass) || {};
|
|
142
|
+
Object.keys(globalClass).forEach(k => {
|
|
143
|
+
let subCss = '';
|
|
144
|
+
globalClass[k].style && Object.keys(globalClass[k].style).forEach(key => {
|
|
145
|
+
subCss += toLine(key) + ':' + globalClass[k].style[key] + ';';
|
|
146
|
+
});
|
|
147
|
+
if (globalClass[k].content) {
|
|
148
|
+
subCss += globalClass[k].content + ';';
|
|
149
|
+
}
|
|
150
|
+
if (subCss) {
|
|
151
|
+
content += `.${k}{${subCss}}`;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
if (props.option && props.option.style) {
|
|
155
|
+
content += props.option.style;
|
|
156
|
+
}
|
|
157
|
+
if (!styleEl) {
|
|
158
|
+
styleEl = document.createElement('style');
|
|
159
|
+
styleEl.type = 'text/css';
|
|
160
|
+
document.head.appendChild(styleEl);
|
|
161
|
+
}
|
|
162
|
+
styleEl.innerHTML = content || '';
|
|
163
|
+
})
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const emit$topForm = debounce(() => {
|
|
167
|
+
fc.bus.$emit('$loadData.$topForm');
|
|
168
|
+
}, 100);
|
|
169
|
+
|
|
170
|
+
const emit$scopeForm = debounce(function () {
|
|
171
|
+
fc.bus.$emit('$loadData.$scopeForm');
|
|
172
|
+
}, 100);
|
|
173
|
+
|
|
174
|
+
const emit$form = debounce(() => {
|
|
175
|
+
fc.bus.$emit('$loadData.$form');
|
|
176
|
+
}, 100);
|
|
177
|
+
|
|
178
|
+
const emit$change = (field) => {
|
|
179
|
+
fc.bus.$emit('change-$form.' + field);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
onMounted(() => {
|
|
183
|
+
if (parent) {
|
|
184
|
+
fapi.top.bus.$on('$loadData.$form', emit$topForm);
|
|
185
|
+
fapi.top.bus.$on('change', emit$change);
|
|
186
|
+
}
|
|
187
|
+
if (fapi !== fapi.scope) {
|
|
188
|
+
fapi.scope.bus.$on('$loadData.$scopeForm', emit$scopeForm);
|
|
189
|
+
}
|
|
190
|
+
fc.mounted();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
onBeforeUnmount(() => {
|
|
194
|
+
if (parent) {
|
|
195
|
+
fapi.top.bus.$off('$loadData.$form', emit$topForm);
|
|
196
|
+
fapi.top.bus.$off('change', emit$change);
|
|
197
|
+
}
|
|
198
|
+
if (fapi !== fapi.scope) {
|
|
199
|
+
fapi.scope.bus.$off('$loadData.$scopeForm', emit$scopeForm);
|
|
200
|
+
}
|
|
201
|
+
rmSubForm();
|
|
202
|
+
data.destroyed = true;
|
|
203
|
+
fc.unmount();
|
|
204
|
+
styleEl && (styleEl.parentNode || styleEl.parentElement) && document.head.removeChild(styleEl);
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
onUpdated(() => {
|
|
208
|
+
fc.updated();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
addSubForm();
|
|
212
|
+
|
|
213
|
+
watch(() => props.option, () => {
|
|
214
|
+
fc.initOptions();
|
|
215
|
+
fapi.refresh();
|
|
216
|
+
}, {deep: true, flush: 'sync'});
|
|
217
|
+
|
|
218
|
+
watch(() => [...rule.value], (n) => {
|
|
219
|
+
if (fc.$handle.isBreakWatch() || n.length === data.renderRule.length && n.every(v => data.renderRule.indexOf(v) > -1)) return;
|
|
220
|
+
fc.$handle.updateAppendData();
|
|
221
|
+
fc.$handle.reloadRule(rule.value);
|
|
222
|
+
vm.setupState.renderRule();
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
watch(() => [props.disabled, props.preview], () => {
|
|
226
|
+
fapi.refresh();
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
watch(modelValue, (n) => {
|
|
230
|
+
if (toJson(n || {}) === data.updateValue) return;
|
|
231
|
+
if (fapi.config.forceCoverValue) {
|
|
232
|
+
fapi.coverValue(n || {});
|
|
233
|
+
} else {
|
|
234
|
+
fapi.setValue(n || {});
|
|
235
|
+
}
|
|
236
|
+
}, {deep: true, flush: 'post'});
|
|
237
|
+
|
|
238
|
+
watch(() => props.index, () => {
|
|
239
|
+
fapi.coverValue({});
|
|
240
|
+
fc.$handle.updateAppendData();
|
|
241
|
+
nextTick(() => {
|
|
242
|
+
nextTick(() => {
|
|
243
|
+
fapi.clearValidateState();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
}, {flush: 'sync'});
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
fc: markRaw(fc),
|
|
250
|
+
parent: parent ? markRaw(parent) : parent,
|
|
251
|
+
top: markRaw(top),
|
|
252
|
+
fapi: markRaw(fapi),
|
|
253
|
+
...toRefs(data),
|
|
254
|
+
getGroupInject: () => getGroupInject(vm, parent),
|
|
255
|
+
refresh() {
|
|
256
|
+
++data.unique;
|
|
257
|
+
},
|
|
258
|
+
renderRule() {
|
|
259
|
+
data.renderRule = [...rule.value || []];
|
|
260
|
+
},
|
|
261
|
+
updateValue(value) {
|
|
262
|
+
if (data.destroyed) return;
|
|
263
|
+
const json = toJson(value);
|
|
264
|
+
if (data.updateValue === json) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
data.updateValue = json;
|
|
268
|
+
vm.emit('update:modelValue', value);
|
|
269
|
+
nextTick(() => {
|
|
270
|
+
emit$form();
|
|
271
|
+
if (!parent) {
|
|
272
|
+
emit$topForm();
|
|
273
|
+
emit$scopeForm();
|
|
274
|
+
} else if (!subForm.value) {
|
|
275
|
+
emit$scopeForm();
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
created() {
|
|
282
|
+
const vm = getCurrentInstance();
|
|
283
|
+
vm.emit('update:api', vm.setupState.fapi);
|
|
284
|
+
vm.setupState.fc.init();
|
|
285
|
+
},
|
|
286
|
+
})
|
|
287
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import unique from '@form-create/utils/lib/unique';
|
|
2
|
+
import toCase from '@form-create/utils/lib/tocase';
|
|
3
|
+
import extend from '@form-create/utils/lib/extend';
|
|
4
|
+
import {enumerable, invoke, mergeRule} from '../frame/util';
|
|
5
|
+
import {deepCopy} from '@form-create/utils/lib/deepextend';
|
|
6
|
+
import {markRaw, reactive} from 'vue';
|
|
7
|
+
import is from '@form-create/utils/lib/type';
|
|
8
|
+
import toArray from '@form-create/utils/lib/toarray';
|
|
9
|
+
|
|
10
|
+
function bind(ctx) {
|
|
11
|
+
Object.defineProperties(ctx.origin, {
|
|
12
|
+
__fc__: enumerable(markRaw(ctx), true)
|
|
13
|
+
});
|
|
14
|
+
if(ctx.rule !== ctx.origin) {
|
|
15
|
+
Object.defineProperties(ctx.rule, {
|
|
16
|
+
__fc__: enumerable(markRaw(ctx), true)
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function RuleContext(handle, rule, defaultValue) {
|
|
22
|
+
const id = unique();
|
|
23
|
+
const isInput = !!rule.field;
|
|
24
|
+
extend(this, {
|
|
25
|
+
id,
|
|
26
|
+
ref: id,
|
|
27
|
+
wrapRef: id + 'fi',
|
|
28
|
+
rule,
|
|
29
|
+
origin: rule.__origin__ || rule,
|
|
30
|
+
name: rule.name,
|
|
31
|
+
pending: {},
|
|
32
|
+
none: false,
|
|
33
|
+
watch: [],
|
|
34
|
+
linkOn: [],
|
|
35
|
+
root: [],
|
|
36
|
+
ctrlRule: [],
|
|
37
|
+
children: [],
|
|
38
|
+
parent: null,
|
|
39
|
+
group: rule.subRule ? this : null,
|
|
40
|
+
cacheConfig: null,
|
|
41
|
+
prop: {...rule},
|
|
42
|
+
computed: {},
|
|
43
|
+
payload: {},
|
|
44
|
+
refRule: {},
|
|
45
|
+
input: isInput,
|
|
46
|
+
el: undefined,
|
|
47
|
+
exportEl: undefined,
|
|
48
|
+
defaultValue: isInput ? deepCopy(defaultValue) : undefined,
|
|
49
|
+
field: rule.field || undefined
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
this.updateKey();
|
|
53
|
+
bind(this);
|
|
54
|
+
this.update(handle, true);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
extend(RuleContext.prototype, {
|
|
58
|
+
getParentGroup() {
|
|
59
|
+
let ctx = this.parent;
|
|
60
|
+
while (ctx) {
|
|
61
|
+
if (ctx.group) {
|
|
62
|
+
return ctx;
|
|
63
|
+
}
|
|
64
|
+
ctx = ctx.parent;
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
loadChildrenPending() {
|
|
68
|
+
const children = this.rule.children || [];
|
|
69
|
+
if (Array.isArray(children))
|
|
70
|
+
return children;
|
|
71
|
+
return this.loadPending({
|
|
72
|
+
key: 'children', origin: children, def: [],
|
|
73
|
+
onLoad: (data) => {
|
|
74
|
+
this.$handle && this.$handle.loadChildren(data, this);
|
|
75
|
+
}, onUpdate: (value, oldValue) => {
|
|
76
|
+
if (this.$handle) {
|
|
77
|
+
value === oldValue ? this.$handle.loadChildren(value, this) : this.$handle.updateChildren(this, value, oldValue);
|
|
78
|
+
}
|
|
79
|
+
}, onReload: (value) => {
|
|
80
|
+
if (this.$handle) {
|
|
81
|
+
this.$handle.updateChildren(this, [], value);
|
|
82
|
+
} else {
|
|
83
|
+
delete this.pending.children;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
loadPending(config) {
|
|
89
|
+
const {key, origin, def, onLoad, onReload, onUpdate} = config;
|
|
90
|
+
|
|
91
|
+
if (this.pending[key] && this.pending[key].origin === origin) {
|
|
92
|
+
return this.getPending(key, def);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
delete this.pending[key];
|
|
96
|
+
|
|
97
|
+
let value = origin;
|
|
98
|
+
if (is.Function(origin)) {
|
|
99
|
+
let source = invoke(() => origin({
|
|
100
|
+
rule: this.rule, api: this.$api, update: (data) => {
|
|
101
|
+
const value = data || def;
|
|
102
|
+
const oldValue = this.getPending(key, def);
|
|
103
|
+
this.setPending(key, origin, value);
|
|
104
|
+
onUpdate && onUpdate(value, oldValue);
|
|
105
|
+
}, reload: () => {
|
|
106
|
+
const oldValue = this.getPending(key, def);
|
|
107
|
+
delete this.pending[key];
|
|
108
|
+
onReload && onReload(oldValue);
|
|
109
|
+
this.$api && this.$api.sync(this.rule);
|
|
110
|
+
}
|
|
111
|
+
}));
|
|
112
|
+
if (source && is.Function(source.then)) {
|
|
113
|
+
source.then((data) => {
|
|
114
|
+
const value = data || def;
|
|
115
|
+
this.setPending(key, origin, value);
|
|
116
|
+
onLoad && onLoad(value);
|
|
117
|
+
this.$api && this.$api.sync(this.rule);
|
|
118
|
+
}).catch(e => {
|
|
119
|
+
console.error(e);
|
|
120
|
+
})
|
|
121
|
+
value = def;
|
|
122
|
+
this.setPending(key, origin, value);
|
|
123
|
+
} else {
|
|
124
|
+
value = source || def;
|
|
125
|
+
this.setPending(key, origin, value);
|
|
126
|
+
onLoad && onLoad(value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return value;
|
|
130
|
+
},
|
|
131
|
+
getPending(key, def) {
|
|
132
|
+
return (this.pending[key] && this.pending[key].value) || def;
|
|
133
|
+
},
|
|
134
|
+
setPending(key, origin, value) {
|
|
135
|
+
this.pending[key] = {
|
|
136
|
+
origin,
|
|
137
|
+
value: reactive(value)
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
effectData(name) {
|
|
141
|
+
if (!this.payload[name]) {
|
|
142
|
+
this.payload[name] = {};
|
|
143
|
+
}
|
|
144
|
+
return this.payload[name];
|
|
145
|
+
},
|
|
146
|
+
clearEffectData(name) {
|
|
147
|
+
if (name === undefined) {
|
|
148
|
+
this.payload = {};
|
|
149
|
+
} else {
|
|
150
|
+
delete this.payload[name];
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
updateKey(flag) {
|
|
154
|
+
this.key = unique();
|
|
155
|
+
flag && this.parent && this.parent.updateKey(flag);
|
|
156
|
+
},
|
|
157
|
+
updateType() {
|
|
158
|
+
this.originType = this.rule.type;
|
|
159
|
+
this.type = toCase(this.rule.type);
|
|
160
|
+
this.trueType = this.$handle.getType(this.originType);
|
|
161
|
+
},
|
|
162
|
+
setParser(parser) {
|
|
163
|
+
this.parser = parser;
|
|
164
|
+
parser.init(this);
|
|
165
|
+
},
|
|
166
|
+
initProp() {
|
|
167
|
+
const rule = {...this.rule};
|
|
168
|
+
delete rule.children;
|
|
169
|
+
delete rule.validate;
|
|
170
|
+
this.prop = mergeRule({}, [rule, ...Object.keys(this.payload).map(k => this.payload[k]), this.computed]);
|
|
171
|
+
this.prop.validate = [...this.refRule?.__$validate?.value || [], ...this.prop.validate || []]
|
|
172
|
+
},
|
|
173
|
+
initNone() {
|
|
174
|
+
this.none = !(is.Undef(this.prop.display) || !!this.prop.display)
|
|
175
|
+
},
|
|
176
|
+
hasHidden() {
|
|
177
|
+
return (!!this.rule.hidden) || (this.parent ? this.parent.hasHidden() : false);
|
|
178
|
+
},
|
|
179
|
+
injectValidate() {
|
|
180
|
+
return this.prop.validate;
|
|
181
|
+
},
|
|
182
|
+
check(handle) {
|
|
183
|
+
return this.vm === handle.vm
|
|
184
|
+
},
|
|
185
|
+
unwatch() {
|
|
186
|
+
this.watch.forEach(un => un());
|
|
187
|
+
this.watch = [];
|
|
188
|
+
Object.keys(this.refRule).forEach(key => {
|
|
189
|
+
if (key.indexOf('__$') !== 0) {
|
|
190
|
+
delete this.refRule[key];
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
},
|
|
194
|
+
unlink() {
|
|
195
|
+
this.linkOn.forEach(un => un());
|
|
196
|
+
this.linkOn = [];
|
|
197
|
+
},
|
|
198
|
+
link() {
|
|
199
|
+
this.unlink();
|
|
200
|
+
this.$handle.appendLink(this);
|
|
201
|
+
},
|
|
202
|
+
watchTo() {
|
|
203
|
+
this.$handle.watchCtx(this);
|
|
204
|
+
},
|
|
205
|
+
delete() {
|
|
206
|
+
this.unwatch();
|
|
207
|
+
this.unlink();
|
|
208
|
+
this.rmCtrl();
|
|
209
|
+
if (this.parent) {
|
|
210
|
+
this.parent.children.splice(this.parent.children.indexOf(this) >>> 0, 1);
|
|
211
|
+
}
|
|
212
|
+
extend(this, {
|
|
213
|
+
deleted: true,
|
|
214
|
+
computed: {},
|
|
215
|
+
parent: null,
|
|
216
|
+
children: [],
|
|
217
|
+
cacheConfig: null,
|
|
218
|
+
none: false,
|
|
219
|
+
})
|
|
220
|
+
},
|
|
221
|
+
rmCtrl() {
|
|
222
|
+
this.ctrlRule.forEach(ctrl => ctrl.__fc__ && ctrl.__fc__.rm());
|
|
223
|
+
this.ctrlRule = [];
|
|
224
|
+
},
|
|
225
|
+
rm() {
|
|
226
|
+
const _rm = () => {
|
|
227
|
+
let index = this.root.indexOf(this.origin);
|
|
228
|
+
if (index > -1) {
|
|
229
|
+
this.root.splice(index, 1);
|
|
230
|
+
this.$handle && this.$handle.refresh();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (this.deleted) {
|
|
234
|
+
_rm();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
this.$handle.noWatch(() => {
|
|
238
|
+
this.$handle.deferSyncValue(() => {
|
|
239
|
+
this.rmCtrl();
|
|
240
|
+
_rm();
|
|
241
|
+
this.$handle.rmCtx(this);
|
|
242
|
+
extend(this, {
|
|
243
|
+
root: []
|
|
244
|
+
});
|
|
245
|
+
}, this.input);
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
update(handle, init) {
|
|
249
|
+
extend(this, {
|
|
250
|
+
deleted: false,
|
|
251
|
+
$handle: handle,
|
|
252
|
+
$render: handle.$render,
|
|
253
|
+
$api: handle.api,
|
|
254
|
+
vm: handle.vm,
|
|
255
|
+
vNode: handle.$render.vNode,
|
|
256
|
+
updated: false,
|
|
257
|
+
cacheValue: this.rule.value
|
|
258
|
+
});
|
|
259
|
+
!init && this.unwatch();
|
|
260
|
+
this.watchTo();
|
|
261
|
+
this.link();
|
|
262
|
+
this.updateType();
|
|
263
|
+
}
|
|
264
|
+
})
|