@longhongguo/form-create-ant-design-vue 3.2.38 → 3.2.40

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.
@@ -1,303 +1,389 @@
1
- import getConfig 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';
1
+ import getConfig 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
5
 
6
6
  function isTooltip(info) {
7
- return info.type === 'tooltip';
7
+ return info.type === 'tooltip'
8
8
  }
9
9
 
10
10
  function tidy(props, name) {
11
- if (!hasProperty(props, name)) return;
12
- if (is.String(props[name])) {
13
- props[name] = {[name]: props[name], show: true};
14
- }
11
+ if (!hasProperty(props, name)) return
12
+ if (is.String(props[name])) {
13
+ props[name] = { [name]: props[name], show: true }
14
+ }
15
15
  }
16
16
 
17
17
  function isFalse(val) {
18
- return val === false;
18
+ return val === false
19
19
  }
20
20
 
21
21
  function tidyBool(opt, name) {
22
- if (hasProperty(opt, name) && !is.Object(opt[name])) {
23
- opt[name] = {show: !!opt[name]};
24
- }
22
+ if (hasProperty(opt, name) && !is.Object(opt[name])) {
23
+ opt[name] = { show: !!opt[name] }
24
+ }
25
25
  }
26
26
 
27
27
  function tidyRule(rule) {
28
- const _rule = {...rule};
29
- delete _rule.children;
30
- return _rule;
28
+ const _rule = { ...rule }
29
+ delete _rule.children
30
+ return _rule
31
31
  }
32
32
 
33
33
  export default {
34
- validate() {
35
- const form = this.form();
36
- if (form) {
37
- return form.validate();
38
- } else {
39
- return new Promise(v => v());
40
- }
41
- },
42
- validateField(field) {
43
- const form = this.form();
44
- if (form) {
45
- return form.validateFields(field);
46
- } else {
47
- return new Promise(v => v());
48
- }
49
- },
50
- clearValidateState(ctx) {
51
- const fItem = this.vm.refs[ctx.wrapRef];
52
- if (fItem) {
53
- fItem.clearValidate();
54
- }
55
- },
56
- tidyOptions(options) {
57
- ['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col', 'title'].forEach(name => {
58
- tidyBool(options, name);
59
- })
60
- return options;
61
- },
62
- tidyRule({prop}) {
63
- tidy(prop, 'title');
64
- tidy(prop, 'info');
65
- return prop;
66
- },
67
- mergeProp(ctx) {
68
- const def = {
69
- info: {
70
- type: 'popover',
71
- placement: 'topLeft',
72
- icon: 'QuestionCircleOutlined'
73
- },
74
- title: {},
75
- col: {span: 24},
76
- wrap: {},
77
- };
78
- ['info', 'wrap', 'col', 'title'].forEach(name => {
79
- ctx.prop[name] = mergeProps([this.options[name] || {}, ctx.prop[name] || {}], def[name]);
80
- });
81
- },
82
- getDefaultOptions() {
83
- return getConfig();
84
- },
85
- adapterValidate(validate, validator) {
86
- validate.validator = (rule, value) => {
87
- return new Promise((resolve, reject) => {
88
- const callback = (err) => {
89
- if (err) {
90
- reject(err);
91
- } else {
92
- resolve();
93
- }
94
- }
95
- return validator(value, callback);
96
- })
34
+ validate() {
35
+ const form = this.form()
36
+ if (form) {
37
+ return form.validate()
38
+ } else {
39
+ return new Promise((v) => v())
40
+ }
41
+ },
42
+ validateField(field) {
43
+ const form = this.form()
44
+ if (form) {
45
+ return form.validateFields(field)
46
+ } else {
47
+ return new Promise((v) => v())
48
+ }
49
+ },
50
+ clearValidateState(ctx) {
51
+ const fItem = this.vm.refs[ctx.wrapRef]
52
+ if (fItem) {
53
+ fItem.clearValidate()
54
+ }
55
+ },
56
+ tidyOptions(options) {
57
+ ;['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col', 'title'].forEach(
58
+ (name) => {
59
+ tidyBool(options, name)
60
+ }
61
+ )
62
+ return options
63
+ },
64
+ tidyRule({ prop }) {
65
+ tidy(prop, 'title')
66
+ tidy(prop, 'info')
67
+ return prop
68
+ },
69
+ mergeProp(ctx) {
70
+ const def = {
71
+ info: {
72
+ type: 'popover',
73
+ placement: 'topLeft',
74
+ icon: 'QuestionCircleOutlined'
75
+ },
76
+ title: {},
77
+ col: { span: 24 },
78
+ wrap: {}
79
+ }
80
+ ;['info', 'wrap', 'col', 'title'].forEach((name) => {
81
+ ctx.prop[name] = mergeProps(
82
+ [this.options[name] || {}, ctx.prop[name] || {}],
83
+ def[name]
84
+ )
85
+ })
86
+ },
87
+ getDefaultOptions() {
88
+ return getConfig()
89
+ },
90
+ adapterValidate(validate, validator) {
91
+ validate.validator = (rule, value) => {
92
+ return new Promise((resolve, reject) => {
93
+ const callback = (err) => {
94
+ if (err) {
95
+ reject(err)
96
+ } else {
97
+ resolve()
98
+ }
97
99
  }
98
- return validate;
99
- },
100
- update() {
101
- const form = this.options.form;
102
- this.rule = {
103
- props: {...form},
104
- on: {
105
- submit: (e) => {
106
- e.preventDefault();
107
- }
108
- },
109
- style: form.style,
110
- type: 'form',
111
- };
112
- },
113
- beforeRender() {
114
- const {key, ref, $handle} = this;
115
- const form = this.options.form;
116
- extend(this.rule, {key, ref, class: [form.className, form.class, 'form-create', this.$handle.preview ? 'is-preview' : '']});
117
- extend(this.rule.props, {
118
- model: $handle.formData,
119
- });
120
- },
121
- render(children) {
122
- if (children.slotLen() && !this.$handle.preview) {
123
- children.setSlot(undefined, () => this.makeFormBtn());
100
+ return validator(value, callback)
101
+ })
102
+ }
103
+ return validate
104
+ },
105
+ update() {
106
+ const form = this.options.form
107
+ this.rule = {
108
+ props: { ...form },
109
+ on: {
110
+ submit: (e) => {
111
+ e.preventDefault()
124
112
  }
125
- return this.$r(this.rule, isFalse(this.options.row.show) ? children.getSlots() : [this.makeRow(children)]);
126
- },
127
- makeWrap(ctx, children) {
128
- const rule = ctx.prop;
129
- const uni = `${this.key}${ctx.key}`;
130
- const col = rule.col;
131
- const isTitle = this.isTitle(rule) && rule.wrap.title !== false;
132
- const {layout, col: _col} = this.rule.props;
133
- const cls = rule.wrap.class;
134
- delete rule.wrap.class;
135
- delete rule.wrap.title;
136
- const item = isFalse(rule.wrap.show) ? children : this.$r(mergeProps([rule.wrap, {
137
- props: {
113
+ },
114
+ style: form.style,
115
+ type: 'form'
116
+ }
117
+ },
118
+ beforeRender() {
119
+ const { key, ref, $handle } = this
120
+ const form = this.options.form
121
+ extend(this.rule, {
122
+ key,
123
+ ref,
124
+ class: [
125
+ form.className,
126
+ form.class,
127
+ 'form-create',
128
+ this.$handle.preview ? 'is-preview' : ''
129
+ ]
130
+ })
131
+ extend(this.rule.props, {
132
+ model: $handle.formData
133
+ })
134
+ },
135
+ render(children) {
136
+ if (children.slotLen() && !this.$handle.preview) {
137
+ children.setSlot(undefined, () => this.makeFormBtn())
138
+ }
139
+ return this.$r(
140
+ this.rule,
141
+ isFalse(this.options.row.show)
142
+ ? children.getSlots()
143
+ : [this.makeRow(children)]
144
+ )
145
+ },
146
+ makeWrap(ctx, children) {
147
+ const rule = ctx.prop
148
+ const uni = `${this.key}${ctx.key}`
149
+ const col = rule.col
150
+ const isTitle = this.isTitle(rule) && rule.wrap.title !== false
151
+ const { layout, col: _col } = this.rule.props
152
+ const cls = rule.wrap.class
153
+ delete rule.wrap.class
154
+ delete rule.wrap.title
155
+ const item = isFalse(rule.wrap.show)
156
+ ? children
157
+ : this.$r(
158
+ mergeProps([
159
+ rule.wrap,
160
+ {
161
+ props: {
138
162
  ...tidyRule(rule.wrap || {}),
163
+ hasFeedback: rule.hasFeedback || false,
139
164
  name: ctx.id,
140
165
  rules: ctx.injectValidate(),
141
- ...(layout !== 'horizontal' ? {labelCol: {}, wrapperCol: {}} : {})
142
- },
143
- class: this.$render.mergeClass(cls || rule.className, 'fc-form-item'),
144
- key: `${uni}fi`,
145
- ref: ctx.wrapRef,
146
- type: 'formItem',
147
- }]), {default: () => children, ...(isTitle ? {label: () => this.makeInfo(rule, uni, ctx)} : {})});
148
- return (layout === 'inline' || isFalse(_col) || isFalse(col.show)) ? item : this.makeCol(rule, uni, [item]);
149
- },
150
- isTitle(rule) {
151
- if (this.options.form.title === false) return false;
152
- const title = rule.title;
153
- return !((!title.title && !title.native) || isFalse(title.show));
154
- },
155
- makeInfo(rule, uni, ctx) {
156
- const titleProp = {...rule.title};
157
- const infoProp = {...rule.info};
158
- if (this.options.form.title === false) return false;
159
- if ((!titleProp.title && !titleProp.native) || isFalse(titleProp.show)) return;
160
- const isTip = isTooltip(infoProp);
161
- const titleSlot = this.getSlot('title');
162
- const children = [titleSlot ? titleSlot({title: ctx.refRule?.__$title?.value, rule: ctx.rule, options: this.options}) : ctx.refRule?.__$title?.value];
166
+ ...(layout !== 'horizontal'
167
+ ? { labelCol: {}, wrapperCol: {} }
168
+ : {})
169
+ },
170
+ class: this.$render.mergeClass(
171
+ cls || rule.className,
172
+ 'fc-form-item'
173
+ ),
174
+ key: `${uni}fi`,
175
+ ref: ctx.wrapRef,
176
+ type: 'formItem'
177
+ }
178
+ ]),
179
+ {
180
+ default: () => children,
181
+ ...(isTitle ? { label: () => this.makeInfo(rule, uni, ctx) } : {})
182
+ }
183
+ )
184
+ return layout === 'inline' || isFalse(_col) || isFalse(col.show)
185
+ ? item
186
+ : this.makeCol(rule, uni, [item])
187
+ },
188
+ isTitle(rule) {
189
+ if (this.options.form.title === false) return false
190
+ const title = rule.title
191
+ return !((!title.title && !title.native) || isFalse(title.show))
192
+ },
193
+ makeInfo(rule, uni, ctx) {
194
+ const titleProp = { ...rule.title }
195
+ const infoProp = { ...rule.info }
196
+ if (this.options.form.title === false) return false
197
+ if ((!titleProp.title && !titleProp.native) || isFalse(titleProp.show))
198
+ return
199
+ const isTip = isTooltip(infoProp)
200
+ const titleSlot = this.getSlot('title')
201
+ const children = [
202
+ titleSlot
203
+ ? titleSlot({
204
+ title: ctx.refRule?.__$title?.value,
205
+ rule: ctx.rule,
206
+ options: this.options
207
+ })
208
+ : ctx.refRule?.__$title?.value
209
+ ]
163
210
 
164
- if (!isFalse(infoProp.show) && (infoProp.info || infoProp.native) && !isFalse(infoProp.icon)) {
165
- const prop = {
166
- type: infoProp.type || 'popover',
167
- props: tidyRule(infoProp),
168
- key: `${uni}pop`,
169
- };
211
+ if (
212
+ !isFalse(infoProp.show) &&
213
+ (infoProp.info || infoProp.native) &&
214
+ !isFalse(infoProp.icon)
215
+ ) {
216
+ const prop = {
217
+ type: infoProp.type || 'popover',
218
+ props: tidyRule(infoProp),
219
+ key: `${uni}pop`
220
+ }
170
221
 
171
- delete prop.props.icon;
172
- delete prop.props.show;
173
- delete prop.props.info;
174
- delete prop.props.align;
175
- delete prop.props.native;
222
+ delete prop.props.icon
223
+ delete prop.props.show
224
+ delete prop.props.info
225
+ delete prop.props.align
226
+ delete prop.props.native
176
227
 
177
- const field = isTip ? 'title' : 'content';
178
- if (infoProp.info && !hasProperty(prop.props, field)) {
179
- prop.props[field] = ctx.refRule?.__$info?.value;
180
- }
181
- children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), {
182
- [titleProp.slot || 'default']: () => this.$r({
183
- type: infoProp.icon === true ? 'QuestionCircleOutlined' : (infoProp.icon || ''),
184
- props: {type: infoProp.icon === true ? 'QuestionCircleOutlined' : infoProp.icon},
185
- key: `${uni}i`
186
- })
187
- }))
188
- }
228
+ const field = isTip ? 'title' : 'content'
229
+ if (infoProp.info && !hasProperty(prop.props, field)) {
230
+ prop.props[field] = ctx.refRule?.__$info?.value
231
+ }
232
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](
233
+ this.$r(mergeProps([infoProp, prop]), {
234
+ [titleProp.slot || 'default']: () =>
235
+ this.$r({
236
+ type:
237
+ infoProp.icon === true
238
+ ? 'QuestionCircleOutlined'
239
+ : infoProp.icon || '',
240
+ props: {
241
+ type:
242
+ infoProp.icon === true
243
+ ? 'QuestionCircleOutlined'
244
+ : infoProp.icon
245
+ },
246
+ key: `${uni}i`
247
+ })
248
+ })
249
+ )
250
+ }
189
251
 
190
- const _prop = mergeProps([titleProp, {
191
- props: tidyRule(titleProp),
192
- key: `${uni}tit`,
193
- class: 'fc-form-title',
194
- type: titleProp.type || 'span',
195
- }]);
252
+ const _prop = mergeProps([
253
+ titleProp,
254
+ {
255
+ props: tidyRule(titleProp),
256
+ key: `${uni}tit`,
257
+ class: 'fc-form-title',
258
+ type: titleProp.type || 'span'
259
+ }
260
+ ])
196
261
 
197
- delete _prop.props.show;
198
- delete _prop.props.title;
199
- delete _prop.props.native;
262
+ delete _prop.props.show
263
+ delete _prop.props.title
264
+ delete _prop.props.native
200
265
 
201
- return this.$r(_prop, children);
202
- },
203
- makeCol(rule, uni, children) {
204
- const col = rule.col;
205
- return this.$r({
206
- class: this.$render.mergeClass(col.class, 'fc-form-col'),
207
- type: 'col',
208
- props: col || {span: 24},
209
- key: `${uni}col`
210
- }, children);
211
- },
212
- makeRow(children) {
213
- const row = this.options.row || {};
214
- return this.$r({
215
- type: 'row',
216
- props: row,
217
- class: this.$render.mergeClass(row.class, 'fc-form-row'),
218
- key: `${this.key}row`
219
- }, children)
220
- },
221
- makeFormBtn() {
222
- let vn = [];
223
- if (!isFalse(this.options.submitBtn.show)) {
224
- vn.push(this.makeSubmitBtn())
225
- }
226
- if (!isFalse(this.options.resetBtn.show)) {
227
- vn.push(this.makeResetBtn())
228
- }
229
- if (!vn.length) {
230
- return;
231
- }
232
- let {labelCol, wrapperCol, layout} = this.rule.props;
233
- if (layout !== 'horizontal') {
234
- labelCol = wrapperCol = {};
266
+ return this.$r(_prop, children)
267
+ },
268
+ makeCol(rule, uni, children) {
269
+ const col = rule.col
270
+ return this.$r(
271
+ {
272
+ class: this.$render.mergeClass(col.class, 'fc-form-col'),
273
+ type: 'col',
274
+ props: col || { span: 24 },
275
+ key: `${uni}col`
276
+ },
277
+ children
278
+ )
279
+ },
280
+ makeRow(children) {
281
+ const row = this.options.row || {}
282
+ return this.$r(
283
+ {
284
+ type: 'row',
285
+ props: row,
286
+ class: this.$render.mergeClass(row.class, 'fc-form-row'),
287
+ key: `${this.key}row`
288
+ },
289
+ children
290
+ )
291
+ },
292
+ makeFormBtn() {
293
+ let vn = []
294
+ if (!isFalse(this.options.submitBtn.show)) {
295
+ vn.push(this.makeSubmitBtn())
296
+ }
297
+ if (!isFalse(this.options.resetBtn.show)) {
298
+ vn.push(this.makeResetBtn())
299
+ }
300
+ if (!vn.length) {
301
+ return
302
+ }
303
+ let { labelCol, wrapperCol, layout } = this.rule.props
304
+ if (layout !== 'horizontal') {
305
+ labelCol = wrapperCol = {}
306
+ }
307
+ const item = this.$r(
308
+ {
309
+ type: 'formItem',
310
+ class: 'fc-form-item fc-form-footer',
311
+ key: `${this.key}fb`,
312
+ props: {
313
+ labelCol,
314
+ wrapperCol,
315
+ label: ' ',
316
+ colon: false
235
317
  }
236
- const item = this.$r({
237
- type: 'formItem',
238
- class: 'fc-form-item fc-form-footer',
239
- key: `${this.key}fb`,
240
- props: {
241
- labelCol,
242
- wrapperCol,
243
- label: ' ', colon: false
244
- }
245
- }, vn);
318
+ },
319
+ vn
320
+ )
246
321
 
247
- return layout === 'inline'
248
- ? item
249
- : this.$r({
250
- type: 'col',
251
- class: 'fc-form-col',
252
- props: {span: 24},
253
- key: `${this.key}fc`
254
- }, [item]);
255
- },
322
+ return layout === 'inline'
323
+ ? item
324
+ : this.$r(
325
+ {
326
+ type: 'col',
327
+ class: 'fc-form-col',
328
+ props: { span: 24 },
329
+ key: `${this.key}fc`
330
+ },
331
+ [item]
332
+ )
333
+ },
256
334
 
257
- makeResetBtn() {
258
- const resetBtn = {...this.options.resetBtn};
259
- const innerText = resetBtn.innerText || this.$handle.api.t('reset') || '重置';
260
- delete resetBtn.innerText;
261
- delete resetBtn.click;
262
- delete resetBtn.col;
263
- delete resetBtn.show;
264
- return this.$r({
265
- type: 'button',
266
- props: resetBtn,
267
- class: 'fc-reset-btn',
268
- style: {width: resetBtn.width, marginLeft: '10px'},
269
- on: {
270
- click: () => {
271
- const fApi = this.$handle.api;
272
- this.options.resetBtn.click
273
- ? this.options.resetBtn.click(fApi)
274
- : fApi.resetFields();
275
- }
276
- },
277
- key: `${this.key}b2`,
278
- }, [innerText]);
279
- },
280
- makeSubmitBtn() {
281
- const submitBtn = {...this.options.submitBtn};
282
- const innerText = submitBtn.innerText || this.$handle.api.t('submit') || '提交';
283
- delete submitBtn.innerText;
284
- delete submitBtn.click;
285
- delete submitBtn.col;
286
- delete submitBtn.show;
287
- return this.$r({
288
- type: 'button',
289
- props: submitBtn,
290
- class: 'fc-submit-btn',
291
- style: {width: submitBtn.width},
292
- on: {
293
- click: () => {
294
- const fApi = this.$handle.api;
295
- this.options.submitBtn.click
296
- ? this.options.submitBtn.click(fApi)
297
- : fApi.submit().catch(()=>{});
298
- }
299
- },
300
- key: `${this.key}b1`,
301
- }, [innerText]);
302
- }
335
+ makeResetBtn() {
336
+ const resetBtn = { ...this.options.resetBtn }
337
+ const innerText =
338
+ resetBtn.innerText || this.$handle.api.t('reset') || '重置'
339
+ delete resetBtn.innerText
340
+ delete resetBtn.click
341
+ delete resetBtn.col
342
+ delete resetBtn.show
343
+ return this.$r(
344
+ {
345
+ type: 'button',
346
+ props: resetBtn,
347
+ class: 'fc-reset-btn',
348
+ style: { width: resetBtn.width, marginLeft: '10px' },
349
+ on: {
350
+ click: () => {
351
+ const fApi = this.$handle.api
352
+ this.options.resetBtn.click
353
+ ? this.options.resetBtn.click(fApi)
354
+ : fApi.resetFields()
355
+ }
356
+ },
357
+ key: `${this.key}b2`
358
+ },
359
+ [innerText]
360
+ )
361
+ },
362
+ makeSubmitBtn() {
363
+ const submitBtn = { ...this.options.submitBtn }
364
+ const innerText =
365
+ submitBtn.innerText || this.$handle.api.t('submit') || '提交'
366
+ delete submitBtn.innerText
367
+ delete submitBtn.click
368
+ delete submitBtn.col
369
+ delete submitBtn.show
370
+ return this.$r(
371
+ {
372
+ type: 'button',
373
+ props: submitBtn,
374
+ class: 'fc-submit-btn',
375
+ style: { width: submitBtn.width },
376
+ on: {
377
+ click: () => {
378
+ const fApi = this.$handle.api
379
+ this.options.submitBtn.click
380
+ ? this.options.submitBtn.click(fApi)
381
+ : fApi.submit().catch(() => {})
382
+ }
383
+ },
384
+ key: `${this.key}b1`
385
+ },
386
+ [innerText]
387
+ )
388
+ }
303
389
  }