@done-coding/admin-core 0.1.1-alpha.2 → 0.1.1-alpha.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.
Files changed (36) hide show
  1. package/es/components/form/FormDatePicker.vue.mjs +7 -0
  2. package/es/components/form/FormDatePicker.vue2.mjs +50 -0
  3. package/es/components/form/index.mjs +19 -19
  4. package/es/components/form/utils.mjs +82 -61
  5. package/es/components/misc/ActionButton.vue.mjs +52 -0
  6. package/es/components/misc/ActionButton.vue2.mjs +4 -0
  7. package/es/components/misc/ActionButtonDanger.vue.mjs +32 -0
  8. package/es/components/misc/ActionButtonDanger.vue2.mjs +4 -0
  9. package/es/components/misc/ActionButtonWarn.vue.mjs +32 -0
  10. package/es/components/misc/ActionButtonWarn.vue2.mjs +4 -0
  11. package/es/components/misc/index.mjs +21 -9
  12. package/es/components/table/TableMain.vue.mjs +1 -1
  13. package/es/components/table/TableMain.vue2.mjs +148 -133
  14. package/es/components/table/TableToolbar.vue.mjs +3 -3
  15. package/es/components/table/TableToolbar.vue2.mjs +154 -70
  16. package/es/components/table/ToolbarButtons.vue.mjs +49 -0
  17. package/es/components/table/ToolbarButtons.vue2.mjs +4 -0
  18. package/es/helpers/list-helper.mjs +29 -33
  19. package/es/index.mjs +104 -92
  20. package/es/style.css +1 -1
  21. package/es/utils/export.mjs +23 -0
  22. package/package.json +2 -2
  23. package/types/components/form/{FormDateTimeRange.vue.d.ts → FormDatePicker.vue.d.ts} +2 -2
  24. package/types/components/form/index.d.ts +2 -2
  25. package/types/components/form/utils.d.ts +3 -1
  26. package/types/components/misc/ActionButton.vue.d.ts +24 -0
  27. package/types/components/misc/ActionButtonDanger.vue.d.ts +19 -0
  28. package/types/components/misc/ActionButtonWarn.vue.d.ts +19 -0
  29. package/types/components/misc/index.d.ts +4 -1
  30. package/types/components/table/TableToolbar.vue.d.ts +66 -9
  31. package/types/components/table/ToolbarButtons.vue.d.ts +19 -0
  32. package/types/components/table/types.d.ts +64 -17
  33. package/types/utils/export.d.ts +30 -0
  34. package/types/utils/index.d.ts +1 -0
  35. package/es/components/form/FormDateTimeRange.vue.mjs +0 -46
  36. package/es/components/form/FormDateTimeRange.vue2.mjs +0 -4
@@ -1,75 +1,149 @@
1
- import { ElDropdown as k, ElButton as B, ElIcon as D, ElDropdownMenu as I, ElDropdownItem as V } from "element-plus/es";
1
+ import { ElDropdown as V, ElButton as $, ElIcon as F, ElDropdownMenu as S, ElDropdownItem as z } from "element-plus/es";
2
2
  import "element-plus/es/components/base/style/css";
3
3
  import "element-plus/es/components/dropdown/style/css";
4
4
  import "element-plus/es/components/dropdown-menu/style/css";
5
5
  import "element-plus/es/components/dropdown-item/style/css";
6
6
  import "element-plus/es/components/button/style/css";
7
7
  import "element-plus/es/components/icon/style/css";
8
- import { defineComponent as C, useModel as M, computed as f, ref as E, watch as N, openBlock as u, createElementBlock as z, createElementVNode as g, createBlock as p, withCtx as o, createVNode as l, createTextVNode as d, unref as w, createCommentVNode as c, normalizeClass as T, mergeModels as U } from "vue";
9
- import { ArrowDown as $, Refresh as j } from "@element-plus/icons-vue";
10
- import q from "../misc/AutoRefresh.vue.mjs";
11
- const G = { class: "table-toolbar" }, H = { class: "table-toolbar-left" }, J = { class: "table-toolbar-right" }, ee = /* @__PURE__ */ C({
8
+ import { defineComponent as L, useModel as P, computed as v, ref as y, watch as N, withDirectives as U, openBlock as c, createElementBlock as X, createElementVNode as R, createBlock as p, withCtx as n, createVNode as r, createTextVNode as h, unref as A, createCommentVNode as g, normalizeClass as q, vShow as O, mergeModels as j } from "vue";
9
+ import { ElMessageBox as G, ElMessage as H } from "element-plus";
10
+ import { ArrowDown as J, Refresh as K } from "@element-plus/icons-vue";
11
+ import Q from "../misc/AutoRefresh.vue.mjs";
12
+ import k from "./ToolbarButtons.vue.mjs";
13
+ import { countAll as W, fetchListAll as M } from "../../helpers/list-helper.mjs";
14
+ import { EXPORT_MAX_LIMIT as f, exportCSV as Y } from "../../utils/export.mjs";
15
+ const Z = { class: "table-toolbar" }, _ = { class: "table-toolbar-left" }, ee = { class: "table-toolbar-right" }, pe = /* @__PURE__ */ L({
12
16
  __name: "TableToolbar",
13
- props: /* @__PURE__ */ U({
14
- leftFeatures: {},
15
- rightFeatures: {},
17
+ props: /* @__PURE__ */ j({
18
+ showRefresh: { type: Boolean, default: !0 },
19
+ showAutoRefresh: { type: Boolean, default: !0 },
16
20
  refreshInterval: { default: 30 },
21
+ exportByFe: { type: Boolean, default: !0 },
17
22
  exportFn: {},
23
+ exportColumns: {},
24
+ leftExtraButtons: {},
25
+ rightExtraButtons: {},
18
26
  tableExpose: {},
19
- loading: { type: Boolean }
27
+ loading: { type: Boolean },
28
+ exportContext: {},
29
+ currentPage: {},
30
+ pageSize: {}
20
31
  }, {
21
32
  isAutoRefresh: { type: Boolean },
22
33
  isAutoRefreshModifiers: {}
23
34
  }),
24
35
  emits: ["update:isAutoRefresh"],
25
- setup(n) {
26
- const t = n, v = M(n, "isAutoRefresh"), x = f(
27
- () => t.leftFeatures === void 0 || t.leftFeatures.includes("export")
28
- ), F = f(
29
- () => t.rightFeatures === void 0 || t.rightFeatures.includes("refresh")
30
- ), _ = f(
31
- () => t.rightFeatures === void 0 || t.rightFeatures.includes("autoRefresh")
32
- ), i = E(30);
36
+ setup(l) {
37
+ const t = l, w = P(l, "isAutoRefresh"), B = v(() => {
38
+ var o;
39
+ return !!((o = t.exportColumns) != null && o.length);
40
+ }), C = v(() => ({
41
+ tableExpose: t.tableExpose,
42
+ loading: t.loading,
43
+ exportContext: t.exportContext,
44
+ selectedList: t.exportContext.selectedList,
45
+ pagination: {
46
+ currentPage: t.currentPage,
47
+ pageSize: t.pageSize,
48
+ total: t.exportContext.total
49
+ }
50
+ })), D = v(
51
+ () => {
52
+ var o, e;
53
+ return [
54
+ B.value,
55
+ t.showAutoRefresh,
56
+ t.showRefresh,
57
+ (o = t.leftExtraButtons) == null ? void 0 : o.length,
58
+ (e = t.rightExtraButtons) == null ? void 0 : e.length
59
+ ].filter(Boolean).length;
60
+ }
61
+ ), E = y(30);
33
62
  N(
34
63
  () => t.refreshInterval,
35
- (a) => {
36
- i.value = a;
64
+ (o) => {
65
+ E.value = o;
37
66
  },
38
67
  { immediate: !0 }
39
68
  );
40
- const r = E(!1), R = (a) => {
41
- r.value || !t.exportFn || (r.value = !0, t.exportFn(a).catch(() => {
69
+ const x = y(!1), I = async (o) => {
70
+ const { selectedList: e, currentPageList: s, api: d, query: i } = t.exportContext, b = t.exportColumns;
71
+ let u;
72
+ switch (o) {
73
+ case "selected":
74
+ u = e;
75
+ break;
76
+ case "current":
77
+ u = s;
78
+ break;
79
+ case "all":
80
+ try {
81
+ const a = await W(d, i);
82
+ if (a > f) {
83
+ try {
84
+ await G.confirm(
85
+ `数据量超过 ${f} 条(共 ${a} 条),是否只导出前 ${f} 条?`,
86
+ "提示",
87
+ {
88
+ confirmButtonText: "导出",
89
+ cancelButtonText: "取消",
90
+ type: "warning"
91
+ }
92
+ );
93
+ } catch {
94
+ return;
95
+ }
96
+ u = await M(d, i, { limit: f });
97
+ } else
98
+ u = await M(d, i, { limit: f });
99
+ } catch (a) {
100
+ H.error(`导出失败:${(a == null ? void 0 : a.message) || (a == null ? void 0 : a.toString())}`);
101
+ return;
102
+ }
103
+ break;
104
+ }
105
+ const m = `${document.title}-${Date.now()}`;
106
+ Y({ columns: b, list: u, filename: m });
107
+ }, T = (o) => {
108
+ var s;
109
+ if (x.value) return;
110
+ x.value = !0;
111
+ const e = t.exportByFe ? I(o) : (s = t.exportFn) == null ? void 0 : s.call(t, o);
112
+ Promise.resolve(e).catch(() => {
42
113
  }).finally(() => {
43
- r.value = !1;
44
- }));
114
+ x.value = !1;
115
+ });
45
116
  };
46
- return (a, e) => {
47
- const h = D, b = B, m = V, y = I, A = k;
48
- return u(), z("div", G, [
49
- g("div", H, [
50
- x.value ? (u(), p(A, {
117
+ return (o, e) => {
118
+ const s = F, d = $, i = z, b = S, u = V;
119
+ return U((c(), X("div", Z, [
120
+ R("div", _, [
121
+ B.value ? (c(), p(u, {
51
122
  key: 0,
52
- disabled: r.value,
53
- onCommand: R
123
+ disabled: !l.exportContext.total,
124
+ onCommand: T
54
125
  }, {
55
- dropdown: o(() => [
56
- l(y, null, {
57
- default: o(() => [
58
- l(m, { command: "selected" }, {
59
- default: o(() => [...e[4] || (e[4] = [
60
- d("导出选择", -1)
126
+ dropdown: n(() => [
127
+ r(b, null, {
128
+ default: n(() => [
129
+ l.exportContext.hasSelection ? (c(), p(i, {
130
+ key: 0,
131
+ command: "selected"
132
+ }, {
133
+ default: n(() => [...e[4] || (e[4] = [
134
+ h(" 导出选择 ", -1)
61
135
  ])]),
62
136
  _: 1
63
- }),
64
- l(m, { command: "current" }, {
65
- default: o(() => [...e[5] || (e[5] = [
66
- d("导出本页", -1)
137
+ })) : g("", !0),
138
+ r(i, { command: "current" }, {
139
+ default: n(() => [...e[5] || (e[5] = [
140
+ h("导出本页", -1)
67
141
  ])]),
68
142
  _: 1
69
143
  }),
70
- l(m, { command: "all" }, {
71
- default: o(() => [...e[6] || (e[6] = [
72
- d("导出全部", -1)
144
+ r(i, { command: "all" }, {
145
+ default: n(() => [...e[6] || (e[6] = [
146
+ h("导出全部", -1)
73
147
  ])]),
74
148
  _: 1
75
149
  })
@@ -77,17 +151,17 @@ const G = { class: "table-toolbar" }, H = { class: "table-toolbar-left" }, J = {
77
151
  _: 1
78
152
  })
79
153
  ]),
80
- default: o(() => [
81
- l(b, {
154
+ default: n(() => [
155
+ r(d, {
82
156
  size: "small",
83
157
  type: "primary",
84
- loading: r.value
158
+ loading: x.value
85
159
  }, {
86
- default: o(() => [
87
- e[3] || (e[3] = d(" 导出 ", -1)),
88
- l(h, null, {
89
- default: o(() => [
90
- l(w($))
160
+ default: n(() => [
161
+ e[3] || (e[3] = h(" 导出 ", -1)),
162
+ r(s, null, {
163
+ default: n(() => [
164
+ r(A(J))
91
165
  ]),
92
166
  _: 1
93
167
  })
@@ -96,41 +170,51 @@ const G = { class: "table-toolbar" }, H = { class: "table-toolbar-left" }, J = {
96
170
  }, 8, ["loading"])
97
171
  ]),
98
172
  _: 1
99
- }, 8, ["disabled"])) : c("", !0)
173
+ }, 8, ["disabled"])) : g("", !0),
174
+ r(k, {
175
+ buttons: l.leftExtraButtons,
176
+ ctx: C.value
177
+ }, null, 8, ["buttons", "ctx"])
100
178
  ]),
101
- g("div", J, [
102
- _.value ? (u(), p(q, {
179
+ R("div", ee, [
180
+ r(k, {
181
+ buttons: l.rightExtraButtons,
182
+ ctx: C.value
183
+ }, null, 8, ["buttons", "ctx"]),
184
+ l.showAutoRefresh ? (c(), p(Q, {
103
185
  key: 0,
104
- modelValue: v.value,
105
- "onUpdate:modelValue": e[0] || (e[0] = (s) => v.value = s),
106
- interval: i.value,
107
- "onUpdate:interval": e[1] || (e[1] = (s) => i.value = s),
108
- refreshFn: t.tableExpose.refresh,
109
- enabled: !n.loading
110
- }, null, 8, ["modelValue", "interval", "refreshFn", "enabled"])) : c("", !0),
111
- F.value ? (u(), p(b, {
186
+ modelValue: w.value,
187
+ "onUpdate:modelValue": e[0] || (e[0] = (m) => w.value = m),
188
+ interval: E.value,
189
+ "onUpdate:interval": e[1] || (e[1] = (m) => E.value = m),
190
+ refreshFn: l.tableExpose.refresh,
191
+ enabled: !l.loading
192
+ }, null, 8, ["modelValue", "interval", "refreshFn", "enabled"])) : g("", !0),
193
+ l.showRefresh ? (c(), p(d, {
112
194
  key: 1,
113
195
  size: "small",
114
196
  circle: "",
115
- onClick: e[2] || (e[2] = (s) => t.tableExpose.refresh())
197
+ onClick: e[2] || (e[2] = (m) => l.tableExpose.refresh())
116
198
  }, {
117
- default: o(() => [
118
- l(h, {
119
- class: T({ "table-toolbar-icon--rotating": n.loading })
199
+ default: n(() => [
200
+ r(s, {
201
+ class: q({ "table-toolbar-icon--rotating": l.loading })
120
202
  }, {
121
- default: o(() => [
122
- l(w(j))
203
+ default: n(() => [
204
+ r(A(K))
123
205
  ]),
124
206
  _: 1
125
207
  }, 8, ["class"])
126
208
  ]),
127
209
  _: 1
128
- })) : c("", !0)
210
+ })) : g("", !0)
129
211
  ])
212
+ ], 512)), [
213
+ [O, D.value]
130
214
  ]);
131
215
  };
132
216
  }
133
217
  });
134
218
  export {
135
- ee as default
219
+ pe as default
136
220
  };
@@ -0,0 +1,49 @@
1
+ import { ElButton as p } from "element-plus/es";
2
+ import "element-plus/es/components/base/style/css";
3
+ import "element-plus/es/components/button/style/css";
4
+ import { defineComponent as y, openBlock as t, createElementBlock as r, Fragment as n, renderList as d, createBlock as c, resolveDynamicComponent as u, unref as x, mergeProps as l, withCtx as m, createTextVNode as i, toDisplayString as f } from "vue";
5
+ import B from "../misc/ActionButton.vue.mjs";
6
+ const A = /* @__PURE__ */ y({
7
+ __name: "ToolbarButtons",
8
+ props: {
9
+ buttons: {},
10
+ ctx: {}
11
+ },
12
+ setup(o) {
13
+ const s = B;
14
+ return (_, R) => {
15
+ const k = p;
16
+ return t(!0), r(n, null, d(o.buttons, (e) => {
17
+ var a;
18
+ return t(), r(n, {
19
+ key: e.key
20
+ }, [
21
+ e.actionButtonProps ? (t(), c(u(x(s)), l({
22
+ key: 0,
23
+ ref_for: !0
24
+ }, e.actionButtonProps(o.ctx)), {
25
+ default: m(() => [
26
+ e.btnRender ? (t(), c(u(() => e.btnRender(o.ctx)), { key: 0 })) : (t(), r(n, { key: 1 }, [
27
+ i(f(e.label), 1)
28
+ ], 64))
29
+ ]),
30
+ _: 2
31
+ }, 1040)) : (t(), c(k, l({
32
+ key: 1,
33
+ ref_for: !0
34
+ }, (a = e.props) == null ? void 0 : a.call(e, o.ctx)), {
35
+ default: m(() => [
36
+ e.btnRender ? (t(), c(u(() => e.btnRender(o.ctx)), { key: 0 })) : (t(), r(n, { key: 1 }, [
37
+ i(f(e.label), 1)
38
+ ], 64))
39
+ ]),
40
+ _: 2
41
+ }, 1040))
42
+ ], 64);
43
+ }), 128);
44
+ };
45
+ }
46
+ });
47
+ export {
48
+ A as default
49
+ };
@@ -0,0 +1,4 @@
1
+ import f from "./ToolbarButtons.vue.mjs";
2
+ export {
3
+ f as default
4
+ };
@@ -1,61 +1,57 @@
1
- async function A(a, c, e) {
2
- var s;
3
- const i = (e == null ? void 0 : e.pageSize) ?? 200, r = (e == null ? void 0 : e.limit) ?? 1e4;
1
+ async function A(r, n, e) {
2
+ var o;
3
+ const i = (e == null ? void 0 : e.pageSize) ?? 200, a = (e == null ? void 0 : e.limit) ?? 1e4;
4
4
  if (i < 1 || i > 1e3)
5
5
  throw new Error(
6
6
  `fetchListAll: pageSize 必须在 [1, 1000] 范围内(实际 ${i})`
7
7
  );
8
8
  const t = [];
9
- let n = 1;
9
+ let c = 1;
10
10
  for (; ; ) {
11
- const o = {
12
- ...c,
13
- page: { page: n, pageSize: i }
14
- }, l = await a(o), p = l.items, g = ((s = l.page) == null ? void 0 : s.totalRecord) ?? 0;
15
- if (n === 1 && g > r)
16
- throw new Error(
17
- `fetchListAll 超出上限 ${r}(实际 totalRecord=${g}),请手动分页或质疑工具适用性`
18
- );
19
- if (t.push(...p), p.length < i || t.length >= g) break;
20
- n += 1;
11
+ const s = {
12
+ ...n,
13
+ page: { page: c, pageSize: i }
14
+ }, l = await r(s), g = l.items, p = ((o = l.page) == null ? void 0 : o.totalRecord) ?? 0;
15
+ if (t.push(...g), t.length >= a || g.length < i || t.length >= p) break;
16
+ c += 1;
21
17
  }
22
- return t;
18
+ return t.slice(0, a);
23
19
  }
24
- function f(a) {
25
- return async (c) => {
26
- const e = c.page;
20
+ function f(r) {
21
+ return async (n) => {
22
+ const e = n.page;
27
23
  if (!e)
28
24
  throw new Error("createListApi: params.page 必填(含 page / pageSize)");
29
- const { page: i, pageSize: r } = e;
30
- if (!r || r <= 0)
25
+ const { page: i, pageSize: a } = e;
26
+ if (!a || a <= 0)
31
27
  throw new Error("createListApi: pageSize 必须 > 0");
32
28
  let t;
33
- if (Array.isArray(a))
34
- t = a;
29
+ if (Array.isArray(r))
30
+ t = r;
35
31
  else {
36
- const o = a();
37
- if (o instanceof Promise) {
38
- const l = await o;
32
+ const s = r();
33
+ if (s instanceof Promise) {
34
+ const l = await s;
39
35
  if (!Array.isArray(l))
40
36
  throw new Error("createListApi: 异步 source 返回值必须为数组");
41
37
  t = l;
42
38
  } else
43
- t = o;
39
+ t = s;
44
40
  }
45
- const n = (i - 1) * r, s = n + r;
41
+ const c = (i - 1) * a, o = c + a;
46
42
  return {
47
- items: t.slice(n, s),
43
+ items: t.slice(c, o),
48
44
  page: {
49
45
  totalRecord: t.length,
50
- pageSize: r,
51
- totalPage: Math.ceil(t.length / r)
46
+ pageSize: a,
47
+ totalPage: Math.ceil(t.length / a)
52
48
  }
53
49
  };
54
50
  };
55
51
  }
56
- function h(a, c) {
57
- return a({
58
- ...c,
52
+ function h(r, n) {
53
+ return r({
54
+ ...n,
59
55
  page: { page: 1, pageSize: 1 }
60
56
  }).then((e) => e.page.totalRecord);
61
57
  }