zhihao-ui 1.3.64-alpha.1 → 1.3.64-alpha.2

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.
@@ -0,0 +1,405 @@
1
+ import { defineComponent as le, useModel as de, ref as R, computed as S, openBlock as d, createBlock as m, unref as p, withCtx as v, createVNode as $, mergeProps as U, createElementBlock as f, Fragment as C, renderList as q, normalizeClass as H, toDisplayString as g, renderSlot as D, createTextVNode as O, resolveDynamicComponent as ie, createCommentVNode as E, createElementVNode as b, mergeModels as se } from "vue";
2
+ import { D as B } from "./BaseItem-B9hyAgCm.js";
3
+ import { m as _, e as K, n as ne, o as ue, p as V, q as W, r as pe, s as X, b as Z } from "./vendor-BnoIpJXx.js";
4
+ import { _ as fe } from "./Button-CSE0Mb4I.js";
5
+ import { w as he } from "./utils-SutTRvhl.js";
6
+ var w = /* @__PURE__ */ ((h) => (h.AUTOCOMPLETE = "autocomplete", h.FORMAT = "format", h.TEXT = "text", h.INDEX = "index", h.SELECTION = "selection", h))(w || {});
7
+ const me = { key: 0 }, ve = {
8
+ key: 1,
9
+ class: "col-edit-header"
10
+ }, we = ["onClick"], ce = { key: 0 }, ye = { class: "header-operation-container" }, ge = { class: "operation-container" }, Ce = ["onClick"], P = "$ZH_DIV$", Ee = /* @__PURE__ */ le({
11
+ name: "zh-diy-data-table",
12
+ __name: "DiyDataTable",
13
+ props: /* @__PURE__ */ se({
14
+ isEdit: { type: Boolean, default: !1 },
15
+ maxRowLength: { default: 50 },
16
+ maxColLength: { default: 10 },
17
+ defaultMinWidth: { default: 120 },
18
+ beforeAddRow: {},
19
+ addRowText: { default: "增行" },
20
+ addColumnText: { default: "增列" },
21
+ customAddRow: { type: Boolean, default: !0 },
22
+ customAddColumn: { type: Boolean, default: !0 },
23
+ operationOption: {},
24
+ canOnlyEditNewlyColumnHeader: { type: Boolean, default: !1 },
25
+ rowKey: { default: "id" }
26
+ }, {
27
+ rawData: { required: !0 },
28
+ rawDataModifiers: {}
29
+ }),
30
+ emits: ["update:rawData"],
31
+ setup(h, { expose: z }) {
32
+ const s = h, n = de(h, "rawData"), i = R([]), A = S(() => s.rowKey || "id");
33
+ let L = 0;
34
+ const c = R({
35
+ isShow: !0,
36
+ width: 150,
37
+ customAddRow: !0,
38
+ addRowText: "增行",
39
+ customAddColumn: !0,
40
+ addColumnText: "增列"
41
+ }), y = S(() => s.operationOption ? {
42
+ ...c.value,
43
+ ...s.operationOption || {}
44
+ } : {
45
+ ...c.value,
46
+ // 兼容之前单个配置项
47
+ customAddRow: s.customAddRow !== void 0 ? s.customAddRow : c.value.customAddRow,
48
+ addRowText: s.addRowText !== void 0 ? s.addRowText : c.value.addRowText,
49
+ customAddColumn: s.customAddColumn !== void 0 ? s.customAddColumn : c.value.customAddColumn,
50
+ addColumnText: s.addColumnText !== void 0 ? s.addColumnText : c.value.addColumnText
51
+ }), x = () => (L++, `key_${Date.now()}_${L}_${Math.random().toString(36).substring(2, 11)}`), M = () => {
52
+ if (n.value.length === s.maxRowLength) {
53
+ _({
54
+ message: `最多添加${s.maxRowLength}行`,
55
+ type: "warning"
56
+ });
57
+ return;
58
+ }
59
+ const t = A.value;
60
+ let o = {
61
+ [t]: x()
62
+ };
63
+ s.beforeAddRow && (o = s.beforeAddRow(n.value), o[t] || (o[t] = x())), n.value.push(o);
64
+ }, N = () => {
65
+ if (i.value.filter((e) => e.isAdd).length >= s.maxColLength) {
66
+ _({
67
+ message: `最多添加${s.maxColLength}列`,
68
+ type: "warning"
69
+ });
70
+ return;
71
+ }
72
+ const o = String(Date.now());
73
+ i.value.push({
74
+ prop: o,
75
+ label: "",
76
+ isEditHeader: !0,
77
+ isAdd: !0,
78
+ maxlength: 15,
79
+ minWidth: 150,
80
+ headerMaxlength: 15,
81
+ isNewlyColumn: !0
82
+ });
83
+ }, j = (t, o) => {
84
+ i.value.splice(t, 1), n.value.forEach((e) => {
85
+ delete e[o.prop];
86
+ });
87
+ }, G = (t) => {
88
+ t === 0 && i.value.forEach((o) => {
89
+ o.isSameData && (n.value[1][o.prop] = n.value[0][o.prop]);
90
+ }), n.value.splice(t, 1);
91
+ }, J = (t, o, e) => {
92
+ o(
93
+ e.completeList.filter((a) => a.includes(t)).map((a) => ({ value: a }))
94
+ );
95
+ }, Q = (t) => [
96
+ {
97
+ validator: (o, e, a) => {
98
+ if (!i.value[t].label) {
99
+ a(new Error("请输入表头"));
100
+ return;
101
+ }
102
+ a();
103
+ },
104
+ message: "请输入表头",
105
+ trigger: ["blur", "change"]
106
+ }
107
+ ], Y = (t, o, e) => {
108
+ const a = [];
109
+ return t.required && a.push({
110
+ required: !0,
111
+ message: t.requiredMessage || t.label + "不能为空",
112
+ trigger: t.slot ? void 0 : "blur"
113
+ }), t.varidate && a.push({
114
+ validator: (r, l, u) => {
115
+ const k = t.varidate(l, o, e);
116
+ k !== !0 ? u(new Error(k)) : u();
117
+ }
118
+ // trigger: column.slot ? undefined : "blur",
119
+ }), a;
120
+ }, ee = (t, o) => {
121
+ let e = t;
122
+ return o.isSameData && (e = n.value[0] || B), o.formatter ? o.showFormatter ? o.type === w.FORMAT ? o.showFormatter(o.formatter(e)) : o.showFormatter(e[o.prop]) : o.formatter(e[o.prop]) : e[o.prop] || B;
123
+ }, T = R(), te = (t, o, e) => {
124
+ if (t.headerRender) {
125
+ const { column: a, ...r } = e, l = {
126
+ $index: o,
127
+ column: a,
128
+ ...r
129
+ };
130
+ return () => t.headerRender(l);
131
+ }
132
+ return null;
133
+ }, I = [w.INDEX, w.SELECTION], oe = {
134
+ width: 132,
135
+ type: w.INDEX,
136
+ prop: "index",
137
+ label: "序号",
138
+ fixed: "left",
139
+ isShow: !0
140
+ // 默认显示序号列
141
+ }, ae = {
142
+ width: 55,
143
+ type: w.SELECTION,
144
+ isShow: !1
145
+ // 默认不显示多选列
146
+ }, F = R([oe, ae]), re = S(() => F.value.filter((t) => t.isShow));
147
+ return z({
148
+ /** 初始化数据 */
149
+ initData: (t, o) => {
150
+ I.forEach((a, r) => {
151
+ const l = (o || []).find((u) => u.type === a);
152
+ l && (F.value[r] = {
153
+ ...l,
154
+ isShow: l.isShow !== !1
155
+ });
156
+ }), t = K(t) || [];
157
+ const e = A.value;
158
+ t.length === 0 ? t.push({ [e]: x() }) : t.forEach((a) => {
159
+ a[e] || (a[e] = x());
160
+ }), o = [
161
+ ...o.filter(
162
+ (a) => !I.includes(a.type)
163
+ )
164
+ ];
165
+ for (const a in t[0])
166
+ if (!o.some(
167
+ (r) => r.prop === a
168
+ )) {
169
+ const r = Date.now() + a, l = a.split(P);
170
+ if (l.length !== 2) {
171
+ console.log("keySplit 失败", a);
172
+ continue;
173
+ }
174
+ const u = Number(l[1]);
175
+ o[u] = {
176
+ prop: a,
177
+ isEditHeader: !0,
178
+ label: l[0],
179
+ key: r,
180
+ isAdd: !0,
181
+ maxlength: 15,
182
+ headerMaxlength: 15,
183
+ // 是否是本地新增的数据
184
+ isNewlyColumn: !1
185
+ };
186
+ }
187
+ n.value = t, i.value = o.filter((a) => a);
188
+ },
189
+ /** 获取数据 */
190
+ getData: async () => {
191
+ await T.value.validate();
192
+ for (const o in i.value) {
193
+ const e = i.value[o];
194
+ for (const a of i.value)
195
+ if (e.prop !== a.prop && e.label === a.label) {
196
+ _({
197
+ message: "所有列的表头不可重复",
198
+ type: "warning"
199
+ });
200
+ return;
201
+ }
202
+ }
203
+ const t = K(n.value);
204
+ for (const o in t) {
205
+ const e = t[o];
206
+ for (const a in i.value) {
207
+ const r = i.value[a];
208
+ if (r.isSameData && o !== "0" && (e[r.prop] = t[0][r.prop]), r.varidate && !r.varidate(e[r.prop], e, o))
209
+ return;
210
+ if (r.isAdd) {
211
+ const l = e[r.prop];
212
+ delete e[r.prop];
213
+ const u = r.label + P + a;
214
+ e[u] = l;
215
+ }
216
+ r.formatter && r.type === w.FORMAT && (e[r.prop] = r.formatter(e));
217
+ }
218
+ }
219
+ return {
220
+ data: t,
221
+ columns: i.value
222
+ };
223
+ },
224
+ /** 更新列配置数据 */
225
+ updateColumn: (t, o) => {
226
+ const e = i.value[t].prop;
227
+ if (i.value[t] = o, e !== o.prop)
228
+ for (const a of n.value)
229
+ a[o.prop] = a[e], delete a[e];
230
+ },
231
+ /** 重置默认列配置数据 */
232
+ resetColumns: (t, o = !1) => {
233
+ const a = i.value.filter((l) => !l.isAdd).reduce((l, u) => (t.some((k) => k.prop === u.prop) || l.push(u.prop), l), []);
234
+ n.value.forEach((l) => {
235
+ a.forEach((u) => {
236
+ delete l[u];
237
+ });
238
+ });
239
+ const r = i.value.filter((l) => l.isAdd);
240
+ o ? i.value = [...t] : i.value = [...t, ...r];
241
+ },
242
+ onAddRow: M,
243
+ onAddColumn: N,
244
+ // 导出formRef
245
+ formRef: T,
246
+ // 导出columns
247
+ getColumns: () => i.value
248
+ }), (t, o) => (d(), m(p(ne), {
249
+ class: "diy-data-table",
250
+ model: h.rawData,
251
+ ref_key: "formRef",
252
+ ref: T
253
+ }, {
254
+ default: v(() => [
255
+ $(p(ue), U({
256
+ class: "diy-data-table-table",
257
+ data: n.value,
258
+ "row-key": A.value
259
+ }, t.$attrs), {
260
+ default: v(() => [
261
+ (d(!0), f(C, null, q(re.value, (e, a) => (d(), m(p(V), U({
262
+ key: `special-${a}`,
263
+ ref_for: !0
264
+ }, e), null, 16))), 128)),
265
+ (d(!0), f(C, null, q(i.value, (e, a) => (d(), m(p(V), {
266
+ key: e.key || a,
267
+ prop: e.prop,
268
+ label: e.label,
269
+ width: e.width,
270
+ "min-width": e.minWidth || t.defaultMinWidth,
271
+ fixed: e.fixed
272
+ }, {
273
+ header: v((r) => [
274
+ e.headerRender ? (d(), m(ie(te(e, a, r)), { key: 0 })) : (d(), f(C, { key: 1 }, [
275
+ t.isEdit ? e.isEditHeader && t.canOnlyEditNewlyColumnHeader && e.isNewlyColumn || e.isEditHeader && !t.canOnlyEditNewlyColumnHeader ? (d(), f("div", ve, [
276
+ $(p(W), {
277
+ prop: `columns.${a}`,
278
+ rules: Q(a)
279
+ }, {
280
+ default: v(() => [
281
+ $(p(X), {
282
+ modelValue: e.label,
283
+ "onUpdate:modelValue": (l) => e.label = l,
284
+ maxlength: e.headerMaxlength || 20,
285
+ placeholder: "请输入表头"
286
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "maxlength"])
287
+ ]),
288
+ _: 2
289
+ }, 1032, ["prop", "rules"]),
290
+ e.isAdd ? (d(), f("i", {
291
+ key: 0,
292
+ class: "iconfont icon-close",
293
+ onClick: (l) => j(a, e)
294
+ }, null, 8, we)) : E("", !0)
295
+ ])) : (d(), f("div", {
296
+ key: 2,
297
+ class: H({ "is-required-label": e.required })
298
+ }, g(e.label), 3)) : (d(), f("div", me, g(e.label), 1))
299
+ ], 64))
300
+ ]),
301
+ default: v((r) => [
302
+ s.isEdit && (!e.isSameData || r.$index === 0) && e.type !== p(w).TEXT && !r.row.disabled ? (d(), m(p(W), {
303
+ key: 0,
304
+ prop: `${r.$index}.${e.prop}`,
305
+ rules: Y(e, r.row, r.$index),
306
+ class: H(["col-edit-container", { "close-padding": e.isAdd }])
307
+ }, {
308
+ default: v(() => [
309
+ e.type === p(w).FORMAT && e.formatter ? (d(), f("div", ce, g(e.showFormatter ? e.showFormatter(
310
+ e.formatter(r.row)
311
+ ) : e.formatter(r.row)), 1)) : e.type === p(w).AUTOCOMPLETE ? (d(), m(p(pe), {
312
+ key: 1,
313
+ modelValue: r.row[e.prop],
314
+ "onUpdate:modelValue": (l) => r.row[e.prop] = l,
315
+ placeholder: e.placeholder || "请输入",
316
+ "fetch-suggestions": (l, u) => J(l, u, e),
317
+ maxlength: e.maxlength || 20
318
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder", "fetch-suggestions", "maxlength"])) : e.slot ? D(t.$slots, e.slot, {
319
+ key: 2,
320
+ row: r.row,
321
+ $index: r.$index
322
+ }, void 0, !0) : (d(), m(p(X), {
323
+ key: 3,
324
+ modelValue: r.row[e.prop],
325
+ "onUpdate:modelValue": (l) => r.row[e.prop] = l,
326
+ placeholder: e.placeholder || "请输入",
327
+ formatter: e.formatter,
328
+ parser: e.parser,
329
+ maxlength: e.maxlength || 20,
330
+ "show-word-limit": e.showWordLimit
331
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "placeholder", "formatter", "parser", "maxlength", "show-word-limit"]))
332
+ ]),
333
+ _: 2
334
+ }, 1032, ["prop", "rules", "class"])) : e.slot ? D(t.$slots, e.slot, {
335
+ key: 1,
336
+ row: r.row,
337
+ $index: r.$index
338
+ }, void 0, !0) : (d(), f(C, { key: 2 }, [
339
+ O(g(ee(r.row, e)), 1)
340
+ ], 64))
341
+ ]),
342
+ _: 2
343
+ }, 1032, ["prop", "label", "width", "min-width", "fixed"]))), 128)),
344
+ s.isEdit && y.value.isShow ? (d(), m(p(V), {
345
+ key: 0,
346
+ width: y.value.width,
347
+ fixed: "right"
348
+ }, {
349
+ header: v(() => [
350
+ b("div", ye, [
351
+ y.value.customAddRow ? (d(), m(p(Z), {
352
+ key: 0,
353
+ type: "primary",
354
+ link: "",
355
+ onClick: M
356
+ }, {
357
+ default: v(() => [
358
+ o[0] || (o[0] = b("i", { class: "iconfont icon-Frame1" }, null, -1)),
359
+ O(g(y.value.addRowText), 1)
360
+ ]),
361
+ _: 1
362
+ })) : E("", !0),
363
+ y.value.customAddColumn ? (d(), m(p(Z), {
364
+ key: 1,
365
+ type: "primary",
366
+ link: "",
367
+ onClick: N
368
+ }, {
369
+ default: v(() => [
370
+ o[1] || (o[1] = b("i", { class: "iconfont icon-Frame-11" }, null, -1)),
371
+ O(g(y.value.addColumnText), 1)
372
+ ]),
373
+ _: 1
374
+ })) : E("", !0)
375
+ ])
376
+ ]),
377
+ default: v(({ $index: e, row: a }) => [
378
+ b("div", ge, [
379
+ t.$slots.operation ? D(t.$slots, "operation", {
380
+ key: 0,
381
+ row: n.value[e],
382
+ $index: e
383
+ }, void 0, !0) : (d(), f(C, { key: 1 }, [
384
+ n.value.length > 1 && !a.disabled ? (d(), f("i", {
385
+ key: 0,
386
+ class: "iconfont icon-close",
387
+ onClick: (r) => G(e)
388
+ }, null, 8, Ce)) : E("", !0)
389
+ ], 64))
390
+ ])
391
+ ]),
392
+ _: 3
393
+ }, 8, ["width"])) : E("", !0)
394
+ ]),
395
+ _: 3
396
+ }, 16, ["data", "row-key"])
397
+ ]),
398
+ _: 3
399
+ }, 8, ["model"]));
400
+ }
401
+ }), xe = /* @__PURE__ */ fe(Ee, [["__scopeId", "data-v-007b68b0"]]), Se = he(xe);
402
+ export {
403
+ w as D,
404
+ Se as Z
405
+ };
package/dist/es/index.js CHANGED
@@ -15,8 +15,8 @@ import { Z as V } from "./PageHeadPanel-TzAwDM3_.js";
15
15
  import { Z as D } from "./ToolTips-BsqDNvAz.js";
16
16
  import { Z as x } from "./BaseInfo-DRE7tqhe.js";
17
17
  import { Z as b } from "./DetailHeader-WPFCQJFq.js";
18
- import { Z as P } from "./DiyDataTable-D1Z76Qqd.js";
19
- import { D as $ } from "./DiyDataTable-D1Z76Qqd.js";
18
+ import { Z as P } from "./DiyDataTable-CPbTx9G5.js";
19
+ import { D as $ } from "./DiyDataTable-CPbTx9G5.js";
20
20
  import { Z as T } from "./Map-BTJrG_eT.js";
21
21
  import { Z as c } from "./Table-DELBhqxN.js";
22
22
  import { Z as ro } from "./BaseItem-B9hyAgCm.js";