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