vue3-smart-table 1.0.4 → 1.0.6

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.
@@ -1,19 +1,105 @@
1
- var ie = Object.defineProperty;
2
- var se = (t, e, n) => e in t ? ie(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var I = (t, e, n) => se(t, typeof e != "symbol" ? e + "" : e, n);
4
- import { defineComponent as O, h as f, ref as R, watch as z, resolveComponent as M, createBlock as _, openBlock as h, mergeProps as B, withKeys as U, withCtx as A, createElementBlock as K, Fragment as H, renderList as L, computed as F, toRefs as ae, createCommentVNode as ce, unref as a, createTextVNode as Z, toDisplayString as W, renderSlot as ne, normalizeProps as ue, resolveDynamicComponent as de, normalizeClass as me, normalizeStyle as fe, resolveDirective as ye, withDirectives as pe, createSlots as ge } from "vue";
5
- import { ElImage as q, ElTag as he, ElMessage as $, ElButton as Ce } from "element-plus";
6
- import { CopyDocument as be, DocumentCopy as ve } from "@element-plus/icons-vue";
7
- class ke {
1
+ var ce = Object.defineProperty;
2
+ var de = (t, e, n) => e in t ? ce(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var W = (t, e, n) => de(t, typeof e != "symbol" ? e + "" : e, n);
4
+ import { ref as L, watch as F, computed as S, defineComponent as R, h as m, resolveComponent as O, createBlock as w, openBlock as y, mergeProps as x, withKeys as J, withCtx as V, createElementBlock as A, Fragment as $, renderList as M, resolveDirective as fe, withDirectives as me, createSlots as ye, createTextVNode as X, toDisplayString as P, renderSlot as Z, resolveDynamicComponent as pe, unref as ee, normalizeClass as ge, normalizeStyle as he, normalizeProps as be, guardReactiveProps as ve } from "vue";
5
+ import { ElImage as q, ElTag as Ce, ElMessage as K, ElButton as we } from "element-plus";
6
+ import { CopyDocument as ke, DocumentCopy as _e } from "@element-plus/icons-vue";
7
+ function te(t, e) {
8
+ if (!(e != null && e.length)) return t;
9
+ const n = new Map(
10
+ e.map((l) => [l.key, l])
11
+ );
12
+ return t.map((l) => {
13
+ const i = n.get(l.key);
14
+ return i ? {
15
+ ...l,
16
+ visible: typeof i.visible == "boolean" ? i.visible : l.visible
17
+ } : l;
18
+ });
19
+ }
20
+ function xe(t, e) {
21
+ const { cacheKey: n, storage: l = localStorage } = e || {}, i = n ? l.getItem(n) : null, r = L(
22
+ te(
23
+ t,
24
+ i ? JSON.parse(i) : []
25
+ )
26
+ );
27
+ return F(
28
+ r,
29
+ (s) => {
30
+ if (!n) return;
31
+ const d = s.map((f) => ({
32
+ key: f.key,
33
+ visible: f.visible,
34
+ columnOpts: f.columnOpts
35
+ }));
36
+ l.setItem(
37
+ n,
38
+ JSON.stringify(d)
39
+ );
40
+ },
41
+ { deep: !0 }
42
+ ), {
43
+ /** 当前列配置(响应式) */
44
+ columns: r,
45
+ /**
46
+ * 主动设置列配置
47
+ * 常用于:列设置弹窗 / 拖拽排序完成
48
+ */
49
+ setColumns(s) {
50
+ r.value = te(
51
+ t,
52
+ s
53
+ ), n && l.setItem(
54
+ n,
55
+ JSON.stringify(s)
56
+ );
57
+ },
58
+ /**
59
+ * 重置为默认列配置
60
+ */
61
+ resetColumns() {
62
+ r.value = t, n && l.removeItem(n);
63
+ }
64
+ };
65
+ }
66
+ function Be(t, e = 10, n = []) {
67
+ const i = "*:*:*", r = (c) => {
68
+ if (!c) return !0;
69
+ const g = Array.isArray(c) ? c : [c];
70
+ return n.some(
71
+ (b) => b === i || g.includes(b)
72
+ );
73
+ }, s = S(() => t.some((c) => r(c.permission))), d = S(() => t.filter((g) => r(g.permission)).slice(0, e).reduce(
74
+ (g, b) => g + (b.width ?? 55),
75
+ 0
76
+ )), f = (c, g) => r(c.permission) && (c.visible ? c.visible(g) : !0), h = (c) => t.filter((b) => f(b, c)).slice(0, e).reduce(
77
+ (b, I) => b + (I.width ?? 55),
78
+ 0
79
+ );
80
+ return {
81
+ hasAnyButton: s,
82
+ optWidth: d,
83
+ hasAnyVisibleButton: (c) => c != null && c.length ? c.some(
84
+ (g) => t.some((b) => f(b, g))
85
+ ) : !1,
86
+ getMaxOptWidth: (c) => c != null && c.length ? c.reduce(
87
+ (g, b) => Math.max(g, h(b)),
88
+ 0
89
+ ) : d.value,
90
+ getVisibleButtons: (c) => t.filter((g) => f(g, c)).slice(0, e)
91
+ };
92
+ }
93
+ class Se {
8
94
  constructor() {
9
- I(this, "renderers", /* @__PURE__ */ new Map());
95
+ W(this, "renderers", /* @__PURE__ */ new Map());
10
96
  }
11
97
  register(e, n) {
12
98
  this.renderers.has(e) && process.env.NODE_ENV === "development" && console.debug(`[SmartTable] Renderer "${e}" already registered, skipping.`), this.renderers.set(e, n);
13
99
  }
14
100
  registerMultiple(e) {
15
- Object.entries(e).forEach(([n, r]) => {
16
- this.renderers.has(n) || this.renderers.set(n, r);
101
+ Object.entries(e).forEach(([n, l]) => {
102
+ this.renderers.has(n) || this.renderers.set(n, l);
17
103
  });
18
104
  }
19
105
  get(e) {
@@ -32,27 +118,27 @@ class ke {
32
118
  return Array.from(this.renderers.keys());
33
119
  }
34
120
  }
35
- let P = null;
36
- function J() {
37
- return P || (P = new ke()), P;
121
+ let D = null;
122
+ function H() {
123
+ return D || (D = new Se()), D;
38
124
  }
39
- function Y(t) {
40
- return O({
41
- props: ["row", "col", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
125
+ function U(t) {
126
+ return R({
127
+ props: ["row", "col", "index", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
42
128
  setup(e) {
43
- return () => f(t, e);
129
+ return () => m(t, e);
44
130
  }
45
131
  });
46
132
  }
47
- function S(t) {
48
- return O({
49
- props: ["row", "col", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
133
+ function B(t) {
134
+ return R({
135
+ props: ["row", "col", "index", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
50
136
  setup(e) {
51
137
  return () => t(e);
52
138
  }
53
139
  });
54
140
  }
55
- function He(t, e) {
141
+ function Ge(t, e) {
56
142
  if (process.env.NODE_ENV !== "production" && e)
57
143
  switch (t) {
58
144
  case "dict":
@@ -88,118 +174,121 @@ function He(t, e) {
88
174
  }
89
175
  function v(t, e) {
90
176
  if (!(!t || !e))
91
- return e.split(".").reduce((n, r) => n == null ? void 0 : n[r], t);
177
+ return e.split(".").reduce((n, l) => n == null ? void 0 : n[l], t);
92
178
  }
93
- function G(t, e, n) {
179
+ function Y(t, e, n) {
94
180
  if (!t || !e) return;
95
- const r = e.split("."), o = r.pop(), l = r.reduce((i, c) => (i[c] || (i[c] = {}), i[c]), t);
96
- l[o] = n;
181
+ const l = e.split("."), i = l.pop(), r = l.reduce((s, d) => (s[d] || (s[d] = {}), s[d]), t);
182
+ r[i] = n;
97
183
  }
98
- const we = /* @__PURE__ */ O({
184
+ const Ee = /* @__PURE__ */ R({
99
185
  __name: "input",
100
186
  props: {
101
187
  row: {},
102
188
  col: {},
189
+ index: {},
103
190
  onCellBlur: { type: Function },
104
191
  onCellEnter: { type: Function }
105
192
  },
106
193
  setup(t) {
107
- const e = t, n = R(v(e.row, e.col.key));
108
- z(n, (l) => {
109
- G(e.row, e.col.key, l);
194
+ const e = t, n = L(v(e.row, e.col.key));
195
+ F(n, (r) => {
196
+ Y(e.row, e.col.key, r);
110
197
  });
111
- const r = () => {
112
- var l;
113
- return (l = e.onCellBlur) == null ? void 0 : l.call(e, e.row, e.col);
114
- }, o = () => {
115
- var l;
116
- return (l = e.onCellEnter) == null ? void 0 : l.call(e, e.row, e.col);
198
+ const l = () => {
199
+ var r;
200
+ return (r = e.onCellBlur) == null ? void 0 : r.call(e, e.row, e.col);
201
+ }, i = () => {
202
+ var r;
203
+ return (r = e.onCellEnter) == null ? void 0 : r.call(e, e.row, e.col);
117
204
  };
118
- return (l, i) => {
119
- const c = M("el-input");
120
- return h(), _(c, B({
205
+ return (r, s) => {
206
+ const d = O("el-input");
207
+ return y(), w(d, x({
121
208
  modelValue: n.value,
122
- "onUpdate:modelValue": i[0] || (i[0] = (d) => n.value = d)
209
+ "onUpdate:modelValue": s[0] || (s[0] = (f) => n.value = f)
123
210
  }, { placeholder: "", size: "small", clearable: !0, ...t.col.renderProps }, {
124
- onBlur: r,
125
- onKeyup: U(o, ["enter"])
211
+ onBlur: l,
212
+ onKeyup: J(i, ["enter"])
126
213
  }), null, 16, ["modelValue"]);
127
214
  };
128
215
  }
129
- }), _e = /* @__PURE__ */ O({
216
+ }), Te = /* @__PURE__ */ R({
130
217
  __name: "inputNumber",
131
218
  props: {
132
219
  row: {},
133
220
  col: {},
221
+ index: {},
134
222
  onCellChange: { type: Function },
135
223
  onCellBlur: { type: Function },
136
224
  onCellEnter: { type: Function }
137
225
  },
138
226
  setup(t) {
139
- const e = t, n = R(v(e.row, e.col.key));
140
- z(n, (l) => {
141
- var i;
142
- G(e.row, e.col.key, l), (i = e.onCellChange) == null || i.call(e, e.row, e.col);
227
+ const e = t, n = L(v(e.row, e.col.key));
228
+ F(n, (r) => {
229
+ var s;
230
+ Y(e.row, e.col.key, r), (s = e.onCellChange) == null || s.call(e, e.row, e.col);
143
231
  });
144
- const r = () => {
145
- var l;
146
- return (l = e.onCellBlur) == null ? void 0 : l.call(e, e.row, e.col);
147
- }, o = () => {
148
- var l;
149
- return (l = e.onCellEnter) == null ? void 0 : l.call(e, e.row, e.col);
232
+ const l = () => {
233
+ var r;
234
+ return (r = e.onCellBlur) == null ? void 0 : r.call(e, e.row, e.col);
235
+ }, i = () => {
236
+ var r;
237
+ return (r = e.onCellEnter) == null ? void 0 : r.call(e, e.row, e.col);
150
238
  };
151
- return (l, i) => {
152
- const c = M("el-input-number");
153
- return h(), _(c, B({
239
+ return (r, s) => {
240
+ const d = O("el-input-number");
241
+ return y(), w(d, x({
154
242
  modelValue: n.value,
155
- "onUpdate:modelValue": i[0] || (i[0] = (d) => n.value = d)
243
+ "onUpdate:modelValue": s[0] || (s[0] = (f) => n.value = f)
156
244
  }, { min: 0, max: 99999, controls: !1, size: "small", ...t.col.renderProps }, {
157
- onBlur: r,
158
- onKeyup: U(o, ["enter"])
245
+ onBlur: l,
246
+ onKeyup: J(i, ["enter"])
159
247
  }), null, 16, ["modelValue"]);
160
248
  };
161
249
  }
162
- }), xe = /* @__PURE__ */ O({
250
+ }), Ve = /* @__PURE__ */ R({
163
251
  __name: "select",
164
252
  props: {
165
253
  row: {},
166
254
  col: {},
255
+ index: {},
167
256
  onCellChange: { type: Function },
168
257
  onCellBlur: { type: Function },
169
258
  onCellEnter: { type: Function }
170
259
  },
171
260
  setup(t) {
172
- const e = t, n = R(v(e.row, e.col.key));
173
- z(n, (i) => {
174
- G(e.row, e.col.key, i);
261
+ const e = t, n = L(v(e.row, e.col.key));
262
+ F(n, (s) => {
263
+ Y(e.row, e.col.key, s);
175
264
  });
176
- const r = () => {
177
- var i;
178
- return (i = e.onCellChange) == null ? void 0 : i.call(e, e.row, e.col);
179
- }, o = () => {
180
- var i;
181
- return (i = e.onCellBlur) == null ? void 0 : i.call(e, e.row, e.col);
182
- }, l = () => {
183
- var i;
184
- return (i = e.onCellEnter) == null ? void 0 : i.call(e, e.row, e.col);
265
+ const l = () => {
266
+ var s;
267
+ return (s = e.onCellChange) == null ? void 0 : s.call(e, e.row, e.col);
268
+ }, i = () => {
269
+ var s;
270
+ return (s = e.onCellBlur) == null ? void 0 : s.call(e, e.row, e.col);
271
+ }, r = () => {
272
+ var s;
273
+ return (s = e.onCellEnter) == null ? void 0 : s.call(e, e.row, e.col);
185
274
  };
186
- return (i, c) => {
187
- const d = M("el-option"), g = M("el-select");
188
- return h(), _(g, B({
275
+ return (s, d) => {
276
+ const f = O("el-option"), h = O("el-select");
277
+ return y(), w(h, x({
189
278
  modelValue: n.value,
190
- "onUpdate:modelValue": c[0] || (c[0] = (b) => n.value = b)
279
+ "onUpdate:modelValue": d[0] || (d[0] = (k) => n.value = k)
191
280
  }, { placeholder: "请选择", size: "small", clearable: !0, ...t.col.renderProps }, {
192
- onChange: r,
193
- onBlur: o,
194
- onKeyup: U(l, ["enter"])
281
+ onChange: l,
282
+ onBlur: i,
283
+ onKeyup: J(r, ["enter"])
195
284
  }), {
196
- default: A(() => {
197
- var b;
285
+ default: V(() => {
286
+ var k;
198
287
  return [
199
- (h(!0), K(H, null, L(((b = t.col.renderProps) == null ? void 0 : b.options) || [], (m) => (h(), _(d, {
200
- key: m.value,
201
- label: m.label,
202
- value: m.value
288
+ (y(!0), A($, null, M(((k = t.col.renderProps) == null ? void 0 : k.options) || [], (E) => (y(), w(f, {
289
+ key: E.value,
290
+ label: E.label,
291
+ value: E.value
203
292
  }, null, 8, ["label", "value"]))), 128))
204
293
  ];
205
294
  }),
@@ -207,33 +296,33 @@ const we = /* @__PURE__ */ O({
207
296
  }, 16, ["modelValue"]);
208
297
  };
209
298
  }
210
- }), Be = Y(we), Se = Y(_e), Ee = Y(xe), Te = S((t) => {
299
+ }), Ae = U(Ee), Me = U(Te), Oe = U(Ve), $e = B((t) => {
211
300
  const e = t.col.renderProps || {}, n = v(t.row, t.col.key);
212
- return f(Ce, {
301
+ return m(we, {
213
302
  type: e.type || "primary",
214
303
  ...e,
215
304
  onClick: () => {
216
- var r;
217
- return (r = t.onClick) == null ? void 0 : r.call(t, t.row, t.col);
305
+ var l;
306
+ return (l = t.onClick) == null ? void 0 : l.call(t, t.row, t.col);
218
307
  }
219
308
  }, () => e.label || n);
220
- }), Ve = S((t) => {
309
+ }), Fe = B((t) => {
221
310
  const e = t.col.renderProps || {}, n = v(t.row, t.col.key);
222
- return f("a", {
311
+ return m("a", {
223
312
  href: e.href || "#",
224
313
  target: e.blank ? "_blank" : "_self",
225
314
  style: e.style || "color:#409EFF;cursor:pointer;"
226
315
  }, e.label || n);
227
- }), Ae = S((t) => {
316
+ }), Re = B((t) => {
228
317
  var n;
229
318
  const e = v(t.row, t.col.key);
230
- return f("div", {
319
+ return m("div", {
231
320
  class: "line-clamp-2",
232
321
  innerHTML: e ?? "",
233
322
  ...((n = t.col) == null ? void 0 : n.renderProps) || {}
234
323
  });
235
- }), Me = S((t) => {
236
- const e = v(t.row, t.col.key) ?? "", n = t.col.renderProps ?? {}, r = {
324
+ }), ze = B((t) => {
325
+ const e = v(t.row, t.col.key) ?? "", n = t.col.renderProps ?? {}, l = {
237
326
  position: "absolute",
238
327
  right: "-5px",
239
328
  top: "50%",
@@ -243,7 +332,7 @@ const we = /* @__PURE__ */ O({
243
332
  "font-size": "12px",
244
333
  color: n.iconColor || "#409EFF",
245
334
  "user-select": "none"
246
- }, o = {
335
+ }, i = {
247
336
  "padding-right": "10px",
248
337
  display: "-webkit-box",
249
338
  "-webkit-box-orient": "vertical",
@@ -251,330 +340,146 @@ const we = /* @__PURE__ */ O({
251
340
  overflow: "hidden",
252
341
  ...n.textStyles
253
342
  };
254
- return f(
343
+ return m(
255
344
  "div",
256
345
  {
257
346
  class: "st_copy_wrapper",
258
347
  style: "width: 100%; position: relative; display: inline-block;"
259
348
  },
260
349
  [
261
- f("span", {
350
+ m("span", {
262
351
  class: `st_copy_text ${n.textClass ?? ""}`,
263
- style: o,
352
+ style: i,
264
353
  title: e
265
354
  }, e),
266
- e && f("span", {
355
+ e && m("span", {
267
356
  class: "st_copy_btn",
268
- style: r,
357
+ style: l,
269
358
  title: n.copyTitle || "复制",
270
359
  onClick: () => {
271
360
  if (e)
272
361
  try {
273
362
  if (navigator.clipboard && navigator.clipboard.writeText)
274
363
  navigator.clipboard.writeText(e).then(() => {
275
- $.success(n.successText ?? "复制成功");
364
+ K.success(n.successText ?? "复制成功");
276
365
  }).catch(() => {
277
- $.error(n.errorText ?? "复制失败");
366
+ K.error(n.errorText ?? "复制失败");
278
367
  });
279
368
  else {
280
- const l = document.createElement("textarea");
281
- l.value = e, l.style.position = "fixed", l.style.opacity = "0", document.body.appendChild(l), l.select();
282
- const i = document.execCommand("copy");
283
- document.body.removeChild(l), i ? $.success(n.successText ?? "复制成功") : $.error(n.errorText ?? "复制失败");
369
+ const r = document.createElement("textarea");
370
+ r.value = e, r.style.position = "fixed", r.style.opacity = "0", document.body.appendChild(r), r.select();
371
+ const s = document.execCommand("copy");
372
+ document.body.removeChild(r), s ? K.success(n.successText ?? "复制成功") : K.error(n.errorText ?? "复制失败");
284
373
  }
285
374
  } catch {
286
- $.error(n.errorText ?? "复制失败");
375
+ K.error(n.errorText ?? "复制失败");
287
376
  }
288
377
  }
289
- }, [f(ve, {
378
+ }, [m(_e, {
290
379
  style: "width: 1em; height: 1em;"
291
380
  })])
292
381
  ].filter(Boolean)
293
382
  );
294
- }), Oe = S((t) => {
295
- var i;
296
- const e = v(t.row, t.col.key) ?? "", n = ((i = t.col) == null ? void 0 : i.renderProps) || {}, o = e ? Array.isArray(e) ? e.filter((c) => c && typeof c == "string") : [e] : [];
297
- if (o.length === 0)
383
+ }), Ke = B((t) => {
384
+ var s;
385
+ const e = v(t.row, t.col.key) ?? "", n = ((s = t.col) == null ? void 0 : s.renderProps) || {}, i = e ? Array.isArray(e) ? e.filter((d) => d && typeof d == "string") : [e] : [];
386
+ if (i.length === 0)
298
387
  return n.placeholder || "";
299
- const l = {
388
+ const r = {
300
389
  width: n.width || "80px",
301
390
  height: n.height || "80px",
302
- marginRight: o.length > 1 ? "4px" : "0",
391
+ marginRight: i.length > 1 ? "4px" : "0",
303
392
  ...n.style || {}
304
393
  };
305
- return o.length === 1 ? f(q, {
306
- src: o[0],
307
- previewSrcList: n.previewSrcList || o,
394
+ return i.length === 1 ? m(q, {
395
+ src: i[0],
396
+ previewSrcList: n.previewSrcList || i,
397
+ previewTeleported: !0,
308
398
  fit: n.fit || "contain",
309
- style: l,
399
+ style: r,
310
400
  ...n
311
- }) : f(
401
+ }) : m(
312
402
  "div",
313
403
  {
314
404
  class: "st_img_wrapper",
315
405
  style: "display: flex; align-items: center; position: relative"
316
406
  },
317
407
  [
318
- f(q, {
319
- src: o[0],
320
- previewSrcList: n.previewSrcList || o,
408
+ m(q, {
409
+ src: i[0],
410
+ previewSrcList: n.previewSrcList || i,
411
+ previewTeleported: !0,
321
412
  fit: n.fit || "contain",
322
- style: l,
413
+ style: r,
323
414
  ...n
324
415
  }),
325
- o.length > 1 && f("span", {
416
+ i.length > 1 && m("span", {
326
417
  class: "st_img_total",
327
418
  style: "position: absolute; top: 0; right: 0; ",
328
- title: `${o.length}`
329
- }, [f(be, { style: "width: 1em; height: 1em; " })])
419
+ title: `${i.length}`
420
+ }, [m(ke, { style: "width: 1em; height: 1em; " })])
330
421
  ]
331
422
  );
332
- }), $e = S((t) => {
333
- const e = v(t.row, t.col.key) ?? "", n = t.col.renderProps || {}, r = n.options ?? [], o = n.showValue ?? !1;
423
+ }), Le = B((t) => {
424
+ const e = v(t.row, t.col.key) ?? "", n = t.col.renderProps || {}, l = n.options ?? [], i = n.showValue ?? !1;
334
425
  if (e == null || e === "") return "";
335
- const l = Array.isArray(e) ? e.map(String) : [String(e)], i = r.filter((g) => l.includes(String(g.value))), c = l.filter((g) => !r.some((b) => String(b.value) === g)), d = i.map((g, b) => f(
336
- he,
337
- { key: g.value, type: g.listClass, class: g.cssClass, disableTransitions: !0 },
338
- { default: () => g.label + " " }
426
+ const r = Array.isArray(e) ? e.map(String) : [String(e)], s = l.filter((h) => r.includes(String(h.value))), d = r.filter((h) => !l.some((k) => String(k.value) === h)), f = s.map((h, k) => m(
427
+ Ce,
428
+ { key: h.value, type: h.listClass, class: h.cssClass, disableTransitions: !0 },
429
+ { default: () => h.label + " " }
339
430
  ));
340
- return o && c.length > 0 && d.push(f("span", {}, c.join(" "))), f("div", {}, d);
341
- }), Fe = S((t) => {
342
- var r;
343
- const e = v(t.row, t.col.key) ?? "", n = ((r = t.col.renderProps) == null ? void 0 : r.options) ?? {};
431
+ return i && d.length > 0 && f.push(m("span", {}, d.join(" "))), m("div", {}, f);
432
+ }), Ie = B((t) => {
433
+ var l;
434
+ const e = v(t.row, t.col.key) ?? "", n = ((l = t.col.renderProps) == null ? void 0 : l.options) ?? {};
344
435
  return e != null ? n[e] ?? "" : "";
345
436
  });
346
- function Re(t) {
437
+ function Ne(t) {
347
438
  return typeof t.formatter == "function";
348
439
  }
349
- const ze = S((t) => {
350
- var o;
351
- const { col: e, row: n } = t, r = v(t.row, t.col.key) ?? "";
352
- return Re(e) ? (o = e.formatter) == null ? void 0 : o.call(e, r, n) : r ?? "";
353
- }), Ke = S((t) => {
440
+ const We = B((t) => {
441
+ var r;
442
+ const { col: e, row: n, index: l } = t, i = v(t.row, t.col.key) ?? "";
443
+ return Ne(e) ? (r = e.formatter) == null ? void 0 : r.call(e, i, n, l) : i ?? "";
444
+ }), Pe = B((t) => {
354
445
  const e = v(t.row, t.col.key) ?? "", n = t.col.renderProps || {};
355
- return e ? /^https?:\/\//.test(e) ? f(q, {
446
+ return e ? /^https?:\/\//.test(e) ? m(q, {
356
447
  src: e,
357
448
  previewSrcList: [e],
449
+ previewTeleported: !0,
358
450
  fit: "contain",
359
451
  style: "width:40px;height:40px",
360
452
  ...n
361
- }) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ? f("div", {
453
+ }) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ? m("div", {
362
454
  innerHTML: e,
363
455
  style: `width:40px;height:40px;display:inline-block;${n.style || ""}`,
364
456
  ...n
365
- }) : f("i", {
457
+ }) : m("i", {
366
458
  class: e,
367
459
  style: `font-size:20px;${n.style || ""}`,
368
460
  ...n
369
461
  }) : "";
370
- }), le = {
371
- input: Be,
372
- "input-number": Se,
373
- select: Ee,
374
- button: Te,
375
- link: Ve,
376
- html: Ae,
377
- copy: Me,
378
- img: Oe,
379
- dict: $e,
380
- map: Fe,
381
- formatter: ze,
382
- icon: Ke
462
+ }), re = {
463
+ input: Ae,
464
+ "input-number": Me,
465
+ select: Oe,
466
+ button: $e,
467
+ link: Fe,
468
+ html: Re,
469
+ copy: ze,
470
+ img: Ke,
471
+ dict: Le,
472
+ map: Ie,
473
+ formatter: We,
474
+ icon: Pe
383
475
  };
384
- function Le(t) {
385
- t.registerMultiple(le);
386
- }
387
- function Ye() {
388
- return le;
389
- }
390
- function Ne(t, e = 10, n = []) {
391
- const o = "*:*:*", l = (s) => {
392
- if (!s) return !0;
393
- const y = Array.isArray(s) ? s : [s];
394
- return n.some(
395
- (p) => p === o || y.includes(p)
396
- );
397
- }, i = F(() => t.some((s) => l(s.permission))), c = F(() => t.filter((y) => l(y.permission)).slice(0, e).reduce(
398
- (y, p) => y + (p.width ?? 60),
399
- 0
400
- )), d = (s, y) => l(s.permission) && (s.visible ? s.visible(y) : !0), g = (s) => t.filter((p) => d(p, s)).slice(0, e).reduce(
401
- (p, E) => p + (E.width ?? 60),
402
- 0
403
- );
404
- return {
405
- hasAnyButton: i,
406
- optWidth: c,
407
- hasAnyVisibleButton: (s) => s != null && s.length ? s.some(
408
- (y) => t.some((p) => d(p, y))
409
- ) : !1,
410
- getMaxOptWidth: (s) => s != null && s.length ? s.reduce(
411
- (y, p) => Math.max(y, g(p)),
412
- 0
413
- ) : c.value,
414
- getVisibleButtons: (s) => t.filter((y) => d(y, s)).slice(0, e)
415
- };
476
+ function De(t) {
477
+ t.registerMultiple(re);
416
478
  }
417
- const De = ["title"], Ie = /* @__PURE__ */ O({
418
- __name: "index",
419
- props: {
420
- col: { type: Object, required: !0 },
421
- permissions: { type: Array, default: () => [] },
422
- pagination: { type: Object, default: () => ({}) }
423
- },
424
- emits: ["cellBlur", "cellEnter", "cellChange", "cellClick"],
425
- setup(t, { emit: e }) {
426
- const n = t, r = e, o = (u) => {
427
- var T, w;
428
- const C = (T = n.pagination) == null ? void 0 : T.page, x = (w = n.pagination) == null ? void 0 : w.size;
429
- return C && x ? (C - 1) * x + u + 1 : u + 1;
430
- }, { col: l } = ae(n), i = (u, C) => r("cellChange", u, C), c = (u, C) => r("cellBlur", u, C), d = (u, C) => r("cellEnter", u, C), g = (u, C) => r("cellClick", u, C);
431
- Le(J());
432
- const b = F(() => {
433
- const u = J(), C = {};
434
- return u.names().forEach((x) => {
435
- const T = u.get(x);
436
- T && (C[x] = T);
437
- }), C;
438
- }), {
439
- hasAnyButton: m,
440
- hasAnyVisibleButton: k,
441
- optWidth: s,
442
- getMaxOptWidth: y,
443
- getVisibleButtons: p
444
- } = Ne(
445
- l.value.buttons || [],
446
- l.value.maxbtn ?? 10,
447
- n.permissions || []
448
- ), E = F(() => (l.value.buttons || []).length ? (l.value.__rows || []).length ? k(l.value.__rows || []) : m.value : !1), N = F(() => l.value.__rows ? y(l.value.__rows) : s.value);
449
- function oe(u) {
450
- return !(u.type === "selection" || u.type === "index" || u.type === "operation" && !E.value || u.visible === !1);
451
- }
452
- return (u, C) => {
453
- const x = M("el-table-column"), T = M("el-button");
454
- return a(l).type === "selection" ? (h(), _(x, B({
455
- key: 0,
456
- type: "selection"
457
- }, a(l).columnProps), null, 16)) : a(l).type === "index" ? (h(), _(x, B({
458
- key: 1,
459
- type: "index",
460
- label: a(l).label || "#",
461
- align: "center"
462
- }, a(l).columnProps), {
463
- default: A(({ $index: w }) => [
464
- Z(W(o(w)), 1)
465
- ]),
466
- _: 1
467
- }, 16, ["label"])) : a(l).type === "operation" && E.value ? (h(), _(x, B({
468
- key: 2,
469
- label: a(l).label || "操作",
470
- align: "center"
471
- }, {
472
- ...a(l).columnProps,
473
- width: N.value
474
- }), {
475
- default: A(({ row: w }) => [
476
- (h(!0), K(H, null, L(a(p)(w), (V) => (h(), _(T, {
477
- key: V.label,
478
- type: V.type || "primary",
479
- link: "",
480
- onClick: (D) => V.action(w)
481
- }, {
482
- default: A(() => [
483
- Z(W(V.label), 1)
484
- ]),
485
- _: 2
486
- }, 1032, ["type", "onClick"]))), 128))
487
- ]),
488
- _: 1
489
- }, 16, ["label"])) : oe(a(l)) ? (h(), _(x, B({
490
- key: 3,
491
- label: a(l).label,
492
- align: "center"
493
- }, a(l).columnProps || {}), {
494
- default: A((w) => {
495
- var V, D, Q, X;
496
- return [
497
- a(l).render === "slot" && u.$slots[((V = a(l)) == null ? void 0 : V.slot) || a(l).key] ? ne(u.$slots, ((D = a(l)) == null ? void 0 : D.slot) || a(l).key, ue(B({ key: 0 }, w))) : a(l).render && b.value[a(l).render] ? (h(), _(de(b.value[a(l).render]), {
498
- key: 1,
499
- row: w.row,
500
- col: a(l),
501
- onCellChange: i,
502
- onCellBlur: c,
503
- onCellEnter: d,
504
- onClick: g
505
- }, null, 40, ["row", "col"])) : (h(), K("span", {
506
- key: 2,
507
- style: fe(((Q = a(l).renderProps) == null ? void 0 : Q.style) || ""),
508
- class: me(((X = a(l).renderProps) == null ? void 0 : X.class) || ""),
509
- title: a(v)(w.row, a(l).key)
510
- }, W(a(v)(w.row, a(l).key)), 15, De))
511
- ];
512
- }),
513
- _: 3
514
- }, 16, ["label"])) : ce("", !0);
515
- };
516
- }
517
- });
518
- function ee(t, e) {
519
- if (!(e != null && e.length)) return t;
520
- const n = new Map(
521
- e.map((r) => [r.key, r])
522
- );
523
- return t.map((r) => {
524
- const o = n.get(r.key);
525
- return o ? {
526
- ...r,
527
- visible: typeof o.visible == "boolean" ? o.visible : r.visible
528
- } : r;
529
- });
530
- }
531
- function We(t, e) {
532
- const { cacheKey: n, storage: r = localStorage } = e || {}, o = n ? r.getItem(n) : null, l = R(
533
- ee(
534
- t,
535
- o ? JSON.parse(o) : []
536
- )
537
- );
538
- return z(
539
- l,
540
- (i) => {
541
- if (!n) return;
542
- const c = i.map((d) => ({
543
- key: d.key,
544
- visible: d.visible,
545
- columnOpts: d.columnOpts
546
- }));
547
- r.setItem(
548
- n,
549
- JSON.stringify(c)
550
- );
551
- },
552
- { deep: !0 }
553
- ), {
554
- /** 当前列配置(响应式) */
555
- columns: l,
556
- /**
557
- * 主动设置列配置
558
- * 常用于:列设置弹窗 / 拖拽排序完成
559
- */
560
- setColumns(i) {
561
- l.value = ee(
562
- t,
563
- i
564
- ), n && r.setItem(
565
- n,
566
- JSON.stringify(i)
567
- );
568
- },
569
- /**
570
- * 重置为默认列配置
571
- */
572
- resetColumns() {
573
- l.value = t, n && r.removeItem(n);
574
- }
575
- };
479
+ function Qe() {
480
+ return re;
576
481
  }
577
- const Ge = /* @__PURE__ */ O({
482
+ const je = ["title"], Xe = /* @__PURE__ */ R({
578
483
  __name: "index",
579
484
  props: {
580
485
  data: { type: Array, default: () => [] },
@@ -596,59 +501,166 @@ const Ge = /* @__PURE__ */ O({
596
501
  "cell-click"
597
502
  ],
598
503
  setup(t, { expose: e, emit: n }) {
599
- const r = t, o = n, { columns: l } = We(r.columns, {
600
- cacheKey: r.cacheKey ?? ""
504
+ const l = t, i = n, { columns: r } = xe(l.columns, {
505
+ cacheKey: l.cacheKey ?? ""
601
506
  });
602
- z(
603
- l,
604
- (m) => o("update:columns", m),
507
+ F(
508
+ r,
509
+ (o) => i("update:columns", o),
510
+ { deep: !0, immediate: !0 }
511
+ ), F(
512
+ () => l.data,
513
+ (o) => {
514
+ o && r.value.forEach((a) => {
515
+ a.type === "operation" && (a.__rows = o);
516
+ });
517
+ },
605
518
  { deep: !0, immediate: !0 }
606
519
  );
607
- const i = (m, k) => o("cellChange", m, k), c = (m, k) => {
608
- o("cellBlur", m, k);
609
- }, d = (m, k) => {
610
- console.log("enter"), o("cellEnter", m, k);
611
- }, g = (m, k) => {
612
- k && o("cell-click", m, k);
613
- }, b = R();
520
+ const s = S(
521
+ () => r.value.filter((o) => o.type === "selection")
522
+ ), d = S(
523
+ () => r.value.filter((o) => o.type === "index")
524
+ ), f = S(
525
+ () => r.value.filter((o) => o.type === "operation")
526
+ ), h = S(
527
+ () => r.value.filter((o) => !(o.type === "selection" || o.type === "index" || o.type === "operation" || o.visible === !1))
528
+ ), k = (o) => {
529
+ var _, z;
530
+ const a = (_ = l.pagination) == null ? void 0 : _.page, p = (z = l.pagination) == null ? void 0 : z.size;
531
+ return a && p ? (a - 1) * p + o + 1 : o + 1;
532
+ };
533
+ De(H());
534
+ const E = S(() => {
535
+ const o = H(), a = {};
536
+ return o.names().forEach((p) => {
537
+ const _ = o.get(p);
538
+ _ && (a[p] = _);
539
+ }), a;
540
+ }), G = S(() => {
541
+ const o = /* @__PURE__ */ new Map();
542
+ return f.value.forEach((a) => {
543
+ const p = Be(
544
+ a.buttons || [],
545
+ a.maxbtn ?? 10,
546
+ l.permissions || []
547
+ );
548
+ o.set(a.key, p);
549
+ }), o;
550
+ }), c = (o) => G.value.get(o.key), g = (o) => {
551
+ const a = c(o);
552
+ return a ? o.__rows ? a.getMaxOptWidth(o.__rows) : a.optWidth.value : 0;
553
+ }, b = (o, a) => {
554
+ const p = c(o);
555
+ return p ? (o.buttons || []).length ? ((o.__rows || []).length, p.getVisibleButtons(a)) : [] : [];
556
+ }, I = () => f.value.filter((o) => {
557
+ const a = c(o);
558
+ return !a || !(o.buttons || []).length ? !1 : (o.__rows || []).length ? a.hasAnyVisibleButton(o.__rows || []) : a.hasAnyButton.value;
559
+ }), oe = (o, a) => {
560
+ i("cellChange", o, a);
561
+ }, ie = (o, a) => {
562
+ i("cellBlur", o, a);
563
+ }, se = (o, a) => {
564
+ i("cellEnter", o, a);
565
+ }, ae = (o, a) => {
566
+ a && i("cell-click", o, a);
567
+ }, Q = L();
614
568
  return e({
615
- tableRef: b
616
- }), (m, k) => {
617
- const s = M("el-table"), y = ye("loading");
618
- return pe((h(), _(s, B({
569
+ tableRef: Q
570
+ }), (o, a) => {
571
+ const p = O("el-table-column"), _ = O("el-button"), z = O("el-table"), ue = fe("loading");
572
+ return me((y(), w(z, x({
619
573
  ref_key: "tableRef",
620
- ref: b
621
- }, m.$attrs, {
574
+ ref: Q
575
+ }, o.$attrs, {
622
576
  data: t.data,
623
577
  "row-key": t.rowKey,
624
578
  class: "smart_table"
625
- }), {
626
- default: A(() => [
627
- (h(!0), K(H, null, L(a(l), (p) => (h(), _(Ie, {
628
- key: p.key,
629
- col: p,
630
- permissions: t.permissions,
631
- pagination: t.pagination,
632
- onCellChange: i,
633
- onCellBlur: c,
634
- onCellEnter: d,
635
- onCellClick: g
636
- }, ge({ _: 2 }, [
637
- L(a(l), (E) => ({
638
- name: E.key,
639
- fn: A((N) => [
640
- ne(m.$slots, E.key, B({ ref_for: !0 }, N))
641
- ])
642
- }))
643
- ]), 1032, ["col", "permissions", "pagination"]))), 128))
579
+ }), ye({
580
+ default: V(() => [
581
+ (y(!0), A($, null, M(s.value, (u) => (y(), w(p, x({
582
+ key: "selection",
583
+ type: "selection"
584
+ }, { ref_for: !0 }, u.columnProps), null, 16))), 128)),
585
+ (y(!0), A($, null, M(d.value, (u) => (y(), w(p, x({
586
+ key: "index",
587
+ type: "index",
588
+ label: u.label || "#",
589
+ align: "center"
590
+ }, { ref_for: !0 }, u.columnProps), {
591
+ default: V(({ $index: C }) => [
592
+ X(P(k(C)), 1)
593
+ ]),
594
+ _: 1
595
+ }, 16, ["label"]))), 128)),
596
+ (y(!0), A($, null, M(I(), (u) => (y(), w(p, x({
597
+ key: u.key,
598
+ label: u.label || "操作",
599
+ align: "center"
600
+ }, { ref_for: !0 }, {
601
+ ...u.columnProps,
602
+ width: g(u)
603
+ }), {
604
+ default: V(({ row: C }) => [
605
+ (y(!0), A($, null, M(b(u, C), (T) => (y(), w(_, {
606
+ key: T.label,
607
+ type: T.type || "primary",
608
+ link: "",
609
+ onClick: (N) => T.action(C)
610
+ }, {
611
+ default: V(() => [
612
+ X(P(T.label), 1)
613
+ ]),
614
+ _: 2
615
+ }, 1032, ["type", "onClick"]))), 128))
616
+ ]),
617
+ _: 2
618
+ }, 1040, ["label"]))), 128)),
619
+ (y(!0), A($, null, M(h.value, (u) => (y(), w(p, x({
620
+ key: u.key,
621
+ label: u.label,
622
+ align: "center"
623
+ }, { ref_for: !0 }, u.columnProps || {}), {
624
+ default: V((C) => {
625
+ var T, N;
626
+ return [
627
+ u.render === "slot" ? Z(o.$slots, (u == null ? void 0 : u.slot) || u.key, x({
628
+ key: 0,
629
+ ref_for: !0
630
+ }, C)) : u.render && E.value[u.render] ? (y(), w(pe(E.value[u.render]), {
631
+ key: 1,
632
+ row: C.row,
633
+ col: u,
634
+ index: C.$index,
635
+ onCellChange: oe,
636
+ onCellBlur: ie,
637
+ onCellEnter: se,
638
+ onClick: ae
639
+ }, null, 40, ["row", "col", "index"])) : (y(), A("span", {
640
+ key: 2,
641
+ style: he(((T = u.renderProps) == null ? void 0 : T.style) || ""),
642
+ class: ge(((N = u.renderProps) == null ? void 0 : N.class) || ""),
643
+ title: ee(v)(C.row, u.key)
644
+ }, P(ee(v)(C.row, u.key)), 15, je))
645
+ ];
646
+ }),
647
+ _: 2
648
+ }, 1040, ["label"]))), 128))
644
649
  ]),
645
- _: 3
646
- }, 16, ["data", "row-key"])), [
647
- [y, t.loading]
650
+ _: 2
651
+ }, [
652
+ M(h.value, (u) => ({
653
+ name: u.key,
654
+ fn: V((C) => [
655
+ Z(o.$slots, u.key, be(ve(C)))
656
+ ])
657
+ }))
658
+ ]), 1040, ["data", "row-key"])), [
659
+ [ue, t.loading]
648
660
  ]);
649
661
  };
650
662
  }
651
- }), te = {
663
+ }), ne = {
652
664
  defaultPagination: {
653
665
  page: 1,
654
666
  size: 10,
@@ -657,9 +669,9 @@ const Ge = /* @__PURE__ */ O({
657
669
  defaultTableProps: {},
658
670
  defaultColumnProps: {}
659
671
  };
660
- class Pe {
672
+ class qe {
661
673
  constructor() {
662
- I(this, "config", { ...te });
674
+ W(this, "config", { ...ne });
663
675
  }
664
676
  /**
665
677
  * 获取所有配置
@@ -671,7 +683,7 @@ class Pe {
671
683
  * 设置配置
672
684
  */
673
685
  setConfig(e) {
674
- this.config = this.mergeConfig(this.config, e), e.renderers && J().registerMultiple(e.renderers);
686
+ this.config = this.mergeConfig(this.config, e), e.renderers && H().registerMultiple(e.renderers);
675
687
  }
676
688
  /**
677
689
  * 获取特定配置项
@@ -683,46 +695,46 @@ class Pe {
683
695
  * 重置为默认配置
684
696
  */
685
697
  reset() {
686
- this.config = { ...te };
698
+ this.config = { ...ne };
687
699
  }
688
700
  /**
689
701
  * 深度合并配置
690
702
  */
691
703
  mergeConfig(e, n) {
692
- const r = { ...e };
693
- for (const o in n)
694
- n[o] && typeof n[o] == "object" && !Array.isArray(n[o]) ? r[o] = this.mergeConfig(e[o] || {}, n[o]) : r[o] = n[o];
695
- return r;
704
+ const l = { ...e };
705
+ for (const i in n)
706
+ n[i] && typeof n[i] == "object" && !Array.isArray(n[i]) ? l[i] = this.mergeConfig(e[i] || {}, n[i]) : l[i] = n[i];
707
+ return l;
696
708
  }
697
709
  }
698
710
  let j = null;
699
- function re() {
700
- return j || (j = new Pe()), j;
711
+ function le() {
712
+ return j || (j = new qe()), j;
701
713
  }
702
- function Qe(t) {
703
- re().setConfig(t);
714
+ function Ze(t) {
715
+ le().setConfig(t);
704
716
  }
705
- function Xe() {
706
- return re().getConfig();
717
+ function et() {
718
+ return le().getConfig();
707
719
  }
708
- function Ze(t, e) {
720
+ function tt(t, e) {
709
721
  return {
710
722
  key: t,
711
723
  ...e
712
724
  };
713
725
  }
714
726
  export {
715
- Ge as SmartTable,
716
- le as builtInRenderers,
717
- S as createFunctionalRenderer,
718
- Ye as createRenderer,
719
- Ge as default,
720
- Ze as defineColumn,
721
- J as getRendererManager,
722
- Xe as getSmartTableConfig,
723
- Le as registerBuiltInRenderers,
724
- Qe as setSmartTableConfig,
725
- He as validateRendererProps,
726
- Y as wrapSFCComponent
727
+ Xe as SmartTable,
728
+ re as builtInRenderers,
729
+ B as createFunctionalRenderer,
730
+ Qe as createRenderer,
731
+ Xe as default,
732
+ tt as defineColumn,
733
+ H as getRendererManager,
734
+ et as getSmartTableConfig,
735
+ De as registerBuiltInRenderers,
736
+ Ze as setSmartTableConfig,
737
+ Ge as validateRendererProps,
738
+ U as wrapSFCComponent
727
739
  };
728
740
  //# sourceMappingURL=vue3-smart-table.es.js.map