icarys-fc-vant 1.0.15 → 1.0.17

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 (112) hide show
  1. package/README.md +40 -205
  2. package/dist/index.js +7590 -0
  3. package/dist/index.min.js +3 -7407
  4. package/dist/index.min.js.map +1 -0
  5. package/package.json +6 -19
  6. package/src/components/common/subform/LICENSE +21 -0
  7. package/src/components/common/subform/README.md +6 -0
  8. package/src/components/common/subform/package.json +48 -0
  9. package/src/components/common/subform/src/component.jsx +75 -0
  10. package/src/components/common/subform/src/index.js +3 -0
  11. package/src/components/common/wangeditor/LICENSE +21 -0
  12. package/src/components/common/wangeditor/README.md +14 -0
  13. package/src/components/common/wangeditor/package-lock.json +114 -0
  14. package/src/components/common/wangeditor/package.json +52 -0
  15. package/src/components/common/wangeditor/src/component.jsx +74 -0
  16. package/src/components/common/wangeditor/src/index.js +3 -0
  17. package/src/core/LICENSE +21 -0
  18. package/src/core/README.md +120 -0
  19. package/src/core/babel.config.js +13 -0
  20. package/src/core/bili.config.js +34 -0
  21. package/src/core/package-lock.json +13 -0
  22. package/src/core/package.json +61 -0
  23. package/src/core/src/components/formCreate.js +287 -0
  24. package/src/core/src/components/fragment.js +12 -0
  25. package/src/core/src/factory/context.js +264 -0
  26. package/src/core/src/factory/creator.js +63 -0
  27. package/src/core/src/factory/maker.js +17 -0
  28. package/src/core/src/factory/manager.js +87 -0
  29. package/src/core/src/factory/node.js +89 -0
  30. package/src/core/src/factory/parser.js +28 -0
  31. package/src/core/src/frame/api.js +691 -0
  32. package/src/core/src/frame/attrs.js +12 -0
  33. package/src/core/src/frame/dataDriver.js +76 -0
  34. package/src/core/src/frame/fetch.js +128 -0
  35. package/src/core/src/frame/index.js +792 -0
  36. package/src/core/src/frame/language.js +50 -0
  37. package/src/core/src/frame/provider.js +297 -0
  38. package/src/core/src/frame/util.js +311 -0
  39. package/src/core/src/handler/context.js +573 -0
  40. package/src/core/src/handler/effect.js +122 -0
  41. package/src/core/src/handler/index.js +143 -0
  42. package/src/core/src/handler/inject.js +199 -0
  43. package/src/core/src/handler/input.js +199 -0
  44. package/src/core/src/handler/lifecycle.js +55 -0
  45. package/src/core/src/handler/loader.js +375 -0
  46. package/src/core/src/handler/page.js +46 -0
  47. package/src/core/src/handler/render.js +29 -0
  48. package/src/core/src/index.js +12 -0
  49. package/src/core/src/parser/html.js +17 -0
  50. package/src/core/src/render/cache.js +47 -0
  51. package/src/core/src/render/index.js +33 -0
  52. package/src/core/src/render/render.js +418 -0
  53. package/src/core/types/index.d.ts +842 -0
  54. package/src/index.js +5 -0
  55. package/src/utils/LICENSE +21 -0
  56. package/src/utils/README.md +24 -0
  57. package/src/utils/lib/console.js +16 -0
  58. package/src/utils/lib/debounce.js +9 -0
  59. package/src/utils/lib/deepextend.js +51 -0
  60. package/src/utils/lib/deepset.js +14 -0
  61. package/src/utils/lib/extend.js +20 -0
  62. package/src/utils/lib/index.js +14 -0
  63. package/src/utils/lib/json.js +90 -0
  64. package/src/utils/lib/mergeprops.js +62 -0
  65. package/src/utils/lib/mitt.js +43 -0
  66. package/src/utils/lib/modify.js +8 -0
  67. package/src/utils/lib/slot.js +8 -0
  68. package/src/utils/lib/toarray.js +5 -0
  69. package/src/utils/lib/tocase.js +11 -0
  70. package/src/utils/lib/todate.js +10 -0
  71. package/src/utils/lib/toline.js +10 -0
  72. package/src/utils/lib/topromise.js +10 -0
  73. package/src/utils/lib/tostring.js +7 -0
  74. package/src/utils/lib/type.js +45 -0
  75. package/src/utils/lib/unique.js +6 -0
  76. package/src/utils/package.json +32 -0
  77. package/src/vant/LICENSE +21 -0
  78. package/src/vant/auto-import.d.ts +5 -0
  79. package/src/vant/auto-import.js +50 -0
  80. package/src/vant/babel.config.js +10 -0
  81. package/src/vant/bili.config.js +40 -0
  82. package/src/vant/examples/App.vue +96 -0
  83. package/src/vant/examples/main.js +13 -0
  84. package/src/vant/examples/rule.js +366 -0
  85. package/src/vant/package.json +83 -0
  86. package/src/vant/public/index.html +14 -0
  87. package/src/vant/src/components/calendar.jsx +128 -0
  88. package/src/vant/src/components/cascader.jsx +120 -0
  89. package/src/vant/src/components/checkbox.jsx +38 -0
  90. package/src/vant/src/components/datePicker.jsx +87 -0
  91. package/src/vant/src/components/group.jsx +384 -0
  92. package/src/vant/src/components/icon/IconWarning.vue +12 -0
  93. package/src/vant/src/components/index.js +26 -0
  94. package/src/vant/src/components/radio.jsx +38 -0
  95. package/src/vant/src/components/select.jsx +81 -0
  96. package/src/vant/src/components/timePicker.jsx +76 -0
  97. package/src/vant/src/components/uploader.jsx +99 -0
  98. package/src/vant/src/core/alias.js +31 -0
  99. package/src/vant/src/core/api.js +135 -0
  100. package/src/vant/src/core/config.js +35 -0
  101. package/src/vant/src/core/index.js +45 -0
  102. package/src/vant/src/core/manager.js +282 -0
  103. package/src/vant/src/core/provider.js +63 -0
  104. package/src/vant/src/core/utils.js +15 -0
  105. package/src/vant/src/index.js +13 -0
  106. package/src/vant/src/parsers/hidden.js +12 -0
  107. package/src/vant/src/parsers/index.js +59 -0
  108. package/src/vant/src/parsers/row.js +10 -0
  109. package/src/vant/src/style/index.css +495 -0
  110. package/src/vant/types/config.d.ts +99 -0
  111. package/src/vant/types/index.d.ts +27 -0
  112. package/src/vant/vue.config.js +21 -0
@@ -0,0 +1,99 @@
1
+ import {defineComponent, ref, toRef, watch} from 'vue';
2
+ import toArray from '@form-create/utils/lib/toarray';
3
+
4
+ const NAME = 'fcUploader';
5
+
6
+ function parseFile(file, i) {
7
+ if (typeof file === 'object') {
8
+ return file;
9
+ }
10
+ return {
11
+ url: file,
12
+ is_string: true,
13
+ name: getFileName(file),
14
+ uid: i
15
+ };
16
+ }
17
+
18
+ function parseUpload(file) {
19
+ return {...file, file, value: file};
20
+ }
21
+
22
+ function getFileName(file) {
23
+ return ('' + file).split('/').pop()
24
+ }
25
+
26
+ export default defineComponent({
27
+ name: NAME,
28
+ inheritAttrs: false,
29
+ props: {
30
+ formCreateInject: Object,
31
+ modelValue: [Array, String, Object],
32
+ afterRead: Function,
33
+ action: String,
34
+ headers: Object,
35
+ method: String,
36
+ data: Object,
37
+ uploadName: String,
38
+ onSuccess: Function,
39
+ onError: Function,
40
+ maxCount: Number,
41
+ },
42
+ emits: ['update:modelValue', 'delete'],
43
+ setup(props, _) {
44
+
45
+ const afterRead = toRef(props, 'afterRead');
46
+ const modelValue = toRef(props, 'modelValue', []);
47
+
48
+ const fileList = ref(toArray(modelValue.value).map(parseFile).map(parseUpload));
49
+
50
+ watch(() => modelValue.value, (n) => {
51
+ fileList.value = toArray(n).map(parseFile).map(parseUpload);
52
+ })
53
+
54
+ const uploadValue = () => {
55
+ let files = fileList.value.map((v) => v.is_string ? v.url : (v.value || v.url)).filter((url) => url !== undefined);
56
+ _.emit('update:modelValue', props.maxCount === 1 ? (files[0] || '') : files);
57
+ };
58
+
59
+ return {
60
+ fileList,
61
+ modelValue,
62
+ onDelete(file) {
63
+ uploadValue();
64
+ _.emit('delete', file);
65
+ },
66
+ uploadFile(file) {
67
+ file.status = 'uploading';
68
+ if (afterRead.value) {
69
+ return afterRead.value(file);
70
+ } else {
71
+ const data = props.data || {};
72
+ data[props.uploadName || 'file'] = file.file;
73
+ props.formCreateInject.api.fetch({
74
+ action: props.action,
75
+ dataType: 'formData',
76
+ source: 'upload',
77
+ headers: props.headers || {},
78
+ method: props.method || 'post',
79
+ data
80
+ }).then(res => {
81
+ file.status = 'success';
82
+ props.onSuccess && props.onSuccess(res, file);
83
+ uploadValue();
84
+ }).catch(e => {
85
+ file.status = 'failed';
86
+ file.message = this.formCreateInject.t('uploadFail') || '上传失败';
87
+ props.onError && props.onError(e, file);
88
+ });
89
+ }
90
+ }
91
+ }
92
+ },
93
+ render() {
94
+ return <van-uploader {...this.$attrs} model-value={this.fileList} maxCount={this.maxCount}
95
+ onUpdate:model-value={(v) => this.fileList = v}
96
+ afterRead={this.uploadFile} onDelete={this.onDelete} v-slots={this.$slots}/>
97
+ }
98
+
99
+ });
@@ -0,0 +1,31 @@
1
+ const PRE = 'van';
2
+ export default {
3
+ button: PRE + '-button',
4
+ icon: PRE + '-icon',
5
+ slider: PRE + '-slider',
6
+ stepper: PRE + '-stepper',
7
+ inputNumber: PRE + '-stepper',
8
+ rate: PRE + '-rate',
9
+ uploader: 'fc-uploader',
10
+ upload: 'fc-uploader',
11
+ cell: PRE + '-cell',
12
+ timePicker: 'fc-time-picker',
13
+ datePicker: 'fc-date-picker',
14
+ 'switch': PRE + '-switch',
15
+ select: 'fc-select',
16
+ cascader: 'fc-cascader',
17
+ calendar: 'fc-calendar',
18
+ checkbox: 'fc-checkbox',
19
+ radio: 'fc-radio',
20
+ input: PRE + '-field',
21
+ textarea: PRE + '-field',
22
+ field: PRE + '-field',
23
+ formItem: PRE + '-field',
24
+ form: PRE + '-form',
25
+ col: PRE + '-col',
26
+ row: PRE + '-row',
27
+ group: 'fc-group',
28
+ array: 'fc-group',
29
+ object: 'fc-sub-form',
30
+ subForm: 'fc-sub-form',
31
+ }
@@ -0,0 +1,135 @@
1
+ import extend from '../../../utils/lib/extend';
2
+ import is from '../../../utils/lib/type';
3
+ import {invoke} from '@form-create/core/src/frame/util';
4
+ import toArray from '../../../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
+ return {
15
+ formEl() {
16
+ return h.$manager.form();
17
+ },
18
+ wrapEl(id) {
19
+ const ctx = h.getFieldCtx(id);
20
+ if (!ctx) return;
21
+ return h.vm.refs[ctx.wrapRef];
22
+ },
23
+ validate(callback) {
24
+ return new Promise((resolve, reject) => {
25
+ const forms = api.children;
26
+ const all = [h.$manager.validate()];
27
+ forms.filter(v=>!v.isScope).forEach(v => {
28
+ all.push(v.validate());
29
+ })
30
+ Promise.all(all).then(() => {
31
+ resolve(true);
32
+ callback && callback(true);
33
+ }).catch((e) => {
34
+ reject(e);
35
+ callback && callback(e);
36
+ h.vm.emit('validate-fail', e, {api});
37
+ h.emitEvent('validate-fail', e, {api});
38
+ })
39
+ });
40
+ },
41
+ validateField(field, callback) {
42
+ return new Promise((resolve, reject) => {
43
+ const ctx = h.getFieldCtx(field);
44
+ if (!ctx) return;
45
+ const sub = h.subForm[ctx.id];
46
+ const all = [h.$manager.validateField(ctx.id)];
47
+ toArray(sub).filter(v=>!v.isScope).forEach(v => {
48
+ all.push(v.validate());
49
+ })
50
+ Promise.all(all).then(() => {
51
+ resolve(null);
52
+ callback && callback(null);
53
+ }).catch((e) => {
54
+ reject(e);
55
+ callback && callback(e);
56
+ h.vm.emit('validate-field-fail', e, {field, api});
57
+ })
58
+ });
59
+ },
60
+ clearValidateState(fields, clearSub = true) {
61
+ api.helper.tidyFields(fields).forEach(field => {
62
+ if (clearSub) this.clearSubValidateState(field);
63
+ h.getCtxs(field).forEach(ctx => {
64
+ h.$manager.clearValidateState(ctx);
65
+ });
66
+ });
67
+ },
68
+ clearSubValidateState(fields) {
69
+ api.helper.tidyFields(fields).forEach(field => {
70
+ h.getCtxs(field).forEach(ctx => {
71
+ const subForm = h.subForm[ctx.id];
72
+ if (!subForm) return;
73
+ if (Array.isArray(subForm)) {
74
+ subForm.forEach(form => {
75
+ form.clearValidateState();
76
+ })
77
+ } else if (subForm) {
78
+ subForm.clearValidateState();
79
+ }
80
+ });
81
+ })
82
+ },
83
+ btn: {
84
+ loading: (loading = true) => {
85
+ api.submitBtnProps({loading: !!loading});
86
+ },
87
+ disabled: (disabled = true) => {
88
+ api.submitBtnProps({disabled: !!disabled});
89
+ },
90
+ show: (isShow = true) => {
91
+ api.submitBtnProps({show: !!isShow});
92
+ }
93
+ },
94
+ resetBtn: {
95
+ loading: (loading = true) => {
96
+ api.resetBtnProps({loading: !!loading});
97
+ },
98
+ disabled: (disabled = true) => {
99
+ api.resetBtnProps({disabled: !!disabled});
100
+ },
101
+ show: (isShow = true) => {
102
+ api.resetBtnProps({show: !!isShow});
103
+ }
104
+ },
105
+ submitBtnProps: (props = {}) => {
106
+ let btn = tidyBtnProp(h.options.submitBtn, true);
107
+ extend(btn, props);
108
+ h.options.submitBtn = btn;
109
+ api.refreshOptions();
110
+ },
111
+ resetBtnProps: (props = {}) => {
112
+ let btn = tidyBtnProp(h.options.resetBtn, false);
113
+ extend(btn, props);
114
+ h.options.resetBtn = btn;
115
+ api.refreshOptions();
116
+ },
117
+ submit(successFn, failFn) {
118
+ return new Promise((resolve, reject) => {
119
+ const promise = h.options.validateOnSubmit === false ? Promise.resolve() : api.validate();
120
+ promise.then(() => {
121
+ let formData = api.formData();
122
+ h.beforeSubmit(formData).then(() => {
123
+ is.Function(successFn) && invoke(() => successFn(formData, api));
124
+ is.Function(h.options.onSubmit) && invoke(() => h.options.onSubmit(formData, api));
125
+ h.vm.emit('submit', formData, api);
126
+ resolve(formData);
127
+ }).catch((e) => {})
128
+ }).catch((...args) => {
129
+ is.Function(failFn) && invoke(() => failFn(api, ...args));
130
+ reject(...args)
131
+ })
132
+ });
133
+ },
134
+ };
135
+ }
@@ -0,0 +1,35 @@
1
+ export default function getConfig() {
2
+ return {
3
+ form: {
4
+ required: 'auto',
5
+ labelAlign: 'right',
6
+ inputAlign: 'right',
7
+ },
8
+ row: {
9
+ show: true,
10
+ gutter: 0,
11
+ },
12
+ submitBtn: {
13
+ type: 'primary',
14
+ loading: false,
15
+ disabled: false,
16
+ block: true,
17
+ innerText: '',
18
+ size: 'small',
19
+ show: true,
20
+ col: undefined,
21
+ click: undefined,
22
+ },
23
+ resetBtn: {
24
+ type: 'default',
25
+ loading: false,
26
+ disabled: false,
27
+ block: true,
28
+ innerText: '',
29
+ size: 'small',
30
+ show: false,
31
+ col: undefined,
32
+ click: undefined,
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,45 @@
1
+ import components from '../components';
2
+ import parsers from '../parsers';
3
+ import alias from './alias';
4
+ import manager from './manager';
5
+ import FormCreateFactory from '../../../core/src/index';
6
+ import '../style/index.css';
7
+ import extendApi from './api';
8
+ import required from './provider';
9
+ import {Field} from 'vant';
10
+
11
+ function install(FormCreate) {
12
+ FormCreate.componentAlias(alias);
13
+
14
+ components.forEach(component => {
15
+ FormCreate.component(component.name, component);
16
+ });
17
+
18
+ FormCreate.register(required);
19
+
20
+ parsers.forEach((parser) => {
21
+ FormCreate.parser(parser);
22
+ });
23
+
24
+ if (Field.props) {
25
+ Field.props.modelValue = {
26
+ type: [String, Number, Array, Object, Boolean, Function],
27
+ default: '',
28
+ };
29
+ }
30
+ }
31
+
32
+ export default function VantFormCreate() {
33
+ return FormCreateFactory({
34
+ ui: 'process.env.UI',
35
+ version: 'process.env.VERSION',
36
+ manager,
37
+ extendApi,
38
+ install,
39
+ isMobile: true,
40
+ attrs: {
41
+ normal: ['col', 'wrap'],
42
+ key: ['title', 'info'],
43
+ }
44
+ });
45
+ }
@@ -0,0 +1,282 @@
1
+ import getConfig from './config';
2
+ import mergeProps from '../../../utils/lib/mergeprops';
3
+ import is, {hasProperty} from '../../../utils/lib/type';
4
+ import extend from '../../../utils/lib/extend';
5
+ import {showNotify} from 'vant';
6
+
7
+ function tidy(props, name) {
8
+ if (!hasProperty(props, name)) return;
9
+ if (is.String(props[name])) {
10
+ props[name] = {[name]: props[name], show: true};
11
+ }
12
+ }
13
+
14
+ function isFalse(val) {
15
+ return val === false;
16
+ }
17
+
18
+ function tidyBool(opt, name) {
19
+ if (hasProperty(opt, name) && !is.Object(opt[name])) {
20
+ opt[name] = {show: !!opt[name]};
21
+ }
22
+ }
23
+
24
+ function tidyRule(rule) {
25
+ const _rule = {...rule};
26
+ delete _rule.children;
27
+ return _rule;
28
+ }
29
+
30
+ export default {
31
+ validate() {
32
+ const form = this.form();
33
+ if (form) {
34
+ return form.validate();
35
+ } else {
36
+ return new Promise(v => v());
37
+ }
38
+ },
39
+ validateField(field) {
40
+ return new Promise((resolve, reject) => {
41
+ const form = this.form();
42
+ if (form) {
43
+ form.validate(field).then(resolve).catch(reject);
44
+ } else {
45
+ resolve();
46
+ }
47
+ });
48
+ },
49
+ clearValidateState(ctx) {
50
+ const form = this.form();
51
+ if (form) {
52
+ return form.resetValidation(ctx.id);
53
+ }
54
+ },
55
+ tidyOptions(options) {
56
+ ['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col', 'title'].forEach(name => {
57
+ tidyBool(options, name);
58
+ })
59
+ return options;
60
+ },
61
+ tidyRule({prop}) {
62
+ tidy(prop, 'title');
63
+ tidy(prop, 'info');
64
+ prop.validate && prop.validate.forEach(item => {
65
+ if (is.String(item.pattern)) {
66
+ item.pattern = new RegExp(item.pattern);
67
+ }
68
+ });
69
+ return prop;
70
+ },
71
+ mergeProp(ctx) {
72
+ const def = {
73
+ info: {
74
+ icon: true,
75
+ },
76
+ title: {},
77
+ col: {span: 24},
78
+ wrap: {},
79
+ };
80
+ ['info', 'wrap', 'col', 'title'].forEach(name => {
81
+ ctx.prop[name] = mergeProps([this.options[name] || {}, ctx.prop[name] || {}], def[name]);
82
+ });
83
+ },
84
+ getDefaultOptions() {
85
+ return getConfig();
86
+ },
87
+ adapterValidate(validate, validator) {
88
+ if (validate.trigger === 'change') {
89
+ validate.trigger = 'onChange';
90
+ } else if (validate.trigger === 'blur') {
91
+ validate.trigger = 'onBlur';
92
+ }
93
+ validate.validator = (value) => {
94
+ return new Promise((resolve) => {
95
+ const callback = (err) => {
96
+ validate.message = err;
97
+ if (err) {
98
+ resolve(false);
99
+ } else {
100
+ resolve();
101
+ }
102
+ }
103
+ return validator(value, callback);
104
+ })
105
+ }
106
+ return validate;
107
+ },
108
+ update() {
109
+ const form = this.options.form;
110
+ this.rule = {
111
+ props: {...form},
112
+ on: {
113
+ submit: (e) => {
114
+ e.preventDefault();
115
+ }
116
+ },
117
+ style: form.style,
118
+ type: 'form',
119
+ };
120
+ },
121
+ beforeRender() {
122
+ const {key, ref} = this;
123
+ const form = this.options.form;
124
+ extend(this.rule, {key, ref, class: [form.className, form.class, 'form-create-m', this.$handle.preview ? 'is-preview' : '']});
125
+ },
126
+ render(children) {
127
+ if (children.slotLen() && !this.$handle.preview) {
128
+ children.setSlot(undefined, () => this.makeFormBtn());
129
+ }
130
+ return this.$r(this.rule, isFalse(this.options.row.show) ? children.getSlots() : [this.makeRow(children)]);
131
+ },
132
+ makeWrap(ctx, children) {
133
+ const rule = ctx.prop;
134
+ const uni = `${this.key}${ctx.key}`;
135
+ const col = rule.col;
136
+ const isTitle = this.isTitle(rule) && rule.wrap.title !== false;
137
+ const {col: _col} = this.rule.props;
138
+ const cls = rule.wrap.class;
139
+ delete rule.wrap.class;
140
+ delete rule.wrap.title;
141
+ const item = isFalse(rule.wrap.show) ? children : this.$r(mergeProps([rule.wrap, {
142
+ props: {
143
+ modelValue: ctx.rule.value,
144
+ label: isTitle ? rule.title.title : undefined,
145
+ ...tidyRule(rule.wrap || {}),
146
+ name: ctx.id,
147
+ rules: ctx.injectValidate(),
148
+ },
149
+ class: this.$render.mergeClass(cls || rule.className, 'fc-form-item'),
150
+ key: `${uni}fi`,
151
+ ref: ctx.wrapRef,
152
+ type: 'formItem',
153
+ }]), {input: () => children, ...(isTitle ? {label: () => this.makeInfo(rule, uni, ctx)} : {})});
154
+ return (isFalse(_col) || isFalse(col.show)) ? item : this.makeCol(rule, uni, [item]);
155
+ },
156
+ isTitle(rule) {
157
+ if (this.options.form.title === false) return false;
158
+ const title = rule.title;
159
+ return !((!title.title && !title.native) || isFalse(title.show))
160
+ },
161
+ makeInfo(rule, uni, ctx) {
162
+ const titleProp = {...rule.title};
163
+ const infoProp = {...rule.info};
164
+ const titleSlot = this.getSlot('title');
165
+ const children = [titleSlot ? titleSlot({
166
+ title: ctx.refRule?.__$title?.value,
167
+ rule: ctx.rule,
168
+ options: this.options
169
+ }) : ctx.refRule?.__$title?.value];
170
+ const flag = !isFalse(infoProp.show) && (infoProp.info || infoProp.native) && !isFalse(infoProp.icon);
171
+ if (flag) {
172
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r({
173
+ type: infoProp.icon === true ? 'icon-warning' : infoProp.icon,
174
+ style: 'width:1em;',
175
+ }));
176
+ }
177
+
178
+ const _prop = mergeProps([titleProp, {
179
+ props: tidyRule(titleProp),
180
+ key: `${uni}tit`,
181
+ class: 'fc-form-title',
182
+ type: titleProp.type || 'span',
183
+ on: {
184
+ click: (...args) => {
185
+ if (flag && infoProp.info) {
186
+ showNotify({type: 'warning', message: ctx.refRule?.__$info?.value, duration: 1000});
187
+ }
188
+ this.$handle.targetHook(ctx, 'titleClick', {args});
189
+ }
190
+ }
191
+ }]);
192
+
193
+ delete _prop.props.show;
194
+ delete _prop.props.title;
195
+ delete _prop.props.native;
196
+
197
+ return this.$r(_prop, children);
198
+ },
199
+ makeCol(rule, uni, children) {
200
+ const col = rule.col;
201
+ return this.$r({
202
+ class: this.$render.mergeClass(col.class, 'fc-form-col'),
203
+ type: 'col',
204
+ props: col || {span: 24},
205
+ key: `${uni}col`
206
+ }, children);
207
+ },
208
+ makeRow(children) {
209
+ const row = this.options.row || {};
210
+ return this.$r({
211
+ type: 'row',
212
+ props: row,
213
+ class: this.$render.mergeClass(row.class, 'fc-form-row'),
214
+ key: `${this.key}row`
215
+ }, children)
216
+ },
217
+ makeFormBtn() {
218
+ let vn = [];
219
+ if (!isFalse(this.options.submitBtn.show)) {
220
+ vn.push(this.makeSubmitBtn())
221
+ }
222
+ if (!isFalse(this.options.resetBtn.show)) {
223
+ vn.push(this.makeResetBtn())
224
+ }
225
+ if (!vn.length) {
226
+ return;
227
+ }
228
+ return this.$r({
229
+ type: 'cell',
230
+ class: 'fc-form-cell fc-form-footer',
231
+ key: `${this.key}fb`
232
+ }, vn);
233
+ },
234
+
235
+ makeResetBtn() {
236
+ const resetBtn = {...this.options.resetBtn};
237
+ const innerText = resetBtn.innerText || this.$handle.api.t('reset') || '重置';
238
+ delete resetBtn.innerText;
239
+ delete resetBtn.click;
240
+ delete resetBtn.col;
241
+ delete resetBtn.show;
242
+ return this.$r({
243
+ type: 'button',
244
+ props: resetBtn,
245
+ class: 'fc-reset-btn',
246
+ style: {width: resetBtn.width},
247
+ on: {
248
+ click: () => {
249
+ const fApi = this.$handle.api;
250
+ this.options.resetBtn.click
251
+ ? this.options.resetBtn.click(fApi)
252
+ : fApi.resetFields();
253
+ }
254
+ },
255
+ key: `${this.key}b2`,
256
+ }, [innerText]);
257
+ },
258
+ makeSubmitBtn() {
259
+ const submitBtn = {...this.options.submitBtn};
260
+ const innerText = submitBtn.innerText || this.$handle.api.t('submit') || '提交';
261
+ delete submitBtn.innerText;
262
+ delete submitBtn.click;
263
+ delete submitBtn.col;
264
+ delete submitBtn.show;
265
+ return this.$r({
266
+ type: 'button',
267
+ props: submitBtn,
268
+ class: 'fc-submit-btn',
269
+ style: {width: submitBtn.width},
270
+ on: {
271
+ click: () => {
272
+ const fApi = this.$handle.api;
273
+ this.options.submitBtn.click
274
+ ? this.options.submitBtn.click(fApi)
275
+ : fApi.submit().catch(() => {
276
+ });
277
+ }
278
+ },
279
+ key: `${this.key}b1`,
280
+ }, [innerText]);
281
+ }
282
+ }
@@ -0,0 +1,63 @@
1
+ import is from '../../../utils/lib/type';
2
+
3
+ const required = {
4
+ name: 'required',
5
+ load(inject, rule, api) {
6
+ const val = parseVal(inject.getValue());
7
+ let _title = undefined;
8
+ if (val.required === false) {
9
+ inject.clearProp();
10
+ api.clearValidateState([rule.field]);
11
+ } else {
12
+ const validate = {
13
+ required: true,
14
+ validator(v) {
15
+ updateMessage();
16
+ return !is.empty(v);
17
+ },
18
+ trigger: ['onChange', 'onSubmit'],
19
+ ...val,
20
+ };
21
+ const updateMessage = () => {
22
+ const title = rule.__fc__.refRule.__$title?.value;
23
+ if (_title === title) {
24
+ return;
25
+ }
26
+ _title = title;
27
+ if (!val.message) {
28
+ validate.message = api.t('required', {title}) || (title + (api.getLocale() === 'en' ? ' is required' : '不能为空'));
29
+ } else {
30
+ const match = val.message.match(/^\{\{\s*\$t\.(.+)\s*\}\}$/);
31
+ if (match) {
32
+ validate.message = api.t(match[1], {title});
33
+ }
34
+ }
35
+ }
36
+ updateMessage();
37
+ inject.getProp().validate = [validate];
38
+ }
39
+ api.sync(rule);
40
+ },
41
+ watch(...args) {
42
+ required.load(...args);
43
+ }
44
+ }
45
+
46
+ function parseVal(val) {
47
+ if (is.Boolean(val)) {
48
+ return {required: val}
49
+ } else if (is.String(val)) {
50
+ return {message: val};
51
+ } else if (is.Undef(val)) {
52
+ return {required: false};
53
+ } else if (is.Function(val)) {
54
+ return {validator: val};
55
+ } else if (!is.Object(val)) {
56
+ return {};
57
+ } else {
58
+ return val;
59
+ }
60
+ }
61
+
62
+
63
+ export default required