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