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