vue3-smart-table 0.0.4 → 1.0.0

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