z-crud-table 0.0.22 → 0.0.23
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/components/CrudTable.vue.d.ts +9 -0
- package/dist/z-crud-table.js +155 -153
- package/dist/z-crud-table.umd.cjs +1 -1
- package/package.json +1 -1
|
@@ -37,6 +37,10 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<im
|
|
|
37
37
|
type: BooleanConstructor;
|
|
38
38
|
default: boolean;
|
|
39
39
|
};
|
|
40
|
+
showSearchActionButtons: {
|
|
41
|
+
type: BooleanConstructor;
|
|
42
|
+
default: boolean;
|
|
43
|
+
};
|
|
40
44
|
showNewBtn: {
|
|
41
45
|
type: BooleanConstructor;
|
|
42
46
|
default: boolean;
|
|
@@ -183,6 +187,10 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<im
|
|
|
183
187
|
type: BooleanConstructor;
|
|
184
188
|
default: boolean;
|
|
185
189
|
};
|
|
190
|
+
showSearchActionButtons: {
|
|
191
|
+
type: BooleanConstructor;
|
|
192
|
+
default: boolean;
|
|
193
|
+
};
|
|
186
194
|
showNewBtn: {
|
|
187
195
|
type: BooleanConstructor;
|
|
188
196
|
default: boolean;
|
|
@@ -290,6 +298,7 @@ declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<im
|
|
|
290
298
|
customClass: string;
|
|
291
299
|
theme: "default" | "large-screen";
|
|
292
300
|
showSearchSection: boolean;
|
|
301
|
+
showSearchActionButtons: boolean;
|
|
293
302
|
showNewBtn: boolean;
|
|
294
303
|
columns: any[];
|
|
295
304
|
showSelectionColumn: boolean;
|
package/dist/z-crud-table.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineComponent as H, ref as
|
|
2
|
-
import { ElMessage as
|
|
1
|
+
import { defineComponent as H, ref as F, resolveComponent as g, createBlock as p, openBlock as n, mergeProps as _, withCtx as u, createElementBlock as b, Fragment as V, renderList as q, createCommentVNode as m, createTextVNode as v, toDisplayString as re, computed as j, reactive as T, onMounted as ne, resolveDirective as ie, normalizeClass as se, renderSlot as y, withDirectives as W, createVNode as w, createElementVNode as E, createSlots as ue } from "vue";
|
|
2
|
+
import { ElMessage as $ } from "element-plus";
|
|
3
3
|
import de from "axios";
|
|
4
4
|
const pe = /* @__PURE__ */ H({
|
|
5
5
|
__name: "DynamicForm",
|
|
@@ -8,34 +8,34 @@ const pe = /* @__PURE__ */ H({
|
|
|
8
8
|
formConfig: {},
|
|
9
9
|
rules: {}
|
|
10
10
|
},
|
|
11
|
-
setup(c, { expose:
|
|
12
|
-
const z =
|
|
13
|
-
return
|
|
11
|
+
setup(c, { expose: k }) {
|
|
12
|
+
const z = F(null);
|
|
13
|
+
return k({
|
|
14
14
|
validate: () => {
|
|
15
15
|
var s;
|
|
16
16
|
return (s = z.value) == null ? void 0 : s.validate();
|
|
17
17
|
}
|
|
18
|
-
}), (s,
|
|
19
|
-
const
|
|
20
|
-
return n(), p(
|
|
18
|
+
}), (s, e) => {
|
|
19
|
+
const A = g("el-input"), Q = g("el-option"), S = g("el-select"), N = g("el-radio"), f = g("el-radio-group"), D = g("el-form-item"), B = g("el-form");
|
|
20
|
+
return n(), p(B, _({
|
|
21
21
|
model: s.modelValue,
|
|
22
22
|
rules: s.rules,
|
|
23
23
|
ref_key: "formRef",
|
|
24
24
|
ref: z
|
|
25
25
|
}, s.$attrs), {
|
|
26
26
|
default: u(() => [
|
|
27
|
-
(n(!0),
|
|
27
|
+
(n(!0), b(V, null, q(s.formConfig, (r) => (n(), p(D, {
|
|
28
28
|
key: r.prop,
|
|
29
29
|
label: r.label,
|
|
30
30
|
prop: r.prop
|
|
31
31
|
}, {
|
|
32
32
|
default: u(() => [
|
|
33
|
-
r.type === "input" ? (n(), p(
|
|
33
|
+
r.type === "input" ? (n(), p(A, _({
|
|
34
34
|
key: 0,
|
|
35
35
|
modelValue: s.modelValue[r.prop],
|
|
36
36
|
"onUpdate:modelValue": (d) => s.modelValue[r.prop] = d
|
|
37
37
|
}, { ref_for: !0 }, r.componentProps), null, 16, ["modelValue", "onUpdate:modelValue"])) : m("", !0),
|
|
38
|
-
r.type === "textarea" ? (n(), p(
|
|
38
|
+
r.type === "textarea" ? (n(), p(A, _({
|
|
39
39
|
key: 1,
|
|
40
40
|
type: "textarea",
|
|
41
41
|
modelValue: s.modelValue[r.prop],
|
|
@@ -47,7 +47,7 @@ const pe = /* @__PURE__ */ H({
|
|
|
47
47
|
"onUpdate:modelValue": (d) => s.modelValue[r.prop] = d
|
|
48
48
|
}, { ref_for: !0 }, r.componentProps), {
|
|
49
49
|
default: u(() => [
|
|
50
|
-
(n(!0),
|
|
50
|
+
(n(!0), b(V, null, q(r.options, (d) => (n(), p(Q, {
|
|
51
51
|
key: d.value,
|
|
52
52
|
label: d.label,
|
|
53
53
|
value: d.value
|
|
@@ -61,7 +61,7 @@ const pe = /* @__PURE__ */ H({
|
|
|
61
61
|
"onUpdate:modelValue": (d) => s.modelValue[r.prop] = d
|
|
62
62
|
}, { ref_for: !0 }, r.componentProps), {
|
|
63
63
|
default: u(() => [
|
|
64
|
-
(n(!0),
|
|
64
|
+
(n(!0), b(V, null, q(r.options, (d) => (n(), p(N, {
|
|
65
65
|
key: d.value,
|
|
66
66
|
label: d.value
|
|
67
67
|
}, {
|
|
@@ -73,7 +73,7 @@ const pe = /* @__PURE__ */ H({
|
|
|
73
73
|
]),
|
|
74
74
|
_: 2
|
|
75
75
|
}, 1040, ["modelValue", "onUpdate:modelValue"])) : m("", !0),
|
|
76
|
-
r.type === "input-disabled" ? (n(), p(
|
|
76
|
+
r.type === "input-disabled" ? (n(), p(A, _({
|
|
77
77
|
key: 4,
|
|
78
78
|
"model-value": s.modelValue[r.prop],
|
|
79
79
|
disabled: ""
|
|
@@ -95,14 +95,14 @@ const pe = /* @__PURE__ */ H({
|
|
|
95
95
|
});
|
|
96
96
|
C.interceptors.request.use(
|
|
97
97
|
(c) => {
|
|
98
|
-
const
|
|
99
|
-
return
|
|
98
|
+
const k = localStorage.getItem("token");
|
|
99
|
+
return k && (c.headers.Authorization = "Bearer " + k), c;
|
|
100
100
|
},
|
|
101
101
|
(c) => (console.log(c), Promise.reject(c))
|
|
102
102
|
);
|
|
103
103
|
C.interceptors.response.use(
|
|
104
104
|
(c) => c.data,
|
|
105
|
-
(c) => (console.log("err" + c),
|
|
105
|
+
(c) => (console.log("err" + c), $({
|
|
106
106
|
message: "接口错误,请刷新接口",
|
|
107
107
|
// 这里是您要求的统一错误提示
|
|
108
108
|
type: "error",
|
|
@@ -134,7 +134,8 @@ const fe = {
|
|
|
134
134
|
apiUrlUpdate: { type: String, required: !0 },
|
|
135
135
|
apiUrlDelete: { type: String, required: !0 },
|
|
136
136
|
showSearchSection: { type: Boolean, default: !0 },
|
|
137
|
-
// ✨
|
|
137
|
+
// ✨ [新增] 控制搜索/清空按钮的显示
|
|
138
|
+
showSearchActionButtons: { type: Boolean, default: !0 },
|
|
138
139
|
// 控制新增按钮
|
|
139
140
|
showNewBtn: { type: Boolean, default: !0 },
|
|
140
141
|
// 表格列定义,通过配置数组动态渲染,比 slot 更灵活。
|
|
@@ -157,7 +158,6 @@ const fe = {
|
|
|
157
158
|
showActionsColumn: { type: Boolean, default: !0 },
|
|
158
159
|
showEditButton: { type: Boolean, default: !0 },
|
|
159
160
|
showDeleteButton: { type: Boolean, default: !0 },
|
|
160
|
-
showNewBtn: { type: Boolean, default: !0 },
|
|
161
161
|
// UI 定制化配置
|
|
162
162
|
actionsColumnWidth: { type: [String, Number], default: 120 },
|
|
163
163
|
dialogWidth: { type: String, default: "50%" },
|
|
@@ -174,94 +174,94 @@ const fe = {
|
|
|
174
174
|
dialogFormRules: { type: Object, default: () => ({}) }
|
|
175
175
|
},
|
|
176
176
|
emits: ["open-dialog", "submit", "delete"],
|
|
177
|
-
setup(c, { expose:
|
|
178
|
-
const s = z,
|
|
177
|
+
setup(c, { expose: k, emit: z }) {
|
|
178
|
+
const s = z, e = c, A = j(() => ["crud-table-wrapper", `theme-${e.theme}`, e.customClass]), Q = j(() => e.theme === "large-screen" ? "large-screen-dialog" : ""), S = (t, o) => t ? !0 : ($.error(`${o} prop is required.`), !1), N = async (t, o) => {
|
|
179
179
|
try {
|
|
180
|
-
let
|
|
181
|
-
if (
|
|
182
|
-
if (!S(
|
|
183
|
-
await C.post(
|
|
180
|
+
let a = { ...o };
|
|
181
|
+
if (e.onBeforeSubmit && (a = await e.onBeforeSubmit(a)), l.submitting = !0, t === "add") {
|
|
182
|
+
if (!S(e.apiUrlCreate, "apiUrlCreate")) return;
|
|
183
|
+
await C.post(e.apiUrlCreate, a), $.success("新增成功");
|
|
184
184
|
} else {
|
|
185
|
-
if (!S(
|
|
186
|
-
await C.put(
|
|
185
|
+
if (!S(e.apiUrlUpdate, "apiUrlUpdate")) return;
|
|
186
|
+
await C.put(e.apiUrlUpdate, a), $.success("更新成功");
|
|
187
187
|
}
|
|
188
|
-
return
|
|
189
|
-
} catch (
|
|
190
|
-
return console.log("Submit error:",
|
|
188
|
+
return e.onAfterSubmit && e.onAfterSubmit(t, a), s("submit", { mode: t, data: a }), l.visible && (l.visible = !1), U(), Promise.resolve();
|
|
189
|
+
} catch (a) {
|
|
190
|
+
return console.log("Submit error:", a), Promise.reject(a);
|
|
191
191
|
} finally {
|
|
192
|
-
|
|
192
|
+
l.submitting = !1;
|
|
193
193
|
}
|
|
194
|
-
}, f = T({ pageNum: 1, pageSize: 10, ...
|
|
195
|
-
if (
|
|
196
|
-
const
|
|
197
|
-
return
|
|
198
|
-
}),
|
|
199
|
-
if (S(
|
|
194
|
+
}, f = T({ pageNum: 1, pageSize: 10, ...e.initialSearchForm }), D = F([]), B = F(0), r = F(!1), d = F([]), l = T({ visible: !1, loading: !1, submitting: !1, mode: "add", data: {}, formRef: null }), M = j(() => l.mode === "add" ? "新增" : "编辑"), G = j(() => {
|
|
195
|
+
if (l.mode === "add") return e.dialogFormConfig.filter((o) => o.prop !== "id");
|
|
196
|
+
const t = [...e.dialogFormConfig.filter((o) => o.prop !== "id")];
|
|
197
|
+
return t.some((o) => o.prop === "id") || t.unshift({ type: "input-disabled", prop: "id", label: "用户ID" }), t;
|
|
198
|
+
}), U = async () => {
|
|
199
|
+
if (S(e.apiUrlQuery, "apiUrlQuery")) {
|
|
200
200
|
r.value = !0;
|
|
201
201
|
try {
|
|
202
|
-
let
|
|
203
|
-
|
|
204
|
-
const o = await C.get(
|
|
205
|
-
if (o && Array.isArray(o.data.rows) && typeof o.data.total == "number") {
|
|
206
|
-
let
|
|
207
|
-
|
|
202
|
+
let t = { ...f };
|
|
203
|
+
e.onBeforeQuery && (t = await e.onBeforeQuery(t));
|
|
204
|
+
const o = await C.get(e.apiUrlQuery, { params: t });
|
|
205
|
+
if (o && o.data && Array.isArray(o.data.rows) && typeof o.data.total == "number") {
|
|
206
|
+
let a = o.data.rows;
|
|
207
|
+
e.onAfterQuery && (a = await e.onAfterQuery(a)), D.value = a, B.value = o.data.total;
|
|
208
208
|
} else
|
|
209
|
-
console.warn("API response is not in the expected { data: [], total: 0 } format."),
|
|
210
|
-
} catch (
|
|
211
|
-
console.error("Fetch data failed:",
|
|
209
|
+
console.warn("API response is not in the expected { data: { rows: [], total: 0 } } format."), D.value = [], B.value = 0;
|
|
210
|
+
} catch (t) {
|
|
211
|
+
console.error("Fetch data failed:", t);
|
|
212
212
|
} finally {
|
|
213
213
|
r.value = !1;
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}, P = () => {
|
|
217
|
-
f.pageNum = 1,
|
|
217
|
+
f.pageNum = 1, U();
|
|
218
218
|
}, J = () => {
|
|
219
|
-
const { pageNum:
|
|
220
|
-
Object.keys(f).forEach((
|
|
221
|
-
|
|
222
|
-
}), Object.assign(f,
|
|
223
|
-
}, K = (
|
|
224
|
-
d.value =
|
|
225
|
-
}, x = async (
|
|
226
|
-
let
|
|
227
|
-
if (
|
|
228
|
-
const
|
|
229
|
-
|
|
219
|
+
const { pageNum: t, pageSize: o, ...a } = e.initialSearchForm;
|
|
220
|
+
Object.keys(f).forEach((h) => {
|
|
221
|
+
h !== "pageNum" && h !== "pageSize" && delete f[h];
|
|
222
|
+
}), Object.assign(f, a), P();
|
|
223
|
+
}, K = (t) => {
|
|
224
|
+
d.value = t;
|
|
225
|
+
}, x = async (t, o) => {
|
|
226
|
+
let a;
|
|
227
|
+
if (t === "add" ? a = o ? { ...o } : { role: "user" } : a = { ...o }, e.onBeforeOpenDialog) {
|
|
228
|
+
const h = await e.onBeforeOpenDialog(t, a);
|
|
229
|
+
h && (a = h);
|
|
230
230
|
}
|
|
231
|
-
if (
|
|
232
|
-
if (!S(
|
|
233
|
-
|
|
231
|
+
if (l.mode = t, l.visible = !0, t === "edit") {
|
|
232
|
+
if (!S(e.apiUrlDetail, "apiUrlDetail")) return;
|
|
233
|
+
l.loading = !0;
|
|
234
234
|
try {
|
|
235
|
-
const
|
|
236
|
-
|
|
235
|
+
const h = await C.get(e.apiUrlDetail + "/" + a.id.toString());
|
|
236
|
+
l.data = h.data.data;
|
|
237
237
|
} finally {
|
|
238
|
-
|
|
238
|
+
l.loading = !1, e.onAfterOpenDialog && e.onAfterOpenDialog(t, l.data), s("open-dialog", { mode: t, data: l.data });
|
|
239
239
|
}
|
|
240
240
|
} else
|
|
241
|
-
|
|
241
|
+
l.data = a, e.onAfterOpenDialog && e.onAfterOpenDialog(t, l.data), s("open-dialog", { mode: t, data: l.data });
|
|
242
242
|
}, X = async () => {
|
|
243
243
|
try {
|
|
244
|
-
|
|
245
|
-
} catch (
|
|
246
|
-
console.log("Validation failed:",
|
|
244
|
+
l.formRef && await l.formRef.validate(), await N(l.mode, l.data);
|
|
245
|
+
} catch (t) {
|
|
246
|
+
console.log("Validation failed:", t);
|
|
247
247
|
}
|
|
248
|
-
}, I = async (
|
|
249
|
-
if (S(
|
|
248
|
+
}, I = async (t) => {
|
|
249
|
+
if (S(e.apiUrlDelete, "apiUrlDelete"))
|
|
250
250
|
try {
|
|
251
|
-
if (
|
|
251
|
+
if (e.onBeforeDelete && await e.onBeforeDelete(t) === !1)
|
|
252
252
|
return;
|
|
253
|
-
const o =
|
|
254
|
-
await C.delete(
|
|
253
|
+
const o = t.join(",");
|
|
254
|
+
await C.delete(e.apiUrlDelete + "/" + o.toString()), $.success("删除成功"), e.onAfterDelete && e.onAfterDelete(t), s("delete", t), D.value.length === t.length && f.pageNum > 1 && f.pageNum--, U();
|
|
255
255
|
} catch (o) {
|
|
256
256
|
console.error("Delete failed", o);
|
|
257
257
|
}
|
|
258
|
-
}, Y = (
|
|
259
|
-
f.pageSize =
|
|
260
|
-
}, Z = (
|
|
261
|
-
f.pageNum =
|
|
258
|
+
}, Y = (t) => {
|
|
259
|
+
f.pageSize = t, P();
|
|
260
|
+
}, Z = (t) => {
|
|
261
|
+
f.pageNum = t, U();
|
|
262
262
|
};
|
|
263
|
-
return ne(
|
|
264
|
-
refresh:
|
|
263
|
+
return ne(U), k({
|
|
264
|
+
refresh: U,
|
|
265
265
|
// 刷新表格
|
|
266
266
|
search: P,
|
|
267
267
|
// 按当前条件搜索
|
|
@@ -271,43 +271,45 @@ const fe = {
|
|
|
271
271
|
// 手动打开弹窗
|
|
272
272
|
submit: N
|
|
273
273
|
// 手动提交
|
|
274
|
-
}), (
|
|
275
|
-
const
|
|
276
|
-
return n(),
|
|
277
|
-
class: se(
|
|
274
|
+
}), (t, o) => {
|
|
275
|
+
const a = g("el-button"), h = g("el-form-item"), ee = g("el-form"), O = g("el-table-column"), te = g("el-popconfirm"), oe = g("el-table"), ae = g("el-pagination"), le = g("el-dialog"), L = ie("loading");
|
|
276
|
+
return n(), b("div", {
|
|
277
|
+
class: se(A.value)
|
|
278
278
|
}, [
|
|
279
|
-
y(
|
|
280
|
-
|
|
281
|
-
|
|
279
|
+
y(t.$slots, "header"),
|
|
280
|
+
e.showSearchSection ? (n(), b("div", fe, [
|
|
281
|
+
w(ee, {
|
|
282
282
|
model: f,
|
|
283
283
|
class: "query-form flex flex-nowrap items-center gap-x-4",
|
|
284
284
|
style: { "overflow-x": "auto", "padding-bottom": "8px" }
|
|
285
285
|
}, {
|
|
286
286
|
default: u(() => [
|
|
287
|
-
y(
|
|
288
|
-
h
|
|
287
|
+
y(t.$slots, "query-conditions", { searchForm: f }),
|
|
288
|
+
w(h, { class: "!mr-0 flex-shrink-0" }, {
|
|
289
289
|
default: u(() => [
|
|
290
290
|
E("div", me, [
|
|
291
|
-
y(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
291
|
+
y(t.$slots, "query-left"),
|
|
292
|
+
e.showSearchActionButtons ? (n(), b(V, { key: 0 }, [
|
|
293
|
+
w(a, {
|
|
294
|
+
type: "primary",
|
|
295
|
+
onClick: P,
|
|
296
|
+
loading: r.value
|
|
297
|
+
}, {
|
|
298
|
+
default: u(() => o[6] || (o[6] = [
|
|
299
|
+
v("搜索")
|
|
300
|
+
])),
|
|
301
|
+
_: 1,
|
|
302
|
+
__: [6]
|
|
303
|
+
}, 8, ["loading"]),
|
|
304
|
+
w(a, { onClick: J }, {
|
|
305
|
+
default: u(() => o[7] || (o[7] = [
|
|
306
|
+
v("清空")
|
|
307
|
+
])),
|
|
308
|
+
_: 1,
|
|
309
|
+
__: [7]
|
|
310
|
+
})
|
|
311
|
+
], 64)) : m("", !0),
|
|
312
|
+
y(t.$slots, "query-right")
|
|
311
313
|
])
|
|
312
314
|
]),
|
|
313
315
|
_: 3
|
|
@@ -316,9 +318,9 @@ const fe = {
|
|
|
316
318
|
_: 3
|
|
317
319
|
}, 8, ["model"]),
|
|
318
320
|
E("div", ge, [
|
|
319
|
-
y(
|
|
320
|
-
y(
|
|
321
|
-
|
|
321
|
+
y(t.$slots, "action-left", { selections: d.value }),
|
|
322
|
+
y(t.$slots, "add-button-content", {}, () => [
|
|
323
|
+
e.showNewBtn ? (n(), p(a, {
|
|
322
324
|
key: 0,
|
|
323
325
|
type: "success",
|
|
324
326
|
onClick: o[0] || (o[0] = (i) => x("add"))
|
|
@@ -330,28 +332,28 @@ const fe = {
|
|
|
330
332
|
__: [8]
|
|
331
333
|
})) : m("", !0)
|
|
332
334
|
]),
|
|
333
|
-
y(
|
|
335
|
+
y(t.$slots, "action-right")
|
|
334
336
|
])
|
|
335
337
|
])) : m("", !0),
|
|
336
338
|
W((n(), p(oe, _({
|
|
337
|
-
data:
|
|
339
|
+
data: D.value,
|
|
338
340
|
onSelectionChange: K
|
|
339
|
-
},
|
|
341
|
+
}, t.$attrs, { style: { width: "100%", "margin-bottom": "1.5rem" } }), {
|
|
340
342
|
default: u(() => [
|
|
341
|
-
|
|
343
|
+
e.showSelectionColumn ? (n(), p(O, {
|
|
342
344
|
key: 0,
|
|
343
345
|
type: "selection",
|
|
344
346
|
width: "55",
|
|
345
347
|
fixed: ""
|
|
346
348
|
})) : m("", !0),
|
|
347
|
-
|
|
349
|
+
e.showIndexColumn ? (n(), p(O, {
|
|
348
350
|
key: 1,
|
|
349
351
|
type: "index",
|
|
350
352
|
label: "序号",
|
|
351
353
|
width: "70",
|
|
352
354
|
fixed: ""
|
|
353
355
|
})) : m("", !0),
|
|
354
|
-
(n(!0),
|
|
356
|
+
(n(!0), b(V, null, q(e.columns, (i) => (n(), p(O, _({
|
|
355
357
|
key: i.prop,
|
|
356
358
|
prop: i.prop,
|
|
357
359
|
label: i.label,
|
|
@@ -361,28 +363,28 @@ const fe = {
|
|
|
361
363
|
i.slot ? {
|
|
362
364
|
name: "default",
|
|
363
365
|
fn: u((R) => [
|
|
364
|
-
y(
|
|
366
|
+
y(t.$slots, i.slot, {
|
|
365
367
|
row: R.row
|
|
366
368
|
})
|
|
367
369
|
]),
|
|
368
370
|
key: "0"
|
|
369
371
|
} : void 0
|
|
370
372
|
]), 1040, ["prop", "label", "width", "sortable"]))), 128)),
|
|
371
|
-
|
|
373
|
+
e.showActionsColumn ? (n(), p(O, {
|
|
372
374
|
key: 2,
|
|
373
375
|
label: "操作",
|
|
374
376
|
width: c.actionsColumnWidth
|
|
375
377
|
}, {
|
|
376
378
|
default: u((i) => [
|
|
377
|
-
i.row ? (n(),
|
|
378
|
-
|
|
379
|
+
i.row ? (n(), b("div", ce, [
|
|
380
|
+
t.$slots.actions ? y(t.$slots, "actions", {
|
|
379
381
|
key: 0,
|
|
380
382
|
row: i.row
|
|
381
|
-
}) : (n(),
|
|
382
|
-
y(
|
|
383
|
+
}) : (n(), b(V, { key: 1 }, [
|
|
384
|
+
y(t.$slots, "action-before-edit", {
|
|
383
385
|
row: i.row
|
|
384
386
|
}),
|
|
385
|
-
|
|
387
|
+
e.showEditButton ? (n(), p(a, {
|
|
386
388
|
key: 0,
|
|
387
389
|
size: "small",
|
|
388
390
|
type: "primary",
|
|
@@ -395,7 +397,7 @@ const fe = {
|
|
|
395
397
|
_: 2,
|
|
396
398
|
__: [9]
|
|
397
399
|
}, 1032, ["onClick"])) : m("", !0),
|
|
398
|
-
|
|
400
|
+
e.showDeleteButton ? (n(), p(te, {
|
|
399
401
|
key: 1,
|
|
400
402
|
title: "确定要删除这条数据吗?",
|
|
401
403
|
onConfirm: (R) => I([i.row.id]),
|
|
@@ -404,7 +406,7 @@ const fe = {
|
|
|
404
406
|
width: "200"
|
|
405
407
|
}, {
|
|
406
408
|
reference: u(() => [
|
|
407
|
-
|
|
409
|
+
w(a, {
|
|
408
410
|
size: "small",
|
|
409
411
|
type: "danger",
|
|
410
412
|
link: ""
|
|
@@ -418,7 +420,7 @@ const fe = {
|
|
|
418
420
|
]),
|
|
419
421
|
_: 2
|
|
420
422
|
}, 1032, ["onConfirm"])) : m("", !0),
|
|
421
|
-
y(
|
|
423
|
+
y(t.$slots, "action-after-delete", {
|
|
422
424
|
row: i.row
|
|
423
425
|
})
|
|
424
426
|
], 64))
|
|
@@ -431,34 +433,34 @@ const fe = {
|
|
|
431
433
|
}, 16, ["data"])), [
|
|
432
434
|
[L, r.value]
|
|
433
435
|
]),
|
|
434
|
-
|
|
435
|
-
|
|
436
|
+
e.showPagination && B.value > 0 ? (n(), b("div", ye, [
|
|
437
|
+
w(ae, {
|
|
436
438
|
"current-page": f.pageNum,
|
|
437
439
|
"onUpdate:currentPage": o[1] || (o[1] = (i) => f.pageNum = i),
|
|
438
440
|
"page-size": f.pageSize,
|
|
439
441
|
"onUpdate:pageSize": o[2] || (o[2] = (i) => f.pageSize = i),
|
|
440
|
-
"page-sizes":
|
|
441
|
-
layout:
|
|
442
|
-
total:
|
|
443
|
-
background:
|
|
444
|
-
small:
|
|
445
|
-
"hide-on-single-page":
|
|
442
|
+
"page-sizes": e.pageSizes,
|
|
443
|
+
layout: e.paginationLayout,
|
|
444
|
+
total: B.value,
|
|
445
|
+
background: e.paginationBackground,
|
|
446
|
+
small: e.paginationSmall,
|
|
447
|
+
"hide-on-single-page": e.paginationHideOnSinglePage,
|
|
446
448
|
onSizeChange: Y,
|
|
447
449
|
onCurrentChange: Z
|
|
448
450
|
}, null, 8, ["current-page", "page-size", "page-sizes", "layout", "total", "background", "small", "hide-on-single-page"])
|
|
449
451
|
])) : m("", !0),
|
|
450
|
-
|
|
451
|
-
modelValue:
|
|
452
|
-
"onUpdate:modelValue": o[5] || (o[5] = (i) =>
|
|
452
|
+
w(le, {
|
|
453
|
+
modelValue: l.visible,
|
|
454
|
+
"onUpdate:modelValue": o[5] || (o[5] = (i) => l.visible = i),
|
|
453
455
|
title: M.value,
|
|
454
|
-
width:
|
|
456
|
+
width: e.dialogWidth,
|
|
455
457
|
"destroy-on-close": !0,
|
|
456
458
|
"custom-class": Q.value
|
|
457
459
|
}, {
|
|
458
460
|
footer: u(() => [
|
|
459
461
|
E("div", be, [
|
|
460
|
-
|
|
461
|
-
onClick: o[4] || (o[4] = (i) =>
|
|
462
|
+
w(a, {
|
|
463
|
+
onClick: o[4] || (o[4] = (i) => l.visible = !1)
|
|
462
464
|
}, {
|
|
463
465
|
default: u(() => o[11] || (o[11] = [
|
|
464
466
|
v("取消")
|
|
@@ -466,10 +468,10 @@ const fe = {
|
|
|
466
468
|
_: 1,
|
|
467
469
|
__: [11]
|
|
468
470
|
}),
|
|
469
|
-
|
|
471
|
+
w(a, {
|
|
470
472
|
type: "primary",
|
|
471
473
|
onClick: X,
|
|
472
|
-
loading:
|
|
474
|
+
loading: l.submitting
|
|
473
475
|
}, {
|
|
474
476
|
default: u(() => o[12] || (o[12] = [
|
|
475
477
|
v("确定")
|
|
@@ -480,23 +482,23 @@ const fe = {
|
|
|
480
482
|
])
|
|
481
483
|
]),
|
|
482
484
|
default: u(() => [
|
|
483
|
-
W((n(),
|
|
484
|
-
y(
|
|
485
|
-
formData:
|
|
486
|
-
mode:
|
|
485
|
+
W((n(), b("div", null, [
|
|
486
|
+
y(t.$slots, "dialog-form-content", {
|
|
487
|
+
formData: l.data,
|
|
488
|
+
mode: l.mode
|
|
487
489
|
}, () => [
|
|
488
|
-
|
|
490
|
+
e.dialogFormConfig.length > 0 ? (n(), p(pe, {
|
|
489
491
|
key: 0,
|
|
490
492
|
"form-config": G.value,
|
|
491
|
-
modelValue:
|
|
492
|
-
"onUpdate:modelValue": o[3] || (o[3] = (i) =>
|
|
493
|
-
ref: (i) =>
|
|
494
|
-
rules:
|
|
493
|
+
modelValue: l.data,
|
|
494
|
+
"onUpdate:modelValue": o[3] || (o[3] = (i) => l.data = i),
|
|
495
|
+
ref: (i) => l.formRef = i,
|
|
496
|
+
rules: e.dialogFormRules,
|
|
495
497
|
"label-width": "80px"
|
|
496
498
|
}, null, 8, ["form-config", "modelValue", "rules"])) : m("", !0)
|
|
497
499
|
])
|
|
498
500
|
])), [
|
|
499
|
-
[L,
|
|
501
|
+
[L, l.loading]
|
|
500
502
|
])
|
|
501
503
|
]),
|
|
502
504
|
_: 3
|
|
@@ -1 +1 @@
|
|
|
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,h,A){"use strict";const E=e.defineComponent({__name:"DynamicForm",props:{modelValue:{},formConfig:{},rules:{}},setup(c,{expose:y}){const b=e.ref(null);return y({validate:()=>{var s;return(s=b.value)==null?void 0:s.validate()}}),(s,o)=>{const w=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:b},s.$attrs),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.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(w,e.mergeProps({key:0,modelValue:s.modelValue[n.prop],"onUpdate:modelValue":d=>s.modelValue[n.prop]=d},{ref_for:!0},n.componentProps),null,16,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),n.type==="textarea"?(e.openBlock(),e.createBlock(w,e.mergeProps({key:1,type:"textarea",modelValue:s.modelValue[n.prop],"onUpdate:modelValue":d=>s.modelValue[n.prop]=d},{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:s.modelValue[n.prop],"onUpdate:modelValue":d=>s.modelValue[n.prop]=d},{ref_for:!0},n.componentProps),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.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),n.type==="radio-group"?(e.openBlock(),e.createBlock(p,e.mergeProps({key:3,modelValue:s.modelValue[n.prop],"onUpdate:modelValue":d=>s.modelValue[n.prop]=d},{ref_for:!0},n.componentProps),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.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),n.type==="input-disabled"?(e.openBlock(),e.createBlock(w,e.mergeProps({key:4,"model-value":s.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"])}}}),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),h.ElMessage({message:"接口错误,请刷新接口",type:"error",duration:5*1e3}),Promise.reject(c)));const $={key:0,class:"flex flex-wrap items-center justify-between gap-4 mb-6"},z={class:"flex items-center gap-x-2"},P={class:"flex items-center gap-x-3 action-buttons flex-shrink-0"},O={key:0,class:"flex items-center gap-x-2"},T={key:1,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},showSearchSection:{type:Boolean,default:!0},showNewBtn:{type:Boolean,default:!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},showNewBtn:{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:b}){const s=b,o=c,w=e.computed(()=>["crud-table-wrapper",`theme-${o.theme}`,o.customClass]),N=e.computed(()=>o.theme==="large-screen"?"large-screen-dialog":""),u=(t,l)=>t?!0:(h.ElMessage.error(`${l} prop is required.`),!1),V=async(t,l)=>{try{let a={...l};if(o.onBeforeSubmit&&(a=await o.onBeforeSubmit(a)),r.submitting=!0,t==="add"){if(!u(o.apiUrlCreate,"apiUrlCreate"))return;await g.post(o.apiUrlCreate,a),h.ElMessage.success("新增成功")}else{if(!u(o.apiUrlUpdate,"apiUrlUpdate"))return;await g.put(o.apiUrlUpdate,a),h.ElMessage.success("更新成功")}return o.onAfterSubmit&&o.onAfterSubmit(t,a),s("submit",{mode:t,data:a}),r.visible&&(r.visible=!1),B(),Promise.resolve()}catch(a){return console.log("Submit error:",a),Promise.reject(a)}finally{r.submitting=!1}},p=e.reactive({pageNum:1,pageSize:10,...o.initialSearchForm}),C=e.ref([]),k=e.ref(0),n=e.ref(!1),d=e.ref([]),r=e.reactive({visible:!1,loading:!1,submitting:!1,mode:"add",data:{},formRef:null}),Q=e.computed(()=>r.mode==="add"?"新增":"编辑"),R=e.computed(()=>{if(r.mode==="add")return o.dialogFormConfig.filter(l=>l.prop!=="id");const t=[...o.dialogFormConfig.filter(l=>l.prop!=="id")];return t.some(l=>l.prop==="id")||t.unshift({type:"input-disabled",prop:"id",label:"用户ID"}),t}),B=async()=>{if(u(o.apiUrlQuery,"apiUrlQuery")){n.value=!0;try{let t={...p};o.onBeforeQuery&&(t=await o.onBeforeQuery(t));const l=await g.get(o.apiUrlQuery,{params:t});if(l&&Array.isArray(l.data.rows)&&typeof l.data.total=="number"){let a=l.data.rows;o.onAfterQuery&&(a=await o.onAfterQuery(a)),C.value=a,k.value=l.data.total}else console.warn("API response is not in the expected { data: [], total: 0 } format."),C.value=[],k.value=0}catch(t){console.error("Fetch data failed:",t)}finally{n.value=!1}}},S=()=>{p.pageNum=1,B()},L=()=>{const{pageNum:t,pageSize:l,...a}=o.initialSearchForm;Object.keys(p).forEach(m=>{m!=="pageNum"&&m!=="pageSize"&&delete p[m]}),Object.assign(p,a),S()},M=t=>{d.value=t},D=async(t,l)=>{let a;if(t==="add"?a=l?{...l}:{role:"user"}:a={...l},o.onBeforeOpenDialog){const m=await o.onBeforeOpenDialog(t,a);m&&(a=m)}if(r.mode=t,r.visible=!0,t==="edit"){if(!u(o.apiUrlDetail,"apiUrlDetail"))return;r.loading=!0;try{const m=await g.get(o.apiUrlDetail,{params:{id:a.id}});r.data=m.data}finally{r.loading=!1,o.onAfterOpenDialog&&o.onAfterOpenDialog(t,r.data),s("open-dialog",{mode:t,data:r.data})}}else r.data=a,o.onAfterOpenDialog&&o.onAfterOpenDialog(t,r.data),s("open-dialog",{mode:t,data:r.data})},I=async()=>{try{r.formRef&&await r.formRef.validate(),await V(r.mode,r.data)}catch(t){console.log("Validation failed:",t)}},U=async t=>{if(u(o.apiUrlDelete,"apiUrlDelete"))try{if(o.onBeforeDelete&&await o.onBeforeDelete(t)===!1)return;const l=t.join(",");await g.delete(o.apiUrlDelete+"/"+l.toString()),h.ElMessage.success("删除成功"),o.onAfterDelete&&o.onAfterDelete(t),s("delete",t),C.value.length===t.length&&p.pageNum>1&&p.pageNum--,B()}catch(l){console.error("Delete failed",l)}},W=t=>{p.pageSize=t,S()},H=t=>{p.pageNum=t,B()};return e.onMounted(B),y({refresh:B,search:S,handleDelete:U,openDialog:D,submit:V}),(t,l)=>{const a=e.resolveComponent("el-button"),m=e.resolveComponent("el-form-item"),Z=e.resolveComponent("el-form"),_=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(w.value)},[e.renderSlot(t.$slots,"header"),o.showSearchSection?(e.openBlock(),e.createElementBlock("div",$,[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(t.$slots,"query-conditions",{searchForm:p}),e.createVNode(m,{class:"!mr-0 flex-shrink-0"},{default:e.withCtx(()=>[e.createElementVNode("div",z,[e.renderSlot(t.$slots,"query-left"),e.createVNode(a,{type:"primary",onClick:S,loading:n.value},{default:e.withCtx(()=>l[6]||(l[6]=[e.createTextVNode("搜索")])),_:1,__:[6]},8,["loading"]),e.createVNode(a,{onClick:L},{default:e.withCtx(()=>l[7]||(l[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:d.value}),e.renderSlot(t.$slots,"add-button-content",{},()=>[o.showNewBtn?(e.openBlock(),e.createBlock(a,{key:0,type:"success",onClick:l[0]||(l[0]=i=>D("add"))},{default:e.withCtx(()=>l[8]||(l[8]=[e.createTextVNode("新增")])),_:1,__:[8]})):e.createCommentVNode("",!0)]),e.renderSlot(t.$slots,"action-right")])])):e.createCommentVNode("",!0),e.withDirectives((e.openBlock(),e.createBlock(J,e.mergeProps({data:C.value,onSelectionChange:M},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,i=>(e.openBlock(),e.createBlock(_,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(t.$slots,i.slot,{row:x.row})]),key:"0"}:void 0]),1040,["prop","label","width","sortable"]))),128)),o.showActionsColumn?(e.openBlock(),e.createBlock(_,{key:2,label:"操作",width:c.actionsColumnWidth},{default:e.withCtx(i=>[i.row?(e.openBlock(),e.createElementBlock("div",O,[t.$slots.actions?e.renderSlot(t.$slots,"actions",{key:0,row:i.row}):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.renderSlot(t.$slots,"action-before-edit",{row:i.row}),o.showEditButton?(e.openBlock(),e.createBlock(a,{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),o.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(a,{size:"small",type:"danger",link:""},{default:e.withCtx(()=>l[10]||(l[10]=[e.createTextVNode("删除")])),_:1,__:[10]})]),_:2},1032,["onConfirm"])):e.createCommentVNode("",!0),e.renderSlot(t.$slots,"action-after-delete",{row:i.row})],64))])):e.createCommentVNode("",!0)]),_:3},8,["width"])):e.createCommentVNode("",!0)]),_:3},16,["data"])),[[F,n.value]]),o.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":o.pageSizes,layout:o.paginationLayout,total:k.value,background:o.paginationBackground,small:o.paginationSmall,"hide-on-single-page":o.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:r.visible,"onUpdate:modelValue":l[5]||(l[5]=i=>r.visible=i),title:Q.value,width:o.dialogWidth,"destroy-on-close":!0,"custom-class":N.value},{footer:e.withCtx(()=>[e.createElementVNode("div",q,[e.createVNode(a,{onClick:l[4]||(l[4]=i=>r.visible=!1)},{default:e.withCtx(()=>l[11]||(l[11]=[e.createTextVNode("取消")])),_:1,__:[11]}),e.createVNode(a,{type:"primary",onClick:I,loading:r.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(t.$slots,"dialog-form-content",{formData:r.data,mode:r.mode},()=>[o.dialogFormConfig.length>0?(e.openBlock(),e.createBlock(E,{key:0,"form-config":R.value,modelValue:r.data,"onUpdate:modelValue":l[3]||(l[3]=i=>r.data=i),ref:i=>r.formRef=i,rules:o.dialogFormRules,"label-width":"80px"},null,8,["form-config","modelValue","rules"])):e.createCommentVNode("",!0)])])),[[F,r.loading]])]),_:3},8,["modelValue","title","width","custom-class"])],2)}}});f.CrudTable=j,Object.defineProperty(f,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,h,A){"use strict";const E=e.defineComponent({__name:"DynamicForm",props:{modelValue:{},formConfig:{},rules:{}},setup(c,{expose:y}){const b=e.ref(null);return y({validate:()=>{var s;return(s=b.value)==null?void 0:s.validate()}}),(s,t)=>{const w=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:b},s.$attrs),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.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(w,e.mergeProps({key:0,modelValue:s.modelValue[n.prop],"onUpdate:modelValue":d=>s.modelValue[n.prop]=d},{ref_for:!0},n.componentProps),null,16,["modelValue","onUpdate:modelValue"])):e.createCommentVNode("",!0),n.type==="textarea"?(e.openBlock(),e.createBlock(w,e.mergeProps({key:1,type:"textarea",modelValue:s.modelValue[n.prop],"onUpdate:modelValue":d=>s.modelValue[n.prop]=d},{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:s.modelValue[n.prop],"onUpdate:modelValue":d=>s.modelValue[n.prop]=d},{ref_for:!0},n.componentProps),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.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),n.type==="radio-group"?(e.openBlock(),e.createBlock(p,e.mergeProps({key:3,modelValue:s.modelValue[n.prop],"onUpdate:modelValue":d=>s.modelValue[n.prop]=d},{ref_for:!0},n.componentProps),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.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),n.type==="input-disabled"?(e.openBlock(),e.createBlock(w,e.mergeProps({key:4,"model-value":s.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"])}}}),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),h.ElMessage({message:"接口错误,请刷新接口",type:"error",duration:5*1e3}),Promise.reject(c)));const $={key:0,class:"flex flex-wrap items-center justify-between gap-4 mb-6"},z={class:"flex items-center gap-x-2"},P={class:"flex items-center gap-x-3 action-buttons flex-shrink-0"},O={key:0,class:"flex items-center gap-x-2"},T={key:1,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},showSearchSection:{type:Boolean,default:!0},showSearchActionButtons:{type:Boolean,default:!0},showNewBtn:{type:Boolean,default:!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:b}){const s=b,t=c,w=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:(h.ElMessage.error(`${l} prop is required.`),!1),V=async(o,l)=>{try{let a={...l};if(t.onBeforeSubmit&&(a=await t.onBeforeSubmit(a)),r.submitting=!0,o==="add"){if(!u(t.apiUrlCreate,"apiUrlCreate"))return;await g.post(t.apiUrlCreate,a),h.ElMessage.success("新增成功")}else{if(!u(t.apiUrlUpdate,"apiUrlUpdate"))return;await g.put(t.apiUrlUpdate,a),h.ElMessage.success("更新成功")}return t.onAfterSubmit&&t.onAfterSubmit(o,a),s("submit",{mode:o,data:a}),r.visible&&(r.visible=!1),B(),Promise.resolve()}catch(a){return console.log("Submit error:",a),Promise.reject(a)}finally{r.submitting=!1}},p=e.reactive({pageNum:1,pageSize:10,...t.initialSearchForm}),C=e.ref([]),k=e.ref(0),n=e.ref(!1),d=e.ref([]),r=e.reactive({visible:!1,loading:!1,submitting:!1,mode:"add",data:{},formRef:null}),Q=e.computed(()=>r.mode==="add"?"新增":"编辑"),R=e.computed(()=>{if(r.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}),B=async()=>{if(u(t.apiUrlQuery,"apiUrlQuery")){n.value=!0;try{let o={...p};t.onBeforeQuery&&(o=await t.onBeforeQuery(o));const l=await g.get(t.apiUrlQuery,{params:o});if(l&&l.data&&Array.isArray(l.data.rows)&&typeof l.data.total=="number"){let a=l.data.rows;t.onAfterQuery&&(a=await t.onAfterQuery(a)),C.value=a,k.value=l.data.total}else console.warn("API response is not in the expected { data: { rows: [], total: 0 } } format."),C.value=[],k.value=0}catch(o){console.error("Fetch data failed:",o)}finally{n.value=!1}}},S=()=>{p.pageNum=1,B()},L=()=>{const{pageNum:o,pageSize:l,...a}=t.initialSearchForm;Object.keys(p).forEach(m=>{m!=="pageNum"&&m!=="pageSize"&&delete p[m]}),Object.assign(p,a),S()},M=o=>{d.value=o},D=async(o,l)=>{let a;if(o==="add"?a=l?{...l}:{role:"user"}:a={...l},t.onBeforeOpenDialog){const m=await t.onBeforeOpenDialog(o,a);m&&(a=m)}if(r.mode=o,r.visible=!0,o==="edit"){if(!u(t.apiUrlDetail,"apiUrlDetail"))return;r.loading=!0;try{const m=await g.get(t.apiUrlDetail+"/"+a.id.toString());r.data=m.data.data}finally{r.loading=!1,t.onAfterOpenDialog&&t.onAfterOpenDialog(o,r.data),s("open-dialog",{mode:o,data:r.data})}}else r.data=a,t.onAfterOpenDialog&&t.onAfterOpenDialog(o,r.data),s("open-dialog",{mode:o,data:r.data})},I=async()=>{try{r.formRef&&await r.formRef.validate(),await V(r.mode,r.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()),h.ElMessage.success("删除成功"),t.onAfterDelete&&t.onAfterDelete(o),s("delete",o),C.value.length===o.length&&p.pageNum>1&&p.pageNum--,B()}catch(l){console.error("Delete failed",l)}},W=o=>{p.pageSize=o,S()},H=o=>{p.pageNum=o,B()};return e.onMounted(B),y({refresh:B,search:S,handleDelete:U,openDialog:D,submit:V}),(o,l)=>{const a=e.resolveComponent("el-button"),m=e.resolveComponent("el-form-item"),Z=e.resolveComponent("el-form"),_=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(w.value)},[e.renderSlot(o.$slots,"header"),t.showSearchSection?(e.openBlock(),e.createElementBlock("div",$,[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"),t.showSearchActionButtons?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createVNode(a,{type:"primary",onClick:S,loading:n.value},{default:e.withCtx(()=>l[6]||(l[6]=[e.createTextVNode("搜索")])),_:1,__:[6]},8,["loading"]),e.createVNode(a,{onClick:L},{default:e.withCtx(()=>l[7]||(l[7]=[e.createTextVNode("清空")])),_:1,__:[7]})],64)):e.createCommentVNode("",!0),e.renderSlot(o.$slots,"query-right")])]),_:3})]),_:3},8,["model"]),e.createElementVNode("div",P,[e.renderSlot(o.$slots,"action-left",{selections:d.value}),e.renderSlot(o.$slots,"add-button-content",{},()=>[t.showNewBtn?(e.openBlock(),e.createBlock(a,{key:0,type:"success",onClick:l[0]||(l[0]=i=>D("add"))},{default:e.withCtx(()=>l[8]||(l[8]=[e.createTextVNode("新增")])),_:1,__:[8]})):e.createCommentVNode("",!0)]),e.renderSlot(o.$slots,"action-right")])])):e.createCommentVNode("",!0),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(_,{key:0,type:"selection",width:"55",fixed:""})):e.createCommentVNode("",!0),t.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(t.columns,i=>(e.openBlock(),e.createBlock(_,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(_,{key:2,label:"操作",width:c.actionsColumnWidth},{default:e.withCtx(i=>[i.row?(e.openBlock(),e.createElementBlock("div",O,[o.$slots.actions?e.renderSlot(o.$slots,"actions",{key:0,row:i.row}):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.renderSlot(o.$slots,"action-before-edit",{row:i.row}),t.showEditButton?(e.openBlock(),e.createBlock(a,{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(a,{size:"small",type:"danger",link:""},{default:e.withCtx(()=>l[10]||(l[10]=[e.createTextVNode("删除")])),_:1,__:[10]})]),_:2},1032,["onConfirm"])):e.createCommentVNode("",!0),e.renderSlot(o.$slots,"action-after-delete",{row:i.row})],64))])):e.createCommentVNode("",!0)]),_:3},8,["width"])):e.createCommentVNode("",!0)]),_:3},16,["data"])),[[F,n.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:r.visible,"onUpdate:modelValue":l[5]||(l[5]=i=>r.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(a,{onClick:l[4]||(l[4]=i=>r.visible=!1)},{default:e.withCtx(()=>l[11]||(l[11]=[e.createTextVNode("取消")])),_:1,__:[11]}),e.createVNode(a,{type:"primary",onClick:I,loading:r.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:r.data,mode:r.mode},()=>[t.dialogFormConfig.length>0?(e.openBlock(),e.createBlock(E,{key:0,"form-config":R.value,modelValue:r.data,"onUpdate:modelValue":l[3]||(l[3]=i=>r.data=i),ref:i=>r.formRef=i,rules:t.dialogFormRules,"label-width":"80px"},null,8,["form-config","modelValue","rules"])):e.createCommentVNode("",!0)])])),[[F,r.loading]])]),_:3},8,["modelValue","title","width","custom-class"])],2)}}});f.CrudTable=j,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|