@tmagic/form 1.2.0-beta.2 → 1.2.0-beta.21

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