@iswangh/element-plus-kit-form 0.1.2 → 0.1.3
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.
- package/README.md +4 -4
- package/dist/FormAction.vue.d.ts.map +1 -1
- package/dist/FormItem.vue.d.ts.map +1 -1
- package/dist/composables/index.d.ts +2 -0
- package/dist/composables/index.d.ts.map +1 -0
- package/dist/composables/useChangeEventState.d.ts +35 -0
- package/dist/composables/useChangeEventState.d.ts.map +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/index.js +365 -192
- package/dist/style.css +1 -1
- package/dist/types/action.d.ts +28 -0
- package/dist/types/common.d.ts +9 -0
- package/dist/types/el.d.ts +43 -0
- package/dist/types/form-item.d.ts +109 -0
- package/dist/types/index.d.ts +5 -125
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/options.d.ts +89 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/options.d.ts +21 -0
- package/dist/utils/options.d.ts.map +1 -0
- package/dist/utils/value.d.ts +13 -0
- package/dist/utils/value.d.ts.map +1 -0
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { checkCondition as
|
|
3
|
-
import { ElTreeSelect as
|
|
4
|
-
var
|
|
1
|
+
import { defineComponent as P, createElementBlock as N, openBlock as p, createElementVNode as J, computed as f, withDirectives as Q, createCommentVNode as ae, createBlock as I, unref as V, withCtx as b, Fragment as Z, renderList as B, mergeProps as D, createTextVNode as se, toDisplayString as ie, resolveDynamicComponent as F, vShow as ee, mergeModels as W, useModel as ce, ref as L, watch as G, watchEffect as ue, normalizeProps as te, guardReactiveProps as oe, createSlots as K, renderSlot as me, nextTick as H, useAttrs as fe, useSlots as de, withModifiers as pe, createVNode as q } from "vue";
|
|
2
|
+
import { checkCondition as X } from "@iswangh/element-plus-kit-core";
|
|
3
|
+
import { ElTreeSelect as ve, ElTransfer as ge, ElTimeSelect as he, ElTimePicker as Ce, ElSwitch as Ee, ElSlider as Ie, ElSelectV2 as ye, ElSelect as Ae, ElRate as be, ElRadioGroup as Se, ElMention as we, ElInputTag as Oe, ElInputNumber as ke, ElInput as De, ElDatePicker as Fe, ElDatePickerPanel as Te, ElColorPicker as Me, ElColorPickerPanel as Ve, ElCheckboxGroup as Pe, ElCascader as xe, ElAutocomplete as _e, ElFormItem as ne, ElButton as Be, ElCol as Ne, ElRow as Ue, ElForm as Re } from "element-plus";
|
|
4
|
+
var $e = /* @__PURE__ */ P({
|
|
5
5
|
name: "Refresh",
|
|
6
6
|
__name: "refresh",
|
|
7
7
|
setup(e) {
|
|
8
|
-
return (
|
|
8
|
+
return (n, t) => (p(), N("svg", {
|
|
9
9
|
xmlns: "http://www.w3.org/2000/svg",
|
|
10
10
|
viewBox: "0 0 1024 1024"
|
|
11
11
|
}, [
|
|
12
|
-
|
|
12
|
+
J("path", {
|
|
13
13
|
fill: "currentColor",
|
|
14
14
|
d: "M771.776 794.88A384 384 0 0 1 128 512h64a320 320 0 0 0 555.712 216.448H654.72a32 32 0 1 1 0-64h149.056a32 32 0 0 1 32 32v148.928a32 32 0 1 1-64 0v-50.56zM276.288 295.616h92.992a32 32 0 0 1 0 64H220.16a32 32 0 0 1-32-32V178.56a32 32 0 0 1 64 0v50.56A384 384 0 0 1 896.128 512h-64a320 320 0 0 0-555.776-216.384z"
|
|
15
15
|
})
|
|
16
16
|
]));
|
|
17
17
|
}
|
|
18
|
-
}),
|
|
18
|
+
}), je = $e, Le = /* @__PURE__ */ P({
|
|
19
19
|
name: "Search",
|
|
20
20
|
__name: "search",
|
|
21
21
|
setup(e) {
|
|
22
|
-
return (
|
|
22
|
+
return (n, t) => (p(), N("svg", {
|
|
23
23
|
xmlns: "http://www.w3.org/2000/svg",
|
|
24
24
|
viewBox: "0 0 1024 1024"
|
|
25
25
|
}, [
|
|
26
|
-
|
|
26
|
+
J("path", {
|
|
27
27
|
fill: "currentColor",
|
|
28
28
|
d: "m795.904 750.72 124.992 124.928a32 32 0 0 1-45.248 45.248L750.656 795.904a416 416 0 1 1 45.248-45.248zM480 832a352 352 0 1 0 0-704 352 352 0 0 0 0 704"
|
|
29
29
|
})
|
|
30
30
|
]));
|
|
31
31
|
}
|
|
32
|
-
}),
|
|
33
|
-
const
|
|
32
|
+
}), ze = Le;
|
|
33
|
+
const We = ["comp", "compAttrs", "vIf", "vShow"], Ge = {
|
|
34
34
|
custom: "div"
|
|
35
|
-
},
|
|
36
|
-
autocomplete:
|
|
37
|
-
cascader:
|
|
38
|
-
checkbox:
|
|
39
|
-
"color-picker-panel":
|
|
40
|
-
"color-picker":
|
|
41
|
-
"date-picker-panel":
|
|
42
|
-
"date-picker":
|
|
43
|
-
input:
|
|
44
|
-
"input-number":
|
|
45
|
-
"input-tag":
|
|
46
|
-
mention:
|
|
47
|
-
radio:
|
|
48
|
-
rate:
|
|
49
|
-
select:
|
|
50
|
-
"select-v2":
|
|
51
|
-
slider:
|
|
52
|
-
switch:
|
|
53
|
-
"time-picker":
|
|
54
|
-
"time-select":
|
|
55
|
-
transfer:
|
|
56
|
-
"tree-select":
|
|
57
|
-
},
|
|
58
|
-
...
|
|
59
|
-
...
|
|
60
|
-
},
|
|
35
|
+
}, Ke = {
|
|
36
|
+
autocomplete: _e,
|
|
37
|
+
cascader: xe,
|
|
38
|
+
checkbox: Pe,
|
|
39
|
+
"color-picker-panel": Ve,
|
|
40
|
+
"color-picker": Me,
|
|
41
|
+
"date-picker-panel": Te,
|
|
42
|
+
"date-picker": Fe,
|
|
43
|
+
input: De,
|
|
44
|
+
"input-number": ke,
|
|
45
|
+
"input-tag": Oe,
|
|
46
|
+
mention: we,
|
|
47
|
+
radio: Se,
|
|
48
|
+
rate: be,
|
|
49
|
+
select: Ae,
|
|
50
|
+
"select-v2": ye,
|
|
51
|
+
slider: Ie,
|
|
52
|
+
switch: Ee,
|
|
53
|
+
"time-picker": Ce,
|
|
54
|
+
"time-select": he,
|
|
55
|
+
transfer: ge,
|
|
56
|
+
"tree-select": ve
|
|
57
|
+
}, He = {
|
|
58
|
+
...Ke,
|
|
59
|
+
...Ge
|
|
60
|
+
}, qe = {
|
|
61
61
|
/**
|
|
62
62
|
* 获取组件默认属性
|
|
63
63
|
*/
|
|
64
64
|
getDefaults(e) {
|
|
65
|
-
const { comp:
|
|
65
|
+
const { comp: n, compAttrs: t = {} } = e, s = this.getComponentType(n);
|
|
66
66
|
return {
|
|
67
67
|
...this.buildComponentAttrs(e, s),
|
|
68
|
-
...
|
|
68
|
+
...t
|
|
69
69
|
// 用户配置最后合并,优先级最高
|
|
70
70
|
};
|
|
71
71
|
},
|
|
@@ -73,24 +73,24 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
|
|
|
73
73
|
* 判断组件类型
|
|
74
74
|
*/
|
|
75
75
|
getComponentType(e) {
|
|
76
|
-
const
|
|
77
|
-
return
|
|
76
|
+
const n = ["autocomplete", "input", "input-number", "input-tag", "mention"], t = ["cascader", "select", "select-v2", "tree-select"], s = ["date-picker", "time-select", "time-picker"];
|
|
77
|
+
return n.includes(e) ? "input" : t.includes(e) ? "select" : s.includes(e) ? "picker" : "other";
|
|
78
78
|
},
|
|
79
79
|
/**
|
|
80
80
|
* 动态生成 placeholder
|
|
81
81
|
*/
|
|
82
|
-
generatePlaceholder(e,
|
|
83
|
-
const { label:
|
|
84
|
-
return
|
|
82
|
+
generatePlaceholder(e, n) {
|
|
83
|
+
const { label: t, comp: s } = e, l = t ? `${t}` : "";
|
|
84
|
+
return n === "input" ? s === "input-number" ? "请输入" : `请输入${l}` : ["select", "picker"].includes(n) ? `请选择${l}` : "";
|
|
85
85
|
},
|
|
86
86
|
/**
|
|
87
87
|
* 构建组件属性
|
|
88
88
|
*/
|
|
89
|
-
buildComponentAttrs(e,
|
|
90
|
-
const
|
|
91
|
-
return ["input", "select", "picker"].includes(
|
|
89
|
+
buildComponentAttrs(e, n) {
|
|
90
|
+
const t = {};
|
|
91
|
+
return ["input", "select", "picker"].includes(n) && (t.placeholder = this.generatePlaceholder(e, n), t.clearable = !0), ["select"].includes(n) && (t.filterable = !0), t;
|
|
92
92
|
}
|
|
93
|
-
},
|
|
93
|
+
}, Xe = {
|
|
94
94
|
showMessage: !0,
|
|
95
95
|
scrollToError: !0,
|
|
96
96
|
scrollIntoViewOptions: {
|
|
@@ -101,16 +101,16 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
|
|
|
101
101
|
inline: "nearest"
|
|
102
102
|
// 水平方向保持最近位置
|
|
103
103
|
}
|
|
104
|
-
},
|
|
105
|
-
search: { label: "搜索", icon:
|
|
106
|
-
reset: { label: "重置", icon:
|
|
104
|
+
}, Ye = {
|
|
105
|
+
search: { label: "搜索", icon: ze, type: "primary" },
|
|
106
|
+
reset: { label: "重置", icon: je },
|
|
107
107
|
submit: { label: "确认", type: "primary" },
|
|
108
108
|
cancel: { label: "取消" }
|
|
109
|
-
},
|
|
110
|
-
getDefaults(e,
|
|
109
|
+
}, Je = {
|
|
110
|
+
getDefaults(e, n) {
|
|
111
111
|
return {
|
|
112
112
|
...this.buildActionAttrs(e),
|
|
113
|
-
...
|
|
113
|
+
...n
|
|
114
114
|
};
|
|
115
115
|
},
|
|
116
116
|
generateActionButtons(e) {
|
|
@@ -123,7 +123,7 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
|
|
|
123
123
|
vShow: !0
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
-
},
|
|
126
|
+
}, Qe = /* @__PURE__ */ P({
|
|
127
127
|
name: "ElementPlusKitFormItemAction",
|
|
128
128
|
__name: "FormAction",
|
|
129
129
|
props: {
|
|
@@ -133,47 +133,118 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
|
|
|
133
133
|
},
|
|
134
134
|
emits: ["action"],
|
|
135
135
|
setup(e) {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
const n = e, t = f(() => ({
|
|
137
|
+
...n,
|
|
138
|
+
config: { ...Je.getDefaults(n.inline, n.config) }
|
|
139
|
+
})), s = f(() => {
|
|
140
|
+
const { buttons: d } = t.value.config;
|
|
141
|
+
return d.map((m) => {
|
|
142
|
+
if (typeof m != "string")
|
|
143
|
+
return m;
|
|
144
|
+
const v = Ye[m];
|
|
145
|
+
return v ? { ...v, eventName: m } : { label: m.toUpperCase(), eventName: m };
|
|
144
146
|
});
|
|
145
|
-
}),
|
|
146
|
-
const { label:
|
|
147
|
-
return
|
|
148
|
-
}
|
|
149
|
-
return (
|
|
147
|
+
}), l = (d) => {
|
|
148
|
+
const { label: m, eventName: v, ...g } = d;
|
|
149
|
+
return g;
|
|
150
|
+
};
|
|
151
|
+
return (d, m) => t.value.config.vIf ? Q((p(), I(V(ne), {
|
|
150
152
|
key: 0,
|
|
151
153
|
prop: "action"
|
|
152
154
|
}, {
|
|
153
|
-
default:
|
|
154
|
-
e.actionSlot ? (
|
|
155
|
+
default: b(() => [
|
|
156
|
+
e.actionSlot ? (p(), I(F(e.actionSlot), {
|
|
155
157
|
key: 1,
|
|
156
158
|
prop: "action"
|
|
157
|
-
})) : (
|
|
158
|
-
key: `${
|
|
159
|
-
}, { ref_for: !0 },
|
|
160
|
-
onClick: (
|
|
159
|
+
})) : (p(!0), N(Z, { key: 0 }, B(s.value, (v, g) => (p(), I(V(Be), D({
|
|
160
|
+
key: `${v.label}-${g}`
|
|
161
|
+
}, { ref_for: !0 }, l(v), {
|
|
162
|
+
onClick: (T) => d.$emit("action", { eventName: v.eventName })
|
|
161
163
|
}), {
|
|
162
|
-
default:
|
|
163
|
-
|
|
164
|
+
default: b(() => [
|
|
165
|
+
se(ie(v.label ?? ""), 1)
|
|
164
166
|
]),
|
|
165
167
|
_: 2
|
|
166
168
|
}, 1040, ["onClick"]))), 128))
|
|
167
169
|
]),
|
|
168
170
|
_: 1
|
|
169
171
|
}, 512)), [
|
|
170
|
-
[
|
|
171
|
-
]) :
|
|
172
|
+
[ee, t.value.config.vShow]
|
|
173
|
+
]) : ae("", !0);
|
|
172
174
|
}
|
|
173
|
-
})
|
|
175
|
+
});
|
|
176
|
+
function Ze() {
|
|
177
|
+
let e = !1, n = !1, t = null, s = !1;
|
|
178
|
+
return {
|
|
179
|
+
/** 是否正在清理 */
|
|
180
|
+
get isClearing() {
|
|
181
|
+
return e;
|
|
182
|
+
},
|
|
183
|
+
/** 是否用户交互 */
|
|
184
|
+
get isUserInteraction() {
|
|
185
|
+
return n;
|
|
186
|
+
},
|
|
187
|
+
/**
|
|
188
|
+
* 开始清理操作
|
|
189
|
+
* @param value - 清理前的值
|
|
190
|
+
*/
|
|
191
|
+
startClearing(l) {
|
|
192
|
+
e = !0, t = l, s = !0;
|
|
193
|
+
},
|
|
194
|
+
/**
|
|
195
|
+
* 结束清理操作(在 nextTick 中调用)
|
|
196
|
+
*/
|
|
197
|
+
endClearing() {
|
|
198
|
+
e = !1, t = null, s = !1;
|
|
199
|
+
},
|
|
200
|
+
/**
|
|
201
|
+
* 开始用户交互
|
|
202
|
+
*/
|
|
203
|
+
startUserInteraction() {
|
|
204
|
+
n = !0;
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
207
|
+
* 结束用户交互(在 nextTick 中调用)
|
|
208
|
+
*/
|
|
209
|
+
endUserInteraction() {
|
|
210
|
+
n = !1;
|
|
211
|
+
},
|
|
212
|
+
/**
|
|
213
|
+
* 判断是否是清理操作
|
|
214
|
+
* @param oldValue - 旧值
|
|
215
|
+
* @param newValue - 新值
|
|
216
|
+
* @param isEmpty - 检查值是否为空的函数
|
|
217
|
+
*/
|
|
218
|
+
isClearingOperation(l, d, m) {
|
|
219
|
+
return !!(e || s || !m(l) && m(d) && l === t);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function re(e, n) {
|
|
224
|
+
if (!e || e.length === 0)
|
|
225
|
+
return [];
|
|
226
|
+
const t = Array.from(new Set(e));
|
|
227
|
+
return n ? t.filter((s) => s !== n) : t;
|
|
228
|
+
}
|
|
229
|
+
function Y(e, n, t) {
|
|
230
|
+
const s = re(e, t), l = {};
|
|
231
|
+
for (const d of s)
|
|
232
|
+
l[d] = n[d];
|
|
233
|
+
return l;
|
|
234
|
+
}
|
|
235
|
+
function $(e) {
|
|
236
|
+
return e && typeof e == "object" && typeof e.loader == "function";
|
|
237
|
+
}
|
|
238
|
+
function z(e) {
|
|
239
|
+
return e == null || e === "";
|
|
240
|
+
}
|
|
241
|
+
function j(e, n) {
|
|
242
|
+
return n.length === 0 ? !1 : z(e) ? !0 : n.some((t) => (typeof t == "object" && t !== null ? t.value : t) === e);
|
|
243
|
+
}
|
|
244
|
+
const et = /* @__PURE__ */ P({
|
|
174
245
|
name: "ElementPlusKitFormItem",
|
|
175
246
|
__name: "FormItem",
|
|
176
|
-
props: /* @__PURE__ */
|
|
247
|
+
props: /* @__PURE__ */ W({
|
|
177
248
|
formItem: {},
|
|
178
249
|
index: {},
|
|
179
250
|
formData: { default: () => ({}) },
|
|
@@ -183,65 +254,168 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
|
|
|
183
254
|
modelValue: {},
|
|
184
255
|
modelModifiers: {}
|
|
185
256
|
}),
|
|
186
|
-
emits: /* @__PURE__ */
|
|
187
|
-
setup(e) {
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
const m = new Set(Pe);
|
|
257
|
+
emits: /* @__PURE__ */ W(["change"], ["update:modelValue"]),
|
|
258
|
+
setup(e, { emit: n }) {
|
|
259
|
+
const t = e, s = n, l = ce(e, "modelValue"), d = f(() => {
|
|
260
|
+
const o = new Set(We);
|
|
191
261
|
return Object.fromEntries(
|
|
192
|
-
Object.entries(
|
|
262
|
+
Object.entries(t.formItem).filter(([i]) => !o.has(i))
|
|
193
263
|
);
|
|
264
|
+
}), m = f(() => t.formSlots.formItemSlots), v = f(() => He[t.formItem.comp] || "div"), g = f(() => ({ prop: t.formItem.prop, formItem: t.formItem, index: t.index })), T = f(() => Object.fromEntries(
|
|
265
|
+
Object.entries(t.dynamicCompEvents).map(([o, i]) => [
|
|
266
|
+
o,
|
|
267
|
+
(...c) => i(g.value, ...c)
|
|
268
|
+
])
|
|
269
|
+
)), S = L([]), w = L(!1), E = Ze();
|
|
270
|
+
function O() {
|
|
271
|
+
if (!z(l.value)) {
|
|
272
|
+
if (E.isClearing)
|
|
273
|
+
return;
|
|
274
|
+
E.startClearing(l.value), l.value = void 0, s("change", g.value, void 0), H(() => {
|
|
275
|
+
E.endClearing();
|
|
276
|
+
});
|
|
277
|
+
}
|
|
194
278
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
279
|
+
function x(o) {
|
|
280
|
+
E.isClearing || (E.startUserInteraction(), s("change", g.value, o), H(() => {
|
|
281
|
+
E.endUserInteraction();
|
|
282
|
+
}));
|
|
283
|
+
}
|
|
284
|
+
const h = f(() => {
|
|
285
|
+
const o = qe.getDefaults(t.formItem), i = t.formItem.compAttrs ?? {}, c = "options" in i;
|
|
286
|
+
return {
|
|
287
|
+
...o,
|
|
288
|
+
...i,
|
|
289
|
+
...T.value,
|
|
290
|
+
...c && {
|
|
291
|
+
options: S.value,
|
|
292
|
+
loading: w.value
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
}), U = (o) => t.formSlots.dynamicComponentSlots.get(o);
|
|
296
|
+
async function r(o, i) {
|
|
297
|
+
try {
|
|
298
|
+
const c = await o(i);
|
|
299
|
+
return Array.isArray(c) ? c : [];
|
|
300
|
+
} catch (c) {
|
|
301
|
+
return console.error(`[FormItem] 加载字段 "${t.formItem.prop}" 的选项失败:`, c), [];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function a() {
|
|
305
|
+
const o = t.formItem.compAttrs?.options;
|
|
306
|
+
return $(o) ? o : null;
|
|
307
|
+
}
|
|
308
|
+
async function u() {
|
|
309
|
+
const o = t.formItem.compAttrs?.options;
|
|
310
|
+
if (o && !Array.isArray(o)) {
|
|
311
|
+
w.value = !0;
|
|
312
|
+
try {
|
|
313
|
+
if (typeof o == "function") {
|
|
314
|
+
const i = await r(o, t.formData ?? {});
|
|
315
|
+
S.value = i, j(l.value, i) || O();
|
|
316
|
+
} else if ($(o)) {
|
|
317
|
+
const { loader: i, deps: c = [] } = o, k = t.formData ?? {}, A = Y(c, k, t.formItem.prop), _ = await r(i, { ...k, ...A });
|
|
318
|
+
S.value = _, j(l.value, _) || O();
|
|
319
|
+
}
|
|
320
|
+
} finally {
|
|
321
|
+
w.value = !1;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function C(o) {
|
|
326
|
+
S.value = o, j(l.value, o) || O();
|
|
327
|
+
}
|
|
328
|
+
function y() {
|
|
329
|
+
u();
|
|
204
330
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
331
|
+
function M(o) {
|
|
332
|
+
const { immediate: i = !1, deps: c = [], loader: k } = o;
|
|
333
|
+
if (c.length > 0) {
|
|
334
|
+
const A = t.formData ?? {}, _ = Y(c, A, t.formItem.prop);
|
|
335
|
+
try {
|
|
336
|
+
k({ ...A, ..._ });
|
|
337
|
+
} catch {
|
|
338
|
+
}
|
|
339
|
+
i && u();
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
i && u();
|
|
343
|
+
}
|
|
344
|
+
const R = f(() => {
|
|
345
|
+
const o = a();
|
|
346
|
+
return o ? re(o.deps ?? [], t.formItem.prop) : [];
|
|
347
|
+
}), le = f(() => {
|
|
348
|
+
const o = a();
|
|
349
|
+
return o ? o.immediate ?? !1 : !1;
|
|
350
|
+
});
|
|
351
|
+
return G(
|
|
352
|
+
() => {
|
|
353
|
+
const o = R.value, i = {};
|
|
354
|
+
for (const c of o)
|
|
355
|
+
i[c] = t.formData?.[c];
|
|
356
|
+
return i;
|
|
357
|
+
},
|
|
358
|
+
() => {
|
|
359
|
+
a() && u();
|
|
360
|
+
},
|
|
361
|
+
{ deep: !0, immediate: le.value }
|
|
362
|
+
), ue(() => {
|
|
363
|
+
const o = t.formItem.compAttrs?.options;
|
|
364
|
+
if (o) {
|
|
365
|
+
if (Array.isArray(o)) {
|
|
366
|
+
C(o);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (typeof o == "function") {
|
|
370
|
+
y();
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
$(o) && M(o);
|
|
374
|
+
}
|
|
375
|
+
}), G(
|
|
376
|
+
() => l.value,
|
|
377
|
+
(o, i) => {
|
|
378
|
+
E.isClearingOperation(i, o, z) || E.isUserInteraction || o !== i && s("change", g.value, o);
|
|
379
|
+
}
|
|
380
|
+
), (o, i) => (p(), I(V(ne), te(oe(d.value)), K({
|
|
381
|
+
default: b(() => [
|
|
382
|
+
e.formItem.comp !== "custom" ? (p(), I(F(v.value), D({ key: 0 }, h.value, {
|
|
383
|
+
modelValue: l.value,
|
|
384
|
+
"onUpdate:modelValue": i[0] || (i[0] = (c) => l.value = c),
|
|
385
|
+
onChange: x
|
|
386
|
+
}), K({ _: 2 }, [
|
|
387
|
+
B(U(e.formItem.prop) ?? [], (c, k) => ({
|
|
388
|
+
name: c.slotName,
|
|
389
|
+
fn: b((A) => [
|
|
390
|
+
(p(), I(F(c.slotFn), D({
|
|
391
|
+
value: l.value,
|
|
218
392
|
form: e.formData,
|
|
219
393
|
"form-item": e.formItem
|
|
220
|
-
},
|
|
394
|
+
}, A), null, 16, ["value", "form", "form-item"]))
|
|
221
395
|
])
|
|
222
396
|
}))
|
|
223
|
-
]), 1040, ["modelValue"])) :
|
|
397
|
+
]), 1040, ["modelValue"])) : me(o.$slots, e.formItem.prop, {
|
|
224
398
|
key: 1,
|
|
225
|
-
value:
|
|
399
|
+
value: l.value,
|
|
226
400
|
form: e.formData,
|
|
227
401
|
formItem: e.formItem
|
|
228
402
|
})
|
|
229
403
|
]),
|
|
230
404
|
_: 2
|
|
231
405
|
}, [
|
|
232
|
-
|
|
233
|
-
name:
|
|
234
|
-
fn:
|
|
235
|
-
(
|
|
236
|
-
value:
|
|
406
|
+
B(m.value, (c, k) => ({
|
|
407
|
+
name: c.slotName,
|
|
408
|
+
fn: b((A) => [
|
|
409
|
+
(p(), I(F(c.slotFn), D({
|
|
410
|
+
value: l.value,
|
|
237
411
|
form: e.formData,
|
|
238
412
|
"form-item": e.formItem
|
|
239
|
-
},
|
|
413
|
+
}, A), null, 16, ["value", "form", "form-item"]))
|
|
240
414
|
])
|
|
241
415
|
}))
|
|
242
416
|
]), 1040));
|
|
243
417
|
}
|
|
244
|
-
}),
|
|
418
|
+
}), rt = /* @__PURE__ */ P({
|
|
245
419
|
name: "WForm",
|
|
246
420
|
__name: "Form",
|
|
247
421
|
props: {
|
|
@@ -265,97 +439,96 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
|
|
|
265
439
|
scrollIntoViewOptions: {}
|
|
266
440
|
},
|
|
267
441
|
emits: ["validate", "change", "action", "search", "reset", "submit", "cancel"],
|
|
268
|
-
setup(e, { expose:
|
|
269
|
-
const s = e,
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
)
|
|
442
|
+
setup(e, { expose: n, emit: t }) {
|
|
443
|
+
const s = e, l = t, d = fe();
|
|
444
|
+
function m(r, a) {
|
|
445
|
+
return r.startsWith("on") && typeof a == "function";
|
|
446
|
+
}
|
|
447
|
+
const v = f(() => Object.fromEntries(
|
|
448
|
+
Object.entries(d).filter(([r, a]) => m(r, a))
|
|
449
|
+
)), g = f(() => {
|
|
450
|
+
const { formItems: r, actionConfig: a, rowAttrs: u, ...C } = s, y = Object.fromEntries(
|
|
451
|
+
Object.entries(d).filter(([M, R]) => !m(M, R))
|
|
278
452
|
);
|
|
279
|
-
return { ...
|
|
280
|
-
}),
|
|
281
|
-
const { span:
|
|
282
|
-
return s.formItems.filter((
|
|
283
|
-
const { colAttrs:
|
|
284
|
-
return { ...
|
|
453
|
+
return { ...C, ...Xe, ...y };
|
|
454
|
+
}), T = f(() => {
|
|
455
|
+
const { span: r } = s?.rowAttrs ?? {};
|
|
456
|
+
return s.formItems.filter((a) => X({ condition: a.vIf, data: s.model, defaultValue: !0 })).map((a) => {
|
|
457
|
+
const { colAttrs: u = {} } = a ?? {};
|
|
458
|
+
return { ...a, colAttrs: { ...u, span: u.span ?? r } };
|
|
285
459
|
});
|
|
286
|
-
}),
|
|
287
|
-
function
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
slotFn: y[r]
|
|
294
|
-
});
|
|
295
|
-
return l;
|
|
460
|
+
}), S = de();
|
|
461
|
+
function w(r) {
|
|
462
|
+
return Object.keys(S).filter((a) => a.startsWith(r)).map((a) => ({
|
|
463
|
+
rawSlotName: a,
|
|
464
|
+
slotName: a.replace(r, ""),
|
|
465
|
+
slotFn: S[a]
|
|
466
|
+
}));
|
|
296
467
|
}
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
-
for (const
|
|
300
|
-
const
|
|
301
|
-
|
|
468
|
+
const E = f(() => {
|
|
469
|
+
const r = w("form-item-"), a = /* @__PURE__ */ new Map();
|
|
470
|
+
for (const u of T.value) {
|
|
471
|
+
const C = w(`${u.prop}-`);
|
|
472
|
+
C.length > 0 && a.set(u.prop, C);
|
|
302
473
|
}
|
|
303
|
-
return { formItemSlots:
|
|
304
|
-
}),
|
|
305
|
-
row:
|
|
306
|
-
col:
|
|
307
|
-
})),
|
|
308
|
-
async function
|
|
309
|
-
const
|
|
310
|
-
[...
|
|
474
|
+
return { formItemSlots: r, dynamicComponentSlots: a };
|
|
475
|
+
}), O = f(() => Object.keys(s.rowAttrs ?? {}).length > 0), x = f(() => ({
|
|
476
|
+
row: g.value.inline || O.value ? Ue : "div",
|
|
477
|
+
col: O.value ? Ne : "div"
|
|
478
|
+
})), h = L();
|
|
479
|
+
async function U({ eventName: r }) {
|
|
480
|
+
const a = ["submit", "search"], u = ["cancel", "reset"];
|
|
481
|
+
if (![...a, ...u].includes(r))
|
|
482
|
+
return l("action", r);
|
|
483
|
+
a.includes(r) && await h.value?.validate?.(), u.includes(r) && h.value?.resetFields?.(), l(r), l("action", r);
|
|
311
484
|
}
|
|
312
|
-
return
|
|
485
|
+
return n({
|
|
313
486
|
// element-plus form exposes
|
|
314
487
|
get fields() {
|
|
315
|
-
return
|
|
488
|
+
return h.value?.fields;
|
|
316
489
|
},
|
|
317
|
-
getField: (
|
|
318
|
-
validate: () =>
|
|
319
|
-
validateField: (
|
|
320
|
-
resetFields: (
|
|
321
|
-
clearValidate: (
|
|
322
|
-
scrollToField: (
|
|
323
|
-
}), (
|
|
490
|
+
getField: (r) => h.value?.getField?.(r),
|
|
491
|
+
validate: () => h.value?.validate?.(),
|
|
492
|
+
validateField: (r) => h.value?.validateField?.(r),
|
|
493
|
+
resetFields: (r) => h.value?.resetFields?.(r),
|
|
494
|
+
clearValidate: (r) => h.value?.clearValidate?.(r),
|
|
495
|
+
scrollToField: (r) => h.value?.scrollToField?.(r)
|
|
496
|
+
}), (r, a) => (p(), I(V(Re), D({
|
|
324
497
|
ref_key: "formRef",
|
|
325
|
-
ref:
|
|
326
|
-
},
|
|
498
|
+
ref: h
|
|
499
|
+
}, g.value, {
|
|
327
500
|
model: e.model,
|
|
328
|
-
onValidate:
|
|
329
|
-
onSubmit:
|
|
501
|
+
onValidate: a[1] || (a[1] = (u, C, y) => l("validate", u, C, y)),
|
|
502
|
+
onSubmit: a[2] || (a[2] = pe(() => {
|
|
330
503
|
}, ["prevent"]))
|
|
331
504
|
}), {
|
|
332
|
-
default:
|
|
333
|
-
(
|
|
334
|
-
default:
|
|
335
|
-
(
|
|
336
|
-
key: `${
|
|
337
|
-
}, { ref_for: !0 },
|
|
338
|
-
default:
|
|
339
|
-
|
|
340
|
-
modelValue: e.model[
|
|
341
|
-
"onUpdate:modelValue": (
|
|
342
|
-
"form-item":
|
|
505
|
+
default: b(() => [
|
|
506
|
+
(p(), I(F(x.value.row), te(oe(e.rowAttrs)), {
|
|
507
|
+
default: b(() => [
|
|
508
|
+
(p(!0), N(Z, null, B(T.value, (u, C) => Q((p(), I(F(x.value.col), D({
|
|
509
|
+
key: `${u.prop}-${C}`
|
|
510
|
+
}, { ref_for: !0 }, u.colAttrs), {
|
|
511
|
+
default: b(() => [
|
|
512
|
+
q(et, {
|
|
513
|
+
modelValue: e.model[u.prop],
|
|
514
|
+
"onUpdate:modelValue": (y) => e.model[u.prop] = y,
|
|
515
|
+
"form-item": u,
|
|
343
516
|
"form-data": e.model,
|
|
344
|
-
"dynamic-comp-events":
|
|
345
|
-
"form-slots":
|
|
346
|
-
index:
|
|
347
|
-
onChange:
|
|
517
|
+
"dynamic-comp-events": v.value,
|
|
518
|
+
"form-slots": E.value,
|
|
519
|
+
index: C,
|
|
520
|
+
onChange: a[0] || (a[0] = (y, M) => l("change", y, M))
|
|
348
521
|
}, null, 8, ["modelValue", "onUpdate:modelValue", "form-item", "form-data", "dynamic-comp-events", "form-slots", "index"])
|
|
349
522
|
]),
|
|
350
523
|
_: 2
|
|
351
524
|
}, 1040)), [
|
|
352
|
-
[
|
|
525
|
+
[ee, V(X)({ condition: u.vShow, data: s.model, defaultValue: !0 })]
|
|
353
526
|
])), 128)),
|
|
354
|
-
|
|
355
|
-
inline:
|
|
356
|
-
"action-slot":
|
|
527
|
+
q(Qe, {
|
|
528
|
+
inline: g.value.inline,
|
|
529
|
+
"action-slot": r.$slots.action,
|
|
357
530
|
config: e.actionConfig,
|
|
358
|
-
onAction:
|
|
531
|
+
onAction: U
|
|
359
532
|
}, null, 8, ["inline", "action-slot", "config"])
|
|
360
533
|
]),
|
|
361
534
|
_: 1
|
|
@@ -366,6 +539,6 @@ const Pe = ["comp", "compAttrs", "vIf", "vShow"], Me = {
|
|
|
366
539
|
}
|
|
367
540
|
});
|
|
368
541
|
export {
|
|
369
|
-
|
|
370
|
-
|
|
542
|
+
rt as WForm,
|
|
543
|
+
rt as default
|
|
371
544
|
};
|