z-crud-table 0.0.14 → 0.0.15

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.
@@ -9,6 +9,10 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<im
9
9
  type: PropType<"default" | "large-screen">;
10
10
  default: string;
11
11
  };
12
+ customClass: {
13
+ type: StringConstructor;
14
+ default: string;
15
+ };
12
16
  apiUrlQuery: {
13
17
  type: StringConstructor;
14
18
  required: true;
@@ -129,6 +133,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<im
129
133
  search: () => void;
130
134
  handleDelete: (ids: number[]) => Promise<void>;
131
135
  openDialog: (mode: "add" | "edit", rowData?: any) => Promise<void>;
136
+ submit: (mode: "add" | "edit", data: Record<string, any>) => Promise<void>;
132
137
  }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
133
138
  submit: (...args: any[]) => void;
134
139
  delete: (...args: any[]) => void;
@@ -142,6 +147,10 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<im
142
147
  type: PropType<"default" | "large-screen">;
143
148
  default: string;
144
149
  };
150
+ customClass: {
151
+ type: StringConstructor;
152
+ default: string;
153
+ };
145
154
  apiUrlQuery: {
146
155
  type: StringConstructor;
147
156
  required: true;
@@ -262,6 +271,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<im
262
271
  onDelete?: ((...args: any[]) => any) | undefined;
263
272
  "onOpen-dialog"?: ((...args: any[]) => any) | undefined;
264
273
  }>, {
274
+ customClass: string;
265
275
  theme: "default" | "large-screen";
266
276
  columns: any[];
267
277
  showSelectionColumn: boolean;
@@ -1,83 +1,83 @@
1
- import { defineComponent as W, ref as A, resolveComponent as f, createBlock as p, openBlock as n, mergeProps as v, withCtx as s, createElementBlock as h, Fragment as x, renderList as q, createCommentVNode as g, createTextVNode as _, toDisplayString as ae, computed as P, reactive as L, onMounted as re, resolveDirective as ne, normalizeClass as ie, renderSlot as y, createElementVNode as O, withDirectives as T, createVNode as b, createSlots as se } from "vue";
1
+ import { defineComponent as H, ref as A, resolveComponent as m, createBlock as f, openBlock as i, mergeProps as h, withCtx as u, createElementBlock as w, Fragment as j, renderList as q, createCommentVNode as c, createTextVNode as v, toDisplayString as re, computed as O, reactive as T, onMounted as ne, resolveDirective as ie, normalizeClass as se, renderSlot as b, createElementVNode as x, withDirectives as W, createVNode as _, createSlots as ue } from "vue";
2
2
  import { ElMessage as F } from "element-plus";
3
- import ue from "axios";
4
- const de = /* @__PURE__ */ W({
3
+ import de from "axios";
4
+ const pe = /* @__PURE__ */ H({
5
5
  __name: "DynamicForm",
6
6
  props: {
7
7
  modelValue: {},
8
8
  formConfig: {},
9
9
  rules: {}
10
10
  },
11
- setup(m, { expose: C }) {
11
+ setup(g, { expose: D }) {
12
12
  const z = A(null);
13
- return C({
13
+ return D({
14
14
  validate: () => {
15
- var i;
16
- return (i = z.value) == null ? void 0 : i.validate();
15
+ var s;
16
+ return (s = z.value) == null ? void 0 : s.validate();
17
17
  }
18
- }), (i, t) => {
19
- const B = f("el-input"), j = f("el-option"), w = f("el-select"), d = f("el-radio"), D = f("el-radio-group"), k = f("el-form-item"), U = f("el-form");
20
- return n(), p(U, v({
21
- model: i.modelValue,
22
- rules: i.rules,
18
+ }), (s, e) => {
19
+ const B = m("el-input"), Q = m("el-option"), C = m("el-select"), $ = m("el-radio"), p = m("el-radio-group"), k = m("el-form-item"), U = m("el-form");
20
+ return i(), f(U, h({
21
+ model: s.modelValue,
22
+ rules: s.rules,
23
23
  ref_key: "formRef",
24
24
  ref: z
25
- }, i.$attrs), {
26
- default: s(() => [
27
- (n(!0), h(x, null, q(i.formConfig, (a) => (n(), p(k, {
25
+ }, s.$attrs), {
26
+ default: u(() => [
27
+ (i(!0), w(j, null, q(s.formConfig, (a) => (i(), f(k, {
28
28
  key: a.prop,
29
29
  label: a.label,
30
30
  prop: a.prop
31
31
  }, {
32
- default: s(() => [
33
- a.type === "input" ? (n(), p(B, v({
32
+ default: u(() => [
33
+ a.type === "input" ? (i(), f(B, h({
34
34
  key: 0,
35
- modelValue: i.modelValue[a.prop],
36
- "onUpdate:modelValue": (o) => i.modelValue[a.prop] = o
37
- }, { ref_for: !0 }, a.componentProps), null, 16, ["modelValue", "onUpdate:modelValue"])) : g("", !0),
38
- a.type === "textarea" ? (n(), p(B, v({
35
+ modelValue: s.modelValue[a.prop],
36
+ "onUpdate:modelValue": (d) => s.modelValue[a.prop] = d
37
+ }, { ref_for: !0 }, a.componentProps), null, 16, ["modelValue", "onUpdate:modelValue"])) : c("", !0),
38
+ a.type === "textarea" ? (i(), f(B, h({
39
39
  key: 1,
40
40
  type: "textarea",
41
- modelValue: i.modelValue[a.prop],
42
- "onUpdate:modelValue": (o) => i.modelValue[a.prop] = o
43
- }, { ref_for: !0 }, a.componentProps), null, 16, ["modelValue", "onUpdate:modelValue"])) : g("", !0),
44
- a.type === "select" ? (n(), p(w, v({
41
+ modelValue: s.modelValue[a.prop],
42
+ "onUpdate:modelValue": (d) => s.modelValue[a.prop] = d
43
+ }, { ref_for: !0 }, a.componentProps), null, 16, ["modelValue", "onUpdate:modelValue"])) : c("", !0),
44
+ a.type === "select" ? (i(), f(C, h({
45
45
  key: 2,
46
- modelValue: i.modelValue[a.prop],
47
- "onUpdate:modelValue": (o) => i.modelValue[a.prop] = o
46
+ modelValue: s.modelValue[a.prop],
47
+ "onUpdate:modelValue": (d) => s.modelValue[a.prop] = d
48
48
  }, { ref_for: !0 }, a.componentProps), {
49
- default: s(() => [
50
- (n(!0), h(x, null, q(a.options, (o) => (n(), p(j, {
51
- key: o.value,
52
- label: o.label,
53
- value: o.value
49
+ default: u(() => [
50
+ (i(!0), w(j, null, q(a.options, (d) => (i(), f(Q, {
51
+ key: d.value,
52
+ label: d.label,
53
+ value: d.value
54
54
  }, null, 8, ["label", "value"]))), 128))
55
55
  ]),
56
56
  _: 2
57
- }, 1040, ["modelValue", "onUpdate:modelValue"])) : g("", !0),
58
- a.type === "radio-group" ? (n(), p(D, v({
57
+ }, 1040, ["modelValue", "onUpdate:modelValue"])) : c("", !0),
58
+ a.type === "radio-group" ? (i(), f(p, h({
59
59
  key: 3,
60
- modelValue: i.modelValue[a.prop],
61
- "onUpdate:modelValue": (o) => i.modelValue[a.prop] = o
60
+ modelValue: s.modelValue[a.prop],
61
+ "onUpdate:modelValue": (d) => s.modelValue[a.prop] = d
62
62
  }, { ref_for: !0 }, a.componentProps), {
63
- default: s(() => [
64
- (n(!0), h(x, null, q(a.options, (o) => (n(), p(d, {
65
- key: o.value,
66
- label: o.value
63
+ default: u(() => [
64
+ (i(!0), w(j, null, q(a.options, (d) => (i(), f($, {
65
+ key: d.value,
66
+ label: d.value
67
67
  }, {
68
- default: s(() => [
69
- _(ae(o.label), 1)
68
+ default: u(() => [
69
+ v(re(d.label), 1)
70
70
  ]),
71
71
  _: 2
72
72
  }, 1032, ["label"]))), 128))
73
73
  ]),
74
74
  _: 2
75
- }, 1040, ["modelValue", "onUpdate:modelValue"])) : g("", !0),
76
- a.type === "input-disabled" ? (n(), p(B, v({
75
+ }, 1040, ["modelValue", "onUpdate:modelValue"])) : c("", !0),
76
+ a.type === "input-disabled" ? (i(), f(B, h({
77
77
  key: 4,
78
- "model-value": i.modelValue[a.prop],
78
+ "model-value": s.modelValue[a.prop],
79
79
  disabled: ""
80
- }, { ref_for: !0 }, a.componentProps), null, 16, ["model-value"])) : g("", !0)
80
+ }, { ref_for: !0 }, a.componentProps), null, 16, ["model-value"])) : c("", !0)
81
81
  ]),
82
82
  _: 2
83
83
  }, 1032, ["label", "prop"]))), 128))
@@ -86,7 +86,7 @@ const de = /* @__PURE__ */ W({
86
86
  }, 16, ["model", "rules"]);
87
87
  };
88
88
  }
89
- }), S = ue.create({
89
+ }), S = de.create({
90
90
  // VITE_APP_BASE_API 是在 .env 文件中定义的基础 URL
91
91
  // 您可以根据您的项目需求进行修改
92
92
  baseURL: "",
@@ -94,28 +94,28 @@ const de = /* @__PURE__ */ W({
94
94
  // 请求超时时间
95
95
  });
96
96
  S.interceptors.request.use(
97
- (m) => {
98
- const C = localStorage.getItem("token");
99
- return C && (m.headers.Authorization = "Bearer " + C), m;
97
+ (g) => {
98
+ const D = localStorage.getItem("token");
99
+ return D && (g.headers.Authorization = "Bearer " + D), g;
100
100
  },
101
- (m) => (console.log(m), Promise.reject(m))
101
+ (g) => (console.log(g), Promise.reject(g))
102
102
  );
103
103
  S.interceptors.response.use(
104
- (m) => m.data,
105
- (m) => (console.log("err" + m), F({
104
+ (g) => g.data,
105
+ (g) => (console.log("err" + g), F({
106
106
  message: "接口错误,请刷新接口",
107
107
  // 这里是您要求的统一错误提示
108
108
  type: "error",
109
109
  duration: 5 * 1e3
110
- }), Promise.reject(m))
110
+ }), Promise.reject(g))
111
111
  );
112
- const pe = { class: "flex flex-wrap items-center justify-between gap-4 mb-6" }, fe = { class: "flex items-center gap-x-2" }, me = { class: "flex items-center gap-x-3 action-buttons flex-shrink-0" }, ge = {
112
+ const fe = { class: "flex flex-wrap items-center justify-between gap-4 mb-6" }, me = { class: "flex items-center gap-x-2" }, ge = { class: "flex items-center gap-x-3 action-buttons flex-shrink-0" }, ce = {
113
113
  key: 0,
114
114
  class: "flex items-center gap-x-2"
115
- }, ce = {
115
+ }, ye = {
116
116
  key: 0,
117
117
  class: "flex justify-end"
118
- }, ye = { class: "dialog-footer" }, he = /* @__PURE__ */ W({
118
+ }, be = { class: "dialog-footer" }, we = /* @__PURE__ */ H({
119
119
  __name: "CrudTable",
120
120
  props: {
121
121
  /**
@@ -123,6 +123,8 @@ const pe = { class: "flex flex-wrap items-center justify-between gap-4 mb-6" },
123
123
  * @type {'default' | 'large-screen'}
124
124
  */
125
125
  theme: { type: String, default: "default" },
126
+ customClass: { type: String, default: "" },
127
+ // ✨ 新增 customClass prop
126
128
  // API 相关配置
127
129
  apiUrlQuery: { type: String, required: !0 },
128
130
  apiUrlDetail: { type: String, required: !0 },
@@ -165,134 +167,141 @@ const pe = { class: "flex flex-wrap items-center justify-between gap-4 mb-6" },
165
167
  dialogFormRules: { type: Object, default: () => ({}) }
166
168
  },
167
169
  emits: ["open-dialog", "submit", "delete"],
168
- setup(m, { expose: C, emit: z }) {
169
- const i = z, t = m, B = P(() => ["crud-table-wrapper", `theme-${t.theme}`]), j = P(() => t.theme === "large-screen" ? "large-screen-dialog" : ""), w = (e, l) => e ? !0 : (F.error(`${l} prop is required.`), !1), d = L({ pageNum: 1, pageSize: 10, ...t.initialSearchForm }), D = A([]), k = A(0), U = A(!1), a = A([]), o = L({ visible: !1, loading: !1, submitting: !1, mode: "add", data: {}, formRef: null }), H = P(() => o.mode === "add" ? "新增" : "编辑"), M = P(() => {
170
- if (o.mode === "add") return t.dialogFormConfig.filter((l) => l.prop !== "id");
171
- const e = [...t.dialogFormConfig.filter((l) => l.prop !== "id")];
172
- return e.some((l) => l.prop === "id") || e.unshift({ type: "input-disabled", prop: "id", label: "用户ID" }), e;
170
+ setup(g, { expose: D, emit: z }) {
171
+ const s = z, e = g, B = O(() => ["crud-table-wrapper", `theme-${e.theme}`, e.customClass]), Q = O(() => e.theme === "large-screen" ? "large-screen-dialog" : ""), C = (t, o) => t ? !0 : (F.error(`${o} prop is required.`), !1), $ = async (t, o) => {
172
+ try {
173
+ let r = { ...o };
174
+ if (e.onBeforeSubmit && (r = await e.onBeforeSubmit(r)), l.submitting = !0, t === "add") {
175
+ if (!C(e.apiUrlCreate, "apiUrlCreate")) return;
176
+ await S.post(e.apiUrlCreate, r), F.success("新增成功");
177
+ } else {
178
+ if (!C(e.apiUrlUpdate, "apiUrlUpdate")) return;
179
+ await S.put(e.apiUrlUpdate, r), F.success("更新成功");
180
+ }
181
+ return e.onAfterSubmit && e.onAfterSubmit(t, r), s("submit", { mode: t, data: r }), l.visible && (l.visible = !1), V(), Promise.resolve();
182
+ } catch (r) {
183
+ return console.log("Submit error:", r), Promise.reject(r);
184
+ } finally {
185
+ l.submitting = !1;
186
+ }
187
+ }, p = T({ pageNum: 1, pageSize: 10, ...e.initialSearchForm }), k = A([]), U = A(0), a = A(!1), d = A([]), l = T({ visible: !1, loading: !1, submitting: !1, mode: "add", data: {}, formRef: null }), M = O(() => l.mode === "add" ? "新增" : "编辑"), G = O(() => {
188
+ if (l.mode === "add") return e.dialogFormConfig.filter((o) => o.prop !== "id");
189
+ const t = [...e.dialogFormConfig.filter((o) => o.prop !== "id")];
190
+ return t.some((o) => o.prop === "id") || t.unshift({ type: "input-disabled", prop: "id", label: "用户ID" }), t;
173
191
  }), V = async () => {
174
- if (w(t.apiUrlQuery, "apiUrlQuery")) {
175
- U.value = !0;
192
+ if (C(e.apiUrlQuery, "apiUrlQuery")) {
193
+ a.value = !0;
176
194
  try {
177
- let e = { ...d };
178
- t.onBeforeQuery && (e = await t.onBeforeQuery(e));
179
- const l = await S.get(t.apiUrlQuery, { params: e });
180
- if (l && Array.isArray(l.data) && typeof l.total == "number") {
181
- let u = l.data;
182
- t.onAfterQuery && (u = await t.onAfterQuery(u)), D.value = u, k.value = l.total;
195
+ let t = { ...p };
196
+ e.onBeforeQuery && (t = await e.onBeforeQuery(t));
197
+ const o = await S.get(e.apiUrlQuery, { params: t });
198
+ if (o && Array.isArray(o.data) && typeof o.total == "number") {
199
+ let r = o.data;
200
+ e.onAfterQuery && (r = await e.onAfterQuery(r)), k.value = r, U.value = o.total;
183
201
  } else
184
- console.warn("API response is not in the expected { data: [], total: 0 } format."), D.value = [], k.value = 0;
185
- } catch (e) {
186
- console.error("Fetch data failed:", e);
202
+ console.warn("API response is not in the expected { data: [], total: 0 } format."), k.value = [], U.value = 0;
203
+ } catch (t) {
204
+ console.error("Fetch data failed:", t);
187
205
  } finally {
188
- U.value = !1;
206
+ a.value = !1;
189
207
  }
190
208
  }
191
- }, $ = () => {
192
- d.pageNum = 1, V();
193
- }, G = () => {
194
- const { pageNum: e, pageSize: l, ...u } = t.initialSearchForm;
195
- Object.keys(d).forEach((c) => {
196
- c !== "pageNum" && c !== "pageSize" && delete d[c];
197
- }), Object.assign(d, u), $();
198
- }, J = (e) => {
199
- a.value = e;
200
- }, Q = async (e, l) => {
201
- let u = e === "add" ? { role: "user" } : { ...l };
202
- if (t.onBeforeOpenDialog) {
203
- const c = await t.onBeforeOpenDialog(e, u);
204
- c && (u = c);
209
+ }, P = () => {
210
+ p.pageNum = 1, V();
211
+ }, J = () => {
212
+ const { pageNum: t, pageSize: o, ...r } = e.initialSearchForm;
213
+ Object.keys(p).forEach((y) => {
214
+ y !== "pageNum" && y !== "pageSize" && delete p[y];
215
+ }), Object.assign(p, r), P();
216
+ }, K = (t) => {
217
+ d.value = t;
218
+ }, R = async (t, o) => {
219
+ let r = t === "add" ? { role: "user" } : { ...o };
220
+ if (e.onBeforeOpenDialog) {
221
+ const y = await e.onBeforeOpenDialog(t, r);
222
+ y && (r = y);
205
223
  }
206
- if (o.mode = e, o.visible = !0, e === "edit") {
207
- if (!w(t.apiUrlDetail, "apiUrlDetail")) return;
208
- o.loading = !0;
224
+ if (l.mode = t, l.visible = !0, t === "edit") {
225
+ if (!C(e.apiUrlDetail, "apiUrlDetail")) return;
226
+ l.loading = !0;
209
227
  try {
210
- const c = await S.get(t.apiUrlDetail + "/" + u.id);
211
- o.data = c.data;
228
+ const y = await S.get(e.apiUrlDetail + "/" + r.id);
229
+ l.data = y.data;
212
230
  } finally {
213
- o.loading = !1, t.onAfterOpenDialog && t.onAfterOpenDialog(e, o.data), i("open-dialog", { mode: e, data: o.data });
231
+ l.loading = !1, e.onAfterOpenDialog && e.onAfterOpenDialog(t, l.data), s("open-dialog", { mode: t, data: l.data });
214
232
  }
215
233
  } else
216
- o.data = u, t.onAfterOpenDialog && t.onAfterOpenDialog(e, o.data), i("open-dialog", { mode: e, data: o.data });
217
- }, K = async () => {
234
+ l.data = r, e.onAfterOpenDialog && e.onAfterOpenDialog(t, l.data), s("open-dialog", { mode: t, data: l.data });
235
+ }, X = async () => {
218
236
  try {
219
- o.formRef && await o.formRef.validate();
220
- let e = { ...o.data };
221
- if (t.onBeforeSubmit && (e = await t.onBeforeSubmit(e)), o.submitting = !0, o.mode === "add") {
222
- if (!w(t.apiUrlCreate, "apiUrlCreate")) return;
223
- await S.post(t.apiUrlCreate, e), F.success("新增成功");
224
- } else {
225
- if (!w(t.apiUrlUpdate, "apiUrlUpdate")) return;
226
- await S.put(t.apiUrlUpdate, e), F.success("更新成功");
227
- }
228
- t.onAfterSubmit && t.onAfterSubmit(o.mode, e), i("submit", { mode: o.mode, data: e }), o.visible = !1, V();
229
- } catch (e) {
230
- console.log("Submit error or validation failed:", e);
231
- } finally {
232
- o.submitting = !1;
237
+ l.formRef && await l.formRef.validate(), await $(l.mode, l.data);
238
+ } catch (t) {
239
+ console.log("Validation failed:", t);
233
240
  }
234
- }, E = async (e) => {
235
- if (w(t.apiUrlDelete, "apiUrlDelete"))
241
+ }, I = async (t) => {
242
+ if (C(e.apiUrlDelete, "apiUrlDelete"))
236
243
  try {
237
- if (t.onBeforeDelete && await t.onBeforeDelete(e) === !1)
244
+ if (e.onBeforeDelete && await e.onBeforeDelete(t) === !1)
238
245
  return;
239
- const l = e.join(",");
240
- await S.delete(t.apiUrlDelete + "/" + l.toString()), F.success("删除成功"), t.onAfterDelete && t.onAfterDelete(e), i("delete", e), D.value.length === e.length && d.pageNum > 1 && d.pageNum--, V();
241
- } catch (l) {
242
- console.error("Delete failed", l);
246
+ const o = t.join(",");
247
+ await S.delete(e.apiUrlDelete + "/" + o.toString()), F.success("删除成功"), e.onAfterDelete && e.onAfterDelete(t), s("delete", t), k.value.length === t.length && p.pageNum > 1 && p.pageNum--, V();
248
+ } catch (o) {
249
+ console.error("Delete failed", o);
243
250
  }
244
- }, X = (e) => {
245
- d.pageSize = e, $();
246
- }, Y = (e) => {
247
- d.pageNum = e, V();
251
+ }, Y = (t) => {
252
+ p.pageSize = t, P();
253
+ }, Z = (t) => {
254
+ p.pageNum = t, V();
248
255
  };
249
- return re(V), C({
256
+ return ne(V), D({
250
257
  refresh: V,
251
258
  // 刷新表格
252
- search: $,
259
+ search: P,
253
260
  // 按当前条件搜索
254
- handleDelete: E,
261
+ handleDelete: I,
255
262
  // 手动触发删除
256
- openDialog: Q
263
+ openDialog: R,
257
264
  // 手动打开弹窗
258
- }), (e, l) => {
259
- const u = f("el-button"), c = f("el-form-item"), Z = f("el-form"), N = f("el-table-column"), ee = f("el-popconfirm"), te = f("el-table"), oe = f("el-pagination"), le = f("el-dialog"), I = ne("loading");
260
- return n(), h("div", {
261
- class: ie(B.value)
265
+ submit: $
266
+ // 手动提交
267
+ }), (t, o) => {
268
+ const r = m("el-button"), y = m("el-form-item"), ee = m("el-form"), N = m("el-table-column"), te = m("el-popconfirm"), oe = m("el-table"), le = m("el-pagination"), ae = m("el-dialog"), L = ie("loading");
269
+ return i(), w("div", {
270
+ class: se(B.value)
262
271
  }, [
263
- y(e.$slots, "header"),
264
- O("div", pe, [
265
- b(Z, {
266
- model: d,
272
+ b(t.$slots, "header"),
273
+ x("div", fe, [
274
+ _(ee, {
275
+ model: p,
267
276
  class: "query-form flex flex-nowrap items-center gap-x-4",
268
277
  style: { "overflow-x": "auto", "padding-bottom": "8px" }
269
278
  }, {
270
- default: s(() => [
271
- y(e.$slots, "query-conditions", { searchForm: d }),
272
- b(c, { class: "!mr-0 flex-shrink-0" }, {
273
- default: s(() => [
274
- O("div", fe, [
275
- y(e.$slots, "query-left"),
276
- b(u, {
279
+ default: u(() => [
280
+ b(t.$slots, "query-conditions", { searchForm: p }),
281
+ _(y, { class: "!mr-0 flex-shrink-0" }, {
282
+ default: u(() => [
283
+ x("div", me, [
284
+ b(t.$slots, "query-left"),
285
+ _(r, {
277
286
  style: { "margin-left": "16px" },
278
287
  type: "primary",
279
- onClick: $,
280
- loading: U.value
288
+ onClick: P,
289
+ loading: a.value
281
290
  }, {
282
- default: s(() => l[6] || (l[6] = [
283
- _("搜索 ")
291
+ default: u(() => o[6] || (o[6] = [
292
+ v("搜索 ")
284
293
  ])),
285
294
  _: 1,
286
295
  __: [6]
287
296
  }, 8, ["loading"]),
288
- b(u, { onClick: G }, {
289
- default: s(() => l[7] || (l[7] = [
290
- _("清空")
297
+ _(r, { onClick: J }, {
298
+ default: u(() => o[7] || (o[7] = [
299
+ v("清空")
291
300
  ])),
292
301
  _: 1,
293
302
  __: [7]
294
303
  }),
295
- y(e.$slots, "query-right")
304
+ b(t.$slots, "query-right")
296
305
  ])
297
306
  ]),
298
307
  _: 3
@@ -300,180 +309,180 @@ const pe = { class: "flex flex-wrap items-center justify-between gap-4 mb-6" },
300
309
  ]),
301
310
  _: 3
302
311
  }, 8, ["model"]),
303
- O("div", me, [
304
- y(e.$slots, "action-left", { selections: a.value }),
305
- y(e.$slots, "add-button-content", {}, () => [
306
- b(u, {
312
+ x("div", ge, [
313
+ b(t.$slots, "action-left", { selections: d.value }),
314
+ b(t.$slots, "add-button-content", {}, () => [
315
+ _(r, {
307
316
  type: "success",
308
- onClick: l[0] || (l[0] = (r) => Q("add"))
317
+ onClick: o[0] || (o[0] = (n) => R("add"))
309
318
  }, {
310
- default: s(() => l[8] || (l[8] = [
311
- _("新增")
319
+ default: u(() => o[8] || (o[8] = [
320
+ v("新增")
312
321
  ])),
313
322
  _: 1,
314
323
  __: [8]
315
324
  })
316
325
  ]),
317
- y(e.$slots, "action-right")
326
+ b(t.$slots, "action-right")
318
327
  ])
319
328
  ]),
320
- T((n(), p(te, v({
321
- data: D.value,
322
- onSelectionChange: J
323
- }, e.$attrs, { style: { width: "100%", "margin-bottom": "1.5rem" } }), {
324
- default: s(() => [
325
- t.showSelectionColumn ? (n(), p(N, {
329
+ W((i(), f(oe, h({
330
+ data: k.value,
331
+ onSelectionChange: K
332
+ }, t.$attrs, { style: { width: "100%", "margin-bottom": "1.5rem" } }), {
333
+ default: u(() => [
334
+ e.showSelectionColumn ? (i(), f(N, {
326
335
  key: 0,
327
336
  type: "selection",
328
337
  width: "55",
329
338
  fixed: ""
330
- })) : g("", !0),
331
- t.showIndexColumn ? (n(), p(N, {
339
+ })) : c("", !0),
340
+ e.showIndexColumn ? (i(), f(N, {
332
341
  key: 1,
333
342
  type: "index",
334
343
  label: "序号",
335
344
  width: "70",
336
345
  fixed: ""
337
- })) : g("", !0),
338
- (n(!0), h(x, null, q(t.columns, (r) => (n(), p(N, v({
339
- key: r.prop,
340
- prop: r.prop,
341
- label: r.label,
342
- width: r.width,
343
- sortable: r.sortable || !1
344
- }, { ref_for: !0 }, r.attrs), se({ _: 2 }, [
345
- r.slot ? {
346
+ })) : c("", !0),
347
+ (i(!0), w(j, null, q(e.columns, (n) => (i(), f(N, h({
348
+ key: n.prop,
349
+ prop: n.prop,
350
+ label: n.label,
351
+ width: n.width,
352
+ sortable: n.sortable || !1
353
+ }, { ref_for: !0 }, n.attrs), ue({ _: 2 }, [
354
+ n.slot ? {
346
355
  name: "default",
347
- fn: s((R) => [
348
- y(e.$slots, r.slot, {
349
- row: R.row
356
+ fn: u((E) => [
357
+ b(t.$slots, n.slot, {
358
+ row: E.row
350
359
  })
351
360
  ]),
352
361
  key: "0"
353
362
  } : void 0
354
363
  ]), 1040, ["prop", "label", "width", "sortable"]))), 128)),
355
- t.showActionsColumn ? (n(), p(N, {
364
+ e.showActionsColumn ? (i(), f(N, {
356
365
  key: 2,
357
366
  label: "操作",
358
- width: m.actionsColumnWidth
367
+ width: g.actionsColumnWidth
359
368
  }, {
360
- default: s((r) => [
361
- r.row ? (n(), h("div", ge, [
362
- y(e.$slots, "actions", {
363
- row: r.row
369
+ default: u((n) => [
370
+ n.row ? (i(), w("div", ce, [
371
+ b(t.$slots, "actions", {
372
+ row: n.row
364
373
  }, () => [
365
- t.showEditButton ? (n(), p(u, {
374
+ e.showEditButton ? (i(), f(r, {
366
375
  key: 0,
367
376
  size: "small",
368
377
  type: "primary",
369
378
  link: "",
370
- onClick: (R) => Q("edit", r.row)
379
+ onClick: (E) => R("edit", n.row)
371
380
  }, {
372
- default: s(() => l[9] || (l[9] = [
373
- _("编辑 ")
381
+ default: u(() => o[9] || (o[9] = [
382
+ v("编辑 ")
374
383
  ])),
375
384
  _: 2,
376
385
  __: [9]
377
- }, 1032, ["onClick"])) : g("", !0),
378
- t.showDeleteButton ? (n(), p(ee, {
386
+ }, 1032, ["onClick"])) : c("", !0),
387
+ e.showDeleteButton ? (i(), f(te, {
379
388
  key: 1,
380
389
  title: "确定要删除这条数据吗?",
381
- onConfirm: (R) => E([r.row.id]),
390
+ onConfirm: (E) => I([n.row.id]),
382
391
  "confirm-button-text": "确定",
383
392
  "cancel-button-text": "取消",
384
393
  width: "200"
385
394
  }, {
386
- reference: s(() => [
387
- b(u, {
395
+ reference: u(() => [
396
+ _(r, {
388
397
  size: "small",
389
398
  type: "danger",
390
399
  link: ""
391
400
  }, {
392
- default: s(() => l[10] || (l[10] = [
393
- _("删除")
401
+ default: u(() => o[10] || (o[10] = [
402
+ v("删除")
394
403
  ])),
395
404
  _: 1,
396
405
  __: [10]
397
406
  })
398
407
  ]),
399
408
  _: 2
400
- }, 1032, ["onConfirm"])) : g("", !0)
409
+ }, 1032, ["onConfirm"])) : c("", !0)
401
410
  ])
402
- ])) : g("", !0)
411
+ ])) : c("", !0)
403
412
  ]),
404
413
  _: 3
405
- }, 8, ["width"])) : g("", !0)
414
+ }, 8, ["width"])) : c("", !0)
406
415
  ]),
407
416
  _: 3
408
417
  }, 16, ["data"])), [
409
- [I, U.value]
418
+ [L, a.value]
410
419
  ]),
411
- t.showPagination && k.value > 0 ? (n(), h("div", ce, [
412
- b(oe, {
413
- "current-page": d.pageNum,
414
- "onUpdate:currentPage": l[1] || (l[1] = (r) => d.pageNum = r),
415
- "page-size": d.pageSize,
416
- "onUpdate:pageSize": l[2] || (l[2] = (r) => d.pageSize = r),
417
- "page-sizes": t.pageSizes,
418
- layout: t.paginationLayout,
419
- total: k.value,
420
- background: t.paginationBackground,
421
- small: t.paginationSmall,
422
- "hide-on-single-page": t.paginationHideOnSinglePage,
423
- onSizeChange: X,
424
- onCurrentChange: Y
420
+ e.showPagination && U.value > 0 ? (i(), w("div", ye, [
421
+ _(le, {
422
+ "current-page": p.pageNum,
423
+ "onUpdate:currentPage": o[1] || (o[1] = (n) => p.pageNum = n),
424
+ "page-size": p.pageSize,
425
+ "onUpdate:pageSize": o[2] || (o[2] = (n) => p.pageSize = n),
426
+ "page-sizes": e.pageSizes,
427
+ layout: e.paginationLayout,
428
+ total: U.value,
429
+ background: e.paginationBackground,
430
+ small: e.paginationSmall,
431
+ "hide-on-single-page": e.paginationHideOnSinglePage,
432
+ onSizeChange: Y,
433
+ onCurrentChange: Z
425
434
  }, null, 8, ["current-page", "page-size", "page-sizes", "layout", "total", "background", "small", "hide-on-single-page"])
426
- ])) : g("", !0),
427
- b(le, {
428
- modelValue: o.visible,
429
- "onUpdate:modelValue": l[5] || (l[5] = (r) => o.visible = r),
430
- title: H.value,
431
- width: t.dialogWidth,
435
+ ])) : c("", !0),
436
+ _(ae, {
437
+ modelValue: l.visible,
438
+ "onUpdate:modelValue": o[5] || (o[5] = (n) => l.visible = n),
439
+ title: M.value,
440
+ width: e.dialogWidth,
432
441
  "destroy-on-close": !0,
433
- "custom-class": j.value
442
+ "custom-class": Q.value
434
443
  }, {
435
- footer: s(() => [
436
- O("div", ye, [
437
- b(u, {
438
- onClick: l[4] || (l[4] = (r) => o.visible = !1)
444
+ footer: u(() => [
445
+ x("div", be, [
446
+ _(r, {
447
+ onClick: o[4] || (o[4] = (n) => l.visible = !1)
439
448
  }, {
440
- default: s(() => l[11] || (l[11] = [
441
- _("取消")
449
+ default: u(() => o[11] || (o[11] = [
450
+ v("取消")
442
451
  ])),
443
452
  _: 1,
444
453
  __: [11]
445
454
  }),
446
- b(u, {
455
+ _(r, {
447
456
  type: "primary",
448
- onClick: K,
449
- loading: o.submitting
457
+ onClick: X,
458
+ loading: l.submitting
450
459
  }, {
451
- default: s(() => l[12] || (l[12] = [
452
- _("确定")
460
+ default: u(() => o[12] || (o[12] = [
461
+ v("确定")
453
462
  ])),
454
463
  _: 1,
455
464
  __: [12]
456
465
  }, 8, ["loading"])
457
466
  ])
458
467
  ]),
459
- default: s(() => [
460
- T((n(), h("div", null, [
461
- y(e.$slots, "dialog-form-content", {
462
- formData: o.data,
463
- mode: o.mode
468
+ default: u(() => [
469
+ W((i(), w("div", null, [
470
+ b(t.$slots, "dialog-form-content", {
471
+ formData: l.data,
472
+ mode: l.mode
464
473
  }, () => [
465
- t.dialogFormConfig.length > 0 ? (n(), p(de, {
474
+ e.dialogFormConfig.length > 0 ? (i(), f(pe, {
466
475
  key: 0,
467
- "form-config": M.value,
468
- modelValue: o.data,
469
- "onUpdate:modelValue": l[3] || (l[3] = (r) => o.data = r),
470
- ref: (r) => o.formRef = r,
471
- rules: t.dialogFormRules,
476
+ "form-config": G.value,
477
+ modelValue: l.data,
478
+ "onUpdate:modelValue": o[3] || (o[3] = (n) => l.data = n),
479
+ ref: (n) => l.formRef = n,
480
+ rules: e.dialogFormRules,
472
481
  "label-width": "80px"
473
- }, null, 8, ["form-config", "modelValue", "rules"])) : g("", !0)
482
+ }, null, 8, ["form-config", "modelValue", "rules"])) : c("", !0)
474
483
  ])
475
484
  ])), [
476
- [I, o.loading]
485
+ [L, l.loading]
477
486
  ])
478
487
  ]),
479
488
  _: 3
@@ -483,5 +492,5 @@ const pe = { class: "flex flex-wrap items-center justify-between gap-4 mb-6" },
483
492
  }
484
493
  });
485
494
  export {
486
- he as CrudTable
495
+ we as CrudTable
487
496
  };
@@ -1 +1 @@
1
- (function(m,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("element-plus"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","element-plus","axios"],e):(m=typeof globalThis<"u"?globalThis:m||self,e(m.ZCrudTable={},m.Vue,m.ElementPlus,m.axios))})(this,function(m,e,B,F){"use strict";const A=e.defineComponent({__name:"DynamicForm",props:{modelValue:{},formConfig:{},rules:{}},setup(p,{expose:u}){const b=e.ref(null);return u({validate:()=>{var i;return(i=b.value)==null?void 0:i.validate()}}),(i,o)=>{const w=e.resolveComponent("el-input"),S=e.resolveComponent("el-option"),g=e.resolveComponent("el-select"),d=e.resolveComponent("el-radio"),y=e.resolveComponent("el-radio-group"),C=e.resolveComponent("el-form-item"),k=e.resolveComponent("el-form");return e.openBlock(),e.createBlock(k,e.mergeProps({model:i.modelValue,rules:i.rules,ref_key:"formRef",ref:b},i.$attrs),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(i.formConfig,r=>(e.openBlock(),e.createBlock(C,{key:r.prop,label:r.label,prop:r.prop},{default:e.withCtx(()=>[r.type==="input"?(e.openBlock(),e.createBlock(w,e.mergeProps({key:0,modelValue:i.modelValue[r.prop],"onUpdate:modelValue":l=>i.modelValue[r.prop]=l},{ref_for:!0},r.componentProps),null,16,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),r.type==="textarea"?(e.openBlock(),e.createBlock(w,e.mergeProps({key:1,type:"textarea",modelValue:i.modelValue[r.prop],"onUpdate:modelValue":l=>i.modelValue[r.prop]=l},{ref_for:!0},r.componentProps),null,16,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),r.type==="select"?(e.openBlock(),e.createBlock(g,e.mergeProps({key:2,modelValue:i.modelValue[r.prop],"onUpdate:modelValue":l=>i.modelValue[r.prop]=l},{ref_for:!0},r.componentProps),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.options,l=>(e.openBlock(),e.createBlock(S,{key:l.value,label:l.label,value:l.value},null,8,["label","value"]))),128))]),_:2},1040,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),r.type==="radio-group"?(e.openBlock(),e.createBlock(y,e.mergeProps({key:3,modelValue:i.modelValue[r.prop],"onUpdate:modelValue":l=>i.modelValue[r.prop]=l},{ref_for:!0},r.componentProps),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.options,l=>(e.openBlock(),e.createBlock(d,{key:l.value,label:l.value},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(l.label),1)]),_:2},1032,["label"]))),128))]),_:2},1040,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),r.type==="input-disabled"?(e.openBlock(),e.createBlock(w,e.mergeProps({key:4,"model-value":i.modelValue[r.prop],disabled:""},{ref_for:!0},r.componentProps),null,16,["model-value"])):e.createCommentVNode("",!0)]),_:2},1032,["label","prop"]))),128))]),_:1},16,["model","rules"])}}}),f=F.create({baseURL:"",timeout:1e4});f.interceptors.request.use(p=>{const u=localStorage.getItem("token");return u&&(p.headers.Authorization="Bearer "+u),p},p=>(console.log(p),Promise.reject(p))),f.interceptors.response.use(p=>p.data,p=>(console.log("err"+p),B.ElMessage({message:"接口错误,请刷新接口",type:"error",duration:5*1e3}),Promise.reject(p)));const z={class:"flex flex-wrap items-center justify-between gap-4 mb-6"},E={class:"flex items-center gap-x-2"},P={class:"flex items-center gap-x-3 action-buttons flex-shrink-0"},$={key:0,class:"flex items-center gap-x-2"},O={key:0,class:"flex justify-end"},T={class:"dialog-footer"},q=e.defineComponent({__name:"CrudTable",props:{theme:{type:String,default:"default"},apiUrlQuery:{type:String,required:!0},apiUrlDetail:{type:String,required:!0},apiUrlCreate:{type:String,required:!0},apiUrlUpdate:{type:String,required:!0},apiUrlDelete:{type:String,required:!0},columns:{type:Array,default:()=>[]},onBeforeQuery:{type:Function},onAfterQuery:{type:Function},onBeforeOpenDialog:{type:Function},onAfterOpenDialog:{type:Function},onBeforeSubmit:{type:Function},onAfterSubmit:{type:Function},onBeforeDelete:{type:Function},onAfterDelete:{type:Function},showSelectionColumn:{type:Boolean,default:!0},showIndexColumn:{type:Boolean,default:!0},showActionsColumn:{type:Boolean,default:!0},showEditButton:{type:Boolean,default:!0},showDeleteButton:{type:Boolean,default:!0},actionsColumnWidth:{type:[String,Number],default:120},dialogWidth:{type:String,default:"50%"},initialSearchForm:{type:Object,default:()=>({pageNum:1,pageSize:10})},showPagination:{type:Boolean,default:!0},pageSizes:{type:Array,default:()=>[10,20,50,100]},paginationLayout:{type:String,default:"total, sizes, prev, pager, next, jumper"},paginationBackground:{type:Boolean,default:!0},paginationSmall:{type:Boolean,default:!1},paginationHideOnSinglePage:{type:Boolean,default:!1},dialogFormConfig:{type:Array,default:()=>[]},dialogFormRules:{type:Object,default:()=>({})}},emits:["open-dialog","submit","delete"],setup(p,{expose:u,emit:b}){const i=b,o=p,w=e.computed(()=>["crud-table-wrapper",`theme-${o.theme}`]),S=e.computed(()=>o.theme==="large-screen"?"large-screen-dialog":""),g=(t,a)=>t?!0:(B.ElMessage.error(`${a} prop is required.`),!1),d=e.reactive({pageNum:1,pageSize:10,...o.initialSearchForm}),y=e.ref([]),C=e.ref(0),k=e.ref(!1),r=e.ref([]),l=e.reactive({visible:!1,loading:!1,submitting:!1,mode:"add",data:{},formRef:null}),j=e.computed(()=>l.mode==="add"?"新增":"编辑"),Q=e.computed(()=>{if(l.mode==="add")return o.dialogFormConfig.filter(a=>a.prop!=="id");const t=[...o.dialogFormConfig.filter(a=>a.prop!=="id")];return t.some(a=>a.prop==="id")||t.unshift({type:"input-disabled",prop:"id",label:"用户ID"}),t}),h=async()=>{if(g(o.apiUrlQuery,"apiUrlQuery")){k.value=!0;try{let t={...d};o.onBeforeQuery&&(t=await o.onBeforeQuery(t));const a=await f.get(o.apiUrlQuery,{params:t});if(a&&Array.isArray(a.data)&&typeof a.total=="number"){let s=a.data;o.onAfterQuery&&(s=await o.onAfterQuery(s)),y.value=s,C.value=a.total}else console.warn("API response is not in the expected { data: [], total: 0 } format."),y.value=[],C.value=0}catch(t){console.error("Fetch data failed:",t)}finally{k.value=!1}}},V=()=>{d.pageNum=1,h()},R=()=>{const{pageNum:t,pageSize:a,...s}=o.initialSearchForm;Object.keys(d).forEach(c=>{c!=="pageNum"&&c!=="pageSize"&&delete d[c]}),Object.assign(d,s),V()},L=t=>{r.value=t},N=async(t,a)=>{let s=t==="add"?{role:"user"}:{...a};if(o.onBeforeOpenDialog){const c=await o.onBeforeOpenDialog(t,s);c&&(s=c)}if(l.mode=t,l.visible=!0,t==="edit"){if(!g(o.apiUrlDetail,"apiUrlDetail"))return;l.loading=!0;try{const c=await f.get(o.apiUrlDetail+"/"+s.id);l.data=c.data}finally{l.loading=!1,o.onAfterOpenDialog&&o.onAfterOpenDialog(t,l.data),i("open-dialog",{mode:t,data:l.data})}}else l.data=s,o.onAfterOpenDialog&&o.onAfterOpenDialog(t,l.data),i("open-dialog",{mode:t,data:l.data})},M=async()=>{try{l.formRef&&await l.formRef.validate();let t={...l.data};if(o.onBeforeSubmit&&(t=await o.onBeforeSubmit(t)),l.submitting=!0,l.mode==="add"){if(!g(o.apiUrlCreate,"apiUrlCreate"))return;await f.post(o.apiUrlCreate,t),B.ElMessage.success("新增成功")}else{if(!g(o.apiUrlUpdate,"apiUrlUpdate"))return;await f.put(o.apiUrlUpdate,t),B.ElMessage.success("更新成功")}o.onAfterSubmit&&o.onAfterSubmit(l.mode,t),i("submit",{mode:l.mode,data:t}),l.visible=!1,h()}catch(t){console.log("Submit error or validation failed:",t)}finally{l.submitting=!1}},x=async t=>{if(g(o.apiUrlDelete,"apiUrlDelete"))try{if(o.onBeforeDelete&&await o.onBeforeDelete(t)===!1)return;const a=t.join(",");await f.delete(o.apiUrlDelete+"/"+a.toString()),B.ElMessage.success("删除成功"),o.onAfterDelete&&o.onAfterDelete(t),i("delete",t),y.value.length===t.length&&d.pageNum>1&&d.pageNum--,h()}catch(a){console.error("Delete failed",a)}},I=t=>{d.pageSize=t,V()},W=t=>{d.pageNum=t,h()};return e.onMounted(h),u({refresh:h,search:V,handleDelete:x,openDialog:N}),(t,a)=>{const s=e.resolveComponent("el-button"),c=e.resolveComponent("el-form-item"),H=e.resolveComponent("el-form"),_=e.resolveComponent("el-table-column"),Z=e.resolveComponent("el-popconfirm"),G=e.resolveComponent("el-table"),J=e.resolveComponent("el-pagination"),K=e.resolveComponent("el-dialog"),U=e.resolveDirective("loading");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(w.value)},[e.renderSlot(t.$slots,"header"),e.createElementVNode("div",z,[e.createVNode(H,{model:d,class:"query-form flex flex-nowrap items-center gap-x-4",style:{"overflow-x":"auto","padding-bottom":"8px"}},{default:e.withCtx(()=>[e.renderSlot(t.$slots,"query-conditions",{searchForm:d}),e.createVNode(c,{class:"!mr-0 flex-shrink-0"},{default:e.withCtx(()=>[e.createElementVNode("div",E,[e.renderSlot(t.$slots,"query-left"),e.createVNode(s,{style:{"margin-left":"16px"},type:"primary",onClick:V,loading:k.value},{default:e.withCtx(()=>a[6]||(a[6]=[e.createTextVNode("搜索 ")])),_:1,__:[6]},8,["loading"]),e.createVNode(s,{onClick:R},{default:e.withCtx(()=>a[7]||(a[7]=[e.createTextVNode("清空")])),_:1,__:[7]}),e.renderSlot(t.$slots,"query-right")])]),_:3})]),_:3},8,["model"]),e.createElementVNode("div",P,[e.renderSlot(t.$slots,"action-left",{selections:r.value}),e.renderSlot(t.$slots,"add-button-content",{},()=>[e.createVNode(s,{type:"success",onClick:a[0]||(a[0]=n=>N("add"))},{default:e.withCtx(()=>a[8]||(a[8]=[e.createTextVNode("新增")])),_:1,__:[8]})]),e.renderSlot(t.$slots,"action-right")])]),e.withDirectives((e.openBlock(),e.createBlock(G,e.mergeProps({data:y.value,onSelectionChange:L},t.$attrs,{style:{width:"100%","margin-bottom":"1.5rem"}}),{default:e.withCtx(()=>[o.showSelectionColumn?(e.openBlock(),e.createBlock(_,{key:0,type:"selection",width:"55",fixed:""})):e.createCommentVNode("",!0),o.showIndexColumn?(e.openBlock(),e.createBlock(_,{key:1,type:"index",label:"序号",width:"70",fixed:""})):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.columns,n=>(e.openBlock(),e.createBlock(_,e.mergeProps({key:n.prop,prop:n.prop,label:n.label,width:n.width,sortable:n.sortable||!1},{ref_for:!0},n.attrs),e.createSlots({_:2},[n.slot?{name:"default",fn:e.withCtx(D=>[e.renderSlot(t.$slots,n.slot,{row:D.row})]),key:"0"}:void 0]),1040,["prop","label","width","sortable"]))),128)),o.showActionsColumn?(e.openBlock(),e.createBlock(_,{key:2,label:"操作",width:p.actionsColumnWidth},{default:e.withCtx(n=>[n.row?(e.openBlock(),e.createElementBlock("div",$,[e.renderSlot(t.$slots,"actions",{row:n.row},()=>[o.showEditButton?(e.openBlock(),e.createBlock(s,{key:0,size:"small",type:"primary",link:"",onClick:D=>N("edit",n.row)},{default:e.withCtx(()=>a[9]||(a[9]=[e.createTextVNode("编辑 ")])),_:2,__:[9]},1032,["onClick"])):e.createCommentVNode("",!0),o.showDeleteButton?(e.openBlock(),e.createBlock(Z,{key:1,title:"确定要删除这条数据吗?",onConfirm:D=>x([n.row.id]),"confirm-button-text":"确定","cancel-button-text":"取消",width:"200"},{reference:e.withCtx(()=>[e.createVNode(s,{size:"small",type:"danger",link:""},{default:e.withCtx(()=>a[10]||(a[10]=[e.createTextVNode("删除")])),_:1,__:[10]})]),_:2},1032,["onConfirm"])):e.createCommentVNode("",!0)])])):e.createCommentVNode("",!0)]),_:3},8,["width"])):e.createCommentVNode("",!0)]),_:3},16,["data"])),[[U,k.value]]),o.showPagination&&C.value>0?(e.openBlock(),e.createElementBlock("div",O,[e.createVNode(J,{"current-page":d.pageNum,"onUpdate:currentPage":a[1]||(a[1]=n=>d.pageNum=n),"page-size":d.pageSize,"onUpdate:pageSize":a[2]||(a[2]=n=>d.pageSize=n),"page-sizes":o.pageSizes,layout:o.paginationLayout,total:C.value,background:o.paginationBackground,small:o.paginationSmall,"hide-on-single-page":o.paginationHideOnSinglePage,onSizeChange:I,onCurrentChange:W},null,8,["current-page","page-size","page-sizes","layout","total","background","small","hide-on-single-page"])])):e.createCommentVNode("",!0),e.createVNode(K,{modelValue:l.visible,"onUpdate:modelValue":a[5]||(a[5]=n=>l.visible=n),title:j.value,width:o.dialogWidth,"destroy-on-close":!0,"custom-class":S.value},{footer:e.withCtx(()=>[e.createElementVNode("div",T,[e.createVNode(s,{onClick:a[4]||(a[4]=n=>l.visible=!1)},{default:e.withCtx(()=>a[11]||(a[11]=[e.createTextVNode("取消")])),_:1,__:[11]}),e.createVNode(s,{type:"primary",onClick:M,loading:l.submitting},{default:e.withCtx(()=>a[12]||(a[12]=[e.createTextVNode("确定")])),_:1,__:[12]},8,["loading"])])]),default:e.withCtx(()=>[e.withDirectives((e.openBlock(),e.createElementBlock("div",null,[e.renderSlot(t.$slots,"dialog-form-content",{formData:l.data,mode:l.mode},()=>[o.dialogFormConfig.length>0?(e.openBlock(),e.createBlock(A,{key:0,"form-config":Q.value,modelValue:l.data,"onUpdate:modelValue":a[3]||(a[3]=n=>l.data=n),ref:n=>l.formRef=n,rules:o.dialogFormRules,"label-width":"80px"},null,8,["form-config","modelValue","rules"])):e.createCommentVNode("",!0)])])),[[U,l.loading]])]),_:3},8,["modelValue","title","width","custom-class"])],2)}}});m.CrudTable=q,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
1
+ (function(f,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("element-plus"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","element-plus","axios"],e):(f=typeof globalThis<"u"?globalThis:f||self,e(f.ZCrudTable={},f.Vue,f.ElementPlus,f.axios))})(this,function(f,e,B,A){"use strict";const E=e.defineComponent({__name:"DynamicForm",props:{modelValue:{},formConfig:{},rules:{}},setup(c,{expose:y}){const w=e.ref(null);return y({validate:()=>{var s;return(s=w.value)==null?void 0:s.validate()}}),(s,t)=>{const b=e.resolveComponent("el-input"),N=e.resolveComponent("el-option"),u=e.resolveComponent("el-select"),V=e.resolveComponent("el-radio"),p=e.resolveComponent("el-radio-group"),C=e.resolveComponent("el-form-item"),k=e.resolveComponent("el-form");return e.openBlock(),e.createBlock(k,e.mergeProps({model:s.modelValue,rules:s.rules,ref_key:"formRef",ref:w},s.$attrs),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.formConfig,r=>(e.openBlock(),e.createBlock(C,{key:r.prop,label:r.label,prop:r.prop},{default:e.withCtx(()=>[r.type==="input"?(e.openBlock(),e.createBlock(b,e.mergeProps({key:0,modelValue:s.modelValue[r.prop],"onUpdate:modelValue":d=>s.modelValue[r.prop]=d},{ref_for:!0},r.componentProps),null,16,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),r.type==="textarea"?(e.openBlock(),e.createBlock(b,e.mergeProps({key:1,type:"textarea",modelValue:s.modelValue[r.prop],"onUpdate:modelValue":d=>s.modelValue[r.prop]=d},{ref_for:!0},r.componentProps),null,16,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),r.type==="select"?(e.openBlock(),e.createBlock(u,e.mergeProps({key:2,modelValue:s.modelValue[r.prop],"onUpdate:modelValue":d=>s.modelValue[r.prop]=d},{ref_for:!0},r.componentProps),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.options,d=>(e.openBlock(),e.createBlock(N,{key:d.value,label:d.label,value:d.value},null,8,["label","value"]))),128))]),_:2},1040,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),r.type==="radio-group"?(e.openBlock(),e.createBlock(p,e.mergeProps({key:3,modelValue:s.modelValue[r.prop],"onUpdate:modelValue":d=>s.modelValue[r.prop]=d},{ref_for:!0},r.componentProps),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.options,d=>(e.openBlock(),e.createBlock(V,{key:d.value,label:d.value},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(d.label),1)]),_:2},1032,["label"]))),128))]),_:2},1040,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),r.type==="input-disabled"?(e.openBlock(),e.createBlock(b,e.mergeProps({key:4,"model-value":s.modelValue[r.prop],disabled:""},{ref_for:!0},r.componentProps),null,16,["model-value"])):e.createCommentVNode("",!0)]),_:2},1032,["label","prop"]))),128))]),_:1},16,["model","rules"])}}}),g=A.create({baseURL:"",timeout:1e4});g.interceptors.request.use(c=>{const y=localStorage.getItem("token");return y&&(c.headers.Authorization="Bearer "+y),c},c=>(console.log(c),Promise.reject(c))),g.interceptors.response.use(c=>c.data,c=>(console.log("err"+c),B.ElMessage({message:"接口错误,请刷新接口",type:"error",duration:5*1e3}),Promise.reject(c)));const P={class:"flex flex-wrap items-center justify-between gap-4 mb-6"},z={class:"flex items-center gap-x-2"},$={class:"flex items-center gap-x-3 action-buttons flex-shrink-0"},O={key:0,class:"flex items-center gap-x-2"},T={key:0,class:"flex justify-end"},q={class:"dialog-footer"},j=e.defineComponent({__name:"CrudTable",props:{theme:{type:String,default:"default"},customClass:{type:String,default:""},apiUrlQuery:{type:String,required:!0},apiUrlDetail:{type:String,required:!0},apiUrlCreate:{type:String,required:!0},apiUrlUpdate:{type:String,required:!0},apiUrlDelete:{type:String,required:!0},columns:{type:Array,default:()=>[]},onBeforeQuery:{type:Function},onAfterQuery:{type:Function},onBeforeOpenDialog:{type:Function},onAfterOpenDialog:{type:Function},onBeforeSubmit:{type:Function},onAfterSubmit:{type:Function},onBeforeDelete:{type:Function},onAfterDelete:{type:Function},showSelectionColumn:{type:Boolean,default:!0},showIndexColumn:{type:Boolean,default:!0},showActionsColumn:{type:Boolean,default:!0},showEditButton:{type:Boolean,default:!0},showDeleteButton:{type:Boolean,default:!0},actionsColumnWidth:{type:[String,Number],default:120},dialogWidth:{type:String,default:"50%"},initialSearchForm:{type:Object,default:()=>({pageNum:1,pageSize:10})},showPagination:{type:Boolean,default:!0},pageSizes:{type:Array,default:()=>[10,20,50,100]},paginationLayout:{type:String,default:"total, sizes, prev, pager, next, jumper"},paginationBackground:{type:Boolean,default:!0},paginationSmall:{type:Boolean,default:!1},paginationHideOnSinglePage:{type:Boolean,default:!1},dialogFormConfig:{type:Array,default:()=>[]},dialogFormRules:{type:Object,default:()=>({})}},emits:["open-dialog","submit","delete"],setup(c,{expose:y,emit:w}){const s=w,t=c,b=e.computed(()=>["crud-table-wrapper",`theme-${t.theme}`,t.customClass]),N=e.computed(()=>t.theme==="large-screen"?"large-screen-dialog":""),u=(o,l)=>o?!0:(B.ElMessage.error(`${l} prop is required.`),!1),V=async(o,l)=>{try{let n={...l};if(t.onBeforeSubmit&&(n=await t.onBeforeSubmit(n)),a.submitting=!0,o==="add"){if(!u(t.apiUrlCreate,"apiUrlCreate"))return;await g.post(t.apiUrlCreate,n),B.ElMessage.success("新增成功")}else{if(!u(t.apiUrlUpdate,"apiUrlUpdate"))return;await g.put(t.apiUrlUpdate,n),B.ElMessage.success("更新成功")}return t.onAfterSubmit&&t.onAfterSubmit(o,n),s("submit",{mode:o,data:n}),a.visible&&(a.visible=!1),h(),Promise.resolve()}catch(n){return console.log("Submit error:",n),Promise.reject(n)}finally{a.submitting=!1}},p=e.reactive({pageNum:1,pageSize:10,...t.initialSearchForm}),C=e.ref([]),k=e.ref(0),r=e.ref(!1),d=e.ref([]),a=e.reactive({visible:!1,loading:!1,submitting:!1,mode:"add",data:{},formRef:null}),Q=e.computed(()=>a.mode==="add"?"新增":"编辑"),R=e.computed(()=>{if(a.mode==="add")return t.dialogFormConfig.filter(l=>l.prop!=="id");const o=[...t.dialogFormConfig.filter(l=>l.prop!=="id")];return o.some(l=>l.prop==="id")||o.unshift({type:"input-disabled",prop:"id",label:"用户ID"}),o}),h=async()=>{if(u(t.apiUrlQuery,"apiUrlQuery")){r.value=!0;try{let o={...p};t.onBeforeQuery&&(o=await t.onBeforeQuery(o));const l=await g.get(t.apiUrlQuery,{params:o});if(l&&Array.isArray(l.data)&&typeof l.total=="number"){let n=l.data;t.onAfterQuery&&(n=await t.onAfterQuery(n)),C.value=n,k.value=l.total}else console.warn("API response is not in the expected { data: [], total: 0 } format."),C.value=[],k.value=0}catch(o){console.error("Fetch data failed:",o)}finally{r.value=!1}}},_=()=>{p.pageNum=1,h()},L=()=>{const{pageNum:o,pageSize:l,...n}=t.initialSearchForm;Object.keys(p).forEach(m=>{m!=="pageNum"&&m!=="pageSize"&&delete p[m]}),Object.assign(p,n),_()},M=o=>{d.value=o},D=async(o,l)=>{let n=o==="add"?{role:"user"}:{...l};if(t.onBeforeOpenDialog){const m=await t.onBeforeOpenDialog(o,n);m&&(n=m)}if(a.mode=o,a.visible=!0,o==="edit"){if(!u(t.apiUrlDetail,"apiUrlDetail"))return;a.loading=!0;try{const m=await g.get(t.apiUrlDetail+"/"+n.id);a.data=m.data}finally{a.loading=!1,t.onAfterOpenDialog&&t.onAfterOpenDialog(o,a.data),s("open-dialog",{mode:o,data:a.data})}}else a.data=n,t.onAfterOpenDialog&&t.onAfterOpenDialog(o,a.data),s("open-dialog",{mode:o,data:a.data})},I=async()=>{try{a.formRef&&await a.formRef.validate(),await V(a.mode,a.data)}catch(o){console.log("Validation failed:",o)}},U=async o=>{if(u(t.apiUrlDelete,"apiUrlDelete"))try{if(t.onBeforeDelete&&await t.onBeforeDelete(o)===!1)return;const l=o.join(",");await g.delete(t.apiUrlDelete+"/"+l.toString()),B.ElMessage.success("删除成功"),t.onAfterDelete&&t.onAfterDelete(o),s("delete",o),C.value.length===o.length&&p.pageNum>1&&p.pageNum--,h()}catch(l){console.error("Delete failed",l)}},W=o=>{p.pageSize=o,_()},H=o=>{p.pageNum=o,h()};return e.onMounted(h),y({refresh:h,search:_,handleDelete:U,openDialog:D,submit:V}),(o,l)=>{const n=e.resolveComponent("el-button"),m=e.resolveComponent("el-form-item"),Z=e.resolveComponent("el-form"),S=e.resolveComponent("el-table-column"),G=e.resolveComponent("el-popconfirm"),J=e.resolveComponent("el-table"),K=e.resolveComponent("el-pagination"),X=e.resolveComponent("el-dialog"),F=e.resolveDirective("loading");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(b.value)},[e.renderSlot(o.$slots,"header"),e.createElementVNode("div",P,[e.createVNode(Z,{model:p,class:"query-form flex flex-nowrap items-center gap-x-4",style:{"overflow-x":"auto","padding-bottom":"8px"}},{default:e.withCtx(()=>[e.renderSlot(o.$slots,"query-conditions",{searchForm:p}),e.createVNode(m,{class:"!mr-0 flex-shrink-0"},{default:e.withCtx(()=>[e.createElementVNode("div",z,[e.renderSlot(o.$slots,"query-left"),e.createVNode(n,{style:{"margin-left":"16px"},type:"primary",onClick:_,loading:r.value},{default:e.withCtx(()=>l[6]||(l[6]=[e.createTextVNode("搜索 ")])),_:1,__:[6]},8,["loading"]),e.createVNode(n,{onClick:L},{default:e.withCtx(()=>l[7]||(l[7]=[e.createTextVNode("清空")])),_:1,__:[7]}),e.renderSlot(o.$slots,"query-right")])]),_:3})]),_:3},8,["model"]),e.createElementVNode("div",$,[e.renderSlot(o.$slots,"action-left",{selections:d.value}),e.renderSlot(o.$slots,"add-button-content",{},()=>[e.createVNode(n,{type:"success",onClick:l[0]||(l[0]=i=>D("add"))},{default:e.withCtx(()=>l[8]||(l[8]=[e.createTextVNode("新增")])),_:1,__:[8]})]),e.renderSlot(o.$slots,"action-right")])]),e.withDirectives((e.openBlock(),e.createBlock(J,e.mergeProps({data:C.value,onSelectionChange:M},o.$attrs,{style:{width:"100%","margin-bottom":"1.5rem"}}),{default:e.withCtx(()=>[t.showSelectionColumn?(e.openBlock(),e.createBlock(S,{key:0,type:"selection",width:"55",fixed:""})):e.createCommentVNode("",!0),t.showIndexColumn?(e.openBlock(),e.createBlock(S,{key:1,type:"index",label:"序号",width:"70",fixed:""})):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.columns,i=>(e.openBlock(),e.createBlock(S,e.mergeProps({key:i.prop,prop:i.prop,label:i.label,width:i.width,sortable:i.sortable||!1},{ref_for:!0},i.attrs),e.createSlots({_:2},[i.slot?{name:"default",fn:e.withCtx(x=>[e.renderSlot(o.$slots,i.slot,{row:x.row})]),key:"0"}:void 0]),1040,["prop","label","width","sortable"]))),128)),t.showActionsColumn?(e.openBlock(),e.createBlock(S,{key:2,label:"操作",width:c.actionsColumnWidth},{default:e.withCtx(i=>[i.row?(e.openBlock(),e.createElementBlock("div",O,[e.renderSlot(o.$slots,"actions",{row:i.row},()=>[t.showEditButton?(e.openBlock(),e.createBlock(n,{key:0,size:"small",type:"primary",link:"",onClick:x=>D("edit",i.row)},{default:e.withCtx(()=>l[9]||(l[9]=[e.createTextVNode("编辑 ")])),_:2,__:[9]},1032,["onClick"])):e.createCommentVNode("",!0),t.showDeleteButton?(e.openBlock(),e.createBlock(G,{key:1,title:"确定要删除这条数据吗?",onConfirm:x=>U([i.row.id]),"confirm-button-text":"确定","cancel-button-text":"取消",width:"200"},{reference:e.withCtx(()=>[e.createVNode(n,{size:"small",type:"danger",link:""},{default:e.withCtx(()=>l[10]||(l[10]=[e.createTextVNode("删除")])),_:1,__:[10]})]),_:2},1032,["onConfirm"])):e.createCommentVNode("",!0)])])):e.createCommentVNode("",!0)]),_:3},8,["width"])):e.createCommentVNode("",!0)]),_:3},16,["data"])),[[F,r.value]]),t.showPagination&&k.value>0?(e.openBlock(),e.createElementBlock("div",T,[e.createVNode(K,{"current-page":p.pageNum,"onUpdate:currentPage":l[1]||(l[1]=i=>p.pageNum=i),"page-size":p.pageSize,"onUpdate:pageSize":l[2]||(l[2]=i=>p.pageSize=i),"page-sizes":t.pageSizes,layout:t.paginationLayout,total:k.value,background:t.paginationBackground,small:t.paginationSmall,"hide-on-single-page":t.paginationHideOnSinglePage,onSizeChange:W,onCurrentChange:H},null,8,["current-page","page-size","page-sizes","layout","total","background","small","hide-on-single-page"])])):e.createCommentVNode("",!0),e.createVNode(X,{modelValue:a.visible,"onUpdate:modelValue":l[5]||(l[5]=i=>a.visible=i),title:Q.value,width:t.dialogWidth,"destroy-on-close":!0,"custom-class":N.value},{footer:e.withCtx(()=>[e.createElementVNode("div",q,[e.createVNode(n,{onClick:l[4]||(l[4]=i=>a.visible=!1)},{default:e.withCtx(()=>l[11]||(l[11]=[e.createTextVNode("取消")])),_:1,__:[11]}),e.createVNode(n,{type:"primary",onClick:I,loading:a.submitting},{default:e.withCtx(()=>l[12]||(l[12]=[e.createTextVNode("确定")])),_:1,__:[12]},8,["loading"])])]),default:e.withCtx(()=>[e.withDirectives((e.openBlock(),e.createElementBlock("div",null,[e.renderSlot(o.$slots,"dialog-form-content",{formData:a.data,mode:a.mode},()=>[t.dialogFormConfig.length>0?(e.openBlock(),e.createBlock(E,{key:0,"form-config":R.value,modelValue:a.data,"onUpdate:modelValue":l[3]||(l[3]=i=>a.data=i),ref:i=>a.formRef=i,rules:t.dialogFormRules,"label-width":"80px"},null,8,["form-config","modelValue","rules"])):e.createCommentVNode("",!0)])])),[[F,a.loading]])]),_:3},8,["modelValue","title","width","custom-class"])],2)}}});f.CrudTable=j,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "z-crud-table",
3
3
  "private": false,
4
- "version": "0.0.14",
4
+ "version": "0.0.15",
5
5
  "type": "module",
6
6
  "description": "A powerful and flexible CRUD table component for Vue 3 and Element Plus.",
7
7
  "keywords": [