vue3-smart-table 1.0.2 → 1.0.4

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