vue3-smart-table 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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, o]) => {
16
+ this.renderers.has(n) || this.renderers.set(n, o);
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 E(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, o) => n == null ? void 0 : n[o], t);
92
+ }
93
+ function G(t, e, n) {
94
+ if (!t || !e) return;
95
+ const o = e.split("."), r = o.pop(), l = o.reduce((i, c) => (i[c] || (i[c] = {}), i[c]), t);
96
+ l[r] = 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
- 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);
111
+ const o = () => {
112
+ var l;
113
+ return (l = e.onCellBlur) == null ? void 0 : l.call(e, e.row, e.col);
114
+ }, r = () => {
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
- onBlur: r,
30
- onKeyup: M(n, ["enter"])
124
+ onBlur: o,
125
+ onKeyup: U(r, ["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
- 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);
144
+ const o = () => {
145
+ var l;
146
+ return (l = e.onCellBlur) == null ? void 0 : l.call(e, e.row, e.col);
147
+ }, r = () => {
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
- onBlur: r,
63
- onKeyup: M(n, ["enter"])
157
+ onBlur: o,
158
+ onKeyup: U(r, ["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
- 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);
176
+ const o = () => {
177
+ var i;
178
+ return (i = e.onCellChange) == null ? void 0 : i.call(e, e.row, e.col);
179
+ }, r = () => {
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
- onChange: r,
98
- onBlur: n,
99
- onKeyup: M(s, ["enter"])
192
+ onChange: o,
193
+ onBlur: r,
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,378 @@ 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) => {
210
+ }), Be = Y(we), Ee = Y(_e), Se = Y(xe), Te = E((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: () => {
215
216
  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) => {
270
- 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 (o = t.onClick) == null ? void 0 : o.call(t, t.row, t.col);
297
218
  }
219
+ }, () => e.label || n);
220
+ }), Ve = E((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 = E((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 = E((t) => {
236
+ const e = v(t.row, t.col.key) ?? "", n = t.col.renderProps ?? {}, o = {
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"
298
246
  };
247
+ return f(
248
+ "div",
249
+ {
250
+ class: "st_copy_wrapper",
251
+ style: "width: 100%; position: relative; display: inline-block;"
252
+ },
253
+ [
254
+ f("span", {
255
+ class: "st_copy_text line-clamp-1",
256
+ style: "padding-right: 10px; display: block;"
257
+ }, e),
258
+ e && f("span", {
259
+ class: "st_copy_btn",
260
+ style: o,
261
+ title: n.copyTitle || "复制",
262
+ onClick: () => {
263
+ if (e)
264
+ try {
265
+ if (navigator.clipboard && navigator.clipboard.writeText)
266
+ navigator.clipboard.writeText(e).then(() => {
267
+ $.success(n.successText ?? "复制成功");
268
+ }).catch(() => {
269
+ $.error(n.errorText ?? "复制失败");
270
+ });
271
+ else {
272
+ const r = document.createElement("textarea");
273
+ r.value = e, r.style.position = "fixed", r.style.opacity = "0", document.body.appendChild(r), r.select();
274
+ const l = document.execCommand("copy");
275
+ document.body.removeChild(r), l ? $.success(n.successText ?? "复制成功") : $.error(n.errorText ?? "复制失败");
276
+ }
277
+ } catch {
278
+ $.error(n.errorText ?? "复制失败");
279
+ }
280
+ }
281
+ }, [f(ve, {
282
+ style: "width: 1em; height: 1em;"
283
+ })])
284
+ ].filter(Boolean)
285
+ );
286
+ }), Oe = E((t) => {
287
+ var i;
288
+ const e = v(t.row, t.col.key) ?? "", n = ((i = t.col) == null ? void 0 : i.renderProps) || {}, r = e ? Array.isArray(e) ? e.filter((c) => c && typeof c == "string") : [e] : [];
289
+ if (r.length === 0)
290
+ return n.placeholder || "";
291
+ const l = {
292
+ width: n.width || "80px",
293
+ height: n.height || "80px",
294
+ marginRight: r.length > 1 ? "4px" : "0",
295
+ ...n.style || {}
296
+ };
297
+ return r.length === 1 ? f(q, {
298
+ src: r[0],
299
+ previewSrcList: n.previewSrcList || r,
300
+ fit: n.fit || "contain",
301
+ style: l,
302
+ ...n
303
+ }) : f(
304
+ "div",
305
+ {
306
+ class: "st_img_wrapper",
307
+ style: "display: flex; align-items: center; position: relative"
308
+ },
309
+ [
310
+ f(q, {
311
+ src: r[0],
312
+ previewSrcList: n.previewSrcList || r,
313
+ fit: n.fit || "contain",
314
+ style: l,
315
+ ...n
316
+ }),
317
+ r.length > 1 && f("span", {
318
+ class: "st_img_total",
319
+ style: "position: absolute; top: 0; right: 0; ",
320
+ title: `${r.length}`
321
+ }, [f(be, { style: "width: 1em; height: 1em; " })])
322
+ ]
323
+ );
324
+ }), $e = E((t) => {
325
+ const e = v(t.row, t.col.key) ?? "", n = t.col.renderProps || {}, o = n.options ?? [], r = n.showValue ?? !1;
326
+ if (e == null || e === "") return "";
327
+ const l = Array.isArray(e) ? e.map(String) : [String(e)], i = o.filter((g) => l.includes(String(g.value))), c = l.filter((g) => !o.some((b) => String(b.value) === g)), d = i.map((g, b) => f(
328
+ he,
329
+ { key: g.value, type: g.listClass, class: g.cssClass, disableTransitions: !0 },
330
+ { default: () => g.label + " " }
331
+ ));
332
+ return r && c.length > 0 && d.push(f("span", {}, c.join(" "))), f("div", {}, d);
333
+ }), Fe = E((t) => {
334
+ var o;
335
+ const e = v(t.row, t.col.key) ?? "", n = ((o = t.col.renderProps) == null ? void 0 : o.options) ?? {};
336
+ return e != null ? n[e] ?? "" : "";
337
+ });
338
+ function Re(t) {
339
+ return typeof t.formatter == "function";
299
340
  }
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)
341
+ const ze = E((t) => {
342
+ var r;
343
+ const { col: e, row: n } = t, o = v(t.row, t.col.key) ?? "";
344
+ return Re(e) ? (r = e.formatter) == null ? void 0 : r.call(e, o, n) : o ?? "";
345
+ }), Ke = E((t) => {
346
+ const e = v(t.row, t.col.key) ?? "", n = t.col.renderProps || {};
347
+ return e ? /^https?:\/\//.test(e) ? f(q, {
348
+ src: e,
349
+ previewSrcList: [e],
350
+ fit: "contain",
351
+ style: "width:40px;height:40px",
352
+ ...n
353
+ }) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ? f("div", {
354
+ innerHTML: e,
355
+ style: `width:40px;height:40px;display:inline-block;${n.style || ""}`,
356
+ ...n
357
+ }) : f("i", {
358
+ class: e,
359
+ style: `font-size:20px;${n.style || ""}`,
360
+ ...n
361
+ }) : "";
362
+ }), le = {
363
+ input: Be,
364
+ "input-number": Ee,
365
+ select: Se,
366
+ button: Te,
367
+ link: Ve,
368
+ html: Ae,
369
+ copy: Me,
370
+ img: Oe,
371
+ dict: $e,
372
+ map: Fe,
373
+ formatter: ze,
374
+ icon: Ke
375
+ };
376
+ function Le(t) {
377
+ t.registerMultiple(le);
378
+ }
379
+ function Ye() {
380
+ return le;
381
+ }
382
+ function Ne(t, e = 10, n = []) {
383
+ const r = "*:*:*", l = (s) => {
384
+ if (!s) return !0;
385
+ const y = Array.isArray(s) ? s : [s];
386
+ return n.some(
387
+ (p) => p === r || y.includes(p)
306
388
  );
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),
389
+ }, i = F(() => t.some((s) => l(s.permission))), c = F(() => t.filter((y) => l(y.permission)).slice(0, e).reduce(
390
+ (y, p) => y + (p.width ?? 60),
309
391
  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),
392
+ )), d = (s, y) => l(s.permission) && (s.visible ? s.visible(y) : !0), g = (s) => t.filter((p) => d(p, s)).slice(0, e).reduce(
393
+ (p, S) => p + (S.width ?? 60),
312
394
  0
313
395
  );
314
396
  return {
315
- hasAnyButton: o,
316
- optWidth: a,
317
- hasAnyVisibleButton: (i) => i != null && i.length ? i.some(
318
- (m) => t.some((p) => y(p, m))
397
+ hasAnyButton: i,
398
+ optWidth: c,
399
+ hasAnyVisibleButton: (s) => s != null && s.length ? s.some(
400
+ (y) => t.some((p) => d(p, y))
319
401
  ) : !1,
320
- getMaxOptWidth: (i) => i != null && i.length ? i.reduce(
321
- (m, p) => Math.max(m, u(p)),
402
+ getMaxOptWidth: (s) => s != null && s.length ? s.reduce(
403
+ (y, p) => Math.max(y, g(p)),
322
404
  0
323
- ) : a.value,
324
- getVisibleButtons: (i) => t.filter((m) => y(m, i)).slice(0, e)
405
+ ) : c.value,
406
+ getVisibleButtons: (s) => t.filter((y) => d(y, s)).slice(0, e)
325
407
  };
326
408
  }
327
- const ie = ["title"], ce = /* @__PURE__ */ E({
409
+ const De = ["title"], Ie = /* @__PURE__ */ O({
328
410
  __name: "index",
329
411
  props: {
330
412
  col: { type: Object, required: !0 },
331
- permissions: { type: Array, default: () => [] }
413
+ permissions: { type: Array, default: () => [] },
414
+ pagination: { type: Object, default: () => ({}) }
332
415
  },
333
416
  emits: ["cellBlur", "cellEnter", "cellChange", "cellClick"],
334
417
  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);
418
+ const n = t, o = e, r = (u) => {
419
+ var T, w;
420
+ const C = (T = n.pagination) == null ? void 0 : T.page, x = (w = n.pagination) == null ? void 0 : w.size;
421
+ return C && x ? (C - 1) * x + u + 1 : u + 1;
422
+ }, { col: l } = ae(n), i = (u, C) => o("cellChange", u, C), c = (u, C) => o("cellBlur", u, C), d = (u, C) => o("cellEnter", u, C), g = (u, C) => o("cellClick", u, C);
423
+ Le(J());
424
+ const b = F(() => {
425
+ const u = J(), C = {};
426
+ return u.names().forEach((x) => {
427
+ const T = u.get(x);
428
+ T && (C[x] = T);
429
+ }), C;
430
+ }), {
431
+ hasAnyButton: m,
432
+ hasAnyVisibleButton: k,
433
+ optWidth: s,
434
+ getMaxOptWidth: y,
435
+ getVisibleButtons: p
436
+ } = Ne(
437
+ l.value.buttons || [],
438
+ l.value.maxbtn ?? 10,
439
+ n.permissions || []
440
+ ), S = 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);
441
+ function oe(u) {
442
+ return !(u.type === "selection" || u.type === "index" || u.type === "operation" && !S.value || u.visible === !1);
348
443
  }
349
- return (v, k) => {
350
- const F = x("el-table-column"), J = x("el-button");
351
- return c(n).type === "selection" ? (h(), b(F, _({
444
+ return (u, C) => {
445
+ const x = M("el-table-column"), T = M("el-button");
446
+ return a(l).type === "selection" ? (h(), _(x, B({
352
447
  key: 0,
353
448
  type: "selection"
354
- }, c(n).columnProps), null, 16)) : c(n).type === "index" ? (h(), b(F, _({
449
+ }, a(l).columnProps), null, 16)) : a(l).type === "index" ? (h(), _(x, B({
355
450
  key: 1,
356
451
  type: "index",
357
- label: c(n).label || "#",
452
+ label: a(l).label || "#",
358
453
  align: "center"
359
- }, c(n).columnProps), null, 16, ["label"])) : c(n).type === "operation" && p.value ? (h(), b(F, _({
454
+ }, a(l).columnProps), {
455
+ default: A(({ $index: w }) => [
456
+ Z(W(r(w)), 1)
457
+ ]),
458
+ _: 1
459
+ }, 16, ["label"])) : a(l).type === "operation" && S.value ? (h(), _(x, B({
360
460
  key: 2,
361
- label: c(n).label || "操作",
461
+ label: a(l).label || "操作",
362
462
  align: "center"
363
463
  }, {
364
- ...c(n).columnProps,
365
- width: $.value
464
+ ...a(l).columnProps,
465
+ width: N.value
366
466
  }), {
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",
467
+ default: A(({ row: w }) => [
468
+ (h(!0), K(H, null, L(a(p)(w), (V) => (h(), _(T, {
469
+ key: V.label,
470
+ type: V.type || "primary",
371
471
  link: "",
372
- onClick: (I) => w.action(B)
472
+ onClick: (D) => V.action(w)
373
473
  }, {
374
- default: P(() => [
375
- H(D(w.label), 1)
474
+ default: A(() => [
475
+ Z(W(V.label), 1)
376
476
  ]),
377
477
  _: 2
378
478
  }, 1032, ["type", "onClick"]))), 128))
379
479
  ]),
380
480
  _: 1
381
- }, 16, ["label"])) : R(c(n)) ? (h(), b(F, _({
481
+ }, 16, ["label"])) : oe(a(l)) ? (h(), _(x, B({
382
482
  key: 3,
383
- prop: c(n).key,
384
- label: c(n).label,
483
+ label: a(l).label,
385
484
  align: "center"
386
- }, c(n).columnProps || {}), {
387
- default: P(({ row: B }) => {
388
- var w, I;
485
+ }, a(l).columnProps || {}), {
486
+ default: A((w) => {
487
+ var V, D, Q, X;
389
488
  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", {
489
+ 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
490
  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))
491
+ row: w.row,
492
+ col: a(l),
493
+ onCellChange: i,
494
+ onCellBlur: c,
495
+ onCellEnter: d,
496
+ onClick: g
497
+ }, null, 40, ["row", "col"])) : (h(), K("span", {
498
+ key: 2,
499
+ style: fe(((Q = a(l).renderProps) == null ? void 0 : Q.style) || ""),
500
+ class: me(((X = a(l).renderProps) == null ? void 0 : X.class) || ""),
501
+ title: a(v)(w.row, a(l).key)
502
+ }, W(a(v)(w.row, a(l).key)), 15, De))
404
503
  ];
405
504
  }),
406
- _: 1
407
- }, 16, ["prop", "label"])) : j("", !0);
505
+ _: 3
506
+ }, 16, ["label"])) : ce("", !0);
408
507
  };
409
508
  }
410
- }), ae = "table_columns_";
411
- function ue(t, e) {
412
- return `${ae}${t}_${e}`;
413
- }
414
- function N(t, e) {
509
+ });
510
+ function ee(t, e) {
415
511
  if (!(e != null && e.length)) return t;
416
- const l = new Map(
417
- e.map((r) => [r.key, r])
512
+ const n = new Map(
513
+ e.map((o) => [o.key, o])
418
514
  );
419
- return t.map((r) => {
420
- const n = l.get(r.key);
421
- return n ? {
422
- ...r,
423
- visible: typeof n.visible == "boolean" ? n.visible : r.visible
424
- } : r;
515
+ return t.map((o) => {
516
+ const r = n.get(o.key);
517
+ return r ? {
518
+ ...o,
519
+ visible: typeof r.visible == "boolean" ? r.visible : o.visible
520
+ } : o;
425
521
  });
426
522
  }
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(
523
+ function We(t, e) {
524
+ const { cacheKey: n, storage: o = localStorage } = e || {}, r = n ? o.getItem(n) : null, l = R(
525
+ ee(
434
526
  t,
435
- a ? JSON.parse(a) : []
527
+ r ? JSON.parse(r) : []
436
528
  )
437
529
  );
438
- return A(
439
- y,
440
- (u) => {
441
- if (!o) return;
442
- const g = u.map((d) => ({
530
+ return z(
531
+ l,
532
+ (i) => {
533
+ if (!n) return;
534
+ const c = i.map((d) => ({
443
535
  key: d.key,
444
536
  visible: d.visible,
445
537
  columnOpts: d.columnOpts
446
538
  }));
447
- n.setItem(
448
- o,
449
- JSON.stringify(g)
539
+ o.setItem(
540
+ n,
541
+ JSON.stringify(c)
450
542
  );
451
543
  },
452
544
  { deep: !0 }
453
545
  ), {
454
546
  /** 当前列配置(响应式) */
455
- columns: y,
547
+ columns: l,
456
548
  /**
457
549
  * 主动设置列配置
458
550
  * 常用于:列设置弹窗 / 拖拽排序完成
459
551
  */
460
- setColumns(u) {
461
- y.value = N(
552
+ setColumns(i) {
553
+ l.value = ee(
462
554
  t,
463
- u
464
- ), o && n.setItem(
465
- o,
466
- JSON.stringify(u)
555
+ i
556
+ ), n && o.setItem(
557
+ n,
558
+ JSON.stringify(i)
467
559
  );
468
560
  },
469
561
  /**
470
562
  * 重置为默认列配置
471
563
  */
472
564
  resetColumns() {
473
- y.value = t, o && n.removeItem(o);
565
+ l.value = t, n && o.removeItem(n);
474
566
  }
475
567
  };
476
568
  }
477
- const ye = /* @__PURE__ */ E({
569
+ const Ge = /* @__PURE__ */ O({
478
570
  __name: "index",
479
571
  props: {
480
572
  data: { type: Array, default: () => [] },
481
573
  columns: { type: Array, default: () => [] },
482
- // v-model:columns
483
- pageKey: String,
484
574
  rowKey: { type: String, default: "id" },
485
575
  loading: { type: Boolean, default: !1 },
486
576
  permissions: {
487
577
  type: Array,
488
578
  default: () => []
489
579
  },
490
- userId: {
491
- /** 当前用户标识(可选,用于列缓存) */
492
- type: [String, Number],
493
- default: ""
494
- }
580
+ cacheKey: String,
581
+ pagination: { type: Object, default: () => ({}) }
495
582
  },
496
583
  emits: [
497
584
  "update:columns",
@@ -500,58 +587,134 @@ const ye = /* @__PURE__ */ E({
500
587
  "cellEnter",
501
588
  "cell-click"
502
589
  ],
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 ?? ""
590
+ setup(t, { expose: e, emit: n }) {
591
+ const o = t, r = n, { columns: l } = We(o.columns, {
592
+ cacheKey: o.cacheKey ?? ""
507
593
  });
508
- A(
509
- s,
510
- (d) => n("update:columns", d),
594
+ z(
595
+ l,
596
+ (m) => r("update:columns", m),
511
597
  { deep: !0, immediate: !0 }
512
598
  );
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();
599
+ const i = (m, k) => r("cellChange", m, k), c = (m, k) => {
600
+ r("cellBlur", m, k);
601
+ }, d = (m, k) => {
602
+ console.log("enter"), r("cellEnter", m, k);
603
+ }, g = (m, k) => {
604
+ k && r("cell-click", m, k);
605
+ }, b = R();
520
606
  return e({
521
- tableRef: g
522
- }), (d, C) => {
523
- const i = x("el-table"), m = G("loading");
524
- return Q((h(), b(i, _({
607
+ tableRef: b
608
+ }), (m, k) => {
609
+ const s = M("el-table"), y = ye("loading");
610
+ return pe((h(), _(s, B({
525
611
  ref_key: "tableRef",
526
- ref: g
527
- }, d.$attrs, {
612
+ ref: b
613
+ }, m.$attrs, {
528
614
  data: t.data,
529
615
  "row-key": t.rowKey,
530
- class: "smart-table"
616
+ class: "smart_table"
531
617
  }), {
532
- default: P(() => [
533
- (h(!0), O(T, null, z(c(s), (p) => (h(), b(ce, {
618
+ default: A(() => [
619
+ (h(!0), K(H, null, L(a(l), (p) => (h(), _(Ie, {
534
620
  key: p.key,
535
621
  col: p,
536
622
  permissions: t.permissions,
537
- onCellChange: o,
538
- onCellBlur: a,
539
- onCellEnter: y,
540
- onCellClick: u
541
- }, null, 8, ["col", "permissions"]))), 128))
623
+ pagination: t.pagination,
624
+ onCellChange: i,
625
+ onCellBlur: c,
626
+ onCellEnter: d,
627
+ onCellClick: g
628
+ }, ge({ _: 2 }, [
629
+ L(a(l), (S) => ({
630
+ name: S.key,
631
+ fn: A((N) => [
632
+ ne(m.$slots, S.key, B({ ref_for: !0 }, N))
633
+ ])
634
+ }))
635
+ ]), 1032, ["col", "permissions", "pagination"]))), 128))
542
636
  ]),
543
- _: 1
637
+ _: 3
544
638
  }, 16, ["data", "row-key"])), [
545
- [m, t.loading]
639
+ [y, t.loading]
546
640
  ]);
547
641
  };
548
642
  }
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"]]);
643
+ }), te = {
644
+ defaultPagination: {
645
+ page: 1,
646
+ size: 10,
647
+ total: 0
648
+ },
649
+ defaultTableProps: {},
650
+ defaultColumnProps: {}
651
+ };
652
+ class Pe {
653
+ constructor() {
654
+ I(this, "config", { ...te });
655
+ }
656
+ /**
657
+ * 获取所有配置
658
+ */
659
+ getConfig() {
660
+ return { ...this.config };
661
+ }
662
+ /**
663
+ * 设置配置
664
+ */
665
+ setConfig(e) {
666
+ this.config = this.mergeConfig(this.config, e), e.renderers && J().registerMultiple(e.renderers);
667
+ }
668
+ /**
669
+ * 获取特定配置项
670
+ */
671
+ get(e) {
672
+ return this.config[e];
673
+ }
674
+ /**
675
+ * 重置为默认配置
676
+ */
677
+ reset() {
678
+ this.config = { ...te };
679
+ }
680
+ /**
681
+ * 深度合并配置
682
+ */
683
+ mergeConfig(e, n) {
684
+ const o = { ...e };
685
+ for (const r in n)
686
+ n[r] && typeof n[r] == "object" && !Array.isArray(n[r]) ? o[r] = this.mergeConfig(e[r] || {}, n[r]) : o[r] = n[r];
687
+ return o;
688
+ }
689
+ }
690
+ let j = null;
691
+ function re() {
692
+ return j || (j = new Pe()), j;
693
+ }
694
+ function Qe(t) {
695
+ re().setConfig(t);
696
+ }
697
+ function Xe() {
698
+ return re().getConfig();
699
+ }
700
+ function Ze(t, e) {
701
+ return {
702
+ key: t,
703
+ ...e
704
+ };
705
+ }
555
706
  export {
556
- he as SmartTable
707
+ Ge as SmartTable,
708
+ le as builtInRenderers,
709
+ E as createFunctionalRenderer,
710
+ Ye as createRenderer,
711
+ Ge as default,
712
+ Ze as defineColumn,
713
+ J as getRendererManager,
714
+ Xe as getSmartTableConfig,
715
+ Le as registerBuiltInRenderers,
716
+ Qe as setSmartTableConfig,
717
+ He as validateRendererProps,
718
+ Y as wrapSFCComponent
557
719
  };
720
+ //# sourceMappingURL=vue3-smart-table.es.js.map