dynamicformdjx 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +153 -6
- package/dist/hooks/useDyForm.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.mjs +149 -145
- package/dist/naiveUi/index.cjs +1 -1
- package/dist/naiveUi/index.mjs +86 -86
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineComponent as N, ref as
|
|
2
|
-
import { t as p, r as
|
|
1
|
+
import { defineComponent as N, ref as w, watch as R, toRaw as h, createVNode as n, createTextVNode as v, nextTick as j, Fragment as x, shallowReactive as O, unref as D, isRef as F } from "vue";
|
|
2
|
+
import { t as p, r as V, f as T, p as L, s as M } from "./index-BqKRE4oH.js";
|
|
3
3
|
const $ = /* @__PURE__ */ N({
|
|
4
4
|
name: "DynamicInput",
|
|
5
5
|
props: {
|
|
@@ -33,107 +33,107 @@ const $ = /* @__PURE__ */ N({
|
|
|
33
33
|
emits: {
|
|
34
34
|
"update:modelValue": (t) => !0,
|
|
35
35
|
onReset: () => !0,
|
|
36
|
-
onMerge: (t,
|
|
36
|
+
onMerge: (t, r) => !0
|
|
37
37
|
},
|
|
38
38
|
setup(t, {
|
|
39
|
-
emit:
|
|
39
|
+
emit: r,
|
|
40
40
|
expose: f
|
|
41
41
|
}) {
|
|
42
|
-
const
|
|
42
|
+
const m = {
|
|
43
43
|
resetTxt: "重置",
|
|
44
44
|
newTxt: "添加项",
|
|
45
45
|
mergeTxt: "合并",
|
|
46
46
|
...t.btnConfigs
|
|
47
|
-
},
|
|
47
|
+
}, c = {
|
|
48
48
|
hideReset: !1,
|
|
49
49
|
maxHeight: "300px",
|
|
50
50
|
autoScroll: !0,
|
|
51
51
|
allowFilter: !0,
|
|
52
52
|
...t.configs
|
|
53
|
-
},
|
|
53
|
+
}, d = {
|
|
54
54
|
arraySplitSymbol: ",",
|
|
55
55
|
...t.dyListConfigs
|
|
56
|
-
},
|
|
57
|
-
return
|
|
56
|
+
}, y = t.size, o = w(p(t.modelValue, t.randomFun, d.arraySplitSymbol)), b = w(null);
|
|
57
|
+
return R(o, (e) => {
|
|
58
58
|
if (!t.isController) return;
|
|
59
|
-
const u =
|
|
60
|
-
|
|
59
|
+
const u = V(e, d.arraySplitSymbol);
|
|
60
|
+
r("update:modelValue", u), r("onMerge", u, h(o.value));
|
|
61
61
|
}, {
|
|
62
62
|
deep: !0
|
|
63
63
|
}), f({
|
|
64
64
|
onSet: (e) => {
|
|
65
|
-
o.value = p(e ?? t.modelValue, t.randomFun,
|
|
65
|
+
o.value = p(e ?? t.modelValue, t.randomFun, d.arraySplitSymbol);
|
|
66
66
|
},
|
|
67
|
-
getResult: (e = "res") => e === "ori" ?
|
|
68
|
-
}), () =>
|
|
69
|
-
class: t.dyCls ?? `dynamicForm ${
|
|
70
|
-
}, [
|
|
67
|
+
getResult: (e = "res") => e === "ori" ? h(o.value) : V(o.value, d.arraySplitSymbol)
|
|
68
|
+
}), () => n("div", {
|
|
69
|
+
class: t.dyCls ?? `dynamicForm ${y}`
|
|
70
|
+
}, [n("div", {
|
|
71
71
|
class: "dyFormList",
|
|
72
|
-
ref:
|
|
72
|
+
ref: b,
|
|
73
73
|
style: {
|
|
74
|
-
maxHeight:
|
|
74
|
+
maxHeight: c.maxHeight
|
|
75
75
|
}
|
|
76
|
-
}, [o.value.map((e, u,
|
|
76
|
+
}, [o.value.map((e, u, l) => n("div", {
|
|
77
77
|
class: "dItem",
|
|
78
78
|
key: e.rId
|
|
79
|
-
}, [
|
|
79
|
+
}, [n("div", {
|
|
80
80
|
class: "input"
|
|
81
|
-
}, [
|
|
82
|
-
size:
|
|
81
|
+
}, [n("input", {
|
|
82
|
+
size: y,
|
|
83
83
|
value: e.key,
|
|
84
84
|
class: "key nativeInput",
|
|
85
85
|
onInput: (s) => {
|
|
86
86
|
e.key = s.target.value;
|
|
87
87
|
}
|
|
88
|
-
}, null),
|
|
88
|
+
}, null), v(":"), n("div", {
|
|
89
89
|
class: "vInput"
|
|
90
|
-
}, [
|
|
90
|
+
}, [n("div", {
|
|
91
91
|
class: "slot"
|
|
92
|
-
}, [
|
|
92
|
+
}, [n("button", {
|
|
93
93
|
class: [e.isArray ? "success" : "default", "small", "bt"],
|
|
94
94
|
onClick: () => {
|
|
95
95
|
e.isArray = !e.isArray;
|
|
96
96
|
}
|
|
97
|
-
}, [
|
|
97
|
+
}, [v("Array")]), v(" "), n("button", {
|
|
98
98
|
class: [e.isNumber ? "success" : "default", "small", "bt"],
|
|
99
99
|
onClick: () => {
|
|
100
100
|
e.isNumber = !e.isNumber;
|
|
101
101
|
}
|
|
102
|
-
}, [
|
|
103
|
-
size:
|
|
102
|
+
}, [v("Number")])]), n("input", {
|
|
103
|
+
size: y,
|
|
104
104
|
value: e.value,
|
|
105
105
|
class: "value nativeV",
|
|
106
106
|
onInput: (s) => {
|
|
107
|
-
const
|
|
108
|
-
|
|
107
|
+
const i = s.target.value;
|
|
108
|
+
c.allowFilter && e.isNumber ? e.value = T(i, e.isArray, d.arraySplitSymbol) : e.value = i;
|
|
109
109
|
}
|
|
110
|
-
}, null)])]),
|
|
110
|
+
}, null)])]), n("div", {
|
|
111
111
|
class: "btn"
|
|
112
|
-
}, [
|
|
113
|
-
class: [
|
|
114
|
-
disabled: u !==
|
|
112
|
+
}, [n("button", {
|
|
113
|
+
class: [y, "success", "bt"],
|
|
114
|
+
disabled: u !== l.length - 1,
|
|
115
115
|
onClick: () => {
|
|
116
116
|
o.value.push({
|
|
117
117
|
rId: t.randomFun(),
|
|
118
118
|
key: "",
|
|
119
119
|
value: ""
|
|
120
|
-
}),
|
|
121
|
-
const s =
|
|
120
|
+
}), c.autoScroll && j(() => {
|
|
121
|
+
const s = b.value;
|
|
122
122
|
s?.scrollTo({
|
|
123
123
|
top: s.scrollHeight,
|
|
124
124
|
behavior: "smooth"
|
|
125
125
|
});
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
-
}, [
|
|
129
|
-
class: ["danger",
|
|
128
|
+
}, [v("+")]), n("button", {
|
|
129
|
+
class: ["danger", y, "bt"],
|
|
130
130
|
onClick: () => {
|
|
131
131
|
o.value = o.value.filter((s) => s.rId !== e.rId);
|
|
132
132
|
}
|
|
133
|
-
}, [
|
|
133
|
+
}, [v("-")])])]))]), n("div", {
|
|
134
134
|
class: "control"
|
|
135
|
-
}, [!o.value.length &&
|
|
136
|
-
class: ["success",
|
|
135
|
+
}, [!o.value.length && n("button", {
|
|
136
|
+
class: ["success", y, "bt"],
|
|
137
137
|
onClick: () => {
|
|
138
138
|
o.value.push({
|
|
139
139
|
rId: t.randomFun(),
|
|
@@ -141,19 +141,19 @@ const $ = /* @__PURE__ */ N({
|
|
|
141
141
|
value: ""
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
}, [
|
|
145
|
-
class: ["default",
|
|
144
|
+
}, [m.newTxt]), !t.isController && n(x, null, [!c.hideReset && n("button", {
|
|
145
|
+
class: ["default", y, "bt"],
|
|
146
146
|
onClick: () => {
|
|
147
|
-
o.value = p(t.modelValue, t.randomFun,
|
|
147
|
+
o.value = p(t.modelValue, t.randomFun, d.arraySplitSymbol), r("onReset");
|
|
148
148
|
}
|
|
149
|
-
}, [
|
|
150
|
-
class: ["info",
|
|
149
|
+
}, [m.resetTxt]), n("button", {
|
|
150
|
+
class: ["info", y, "bt"],
|
|
151
151
|
onClick: () => {
|
|
152
|
-
o.value.sort((u,
|
|
153
|
-
const e =
|
|
154
|
-
|
|
152
|
+
o.value.sort((u, l) => +u.rId - +l.rId);
|
|
153
|
+
const e = V(o.value, d.arraySplitSymbol);
|
|
154
|
+
r("update:modelValue", e), r("onMerge", e, h(o.value)), o.value = p(e, t.randomFun, d.arraySplitSymbol);
|
|
155
155
|
}
|
|
156
|
-
}, [
|
|
156
|
+
}, [m.mergeTxt])])])]);
|
|
157
157
|
}
|
|
158
158
|
}), H = /* @__PURE__ */ N({
|
|
159
159
|
name: "DynamicCascadeInput",
|
|
@@ -194,18 +194,18 @@ const $ = /* @__PURE__ */ N({
|
|
|
194
194
|
emits: {
|
|
195
195
|
"update:modelValue": (t) => !0,
|
|
196
196
|
onReset: () => !0,
|
|
197
|
-
onMerge: (t,
|
|
197
|
+
onMerge: (t, r) => !0
|
|
198
198
|
},
|
|
199
199
|
setup(t, {
|
|
200
|
-
emit:
|
|
200
|
+
emit: r,
|
|
201
201
|
expose: f
|
|
202
202
|
}) {
|
|
203
|
-
const
|
|
203
|
+
const m = {
|
|
204
204
|
resetTxt: "重置",
|
|
205
205
|
newTxt: "添加项",
|
|
206
206
|
mergeTxt: "合并",
|
|
207
207
|
...t.btnConfigs
|
|
208
|
-
},
|
|
208
|
+
}, c = {
|
|
209
209
|
hideReset: !1,
|
|
210
210
|
maxHeight: "600px",
|
|
211
211
|
allowFilter: !0,
|
|
@@ -214,125 +214,125 @@ const $ = /* @__PURE__ */ N({
|
|
|
214
214
|
retractLen: 0,
|
|
215
215
|
borderColors: [],
|
|
216
216
|
...t.configs
|
|
217
|
-
},
|
|
217
|
+
}, d = {
|
|
218
218
|
arraySplitSymbol: ",",
|
|
219
219
|
...t.dyListConfigs
|
|
220
|
-
},
|
|
221
|
-
let
|
|
222
|
-
const g = Array.isArray(
|
|
223
|
-
return
|
|
224
|
-
rId: t.randomFun(
|
|
220
|
+
}, y = (l) => ["string", "number"].includes(l), o = (l) => Object.keys(l).map((s, i) => {
|
|
221
|
+
let a = l[s];
|
|
222
|
+
const g = Array.isArray(a), A = g ? a.every((S) => typeof S == "number") : typeof a == "number", C = a === null;
|
|
223
|
+
return y(typeof a) && (a = l[s]), C && (a = ""), {
|
|
224
|
+
rId: t.randomFun(i),
|
|
225
225
|
key: s,
|
|
226
|
-
value: Object.prototype.toString.call(
|
|
226
|
+
value: Object.prototype.toString.call(a) === "[object Object]" ? o(l[s]) : g ? a.join(d.arraySplitSymbol) : a,
|
|
227
227
|
isArray: g || void 0,
|
|
228
228
|
isNumber: A || void 0
|
|
229
229
|
};
|
|
230
|
-
}),
|
|
231
|
-
const
|
|
232
|
-
return
|
|
233
|
-
}, {}), e =
|
|
234
|
-
class: [`depth-${s}`,
|
|
230
|
+
}), b = (l) => l.reduce((s, i) => {
|
|
231
|
+
const a = i.value;
|
|
232
|
+
return i.key.trim().length && (s[i.key] = Array.isArray(a) ? b(a) : L(i.value, i.isArray, i.isNumber, d.arraySplitSymbol)), s;
|
|
233
|
+
}, {}), e = w(o(t.modelValue)), u = (l, s = 1, i) => n("div", {
|
|
234
|
+
class: [`depth-${s}`, c.showBorder ? "" : "no-border", c.showPad ? "" : "no-pad"],
|
|
235
235
|
style: {
|
|
236
236
|
"--depth": s,
|
|
237
|
-
["--c" + [s]]: M(
|
|
237
|
+
["--c" + [s]]: M(c.borderColors, s)
|
|
238
238
|
}
|
|
239
|
-
}, [
|
|
240
|
-
const C = Array.isArray(
|
|
241
|
-
return
|
|
239
|
+
}, [l.map((a, g, A) => {
|
|
240
|
+
const C = Array.isArray(a.value), S = y(typeof a.value);
|
|
241
|
+
return n("div", {
|
|
242
242
|
class: "dItem",
|
|
243
|
-
key:
|
|
243
|
+
key: a.rId,
|
|
244
244
|
style: {
|
|
245
|
-
marginLeft: s > 1 ? `${s *
|
|
245
|
+
marginLeft: s > 1 ? `${s * c.retractLen}px` : "0"
|
|
246
246
|
}
|
|
247
|
-
}, [
|
|
247
|
+
}, [n("div", {
|
|
248
248
|
class: "input"
|
|
249
|
-
}, [!C &&
|
|
250
|
-
value:
|
|
249
|
+
}, [!C && n(x, null, [n("input", {
|
|
250
|
+
value: a.key,
|
|
251
251
|
class: "key nativeInput",
|
|
252
|
-
onInput: (
|
|
253
|
-
}, null),
|
|
252
|
+
onInput: (I) => a.key = I.target.value
|
|
253
|
+
}, null), v(":")]), n("div", {
|
|
254
254
|
class: "vInput"
|
|
255
|
-
}, [
|
|
255
|
+
}, [n("div", {
|
|
256
256
|
class: "slot"
|
|
257
|
-
}, [Array.isArray(
|
|
258
|
-
class: [
|
|
257
|
+
}, [Array.isArray(a.value) ? void 0 : n(x, null, [n("button", {
|
|
258
|
+
class: [a.isArray ? "success" : "default", "small", "bt"],
|
|
259
259
|
onClick: () => {
|
|
260
|
-
|
|
260
|
+
a.isArray = !a.isArray;
|
|
261
261
|
}
|
|
262
|
-
}, [
|
|
263
|
-
class: [
|
|
262
|
+
}, [v("Array")]), v(" "), n("button", {
|
|
263
|
+
class: [a.isNumber ? "success" : "default", "small", "bt"],
|
|
264
264
|
onClick: () => {
|
|
265
|
-
|
|
265
|
+
a.isNumber = !a.isNumber;
|
|
266
266
|
}
|
|
267
|
-
}, [
|
|
267
|
+
}, [v("Number")])])]), n("input", {
|
|
268
268
|
class: `value nativeV ${C ? "isKey" : ""}`,
|
|
269
|
-
value:
|
|
270
|
-
onInput: (
|
|
271
|
-
const k =
|
|
269
|
+
value: S ? a.value : a.key,
|
|
270
|
+
onInput: (I) => {
|
|
271
|
+
const k = I.target.value;
|
|
272
272
|
if (C) {
|
|
273
|
-
|
|
273
|
+
a.key = k;
|
|
274
274
|
return;
|
|
275
275
|
}
|
|
276
|
-
|
|
276
|
+
c.allowFilter && a.isNumber ? a.value = T(k, a.isArray, d.arraySplitSymbol) : a.value = k;
|
|
277
277
|
}
|
|
278
|
-
}, null),
|
|
278
|
+
}, null), n("div", {
|
|
279
279
|
class: "surSlot"
|
|
280
|
-
}, [s < t.depth ? !C &&
|
|
280
|
+
}, [s < t.depth ? !C && n("button", {
|
|
281
281
|
class: ["success", "bt"],
|
|
282
282
|
onClick: () => {
|
|
283
|
-
|
|
283
|
+
S && (a.value = [], a.isArray = void 0), a.value.push({
|
|
284
284
|
rId: t.randomFun(),
|
|
285
285
|
key: "",
|
|
286
286
|
value: ""
|
|
287
287
|
});
|
|
288
288
|
}
|
|
289
|
-
}, [t.newChildTxt(
|
|
289
|
+
}, [t.newChildTxt(a)]) : null])])]), n("div", {
|
|
290
290
|
class: "btn"
|
|
291
|
-
}, [
|
|
291
|
+
}, [n("button", {
|
|
292
292
|
class: ["success", "bt"],
|
|
293
293
|
disabled: g !== A.length - 1,
|
|
294
294
|
onClick: () => {
|
|
295
|
-
|
|
295
|
+
l.push({
|
|
296
296
|
rId: t.randomFun(),
|
|
297
297
|
key: "",
|
|
298
298
|
value: ""
|
|
299
299
|
});
|
|
300
300
|
}
|
|
301
|
-
}, [
|
|
301
|
+
}, [v("+")]), n("button", {
|
|
302
302
|
class: ["danger", "bt"],
|
|
303
303
|
onClick: () => {
|
|
304
|
-
if (
|
|
305
|
-
if (
|
|
306
|
-
const
|
|
307
|
-
s < 1 ? e.value.splice(
|
|
308
|
-
...
|
|
304
|
+
if (l.splice(g, 1), l.length < 1) {
|
|
305
|
+
if (i === void 0) return b([]);
|
|
306
|
+
const I = e.value.findIndex((k) => k.rId === i?.rId);
|
|
307
|
+
s < 1 ? e.value.splice(I, 1, {
|
|
308
|
+
...i,
|
|
309
309
|
value: ""
|
|
310
|
-
}) :
|
|
310
|
+
}) : i.value = "";
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
|
-
}, [
|
|
313
|
+
}, [v("-")])]), Array.isArray(a.value) && u(a.value, s + 1, a)]);
|
|
314
314
|
})]);
|
|
315
|
-
return
|
|
315
|
+
return R(e, (l) => {
|
|
316
316
|
if (!t.isController) return;
|
|
317
|
-
const s =
|
|
318
|
-
|
|
317
|
+
const s = b(l);
|
|
318
|
+
r("update:modelValue", s), r("onMerge", s, h(e.value));
|
|
319
319
|
}, {
|
|
320
320
|
deep: !0
|
|
321
321
|
}), f({
|
|
322
|
-
onSet: (
|
|
323
|
-
e.value = o(
|
|
322
|
+
onSet: (l) => {
|
|
323
|
+
e.value = o(l ?? t.modelValue);
|
|
324
324
|
},
|
|
325
|
-
getResult: (
|
|
326
|
-
}), () =>
|
|
325
|
+
getResult: (l = "res") => l === "ori" ? h(e.value) : b(e.value)
|
|
326
|
+
}), () => n("div", {
|
|
327
327
|
class: t.dyCls ?? "dynamicCascadeForm"
|
|
328
|
-
}, [
|
|
328
|
+
}, [n("div", {
|
|
329
329
|
class: "dyFormList",
|
|
330
330
|
style: {
|
|
331
|
-
maxHeight:
|
|
331
|
+
maxHeight: c.maxHeight
|
|
332
332
|
}
|
|
333
|
-
}, [u(e.value)]),
|
|
333
|
+
}, [u(e.value)]), n("div", {
|
|
334
334
|
class: "control"
|
|
335
|
-
}, [!e.value.length &&
|
|
335
|
+
}, [!e.value.length && n("button", {
|
|
336
336
|
class: ["success", "bt"],
|
|
337
337
|
onClick: () => {
|
|
338
338
|
e.value.push({
|
|
@@ -341,52 +341,56 @@ const $ = /* @__PURE__ */ N({
|
|
|
341
341
|
value: ""
|
|
342
342
|
});
|
|
343
343
|
}
|
|
344
|
-
}, [
|
|
344
|
+
}, [m.newTxt]), !t.isController && n(x, null, [!c.hideReset && n("button", {
|
|
345
345
|
class: ["default", "bt"],
|
|
346
346
|
onClick: () => {
|
|
347
|
-
e.value = o(t.modelValue),
|
|
347
|
+
e.value = o(t.modelValue), r("onReset");
|
|
348
348
|
}
|
|
349
|
-
}, [
|
|
349
|
+
}, [m.resetTxt]), n("button", {
|
|
350
350
|
class: ["info", "bt"],
|
|
351
351
|
onClick: () => {
|
|
352
|
-
const
|
|
353
|
-
|
|
352
|
+
const l = b(e.value);
|
|
353
|
+
r("update:modelValue", l), r("onMerge", l, h(e.value)), e.value = o(l);
|
|
354
354
|
}
|
|
355
|
-
}, [
|
|
355
|
+
}, [m.mergeTxt])])])]);
|
|
356
356
|
}
|
|
357
357
|
});
|
|
358
|
-
function E(t,
|
|
359
|
-
return
|
|
358
|
+
function E(t, r = !0) {
|
|
359
|
+
return r ? t.map((f) => O(f)) : t;
|
|
360
360
|
}
|
|
361
361
|
function P(t) {
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
const
|
|
365
|
-
(!
|
|
362
|
+
const r = () => D(t), f = (e, u) => {
|
|
363
|
+
r().forEach((l) => {
|
|
364
|
+
const s = l.key;
|
|
365
|
+
(!u || u.includes(s)) && (l.disabled = e);
|
|
366
366
|
});
|
|
367
|
-
},
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
(!
|
|
367
|
+
}, m = (e, u) => {
|
|
368
|
+
r().forEach((l) => {
|
|
369
|
+
const s = l.key;
|
|
370
|
+
(!u || u.includes(s)) && (l.hidden = e);
|
|
371
371
|
});
|
|
372
|
-
},
|
|
373
|
-
const
|
|
374
|
-
|
|
372
|
+
}, c = (e, u) => {
|
|
373
|
+
const l = r().find((s) => s.key === e);
|
|
374
|
+
l && (F(l.value) ? l.value.value = u : l.value = u);
|
|
375
375
|
};
|
|
376
|
-
return { setDisabled: f, setHidden:
|
|
377
|
-
Object.entries(
|
|
378
|
-
|
|
376
|
+
return { setDisabled: f, setHidden: m, setValue: c, setValues: (e) => {
|
|
377
|
+
Object.entries(e).forEach(([u, l]) => {
|
|
378
|
+
c(u, l);
|
|
379
379
|
});
|
|
380
|
-
}, getValue: (
|
|
381
|
-
const
|
|
382
|
-
return
|
|
383
|
-
const
|
|
384
|
-
if (!
|
|
385
|
-
const
|
|
386
|
-
|
|
380
|
+
}, getValue: (e) => r().find((u) => u.key === e), getValues: (e) => {
|
|
381
|
+
const u = e && e.length ? new Set(e) : null;
|
|
382
|
+
return r().reduce((l, s) => {
|
|
383
|
+
const i = s.key;
|
|
384
|
+
if (!u || u.has(i)) {
|
|
385
|
+
const a = F(s.value) ? s.value.value : s.value;
|
|
386
|
+
l[i] = a;
|
|
387
387
|
}
|
|
388
|
-
return
|
|
388
|
+
return l;
|
|
389
389
|
}, {});
|
|
390
|
+
}, onReset: (e = null) => {
|
|
391
|
+
r().forEach((u) => {
|
|
392
|
+
F(u.value) ? u.value.value = e : u.value = e;
|
|
393
|
+
});
|
|
390
394
|
} };
|
|
391
395
|
}
|
|
392
396
|
const q = {
|
package/dist/naiveUi/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),s=require("naive-ui"),b=require("../index-BWQjnQQF.cjs"),k=e.defineComponent({name:"NaiDynamicInput",props:{size:{type:String},isController:{type:Boolean},dyCls:{type:String},randomFun:{type:Function,default:t=>`${Date.now()}_${t??0}`},btnConfigs:{type:Object},configs:{type:Object},dyListConfigs:{type:Object},modelValue:{type:Object,required:!0}},emits:{"update:modelValue":t=>!0,onReset:()=>!0,onMerge:(t,o)=>!0},setup(t,{emit:o,expose:d}){const l={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...t.btnConfigs},i={hideReset:!1,maxHeight:"300px",autoScroll:!0,allowFilter:!0,...t.configs},c={arraySplitSymbol:",",...t.dyListConfigs},v=t.size,y=e.ref(b.tranArr(t.modelValue,t.randomFun,c.arraySplitSymbol)),N=e.ref(null);return e.watch(y,n=>{if(!t.isController)return;const m=b.resetObj(n,c.arraySplitSymbol);o("update:modelValue",m),o("onMerge",m,e.toRaw(y.value))},{deep:!0}),d({onSet:n=>{y.value=b.tranArr(n??t.modelValue,t.randomFun,c.arraySplitSymbol)},getResult:(n="res")=>n==="ori"?e.toRaw(y.value):b.resetObj(y.value,c.arraySplitSymbol)}),()=>e.createVNode("div",{class:t.dyCls??`dynamicForm ${v}`},[e.createVNode("div",{class:"dyFormList",ref:N,style:{maxHeight:i.maxHeight}},[y.value.map((n,m,a)=>e.createVNode("div",{class:"dItem",key:n.rId},[e.createVNode("div",{class:"input"},[e.createVNode(s.NInput,{size:v,value:n.key,class:"key",onInput:r=>{n.key=r}},null),e.createTextVNode(":"),e.createVNode(s.NInput,{size:v,value:n.value,class:"value",onInput:r=>{i.allowFilter&&n.isNumber?n.value=b.formatNumberInput(r,n.isArray,c.arraySplitSymbol):n.value=r}},{prefix:()=>e.createVNode(e.Fragment,null,[e.createVNode(s.NButton,{type:n.isArray?"success":"default",size:"tiny",onClick:()=>{n.isArray=!n.isArray}},{default:()=>[e.createTextVNode("Array")]}),e.createTextVNode(" "),e.createVNode(s.NButton,{type:n.isNumber?"success":"default",size:"tiny",onClick:()=>{n.isNumber=!n.isNumber}},{default:()=>[e.createTextVNode("Number")]})])})]),e.createVNode("div",{class:"btn"},[e.createVNode(s.NButton,{type:"success",size:v,disabled:m!==a.length-1,onClick:()=>{y.value.push({rId:t.randomFun(),key:"",value:""}),i.autoScroll&&e.nextTick(()=>{const r=N.value;r?.scrollTo({top:r.scrollHeight,behavior:"smooth"})})}},{default:()=>[e.createTextVNode("+")]}),e.createVNode(s.NButton,{size:v,type:"error",onClick:()=>{y.value=y.value.filter(r=>r.rId!==n.rId)}},{default:()=>[e.createTextVNode("-")]})])]))]),e.createVNode("div",{class:"control"},[!y.value.length&&e.createVNode(s.NButton,{size:v,type:"success",onClick:()=>{y.value.push({rId:t.randomFun(),key:"",value:""})}},{default:()=>[l.newTxt]}),!t.isController&&e.createVNode(e.Fragment,null,[!i.hideReset&&e.createVNode(s.NButton,{size:v,type:"default",onClick:()=>{y.value=b.tranArr(t.modelValue,t.randomFun,c.arraySplitSymbol),o("onReset")}},{default:()=>[l.resetTxt]}),e.createVNode(s.NButton,{size:v,type:"info",onClick:()=>{y.value.sort((m,a)=>+m.rId-+a.rId);const n=b.resetObj(y.value,c.arraySplitSymbol);o("update:modelValue",n),o("onMerge",n,e.toRaw(y.value)),y.value=b.tranArr(n,t.randomFun,c.arraySplitSymbol)}},{default:()=>[l.mergeTxt]})])])])}});function F(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!e.isVNode(t)}const I=e.defineComponent({name:"NaiveUiDynamicCascadeInput",props:{modelValue:{type:Object,required:!0},isController:{type:Boolean},dyCls:{type:String},randomFun:{type:Function,default:t=>`${Date.now()}_${t??0}`},depth:{type:Number,default:3},btnConfigs:{type:Object},configs:{type:Object},dyListConfigs:{type:Object},newChildTxt:{type:Function,default:t=>`添加 '${t.key}' 子项`}},emits:{"update:modelValue":t=>!0,onReset:()=>!0,onMerge:(t,o)=>!0},setup(t,{emit:o,expose:d}){const l={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...t.btnConfigs},i={hideReset:!1,maxHeight:"600px",allowFilter:!0,showBorder:!0,showPad:!0,retractLen:0,borderColors:[],...t.configs},c={arraySplitSymbol:",",...t.dyListConfigs},v=a=>["string","number"].includes(a),y=a=>Object.keys(a).map((r,f)=>{let u=a[r];const g=Array.isArray(u),C=g?u.every(h=>typeof h=="number"):typeof u=="number",V=u===null;return v(typeof u)&&(u=a[r]),V&&(u=""),{rId:t.randomFun(f),key:r,value:Object.prototype.toString.call(u)==="[object Object]"?y(a[r]):g?u.join(c.arraySplitSymbol):u,isArray:g||void 0,isNumber:C||void 0}}),N=a=>a.reduce((r,f)=>{const u=f.value;return f.key.trim().length&&(r[f.key]=Array.isArray(u)?N(u):b.parseValue(f.value,f.isArray,f.isNumber,c.arraySplitSymbol)),r},{}),n=e.ref(y(t.modelValue)),m=(a,r=1,f)=>e.createVNode("div",{class:[`depth-${r}`,i.showBorder?"":"no-border",i.showPad?"":"no-pad"],style:{"--depth":r,["--c"+[r]]:b.saferRepairColor(i.borderColors,r)}},[a.map((u,g,C)=>{const V=Array.isArray(u.value),h=v(typeof u.value);return e.createVNode("div",{class:"dItem",key:u.rId,style:{marginLeft:r>1?`${r*i.retractLen}px`:"0"}},[e.createVNode("div",{class:"input"},[!V&&e.createVNode(e.Fragment,null,[e.createVNode(s.NInput,{value:u.key,class:"key",onInput:p=>u.key=p},null),e.createTextVNode(":")]),e.createVNode(s.NInput,{class:`value ${V?"isKey":""}`,value:h?u.value:u.key,onInput:p=>{if(V){u.key=p;return}i.allowFilter&&u.isNumber?u.value=b.formatNumberInput(p,u.isArray,c.arraySplitSymbol):u.value=p}},{prefix:Array.isArray(u.value)?void 0:()=>e.createVNode(e.Fragment,null,[e.createVNode(s.NButton,{type:u.isArray?"success":"default",size:"tiny",onClick:()=>{u.isArray=!u.isArray}},{default:()=>[e.createTextVNode("Array")]}),e.createTextVNode(" "),e.createVNode(s.NButton,{type:u.isNumber?"success":"default",size:"tiny",onClick:()=>{u.isNumber=!u.isNumber}},{default:()=>[e.createTextVNode("Number")]})]),suffix:()=>{let p;return r<t.depth?!V&&e.createVNode(s.NButton,{type:"success",size:"tiny",onClick:()=>{h&&(u.value=[],u.isArray=void 0),u.value.push({rId:t.randomFun(),key:"",value:""})}},F(p=t.newChildTxt(u))?p:{default:()=>[p]}):null}})]),e.createVNode("div",{class:"btn"},[e.createVNode(s.NButton,{type:"success",disabled:g!==C.length-1,onClick:()=>{a.push({rId:t.randomFun(),key:"",value:""})}},{default:()=>[e.createTextVNode("+")]}),e.createVNode(s.NButton,{type:"error",onClick:()=>{if(a.splice(g,1),a.length<1){if(f===void 0)return N([]);const p=n.value.findIndex(S=>S.rId===f?.rId);r<1?n.value.splice(p,1,{...f,value:""}):f.value=""}}},{default:()=>[e.createTextVNode("-")]})]),Array.isArray(u.value)&&m(u.value,r+1,u)])})]);return e.watch(n,a=>{if(!t.isController)return;const r=N(a);o("update:modelValue",r),o("onMerge",r,e.toRaw(n.value))},{deep:!0}),d({onSet:a=>{n.value=y(a??t.modelValue)},getResult:(a="res")=>a==="ori"?e.toRaw(n.value):N(n.value)}),()=>e.createVNode("div",{class:t.dyCls??"dynamicCascadeForm"},[e.createVNode("div",{class:"dyFormList",style:{maxHeight:i.maxHeight}},[m(n.value)]),e.createVNode("div",{class:"control"},[!n.value.length&&e.createVNode(s.NButton,{type:"success",onClick:()=>{n.value.push({rId:t.randomFun(),key:"",value:""})}},{default:()=>[l.newTxt]}),!t.isController&&e.createVNode(e.Fragment,null,[!i.hideReset&&e.createVNode(s.NButton,{type:"default",onClick:()=>{n.value=y(t.modelValue),o("onReset")}},{default:()=>[l.resetTxt]}),e.createVNode(s.NButton,{type:"info",onClick:()=>{const a=N(n.value);o("update:modelValue",a),o("onMerge",a,e.toRaw(n.value)),n.value=y(a)}},{default:()=>[l.mergeTxt]})])])])}}),T=e.defineComponent({name:"NaiDynamicForm",props:{formConfig:{type:Object,default:()=>({labelPlacement:"left",size:"medium"})},gridConfig:{type:Object,default:()=>({responsive:"screen",cols:"xs:1 s:2 m:3 l:3 xl:4 2xl:4",xGap:10})},rules:{type:Object},preset:{type:String,default:"fullRow",validator:t=>["fullRow","grid"].includes(t)?!0:(console.error("preset value must be `fullRow` or `grid`, the default value is `fullRow`"),!1)},items:{type:Array,require:!0}},setup(t,{emit:o,expose:d}){const l=e.ref(null),i=e.computed(()=>(t.items??[]).filter(m=>!m.hidden)),c=e.computed(()=>i.value?i.value.reduce((m,a)=>(m[a.key]=a.value.value,m),{}):{}),v=e.computed(()=>({...i.value?.reduce((a,r)=>{let f=r.rule;return r.required&&!r.rule&&(f={required:!0,message:`${r.label}不能为空`,trigger:["blur"]}),a[r.key]=f,a},{}),...t.rules})),y=e.computed(()=>[...i.value].sort((a,r)=>{const f=a.sort??1/0,u=r.sort??1/0;return Number(f)-Number(u)}));function N(m=null){i.value&&i.value.forEach(a=>{a.reset?a.reset(a):a.value.value=m})}function n(){return new Promise((m,a)=>{l.value?.validate(r=>{r?a(r):m(c.value)})})}if(d({reset:N,validator:n,getResult:(m="res")=>m==="ori"?i.value:c.value}),!t.items)throw new Error("prop items must be not null");return()=>e.createVNode("div",{class:"naiDynamicForm"},[e.createVNode(s.NForm,e.mergeProps({ref:l},t.formConfig,{model:c.value,rules:v.value}),{default(){const m=y.value;return t.preset==="grid"?e.h(s.NGrid,{...t.gridConfig},{default:()=>m?.map(a=>e.h(s.NFormItemGridItem,{label:a.label,path:a.path||a.key},{default:x(a)}))}):m?.map(a=>e.h(s.NFormItem,{label:a.label,path:a.path||a.key},{default:x(a)}))}})])}});function x(t){return function(){return t.render2?t.render2(t):null}}function R(t,o={},d){return e.h(s.NInput,{...d,value:t.value,onUpdateValue:l=>{t.value=l,d?.onChange?.(l,d)},...o})}function A(t,o,d={},l){return e.h(s.NSelect,{...l,value:t.value,options:o,onUpdateValue:i=>{t.value=i,l?.onChange?.(i,l,o)},...d})}function w(t,o,d={},l,i){const{value:c,labelField:v,valueField:y,...N}=l,n=v??"label",m=y??"value",a=N.options??o;return e.createVNode(s.NPopselect,{...N,value:t.value,onUpdateValue:r=>{t.value=r,l?.onChange?.(r,l,a)},options:a.map(r=>({...r,label:r[n],value:r[m]})),...d},{default:()=>i??e.createVNode(s.NButton,null,{default:()=>t.value||"请选择"})})}function j(t,o,d={},l){const{valueField:i="value",...c}=l;return e.h(s.NTreeSelect,{...c,value:t.value,options:o,onUpdateValue:v=>{t.value=v,l?.onChange?.(v,l,o)},keyField:i,...d})}function B(t,o,d={},l){return e.h(s.NRadioGroup,{...l,value:t.value,onUpdateValue:i=>{t.value=i,l?.onChange?.(i,l,o)},...d},{default:()=>(l?.options??o).map(c=>{const v=l,y=c[v?.labelField??"label"],N=c[v?.valueField??"value"];return e.h(s.NRadio,{...c,label:y,value:N},{default:()=>c.label})})})}function O(t,o,d={},l){return e.createVNode(s.NRadioGroup,{...l,value:t.value,onUpdateValue:i=>{t.value=i,l?.onChange?.(i,l,o)},...d},{default:()=>(l?.options??o).map(c=>{const v=l,y=c[v?.labelField??"label"],N=c[v?.valueField??"value"];return e.createVNode(s.NRadioButton,{...c,label:y,value:N},{default:()=>c.label})})})}function P(t,o,d={},l){return e.h(s.NCheckboxGroup,{...l,value:t.value,onUpdateValue:i=>{t.value=i,l?.onChange?.(i,l,o)},...d},{default:()=>e.h(s.NSpace,{itemStyle:"display: flex"},{default:()=>(l?.options??o).map(c=>{const v=l,y=c[v?.labelField??"label"],N=c[v?.valueField??"value"];return e.h(s.NCheckbox,{value:N,label:y})})})})}function z(t,o={},d){return e.h(s.NSwitch,{...d,value:t.value,onUpdateValue:l=>{t.value=l,d?.onChange?.(l,d)},...o})}function D(t,o={},d){return e.h(s.NDatePicker,{...d,value:t.value,onUpdateValue:l=>{t.value=l,d?.onChange?.(l,d)},...o})}function G(t,o={},d){return e.h(s.NTimePicker,{...d,value:t.value,onUpdateValue:l=>{t.value=l,d?.onChange?.(l,d)},...o})}exports.NaiDynamicCascadeInput=I;exports.NaiDynamicForm=T;exports.NaiDynamicInput=k;exports.renderCheckboxGroup=P;exports.renderDatePicker=D;exports.renderInput=R;exports.renderPopSelect=w;exports.renderRadioButtonGroup=O;exports.renderRadioGroup=B;exports.renderSelect=A;exports.renderSwitch=z;exports.renderTimePicker=G;exports.renderTreeSelect=j;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),s=require("naive-ui"),b=require("../index-BWQjnQQF.cjs"),k=e.defineComponent({name:"NaiDynamicInput",props:{size:{type:String},isController:{type:Boolean},dyCls:{type:String},randomFun:{type:Function,default:t=>`${Date.now()}_${t??0}`},btnConfigs:{type:Object},configs:{type:Object},dyListConfigs:{type:Object},modelValue:{type:Object,required:!0}},emits:{"update:modelValue":t=>!0,onReset:()=>!0,onMerge:(t,o)=>!0},setup(t,{emit:o,expose:c}){const l={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...t.btnConfigs},i={hideReset:!1,maxHeight:"300px",autoScroll:!0,allowFilter:!0,...t.configs},y={arraySplitSymbol:",",...t.dyListConfigs},v=t.size,d=e.ref(b.tranArr(t.modelValue,t.randomFun,y.arraySplitSymbol)),N=e.ref(null);return e.watch(d,n=>{if(!t.isController)return;const m=b.resetObj(n,y.arraySplitSymbol);o("update:modelValue",m),o("onMerge",m,e.toRaw(d.value))},{deep:!0}),c({onSet:n=>{d.value=b.tranArr(n??t.modelValue,t.randomFun,y.arraySplitSymbol)},getResult:(n="res")=>n==="ori"?e.toRaw(d.value):b.resetObj(d.value,y.arraySplitSymbol)}),()=>e.createVNode("div",{class:t.dyCls??`dynamicForm ${v}`},[e.createVNode("div",{class:`dyFormList ${d.value.length?"":"noList"}`,ref:N,style:{maxHeight:i.maxHeight}},[d.value.map((n,m,a)=>e.createVNode("div",{class:"dItem",key:n.rId},[e.createVNode("div",{class:"input"},[e.createVNode(s.NInput,{size:v,value:n.key,class:"key",onInput:r=>{n.key=r}},null),e.createTextVNode(":"),e.createVNode(s.NInput,{size:v,value:n.value,class:"value",onInput:r=>{i.allowFilter&&n.isNumber?n.value=b.formatNumberInput(r,n.isArray,y.arraySplitSymbol):n.value=r}},{prefix:()=>e.createVNode(e.Fragment,null,[e.createVNode(s.NButton,{type:n.isArray?"success":"default",size:"tiny",onClick:()=>{n.isArray=!n.isArray}},{default:()=>[e.createTextVNode("Array")]}),e.createTextVNode(" "),e.createVNode(s.NButton,{type:n.isNumber?"success":"default",size:"tiny",onClick:()=>{n.isNumber=!n.isNumber}},{default:()=>[e.createTextVNode("Number")]})])})]),e.createVNode("div",{class:"btn"},[e.createVNode(s.NButton,{type:"success",size:v,disabled:m!==a.length-1,onClick:()=>{d.value.push({rId:t.randomFun(),key:"",value:""}),i.autoScroll&&e.nextTick(()=>{const r=N.value;r?.scrollTo({top:r.scrollHeight,behavior:"smooth"})})}},{default:()=>[e.createTextVNode("+")]}),e.createVNode(s.NButton,{size:v,type:"error",onClick:()=>{d.value=d.value.filter(r=>r.rId!==n.rId)}},{default:()=>[e.createTextVNode("-")]})])]))]),e.createVNode("div",{class:`control ${d.value.length?"":"noList"}`},[!d.value.length&&e.createVNode(s.NButton,{size:v,type:"success",onClick:()=>{d.value.push({rId:t.randomFun(),key:"",value:""})}},{default:()=>[l.newTxt]}),!t.isController&&e.createVNode(e.Fragment,null,[!i.hideReset&&e.createVNode(s.NButton,{size:v,type:"default",onClick:()=>{d.value=b.tranArr(t.modelValue,t.randomFun,y.arraySplitSymbol),o("onReset")}},{default:()=>[l.resetTxt]}),e.createVNode(s.NButton,{size:v,type:"info",onClick:()=>{d.value.sort((m,a)=>+m.rId-+a.rId);const n=b.resetObj(d.value,y.arraySplitSymbol);o("update:modelValue",n),o("onMerge",n,e.toRaw(d.value)),d.value=b.tranArr(n,t.randomFun,y.arraySplitSymbol)}},{default:()=>[l.mergeTxt]})])])])}});function F(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!e.isVNode(t)}const I=e.defineComponent({name:"NaiveUiDynamicCascadeInput",props:{modelValue:{type:Object,required:!0},isController:{type:Boolean},dyCls:{type:String},randomFun:{type:Function,default:t=>`${Date.now()}_${t??0}`},depth:{type:Number,default:3},btnConfigs:{type:Object},configs:{type:Object},dyListConfigs:{type:Object},newChildTxt:{type:Function,default:t=>`添加 '${t.key}' 子项`}},emits:{"update:modelValue":t=>!0,onReset:()=>!0,onMerge:(t,o)=>!0},setup(t,{emit:o,expose:c}){const l={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...t.btnConfigs},i={hideReset:!1,maxHeight:"600px",allowFilter:!0,showBorder:!0,showPad:!0,retractLen:0,borderColors:[],...t.configs},y={arraySplitSymbol:",",...t.dyListConfigs},v=a=>["string","number"].includes(a),d=a=>Object.keys(a).map((r,f)=>{let u=a[r];const g=Array.isArray(u),C=g?u.every(h=>typeof h=="number"):typeof u=="number",V=u===null;return v(typeof u)&&(u=a[r]),V&&(u=""),{rId:t.randomFun(f),key:r,value:Object.prototype.toString.call(u)==="[object Object]"?d(a[r]):g?u.join(y.arraySplitSymbol):u,isArray:g||void 0,isNumber:C||void 0}}),N=a=>a.reduce((r,f)=>{const u=f.value;return f.key.trim().length&&(r[f.key]=Array.isArray(u)?N(u):b.parseValue(f.value,f.isArray,f.isNumber,y.arraySplitSymbol)),r},{}),n=e.ref(d(t.modelValue)),m=(a,r=1,f)=>e.createVNode("div",{class:[`depth-${r}`,i.showBorder?"":"no-border",i.showPad?"":"no-pad"],style:{"--depth":r,["--c"+[r]]:b.saferRepairColor(i.borderColors,r)}},[a.map((u,g,C)=>{const V=Array.isArray(u.value),h=v(typeof u.value);return e.createVNode("div",{class:"dItem",key:u.rId,style:{marginLeft:r>1?`${r*i.retractLen}px`:"0"}},[e.createVNode("div",{class:"input"},[!V&&e.createVNode(e.Fragment,null,[e.createVNode(s.NInput,{value:u.key,class:"key",onInput:p=>u.key=p},null),e.createTextVNode(":")]),e.createVNode(s.NInput,{class:`value ${V?"isKey":""}`,value:h?u.value:u.key,onInput:p=>{if(V){u.key=p;return}i.allowFilter&&u.isNumber?u.value=b.formatNumberInput(p,u.isArray,y.arraySplitSymbol):u.value=p}},{prefix:Array.isArray(u.value)?void 0:()=>e.createVNode(e.Fragment,null,[e.createVNode(s.NButton,{type:u.isArray?"success":"default",size:"tiny",onClick:()=>{u.isArray=!u.isArray}},{default:()=>[e.createTextVNode("Array")]}),e.createTextVNode(" "),e.createVNode(s.NButton,{type:u.isNumber?"success":"default",size:"tiny",onClick:()=>{u.isNumber=!u.isNumber}},{default:()=>[e.createTextVNode("Number")]})]),suffix:()=>{let p;return r<t.depth?!V&&e.createVNode(s.NButton,{type:"success",size:"tiny",onClick:()=>{h&&(u.value=[],u.isArray=void 0),u.value.push({rId:t.randomFun(),key:"",value:""})}},F(p=t.newChildTxt(u))?p:{default:()=>[p]}):null}})]),e.createVNode("div",{class:"btn"},[e.createVNode(s.NButton,{type:"success",disabled:g!==C.length-1,onClick:()=>{a.push({rId:t.randomFun(),key:"",value:""})}},{default:()=>[e.createTextVNode("+")]}),e.createVNode(s.NButton,{type:"error",onClick:()=>{if(a.splice(g,1),a.length<1){if(f===void 0)return N([]);const p=n.value.findIndex(S=>S.rId===f?.rId);r<1?n.value.splice(p,1,{...f,value:""}):f.value=""}}},{default:()=>[e.createTextVNode("-")]})]),Array.isArray(u.value)&&m(u.value,r+1,u)])})]);return e.watch(n,a=>{if(!t.isController)return;const r=N(a);o("update:modelValue",r),o("onMerge",r,e.toRaw(n.value))},{deep:!0}),c({onSet:a=>{n.value=d(a??t.modelValue)},getResult:(a="res")=>a==="ori"?e.toRaw(n.value):N(n.value)}),()=>e.createVNode("div",{class:t.dyCls??"dynamicCascadeForm"},[e.createVNode("div",{class:"dyFormList",style:{maxHeight:i.maxHeight}},[m(n.value)]),e.createVNode("div",{class:"control"},[!n.value.length&&e.createVNode(s.NButton,{type:"success",onClick:()=>{n.value.push({rId:t.randomFun(),key:"",value:""})}},{default:()=>[l.newTxt]}),!t.isController&&e.createVNode(e.Fragment,null,[!i.hideReset&&e.createVNode(s.NButton,{type:"default",onClick:()=>{n.value=d(t.modelValue),o("onReset")}},{default:()=>[l.resetTxt]}),e.createVNode(s.NButton,{type:"info",onClick:()=>{const a=N(n.value);o("update:modelValue",a),o("onMerge",a,e.toRaw(n.value)),n.value=d(a)}},{default:()=>[l.mergeTxt]})])])])}}),T=e.defineComponent({name:"NaiDynamicForm",props:{formConfig:{type:Object,default:()=>({labelPlacement:"left",size:"medium"})},gridConfig:{type:Object,default:()=>({responsive:"screen",cols:"xs:1 s:2 m:3 l:3 xl:4 2xl:4",xGap:10})},rules:{type:Object},preset:{type:String,default:"fullRow",validator:t=>["fullRow","grid"].includes(t)?!0:(console.error("preset value must be `fullRow` or `grid`, the default value is `fullRow`"),!1)},items:{type:Array,require:!0}},setup(t,{emit:o,expose:c}){const l=e.ref(null),i=e.computed(()=>(t.items??[]).filter(m=>!m.hidden)),y=e.computed(()=>i.value?i.value.reduce((m,a)=>(m[a.key]=a.value.value,m),{}):{}),v=e.computed(()=>({...i.value?.reduce((a,r)=>{let f=r.rule;return r.required&&!r.rule&&(f={required:!0,message:`${r.label}不能为空`,trigger:["blur"]}),a[r.key]=f,a},{}),...t.rules})),d=e.computed(()=>[...i.value].sort((a,r)=>{const f=a.sort??1/0,u=r.sort??1/0;return Number(f)-Number(u)}));function N(m=null){i.value&&i.value.forEach(a=>{a.reset?a.reset(a):a.value.value=m})}function n(){return new Promise((m,a)=>{l.value?.validate(r=>{r?a(r):m(y.value)})})}if(c({reset:N,validator:n,getResult:(m="res")=>m==="ori"?i.value:y.value}),!t.items)throw new Error("prop items must be not null");return()=>e.createVNode("div",{class:"naiDynamicForm"},[e.createVNode(s.NForm,e.mergeProps({ref:l},t.formConfig,{model:y.value,rules:v.value}),{default(){const m=d.value;return t.preset==="grid"?e.h(s.NGrid,{...t.gridConfig},{default:()=>m?.map(a=>e.h(s.NFormItemGridItem,{label:a.label,path:a.path||a.key},{default:x(a)}))}):m?.map(a=>e.h(s.NFormItem,{label:a.label,path:a.path||a.key},{default:x(a)}))}})])}});function x(t){return function(){return t.render2?t.render2(t):null}}function R(t,o={},c){return e.h(s.NInput,{...c,value:t.value,onUpdateValue:l=>{t.value=l,c?.onChange?.(l,c)},...o})}function A(t,o,c={},l){return e.h(s.NSelect,{...l,value:t.value,options:o,onUpdateValue:i=>{t.value=i,l?.onChange?.(i,l,o)},...c})}function w(t,o,c={},l,i){const{value:y,labelField:v,valueField:d,...N}=l,n=v??"label",m=d??"value",a=N.options??o;return e.createVNode(s.NPopselect,{...N,value:t.value,onUpdateValue:r=>{t.value=r,l?.onChange?.(r,l,a)},options:a.map(r=>({...r,label:r[n],value:r[m]})),...c},{default:()=>i??e.createVNode(s.NButton,null,{default:()=>t.value||"请选择"})})}function j(t,o,c={},l){const{valueField:i="value",...y}=l;return e.h(s.NTreeSelect,{...y,value:t.value,options:o,onUpdateValue:v=>{t.value=v,l?.onChange?.(v,l,o)},keyField:i,...c})}function B(t,o,c={},l){return e.h(s.NRadioGroup,{...l,value:t.value,onUpdateValue:i=>{t.value=i,l?.onChange?.(i,l,o)},...c},{default:()=>(l?.options??o).map(y=>{const v=l,d=y[v?.labelField??"label"],N=y[v?.valueField??"value"];return e.h(s.NRadio,{...y,label:d,value:N},{default:()=>y.label})})})}function O(t,o,c={},l){return e.createVNode(s.NRadioGroup,{...l,value:t.value,onUpdateValue:i=>{t.value=i,l?.onChange?.(i,l,o)},...c},{default:()=>(l?.options??o).map(y=>{const v=l,d=y[v?.labelField??"label"],N=y[v?.valueField??"value"];return e.createVNode(s.NRadioButton,{...y,label:d,value:N},{default:()=>y.label})})})}function P(t,o,c={},l){return e.h(s.NCheckboxGroup,{...l,value:t.value,onUpdateValue:i=>{t.value=i,l?.onChange?.(i,l,o)},...c},{default:()=>e.h(s.NSpace,{itemStyle:"display: flex"},{default:()=>(l?.options??o).map(y=>{const v=l,d=y[v?.labelField??"label"],N=y[v?.valueField??"value"];return e.h(s.NCheckbox,{value:N,label:d})})})})}function z(t,o={},c){return e.h(s.NSwitch,{...c,value:t.value,onUpdateValue:l=>{t.value=l,c?.onChange?.(l,c)},...o})}function D(t,o={},c){return e.h(s.NDatePicker,{...c,value:t.value,onUpdateValue:l=>{t.value=l,c?.onChange?.(l,c)},...o})}function G(t,o={},c){return e.h(s.NTimePicker,{...c,value:t.value,onUpdateValue:l=>{t.value=l,c?.onChange?.(l,c)},...o})}exports.NaiDynamicCascadeInput=I;exports.NaiDynamicForm=T;exports.NaiDynamicInput=k;exports.renderCheckboxGroup=P;exports.renderDatePicker=D;exports.renderInput=R;exports.renderPopSelect=w;exports.renderRadioButtonGroup=O;exports.renderRadioGroup=B;exports.renderSelect=A;exports.renderSwitch=z;exports.renderTimePicker=G;exports.renderTreeSelect=j;
|