@tmagic/form 1.0.0-beta.1

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 (94) hide show
  1. package/dist/style.css +161 -0
  2. package/dist/tmagic-form.es.js +3749 -0
  3. package/dist/tmagic-form.es.js.map +1 -0
  4. package/dist/tmagic-form.umd.js +3790 -0
  5. package/dist/tmagic-form.umd.js.map +1 -0
  6. package/dist/types/src/Form.vue.d.ts +304 -0
  7. package/dist/types/src/FormDialog.vue.d.ts +641 -0
  8. package/dist/types/src/containers/Container.vue.d.ts +69 -0
  9. package/dist/types/src/containers/Fieldset.vue.d.ts +56 -0
  10. package/dist/types/src/containers/GroupList.vue.d.ts +56 -0
  11. package/dist/types/src/containers/GroupListItem.vue.d.ts +72 -0
  12. package/dist/types/src/containers/Panel.vue.d.ts +41 -0
  13. package/dist/types/src/containers/Row.vue.d.ts +42 -0
  14. package/dist/types/src/containers/Step.vue.d.ts +45 -0
  15. package/dist/types/src/containers/Table.vue.d.ts +1401 -0
  16. package/dist/types/src/containers/Tabs.vue.d.ts +45 -0
  17. package/dist/types/src/fields/Cascader.vue.d.ts +1748 -0
  18. package/dist/types/src/fields/Checkbox.vue.d.ts +59 -0
  19. package/dist/types/src/fields/CheckboxGroup.vue.d.ts +56 -0
  20. package/dist/types/src/fields/Date.vue.d.ts +58 -0
  21. package/dist/types/src/fields/DateTime.vue.d.ts +57 -0
  22. package/dist/types/src/fields/Daterange.vue.d.ts +57 -0
  23. package/dist/types/src/fields/Display.vue.d.ts +3 -0
  24. package/dist/types/src/fields/DynamicField.vue.d.ts +76 -0
  25. package/dist/types/src/fields/Hidden.vue.d.ts +3 -0
  26. package/dist/types/src/fields/Link.vue.d.ts +1365 -0
  27. package/dist/types/src/fields/Number.vue.d.ts +59 -0
  28. package/dist/types/src/fields/RadioGroup.vue.d.ts +55 -0
  29. package/dist/types/src/fields/Select.vue.d.ts +975 -0
  30. package/dist/types/src/fields/Switch.vue.d.ts +59 -0
  31. package/dist/types/src/fields/Text.vue.d.ts +61 -0
  32. package/dist/types/src/fields/Textarea.vue.d.ts +56 -0
  33. package/dist/types/src/fields/Time.vue.d.ts +54 -0
  34. package/dist/types/src/index.d.ts +36 -0
  35. package/dist/types/src/schema.d.ts +495 -0
  36. package/dist/types/src/shims-vue.d.ts +6 -0
  37. package/dist/types/src/utils/config.d.ts +3 -0
  38. package/dist/types/src/utils/fieldProps.d.ts +21 -0
  39. package/dist/types/src/utils/form.d.ts +8 -0
  40. package/dist/types/src/utils/useAddField.d.ts +1 -0
  41. package/dist/types/src/vite-env.d.ts +1 -0
  42. package/package.json +51 -0
  43. package/src/Form.vue +188 -0
  44. package/src/FormDialog.vue +163 -0
  45. package/src/containers/Container.vue +263 -0
  46. package/src/containers/Fieldset.vue +138 -0
  47. package/src/containers/GroupList.vue +152 -0
  48. package/src/containers/GroupListItem.vue +159 -0
  49. package/src/containers/Panel.vue +106 -0
  50. package/src/containers/Row.vue +68 -0
  51. package/src/containers/Step.vue +82 -0
  52. package/src/containers/Table.vue +624 -0
  53. package/src/containers/Tabs.vue +176 -0
  54. package/src/fields/Cascader.vue +147 -0
  55. package/src/fields/Checkbox.vue +67 -0
  56. package/src/fields/CheckboxGroup.vue +44 -0
  57. package/src/fields/ColorPicker.vue +38 -0
  58. package/src/fields/Date.vue +51 -0
  59. package/src/fields/DateTime.vue +59 -0
  60. package/src/fields/Daterange.vue +75 -0
  61. package/src/fields/Display.vue +34 -0
  62. package/src/fields/DynamicField.vue +109 -0
  63. package/src/fields/Hidden.vue +29 -0
  64. package/src/fields/Link.vue +112 -0
  65. package/src/fields/Number.vue +53 -0
  66. package/src/fields/RadioGroup.vue +33 -0
  67. package/src/fields/Select.vue +393 -0
  68. package/src/fields/Switch.vue +65 -0
  69. package/src/fields/Text.vue +134 -0
  70. package/src/fields/Textarea.vue +62 -0
  71. package/src/fields/Time.vue +48 -0
  72. package/src/index.ts +127 -0
  73. package/src/schema.ts +638 -0
  74. package/src/shims-vue.d.ts +6 -0
  75. package/src/theme/date-time.scss +7 -0
  76. package/src/theme/fieldset.scss +24 -0
  77. package/src/theme/form-dialog.scss +13 -0
  78. package/src/theme/form.scss +30 -0
  79. package/src/theme/group-list.scss +23 -0
  80. package/src/theme/index.scss +9 -0
  81. package/src/theme/link.scss +3 -0
  82. package/src/theme/panel.scss +18 -0
  83. package/src/theme/select.scss +3 -0
  84. package/src/theme/table.scss +69 -0
  85. package/src/theme/tabs.scss +25 -0
  86. package/src/utils/config.ts +27 -0
  87. package/src/utils/containerProps.ts +50 -0
  88. package/src/utils/createForm.ts +25 -0
  89. package/src/utils/fieldProps.ts +39 -0
  90. package/src/utils/form.ts +266 -0
  91. package/src/utils/useAddField.ts +40 -0
  92. package/src/vite-env.d.ts +1 -0
  93. package/tsconfig.json +9 -0
  94. package/vite.config.ts +27 -0
@@ -0,0 +1,3749 @@
1
+ import { toRaw, defineComponent, inject, ref, computed, resolveComponent, watchEffect, openBlock, createElementBlock, normalizeStyle, normalizeClass, createBlock, resolveDynamicComponent, Fragment, createVNode, withCtx, createElementVNode, createCommentVNode, renderList, createTextVNode, toDisplayString, withDirectives, vShow, renderSlot, onMounted, toRefs, getCurrentInstance, watch, unref, reactive, onBeforeUnmount, vModelText, onBeforeMount, resolveDirective, createSlots, provide } from 'vue';
2
+ import { cloneDeep } from 'lodash-es';
3
+ import { CaretRight, CaretBottom, Delete, ArrowDown, ArrowUp } from '@element-plus/icons';
4
+ import { ElMessage, ElForm } from 'element-plus';
5
+ import Sortable from 'sortablejs';
6
+ import { asyncLoadJs, sleep, datetimeFormatter } from '@tmagic/utils';
7
+
8
+ const isTableSelect = (type) => typeof type === "string" && ["table-select", "tableSelect"].includes(type);
9
+ const asyncLoadConfig = (value, initValue2, { asyncLoad, name, type }) => {
10
+ if (type === "html" && typeof asyncLoad === "object" && typeof name !== "undefined") {
11
+ asyncLoad.name = name;
12
+ value.asyncLoad = typeof initValue2.asyncLoad === "object" ? initValue2.asyncLoad : asyncLoad;
13
+ }
14
+ };
15
+ const isMultipleValue = (type) => typeof type === "string" && [
16
+ "checkbox-group",
17
+ "checkboxGroup",
18
+ "table",
19
+ "cascader",
20
+ "group-list",
21
+ "groupList",
22
+ "dynamic-tab",
23
+ "dynamicTab"
24
+ ].includes(type);
25
+ const initItemsValue = (mForm, value, initValue2, { items, name, extensible }) => {
26
+ if (Array.isArray(initValue2[name])) {
27
+ value[name] = initValue2[name].map((v) => init(mForm, items, v));
28
+ } else {
29
+ value[name] = init(mForm, items, initValue2[name], value[name]);
30
+ if (extensible) {
31
+ value[name] = Object.assign({}, initValue2[name], value[name]);
32
+ }
33
+ }
34
+ };
35
+ const setValue = (mForm, value, initValue2, item) => {
36
+ const { items, name, type, checkbox } = item;
37
+ if (isMultipleValue(type)) {
38
+ value[name] = initValue2[name] || [];
39
+ }
40
+ if (items) {
41
+ initItemsValue(mForm, value, initValue2, item);
42
+ } else {
43
+ value[name] = getDefaultValue(mForm, item);
44
+ }
45
+ if (type === "fieldset" && checkbox) {
46
+ if (typeof value[name] === "object") {
47
+ value[name].value = typeof initValue2[name] === "object" ? initValue2[name].value || 0 : 0;
48
+ }
49
+ }
50
+ };
51
+ const initValueItem = function(mForm, item, initValue2, value) {
52
+ const { items } = item;
53
+ const { names } = item;
54
+ const { type, name } = item;
55
+ if (isTableSelect(type) && name) {
56
+ value[name] = initValue2[name] || "";
57
+ return value;
58
+ }
59
+ asyncLoadConfig(value, initValue2, item);
60
+ if (name && !items && typeof initValue2[name] !== "undefined") {
61
+ if (typeof value[name] === "undefined") {
62
+ value[name] = typeof initValue2[name] === "object" ? cloneDeep(initValue2[name]) : initValue2[name];
63
+ }
64
+ return value;
65
+ }
66
+ if (names) {
67
+ return names.forEach((n) => value[n] = initValue2[n] || "");
68
+ }
69
+ if (!name) {
70
+ return init(mForm, items, initValue2, value);
71
+ }
72
+ setValue(mForm, value, initValue2, item);
73
+ return value;
74
+ };
75
+ const init = function(mForm, config = [], initValue2 = {}, value = {}) {
76
+ if (Array.isArray(config)) {
77
+ config.forEach((item) => {
78
+ initValueItem(mForm, item, initValue2, value);
79
+ });
80
+ }
81
+ return value;
82
+ };
83
+ const getDefaultValue = function(mForm, { defaultValue, type, filter, multiple }) {
84
+ if (typeof defaultValue === "function") {
85
+ return defaultValue(mForm);
86
+ }
87
+ if (defaultValue === "undefined") {
88
+ return void 0;
89
+ }
90
+ if (typeof defaultValue !== "undefined") {
91
+ return defaultValue;
92
+ }
93
+ if (type === "number" || filter === "number") {
94
+ return 0;
95
+ }
96
+ if (["switch", "checkbox"].includes(type)) {
97
+ return false;
98
+ }
99
+ if (multiple) {
100
+ return [];
101
+ }
102
+ return "";
103
+ };
104
+ const filterFunction = (mForm, config, props) => {
105
+ if (typeof config !== "function") {
106
+ return config;
107
+ }
108
+ return config(mForm, {
109
+ values: mForm?.initValues || {},
110
+ model: props.model,
111
+ parent: mForm?.parentValues || {},
112
+ formValue: mForm?.values || props.model,
113
+ prop: props.prop
114
+ });
115
+ };
116
+ const display = function(mForm, config, props) {
117
+ if (typeof config === "function") {
118
+ return filterFunction(mForm, config, props);
119
+ }
120
+ if (config === false) {
121
+ return false;
122
+ }
123
+ return true;
124
+ };
125
+ const getRules = function(mForm, rules = [], props) {
126
+ rules = cloneDeep(rules);
127
+ if (typeof rules === "object" && !Array.isArray(rules)) {
128
+ rules = [rules];
129
+ }
130
+ return rules.map((item) => {
131
+ if (typeof item.validator === "function") {
132
+ const fnc = item.validator;
133
+ item.validator = (rule, value, callback, source, options) => fnc({
134
+ rule,
135
+ value,
136
+ callback,
137
+ source,
138
+ options
139
+ }, {
140
+ values: mForm?.initValues || {},
141
+ model: props.model,
142
+ parent: mForm?.parentValues || {},
143
+ formValue: mForm?.values || props.model,
144
+ prop: props.prop
145
+ }, mForm);
146
+ }
147
+ return item;
148
+ });
149
+ };
150
+ const initValue = async (mForm, { initValues, config }) => {
151
+ if (!Array.isArray(config))
152
+ throw new Error("config\u5E94\u8BE5\u4E3A\u6570\u7EC4");
153
+ let valuesTmp = init(mForm, config, toRaw(initValues), {});
154
+ const [firstForm] = config;
155
+ if (firstForm && typeof firstForm.onInitValue === "function") {
156
+ valuesTmp = await firstForm.onInitValue(mForm, {
157
+ formValue: valuesTmp,
158
+ initValue: initValues
159
+ });
160
+ }
161
+ return valuesTmp || {};
162
+ };
163
+
164
+ var _export_sfc = (sfc, props) => {
165
+ const target = sfc.__vccOpts || sfc;
166
+ for (const [key, val] of props) {
167
+ target[key] = val;
168
+ }
169
+ return target;
170
+ };
171
+
172
+ const _sfc_main$s = defineComponent({
173
+ name: "m-form-container",
174
+ props: {
175
+ labelWidth: String,
176
+ expandMore: Boolean,
177
+ model: {
178
+ type: [Object, Array],
179
+ required: true
180
+ },
181
+ config: {
182
+ type: Object,
183
+ required: true
184
+ },
185
+ prop: {
186
+ type: String,
187
+ default: () => ""
188
+ },
189
+ stepActive: {
190
+ type: [String, Number]
191
+ },
192
+ size: {
193
+ type: String,
194
+ default: "small"
195
+ }
196
+ },
197
+ emits: ["change"],
198
+ setup(props, { emit }) {
199
+ const mForm = inject("mForm");
200
+ const expand = ref(false);
201
+ const name = computed(() => props.config.name || "");
202
+ const items = computed(() => props.config.items);
203
+ const itemProp = computed(() => name.value ? `${props.prop}${props.prop ? "." : ""}${name.value}` : props.prop);
204
+ const tagName = computed(() => {
205
+ const component = resolveComponent(`m-${items.value ? "form" : "fields"}-${type.value}`);
206
+ if (typeof component !== "string")
207
+ return component;
208
+ return "m-fields-text";
209
+ });
210
+ const disabled = computed(() => filterFunction(mForm, props.config.disabled, props));
211
+ const tooltip = computed(() => filterFunction(mForm, props.config.tooltip, props));
212
+ const extra = computed(() => filterFunction(mForm, props.config.extra, props));
213
+ const rule = computed(() => getRules(mForm, props.config.rules, props));
214
+ const type = computed(() => {
215
+ let { type: type2 } = props.config;
216
+ if (typeof type2 === "function") {
217
+ type2 = type2(mForm, {
218
+ model: props.model
219
+ });
220
+ }
221
+ if (type2 === "form")
222
+ return "";
223
+ return type2?.replace(/([A-Z])/g, "-$1").toLowerCase() || (items.value ? "" : "text");
224
+ });
225
+ const display$1 = computed(() => {
226
+ if (props.config.display === "expand") {
227
+ return expand.value;
228
+ }
229
+ return display(mForm, props.config.display, props);
230
+ });
231
+ watchEffect(() => {
232
+ expand.value = props.expandMore;
233
+ });
234
+ const expandHandler = () => expand.value = !expand.value;
235
+ const key = (config) => config[mForm?.keyProps];
236
+ const filterHandler = (filter, value) => {
237
+ if (typeof filter === "function") {
238
+ return filter(mForm, value, {
239
+ model: props.model,
240
+ values: mForm?.initValues,
241
+ formValue: mForm?.values,
242
+ prop: itemProp.value
243
+ });
244
+ }
245
+ if (filter === "number") {
246
+ return +value;
247
+ }
248
+ return value;
249
+ };
250
+ const changeHandler = (onChange, value) => {
251
+ if (typeof onChange === "function") {
252
+ return onChange(mForm, value, {
253
+ model: props.model,
254
+ values: mForm?.initValues,
255
+ formValue: mForm?.values,
256
+ prop: itemProp.value
257
+ });
258
+ }
259
+ };
260
+ const trimHandler = (trim, value) => {
261
+ if (typeof value === "string" && trim) {
262
+ return value.replace(/^\s*/, "").replace(/\s*$/, "");
263
+ }
264
+ };
265
+ const onChangeHandler = async function(v, key2) {
266
+ const { filter, onChange, trim, name: name2, dynamicKey } = props.config;
267
+ let value = filterHandler(filter, v);
268
+ value = await changeHandler(onChange, value) ?? value;
269
+ value = trimHandler(trim, value) ?? value;
270
+ if ((name2 || name2 === 0) && props.model !== value && (v !== value || props.model[name2] !== value)) {
271
+ props.model[name2] = value;
272
+ }
273
+ if (key2 !== void 0 && dynamicKey) {
274
+ props.model[key2] = value;
275
+ }
276
+ emit("change", props.model);
277
+ };
278
+ return {
279
+ expand,
280
+ name,
281
+ type,
282
+ disabled,
283
+ itemProp,
284
+ items,
285
+ display: display$1,
286
+ tagName,
287
+ rule,
288
+ tooltip,
289
+ extra,
290
+ key,
291
+ onChangeHandler,
292
+ expandHandler
293
+ };
294
+ }
295
+ });
296
+ const _hoisted_1$g = ["innerHTML"];
297
+ const _hoisted_2$7 = ["innerHTML"];
298
+ const _hoisted_3$7 = ["innerHTML"];
299
+ const _hoisted_4$6 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-warning" }, null, -1);
300
+ const _hoisted_5$4 = ["innerHTML"];
301
+ const _hoisted_6$3 = {
302
+ key: 4,
303
+ style: { "text-align": "center" }
304
+ };
305
+ function _sfc_render$p(_ctx, _cache, $props, $setup, $data, $options) {
306
+ const _component_m_fields_hidden = resolveComponent("m-fields-hidden");
307
+ const _component_el_tooltip = resolveComponent("el-tooltip");
308
+ const _component_el_form_item = resolveComponent("el-form-item");
309
+ const _component_m_form_container = resolveComponent("m-form-container");
310
+ const _component_el_button = resolveComponent("el-button");
311
+ return _ctx.config ? (openBlock(), createElementBlock("div", {
312
+ key: 0,
313
+ style: normalizeStyle(_ctx.config.tip ? "display: flex" : ""),
314
+ class: normalizeClass([_ctx.config.className, "m-form-container"])
315
+ }, [
316
+ _ctx.type === "hidden" ? (openBlock(), createBlock(_component_m_fields_hidden, {
317
+ key: 0,
318
+ model: _ctx.model,
319
+ config: _ctx.config,
320
+ name: _ctx.config.name,
321
+ disabled: _ctx.disabled,
322
+ prop: _ctx.itemProp
323
+ }, null, 8, ["model", "config", "name", "disabled", "prop"])) : _ctx.items && !_ctx.config.text && _ctx.type && _ctx.display ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.tagName), {
324
+ key: _ctx.key(_ctx.config),
325
+ size: _ctx.size,
326
+ model: _ctx.model,
327
+ config: _ctx.config,
328
+ name: _ctx.name,
329
+ prop: _ctx.itemProp,
330
+ "step-active": _ctx.stepActive,
331
+ "expand-more": _ctx.expand,
332
+ "label-width": _ctx.config.labelWidth || _ctx.labelWidth,
333
+ onChange: _ctx.onChangeHandler
334
+ }, null, 8, ["size", "model", "config", "name", "prop", "step-active", "expand-more", "label-width", "onChange"])) : _ctx.type && _ctx.display ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
335
+ createVNode(_component_el_form_item, {
336
+ style: normalizeStyle(_ctx.config.tip ? "flex: 1" : ""),
337
+ prop: _ctx.itemProp,
338
+ "label-width": _ctx.config.text ? _ctx.config.labelWidth || _ctx.labelWidth : "0",
339
+ rules: _ctx.rule
340
+ }, {
341
+ label: withCtx(() => [
342
+ createElementVNode("span", {
343
+ innerHTML: _ctx.type === "checkbox" ? "" : _ctx.config.text
344
+ }, null, 8, _hoisted_1$g)
345
+ ]),
346
+ default: withCtx(() => [
347
+ _ctx.tooltip ? (openBlock(), createBlock(_component_el_tooltip, { key: 0 }, {
348
+ content: withCtx(() => [
349
+ createElementVNode("div", { innerHTML: _ctx.tooltip }, null, 8, _hoisted_2$7)
350
+ ]),
351
+ default: withCtx(() => [
352
+ (openBlock(), createBlock(resolveDynamicComponent(_ctx.tagName), {
353
+ key: _ctx.key(_ctx.config),
354
+ size: _ctx.size,
355
+ model: _ctx.model,
356
+ config: _ctx.config,
357
+ name: _ctx.name,
358
+ disabled: _ctx.disabled,
359
+ prop: _ctx.itemProp,
360
+ onChange: _ctx.onChangeHandler
361
+ }, null, 8, ["size", "model", "config", "name", "disabled", "prop", "onChange"]))
362
+ ]),
363
+ _: 1
364
+ })) : (openBlock(), createBlock(resolveDynamicComponent(_ctx.tagName), {
365
+ key: _ctx.key(_ctx.config),
366
+ size: _ctx.size,
367
+ model: _ctx.model,
368
+ config: _ctx.config,
369
+ name: _ctx.name,
370
+ disabled: _ctx.disabled,
371
+ prop: _ctx.itemProp,
372
+ onChange: _ctx.onChangeHandler
373
+ }, null, 8, ["size", "model", "config", "name", "disabled", "prop", "onChange"])),
374
+ _ctx.extra ? (openBlock(), createElementBlock("div", {
375
+ key: 2,
376
+ innerHTML: _ctx.extra,
377
+ class: "m-form-tip"
378
+ }, null, 8, _hoisted_3$7)) : createCommentVNode("", true)
379
+ ]),
380
+ _: 1
381
+ }, 8, ["style", "prop", "label-width", "rules"]),
382
+ _ctx.config.tip ? (openBlock(), createBlock(_component_el_tooltip, {
383
+ key: 0,
384
+ placement: "top",
385
+ style: { "line-height": "40px", "margin-left": "5px" }
386
+ }, {
387
+ content: withCtx(() => [
388
+ createElementVNode("div", {
389
+ innerHTML: _ctx.config.tip
390
+ }, null, 8, _hoisted_5$4)
391
+ ]),
392
+ default: withCtx(() => [
393
+ _hoisted_4$6
394
+ ]),
395
+ _: 1
396
+ })) : createCommentVNode("", true)
397
+ ], 64)) : _ctx.items && _ctx.display ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
398
+ (_ctx.name || _ctx.name === 0 ? _ctx.model[_ctx.name] : _ctx.model) ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(_ctx.items, (item) => {
399
+ return openBlock(), createBlock(_component_m_form_container, {
400
+ key: _ctx.key(item),
401
+ model: _ctx.name || _ctx.name === 0 ? _ctx.model[_ctx.name] : _ctx.model,
402
+ config: item,
403
+ size: _ctx.size,
404
+ "step-active": _ctx.stepActive,
405
+ "expand-more": _ctx.expand,
406
+ "label-width": _ctx.config.labelWidth || _ctx.labelWidth,
407
+ prop: _ctx.itemProp,
408
+ onChange: _ctx.onChangeHandler
409
+ }, null, 8, ["model", "config", "size", "step-active", "expand-more", "label-width", "prop", "onChange"]);
410
+ }), 128)) : createCommentVNode("", true)
411
+ ], 64)) : createCommentVNode("", true),
412
+ _ctx.config.expand && _ctx.type !== "fieldset" ? (openBlock(), createElementBlock("div", _hoisted_6$3, [
413
+ createVNode(_component_el_button, {
414
+ type: "text",
415
+ onClick: _ctx.expandHandler
416
+ }, {
417
+ default: withCtx(() => [
418
+ createTextVNode(toDisplayString(_ctx.expand ? "\u6536\u8D77\u914D\u7F6E" : "\u5C55\u5F00\u66F4\u591A\u914D\u7F6E"), 1)
419
+ ]),
420
+ _: 1
421
+ }, 8, ["onClick"])
422
+ ])) : createCommentVNode("", true)
423
+ ], 6)) : createCommentVNode("", true);
424
+ }
425
+ var Container = /* @__PURE__ */ _export_sfc(_sfc_main$s, [["render", _sfc_render$p]]);
426
+
427
+ const _sfc_main$r = defineComponent({
428
+ name: "m-form-fieldset",
429
+ props: {
430
+ labelWidth: String,
431
+ model: {
432
+ type: Object,
433
+ default: () => ({})
434
+ },
435
+ config: {
436
+ type: Object,
437
+ default: () => ({})
438
+ },
439
+ rules: {
440
+ type: Object,
441
+ default: () => ({})
442
+ },
443
+ prop: {
444
+ type: String,
445
+ default: () => ""
446
+ },
447
+ size: String
448
+ },
449
+ emits: ["change"],
450
+ setup(props, { emit }) {
451
+ const mForm = inject("mForm");
452
+ const name = computed(() => props.config.name || "");
453
+ const show = computed(() => {
454
+ if (props.config.expand && name.value) {
455
+ return props.model[name.value]?.value;
456
+ }
457
+ return true;
458
+ });
459
+ const lWidth = computed(() => {
460
+ if (props.config.items) {
461
+ return props.config.labelWidth || props.labelWidth;
462
+ }
463
+ return props.config.labelWidth || props.labelWidth || (props.config.text ? null : "0");
464
+ });
465
+ const change = () => {
466
+ emit("change", props.model);
467
+ };
468
+ const key = (item, index) => item[mForm?.keyProp || "__key"] ?? index;
469
+ return {
470
+ show,
471
+ name,
472
+ mForm,
473
+ lWidth,
474
+ key,
475
+ change
476
+ };
477
+ }
478
+ });
479
+ const _hoisted_1$f = ["innerHTML"];
480
+ const _hoisted_2$6 = ["innerHTML"];
481
+ const _hoisted_3$6 = { key: 1 };
482
+ const _hoisted_4$5 = ["innerHTML"];
483
+ const _hoisted_5$3 = ["innerHTML"];
484
+ const _hoisted_6$2 = { key: 2 };
485
+ const _hoisted_7$2 = ["innerHTML"];
486
+ const _hoisted_8$1 = ["innerHTML"];
487
+ const _hoisted_9$1 = {
488
+ key: 3,
489
+ style: { "display": "flex" }
490
+ };
491
+ const _hoisted_10$1 = { style: { "flex": "1" } };
492
+ const _hoisted_11 = ["src"];
493
+ function _sfc_render$o(_ctx, _cache, $props, $setup, $data, $options) {
494
+ const _component_el_checkbox = resolveComponent("el-checkbox");
495
+ const _component_m_form_container = resolveComponent("m-form-container");
496
+ return (_ctx.name ? _ctx.model[_ctx.name] : _ctx.model) ? (openBlock(), createElementBlock("fieldset", {
497
+ key: 0,
498
+ class: "m-fieldset",
499
+ style: normalizeStyle(_ctx.show ? "padding: 15px 15px 0 5px;" : "border: 0")
500
+ }, [
501
+ !_ctx.show && _ctx.name ? (openBlock(), createBlock(_component_el_checkbox, {
502
+ key: 0,
503
+ modelValue: _ctx.model[_ctx.name].value,
504
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name].value = $event),
505
+ prop: `${_ctx.prop}${_ctx.prop ? "." : ""}${_ctx.config.name}.value`,
506
+ "true-label": 1,
507
+ "false-label": 0,
508
+ onChange: _ctx.change
509
+ }, {
510
+ default: withCtx(() => [
511
+ createElementVNode("span", {
512
+ innerHTML: _ctx.config.legend
513
+ }, null, 8, _hoisted_1$f),
514
+ _ctx.config.extra ? (openBlock(), createElementBlock("span", {
515
+ key: 0,
516
+ innerHTML: _ctx.config.extra,
517
+ class: "m-form-tip"
518
+ }, null, 8, _hoisted_2$6)) : createCommentVNode("", true)
519
+ ]),
520
+ _: 1
521
+ }, 8, ["modelValue", "prop", "onChange"])) : _ctx.config.checkbox && _ctx.name ? (openBlock(), createElementBlock("legend", _hoisted_3$6, [
522
+ createVNode(_component_el_checkbox, {
523
+ modelValue: _ctx.model[_ctx.name].value,
524
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => _ctx.model[_ctx.name].value = $event),
525
+ prop: `${_ctx.prop}${_ctx.prop ? "." : ""}${_ctx.config.name}.value`,
526
+ "true-label": 1,
527
+ "false-label": 0,
528
+ onChange: _ctx.change
529
+ }, {
530
+ default: withCtx(() => [
531
+ createElementVNode("span", {
532
+ innerHTML: _ctx.config.legend
533
+ }, null, 8, _hoisted_4$5),
534
+ _ctx.config.extra ? (openBlock(), createElementBlock("span", {
535
+ key: 0,
536
+ innerHTML: _ctx.config.extra,
537
+ class: "m-form-tip"
538
+ }, null, 8, _hoisted_5$3)) : createCommentVNode("", true)
539
+ ]),
540
+ _: 1
541
+ }, 8, ["modelValue", "prop", "onChange"])
542
+ ])) : (openBlock(), createElementBlock("legend", _hoisted_6$2, [
543
+ createElementVNode("span", {
544
+ innerHTML: _ctx.config.legend
545
+ }, null, 8, _hoisted_7$2),
546
+ _ctx.config.extra ? (openBlock(), createElementBlock("span", {
547
+ key: 0,
548
+ innerHTML: _ctx.config.extra,
549
+ class: "m-form-tip"
550
+ }, null, 8, _hoisted_8$1)) : createCommentVNode("", true)
551
+ ])),
552
+ _ctx.config.schematic && _ctx.show ? (openBlock(), createElementBlock("div", _hoisted_9$1, [
553
+ createElementVNode("div", _hoisted_10$1, [
554
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.config.items, (item, index) => {
555
+ return openBlock(), createBlock(_component_m_form_container, {
556
+ key: _ctx.key(item, index),
557
+ model: _ctx.name ? _ctx.model[_ctx.name] : _ctx.model,
558
+ rules: _ctx.name ? _ctx.rules[_ctx.name] : [],
559
+ config: item,
560
+ prop: _ctx.prop,
561
+ labelWidth: _ctx.lWidth,
562
+ size: _ctx.size,
563
+ onChange: _ctx.change
564
+ }, null, 8, ["model", "rules", "config", "prop", "labelWidth", "size", "onChange"]);
565
+ }), 128))
566
+ ]),
567
+ createElementVNode("img", {
568
+ class: "m-form-schematic",
569
+ src: _ctx.config.schematic
570
+ }, null, 8, _hoisted_11)
571
+ ])) : _ctx.show ? (openBlock(true), createElementBlock(Fragment, { key: 4 }, renderList(_ctx.config.items, (item, index) => {
572
+ return openBlock(), createBlock(_component_m_form_container, {
573
+ key: _ctx.key(item, index),
574
+ model: _ctx.name ? _ctx.model[_ctx.name] : _ctx.model,
575
+ rules: _ctx.name ? _ctx.rules[_ctx.name] : [],
576
+ config: item,
577
+ prop: _ctx.prop,
578
+ labelWidth: _ctx.lWidth,
579
+ size: _ctx.size,
580
+ onChange: _ctx.change
581
+ }, null, 8, ["model", "rules", "config", "prop", "labelWidth", "size", "onChange"]);
582
+ }), 128)) : createCommentVNode("", true)
583
+ ], 4)) : createCommentVNode("", true);
584
+ }
585
+ var Fieldset = /* @__PURE__ */ _export_sfc(_sfc_main$r, [["render", _sfc_render$o]]);
586
+
587
+ const _sfc_main$q = defineComponent({
588
+ name: "m-form-group-list-item",
589
+ components: { CaretRight, CaretBottom },
590
+ props: {
591
+ labelWidth: String,
592
+ model: {
593
+ type: Object,
594
+ default: () => ({})
595
+ },
596
+ config: {
597
+ type: Object,
598
+ default: () => ({})
599
+ },
600
+ prop: String,
601
+ size: String,
602
+ index: {
603
+ type: [Number, String, Symbol],
604
+ default: 0
605
+ },
606
+ groupModel: {
607
+ type: Array,
608
+ default: () => []
609
+ }
610
+ },
611
+ emits: ["swap-item", "remove-item", "change"],
612
+ setup(props, { emit }) {
613
+ const mForm = inject("mForm");
614
+ const expand = ref(false);
615
+ watchEffect(() => {
616
+ expand.value = !props.index;
617
+ });
618
+ const rowConfig = computed(() => ({
619
+ type: "row",
620
+ span: props.config.span || 24,
621
+ items: props.config.items,
622
+ labelWidth: props.config.labelWidth,
623
+ [mForm?.keyProp || "__key"]: `${props.config[mForm?.keyProp || "__key"]}${String(props.index)}`
624
+ }));
625
+ const title = computed(() => {
626
+ if (props.config.titleKey && props.model[props.config.titleKey]) {
627
+ return props.model[props.config.titleKey];
628
+ }
629
+ return `\u7EC4 ${String(props.index)}`;
630
+ });
631
+ const length = computed(() => props.groupModel?.length || 0);
632
+ const itemExtra = computed(() => filterFunction(mForm, props.config.itemExtra, props));
633
+ const removeHandler = () => emit("remove-item", props.index);
634
+ const changeHandler = () => emit("change");
635
+ const expandHandler = () => {
636
+ expand.value = !expand.value;
637
+ };
638
+ const showDelete = (index) => {
639
+ const deleteFunc = props.config.delete;
640
+ if (deleteFunc && typeof deleteFunc === "function") {
641
+ return deleteFunc(props.model, index, mForm?.values);
642
+ }
643
+ return true;
644
+ };
645
+ const changeOrder = (offset = 0) => emit("swap-item", props.index, `${String(props.index)}${offset}`);
646
+ const movable = () => {
647
+ const { movable: movable2 } = props.config;
648
+ if (movable2 === void 0)
649
+ return true;
650
+ if (typeof movable2 === "function") {
651
+ return movable2(mForm, props.index || 0, props.model, props.groupModel);
652
+ }
653
+ return movable2;
654
+ };
655
+ return {
656
+ expand,
657
+ expandHandler,
658
+ title,
659
+ showDelete,
660
+ removeHandler,
661
+ movable,
662
+ changeOrder,
663
+ itemExtra,
664
+ rowConfig,
665
+ changeHandler,
666
+ length,
667
+ Delete
668
+ };
669
+ }
670
+ });
671
+ const _hoisted_1$e = { class: "m-fields-group-list-item" };
672
+ const _hoisted_2$5 = /* @__PURE__ */ createTextVNode("\u4E0A\u79FB");
673
+ const _hoisted_3$5 = /* @__PURE__ */ createTextVNode("\u4E0B\u79FB");
674
+ const _hoisted_4$4 = ["innerHTML"];
675
+ function _sfc_render$n(_ctx, _cache, $props, $setup, $data, $options) {
676
+ const _component_caret_bottom = resolveComponent("caret-bottom");
677
+ const _component_caret_right = resolveComponent("caret-right");
678
+ const _component_el_icon = resolveComponent("el-icon");
679
+ const _component_el_button = resolveComponent("el-button");
680
+ const _component_CaretRight = resolveComponent("CaretRight");
681
+ const _component_CaretBottom = resolveComponent("CaretBottom");
682
+ const _component_m_form_container = resolveComponent("m-form-container");
683
+ return openBlock(), createElementBlock("div", _hoisted_1$e, [
684
+ createElementVNode("div", null, [
685
+ createVNode(_component_el_icon, {
686
+ style: { "margin-right": "7px" },
687
+ onClick: _ctx.expandHandler
688
+ }, {
689
+ default: withCtx(() => [
690
+ _ctx.expand ? (openBlock(), createBlock(_component_caret_bottom, { key: 0 })) : (openBlock(), createBlock(_component_caret_right, { key: 1 }))
691
+ ]),
692
+ _: 1
693
+ }, 8, ["onClick"]),
694
+ createVNode(_component_el_button, {
695
+ type: "text",
696
+ onClick: _ctx.expandHandler
697
+ }, {
698
+ default: withCtx(() => [
699
+ createTextVNode(toDisplayString(_ctx.title), 1)
700
+ ]),
701
+ _: 1
702
+ }, 8, ["onClick"]),
703
+ withDirectives(createVNode(_component_el_button, {
704
+ type: "text",
705
+ icon: _ctx.Delete,
706
+ style: { "color": "#f56c6c" },
707
+ onClick: _ctx.removeHandler
708
+ }, null, 8, ["icon", "onClick"]), [
709
+ [vShow, _ctx.showDelete(parseInt(String(_ctx.index)))]
710
+ ]),
711
+ _ctx.movable() ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
712
+ withDirectives(createVNode(_component_el_button, {
713
+ type: "text",
714
+ size: "small",
715
+ onClick: _cache[0] || (_cache[0] = ($event) => _ctx.changeOrder(-1))
716
+ }, {
717
+ default: withCtx(() => [
718
+ _hoisted_2$5,
719
+ createVNode(_component_el_icon, null, {
720
+ default: withCtx(() => [
721
+ createVNode(_component_CaretRight)
722
+ ]),
723
+ _: 1
724
+ })
725
+ ]),
726
+ _: 1
727
+ }, 512), [
728
+ [vShow, _ctx.index !== 0]
729
+ ]),
730
+ withDirectives(createVNode(_component_el_button, {
731
+ type: "text",
732
+ size: "small",
733
+ onClick: _cache[1] || (_cache[1] = ($event) => _ctx.changeOrder(1))
734
+ }, {
735
+ default: withCtx(() => [
736
+ _hoisted_3$5,
737
+ createVNode(_component_el_icon, null, {
738
+ default: withCtx(() => [
739
+ createVNode(_component_CaretBottom)
740
+ ]),
741
+ _: 1
742
+ })
743
+ ]),
744
+ _: 1
745
+ }, 512), [
746
+ [vShow, _ctx.index !== _ctx.length - 1]
747
+ ])
748
+ ], 64)) : createCommentVNode("", true),
749
+ _ctx.itemExtra ? (openBlock(), createElementBlock("span", {
750
+ key: 1,
751
+ innerHTML: _ctx.itemExtra,
752
+ class: "m-form-tip"
753
+ }, null, 8, _hoisted_4$4)) : createCommentVNode("", true)
754
+ ]),
755
+ _ctx.expand ? (openBlock(), createBlock(_component_m_form_container, {
756
+ key: 0,
757
+ config: _ctx.rowConfig,
758
+ model: _ctx.model,
759
+ labelWidth: _ctx.labelWidth,
760
+ prop: `${_ctx.prop}${_ctx.prop ? "." : ""}${String(_ctx.index)}`,
761
+ size: _ctx.size,
762
+ onChange: _ctx.changeHandler
763
+ }, null, 8, ["config", "model", "labelWidth", "prop", "size", "onChange"])) : createCommentVNode("", true)
764
+ ]);
765
+ }
766
+ var MFieldsGroupListItem = /* @__PURE__ */ _export_sfc(_sfc_main$q, [["render", _sfc_render$n]]);
767
+
768
+ const _sfc_main$p = defineComponent({
769
+ name: "m-form-group-list",
770
+ components: { MFieldsGroupListItem },
771
+ props: {
772
+ labelWidth: String,
773
+ model: {
774
+ type: Object,
775
+ default: () => ({})
776
+ },
777
+ config: {
778
+ type: Object,
779
+ default: () => ({})
780
+ },
781
+ prop: {
782
+ type: String,
783
+ default: ""
784
+ },
785
+ size: String,
786
+ name: {
787
+ type: String,
788
+ default: ""
789
+ }
790
+ },
791
+ emits: ["change"],
792
+ setup(props, { emit }) {
793
+ const mForm = inject("mForm");
794
+ const addable = computed(() => {
795
+ if (!props.name)
796
+ return false;
797
+ if (typeof props.config.addable === "function") {
798
+ return props.config.addable(mForm, {
799
+ model: props.model[props.name],
800
+ formValue: mForm?.values
801
+ });
802
+ }
803
+ return typeof props.config.addable === "undefined" ? true : props.config.addable;
804
+ });
805
+ const changeHandler = () => {
806
+ if (!props.name)
807
+ return false;
808
+ emit("change", props.model[props.name]);
809
+ };
810
+ const addHandler = async () => {
811
+ if (!props.name)
812
+ return false;
813
+ let initValues = {};
814
+ if (typeof props.config.defaultAdd === "function") {
815
+ initValues = await props.config.defaultAdd(mForm, {
816
+ model: props.model[props.name],
817
+ formValue: mForm?.values
818
+ });
819
+ } else if (props.config.defaultAdd) {
820
+ initValues = props.config.defaultAdd;
821
+ }
822
+ const groupValue = await initValue(mForm, {
823
+ config: props.config.items,
824
+ initValues
825
+ });
826
+ props.model[props.name].push(groupValue);
827
+ };
828
+ const removeHandler = (index) => {
829
+ if (!props.name)
830
+ return false;
831
+ props.model[props.name].splice(index, 1);
832
+ changeHandler();
833
+ };
834
+ const swapHandler = (idx1, idx2) => {
835
+ if (!props.name)
836
+ return false;
837
+ const [currRow] = props.model[props.name].splice(idx1, 1);
838
+ props.model[props.name].splice(idx2, 0, currRow);
839
+ changeHandler();
840
+ };
841
+ const toggleMode = () => {
842
+ props.config.type = "table";
843
+ props.config.groupItems = props.config.items;
844
+ props.config.items = props.config.tableItems || props.config.items.map((item) => ({
845
+ ...item,
846
+ label: item.label || item.text,
847
+ text: null
848
+ }));
849
+ };
850
+ return {
851
+ addable,
852
+ toggleMode,
853
+ removeHandler,
854
+ swapHandler,
855
+ changeHandler,
856
+ addHandler
857
+ };
858
+ }
859
+ });
860
+ const _hoisted_1$d = { class: "m-fields-group-list" };
861
+ const _hoisted_2$4 = ["innerHTML"];
862
+ const _hoisted_3$4 = {
863
+ key: 1,
864
+ class: "el-table__empty-block"
865
+ };
866
+ const _hoisted_4$3 = /* @__PURE__ */ createElementVNode("span", { class: "el-table__empty-text" }, "\u6682\u65E0\u6570\u636E", -1);
867
+ const _hoisted_5$2 = [
868
+ _hoisted_4$3
869
+ ];
870
+ const _hoisted_6$1 = /* @__PURE__ */ createTextVNode("\u6DFB\u52A0\u7EC4");
871
+ const _hoisted_7$1 = /* @__PURE__ */ createTextVNode("\u5207\u6362\u4E3A\u8868\u683C");
872
+ function _sfc_render$m(_ctx, _cache, $props, $setup, $data, $options) {
873
+ const _component_m_fields_group_list_item = resolveComponent("m-fields-group-list-item");
874
+ const _component_el_button = resolveComponent("el-button");
875
+ return openBlock(), createElementBlock("div", _hoisted_1$d, [
876
+ _ctx.config.extra ? (openBlock(), createElementBlock("div", {
877
+ key: 0,
878
+ innerHTML: _ctx.config.extra,
879
+ style: { "color": "rgba(0, 0, 0, 0.45)" }
880
+ }, null, 8, _hoisted_2$4)) : createCommentVNode("", true),
881
+ !_ctx.model[_ctx.name] || !_ctx.model[_ctx.name].length ? (openBlock(), createElementBlock("div", _hoisted_3$4, _hoisted_5$2)) : (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(_ctx.model[_ctx.name], (item, index) => {
882
+ return openBlock(), createBlock(_component_m_fields_group_list_item, {
883
+ key: index,
884
+ model: item,
885
+ config: _ctx.config,
886
+ prop: _ctx.prop,
887
+ index,
888
+ "label-width": _ctx.labelWidth,
889
+ size: _ctx.size,
890
+ "group-model": _ctx.model[_ctx.name],
891
+ onRemoveItem: _ctx.removeHandler,
892
+ onSwapItem: _ctx.swapHandler,
893
+ onChange: _ctx.changeHandler
894
+ }, null, 8, ["model", "config", "prop", "index", "label-width", "size", "group-model", "onRemoveItem", "onSwapItem", "onChange"]);
895
+ }), 128)),
896
+ _ctx.addable ? (openBlock(), createBlock(_component_el_button, {
897
+ key: 3,
898
+ onClick: _ctx.addHandler,
899
+ size: "small"
900
+ }, {
901
+ default: withCtx(() => [
902
+ _hoisted_6$1
903
+ ]),
904
+ _: 1
905
+ }, 8, ["onClick"])) : createCommentVNode("", true),
906
+ _ctx.config.enableToggleMode ? (openBlock(), createBlock(_component_el_button, {
907
+ key: 4,
908
+ icon: "el-icon-s-grid",
909
+ size: "small",
910
+ onClick: _ctx.toggleMode
911
+ }, {
912
+ default: withCtx(() => [
913
+ _hoisted_7$1
914
+ ]),
915
+ _: 1
916
+ }, 8, ["onClick"])) : createCommentVNode("", true)
917
+ ]);
918
+ }
919
+ var GroupList = /* @__PURE__ */ _export_sfc(_sfc_main$p, [["render", _sfc_render$m]]);
920
+
921
+ const _sfc_main$o = defineComponent({
922
+ name: "m-form-panel",
923
+ components: { CaretBottom, CaretRight },
924
+ props: {
925
+ labelWidth: String,
926
+ model: {
927
+ type: Object,
928
+ default: () => ({})
929
+ },
930
+ config: {
931
+ type: Object,
932
+ default: () => ({})
933
+ },
934
+ prop: String,
935
+ size: String,
936
+ name: String
937
+ },
938
+ emits: ["change"],
939
+ setup(props, { emit }) {
940
+ const mForm = inject("mForm");
941
+ const expand = ref(props.config.expand !== false);
942
+ const items = computed(() => props.config.items);
943
+ const filter = (config) => filterFunction(mForm, config, props);
944
+ const changeHandler = () => emit("change", props.model);
945
+ return {
946
+ mForm,
947
+ expand,
948
+ items,
949
+ filter,
950
+ changeHandler
951
+ };
952
+ }
953
+ });
954
+ const _hoisted_1$c = { class: "clearfix" };
955
+ const _hoisted_2$3 = ["innerHTML"];
956
+ const _hoisted_3$3 = {
957
+ key: 0,
958
+ style: { "display": "flex" }
959
+ };
960
+ const _hoisted_4$2 = { style: { "flex": "1" } };
961
+ const _hoisted_5$1 = ["src"];
962
+ function _sfc_render$l(_ctx, _cache, $props, $setup, $data, $options) {
963
+ const _component_caret_bottom = resolveComponent("caret-bottom");
964
+ const _component_caret_right = resolveComponent("caret-right");
965
+ const _component_el_icon = resolveComponent("el-icon");
966
+ const _component_m_form_container = resolveComponent("m-form-container");
967
+ const _component_el_card = resolveComponent("el-card");
968
+ return _ctx.items && _ctx.items.length ? (openBlock(), createBlock(_component_el_card, {
969
+ key: 0,
970
+ class: "box-card m-form-panel",
971
+ "body-style": { display: _ctx.expand ? "block" : "none" }
972
+ }, {
973
+ header: withCtx(() => [
974
+ createElementVNode("div", _hoisted_1$c, [
975
+ createElementVNode("a", {
976
+ href: "javascript:",
977
+ style: { "width": "100%", "display": "block" },
978
+ onClick: _cache[0] || (_cache[0] = ($event) => _ctx.expand = !_ctx.expand)
979
+ }, [
980
+ createVNode(_component_el_icon, null, {
981
+ default: withCtx(() => [
982
+ _ctx.expand ? (openBlock(), createBlock(_component_caret_bottom, { key: 0 })) : (openBlock(), createBlock(_component_caret_right, { key: 1 }))
983
+ ]),
984
+ _: 1
985
+ }),
986
+ createTextVNode(" " + toDisplayString(_ctx.filter(_ctx.config.title)) + " ", 1),
987
+ _ctx.config && _ctx.config.extra ? (openBlock(), createElementBlock("span", {
988
+ key: 0,
989
+ innerHTML: _ctx.config.extra,
990
+ class: "m-form-tip"
991
+ }, null, 8, _hoisted_2$3)) : createCommentVNode("", true)
992
+ ])
993
+ ])
994
+ ]),
995
+ default: withCtx(() => [
996
+ createElementVNode("div", null, [
997
+ renderSlot(_ctx.$slots, "default"),
998
+ _ctx.config.schematic ? (openBlock(), createElementBlock("div", _hoisted_3$3, [
999
+ createElementVNode("div", _hoisted_4$2, [
1000
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.items, (item, index) => {
1001
+ return openBlock(), createBlock(_component_m_form_container, {
1002
+ key: item[_ctx.mForm?.keyProp || "__key"] ?? index,
1003
+ config: item,
1004
+ model: _ctx.name ? _ctx.model[_ctx.name] : _ctx.model,
1005
+ prop: _ctx.prop,
1006
+ size: _ctx.size,
1007
+ "label-width": _ctx.config.labelWidth || _ctx.labelWidth,
1008
+ onChange: _ctx.changeHandler
1009
+ }, null, 8, ["config", "model", "prop", "size", "label-width", "onChange"]);
1010
+ }), 128))
1011
+ ]),
1012
+ createElementVNode("img", {
1013
+ class: "m-form-schematic",
1014
+ src: _ctx.config.schematic
1015
+ }, null, 8, _hoisted_5$1)
1016
+ ])) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.items, (item, index) => {
1017
+ return openBlock(), createBlock(_component_m_form_container, {
1018
+ key: item[_ctx.mForm?.keyProp || "__key"] ?? index,
1019
+ config: item,
1020
+ model: _ctx.name ? _ctx.model[_ctx.name] : _ctx.model,
1021
+ prop: _ctx.prop,
1022
+ size: _ctx.size,
1023
+ "label-width": _ctx.config.labelWidth || _ctx.labelWidth,
1024
+ onChange: _ctx.changeHandler
1025
+ }, null, 8, ["config", "model", "prop", "size", "label-width", "onChange"]);
1026
+ }), 128))
1027
+ ])
1028
+ ]),
1029
+ _: 3
1030
+ }, 8, ["body-style"])) : createCommentVNode("", true);
1031
+ }
1032
+ var Panel = /* @__PURE__ */ _export_sfc(_sfc_main$o, [["render", _sfc_render$l]]);
1033
+
1034
+ const _sfc_main$n = defineComponent({
1035
+ name: "m-form-row",
1036
+ props: {
1037
+ labelWidth: String,
1038
+ expandMore: Boolean,
1039
+ model: {
1040
+ type: Object,
1041
+ default: () => ({})
1042
+ },
1043
+ config: {
1044
+ type: Object,
1045
+ default: () => ({})
1046
+ },
1047
+ prop: String,
1048
+ name: String,
1049
+ size: String
1050
+ },
1051
+ emits: ["change"],
1052
+ setup(props, { emit }) {
1053
+ const mForm = inject("mForm");
1054
+ const changeHandler = () => emit("change", props.name ? props.model[props.name] : props.model);
1055
+ return {
1056
+ mForm,
1057
+ display(config) {
1058
+ return display(mForm, config.display, props);
1059
+ },
1060
+ changeHandler
1061
+ };
1062
+ }
1063
+ });
1064
+ function _sfc_render$k(_ctx, _cache, $props, $setup, $data, $options) {
1065
+ const _component_m_form_container = resolveComponent("m-form-container");
1066
+ const _component_el_col = resolveComponent("el-col");
1067
+ const _component_el_row = resolveComponent("el-row");
1068
+ return openBlock(), createBlock(_component_el_row, { gutter: 10 }, {
1069
+ default: withCtx(() => [
1070
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.config.items, (col, index) => {
1071
+ return openBlock(), createBlock(_component_el_col, {
1072
+ style: normalizeStyle(!_ctx.display(col) || col.type === "hidden" ? "display: none" : ""),
1073
+ key: col[_ctx.mForm?.keyProp || "__key"] ?? index,
1074
+ span: col.span || _ctx.config.span || 24 / _ctx.config.items.length
1075
+ }, {
1076
+ default: withCtx(() => [
1077
+ createVNode(_component_m_form_container, {
1078
+ model: _ctx.name ? _ctx.model[_ctx.name] : _ctx.model,
1079
+ config: col,
1080
+ prop: _ctx.prop,
1081
+ "label-width": _ctx.config.labelWidth || _ctx.labelWidth,
1082
+ "expand-more": _ctx.expandMore,
1083
+ size: _ctx.size,
1084
+ onChange: _ctx.changeHandler
1085
+ }, null, 8, ["model", "config", "prop", "label-width", "expand-more", "size", "onChange"])
1086
+ ]),
1087
+ _: 2
1088
+ }, 1032, ["style", "span"]);
1089
+ }), 128))
1090
+ ]),
1091
+ _: 1
1092
+ });
1093
+ }
1094
+ var Row = /* @__PURE__ */ _export_sfc(_sfc_main$n, [["render", _sfc_render$k]]);
1095
+
1096
+ const _sfc_main$m = defineComponent({
1097
+ name: "m-form-step",
1098
+ props: {
1099
+ model: {
1100
+ type: Object,
1101
+ default: () => ({})
1102
+ },
1103
+ config: {
1104
+ type: Object,
1105
+ default: () => ({})
1106
+ },
1107
+ stepActive: {
1108
+ type: Number,
1109
+ default: () => 1
1110
+ },
1111
+ size: String,
1112
+ labelWidth: String
1113
+ },
1114
+ emits: ["change"],
1115
+ setup(props, { emit }) {
1116
+ const mForm = inject("mForm");
1117
+ const active = ref(1);
1118
+ watchEffect(() => {
1119
+ active.value = props.stepActive;
1120
+ });
1121
+ const stepClick = (index) => {
1122
+ active.value = index + 1;
1123
+ mForm?.$emit("update:stepActive", active.value);
1124
+ };
1125
+ const changeHandler = () => {
1126
+ emit("change", props.model);
1127
+ };
1128
+ return { mForm, active, stepClick, changeHandler };
1129
+ }
1130
+ });
1131
+ function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
1132
+ const _component_el_step = resolveComponent("el-step");
1133
+ const _component_el_steps = resolveComponent("el-steps");
1134
+ const _component_m_form_container = resolveComponent("m-form-container");
1135
+ return openBlock(), createElementBlock("div", null, [
1136
+ createVNode(_component_el_steps, {
1137
+ active: _ctx.active,
1138
+ "align-center": "",
1139
+ space: _ctx.config.space
1140
+ }, {
1141
+ default: withCtx(() => [
1142
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.config.items, (item, index) => {
1143
+ return openBlock(), createBlock(_component_el_step, {
1144
+ key: item.__key,
1145
+ title: item.title,
1146
+ active: _ctx.active,
1147
+ onClick: ($event) => _ctx.stepClick(index)
1148
+ }, null, 8, ["title", "active", "onClick"]);
1149
+ }), 128))
1150
+ ]),
1151
+ _: 1
1152
+ }, 8, ["active", "space"]),
1153
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.config.items, (step, index) => {
1154
+ return openBlock(), createElementBlock(Fragment, null, [
1155
+ (openBlock(true), createElementBlock(Fragment, null, renderList(step.items, (item) => {
1156
+ return openBlock(), createElementBlock(Fragment, null, [
1157
+ item ? withDirectives((openBlock(), createBlock(_component_m_form_container, {
1158
+ key: item[_ctx.mForm?.keyProp || "__key"],
1159
+ config: item,
1160
+ model: step.name ? _ctx.model[step.name] : _ctx.model,
1161
+ prop: step.name,
1162
+ size: _ctx.size,
1163
+ "label-width": _ctx.config.labelWidth || _ctx.labelWidth,
1164
+ onChange: _ctx.changeHandler
1165
+ }, null, 8, ["config", "model", "prop", "size", "label-width", "onChange"])), [
1166
+ [vShow, _ctx.active - 1 === index]
1167
+ ]) : createCommentVNode("", true)
1168
+ ], 64);
1169
+ }), 256))
1170
+ ], 64);
1171
+ }), 256))
1172
+ ]);
1173
+ }
1174
+ var MStep = /* @__PURE__ */ _export_sfc(_sfc_main$m, [["render", _sfc_render$j]]);
1175
+
1176
+ let loadedAMapJS = false;
1177
+ let firstLoadingAMapJS = true;
1178
+ const _sfc_main$l = defineComponent({
1179
+ name: "m-form-table",
1180
+ props: {
1181
+ name: {
1182
+ type: String,
1183
+ required: true
1184
+ },
1185
+ model: {
1186
+ type: Object,
1187
+ required: true,
1188
+ default: () => ({})
1189
+ },
1190
+ config: {
1191
+ type: Object,
1192
+ required: true,
1193
+ default: () => ({})
1194
+ },
1195
+ prop: {
1196
+ type: String
1197
+ },
1198
+ labelWidth: {
1199
+ type: String
1200
+ },
1201
+ sort: {
1202
+ type: Boolean,
1203
+ default: false
1204
+ },
1205
+ sortKey: {
1206
+ type: String,
1207
+ default: ""
1208
+ },
1209
+ text: {
1210
+ type: String
1211
+ },
1212
+ size: String,
1213
+ enableToggleMode: {
1214
+ type: Boolean,
1215
+ default: true
1216
+ }
1217
+ },
1218
+ emits: ["change", "select"],
1219
+ setup(props, { emit }) {
1220
+ let timer = null;
1221
+ const mForm = inject("mForm");
1222
+ const elTable = ref();
1223
+ const excelBtn = ref();
1224
+ const mTable = ref();
1225
+ const pagesize = ref(10);
1226
+ const pagecontext = ref(0);
1227
+ const updateKey = ref(1);
1228
+ const isFullscreen = ref(false);
1229
+ const modelName = computed(() => props.name || props.config.name || "");
1230
+ const sortChange = ({ prop, order }) => {
1231
+ if (order === "ascending") {
1232
+ props.model[modelName.value] = props.model[modelName.value].sort((a, b) => a[prop] - b[prop]);
1233
+ } else if (order === "descending") {
1234
+ props.model[modelName.value] = props.model[modelName.value].sort((a, b) => b[prop] - a[prop]);
1235
+ }
1236
+ };
1237
+ const foreUpdate = () => {
1238
+ updateKey.value += 1;
1239
+ setTimeout(() => rowDrop());
1240
+ };
1241
+ const swapArray = (index1, index2) => {
1242
+ [props.model[modelName.value][index1]] = props.model[modelName.value].splice(index2, 1, props.model[modelName.value][index1]);
1243
+ if (props.sortKey) {
1244
+ for (let i = props.model[modelName.value].length - 1, v = 0; i >= 0; i--, v++) {
1245
+ props.model[modelName.value][v][props.sortKey] = i;
1246
+ }
1247
+ }
1248
+ mForm?.$emit("field-change", props.prop, props.model[modelName.value]);
1249
+ };
1250
+ const rowDrop = () => {
1251
+ const tableEl = elTable.value?.$el;
1252
+ if (tableEl?.querySelectorAll(".el-table__body > tbody")) {
1253
+ const el = tableEl.querySelectorAll(".el-table__body > tbody")[0];
1254
+ const sortable = Sortable.create(el, {
1255
+ onEnd: ({ newIndex, oldIndex }) => {
1256
+ if (typeof newIndex === "undefined")
1257
+ return;
1258
+ if (typeof oldIndex === "undefined")
1259
+ return;
1260
+ swapArray(newIndex, oldIndex);
1261
+ emit("change", props.model[modelName.value]);
1262
+ foreUpdate();
1263
+ sortable.destroy();
1264
+ mForm?.$emit("field-change", props.prop, props.model[modelName.value]);
1265
+ sleep(1e3).then(() => {
1266
+ const eltrs = tableEl.querySelectorAll(".el-table__body > tbody > tr");
1267
+ if (eltrs?.[newIndex]) {
1268
+ eltrs[newIndex].style.backgroundColor = "rgba(243, 89, 59, 0.2)";
1269
+ sleep(1e3).then(() => {
1270
+ eltrs[newIndex].style.backgroundColor = "";
1271
+ });
1272
+ }
1273
+ });
1274
+ }
1275
+ });
1276
+ }
1277
+ };
1278
+ const newHandler = async (row) => {
1279
+ if (props.config.max && props.model[modelName.value].length >= props.config.max) {
1280
+ ElMessage.error(`\u6700\u591A\u65B0\u589E\u914D\u7F6E\u4E0D\u80FD\u8D85\u8FC7${props.config.max}\u6761`);
1281
+ return;
1282
+ }
1283
+ const columns = props.config.items;
1284
+ const enumValues = props.config.enum || [];
1285
+ let enumV = [];
1286
+ const { length } = props.model[modelName.value];
1287
+ const key = props.config.key || "id";
1288
+ let inputs = {};
1289
+ if (enumValues.length) {
1290
+ if (length >= enumValues.length) {
1291
+ return;
1292
+ }
1293
+ enumV = enumValues.filter((item) => {
1294
+ let i = 0;
1295
+ for (; i < length; i++) {
1296
+ if (item[key] === props.model[modelName.value][i][key]) {
1297
+ break;
1298
+ }
1299
+ }
1300
+ return i === length;
1301
+ });
1302
+ if (enumV.length > 0) {
1303
+ inputs = enumV[0];
1304
+ }
1305
+ } else if (Array.isArray(row)) {
1306
+ columns.forEach((column, index) => {
1307
+ column.name && (inputs[column.name] = row[index]);
1308
+ });
1309
+ } else {
1310
+ if (typeof props.config.defaultAdd === "function") {
1311
+ inputs = await props.config.defaultAdd(mForm, {
1312
+ model: props.model[modelName.value],
1313
+ formValue: mForm?.values
1314
+ });
1315
+ } else if (props.config.defaultAdd) {
1316
+ inputs = props.config.defaultAdd;
1317
+ }
1318
+ inputs = await initValue(mForm, {
1319
+ config: columns,
1320
+ initValues: inputs
1321
+ });
1322
+ }
1323
+ if (props.sortKey && length) {
1324
+ inputs[props.sortKey] = props.model[modelName.value][length - 1][props.sortKey] - 1;
1325
+ }
1326
+ props.model[modelName.value].push(inputs);
1327
+ emit("change", props.model[modelName.value]);
1328
+ };
1329
+ if (!loadedAMapJS && firstLoadingAMapJS && !globalThis.XLSX) {
1330
+ firstLoadingAMapJS = false;
1331
+ asyncLoadJs("https://cdn.bootcdn.net/ajax/libs/xlsx/0.17.0/xlsx.full.min.js").then(() => {
1332
+ loadedAMapJS = true;
1333
+ }).catch(() => {
1334
+ firstLoadingAMapJS = true;
1335
+ });
1336
+ }
1337
+ onMounted(() => {
1338
+ if (props.config.defautSort) {
1339
+ sortChange(props.config.defautSort);
1340
+ }
1341
+ if (props.sort && props.sortKey) {
1342
+ props.model[modelName.value].sort((a, b) => b[props.sortKey] - a[props.sortKey]);
1343
+ }
1344
+ if (props.config.dropSort) {
1345
+ rowDrop();
1346
+ }
1347
+ });
1348
+ return {
1349
+ mForm,
1350
+ pagesize,
1351
+ pagecontext,
1352
+ foreUpdate,
1353
+ isFullscreen,
1354
+ elTable,
1355
+ mTable,
1356
+ excelBtn,
1357
+ modelName,
1358
+ updateKey,
1359
+ ArrowDown,
1360
+ ArrowUp,
1361
+ Delete,
1362
+ data: computed(() => props.model[modelName.value].filter((item, index) => index >= pagecontext.value * pagesize.value && index + 1 <= (pagecontext.value + 1) * pagesize.value)),
1363
+ addable: computed(() => {
1364
+ if (!props.model[modelName.value].length) {
1365
+ return true;
1366
+ }
1367
+ if (typeof props.config.addable === "function") {
1368
+ return props.config.addable(mForm, {
1369
+ model: props.model[modelName.value],
1370
+ formValue: mForm?.values,
1371
+ prop: props.prop
1372
+ });
1373
+ }
1374
+ return typeof props.config.addable === "undefined" ? true : props.config.addable;
1375
+ }),
1376
+ selection: computed(() => {
1377
+ if (typeof props.config.selection === "function") {
1378
+ return props.config.selection(mForm, { model: props.model[modelName.value] });
1379
+ }
1380
+ return props.config.selection;
1381
+ }),
1382
+ importable: computed(() => {
1383
+ if (typeof props.config.importable === "function") {
1384
+ return props.config.importable(mForm, {
1385
+ formValue: mForm?.values,
1386
+ model: props.model[modelName.value]
1387
+ });
1388
+ }
1389
+ return typeof props.config.importable === "undefined" ? false : props.config.importable;
1390
+ }),
1391
+ sortChange,
1392
+ display(fuc) {
1393
+ return display(mForm, fuc, props);
1394
+ },
1395
+ itemExtra(fuc, index) {
1396
+ if (typeof fuc === "function") {
1397
+ return fuc(mForm, {
1398
+ values: mForm?.initValues,
1399
+ model: props.model,
1400
+ formValue: mForm ? mForm.values : props.model,
1401
+ prop: props.prop,
1402
+ index
1403
+ });
1404
+ }
1405
+ return fuc;
1406
+ },
1407
+ newHandler,
1408
+ removeHandler(index) {
1409
+ props.model[modelName.value].splice(index, 1);
1410
+ emit("change", props.model[modelName.value]);
1411
+ },
1412
+ selectHandle(selection, row) {
1413
+ if (typeof props.config.selection === "string" && props.config.selection === "single") {
1414
+ elTable.value?.clearSelection();
1415
+ elTable.value?.toggleRowSelection(row, true);
1416
+ }
1417
+ emit("select", selection, row);
1418
+ if (typeof props.config.onSelect === "function") {
1419
+ props.config.onSelect(mForm, { selection, row });
1420
+ }
1421
+ },
1422
+ toggleRowSelection(row, selected) {
1423
+ elTable.value?.toggleRowSelection.call(elTable.value, row, selected);
1424
+ },
1425
+ makeConfig(config) {
1426
+ const newConfig = cloneDeep(config);
1427
+ delete newConfig.display;
1428
+ return newConfig;
1429
+ },
1430
+ upHandler(index) {
1431
+ if (timer) {
1432
+ clearTimeout(timer);
1433
+ }
1434
+ timer = setTimeout(() => {
1435
+ swapArray(index, index - 1);
1436
+ }, 300);
1437
+ },
1438
+ topHandler(index) {
1439
+ if (timer) {
1440
+ clearTimeout(timer);
1441
+ }
1442
+ const moveNum = index;
1443
+ for (let i = 0; i < moveNum; i++) {
1444
+ swapArray(index, index - 1);
1445
+ index -= 1;
1446
+ }
1447
+ },
1448
+ downHandler(index) {
1449
+ if (timer) {
1450
+ clearTimeout(timer);
1451
+ }
1452
+ timer = setTimeout(() => {
1453
+ swapArray(index, index + 1);
1454
+ }, 300);
1455
+ },
1456
+ bottomHandler(index) {
1457
+ if (timer) {
1458
+ clearTimeout(timer);
1459
+ }
1460
+ const moveNum = props.model[modelName.value].length - 1 - index;
1461
+ for (let i = 0; i < moveNum; i++) {
1462
+ swapArray(index, index + 1);
1463
+ index += 1;
1464
+ }
1465
+ },
1466
+ showDelete(index) {
1467
+ const deleteFunc = props.config.delete;
1468
+ if (deleteFunc && typeof deleteFunc === "function") {
1469
+ return deleteFunc(props.model[modelName.value], index, mForm?.values);
1470
+ }
1471
+ return true;
1472
+ },
1473
+ clearHandler() {
1474
+ const len = props.model[modelName.value].length;
1475
+ props.model[modelName.value].splice(0, len);
1476
+ mForm?.$emit("field-change", props.prop, props.model[modelName.value]);
1477
+ },
1478
+ excelHandler(file) {
1479
+ if (!file || !file.raw) {
1480
+ return false;
1481
+ }
1482
+ const reader = new FileReader();
1483
+ reader.onload = () => {
1484
+ const data = reader.result;
1485
+ const pdata = globalThis.XLSX.read(data, { type: "array" });
1486
+ pdata.SheetNames.forEach((sheetName) => {
1487
+ const arr = globalThis.XLSX.utils.sheet_to_json(pdata.Sheets[sheetName], { header: 1 });
1488
+ if (arr?.[0]) {
1489
+ arr.forEach((row) => {
1490
+ newHandler(row);
1491
+ });
1492
+ }
1493
+ setTimeout(() => {
1494
+ excelBtn.value?.clearFiles();
1495
+ }, 300);
1496
+ });
1497
+ };
1498
+ reader.readAsArrayBuffer(file.raw);
1499
+ return false;
1500
+ },
1501
+ handleSizeChange(val) {
1502
+ pagesize.value = val;
1503
+ },
1504
+ handleCurrentChange(val) {
1505
+ pagecontext.value = val - 1;
1506
+ },
1507
+ toggleMode() {
1508
+ const calcLabelWidth = (label) => {
1509
+ if (!label)
1510
+ return "0px";
1511
+ const zhLength = label.match(/[^\x00-\xff]/g)?.length || 0;
1512
+ const chLength = label.length - zhLength;
1513
+ return `${Math.max(chLength * 8 + zhLength * 20, 80)}px`;
1514
+ };
1515
+ props.config.type = "groupList";
1516
+ props.config.enableToggleMode = true;
1517
+ props.config.tableItems = props.config.items;
1518
+ props.config.items = props.config.groupItems || props.config.items.map((item) => {
1519
+ const text = item.text || item.label;
1520
+ const labelWidth = calcLabelWidth(text);
1521
+ return {
1522
+ ...item,
1523
+ text,
1524
+ labelWidth,
1525
+ span: item.span || 12
1526
+ };
1527
+ });
1528
+ },
1529
+ toggleFullscreen() {
1530
+ if (isFullscreen.value) {
1531
+ mTable.value?.classList.remove("fixed");
1532
+ isFullscreen.value = false;
1533
+ } else {
1534
+ mTable.value?.classList.add("fixed");
1535
+ isFullscreen.value = true;
1536
+ }
1537
+ },
1538
+ getProp(index) {
1539
+ const { prop } = toRefs(props);
1540
+ return `${prop.value}${prop.value ? "." : ""}${index + 1 + pagecontext.value * pagesize.value - 1}`;
1541
+ }
1542
+ };
1543
+ }
1544
+ });
1545
+ const _hoisted_1$b = ["innerHTML"];
1546
+ const _hoisted_2$2 = { class: "el-form-item__content" };
1547
+ const _hoisted_3$2 = ["innerHTML"];
1548
+ const _hoisted_4$1 = /* @__PURE__ */ createTextVNode("\u6DFB\u52A0");
1549
+ const _hoisted_5 = /* @__PURE__ */ createTextVNode(" \xA0 ");
1550
+ const _hoisted_6 = /* @__PURE__ */ createTextVNode("\u5C55\u5F00\u914D\u7F6E");
1551
+ const _hoisted_7 = /* @__PURE__ */ createTextVNode("\u5BFC\u5165EXCEL");
1552
+ const _hoisted_8 = /* @__PURE__ */ createTextVNode("\xA0 ");
1553
+ const _hoisted_9 = /* @__PURE__ */ createTextVNode("\u6E05\u7A7A");
1554
+ const _hoisted_10 = {
1555
+ class: "bottom",
1556
+ style: { "text-align": "right" }
1557
+ };
1558
+ function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
1559
+ const _component_el_table_column = resolveComponent("el-table-column");
1560
+ const _component_el_button = resolveComponent("el-button");
1561
+ const _component_el_tooltip = resolveComponent("el-tooltip");
1562
+ const _component_m_form_container = resolveComponent("m-form-container");
1563
+ const _component_el_table = resolveComponent("el-table");
1564
+ const _component_el_upload = resolveComponent("el-upload");
1565
+ const _component_el_pagination = resolveComponent("el-pagination");
1566
+ return openBlock(), createElementBlock("div", {
1567
+ ref: "mTable",
1568
+ class: normalizeClass(["m-fields-table", { "m-fields-table-item-extra": _ctx.config.itemExtra }])
1569
+ }, [
1570
+ _ctx.config.extra ? (openBlock(), createElementBlock("span", {
1571
+ key: 0,
1572
+ style: { "color": "rgba(0, 0, 0, 0.45)" },
1573
+ innerHTML: _ctx.config.extra
1574
+ }, null, 8, _hoisted_1$b)) : createCommentVNode("", true),
1575
+ createElementVNode("div", _hoisted_2$2, [
1576
+ createVNode(_component_el_tooltip, {
1577
+ content: "\u62D6\u62FD\u53EF\u6392\u5E8F",
1578
+ placement: "left-start",
1579
+ disabled: _ctx.config.dropSort !== true
1580
+ }, {
1581
+ default: withCtx(() => [
1582
+ _ctx.model[_ctx.modelName] ? (openBlock(), createBlock(_component_el_table, {
1583
+ ref: "elTable",
1584
+ style: { "width": "100%" },
1585
+ data: _ctx.model[_ctx.modelName],
1586
+ border: _ctx.config.border,
1587
+ "max-height": _ctx.config.maxHeight,
1588
+ "default-expand-all": true,
1589
+ key: _ctx.updateKey,
1590
+ onSelect: _ctx.selectHandle,
1591
+ onSortChange: _ctx.sortChange
1592
+ }, {
1593
+ default: withCtx(() => [
1594
+ _ctx.config.itemExtra ? (openBlock(), createBlock(_component_el_table_column, {
1595
+ key: 0,
1596
+ fixed: "left",
1597
+ width: "30",
1598
+ type: "expand"
1599
+ }, {
1600
+ default: withCtx((scope) => [
1601
+ createElementVNode("span", {
1602
+ innerHTML: _ctx.itemExtra(_ctx.config.itemExtra, scope.$index),
1603
+ class: "m-form-tip"
1604
+ }, null, 8, _hoisted_3$2)
1605
+ ]),
1606
+ _: 1
1607
+ })) : createCommentVNode("", true),
1608
+ createVNode(_component_el_table_column, {
1609
+ label: "\u64CD\u4F5C",
1610
+ width: "50",
1611
+ fixed: _ctx.config.fixed === false ? void 0 : "left"
1612
+ }, {
1613
+ default: withCtx((scope) => [
1614
+ withDirectives(createVNode(_component_el_button, {
1615
+ style: { "color": "#f56c6c" },
1616
+ type: "text",
1617
+ icon: _ctx.Delete,
1618
+ onClick: ($event) => _ctx.removeHandler(scope.$index + 1 + _ctx.pagecontext * _ctx.pagesize - 1)
1619
+ }, null, 8, ["icon", "onClick"]), [
1620
+ [vShow, _ctx.showDelete(scope.$index + 1 + _ctx.pagecontext * _ctx.pagesize - 1)]
1621
+ ])
1622
+ ]),
1623
+ _: 1
1624
+ }, 8, ["fixed"]),
1625
+ _ctx.sort && _ctx.model[_ctx.modelName] && _ctx.model[_ctx.modelName].length > 1 ? (openBlock(), createBlock(_component_el_table_column, {
1626
+ key: 1,
1627
+ label: "\u6392\u5E8F",
1628
+ width: "70"
1629
+ }, {
1630
+ default: withCtx((scope) => [
1631
+ scope.$index + 1 + _ctx.pagecontext * _ctx.pagesize - 1 !== 0 ? (openBlock(), createBlock(_component_el_tooltip, {
1632
+ key: 0,
1633
+ content: "\u70B9\u51FB\u4E0A\u79FB\uFF0C\u53CC\u51FB\u7F6E\u9876",
1634
+ placement: "top"
1635
+ }, {
1636
+ default: withCtx(() => [
1637
+ createVNode(_component_el_button, {
1638
+ plain: "",
1639
+ size: "small",
1640
+ icon: _ctx.ArrowUp,
1641
+ type: "text",
1642
+ onClick: ($event) => _ctx.upHandler(scope.$index + 1 + _ctx.pagecontext * _ctx.pagesize - 1),
1643
+ onDblclick: ($event) => _ctx.topHandler(scope.$index + 1 + _ctx.pagecontext * _ctx.pagesize - 1)
1644
+ }, null, 8, ["icon", "onClick", "onDblclick"])
1645
+ ]),
1646
+ _: 2
1647
+ }, 1024)) : createCommentVNode("", true),
1648
+ scope.$index + 1 + _ctx.pagecontext * _ctx.pagesize - 1 !== _ctx.model[_ctx.modelName].length - 1 ? (openBlock(), createBlock(_component_el_tooltip, {
1649
+ key: 1,
1650
+ content: "\u70B9\u51FB\u4E0B\u79FB\uFF0C\u53CC\u51FB\u7F6E\u5E95",
1651
+ placement: "top"
1652
+ }, {
1653
+ default: withCtx(() => [
1654
+ createVNode(_component_el_button, {
1655
+ plain: "",
1656
+ size: "small",
1657
+ icon: _ctx.ArrowDown,
1658
+ type: "text",
1659
+ onClick: ($event) => _ctx.downHandler(scope.$index + 1 + _ctx.pagecontext * _ctx.pagesize - 1),
1660
+ onDblclick: ($event) => _ctx.bottomHandler(scope.$index + 1 + _ctx.pagecontext * _ctx.pagesize - 1)
1661
+ }, null, 8, ["icon", "onClick", "onDblclick"])
1662
+ ]),
1663
+ _: 2
1664
+ }, 1024)) : createCommentVNode("", true)
1665
+ ]),
1666
+ _: 1
1667
+ })) : createCommentVNode("", true),
1668
+ _ctx.selection ? (openBlock(), createBlock(_component_el_table_column, {
1669
+ key: 2,
1670
+ align: "center",
1671
+ "header-align": "center",
1672
+ type: "selection",
1673
+ width: "45"
1674
+ })) : createCommentVNode("", true),
1675
+ createVNode(_component_el_table_column, {
1676
+ width: "50",
1677
+ label: "\u5E8F\u53F7"
1678
+ }, {
1679
+ default: withCtx((scope) => [
1680
+ createTextVNode(toDisplayString(scope.$index + 1 + _ctx.pagecontext * _ctx.pagesize), 1)
1681
+ ]),
1682
+ _: 1
1683
+ }),
1684
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.config.items, (column, index) => {
1685
+ return openBlock(), createElementBlock(Fragment, null, [
1686
+ column.type !== "hidden" && _ctx.display(column.display) ? (openBlock(), createBlock(_component_el_table_column, {
1687
+ prop: column.name,
1688
+ width: column.width,
1689
+ label: column.label,
1690
+ sortable: column.sortable,
1691
+ "sort-orders": ["ascending", "descending"],
1692
+ key: column[_ctx.mForm?.keyProp || "__key"] ?? index,
1693
+ "class-name": _ctx.config.dropSort === true ? "el-table__column--dropable" : ""
1694
+ }, {
1695
+ default: withCtx((scope) => [
1696
+ scope.$index > -1 ? (openBlock(), createBlock(_component_m_form_container, {
1697
+ key: 0,
1698
+ labelWidth: "0",
1699
+ prop: _ctx.getProp(scope.$index),
1700
+ rules: column.rules,
1701
+ config: _ctx.makeConfig(column),
1702
+ model: scope.row,
1703
+ size: _ctx.size,
1704
+ onChange: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("change", _ctx.model[_ctx.modelName]))
1705
+ }, null, 8, ["prop", "rules", "config", "model", "size"])) : createCommentVNode("", true)
1706
+ ]),
1707
+ _: 2
1708
+ }, 1032, ["prop", "width", "label", "sortable", "class-name"])) : createCommentVNode("", true)
1709
+ ], 64);
1710
+ }), 256))
1711
+ ]),
1712
+ _: 1
1713
+ }, 8, ["data", "border", "max-height", "onSelect", "onSortChange"])) : createCommentVNode("", true)
1714
+ ]),
1715
+ _: 1
1716
+ }, 8, ["disabled"]),
1717
+ renderSlot(_ctx.$slots, "default"),
1718
+ _ctx.addable ? (openBlock(), createBlock(_component_el_button, {
1719
+ key: 0,
1720
+ size: "small",
1721
+ type: "primary",
1722
+ plain: "",
1723
+ onClick: _cache[1] || (_cache[1] = ($event) => _ctx.newHandler())
1724
+ }, {
1725
+ default: withCtx(() => [
1726
+ _hoisted_4$1
1727
+ ]),
1728
+ _: 1
1729
+ })) : createCommentVNode("", true),
1730
+ _hoisted_5,
1731
+ _ctx.enableToggleMode && !_ctx.isFullscreen ? (openBlock(), createBlock(_component_el_button, {
1732
+ key: 1,
1733
+ icon: "el-icon-s-grid",
1734
+ size: "small",
1735
+ onClick: _ctx.toggleMode
1736
+ }, {
1737
+ default: withCtx(() => [
1738
+ _hoisted_6
1739
+ ]),
1740
+ _: 1
1741
+ }, 8, ["onClick"])) : createCommentVNode("", true),
1742
+ _ctx.config.enableFullscreen !== false ? (openBlock(), createBlock(_component_el_button, {
1743
+ key: 2,
1744
+ icon: "el-icon-s-grid",
1745
+ size: "small",
1746
+ onClick: _ctx.toggleFullscreen
1747
+ }, {
1748
+ default: withCtx(() => [
1749
+ createTextVNode(toDisplayString(_ctx.isFullscreen ? "\u9000\u51FA\u5168\u5C4F" : "\u5168\u5C4F\u7F16\u8F91"), 1)
1750
+ ]),
1751
+ _: 1
1752
+ }, 8, ["onClick"])) : createCommentVNode("", true),
1753
+ _ctx.importable ? (openBlock(), createBlock(_component_el_upload, {
1754
+ key: 3,
1755
+ ref: "excelBtn",
1756
+ action: "/noop",
1757
+ "on-change": _ctx.excelHandler,
1758
+ "auto-upload": false,
1759
+ style: { "display": "inline-block" }
1760
+ }, {
1761
+ default: withCtx(() => [
1762
+ createVNode(_component_el_button, {
1763
+ size: "small",
1764
+ type: "success",
1765
+ plain: ""
1766
+ }, {
1767
+ default: withCtx(() => [
1768
+ _hoisted_7
1769
+ ]),
1770
+ _: 1
1771
+ })
1772
+ ]),
1773
+ _: 1
1774
+ }, 8, ["on-change"])) : createCommentVNode("", true),
1775
+ _hoisted_8,
1776
+ _ctx.importable ? (openBlock(), createBlock(_component_el_button, {
1777
+ key: 4,
1778
+ size: "small",
1779
+ type: "warning",
1780
+ plain: "",
1781
+ onClick: _cache[2] || (_cache[2] = ($event) => _ctx.clearHandler())
1782
+ }, {
1783
+ default: withCtx(() => [
1784
+ _hoisted_9
1785
+ ]),
1786
+ _: 1
1787
+ })) : createCommentVNode("", true)
1788
+ ]),
1789
+ createElementVNode("div", _hoisted_10, [
1790
+ createVNode(_component_el_pagination, {
1791
+ layout: "total, sizes, prev, pager, next, jumper",
1792
+ "hide-on-single-page": _ctx.model[_ctx.modelName].length < _ctx.pagesize,
1793
+ "current-page": _ctx.pagecontext + 1,
1794
+ "page-sizes": [_ctx.pagesize, 60, 120, 300],
1795
+ "page-size": _ctx.pagesize,
1796
+ total: _ctx.model[_ctx.modelName].length,
1797
+ onSizeChange: _ctx.handleSizeChange,
1798
+ onCurrentChange: _ctx.handleCurrentChange
1799
+ }, null, 8, ["hide-on-single-page", "current-page", "page-sizes", "page-size", "total", "onSizeChange", "onCurrentChange"])
1800
+ ])
1801
+ ], 2);
1802
+ }
1803
+ var Table = /* @__PURE__ */ _export_sfc(_sfc_main$l, [["render", _sfc_render$i]]);
1804
+
1805
+ const getActive = (mForm, props, activeTabName) => {
1806
+ const { config, model, prop } = props;
1807
+ const { active } = config;
1808
+ if (typeof active === "function")
1809
+ return active(mForm, { model, formValue: mForm?.values, prop });
1810
+ if (+activeTabName >= props.config.items.length)
1811
+ return "0";
1812
+ if (typeof active !== "undefined")
1813
+ return active;
1814
+ return "0";
1815
+ };
1816
+ const tabClickHandler = (mForm, tab, props) => {
1817
+ const { config, model, prop } = props;
1818
+ if (typeof config.onTabClick === "function") {
1819
+ config.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop });
1820
+ }
1821
+ const tabConfig = config.items.find((item) => tab.name === item.status);
1822
+ if (tabConfig && typeof tabConfig.onTabClick === "function") {
1823
+ tabConfig.onTabClick(mForm, tab, { model, formValue: mForm?.values, prop });
1824
+ }
1825
+ };
1826
+ const Tab = defineComponent({
1827
+ name: "m-form-tab",
1828
+ props: {
1829
+ labelWidth: String,
1830
+ expandMore: Boolean,
1831
+ model: {
1832
+ type: Object,
1833
+ default: () => ({})
1834
+ },
1835
+ config: {
1836
+ type: Object,
1837
+ default: () => ({})
1838
+ },
1839
+ prop: String,
1840
+ size: String
1841
+ },
1842
+ emits: {
1843
+ change(values) {
1844
+ return values;
1845
+ }
1846
+ },
1847
+ setup(props, { emit }) {
1848
+ const mForm = inject("mForm");
1849
+ const activeTabName = ref(getActive(mForm, props, ""));
1850
+ const tabs = computed(() => {
1851
+ if (props.config.dynamic) {
1852
+ if (!props.config.name)
1853
+ throw new Error("dynamic tab \u5FC5\u987B\u914D\u7F6Ename");
1854
+ return props.model[props.config.name] || [];
1855
+ }
1856
+ return props.config.items;
1857
+ });
1858
+ const filter = (config) => filterFunction(mForm, config, props);
1859
+ watchEffect(() => {
1860
+ if (typeof props.config.activeChange === "function") {
1861
+ props.config.activeChange(mForm, activeTabName.value, {
1862
+ model: props.model,
1863
+ prop: props.prop
1864
+ });
1865
+ }
1866
+ });
1867
+ return {
1868
+ mForm,
1869
+ activeTabName,
1870
+ tabs,
1871
+ filter,
1872
+ tabItems: (tab) => props.config.dynamic ? props.config.items : tab.items,
1873
+ tabClickHandler: (tab) => tabClickHandler(mForm, tab, props),
1874
+ onTabAdd: () => {
1875
+ if (!props.config.name)
1876
+ throw new Error("dynamic tab \u5FC5\u987B\u914D\u7F6Ename");
1877
+ if (typeof props.config.onTabAdd === "function") {
1878
+ props.config.onTabAdd(mForm, { model: props.model });
1879
+ } else if (tabs.value.length > 0) {
1880
+ const newObj = cloneDeep(tabs.value[0]);
1881
+ newObj.title = `\u6807\u7B7E${tabs.value.length + 1}`;
1882
+ props.model[props.config.name].push(newObj);
1883
+ }
1884
+ emit("change", props.model);
1885
+ mForm?.$emit("field-change", props.prop, props.model[props.config.name]);
1886
+ },
1887
+ onTabRemove: (tabName) => {
1888
+ if (!props.config.name)
1889
+ throw new Error("dynamic tab \u5FC5\u987B\u914D\u7F6Ename");
1890
+ if (typeof props.config.onTabRemove === "function") {
1891
+ props.config.onTabRemove(mForm, tabName, { model: props.model });
1892
+ } else {
1893
+ props.model[props.config.name].splice(+tabName, 1);
1894
+ if (tabName < activeTabName.value || activeTabName.value >= props.model[props.config.name].length) {
1895
+ activeTabName.value = (+activeTabName.value - 1).toString();
1896
+ tabClickHandler(mForm, { name: activeTabName.value }, props);
1897
+ }
1898
+ }
1899
+ emit("change", props.model);
1900
+ mForm?.$emit("field-change", props.prop, props.model[props.config.name]);
1901
+ },
1902
+ display: (displayConfig) => display(mForm, displayConfig, props),
1903
+ changeHandler: () => {
1904
+ emit("change", props.model);
1905
+ if (typeof props.config.onChange === "function") {
1906
+ props.config.onChange(mForm, { model: props.model });
1907
+ }
1908
+ }
1909
+ };
1910
+ }
1911
+ });
1912
+ const _sfc_main$k = Tab;
1913
+ function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
1914
+ const _component_m_form_container = resolveComponent("m-form-container");
1915
+ const _component_el_tab_pane = resolveComponent("el-tab-pane");
1916
+ const _component_el_tabs = resolveComponent("el-tabs");
1917
+ return openBlock(), createBlock(_component_el_tabs, {
1918
+ modelValue: _ctx.activeTabName,
1919
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.activeTabName = $event),
1920
+ class: normalizeClass(_ctx.config.dynamic ? "magic-form-dynamic-tab" : "magic-form-tab"),
1921
+ type: _ctx.config.tabType,
1922
+ editable: _ctx.config.editable || false,
1923
+ "tab-position": _ctx.config.tabPosition || "top",
1924
+ onTabClick: _ctx.tabClickHandler,
1925
+ onTabAdd: _ctx.onTabAdd,
1926
+ onTabRemove: _ctx.onTabRemove
1927
+ }, {
1928
+ default: withCtx(() => [
1929
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.tabs, (tab, tabIndex) => {
1930
+ return openBlock(), createElementBlock(Fragment, null, [
1931
+ _ctx.display(tab.display) && _ctx.tabItems(tab).length ? (openBlock(), createBlock(_component_el_tab_pane, {
1932
+ key: tab[_ctx.mForm?.keyProp || "__key"] ?? tabIndex,
1933
+ name: _ctx.filter(tab.status) || tabIndex.toString(),
1934
+ label: _ctx.filter(tab.title),
1935
+ lazy: tab.lazy || false
1936
+ }, {
1937
+ default: withCtx(() => [
1938
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.tabItems(tab), (item) => {
1939
+ return openBlock(), createBlock(_component_m_form_container, {
1940
+ key: item[_ctx.mForm?.keyProp || "__key"],
1941
+ config: item,
1942
+ model: _ctx.config.dynamic ? _ctx.model[_ctx.config.name || ""][tabIndex] : tab.name ? _ctx.model[tab.name] : _ctx.model,
1943
+ prop: _ctx.config.dynamic ? `${_ctx.prop}${_ctx.prop ? "." : ""}${String(tabIndex)}` : _ctx.prop,
1944
+ size: _ctx.size,
1945
+ "label-width": tab.labelWidth || _ctx.labelWidth,
1946
+ "expand-more": _ctx.expandMore,
1947
+ onChange: _ctx.changeHandler
1948
+ }, null, 8, ["config", "model", "prop", "size", "label-width", "expand-more", "onChange"]);
1949
+ }), 128))
1950
+ ]),
1951
+ _: 2
1952
+ }, 1032, ["name", "label", "lazy"])) : createCommentVNode("", true)
1953
+ ], 64);
1954
+ }), 256))
1955
+ ]),
1956
+ _: 1
1957
+ }, 8, ["modelValue", "class", "type", "editable", "tab-position", "onTabClick", "onTabAdd", "onTabRemove"]);
1958
+ }
1959
+ var Tabs = /* @__PURE__ */ _export_sfc(_sfc_main$k, [["render", _sfc_render$h]]);
1960
+
1961
+ let $MAGIC_FORM = {};
1962
+ const setConfig = (option) => {
1963
+ $MAGIC_FORM = option;
1964
+ };
1965
+ const getConfig = (key) => $MAGIC_FORM[key];
1966
+
1967
+ var fieldProps = {
1968
+ model: {
1969
+ type: Object,
1970
+ required: true,
1971
+ default: () => ({})
1972
+ },
1973
+ name: {
1974
+ type: String,
1975
+ default: ""
1976
+ },
1977
+ disabled: {
1978
+ type: Boolean,
1979
+ default: false
1980
+ },
1981
+ size: String,
1982
+ prop: String,
1983
+ initValues: Object,
1984
+ values: Object
1985
+ };
1986
+
1987
+ const useAddField = (prop) => {
1988
+ if (!prop)
1989
+ return;
1990
+ const mForm = inject("mForm");
1991
+ const instance = getCurrentInstance();
1992
+ watch(() => instance?.proxy, (vm) => {
1993
+ if (vm) {
1994
+ mForm?.setField(prop, vm);
1995
+ } else {
1996
+ mForm?.deleteField(prop);
1997
+ }
1998
+ }, {
1999
+ immediate: true
2000
+ });
2001
+ };
2002
+
2003
+ const _sfc_main$j = defineComponent({
2004
+ name: "m-fields-cascader",
2005
+ props: {
2006
+ ...fieldProps,
2007
+ config: {
2008
+ type: Object,
2009
+ required: true
2010
+ }
2011
+ },
2012
+ emits: ["change"],
2013
+ setup(props, { emit }) {
2014
+ const mForm = inject("mForm");
2015
+ const vm = getCurrentInstance();
2016
+ useAddField(props.prop);
2017
+ const requestFunc = getConfig("request");
2018
+ const cascader = ref(null);
2019
+ const dialog = ref(null);
2020
+ const options = Array.isArray(props.config.options) ? ref(props.config.options) : ref([]);
2021
+ const remoteData = ref(null);
2022
+ const setRemoteOptions = async function() {
2023
+ const { config } = props;
2024
+ const { option } = config;
2025
+ if (!option)
2026
+ return;
2027
+ let { body } = option;
2028
+ const postOptions = {
2029
+ url: option.url,
2030
+ cache: option.cache,
2031
+ timeout: option.timeout,
2032
+ data: {}
2033
+ };
2034
+ if (body && mForm) {
2035
+ if (typeof body === "function" && props.model && mForm) {
2036
+ body = body(mForm, {
2037
+ model: props.model,
2038
+ formValue: null,
2039
+ formValues: mForm.values
2040
+ });
2041
+ }
2042
+ postOptions.data = body;
2043
+ }
2044
+ const res = await requestFunc(postOptions);
2045
+ remoteData.value = res[option.root];
2046
+ if (remoteData.value && typeof option?.item === "function") {
2047
+ options.value = option.item(res[option.root]);
2048
+ }
2049
+ };
2050
+ if (typeof props.config.options === "function" && props.model && mForm) {
2051
+ watchEffect(() => options.value = props.config.options(vm, { model: props.model, formValues: mForm.values }));
2052
+ } else if (!props.config.options || !props.config.options.length || props.config.remote) {
2053
+ Promise.resolve(setRemoteOptions());
2054
+ }
2055
+ const action = computed(() => {
2056
+ if (props.config.add?.action.method === "post") {
2057
+ return (options2) => requestFunc({
2058
+ ...props.config?.add?.action.body,
2059
+ ...options2
2060
+ });
2061
+ }
2062
+ return null;
2063
+ });
2064
+ return {
2065
+ options,
2066
+ remoteData,
2067
+ addButtonStyle: {
2068
+ top: 0,
2069
+ left: 0,
2070
+ width: "auto"
2071
+ },
2072
+ dialogVisible: false,
2073
+ cascader,
2074
+ dialog,
2075
+ action,
2076
+ setRemoteOptions,
2077
+ changeHandler: (value) => {
2078
+ if (!cascader.value)
2079
+ return;
2080
+ cascader.value.query = "";
2081
+ cascader.value.previousQuery = null;
2082
+ emit("change", value);
2083
+ },
2084
+ addHandler: () => {
2085
+ if (!dialog.value)
2086
+ return;
2087
+ dialog.value.dialogVisible = true;
2088
+ },
2089
+ editAfterAction: () => {
2090
+ setRemoteOptions();
2091
+ }
2092
+ };
2093
+ }
2094
+ });
2095
+ const _hoisted_1$a = {
2096
+ class: "m-cascader",
2097
+ style: { "width": "100%" }
2098
+ };
2099
+ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
2100
+ const _component_el_cascader = resolveComponent("el-cascader");
2101
+ return openBlock(), createElementBlock("div", _hoisted_1$a, [
2102
+ createVNode(_component_el_cascader, {
2103
+ modelValue: _ctx.model[_ctx.name],
2104
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
2105
+ ref: "cascader",
2106
+ style: { "width": "100%" },
2107
+ clearable: "",
2108
+ filterable: "",
2109
+ size: _ctx.size,
2110
+ placeholder: _ctx.config.placeholder,
2111
+ disabled: _ctx.disabled,
2112
+ options: _ctx.options,
2113
+ props: { multiple: _ctx.config.multiple },
2114
+ onChange: _ctx.changeHandler
2115
+ }, null, 8, ["modelValue", "size", "placeholder", "disabled", "options", "props", "onChange"])
2116
+ ]);
2117
+ }
2118
+ var Cascader = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$g]]);
2119
+
2120
+ const _sfc_main$i = defineComponent({
2121
+ name: "m-fields-checkbox",
2122
+ props: {
2123
+ ...fieldProps,
2124
+ config: {
2125
+ type: Object,
2126
+ required: true
2127
+ }
2128
+ },
2129
+ emits: ["change", "input"],
2130
+ setup(props, { emit }) {
2131
+ useAddField(props.prop);
2132
+ return {
2133
+ activeValue: computed(() => {
2134
+ if (typeof props.config.activeValue === "undefined") {
2135
+ if (props.config.filter === "number") {
2136
+ return 1;
2137
+ }
2138
+ } else {
2139
+ return props.config.activeValue;
2140
+ }
2141
+ return "true";
2142
+ }),
2143
+ inactiveValue: computed(() => {
2144
+ if (typeof props.config.inactiveValue === "undefined") {
2145
+ if (props.config.filter === "number") {
2146
+ return 0;
2147
+ }
2148
+ } else {
2149
+ return props.config.inactiveValue;
2150
+ }
2151
+ return "false";
2152
+ }),
2153
+ changeHandler(value) {
2154
+ emit("change", value);
2155
+ }
2156
+ };
2157
+ }
2158
+ });
2159
+ function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
2160
+ const _component_el_checkbox = resolveComponent("el-checkbox");
2161
+ return openBlock(), createBlock(_component_el_checkbox, {
2162
+ modelValue: _ctx.model[_ctx.name],
2163
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
2164
+ size: _ctx.size,
2165
+ trueLabel: _ctx.activeValue,
2166
+ falseLabel: _ctx.inactiveValue,
2167
+ disabled: _ctx.disabled,
2168
+ label: _ctx.config.text,
2169
+ onChange: _ctx.changeHandler
2170
+ }, null, 8, ["modelValue", "size", "trueLabel", "falseLabel", "disabled", "label", "onChange"]);
2171
+ }
2172
+ var Checkbox = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$f]]);
2173
+
2174
+ const _sfc_main$h = defineComponent({
2175
+ name: "m-fields-checkbox-group",
2176
+ props: {
2177
+ ...fieldProps,
2178
+ config: {
2179
+ type: Object,
2180
+ required: true
2181
+ }
2182
+ },
2183
+ emits: ["change"],
2184
+ setup(props, { emit }) {
2185
+ useAddField(props.prop);
2186
+ if (props.model && !props.model[props.name]) {
2187
+ props.model[props.name] = [];
2188
+ }
2189
+ return {
2190
+ changeHandler: (v) => {
2191
+ emit("change", v);
2192
+ }
2193
+ };
2194
+ }
2195
+ });
2196
+ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2197
+ const _component_el_checkbox = resolveComponent("el-checkbox");
2198
+ const _component_el_checkbox_group = resolveComponent("el-checkbox-group");
2199
+ return openBlock(), createBlock(_component_el_checkbox_group, {
2200
+ modelValue: _ctx.model[_ctx.name],
2201
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
2202
+ size: _ctx.size,
2203
+ disabled: _ctx.disabled,
2204
+ onChange: _ctx.changeHandler
2205
+ }, {
2206
+ default: withCtx(() => [
2207
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.config.options, (option) => {
2208
+ return openBlock(), createBlock(_component_el_checkbox, {
2209
+ label: option.value,
2210
+ key: option.value
2211
+ }, {
2212
+ default: withCtx(() => [
2213
+ createTextVNode(toDisplayString(option.text), 1)
2214
+ ]),
2215
+ _: 2
2216
+ }, 1032, ["label"]);
2217
+ }), 128))
2218
+ ]),
2219
+ _: 1
2220
+ }, 8, ["modelValue", "size", "disabled", "onChange"]);
2221
+ }
2222
+ var CheckboxGroup = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$e]]);
2223
+
2224
+ const _hoisted_1$9 = { key: 0 };
2225
+ const __default__$2 = defineComponent({
2226
+ name: "m-fields-color-picker"
2227
+ });
2228
+ const _sfc_main$g = /* @__PURE__ */ defineComponent({
2229
+ ...__default__$2,
2230
+ props: {
2231
+ ...fieldProps,
2232
+ config: {
2233
+ type: Object,
2234
+ required: true
2235
+ }
2236
+ },
2237
+ emits: ["change"],
2238
+ setup(__props, { emit }) {
2239
+ const props = __props;
2240
+ useAddField(props.prop);
2241
+ const changeHandler = (value) => emit("change", value);
2242
+ return (_ctx, _cache) => {
2243
+ const _component_el_color_picker = resolveComponent("el-color-picker");
2244
+ return _ctx.model ? (openBlock(), createElementBlock("div", _hoisted_1$9, [
2245
+ createVNode(_component_el_color_picker, {
2246
+ modelValue: _ctx.model[_ctx.name],
2247
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
2248
+ size: _ctx.size,
2249
+ disabled: _ctx.disabled,
2250
+ showAlpha: true,
2251
+ onChange: changeHandler
2252
+ }, null, 8, ["modelValue", "size", "disabled"])
2253
+ ])) : createCommentVNode("", true);
2254
+ };
2255
+ }
2256
+ });
2257
+
2258
+ const _sfc_main$f = defineComponent({
2259
+ name: "m-fields-date",
2260
+ props: {
2261
+ ...fieldProps,
2262
+ config: {
2263
+ type: Object,
2264
+ required: true
2265
+ }
2266
+ },
2267
+ emits: ["change", "input"],
2268
+ setup(props, { emit }) {
2269
+ useAddField(props.prop);
2270
+ const modelName = computed(() => props.prop || props.config.name || "");
2271
+ props.model[modelName.value] = datetimeFormatter(props.model[modelName.value], "");
2272
+ return {
2273
+ modelName,
2274
+ changeHandler(v) {
2275
+ emit("change", v);
2276
+ }
2277
+ };
2278
+ }
2279
+ });
2280
+ const _hoisted_1$8 = { key: 0 };
2281
+ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2282
+ const _component_el_date_picker = resolveComponent("el-date-picker");
2283
+ return _ctx.model ? (openBlock(), createElementBlock("div", _hoisted_1$8, [
2284
+ createVNode(_component_el_date_picker, {
2285
+ modelValue: _ctx.model[_ctx.modelName],
2286
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.modelName] = $event),
2287
+ type: "date",
2288
+ size: _ctx.size,
2289
+ placeholder: _ctx.config.placeholder,
2290
+ disabled: _ctx.disabled,
2291
+ format: _ctx.config.format,
2292
+ "value-format": _ctx.config.format || "YYYY-MM-DD HH:mm:ss",
2293
+ onChange: _ctx.changeHandler
2294
+ }, null, 8, ["modelValue", "size", "placeholder", "disabled", "format", "value-format", "onChange"])
2295
+ ])) : createCommentVNode("", true);
2296
+ }
2297
+ var Date$1 = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$d]]);
2298
+
2299
+ const _sfc_main$e = defineComponent({
2300
+ name: "m-fields-daterange",
2301
+ props: {
2302
+ ...fieldProps,
2303
+ config: {
2304
+ type: Object,
2305
+ required: true
2306
+ }
2307
+ },
2308
+ emits: ["change"],
2309
+ setup(props, { emit }) {
2310
+ useAddField(props.prop);
2311
+ const { names } = props.config;
2312
+ const value = ref([]);
2313
+ if (props.model !== void 0) {
2314
+ if (names?.length) {
2315
+ value.value = names.map((item) => datetimeFormatter(props.model?.[item], ""));
2316
+ } else if (props.name && props.model[props.name]) {
2317
+ value.value = props.model[props.name].map((item) => datetimeFormatter(item, ""));
2318
+ }
2319
+ }
2320
+ const setValue = (v) => {
2321
+ if (names?.length && v instanceof Array) {
2322
+ names.forEach((item, index) => {
2323
+ if (props.model) {
2324
+ props.model[item] = datetimeFormatter(v[index].toString(), "");
2325
+ }
2326
+ });
2327
+ } else if (props.model && props.name && v instanceof Date) {
2328
+ props.model[props.name] = datetimeFormatter(v.toString(), "");
2329
+ }
2330
+ };
2331
+ return {
2332
+ value,
2333
+ changeHandler(v) {
2334
+ setValue(v);
2335
+ emit("change", v);
2336
+ }
2337
+ };
2338
+ }
2339
+ });
2340
+ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
2341
+ const _component_el_date_picker = resolveComponent("el-date-picker");
2342
+ return openBlock(), createElementBlock("div", null, [
2343
+ createVNode(_component_el_date_picker, {
2344
+ modelValue: _ctx.value,
2345
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.value = $event),
2346
+ type: "datetimerange",
2347
+ "range-separator": "-",
2348
+ "start-placeholder": "\u5F00\u59CB\u65E5\u671F",
2349
+ "end-placeholder": "\u7ED3\u675F\u65E5\u671F",
2350
+ size: _ctx.size,
2351
+ "unlink-panels": true,
2352
+ disabled: _ctx.disabled,
2353
+ onChange: _ctx.changeHandler
2354
+ }, null, 8, ["modelValue", "size", "disabled", "onChange"])
2355
+ ]);
2356
+ }
2357
+ var Daterange = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$c]]);
2358
+
2359
+ const _sfc_main$d = defineComponent({
2360
+ name: "m-fields-datetime",
2361
+ props: {
2362
+ ...fieldProps,
2363
+ config: {
2364
+ type: Object,
2365
+ required: true
2366
+ }
2367
+ },
2368
+ emits: ["change"],
2369
+ setup(props, { emit }) {
2370
+ useAddField(props.prop);
2371
+ const value = props.model?.[props.name].toString();
2372
+ if (props.model) {
2373
+ if (value === "Invalid Date") {
2374
+ props.model[props.name] = "";
2375
+ } else {
2376
+ props.model[props.name] = datetimeFormatter(props.model[props.name], "", props.config.valueFormat);
2377
+ }
2378
+ }
2379
+ return {
2380
+ value,
2381
+ changeHandler: (v) => {
2382
+ emit("change", v);
2383
+ }
2384
+ };
2385
+ }
2386
+ });
2387
+ const _hoisted_1$7 = { key: 0 };
2388
+ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
2389
+ const _component_el_date_picker = resolveComponent("el-date-picker");
2390
+ return _ctx.model ? (openBlock(), createElementBlock("div", _hoisted_1$7, [
2391
+ createVNode(_component_el_date_picker, {
2392
+ modelValue: _ctx.model[_ctx.name],
2393
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
2394
+ "popper-class": "magic-datetime-picker-popper",
2395
+ type: "datetime",
2396
+ size: _ctx.size,
2397
+ placeholder: _ctx.config.placeholder,
2398
+ disabled: _ctx.disabled,
2399
+ format: _ctx.config.format || "YYYY-MM-DD HH:mm:ss",
2400
+ "value-format": _ctx.config.valueFormat || "YYYY-MM-DD HH:mm:ss",
2401
+ onChange: _ctx.changeHandler
2402
+ }, null, 8, ["modelValue", "size", "placeholder", "disabled", "format", "value-format", "onChange"])
2403
+ ])) : createCommentVNode("", true);
2404
+ }
2405
+ var DateTime = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$b]]);
2406
+
2407
+ const _hoisted_1$6 = { key: 0 };
2408
+ const __default__$1 = defineComponent({
2409
+ name: "m-fields-display"
2410
+ });
2411
+ const _sfc_main$c = /* @__PURE__ */ defineComponent({
2412
+ ...__default__$1,
2413
+ props: {
2414
+ ...fieldProps,
2415
+ config: {
2416
+ type: Object,
2417
+ required: true
2418
+ }
2419
+ },
2420
+ setup(__props) {
2421
+ const props = __props;
2422
+ const n = computed(() => props.name || props.config.name || "");
2423
+ if (props.config.initValue && n.value && props.model) {
2424
+ props.model[n.value] = props.config.initValue;
2425
+ }
2426
+ useAddField(props.prop);
2427
+ return (_ctx, _cache) => {
2428
+ return _ctx.model ? (openBlock(), createElementBlock("span", _hoisted_1$6, toDisplayString(_ctx.model[unref(n)]), 1)) : createCommentVNode("", true);
2429
+ };
2430
+ }
2431
+ });
2432
+
2433
+ const _sfc_main$b = defineComponent({
2434
+ name: "m-fields-dynamic-field",
2435
+ props: {
2436
+ ...fieldProps,
2437
+ config: {
2438
+ type: Object,
2439
+ required: true
2440
+ }
2441
+ },
2442
+ emits: ["change"],
2443
+ setup(props, { emit }) {
2444
+ useAddField(props.prop);
2445
+ const request = getConfig("request");
2446
+ const fieldMap = reactive({
2447
+ value: {}
2448
+ });
2449
+ const fieldLabelMap = reactive({
2450
+ value: {}
2451
+ });
2452
+ const changeFieldMap = async () => {
2453
+ if (typeof props.config.returnFields !== "function" || !props.model)
2454
+ return;
2455
+ const fields = await props.config.returnFields(props.config, props.model, request);
2456
+ fieldMap.value = {};
2457
+ fieldLabelMap.value = {};
2458
+ fields.forEach((v) => {
2459
+ if (typeof v !== "object" || v.name === void 0)
2460
+ return;
2461
+ let oldVal = props.model?.[v.name] || "";
2462
+ if (!oldVal && v.defaultValue !== void 0) {
2463
+ oldVal = v.defaultValue;
2464
+ emit("change", oldVal, v.name);
2465
+ }
2466
+ fieldMap.value[v.name] = oldVal;
2467
+ fieldLabelMap.value[v.name] = v.label || "";
2468
+ });
2469
+ };
2470
+ const unwatch = watch(() => props.model?.[props.config.dynamicKey], (val) => {
2471
+ if (val !== "") {
2472
+ changeFieldMap();
2473
+ }
2474
+ }, {
2475
+ immediate: true
2476
+ });
2477
+ onBeforeUnmount(() => {
2478
+ if (typeof unwatch === "function") {
2479
+ unwatch();
2480
+ }
2481
+ });
2482
+ return {
2483
+ request,
2484
+ fieldMap,
2485
+ fieldLabelMap,
2486
+ unwatch,
2487
+ changeFieldMap,
2488
+ inputChangeHandler: (key) => {
2489
+ emit("change", fieldMap.value[key], key);
2490
+ }
2491
+ };
2492
+ },
2493
+ methods: {
2494
+ init() {
2495
+ }
2496
+ }
2497
+ });
2498
+ const _hoisted_1$5 = { class: "m-fields-dynamic-field" };
2499
+ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2500
+ const _component_el_input = resolveComponent("el-input");
2501
+ const _component_el_form_item = resolveComponent("el-form-item");
2502
+ const _component_el_form = resolveComponent("el-form");
2503
+ return openBlock(), createElementBlock("div", _hoisted_1$5, [
2504
+ createVNode(_component_el_form, { size: "small" }, {
2505
+ default: withCtx(() => [
2506
+ (openBlock(true), createElementBlock(Fragment, null, renderList(Object.keys(_ctx.fieldMap.value), (key) => {
2507
+ return openBlock(), createBlock(_component_el_form_item, {
2508
+ key,
2509
+ label: _ctx.fieldLabelMap.value[key]
2510
+ }, {
2511
+ default: withCtx(() => [
2512
+ createVNode(_component_el_input, {
2513
+ modelValue: _ctx.fieldMap.value[key],
2514
+ "onUpdate:modelValue": ($event) => _ctx.fieldMap.value[key] = $event,
2515
+ placeholder: _ctx.fieldLabelMap.value[key],
2516
+ onChange: ($event) => _ctx.inputChangeHandler(key)
2517
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder", "onChange"])
2518
+ ]),
2519
+ _: 2
2520
+ }, 1032, ["label"]);
2521
+ }), 128))
2522
+ ]),
2523
+ _: 1
2524
+ })
2525
+ ]);
2526
+ }
2527
+ var DynamicField = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$a]]);
2528
+
2529
+ const __default__ = defineComponent({
2530
+ name: "m-fields-hidden"
2531
+ });
2532
+ const _sfc_main$a = /* @__PURE__ */ defineComponent({
2533
+ ...__default__,
2534
+ props: {
2535
+ ...fieldProps,
2536
+ config: {
2537
+ type: Object,
2538
+ required: true
2539
+ }
2540
+ },
2541
+ setup(__props) {
2542
+ const props = __props;
2543
+ const n = computed(() => props.name || props.config.name || "");
2544
+ useAddField(props.prop);
2545
+ return (_ctx, _cache) => {
2546
+ return _ctx.model ? withDirectives((openBlock(), createElementBlock("input", {
2547
+ key: 0,
2548
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[unref(n)] = $event),
2549
+ type: "hidden"
2550
+ }, null, 512)), [
2551
+ [vModelText, _ctx.model[unref(n)]]
2552
+ ]) : createCommentVNode("", true);
2553
+ };
2554
+ }
2555
+ });
2556
+
2557
+ const _sfc_main$9 = defineComponent({
2558
+ name: "m-fields-link",
2559
+ props: {
2560
+ ...fieldProps,
2561
+ config: {
2562
+ type: Object,
2563
+ required: true
2564
+ }
2565
+ },
2566
+ emits: ["change"],
2567
+ setup(props, { emit }) {
2568
+ useAddField(props.prop);
2569
+ const formValue = ref({});
2570
+ const editor = ref();
2571
+ const mForm = inject("mForm");
2572
+ const href = computed(() => {
2573
+ if (typeof props.config.href === "function" && props.model) {
2574
+ return props.config.href(props.model);
2575
+ }
2576
+ return props.config.href || props.model?.[props.name];
2577
+ });
2578
+ const init = () => {
2579
+ formValue.value = props.model?.[props.name] || {};
2580
+ };
2581
+ return {
2582
+ formValue,
2583
+ editor,
2584
+ href,
2585
+ formConfig: computed(() => {
2586
+ if (typeof props.config.form === "function") {
2587
+ return props.config.form(mForm, {
2588
+ model: props.model || {},
2589
+ values: props.values || {}
2590
+ });
2591
+ }
2592
+ return props.config.form;
2593
+ }),
2594
+ disable: computed(() => {
2595
+ if (typeof props.config.disabled !== "undefined") {
2596
+ return props.config.disabled;
2597
+ }
2598
+ return !href.value;
2599
+ }),
2600
+ displayText: computed(() => {
2601
+ if (typeof props.config.displayText === "function") {
2602
+ return props.config.displayText(mForm, { model: props.model || {} });
2603
+ }
2604
+ if (props.config.displayText) {
2605
+ return props.config.displayText;
2606
+ }
2607
+ return "\u8DF3\u8F6C";
2608
+ }),
2609
+ init,
2610
+ editHandler: () => {
2611
+ init();
2612
+ editor.value && (editor.value.dialogVisible = true);
2613
+ },
2614
+ action: (data) => {
2615
+ if (props.model) {
2616
+ props.model[props.name] = data;
2617
+ formValue.value = data;
2618
+ emit("change", props.model[props.name]);
2619
+ }
2620
+ editor.value && (editor.value.dialogVisible = false);
2621
+ }
2622
+ };
2623
+ }
2624
+ });
2625
+ const _hoisted_1$4 = ["href"];
2626
+ const _hoisted_2$1 = {
2627
+ key: 2,
2628
+ class: "m-fields-link"
2629
+ };
2630
+ const _hoisted_3$1 = /* @__PURE__ */ createTextVNode("\u70B9\u51FB\u7F16\u8F91");
2631
+ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
2632
+ const _component_el_button = resolveComponent("el-button");
2633
+ const _component_m_form_dialog = resolveComponent("m-form-dialog");
2634
+ return _ctx.config.href && !_ctx.disabled ? (openBlock(), createElementBlock("a", {
2635
+ key: 0,
2636
+ target: "_blank",
2637
+ href: _ctx.href,
2638
+ style: normalizeStyle(_ctx.config.css || {})
2639
+ }, toDisplayString(_ctx.displayText), 13, _hoisted_1$4)) : _ctx.config.href && _ctx.disabled ? (openBlock(), createElementBlock("span", {
2640
+ key: 1,
2641
+ style: normalizeStyle(_ctx.config.disabledCss || {})
2642
+ }, toDisplayString(_ctx.displayText), 5)) : (openBlock(), createElementBlock("div", _hoisted_2$1, [
2643
+ createVNode(_component_el_button, {
2644
+ type: "text",
2645
+ onClick: _ctx.editHandler
2646
+ }, {
2647
+ default: withCtx(() => [
2648
+ _hoisted_3$1
2649
+ ]),
2650
+ _: 1
2651
+ }, 8, ["onClick"]),
2652
+ createVNode(_component_m_form_dialog, {
2653
+ ref: "editor",
2654
+ title: _ctx.config.formTitle || "\u7F16\u8F91\u6269\u5C55\u914D\u7F6E",
2655
+ width: _ctx.config.formWidth,
2656
+ values: _ctx.formValue,
2657
+ config: _ctx.formConfig,
2658
+ parentValues: _ctx.values,
2659
+ fullscreen: _ctx.config.fullscreen,
2660
+ onSubmit: _ctx.action
2661
+ }, null, 8, ["title", "width", "values", "config", "parentValues", "fullscreen", "onSubmit"])
2662
+ ]));
2663
+ }
2664
+ var Link = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
2665
+
2666
+ const _sfc_main$8 = defineComponent({
2667
+ name: "m-fields-number",
2668
+ props: {
2669
+ ...fieldProps,
2670
+ config: {
2671
+ type: Object,
2672
+ required: true
2673
+ }
2674
+ },
2675
+ emits: ["change", "input"],
2676
+ setup(props, { emit }) {
2677
+ useAddField(props.prop);
2678
+ const mForm = inject("mForm");
2679
+ return {
2680
+ mForm,
2681
+ changeHandler: (value) => {
2682
+ emit("change", value);
2683
+ },
2684
+ inputHandler: (v) => {
2685
+ emit("input", v);
2686
+ mForm?.$emit("field-input", props.prop, v);
2687
+ }
2688
+ };
2689
+ }
2690
+ });
2691
+ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
2692
+ const _component_el_input_number = resolveComponent("el-input-number");
2693
+ return _ctx.model ? (openBlock(), createBlock(_component_el_input_number, {
2694
+ key: 0,
2695
+ modelValue: _ctx.model[_ctx.name],
2696
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
2697
+ clearable: "",
2698
+ "controls-position": "right",
2699
+ size: _ctx.size,
2700
+ max: _ctx.config.max,
2701
+ min: _ctx.config.min,
2702
+ step: _ctx.config.step,
2703
+ placeholder: _ctx.config.placeholder,
2704
+ disabled: _ctx.disabled,
2705
+ onChange: _ctx.changeHandler,
2706
+ onInput: _ctx.inputHandler
2707
+ }, null, 8, ["modelValue", "size", "max", "min", "step", "placeholder", "disabled", "onChange", "onInput"])) : createCommentVNode("", true);
2708
+ }
2709
+ var Number$1 = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
2710
+
2711
+ const _sfc_main$7 = defineComponent({
2712
+ name: "m-fields-radio-group",
2713
+ props: {
2714
+ ...fieldProps,
2715
+ config: {
2716
+ type: Object,
2717
+ required: true
2718
+ }
2719
+ },
2720
+ emits: ["change"],
2721
+ setup(props, { emit }) {
2722
+ useAddField(props.prop);
2723
+ return {
2724
+ changeHandler: (v) => emit("change", v)
2725
+ };
2726
+ }
2727
+ });
2728
+ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
2729
+ const _component_el_radio = resolveComponent("el-radio");
2730
+ const _component_el_radio_group = resolveComponent("el-radio-group");
2731
+ return _ctx.model ? (openBlock(), createBlock(_component_el_radio_group, {
2732
+ key: 0,
2733
+ modelValue: _ctx.model[_ctx.name],
2734
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
2735
+ size: _ctx.size,
2736
+ disabled: _ctx.disabled,
2737
+ onChange: _ctx.changeHandler
2738
+ }, {
2739
+ default: withCtx(() => [
2740
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.config.options, (option) => {
2741
+ return openBlock(), createBlock(_component_el_radio, {
2742
+ label: option.value,
2743
+ key: option.value
2744
+ }, {
2745
+ default: withCtx(() => [
2746
+ createTextVNode(toDisplayString(option.text), 1)
2747
+ ]),
2748
+ _: 2
2749
+ }, 1032, ["label"]);
2750
+ }), 128))
2751
+ ]),
2752
+ _: 1
2753
+ }, 8, ["modelValue", "size", "disabled", "onChange"])) : createCommentVNode("", true);
2754
+ }
2755
+ var RadioGroup = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
2756
+
2757
+ const _sfc_main$6 = defineComponent({
2758
+ name: "m-fields-select",
2759
+ props: {
2760
+ ...fieldProps,
2761
+ config: {
2762
+ type: Object,
2763
+ required: true
2764
+ }
2765
+ },
2766
+ emits: ["change"],
2767
+ setup(props, { emit }) {
2768
+ if (!props.model)
2769
+ throw new Error("\u4E0D\u80FD\u6CA1\u6709model");
2770
+ useAddField(props.prop);
2771
+ const select = ref();
2772
+ const mForm = inject("mForm");
2773
+ const options = ref([]);
2774
+ const localOptions = ref([]);
2775
+ const loading = ref(false);
2776
+ const moreLoadingVisible = ref(false);
2777
+ const total = ref(0);
2778
+ const pgIndex = ref(0);
2779
+ const pgSize = ref(20);
2780
+ const query = ref("");
2781
+ const remoteData = ref([]);
2782
+ const remote = ref(true);
2783
+ const equalValue = (value, v) => {
2784
+ if (typeof v === "object") {
2785
+ const key = props.config.valueKey || "value";
2786
+ return v[key] === value[key];
2787
+ }
2788
+ return value === v;
2789
+ };
2790
+ const mapOptions = (data) => {
2791
+ const { option } = props.config;
2792
+ const { text } = option;
2793
+ const { value } = option;
2794
+ return data.map((item) => ({
2795
+ text: typeof text === "function" ? text(item) : item[text || "text"],
2796
+ value: typeof value === "function" ? value(item) : item[value || "value"]
2797
+ }));
2798
+ };
2799
+ const getOptions = async () => {
2800
+ if (!props.model)
2801
+ return [];
2802
+ if (localOptions.value.length) {
2803
+ return localOptions.value;
2804
+ }
2805
+ loading.value = true;
2806
+ let items = [];
2807
+ const { config } = props;
2808
+ const { option } = config;
2809
+ let { body } = option;
2810
+ let postOptions = {
2811
+ method: option.method || "POST",
2812
+ url: option.url,
2813
+ cache: option.cache,
2814
+ timeout: option.timeout,
2815
+ mode: option.mode,
2816
+ headers: option.headers || {},
2817
+ json: option.json || false
2818
+ };
2819
+ if (body) {
2820
+ if (typeof body === "function") {
2821
+ body = body(mForm, {
2822
+ model: props.model,
2823
+ formValue: mForm?.values,
2824
+ formValues: mForm?.values
2825
+ });
2826
+ }
2827
+ body.query = query.value;
2828
+ body.pgSize = pgSize.value;
2829
+ body.pgIndex = pgIndex.value;
2830
+ postOptions.data = body;
2831
+ }
2832
+ const requestFuc = getConfig("request");
2833
+ if (typeof option.beforeRequest === "function") {
2834
+ postOptions = option.beforeRequest(mForm, postOptions, {
2835
+ model: props.model,
2836
+ formValue: mForm?.values
2837
+ });
2838
+ }
2839
+ if (option.method?.toLocaleLowerCase() === "jsonp") {
2840
+ postOptions.jsonpCallback = option.jsonpCallback || "callback";
2841
+ }
2842
+ let res = await requestFuc(postOptions);
2843
+ if (typeof option.afterRequest === "function") {
2844
+ res = option.afterRequest(mForm, res, {
2845
+ model: props.model,
2846
+ formValue: mForm?.values,
2847
+ formValues: mForm?.values
2848
+ });
2849
+ }
2850
+ const optionsData = res[option.root];
2851
+ if (res.total > 0) {
2852
+ total.value = res.total;
2853
+ }
2854
+ remoteData.value = remoteData.value.concat(optionsData);
2855
+ if (optionsData) {
2856
+ if (typeof option.item === "function") {
2857
+ items = option.item(optionsData);
2858
+ } else if (optionsData.map) {
2859
+ items = mapOptions(optionsData);
2860
+ }
2861
+ }
2862
+ loading.value = false;
2863
+ const selectedOptions = [];
2864
+ if (props.config.multiple && props.model[props.name]) {
2865
+ options.value.forEach((o) => {
2866
+ const isInclude = props.model?.[props.name].includes(o.value);
2867
+ if (isInclude && !items.find((op) => op.value === o.value)) {
2868
+ selectedOptions.push(o);
2869
+ }
2870
+ });
2871
+ }
2872
+ return pgIndex.value === 0 ? selectedOptions.concat(items) : options.value.concat(items);
2873
+ };
2874
+ const getInitLocalOption = async () => {
2875
+ if (!props.model)
2876
+ return [];
2877
+ const value = props.model[props.name];
2878
+ const { config } = props;
2879
+ localOptions.value = await getOptions();
2880
+ remote.value = false;
2881
+ if (config.group) {
2882
+ if (config.multiple && value.findIndex) {
2883
+ return localOptions.value.filter((group) => group.options.findIndex((item) => value.find((v) => equalValue(item.value, v)) > -1) > -1);
2884
+ }
2885
+ return localOptions.value.filter((group) => group.options.findIndex((item) => equalValue(item.value, value)) > -1);
2886
+ }
2887
+ if (config.multiple && value.findIndex) {
2888
+ return localOptions.value.filter((item) => value.findIndex((v) => equalValue(item.value, v)) > -1);
2889
+ }
2890
+ return localOptions.value.filter((item) => equalValue(item.value, value));
2891
+ };
2892
+ const getInitOption = async () => {
2893
+ if (!props.model)
2894
+ return [];
2895
+ const { config } = props;
2896
+ const { option } = config;
2897
+ let options2 = [];
2898
+ let url = option.initUrl;
2899
+ if (!url) {
2900
+ return getInitLocalOption();
2901
+ }
2902
+ if (typeof url === "function") {
2903
+ url = await url(mForm, { model: props.model, formValue: mForm?.values });
2904
+ }
2905
+ const postOptions = {
2906
+ method: option.method || "POST",
2907
+ url,
2908
+ data: {
2909
+ id: props.model[props.name]
2910
+ },
2911
+ mode: option.mode,
2912
+ headers: option.headers || {},
2913
+ json: option.json || false
2914
+ };
2915
+ if (option.method?.toLocaleLowerCase() === "jsonp") {
2916
+ postOptions.jsonpCallback = option.jsonpCallback || "callback";
2917
+ }
2918
+ const requestFuc = getConfig("request");
2919
+ const res = await requestFuc(postOptions);
2920
+ let initData = res[option.root];
2921
+ if (initData) {
2922
+ if (!Array.isArray(initData)) {
2923
+ initData = [initData];
2924
+ }
2925
+ if (typeof option.item === "function") {
2926
+ options2 = option.item(initData);
2927
+ } else if (initData.map) {
2928
+ options2 = mapOptions(initData);
2929
+ }
2930
+ }
2931
+ return options2;
2932
+ };
2933
+ if (typeof props.config.options === "function") {
2934
+ watch(() => mForm?.values, () => {
2935
+ typeof props.config.options === "function" && Promise.resolve(props.config.options(mForm, {
2936
+ model: props.model,
2937
+ formValues: mForm?.values,
2938
+ formValue: mForm?.values
2939
+ })).then((data) => {
2940
+ options.value = data;
2941
+ });
2942
+ }, {
2943
+ deep: true,
2944
+ immediate: true
2945
+ });
2946
+ } else if (Array.isArray(props.config.options)) {
2947
+ watch(() => props.config.options, () => {
2948
+ options.value = props.config.options;
2949
+ }, { immediate: true });
2950
+ } else if (props.config.option) {
2951
+ onBeforeMount(() => {
2952
+ if (!props.model)
2953
+ return;
2954
+ const v = props.model[props.name];
2955
+ if (Array.isArray(v) ? v.length : v) {
2956
+ getInitOption().then((data) => {
2957
+ options.value = data;
2958
+ });
2959
+ }
2960
+ });
2961
+ }
2962
+ props.config.remote && onMounted(() => {
2963
+ select.value?.scrollbar.wrap$.addEventListener("scroll", async (e) => {
2964
+ const el = e.currentTarget;
2965
+ if (moreLoadingVisible.value) {
2966
+ return;
2967
+ }
2968
+ if (el.scrollHeight - el.clientHeight - el.scrollTop > 1) {
2969
+ return;
2970
+ }
2971
+ if (total.value <= options.value.length) {
2972
+ return;
2973
+ }
2974
+ moreLoadingVisible.value = true;
2975
+ pgIndex.value += 1;
2976
+ options.value = await getOptions();
2977
+ moreLoadingVisible.value = false;
2978
+ });
2979
+ });
2980
+ return {
2981
+ select,
2982
+ loading,
2983
+ remote,
2984
+ options,
2985
+ moreLoadingVisible,
2986
+ getRequestFuc() {
2987
+ return getConfig("request");
2988
+ },
2989
+ async getInitOption() {
2990
+ },
2991
+ changeHandler(value) {
2992
+ emit("change", value);
2993
+ },
2994
+ async visibleHandler(visible) {
2995
+ if (!visible)
2996
+ return;
2997
+ if (!props.config.remote)
2998
+ return;
2999
+ if (query.value && select.value) {
3000
+ select.value.query = query.value;
3001
+ select.value.previousQuery = query.value;
3002
+ select.value.selectedLabel = query.value;
3003
+ } else if (options.value.length <= (props.config.multiple ? props.model?.[props.name].length : 1)) {
3004
+ options.value = await getOptions();
3005
+ }
3006
+ },
3007
+ async editAfterAction() {
3008
+ pgIndex.value = 0;
3009
+ options.value = await getOptions();
3010
+ },
3011
+ async remoteMethod(q) {
3012
+ if (!localOptions.value.length) {
3013
+ query.value = q;
3014
+ pgIndex.value = 0;
3015
+ options.value = await getOptions();
3016
+ if (props.config.multiple)
3017
+ setTimeout(() => {
3018
+ select.value?.setSelected();
3019
+ }, 0);
3020
+ }
3021
+ }
3022
+ };
3023
+ }
3024
+ });
3025
+ const _hoisted_1$3 = { key: 2 };
3026
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3027
+ const _component_el_option = resolveComponent("el-option");
3028
+ const _component_el_option_group = resolveComponent("el-option-group");
3029
+ const _component_el_select = resolveComponent("el-select");
3030
+ const _directive_loading = resolveDirective("loading");
3031
+ return _ctx.model ? withDirectives((openBlock(), createBlock(_component_el_select, {
3032
+ key: 0,
3033
+ modelValue: _ctx.model[_ctx.name],
3034
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
3035
+ class: "m-select",
3036
+ ref: "select",
3037
+ clearable: "",
3038
+ filterable: "",
3039
+ size: _ctx.size,
3040
+ remote: _ctx.remote,
3041
+ placeholder: _ctx.config.placeholder,
3042
+ multiple: _ctx.config.multiple,
3043
+ "value-key": _ctx.config.valueKey || "value",
3044
+ "allow-create": _ctx.config.allowCreate,
3045
+ disabled: _ctx.disabled,
3046
+ "remote-method": _ctx.remoteMethod,
3047
+ onChange: _ctx.changeHandler,
3048
+ onVisibleChange: _ctx.visibleHandler
3049
+ }, {
3050
+ default: withCtx(() => [
3051
+ _ctx.config.group ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(_ctx.options, (group, index) => {
3052
+ return openBlock(), createBlock(_component_el_option_group, {
3053
+ key: group.label + index,
3054
+ label: group.label,
3055
+ disabled: group.disabled
3056
+ }, {
3057
+ default: withCtx(() => [
3058
+ (openBlock(true), createElementBlock(Fragment, null, renderList(group.options, (item, index2) => {
3059
+ return openBlock(), createBlock(_component_el_option, {
3060
+ key: item.label + index2,
3061
+ label: item.label,
3062
+ value: item.value,
3063
+ disabled: item.disabled
3064
+ }, null, 8, ["label", "value", "disabled"]);
3065
+ }), 128))
3066
+ ]),
3067
+ _: 2
3068
+ }, 1032, ["label", "disabled"]);
3069
+ }), 128)) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.options, (option) => {
3070
+ return openBlock(), createBlock(_component_el_option, {
3071
+ label: option.text,
3072
+ value: option.value,
3073
+ key: _ctx.config.valueKey ? option.value[_ctx.config.valueKey] : option.value,
3074
+ disabled: option.disabled
3075
+ }, null, 8, ["label", "value", "disabled"]);
3076
+ }), 128)),
3077
+ _ctx.moreLoadingVisible ? withDirectives((openBlock(), createElementBlock("div", _hoisted_1$3, null, 512)), [
3078
+ [_directive_loading, true]
3079
+ ]) : createCommentVNode("", true)
3080
+ ]),
3081
+ _: 1
3082
+ }, 8, ["modelValue", "size", "remote", "placeholder", "multiple", "value-key", "allow-create", "disabled", "remote-method", "onChange", "onVisibleChange"])), [
3083
+ [_directive_loading, _ctx.loading]
3084
+ ]) : createCommentVNode("", true);
3085
+ }
3086
+ var Select = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$6]]);
3087
+
3088
+ const _sfc_main$5 = defineComponent({
3089
+ name: "m-fields-switch",
3090
+ props: {
3091
+ ...fieldProps,
3092
+ config: {
3093
+ type: Object,
3094
+ required: true
3095
+ }
3096
+ },
3097
+ emits: ["change"],
3098
+ setup(props, { emit }) {
3099
+ useAddField(props.prop);
3100
+ return {
3101
+ n: computed(() => props.name || props.config.name || ""),
3102
+ activeValue: computed(() => {
3103
+ if (typeof props.config.activeValue === "undefined") {
3104
+ if (props.config.filter === "number") {
3105
+ return 1;
3106
+ }
3107
+ } else {
3108
+ return props.config.activeValue;
3109
+ }
3110
+ return true;
3111
+ }),
3112
+ inactiveValue: computed(() => {
3113
+ if (typeof props.config.inactiveValue === "undefined") {
3114
+ if (props.config.filter === "number") {
3115
+ return 0;
3116
+ }
3117
+ } else {
3118
+ return props.config.inactiveValue;
3119
+ }
3120
+ return false;
3121
+ }),
3122
+ changeHandler: (v) => {
3123
+ emit("change", v);
3124
+ }
3125
+ };
3126
+ }
3127
+ });
3128
+ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3129
+ const _component_el_switch = resolveComponent("el-switch");
3130
+ return _ctx.model ? (openBlock(), createBlock(_component_el_switch, {
3131
+ key: 0,
3132
+ modelValue: _ctx.model[_ctx.n],
3133
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.n] = $event),
3134
+ size: _ctx.size,
3135
+ activeValue: _ctx.activeValue,
3136
+ inactiveValue: _ctx.inactiveValue,
3137
+ disabled: _ctx.disabled,
3138
+ onChange: _ctx.changeHandler
3139
+ }, null, 8, ["modelValue", "size", "activeValue", "inactiveValue", "disabled", "onChange"])) : createCommentVNode("", true);
3140
+ }
3141
+ var Switch = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3142
+
3143
+ const _sfc_main$4 = defineComponent({
3144
+ name: "m-fields-text",
3145
+ props: {
3146
+ ...fieldProps,
3147
+ config: {
3148
+ type: Object,
3149
+ required: true
3150
+ }
3151
+ },
3152
+ emits: ["change", "input"],
3153
+ setup(props, { emit }) {
3154
+ useAddField(props.prop);
3155
+ const modelName = computed(() => props.name || props.config.name || "");
3156
+ return {
3157
+ modelName,
3158
+ changeHandler(v) {
3159
+ emit("change", v);
3160
+ },
3161
+ inputHandler(v) {
3162
+ const mForm = inject("mForm");
3163
+ emit("input", v);
3164
+ mForm?.$emit("field-input", props.prop, v);
3165
+ },
3166
+ buttonClickHandler() {
3167
+ const mForm = inject("mForm");
3168
+ if (typeof props.config.append === "string")
3169
+ return;
3170
+ if (props.config.append?.handler) {
3171
+ props.config.append.handler(mForm, {
3172
+ model: props.model,
3173
+ values: mForm?.values
3174
+ });
3175
+ }
3176
+ },
3177
+ keyUpHandler($event) {
3178
+ if (!props.model)
3179
+ return;
3180
+ if (!modelName.value)
3181
+ return;
3182
+ const arrowUp = $event.key === "ArrowUp";
3183
+ const arrowDown = $event.key === "ArrowDown";
3184
+ if (!arrowUp && !arrowDown) {
3185
+ return;
3186
+ }
3187
+ const value = props.model[modelName.value];
3188
+ let num;
3189
+ let unit;
3190
+ if (/^([0-9.]+)$/.test(value)) {
3191
+ num = +value;
3192
+ } else {
3193
+ value.replace(/^([0-9.]+)([a-z%]+)$/, ($0, $1, $2) => {
3194
+ num = +$1;
3195
+ unit = $2;
3196
+ });
3197
+ }
3198
+ if (num === void 0) {
3199
+ return;
3200
+ }
3201
+ const ctrl = navigator.platform.match("Mac") ? $event.metaKey : $event.ctrlKey;
3202
+ const shif = $event.shiftKey;
3203
+ const alt = $event.altKey;
3204
+ if (arrowUp) {
3205
+ if (ctrl) {
3206
+ num += 100;
3207
+ } else if (alt) {
3208
+ num = (num * 1e4 + 1e3) / 1e4;
3209
+ } else if (shif) {
3210
+ num = num + 10;
3211
+ } else {
3212
+ num += 1;
3213
+ }
3214
+ } else if (arrowDown) {
3215
+ if (ctrl) {
3216
+ num -= 100;
3217
+ } else if (alt) {
3218
+ num = (num * 1e4 - 1e3) / 1e4;
3219
+ } else if (shif) {
3220
+ num -= 10;
3221
+ } else {
3222
+ num -= 1;
3223
+ }
3224
+ }
3225
+ props.model[modelName.value] = `${num}${unit || ""}`;
3226
+ emit("change", props.model[modelName.value]);
3227
+ }
3228
+ };
3229
+ }
3230
+ });
3231
+ const _hoisted_1$2 = { key: 0 };
3232
+ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3233
+ const _component_el_button = resolveComponent("el-button");
3234
+ const _component_el_input = resolveComponent("el-input");
3235
+ return openBlock(), createBlock(_component_el_input, {
3236
+ modelValue: _ctx.model[_ctx.modelName],
3237
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.modelName] = $event),
3238
+ clearable: "",
3239
+ size: _ctx.size,
3240
+ placeholder: _ctx.config.placeholder,
3241
+ disabled: _ctx.disabled,
3242
+ onChange: _ctx.changeHandler,
3243
+ onInput: _ctx.inputHandler,
3244
+ onKeyup: _cache[1] || (_cache[1] = ($event) => _ctx.keyUpHandler($event))
3245
+ }, createSlots({ _: 2 }, [
3246
+ _ctx.config.append ? {
3247
+ name: "append",
3248
+ fn: withCtx(() => [
3249
+ typeof _ctx.config.append === "string" ? (openBlock(), createElementBlock("span", _hoisted_1$2, toDisplayString(_ctx.config.append), 1)) : createCommentVNode("", true),
3250
+ typeof _ctx.config.append === "object" && _ctx.config.append.type === "button" ? (openBlock(), createBlock(_component_el_button, {
3251
+ key: 1,
3252
+ style: { "color": "#409eff" },
3253
+ onClick: _ctx.buttonClickHandler
3254
+ }, {
3255
+ default: withCtx(() => [
3256
+ createTextVNode(toDisplayString(_ctx.config.append.text), 1)
3257
+ ]),
3258
+ _: 1
3259
+ }, 8, ["onClick"])) : createCommentVNode("", true)
3260
+ ])
3261
+ } : void 0
3262
+ ]), 1032, ["modelValue", "size", "placeholder", "disabled", "onChange", "onInput"]);
3263
+ }
3264
+ var Text = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$4]]);
3265
+
3266
+ const _sfc_main$3 = defineComponent({
3267
+ name: "m-fields-textarea",
3268
+ props: {
3269
+ ...fieldProps,
3270
+ config: {
3271
+ type: Object,
3272
+ required: true
3273
+ }
3274
+ },
3275
+ emits: {
3276
+ change(values) {
3277
+ return values;
3278
+ },
3279
+ input(values) {
3280
+ return values;
3281
+ }
3282
+ },
3283
+ setup(props, { emit }) {
3284
+ useAddField(props.prop);
3285
+ const mForm = inject("mForm");
3286
+ return {
3287
+ mForm,
3288
+ changeHandler: (v) => {
3289
+ emit("change", v);
3290
+ },
3291
+ inputHandler: (v) => {
3292
+ emit("input", v);
3293
+ mForm?.$emit("field-input", props.prop, v);
3294
+ }
3295
+ };
3296
+ }
3297
+ });
3298
+ const _hoisted_1$1 = { key: 0 };
3299
+ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3300
+ const _component_el_input = resolveComponent("el-input");
3301
+ return _ctx.model ? (openBlock(), createElementBlock("div", _hoisted_1$1, [
3302
+ createVNode(_component_el_input, {
3303
+ modelValue: _ctx.model[_ctx.name],
3304
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
3305
+ type: "textarea",
3306
+ size: _ctx.size,
3307
+ clearable: "",
3308
+ placeholder: _ctx.config.placeholder,
3309
+ disabled: _ctx.disabled,
3310
+ onChange: _ctx.changeHandler,
3311
+ onInput: _ctx.inputHandler
3312
+ }, null, 8, ["modelValue", "size", "placeholder", "disabled", "onChange", "onInput"])
3313
+ ])) : createCommentVNode("", true);
3314
+ }
3315
+ var Textarea = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3]]);
3316
+
3317
+ const _sfc_main$2 = defineComponent({
3318
+ name: "m-fields-time",
3319
+ props: {
3320
+ ...fieldProps,
3321
+ config: {
3322
+ type: Object,
3323
+ required: true
3324
+ }
3325
+ },
3326
+ emits: {
3327
+ change(values) {
3328
+ return values;
3329
+ }
3330
+ },
3331
+ setup(props, { emit }) {
3332
+ useAddField(props.prop);
3333
+ return {
3334
+ changeHandler: (v) => {
3335
+ emit("change", v);
3336
+ }
3337
+ };
3338
+ }
3339
+ });
3340
+ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
3341
+ const _component_el_time_picker = resolveComponent("el-time-picker");
3342
+ return openBlock(), createElementBlock("div", null, [
3343
+ createVNode(_component_el_time_picker, {
3344
+ modelValue: _ctx.model[_ctx.name],
3345
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.model[_ctx.name] = $event),
3346
+ size: _ctx.size,
3347
+ "value-format": "HH:mm:ss",
3348
+ placeholder: _ctx.config.placeholder,
3349
+ disabled: _ctx.disabled,
3350
+ onChange: _ctx.changeHandler
3351
+ }, null, 8, ["modelValue", "size", "placeholder", "disabled", "onChange"])
3352
+ ]);
3353
+ }
3354
+ var Time = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2]]);
3355
+
3356
+ const _sfc_main$1 = defineComponent({
3357
+ name: "m-form",
3358
+ components: { ElForm, MContainer: Container },
3359
+ props: {
3360
+ initValues: {
3361
+ type: Object,
3362
+ required: true,
3363
+ default: () => ({})
3364
+ },
3365
+ parentValues: {
3366
+ type: Object,
3367
+ default: () => ({})
3368
+ },
3369
+ config: {
3370
+ type: Array,
3371
+ required: true,
3372
+ default: () => []
3373
+ },
3374
+ labelWidth: {
3375
+ type: String,
3376
+ default: () => "200px"
3377
+ },
3378
+ disabled: {
3379
+ type: Boolean,
3380
+ default: () => false
3381
+ },
3382
+ height: {
3383
+ type: String,
3384
+ default: () => "auto"
3385
+ },
3386
+ stepActive: {
3387
+ type: [String, Number],
3388
+ default: () => 1
3389
+ },
3390
+ size: {
3391
+ type: String,
3392
+ default: "small"
3393
+ },
3394
+ inline: {
3395
+ type: Boolean,
3396
+ default: false
3397
+ },
3398
+ labelPosition: {
3399
+ type: String,
3400
+ default: "right"
3401
+ },
3402
+ keyProp: {
3403
+ type: String,
3404
+ default: "__key"
3405
+ }
3406
+ },
3407
+ emits: ["change", "field-input", "field-change"],
3408
+ setup(props, { emit }) {
3409
+ const elForm = ref();
3410
+ const initialized = ref(false);
3411
+ const values = ref({});
3412
+ const fields = /* @__PURE__ */ new Map();
3413
+ const requestFuc = getConfig("request");
3414
+ const formState = reactive({
3415
+ keyProp: props.keyProp,
3416
+ config: props.config,
3417
+ initValues: props.initValues,
3418
+ parentValues: props.parentValues,
3419
+ values,
3420
+ $emit: emit,
3421
+ fields,
3422
+ setField: (prop, field) => fields.set(prop, field),
3423
+ getField: (prop) => fields.get(prop),
3424
+ deleteField: (prop) => fields.delete(prop),
3425
+ post: (options) => {
3426
+ if (requestFuc) {
3427
+ return requestFuc({
3428
+ ...options,
3429
+ method: "POST"
3430
+ });
3431
+ }
3432
+ }
3433
+ });
3434
+ provide("mForm", formState);
3435
+ watchEffect(() => {
3436
+ initialized.value = false;
3437
+ initValue(formState, {
3438
+ initValues: props.initValues,
3439
+ config: props.config
3440
+ }).then((value) => {
3441
+ values.value = value;
3442
+ initialized.value = true;
3443
+ });
3444
+ });
3445
+ return {
3446
+ initialized,
3447
+ values,
3448
+ elForm,
3449
+ formState,
3450
+ changeHandler: () => {
3451
+ emit("change", values.value);
3452
+ },
3453
+ resetForm: () => elForm.value?.resetFields(),
3454
+ submitForm: async (native) => {
3455
+ try {
3456
+ await elForm.value?.validate();
3457
+ return native ? values.value : cloneDeep(values.value);
3458
+ } catch (invalidFields) {
3459
+ const error = [];
3460
+ Object.entries(invalidFields).forEach(([, ValidateError]) => {
3461
+ ValidateError.forEach(({ field, message }) => {
3462
+ if (field && message)
3463
+ error.push(`${field} -> ${message}`);
3464
+ if (field && !message)
3465
+ error.push(`${field} -> \u51FA\u73B0\u9519\u8BEF`);
3466
+ if (!field && message)
3467
+ error.push(`${message}`);
3468
+ });
3469
+ });
3470
+ throw new Error(error.join("<br>"));
3471
+ }
3472
+ }
3473
+ };
3474
+ }
3475
+ });
3476
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
3477
+ const _component_MContainer = resolveComponent("MContainer");
3478
+ const _component_ElForm = resolveComponent("ElForm");
3479
+ return _ctx.initialized && Array.isArray(_ctx.config) ? (openBlock(), createBlock(_component_ElForm, {
3480
+ key: 0,
3481
+ class: "m-form",
3482
+ ref: "elForm",
3483
+ model: _ctx.values,
3484
+ "label-width": _ctx.labelWidth,
3485
+ disabled: _ctx.disabled,
3486
+ style: normalizeStyle(`height: ${_ctx.height}`),
3487
+ inline: _ctx.inline,
3488
+ "label-position": _ctx.labelPosition
3489
+ }, {
3490
+ default: withCtx(() => [
3491
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.config, (item, index) => {
3492
+ return openBlock(), createBlock(_component_MContainer, {
3493
+ key: item[_ctx.keyProp] ?? index,
3494
+ config: item,
3495
+ model: _ctx.values,
3496
+ "label-width": item.labelWidth || _ctx.labelWidth,
3497
+ "step-active": _ctx.stepActive,
3498
+ size: _ctx.size,
3499
+ onChange: _ctx.changeHandler
3500
+ }, null, 8, ["config", "model", "label-width", "step-active", "size", "onChange"]);
3501
+ }), 128))
3502
+ ]),
3503
+ _: 1
3504
+ }, 8, ["model", "label-width", "disabled", "style", "inline", "label-position"])) : createCommentVNode("", true);
3505
+ }
3506
+ var Form = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
3507
+
3508
+ const _sfc_main = defineComponent({
3509
+ name: "m-form-dialog",
3510
+ props: {
3511
+ values: {
3512
+ type: Object,
3513
+ default: () => ({})
3514
+ },
3515
+ width: [Number, String],
3516
+ fullscreen: Boolean,
3517
+ title: String,
3518
+ config: {
3519
+ type: Array,
3520
+ required: true,
3521
+ default: () => []
3522
+ },
3523
+ labelWidth: [Number, String],
3524
+ confirmText: {
3525
+ type: String,
3526
+ default: "\u786E\u5B9A"
3527
+ }
3528
+ },
3529
+ emits: ["close", "submit", "error", "change"],
3530
+ setup(props, { emit }) {
3531
+ const form = ref();
3532
+ const dialogVisible = ref(false);
3533
+ const saveFetch = ref(false);
3534
+ const stepActive = ref(1);
3535
+ const bodyHeight = ref(`${document.body.clientHeight - 194}px`);
3536
+ const stepCount = computed(() => {
3537
+ const { length } = props.config;
3538
+ for (let index = 0; index < length; index++) {
3539
+ if (props.config[index].type === "step") {
3540
+ return props.config[index].items.length;
3541
+ }
3542
+ }
3543
+ return 0;
3544
+ });
3545
+ const hasStep = computed(() => {
3546
+ const { length } = props.config;
3547
+ for (let index = 0; index < length; index++) {
3548
+ if (props.config[index].type === "step") {
3549
+ return true;
3550
+ }
3551
+ }
3552
+ return false;
3553
+ });
3554
+ const cancel = () => {
3555
+ dialogVisible.value = false;
3556
+ };
3557
+ const closeHandler = () => {
3558
+ stepActive.value = 1;
3559
+ emit("close");
3560
+ };
3561
+ const save = async () => {
3562
+ try {
3563
+ const values = await form.value?.submitForm();
3564
+ emit("submit", values);
3565
+ } catch (e) {
3566
+ emit("error", e);
3567
+ }
3568
+ };
3569
+ const preStep = () => {
3570
+ stepActive.value -= 1;
3571
+ };
3572
+ const nextStep = () => {
3573
+ stepActive.value += 1;
3574
+ };
3575
+ const changeHandler = (value) => {
3576
+ emit("change", value);
3577
+ };
3578
+ return {
3579
+ form,
3580
+ saveFetch,
3581
+ stepActive,
3582
+ dialogVisible,
3583
+ bodyHeight,
3584
+ stepCount,
3585
+ hasStep,
3586
+ cancel,
3587
+ closeHandler,
3588
+ save,
3589
+ preStep,
3590
+ nextStep,
3591
+ changeHandler
3592
+ };
3593
+ }
3594
+ });
3595
+ const _hoisted_1 = { style: { "min-height": "1px" } };
3596
+ const _hoisted_2 = /* @__PURE__ */ createTextVNode("\u53D6 \u6D88");
3597
+ const _hoisted_3 = /* @__PURE__ */ createTextVNode("\u4E0A\u4E00\u6B65");
3598
+ const _hoisted_4 = /* @__PURE__ */ createTextVNode("\u4E0B\u4E00\u6B65");
3599
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
3600
+ const _component_m_form = resolveComponent("m-form");
3601
+ const _component_el_col = resolveComponent("el-col");
3602
+ const _component_el_button = resolveComponent("el-button");
3603
+ const _component_el_row = resolveComponent("el-row");
3604
+ const _component_el_dialog = resolveComponent("el-dialog");
3605
+ return openBlock(), createElementBlock("div", null, [
3606
+ createVNode(_component_el_dialog, {
3607
+ modelValue: _ctx.dialogVisible,
3608
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => _ctx.dialogVisible = $event),
3609
+ "custom-class": "m-form-dialog",
3610
+ top: "20px",
3611
+ title: _ctx.title,
3612
+ appendToBody: true,
3613
+ width: _ctx.width,
3614
+ fullscreen: _ctx.fullscreen,
3615
+ "close-on-click-modal": false,
3616
+ onClose: _ctx.closeHandler
3617
+ }, {
3618
+ footer: withCtx(() => [
3619
+ createVNode(_component_el_row, { class: "dialog-footer" }, {
3620
+ default: withCtx(() => [
3621
+ createVNode(_component_el_col, {
3622
+ span: 12,
3623
+ style: { "text-align": "left" }
3624
+ }, {
3625
+ default: withCtx(() => [
3626
+ createElementVNode("div", _hoisted_1, [
3627
+ renderSlot(_ctx.$slots, "left")
3628
+ ])
3629
+ ]),
3630
+ _: 3
3631
+ }),
3632
+ createVNode(_component_el_col, { span: 12 }, {
3633
+ default: withCtx(() => [
3634
+ renderSlot(_ctx.$slots, "footer", {}, () => [
3635
+ createVNode(_component_el_button, {
3636
+ onClick: _ctx.cancel,
3637
+ size: "small"
3638
+ }, {
3639
+ default: withCtx(() => [
3640
+ _hoisted_2
3641
+ ]),
3642
+ _: 1
3643
+ }, 8, ["onClick"]),
3644
+ _ctx.hasStep && _ctx.stepActive > 1 ? (openBlock(), createBlock(_component_el_button, {
3645
+ key: 0,
3646
+ type: "info",
3647
+ size: "small",
3648
+ onClick: _ctx.preStep
3649
+ }, {
3650
+ default: withCtx(() => [
3651
+ _hoisted_3
3652
+ ]),
3653
+ _: 1
3654
+ }, 8, ["onClick"])) : createCommentVNode("", true),
3655
+ _ctx.hasStep && _ctx.stepCount > _ctx.stepActive ? (openBlock(), createBlock(_component_el_button, {
3656
+ key: 1,
3657
+ type: "info",
3658
+ size: "small",
3659
+ onClick: _ctx.nextStep
3660
+ }, {
3661
+ default: withCtx(() => [
3662
+ _hoisted_4
3663
+ ]),
3664
+ _: 1
3665
+ }, 8, ["onClick"])) : (openBlock(), createBlock(_component_el_button, {
3666
+ key: 2,
3667
+ type: "primary",
3668
+ size: "small",
3669
+ loading: _ctx.saveFetch,
3670
+ onClick: _ctx.save
3671
+ }, {
3672
+ default: withCtx(() => [
3673
+ createTextVNode(toDisplayString(_ctx.confirmText), 1)
3674
+ ]),
3675
+ _: 1
3676
+ }, 8, ["loading", "onClick"]))
3677
+ ])
3678
+ ]),
3679
+ _: 3
3680
+ })
3681
+ ]),
3682
+ _: 3
3683
+ })
3684
+ ]),
3685
+ default: withCtx(() => [
3686
+ createElementVNode("div", {
3687
+ class: "m-dialog-body",
3688
+ style: normalizeStyle(`max-height: ${_ctx.bodyHeight}; overflow-y: auto; overflow-x: hidden;`)
3689
+ }, [
3690
+ createVNode(_component_m_form, {
3691
+ modelValue: _ctx.stepActive,
3692
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.stepActive = $event),
3693
+ ref: "form",
3694
+ config: _ctx.config,
3695
+ "init-values": _ctx.values,
3696
+ "label-width": _ctx.labelWidth,
3697
+ onChange: _ctx.changeHandler
3698
+ }, null, 8, ["modelValue", "config", "init-values", "label-width", "onChange"]),
3699
+ renderSlot(_ctx.$slots, "default")
3700
+ ], 4)
3701
+ ]),
3702
+ _: 3
3703
+ }, 8, ["modelValue", "title", "width", "fullscreen", "onClose"])
3704
+ ]);
3705
+ }
3706
+ var FormDialog = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
3707
+
3708
+ var index$1 = '';
3709
+
3710
+ const defaultInstallOpt = {};
3711
+ const install = (app, opt) => {
3712
+ const option = Object.assign(defaultInstallOpt, opt);
3713
+ app.config.globalProperties.$MAGIC_FORM = option;
3714
+ setConfig(option);
3715
+ app.component(Form.name, Form);
3716
+ app.component(FormDialog.name, FormDialog);
3717
+ app.component(Container.name, Container);
3718
+ app.component(Fieldset.name, Fieldset);
3719
+ app.component(GroupList.name, GroupList);
3720
+ app.component(Panel.name, Panel);
3721
+ app.component(Row.name, Row);
3722
+ app.component(MStep.name, MStep);
3723
+ app.component(Table.name, Table);
3724
+ app.component(Tabs.name, Tabs);
3725
+ app.component(Text.name, Text);
3726
+ app.component(Number$1.name, Number$1);
3727
+ app.component(Textarea.name, Textarea);
3728
+ app.component(_sfc_main$a.name, _sfc_main$a);
3729
+ app.component(Date$1.name, Date$1);
3730
+ app.component(DateTime.name, DateTime);
3731
+ app.component(Time.name, Time);
3732
+ app.component(Checkbox.name, Checkbox);
3733
+ app.component(Switch.name, Switch);
3734
+ app.component(Daterange.name, Daterange);
3735
+ app.component(_sfc_main$g.name, _sfc_main$g);
3736
+ app.component(CheckboxGroup.name, CheckboxGroup);
3737
+ app.component(RadioGroup.name, RadioGroup);
3738
+ app.component(_sfc_main$c.name, _sfc_main$c);
3739
+ app.component(Link.name, Link);
3740
+ app.component(Select.name, Select);
3741
+ app.component(Cascader.name, Cascader);
3742
+ app.component(DynamicField.name, DynamicField);
3743
+ };
3744
+ var index = {
3745
+ install
3746
+ };
3747
+
3748
+ export { Cascader as MCascader, Checkbox as MCheckbox, CheckboxGroup as MCheckboxGroup, _sfc_main$g as MColorPicker, Container as MContainer, Date$1 as MDate, DateTime as MDateTime, Daterange as MDaterange, _sfc_main$c as MDisplay, DynamicField as MDynamicField, Fieldset as MFieldset, Form as MForm, FormDialog as MFormDialog, GroupList as MGroupList, _sfc_main$a as MHidden, Link as MLink, Number$1 as MNumber, Panel as MPanel, RadioGroup as MRadioGroup, Row as MRow, Select as MSelect, Switch as MSwitch, Table as MTable, Tabs as MTabs, Text as MText, Textarea as MTextarea, Time as MTime, index as default, display, fieldProps, filterFunction, getRules, initValue, useAddField };
3749
+ //# sourceMappingURL=tmagic-form.es.js.map