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