@form-create/iview 2.5.9

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/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@form-create/iview",
3
+ "version": "2.5.9",
4
+ "description": "iview动态表单|form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON. Supports 3 UI frameworks, and supports the generation of any Vue components. Built-in 20 kinds of commonly used form components and custom components, no matter how complex forms can be easily handled.",
5
+ "main": "./dist/form-create.min.js",
6
+ "module": "./dist/form-create.min.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
+ "dev:iview": "vue-cli-service serve",
13
+ "bili": "cross-env UI_LIB=iview bili",
14
+ "build": "npm-run-all clean bili"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/xaboy/form-create.git"
19
+ },
20
+ "keywords": [
21
+ "动态表单",
22
+ "@form-create",
23
+ "form-builder",
24
+ "form",
25
+ "components",
26
+ "vue.js",
27
+ "iview",
28
+ "json-form",
29
+ "dynamic-form"
30
+ ],
31
+ "files": [
32
+ "README.md",
33
+ "package.json",
34
+ "LICENSE",
35
+ "src",
36
+ "types",
37
+ "dist"
38
+ ],
39
+ "author": "xaboy",
40
+ "license": "MIT",
41
+ "bugs": {
42
+ "url": "https://github.com/xaboy/form-create/issues"
43
+ },
44
+ "homepage": "http://www.form-create.com",
45
+ "dependencies": {
46
+ "@form-create/component-ivu-checkbox": "^2.5.9",
47
+ "@form-create/component-ivu-frame": "^2.5.9",
48
+ "@form-create/component-ivu-group": "^2.5.9",
49
+ "@form-create/component-ivu-radio": "^2.5.9",
50
+ "@form-create/component-ivu-select": "^2.5.9",
51
+ "@form-create/component-ivu-tree": "^2.5.9",
52
+ "@form-create/component-ivu-upload": "^2.5.9",
53
+ "@form-create/component-subform": "^2.5.9",
54
+ "@form-create/core": "^2.5.9",
55
+ "@form-create/utils": "^2.5.9"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "devDependencies": {
61
+ "@form-create/component-wangeditor": "^2.5.5",
62
+ "@vue/cli-plugin-babel": "^4.5.9",
63
+ "@vue/cli-service": "^4.5.3",
64
+ "@vue/composition-api": "^1.0.0-beta.22",
65
+ "iview": "^3.3.3",
66
+ "v-jsoneditor": "^1.4.2"
67
+ },
68
+ "gitHead": "b4e39524136df76ad16c92a3697fdfe94ac296a7"
69
+ }
@@ -0,0 +1,19 @@
1
+ import checkbox from '@form-create/component-ivu-checkbox/src/index';
2
+ import frame from '@form-create/component-ivu-frame/src/index';
3
+ import radio from '@form-create/component-ivu-radio/src/index';
4
+ import select from '@form-create/component-ivu-select/src/index';
5
+ import tree from '@form-create/component-ivu-tree/src/index';
6
+ import upload from '@form-create/component-ivu-upload/src/index';
7
+ import group from '@form-create/component-ivu-group/src/index';
8
+ import subForm from '@form-create/component-subform/src/index';
9
+
10
+ export default [
11
+ checkbox,
12
+ radio,
13
+ select,
14
+ tree,
15
+ subForm,
16
+ frame,
17
+ upload,
18
+ group
19
+ ];
@@ -0,0 +1,27 @@
1
+ export default {
2
+ button: 'iButton',
3
+ icon: 'Icon',
4
+ slider: 'Slider',
5
+ rate: 'Rate',
6
+ upload: 'fcUpload',
7
+ cascader: 'Cascader',
8
+ colorPicker: 'ColorPicker',
9
+ timePicker: 'TimePicker',
10
+ datePicker: 'DatePicker',
11
+ 'switch': 'iSwitch',
12
+ select: 'fcSelect',
13
+ checkbox: 'fcCheckbox',
14
+ radio: 'fcRadio',
15
+ inputNumber: 'InputNumber',
16
+ input: 'iInput',
17
+ formItem: 'FormItem',
18
+ form: 'iForm',
19
+ frame: 'fcFrame',
20
+ col: 'iCol',
21
+ row: 'row',
22
+ tree: 'fcTree',
23
+ autoComplete: 'AutoComplete',
24
+ group: 'fcGroup',
25
+ subForm: 'fcSubForm',
26
+ object: 'fcSubForm',
27
+ }
@@ -0,0 +1,159 @@
1
+ import extend from '@form-create/utils/lib/extend';
2
+ import is from '@form-create/utils/lib/type';
3
+ import {invoke} from '@form-create/core/src/frame/util';
4
+ import toArray from '@form-create/utils/lib/toarray';
5
+
6
+ function tidyBtnProp(btn, def) {
7
+ if (is.Boolean(btn))
8
+ btn = {show: btn};
9
+ else if (!is.Undef(btn) && !is.Object(btn)) btn = {show: def};
10
+ return btn;
11
+ }
12
+
13
+ export default function extendApi(api, h) {
14
+ extend(api, {
15
+ validate(callback) {
16
+ let flag;
17
+ const forms = api.children;
18
+ let len = forms.length;
19
+ const validate = () => {
20
+ h.$manager.validate((...args) => {
21
+ if (!args[0] || !flag) {
22
+ flag = args;
23
+ }
24
+ callback && callback(...flag);
25
+ });
26
+ };
27
+
28
+ const validFn = (args) => {
29
+ setTimeout(() => {
30
+ if (!args[0]) {
31
+ if (!flag) {
32
+ flag = args;
33
+ }
34
+ }
35
+ if (!--len) {
36
+ validate();
37
+ }
38
+ });
39
+ };
40
+
41
+ forms.forEach(form => {
42
+ form.validate((...args) => validFn(args))
43
+ })
44
+
45
+ if (!len) {
46
+ validate();
47
+ }
48
+ },
49
+ validateField: (field, callback) => {
50
+ if (!h.fieldCtx[field])
51
+ return;
52
+ const sub = h.subForm[field];
53
+ let len = 0;
54
+ let flag;
55
+ const validate = () => {
56
+ h.$manager.validateField(field, (...args) => {
57
+ if (args[0]) {
58
+ flag = args;
59
+ } else if (flag) {
60
+ return callback && callback('子表单验证未通过');
61
+ }
62
+ callback && callback(...flag || args);
63
+ });
64
+ };
65
+ const validFn = (args) => {
66
+ setTimeout(() => {
67
+ if (!args[0]) {
68
+ if (!flag) {
69
+ flag = args;
70
+ }
71
+ }
72
+ if (!--len) {
73
+ validate();
74
+ }
75
+ });
76
+ };
77
+ sub && toArray(sub).forEach(form => {
78
+ len++;
79
+ form.validate((...args) => validFn(args))
80
+ });
81
+
82
+ if (!len) {
83
+ validate();
84
+ }
85
+ },
86
+ clearValidateState(fields, clearSub = true) {
87
+ api.helper.tidyFields(fields).forEach(field => {
88
+ if (clearSub) this.clearSubValidateState(field);
89
+ const ctx = h.fieldCtx[field];
90
+ if (!ctx) return;
91
+ h.$manager.clearValidateState(ctx);
92
+ });
93
+ },
94
+ clearSubValidateState(fields) {
95
+ api.helper.tidyFields(fields).forEach(field => {
96
+ const subForm = h.subForm[field];
97
+ if (!subForm) return;
98
+ if (Array.isArray(subForm)) {
99
+ subForm.forEach(form => {
100
+ form.clearValidateState();
101
+ })
102
+ } else if (subForm) {
103
+ subForm.clearValidateState();
104
+ }
105
+ })
106
+ },
107
+ btn: {
108
+ loading: (loading = true) => {
109
+ api.submitBtnProps({loading: !!loading});
110
+ },
111
+ disabled: (disabled = true) => {
112
+ api.submitBtnProps({disabled: !!disabled});
113
+ },
114
+ show: (isShow = true) => {
115
+ api.submitBtnProps({show: !!isShow});
116
+ }
117
+ },
118
+ resetBtn: {
119
+ loading: (loading = true) => {
120
+ api.resetBtnProps({loading: !!loading});
121
+ },
122
+ disabled: (disabled = true) => {
123
+ api.resetBtnProps({disabled: !!disabled});
124
+ },
125
+ show: (isShow = true) => {
126
+ api.resetBtnProps({show: !!isShow});
127
+ }
128
+ },
129
+ submitBtnProps: (props = {}) => {
130
+ let btn = tidyBtnProp(h.options.submitBtn, true);
131
+ extend(btn, props);
132
+ h.options.submitBtn = btn;
133
+ api.refreshOptions();
134
+ },
135
+ resetBtnProps: (props = {}) => {
136
+ let btn = tidyBtnProp(h.options.resetBtn, false);
137
+ extend(btn, props);
138
+ h.options.resetBtn = btn;
139
+ api.refreshOptions();
140
+ },
141
+ submit(successFn, failFn) {
142
+ api.validate((valid) => {
143
+ if (valid) {
144
+ let formData = api.formData();
145
+ if (is.Function(successFn))
146
+ invoke(() => successFn(formData, this));
147
+ else {
148
+ is.Function(h.options.onSubmit) && invoke(() => h.options.onSubmit(formData, this));
149
+ h.vm.$emit('submit', formData, this);
150
+ }
151
+ } else {
152
+ is.Function(failFn) && invoke(() => failFn(this, ...arguments));
153
+ }
154
+ });
155
+ },
156
+ });
157
+
158
+ return api;
159
+ }
@@ -0,0 +1,48 @@
1
+ export const iviewConfig = {
2
+ resetBtnType: 'default',
3
+ resetBtnIcon: 'md-refresh',
4
+ infoIcon: 'ios-information-circle-outline',
5
+ };
6
+
7
+ export function info() {
8
+ return {
9
+ type: 'poptip',
10
+ trigger: 'hover',
11
+ placement: 'top-start',
12
+ wordWrap: true,
13
+ icon: iviewConfig.infoIcon
14
+ }
15
+ }
16
+
17
+ export default function getConfig() {
18
+ return {
19
+ form: {
20
+ inline: false,
21
+ labelPosition: 'right',
22
+ labelWidth: 125,
23
+ showMessage: true,
24
+ autocomplete: 'off',
25
+ size: undefined,
26
+ },
27
+ row: {
28
+ gutter: 0,
29
+ },
30
+ submitBtn: {
31
+ type: 'primary',
32
+ disabled: false,
33
+ innerText: '提交',
34
+ loading: false,
35
+ show: true,
36
+ click: undefined,
37
+ },
38
+ resetBtn: {
39
+ type: iviewConfig.resetBtnType,
40
+ disabled: false,
41
+ icon: iviewConfig.resetBtnIcon,
42
+ innerText: '重置',
43
+ loading: false,
44
+ show: false,
45
+ click: undefined,
46
+ },
47
+ };
48
+ }
@@ -0,0 +1,39 @@
1
+ import components from '../components';
2
+ import parsers from '../parsers';
3
+ import alias from './alias';
4
+ import manager from './manager';
5
+ import FormCreateFactory from '@form-create/core/src/index';
6
+ import makers from './maker';
7
+ import '../style/index.css';
8
+ import extendApi from './api';
9
+
10
+ function install(FormCreate) {
11
+ FormCreate.componentAlias(alias);
12
+
13
+ components.forEach(component => {
14
+ FormCreate.component(component.name, component);
15
+ });
16
+
17
+ parsers.forEach((parser) => {
18
+ FormCreate.parser(parser);
19
+ });
20
+
21
+ Object.keys(makers).forEach(name => {
22
+ FormCreate.maker[name] = makers[name];
23
+ });
24
+ }
25
+
26
+ export default function ivuFormCreate() {
27
+ return FormCreateFactory({
28
+ ui: `${process.env.UI}`,
29
+ version: `${process.env.VERSION}`,
30
+ manager,
31
+ install,
32
+ extendApi,
33
+ attrs: {
34
+ normal: ['col', 'wrap'],
35
+ array: ['className'],
36
+ key: ['title', 'info'],
37
+ }
38
+ });
39
+ }
@@ -0,0 +1,93 @@
1
+ import {creatorFactory} from '@form-create/core/src/index';
2
+
3
+ const maker = {};
4
+
5
+ const names = ['upload', 'select', 'tree', 'checkbox', 'autoComplete', 'cascader', 'colorPicker', 'frame', 'inputNumber', 'radio', 'rate', 'timePicker', 'group'];
6
+
7
+ function useAlias(maker) {
8
+ names.forEach(name => {
9
+ maker[name] = creatorFactory(name);
10
+ });
11
+ maker.auto = maker.autoComplete;
12
+ maker.number = maker.inputNumber;
13
+ maker.color = maker.colorPicker;
14
+ }
15
+
16
+
17
+ function useUpload(maker) {
18
+ const name = 'upload';
19
+
20
+ const types = {
21
+ image: ['image', 0],
22
+ file: ['file', 0],
23
+ uploadFileOne: ['file', 1],
24
+ uploadImageOne: ['image', 1],
25
+ };
26
+
27
+ Object.keys(types).reduce((maker, key) => {
28
+ maker[key] = creatorFactory(name, m => m.props({uploadType: types[key][0], maxLength: types[key][1]}));
29
+ return maker
30
+ }, maker);
31
+
32
+ maker.uploadImage = maker.image;
33
+ maker.uploadFile = maker.file;
34
+ }
35
+
36
+ function useTree(maker) {
37
+ const name = 'tree';
38
+
39
+ const types = {'treeSelected': 'selected', 'treeChecked': 'checked'};
40
+
41
+ Object.keys(types).reduce((maker, key) => {
42
+ maker[key] = creatorFactory(name, {type:types[key]});
43
+ return maker;
44
+ }, maker);
45
+ }
46
+
47
+ function useTimePicker(maker) {
48
+ const name = 'timePicker';
49
+
50
+ maker.time = creatorFactory(name, {type:'time'})
51
+ maker.timeRange = creatorFactory(name, {type:'timerange'})
52
+ }
53
+
54
+
55
+ function useSelect(maker) {
56
+ const name = 'select';
57
+
58
+ maker.selectMultiple = creatorFactory(name, {multiple:true})
59
+ maker.selectOne = creatorFactory(name, {multiple:false})
60
+ }
61
+
62
+
63
+ function useFrame(maker) {
64
+ const name = 'frame';
65
+
66
+ const types = {
67
+ frameInputs: ['input', 0],
68
+ frameFiles: ['file', 0],
69
+ frameImages: ['image', 0],
70
+ frameInputOne: ['input', 1],
71
+ frameFileOne: ['file', 1],
72
+ frameImageOne: ['image', 1]
73
+ };
74
+
75
+ Object.keys(types).reduce((maker, key) => {
76
+ maker[key] = creatorFactory(name, m => m.props({type: types[key][0], maxLength: types[key][1]}));
77
+ return maker
78
+ }, maker);
79
+
80
+
81
+ maker.frameInput = maker.frameInputs;
82
+ maker.frameFile = maker.frameFiles;
83
+ maker.frameImage = maker.frameImages;
84
+ }
85
+
86
+ useAlias(maker);
87
+ useUpload(maker);
88
+ useTree(maker);
89
+ useSelect(maker);
90
+ useFrame(maker);
91
+ useTimePicker(maker);
92
+
93
+ export default maker;
@@ -0,0 +1,241 @@
1
+ import getConfig, {info, iviewConfig} from './config';
2
+ import mergeProps from '@form-create/utils/lib/mergeprops';
3
+ import is, {hasProperty} from '@form-create/utils/lib/type';
4
+ import extend from '@form-create/utils/lib/extend';
5
+
6
+ function tidy(props, name) {
7
+ if (!hasProperty(props, name)) return;
8
+ if (is.String(props[name])) {
9
+ props[name] = {[name]: props[name], show: true};
10
+ }
11
+ }
12
+
13
+ function isFalse(val) {
14
+ return val === false;
15
+ }
16
+
17
+ function tidyBool(opt, name) {
18
+ if (hasProperty(opt, name) && !is.Object(opt[name])) {
19
+ opt[name] = {show: !!opt[name]};
20
+ }
21
+ }
22
+
23
+ export default {
24
+ validate(call) {
25
+ this.form().validate(call);
26
+ },
27
+ validateField(field, call) {
28
+ this.form().validateField(field, call);
29
+ },
30
+ clearValidateState(ctx) {
31
+ const fItem = this.vm.$refs[ctx.wrapRef];
32
+ if (fItem) {
33
+ fItem.validateMessage = '';
34
+ fItem.validateState = '';
35
+ }
36
+ },
37
+ tidyOptions(options) {
38
+ ['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col'].forEach(name => {
39
+ tidyBool(options, name);
40
+ })
41
+ return options;
42
+ },
43
+ tidyRule({prop}) {
44
+ tidy(prop, 'title');
45
+ tidy(prop, 'info');
46
+ return prop;
47
+ },
48
+ mergeProp(ctx) {
49
+ ctx.prop = mergeProps([{
50
+ info: this.options.info || {},
51
+ wrap: this.options.wrap || {},
52
+ col: this.options.col || {},
53
+ }, ctx.prop], {
54
+ info: info(),
55
+ title: {},
56
+ col: {span: 24},
57
+ wrap: {},
58
+ }, {normal: ['title', 'info', 'col', 'wrap']});
59
+ this.setSize(ctx.prop.props);
60
+ },
61
+ setSize(props) {
62
+ if (!props.size && this.options.form.size) {
63
+ props.size = this.options.form.size;
64
+ }
65
+ },
66
+ getDefaultOptions() {
67
+ return getConfig();
68
+ },
69
+ update() {
70
+ const form = this.options.form;
71
+ this.rule = {
72
+ props: {...form},
73
+ nativeOn: {
74
+ submit: (e) => {
75
+ e.preventDefault();
76
+ }
77
+ },
78
+ class: [form.className, form.class, 'form-create'],
79
+ style: form.style,
80
+ type: 'form',
81
+ };
82
+ },
83
+ beforeRender() {
84
+ const {key, ref, $handle} = this;
85
+ extend(this.rule, {key, ref});
86
+ extend(this.rule.props, {
87
+ model: $handle.formData,
88
+ rules: $handle.validate(),
89
+ });
90
+ },
91
+ render(children) {
92
+ if (children.length) {
93
+ children.push(this.makeFormBtn());
94
+ }
95
+ return this.$r(this.rule, isFalse(this.options.row.show) ? children : [this.makeRow(children)]);
96
+ },
97
+ makeWrap(ctx, children) {
98
+ const rule = ctx.prop;
99
+ const uni = `${this.key}${ctx.key}`;
100
+ const col = rule.col;
101
+ const isTitle = this.isTitle(rule);
102
+ const labelWidth = (!col.labelWidth && !isTitle) ? 0 : col.labelWidth;
103
+ const {inline, col: _col} = this.rule.props;
104
+ const item = isFalse(rule.wrap.show) ? children : this.$r(mergeProps([rule.wrap, {
105
+ props: {
106
+ label: rule.title.title,
107
+ labelWidth,
108
+ ...(rule.wrap || {}),
109
+ prop: ctx.field,
110
+ rules: rule.validate,
111
+ },
112
+ class: rule.className,
113
+ key: `${uni}fi`,
114
+ ref: ctx.wrapRef,
115
+ type: 'formItem',
116
+ }]), [children, isTitle ? this.makeInfo(rule, uni) : null]);
117
+ return (inline === true || isFalse(_col) || isFalse(col.show)) ? item : this.makeCol(rule, uni, [item]);
118
+ },
119
+ isTitle(rule) {
120
+ const title = rule.title;
121
+ return !((!title.title && !title.native) || isFalse(title.show))
122
+ },
123
+ makeInfo(rule, uni) {
124
+ const titleProp = rule.title;
125
+ const infoProp = rule.info;
126
+ const children = [titleProp.title];
127
+
128
+ const titleFn = (pop) => this.$r(mergeProps([titleProp, {
129
+ props: titleProp,
130
+ slot: titleProp.slot || (pop ? 'default' : 'label'),
131
+ key: `${uni}tit`,
132
+ type: titleProp.type || 'span',
133
+ }]), children);
134
+
135
+ if (!isFalse(infoProp.show) && (infoProp.info || infoProp.native)) {
136
+ if (infoProp.icon !== false) {
137
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r({
138
+ type: 'icon',
139
+ props: {type: infoProp.icon === true ? iviewConfig.infoIcon : infoProp.icon, size: 16},
140
+ style: 'margin-top: -1px',
141
+ key: `${uni}i`
142
+ }));
143
+ }
144
+
145
+ const prop = {
146
+ type: infoProp.type || 'poptip',
147
+ props: {...infoProp},
148
+ key: `${uni}pop`,
149
+ slot: 'label'
150
+ };
151
+
152
+ const field = 'content';
153
+ if (infoProp.info && !hasProperty(prop.props, field)) {
154
+ prop.props[field] = infoProp.info;
155
+ }
156
+
157
+ return this.$r(mergeProps([infoProp, prop]), [
158
+ titleFn(true)
159
+ ])
160
+ }
161
+ return titleFn();
162
+ },
163
+ makeCol(rule, uni, children) {
164
+ const col = rule.col;
165
+ return this.$r({
166
+ class: col.class,
167
+ type: 'col',
168
+ props: col || {span: 24},
169
+ key: `${uni}col`
170
+ }, children);
171
+ },
172
+ makeRow(children) {
173
+ const row = this.options.row || {};
174
+ return this.$r({
175
+ type: 'row',
176
+ props: row,
177
+ class: row.class,
178
+ key: `${this.key}row`
179
+ }, children)
180
+ },
181
+ makeFormBtn() {
182
+ let vn = [];
183
+ if (!isFalse(this.options.submitBtn.show)) {
184
+ vn.push(this.makeSubmitBtn())
185
+ }
186
+ if (!isFalse(this.options.resetBtn.show)) {
187
+ vn.push(this.makeResetBtn())
188
+ }
189
+ if (!vn.length) {
190
+ return;
191
+ }
192
+ const item = this.$r({
193
+ type: 'formItem',
194
+ key: `${this.key}fb`
195
+ }, vn);
196
+
197
+ return this.rule.props.inline === true
198
+ ? item
199
+ : this.$r({
200
+ type: 'col',
201
+ props: {span: 24},
202
+ key: `${this.key}fc`
203
+ }, [item]);
204
+ },
205
+ makeResetBtn() {
206
+ const resetBtn = this.options.resetBtn;
207
+ this.setSize(resetBtn);
208
+ return this.$r({
209
+ type: 'button',
210
+ props: resetBtn,
211
+ style: {width: resetBtn.width, marginLeft: '15px'},
212
+ on: {
213
+ click: () => {
214
+ const fApi = this.$handle.api;
215
+ resetBtn.click
216
+ ? resetBtn.click(fApi)
217
+ : fApi.resetFields();
218
+ }
219
+ },
220
+ key: `${this.key}b2`,
221
+ }, [resetBtn.innerText]);
222
+ },
223
+ makeSubmitBtn() {
224
+ const submitBtn = this.options.submitBtn;
225
+ this.setSize(submitBtn);
226
+ return this.$r({
227
+ type: 'button',
228
+ props: submitBtn,
229
+ style: {width: submitBtn.width},
230
+ on: {
231
+ click: () => {
232
+ const fApi = this.$handle.api;
233
+ submitBtn.click
234
+ ? submitBtn.click(fApi)
235
+ : fApi.submit();
236
+ }
237
+ },
238
+ key: `${this.key}b1`,
239
+ }, [submitBtn.innerText]);
240
+ }
241
+ }