ct-component-plus 0.0.42 → 0.0.43
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/package.json +36 -36
- package/packages/components/button/index.js +8 -8
- package/packages/components/button/src/button.vue +171 -171
- package/packages/components/cascader/index.js +7 -7
- package/packages/components/cascader/src/cascader.vue +247 -247
- package/packages/components/cascader/src/ct-cascader.vue +260 -260
- package/packages/components/cascader/src/index.js +50 -50
- package/packages/components/checkbox/index.js +7 -7
- package/packages/components/checkbox/src/checkbox.vue +51 -51
- package/packages/components/checkbox/src/index.js +12 -12
- package/packages/components/date-picker/index.js +8 -8
- package/packages/components/date-picker/src/clear-icon.vue +2 -2
- package/packages/components/date-picker/src/date-icon.vue +2 -2
- package/packages/components/date-picker/src/date-picker.vue +77 -77
- package/packages/components/date-picker/src/index.js +33 -33
- package/packages/components/dialog/index.js +8 -8
- package/packages/components/dialog/src/dialog.vue +103 -103
- package/packages/components/empty/index.js +8 -8
- package/packages/components/empty/src/empty.vue +97 -97
- package/packages/components/index.js +81 -81
- package/packages/components/input/index.js +7 -7
- package/packages/components/input/src/index.js +13 -13
- package/packages/components/input/src/input.vue +106 -106
- package/packages/components/input-range/index.js +7 -7
- package/packages/components/input-range/src/index.js +29 -29
- package/packages/components/input-range/src/input-range.vue +233 -233
- package/packages/components/loading/index.js +7 -7
- package/packages/components/loading/src/CtLoading.vue +74 -74
- package/packages/components/loading/src/beating.vue +71 -71
- package/packages/components/loading/src/progress.vue +120 -120
- package/packages/components/loading/src/spinner.vue +38 -38
- package/packages/components/menu/index.js +7 -7
- package/packages/components/menu/src/item.vue +46 -46
- package/packages/components/menu/src/link.vue +28 -28
- package/packages/components/menu/src/logo.vue +25 -25
- package/packages/components/menu/src/menu-item.vue +103 -103
- package/packages/components/menu/src/menu.vue +191 -191
- package/packages/components/menu/src/utils/index.js +4 -4
- package/packages/components/message/icon/ErrorIcon.vue +25 -25
- package/packages/components/message/icon/InfoIcon.vue +25 -25
- package/packages/components/message/icon/SuccessIcon.vue +25 -25
- package/packages/components/message/icon/WarningIcon.vue +25 -25
- package/packages/components/message/index.js +8 -8
- package/packages/components/message/src/method.js +54 -54
- package/packages/components/message-box/index.js +7 -7
- package/packages/components/message-box/src/message-box.vue +107 -107
- package/packages/components/page/index.js +7 -7
- package/packages/components/page/src/modules/DownloadButton.vue +21 -21
- package/packages/components/page/src/modules/TableTitle.vue +151 -151
- package/packages/components/page/src/page.vue +382 -382
- package/packages/components/pagination/index.js +7 -7
- package/packages/components/pagination/src/pagination.vue +36 -36
- package/packages/components/radio/index.js +7 -7
- package/packages/components/radio/src/index.js +12 -12
- package/packages/components/radio/src/radio.vue +47 -47
- package/packages/components/search-box/index.js +24 -24
- package/packages/components/search-box/src/index.js +29 -29
- package/packages/components/search-box/src/search-box.vue +250 -251
- package/packages/components/search-box/src/slot.vue +4 -4
- package/packages/components/select/index.js +7 -7
- package/packages/components/select/src/arrow-down.vue +2 -2
- package/packages/components/select/src/clear-icon.vue +2 -2
- package/packages/components/select/src/empty.vue +13 -13
- package/packages/components/select/src/index.js +51 -51
- package/packages/components/select/src/select.vue +380 -380
- package/packages/components/table/index.js +7 -7
- package/packages/components/table/src/TableSort.vue +179 -179
- package/packages/components/table/src/index.js +70 -66
- package/packages/components/table/src/table.vue +287 -287
- package/packages/components/tabs/index.js +7 -7
- package/packages/components/tabs/src/tabs.vue +225 -225
- package/packages/components/year-select/index.js +7 -7
- package/packages/components/year-select/src/index.js +44 -44
- package/packages/components/year-select/src/year-select.vue +273 -273
- package/packages/echarts/bar/index.js +63 -63
- package/packages/echarts/base.js +99 -99
- package/packages/echarts/line/index.js +106 -106
- package/packages/hooks/index.js +5 -5
- package/packages/hooks/use-buried/index.js +46 -46
- package/packages/hooks/use-checked-all/index.js +37 -37
- package/packages/hooks/use-echarts/index.js +1 -1
- package/packages/hooks/use-echarts/use-bar/index.js +72 -72
- package/packages/hooks/use-echarts/use-line/index.js +88 -88
- package/packages/hooks/use-namespace/index.js +65 -65
- package/packages/hooks/use-search-component/index.js +28 -28
- package/packages/style/element.less +725 -725
- package/packages/style/index.js +2 -2
- package/packages/style/init.less +114 -114
- package/packages/utils/index.js +1 -1
- package/packages/utils/operate.js +77 -77
- package/packages/utils/types.js +35 -35
|
@@ -1,382 +1,382 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import {
|
|
3
|
-
h,
|
|
4
|
-
reactive,
|
|
5
|
-
inject,
|
|
6
|
-
ref,
|
|
7
|
-
computed,
|
|
8
|
-
resolveComponent,
|
|
9
|
-
provide,
|
|
10
|
-
nextTick,
|
|
11
|
-
} from "vue";
|
|
12
|
-
import { useNamespace } from "../../../hooks";
|
|
13
|
-
import SearchBox from "../../search-box";
|
|
14
|
-
import TableBox from "../../table";
|
|
15
|
-
import CtEmpty from "../../empty";
|
|
16
|
-
import CtPagination from "../../pagination";
|
|
17
|
-
import CtLoading from "../../loading";
|
|
18
|
-
import TableTitle from "./modules/TableTitle.vue";
|
|
19
|
-
import { isFunction } from "../../../utils";
|
|
20
|
-
export default {
|
|
21
|
-
name: "PageComponent",
|
|
22
|
-
props: {
|
|
23
|
-
searchApi: {
|
|
24
|
-
type: String,
|
|
25
|
-
default: "",
|
|
26
|
-
},
|
|
27
|
-
needInit: {
|
|
28
|
-
type: Boolean,
|
|
29
|
-
default: true,
|
|
30
|
-
},
|
|
31
|
-
searchConfig: {
|
|
32
|
-
type: Object,
|
|
33
|
-
default: () => {
|
|
34
|
-
return {};
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
pageSize: Number,
|
|
38
|
-
tableHandleList: {
|
|
39
|
-
type: Array,
|
|
40
|
-
default: () => {
|
|
41
|
-
return ["sort", "download"];
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
searchProps: {
|
|
45
|
-
type: Object,
|
|
46
|
-
default: () => {
|
|
47
|
-
return {};
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
tableProps: {
|
|
51
|
-
type: Object,
|
|
52
|
-
default: () => {
|
|
53
|
-
return {};
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
loadProps: {
|
|
57
|
-
type: Object,
|
|
58
|
-
default: () => {
|
|
59
|
-
return {};
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
paginationProps: {
|
|
63
|
-
type: Object,
|
|
64
|
-
default: () => {
|
|
65
|
-
return {};
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
cbs: {
|
|
69
|
-
type: Object,
|
|
70
|
-
default: () => {
|
|
71
|
-
return {};
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
pageProps: {
|
|
75
|
-
type: Object,
|
|
76
|
-
default: () => {
|
|
77
|
-
return {};
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
setup(props, { emit, slots, expose }) {
|
|
82
|
-
const baseDao = inject("$ctBaseDao");
|
|
83
|
-
const serviceConfig = inject("$ctServiceConfig");
|
|
84
|
-
const searchMethod =
|
|
85
|
-
props.searchConfig.method || serviceConfig.defaultMethod || "post";
|
|
86
|
-
const downlaodMethod =
|
|
87
|
-
props.searchConfig.downlaodMethod ||
|
|
88
|
-
serviceConfig.defaultDownlaodMethod ||
|
|
89
|
-
"handlerDownload";
|
|
90
|
-
const state = reactive({
|
|
91
|
-
total: 0,
|
|
92
|
-
pageSize: props.pageSize,
|
|
93
|
-
pageNo: 1,
|
|
94
|
-
sortObj: {},
|
|
95
|
-
searchParams: {},
|
|
96
|
-
pageLoading: false,
|
|
97
|
-
downloadLoading: false,
|
|
98
|
-
pageError: false,
|
|
99
|
-
});
|
|
100
|
-
const downloadLoading = ref(false);
|
|
101
|
-
provide("downloadLoading", downloadLoading);
|
|
102
|
-
const getSelfSlots = (name) => {
|
|
103
|
-
if (!name) return null;
|
|
104
|
-
const key = `_${name}-`;
|
|
105
|
-
const res = {};
|
|
106
|
-
Object.keys(slots).forEach((slotName) => {
|
|
107
|
-
if (slotName.startsWith(key)) {
|
|
108
|
-
res[slotName.replace(key, "")] = slots[slotName];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
return res;
|
|
112
|
-
};
|
|
113
|
-
// searchBox逻辑
|
|
114
|
-
const searchRef = ref(null);
|
|
115
|
-
const doSearch = (params) => {
|
|
116
|
-
state.searchParams = params;
|
|
117
|
-
state.pageNo = 1;
|
|
118
|
-
getPageData();
|
|
119
|
-
};
|
|
120
|
-
const setTableProps = (data) => {
|
|
121
|
-
const { total, tableData, columnData, list } = data;
|
|
122
|
-
state.total = total || 0;
|
|
123
|
-
if (columnData) {
|
|
124
|
-
tableProps.columnData = columnData;
|
|
125
|
-
}
|
|
126
|
-
tableProps.tableData = tableData || list || [];
|
|
127
|
-
};
|
|
128
|
-
const getPageData = async (download = false) => {
|
|
129
|
-
let dataP = {
|
|
130
|
-
...state.searchParams,
|
|
131
|
-
};
|
|
132
|
-
if (state.sortObj?.order && state.sortObj?.prop) {
|
|
133
|
-
dataP.sortObj = state.sortObj;
|
|
134
|
-
}
|
|
135
|
-
if (props.pageSize) {
|
|
136
|
-
dataP.pageSize = props.pageSize;
|
|
137
|
-
dataP.pageNo = state.pageNo;
|
|
138
|
-
}
|
|
139
|
-
state.pageError = false;
|
|
140
|
-
state.pageLoading = true;
|
|
141
|
-
if (isFunction(props.cbs.doSearch)) {
|
|
142
|
-
const res = await props.cbs.doSearch(dataP);
|
|
143
|
-
if (res) {
|
|
144
|
-
if (Array.isArray(res)) {
|
|
145
|
-
tableProps.tableData = res;
|
|
146
|
-
} else if (typeof res === "object") {
|
|
147
|
-
setTableProps(res);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
state.pageLoading = false;
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (isFunction(props.cbs.beforeSearch)) {
|
|
154
|
-
const paramsHandle = await props.cbs.beforeSearch(dataP);
|
|
155
|
-
if (paramsHandle === false) return;
|
|
156
|
-
dataP = paramsHandle || dataP;
|
|
157
|
-
}
|
|
158
|
-
if (download) {
|
|
159
|
-
dataP.download = true;
|
|
160
|
-
if (isFunction(props.cbs.doDownload)) {
|
|
161
|
-
await props.cbs.doDownload(dataP);
|
|
162
|
-
} else {
|
|
163
|
-
try {
|
|
164
|
-
await baseDao[downlaodMethod](props.searchApi, dataP);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
console.error(error);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
state.pageLoading = false;
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
await baseDao[searchMethod](props.searchApi, dataP)
|
|
173
|
-
.then(async (res) => {
|
|
174
|
-
let data = res || {};
|
|
175
|
-
if (isFunction(props.cbs.afterSearch)) {
|
|
176
|
-
const dataHandle = await props.cbs.afterSearch(data);
|
|
177
|
-
if (dataHandle) data = dataHandle;
|
|
178
|
-
}
|
|
179
|
-
setTableProps(data);
|
|
180
|
-
})
|
|
181
|
-
.catch(() => {
|
|
182
|
-
state.pageError = true;
|
|
183
|
-
});
|
|
184
|
-
state.pageLoading = false;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const tableTitleRef = ref(null);
|
|
188
|
-
// tableBox逻辑
|
|
189
|
-
const tableRef = ref(null);
|
|
190
|
-
const paginationRef = ref(null);
|
|
191
|
-
const tableProps = reactive({
|
|
192
|
-
columnData: props.tableProps.columnData || [],
|
|
193
|
-
tableData: [
|
|
194
|
-
// { index: 1, result: 3, status: "暂未处理" },
|
|
195
|
-
// { index: 2, result: 0, status: "无需处理" },
|
|
196
|
-
// { index: 3, result: 3, status: "处理中" },
|
|
197
|
-
// { index: 4, result: 0, status: "处理完成" },
|
|
198
|
-
],
|
|
199
|
-
});
|
|
200
|
-
const sortList = computed(() => {
|
|
201
|
-
const tableSortList = props.tableProps.columnData.filter((item) => {
|
|
202
|
-
return item.sortable;
|
|
203
|
-
});
|
|
204
|
-
return tableSortList || [];
|
|
205
|
-
});
|
|
206
|
-
const changeSort = (val) => {
|
|
207
|
-
state.pageNo = 1;
|
|
208
|
-
state.sortObj = val;
|
|
209
|
-
getPageData();
|
|
210
|
-
};
|
|
211
|
-
const changePageNo = (val) => {
|
|
212
|
-
state.pageNo = val;
|
|
213
|
-
getPageData();
|
|
214
|
-
};
|
|
215
|
-
const doDownload = async () => {
|
|
216
|
-
downloadLoading.value = true;
|
|
217
|
-
try {
|
|
218
|
-
await getPageData(true);
|
|
219
|
-
} catch (error) {}
|
|
220
|
-
await new Promise((resolve) => {
|
|
221
|
-
setTimeout(() => {
|
|
222
|
-
resolve();
|
|
223
|
-
}, 3000);
|
|
224
|
-
});
|
|
225
|
-
downloadLoading.value = false;
|
|
226
|
-
};
|
|
227
|
-
const clickSearch = () => {
|
|
228
|
-
if (searchRef.value && isFunction(searchRef.value.doSearch)) {
|
|
229
|
-
searchRef.value.doSearch();
|
|
230
|
-
} else {
|
|
231
|
-
doSearch({});
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
if (props.needInit) {
|
|
235
|
-
nextTick(() => {
|
|
236
|
-
clickSearch();
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
const ns = useNamespace("page-component");
|
|
240
|
-
console.log(slots);
|
|
241
|
-
expose({
|
|
242
|
-
searchMethod,
|
|
243
|
-
searchRef,
|
|
244
|
-
tableTitleRef,
|
|
245
|
-
tableRef,
|
|
246
|
-
paginationRef,
|
|
247
|
-
doSearch,
|
|
248
|
-
clickSearch,
|
|
249
|
-
getPageData,
|
|
250
|
-
changePageNo,
|
|
251
|
-
changeSort,
|
|
252
|
-
state,
|
|
253
|
-
});
|
|
254
|
-
return () =>
|
|
255
|
-
h("div", { class: ns.b() }, [
|
|
256
|
-
h("div", { class: ns.e("container") }, [
|
|
257
|
-
h("div", { class: ns.e("header") }, [
|
|
258
|
-
slots.header
|
|
259
|
-
? slots.header()
|
|
260
|
-
: h("div", { class: ns.em("header", "default") }, [
|
|
261
|
-
slots["header-before"] ? slots["header-before"]() : null,
|
|
262
|
-
h("div", { class: ns.e("search") }, [
|
|
263
|
-
h(
|
|
264
|
-
SearchBox,
|
|
265
|
-
{
|
|
266
|
-
onDoSearch: doSearch,
|
|
267
|
-
...props.searchProps,
|
|
268
|
-
ref: searchRef,
|
|
269
|
-
},
|
|
270
|
-
{ ...getSelfSlots("search") }
|
|
271
|
-
),
|
|
272
|
-
]),
|
|
273
|
-
slots["header-after"] ? slots["header-after"]() : null,
|
|
274
|
-
]),
|
|
275
|
-
]),
|
|
276
|
-
h("div", { class: ns.e("content") }, [
|
|
277
|
-
slots.content
|
|
278
|
-
? slots.content()
|
|
279
|
-
: h("div", { class: ns.em("content", "default") }, [
|
|
280
|
-
state.pageError
|
|
281
|
-
? h(CtEmpty, {
|
|
282
|
-
class: ns.e("error-empty"),
|
|
283
|
-
innerText:
|
|
284
|
-
props.pageProps?.pageErrorText || "接口请求错误",
|
|
285
|
-
})
|
|
286
|
-
: h(
|
|
287
|
-
CtLoading,
|
|
288
|
-
{ "is-load": state.pageLoading, ...props.loadProps },
|
|
289
|
-
{
|
|
290
|
-
default: () => [
|
|
291
|
-
slots["content-before"]
|
|
292
|
-
? slots["content-before"]()
|
|
293
|
-
: null,
|
|
294
|
-
slots["table-top"]
|
|
295
|
-
? slots["table-top"]()
|
|
296
|
-
: h(
|
|
297
|
-
TableTitle,
|
|
298
|
-
{
|
|
299
|
-
total: state.total,
|
|
300
|
-
pageSize: state.pageSize,
|
|
301
|
-
handleList: props.tableHandleList,
|
|
302
|
-
sortList: sortList.value,
|
|
303
|
-
sortObj: state.sortObj,
|
|
304
|
-
"onUpdate:sortObj": (val) => {
|
|
305
|
-
state.sortObj = val;
|
|
306
|
-
},
|
|
307
|
-
onChangeSort: changeSort,
|
|
308
|
-
onDownload: doDownload,
|
|
309
|
-
ref: tableTitleRef,
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
"table-title": slots["table-title"],
|
|
313
|
-
"table-desc": slots["table-desc"],
|
|
314
|
-
"table-handle": slots["table-handle"],
|
|
315
|
-
"table-handle-before":
|
|
316
|
-
slots["table-handle-before"],
|
|
317
|
-
"table-handle-after":
|
|
318
|
-
slots["table-handle-after"],
|
|
319
|
-
}
|
|
320
|
-
),
|
|
321
|
-
h("div", { class: ns.e("table") }, [
|
|
322
|
-
h(
|
|
323
|
-
TableBox,
|
|
324
|
-
{
|
|
325
|
-
"table-props": tableProps,
|
|
326
|
-
...props.tableProps,
|
|
327
|
-
ref: tableRef,
|
|
328
|
-
},
|
|
329
|
-
{ ...getSelfSlots("table") }
|
|
330
|
-
),
|
|
331
|
-
h(CtPagination, {
|
|
332
|
-
class: ns.e("pagination"),
|
|
333
|
-
pageSize: state.pageSize,
|
|
334
|
-
total: state.total,
|
|
335
|
-
"current-page": state.pageNo,
|
|
336
|
-
"onUpdate:current-page": changePageNo,
|
|
337
|
-
...props.paginationProps,
|
|
338
|
-
ref: paginationRef,
|
|
339
|
-
}),
|
|
340
|
-
]),
|
|
341
|
-
slots["content-after"]
|
|
342
|
-
? slots["content-after"]()
|
|
343
|
-
: null,
|
|
344
|
-
],
|
|
345
|
-
}
|
|
346
|
-
),
|
|
347
|
-
]),
|
|
348
|
-
]),
|
|
349
|
-
slots.default ? slots.default() : null,
|
|
350
|
-
]),
|
|
351
|
-
]);
|
|
352
|
-
},
|
|
353
|
-
};
|
|
354
|
-
</script>
|
|
355
|
-
<style lang="less">
|
|
356
|
-
.ct-page-component {
|
|
357
|
-
--content-spacing-horizontal: 20px;
|
|
358
|
-
&__header {
|
|
359
|
-
background-color: #fff;
|
|
360
|
-
padding: var(--content-spacing-horizontal);
|
|
361
|
-
margin-bottom: 16px;
|
|
362
|
-
border-radius: var(--ct-border-radius);
|
|
363
|
-
.ct-search-box {
|
|
364
|
-
margin-bottom: 0;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
&__content {
|
|
368
|
-
background-color: #fff;
|
|
369
|
-
padding: 0 var(--content-spacing-horizontal)
|
|
370
|
-
var(--content-spacing-horizontal);
|
|
371
|
-
border-radius: var(--ct-border-radius);
|
|
372
|
-
.ct-table-box {
|
|
373
|
-
margin-bottom: 0;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
&__pagination {
|
|
377
|
-
justify-content: flex-end;
|
|
378
|
-
margin-top: 15px;
|
|
379
|
-
margin-bottom: 0;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
</style>
|
|
1
|
+
<script>
|
|
2
|
+
import {
|
|
3
|
+
h,
|
|
4
|
+
reactive,
|
|
5
|
+
inject,
|
|
6
|
+
ref,
|
|
7
|
+
computed,
|
|
8
|
+
resolveComponent,
|
|
9
|
+
provide,
|
|
10
|
+
nextTick,
|
|
11
|
+
} from "vue";
|
|
12
|
+
import { useNamespace } from "../../../hooks";
|
|
13
|
+
import SearchBox from "../../search-box";
|
|
14
|
+
import TableBox from "../../table";
|
|
15
|
+
import CtEmpty from "../../empty";
|
|
16
|
+
import CtPagination from "../../pagination";
|
|
17
|
+
import CtLoading from "../../loading";
|
|
18
|
+
import TableTitle from "./modules/TableTitle.vue";
|
|
19
|
+
import { isFunction } from "../../../utils";
|
|
20
|
+
export default {
|
|
21
|
+
name: "PageComponent",
|
|
22
|
+
props: {
|
|
23
|
+
searchApi: {
|
|
24
|
+
type: String,
|
|
25
|
+
default: "",
|
|
26
|
+
},
|
|
27
|
+
needInit: {
|
|
28
|
+
type: Boolean,
|
|
29
|
+
default: true,
|
|
30
|
+
},
|
|
31
|
+
searchConfig: {
|
|
32
|
+
type: Object,
|
|
33
|
+
default: () => {
|
|
34
|
+
return {};
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
pageSize: Number,
|
|
38
|
+
tableHandleList: {
|
|
39
|
+
type: Array,
|
|
40
|
+
default: () => {
|
|
41
|
+
return ["sort", "download"];
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
searchProps: {
|
|
45
|
+
type: Object,
|
|
46
|
+
default: () => {
|
|
47
|
+
return {};
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
tableProps: {
|
|
51
|
+
type: Object,
|
|
52
|
+
default: () => {
|
|
53
|
+
return {};
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
loadProps: {
|
|
57
|
+
type: Object,
|
|
58
|
+
default: () => {
|
|
59
|
+
return {};
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
paginationProps: {
|
|
63
|
+
type: Object,
|
|
64
|
+
default: () => {
|
|
65
|
+
return {};
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
cbs: {
|
|
69
|
+
type: Object,
|
|
70
|
+
default: () => {
|
|
71
|
+
return {};
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
pageProps: {
|
|
75
|
+
type: Object,
|
|
76
|
+
default: () => {
|
|
77
|
+
return {};
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
setup(props, { emit, slots, expose }) {
|
|
82
|
+
const baseDao = inject("$ctBaseDao");
|
|
83
|
+
const serviceConfig = inject("$ctServiceConfig");
|
|
84
|
+
const searchMethod =
|
|
85
|
+
props.searchConfig.method || serviceConfig.defaultMethod || "post";
|
|
86
|
+
const downlaodMethod =
|
|
87
|
+
props.searchConfig.downlaodMethod ||
|
|
88
|
+
serviceConfig.defaultDownlaodMethod ||
|
|
89
|
+
"handlerDownload";
|
|
90
|
+
const state = reactive({
|
|
91
|
+
total: 0,
|
|
92
|
+
pageSize: props.pageSize,
|
|
93
|
+
pageNo: 1,
|
|
94
|
+
sortObj: {},
|
|
95
|
+
searchParams: {},
|
|
96
|
+
pageLoading: false,
|
|
97
|
+
downloadLoading: false,
|
|
98
|
+
pageError: false,
|
|
99
|
+
});
|
|
100
|
+
const downloadLoading = ref(false);
|
|
101
|
+
provide("downloadLoading", downloadLoading);
|
|
102
|
+
const getSelfSlots = (name) => {
|
|
103
|
+
if (!name) return null;
|
|
104
|
+
const key = `_${name}-`;
|
|
105
|
+
const res = {};
|
|
106
|
+
Object.keys(slots).forEach((slotName) => {
|
|
107
|
+
if (slotName.startsWith(key)) {
|
|
108
|
+
res[slotName.replace(key, "")] = slots[slotName];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return res;
|
|
112
|
+
};
|
|
113
|
+
// searchBox逻辑
|
|
114
|
+
const searchRef = ref(null);
|
|
115
|
+
const doSearch = (params) => {
|
|
116
|
+
state.searchParams = params;
|
|
117
|
+
state.pageNo = 1;
|
|
118
|
+
getPageData();
|
|
119
|
+
};
|
|
120
|
+
const setTableProps = (data) => {
|
|
121
|
+
const { total, tableData, columnData, list } = data;
|
|
122
|
+
state.total = total || 0;
|
|
123
|
+
if (columnData) {
|
|
124
|
+
tableProps.columnData = columnData;
|
|
125
|
+
}
|
|
126
|
+
tableProps.tableData = tableData || list || [];
|
|
127
|
+
};
|
|
128
|
+
const getPageData = async (download = false) => {
|
|
129
|
+
let dataP = {
|
|
130
|
+
...state.searchParams,
|
|
131
|
+
};
|
|
132
|
+
if (state.sortObj?.order && state.sortObj?.prop) {
|
|
133
|
+
dataP.sortObj = state.sortObj;
|
|
134
|
+
}
|
|
135
|
+
if (props.pageSize) {
|
|
136
|
+
dataP.pageSize = props.pageSize;
|
|
137
|
+
dataP.pageNo = state.pageNo;
|
|
138
|
+
}
|
|
139
|
+
state.pageError = false;
|
|
140
|
+
state.pageLoading = true;
|
|
141
|
+
if (isFunction(props.cbs.doSearch)) {
|
|
142
|
+
const res = await props.cbs.doSearch(dataP);
|
|
143
|
+
if (res) {
|
|
144
|
+
if (Array.isArray(res)) {
|
|
145
|
+
tableProps.tableData = res;
|
|
146
|
+
} else if (typeof res === "object") {
|
|
147
|
+
setTableProps(res);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
state.pageLoading = false;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (isFunction(props.cbs.beforeSearch)) {
|
|
154
|
+
const paramsHandle = await props.cbs.beforeSearch(dataP);
|
|
155
|
+
if (paramsHandle === false) return;
|
|
156
|
+
dataP = paramsHandle || dataP;
|
|
157
|
+
}
|
|
158
|
+
if (download) {
|
|
159
|
+
dataP.download = true;
|
|
160
|
+
if (isFunction(props.cbs.doDownload)) {
|
|
161
|
+
await props.cbs.doDownload(dataP);
|
|
162
|
+
} else {
|
|
163
|
+
try {
|
|
164
|
+
await baseDao[downlaodMethod](props.searchApi, dataP);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
console.error(error);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
state.pageLoading = false;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
await baseDao[searchMethod](props.searchApi, dataP)
|
|
173
|
+
.then(async (res) => {
|
|
174
|
+
let data = res || {};
|
|
175
|
+
if (isFunction(props.cbs.afterSearch)) {
|
|
176
|
+
const dataHandle = await props.cbs.afterSearch(data);
|
|
177
|
+
if (dataHandle) data = dataHandle;
|
|
178
|
+
}
|
|
179
|
+
setTableProps(data);
|
|
180
|
+
})
|
|
181
|
+
.catch(() => {
|
|
182
|
+
state.pageError = true;
|
|
183
|
+
});
|
|
184
|
+
state.pageLoading = false;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const tableTitleRef = ref(null);
|
|
188
|
+
// tableBox逻辑
|
|
189
|
+
const tableRef = ref(null);
|
|
190
|
+
const paginationRef = ref(null);
|
|
191
|
+
const tableProps = reactive({
|
|
192
|
+
columnData: props.tableProps.columnData || [],
|
|
193
|
+
tableData: [
|
|
194
|
+
// { index: 1, result: 3, status: "暂未处理" },
|
|
195
|
+
// { index: 2, result: 0, status: "无需处理" },
|
|
196
|
+
// { index: 3, result: 3, status: "处理中" },
|
|
197
|
+
// { index: 4, result: 0, status: "处理完成" },
|
|
198
|
+
],
|
|
199
|
+
});
|
|
200
|
+
const sortList = computed(() => {
|
|
201
|
+
const tableSortList = props.tableProps.columnData.filter((item) => {
|
|
202
|
+
return item.sortable;
|
|
203
|
+
});
|
|
204
|
+
return tableSortList || [];
|
|
205
|
+
});
|
|
206
|
+
const changeSort = (val) => {
|
|
207
|
+
state.pageNo = 1;
|
|
208
|
+
state.sortObj = val;
|
|
209
|
+
getPageData();
|
|
210
|
+
};
|
|
211
|
+
const changePageNo = (val) => {
|
|
212
|
+
state.pageNo = val;
|
|
213
|
+
getPageData();
|
|
214
|
+
};
|
|
215
|
+
const doDownload = async () => {
|
|
216
|
+
downloadLoading.value = true;
|
|
217
|
+
try {
|
|
218
|
+
await getPageData(true);
|
|
219
|
+
} catch (error) {}
|
|
220
|
+
await new Promise((resolve) => {
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
resolve();
|
|
223
|
+
}, 3000);
|
|
224
|
+
});
|
|
225
|
+
downloadLoading.value = false;
|
|
226
|
+
};
|
|
227
|
+
const clickSearch = () => {
|
|
228
|
+
if (searchRef.value && isFunction(searchRef.value.doSearch)) {
|
|
229
|
+
searchRef.value.doSearch();
|
|
230
|
+
} else {
|
|
231
|
+
doSearch({});
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
if (props.needInit) {
|
|
235
|
+
nextTick(() => {
|
|
236
|
+
clickSearch();
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const ns = useNamespace("page-component");
|
|
240
|
+
console.log(slots);
|
|
241
|
+
expose({
|
|
242
|
+
searchMethod,
|
|
243
|
+
searchRef,
|
|
244
|
+
tableTitleRef,
|
|
245
|
+
tableRef,
|
|
246
|
+
paginationRef,
|
|
247
|
+
doSearch,
|
|
248
|
+
clickSearch,
|
|
249
|
+
getPageData,
|
|
250
|
+
changePageNo,
|
|
251
|
+
changeSort,
|
|
252
|
+
state,
|
|
253
|
+
});
|
|
254
|
+
return () =>
|
|
255
|
+
h("div", { class: ns.b() }, [
|
|
256
|
+
h("div", { class: ns.e("container") }, [
|
|
257
|
+
h("div", { class: ns.e("header") }, [
|
|
258
|
+
slots.header
|
|
259
|
+
? slots.header()
|
|
260
|
+
: h("div", { class: ns.em("header", "default") }, [
|
|
261
|
+
slots["header-before"] ? slots["header-before"]() : null,
|
|
262
|
+
h("div", { class: ns.e("search") }, [
|
|
263
|
+
h(
|
|
264
|
+
SearchBox,
|
|
265
|
+
{
|
|
266
|
+
onDoSearch: doSearch,
|
|
267
|
+
...props.searchProps,
|
|
268
|
+
ref: searchRef,
|
|
269
|
+
},
|
|
270
|
+
{ ...getSelfSlots("search") }
|
|
271
|
+
),
|
|
272
|
+
]),
|
|
273
|
+
slots["header-after"] ? slots["header-after"]() : null,
|
|
274
|
+
]),
|
|
275
|
+
]),
|
|
276
|
+
h("div", { class: ns.e("content") }, [
|
|
277
|
+
slots.content
|
|
278
|
+
? slots.content()
|
|
279
|
+
: h("div", { class: ns.em("content", "default") }, [
|
|
280
|
+
state.pageError
|
|
281
|
+
? h(CtEmpty, {
|
|
282
|
+
class: ns.e("error-empty"),
|
|
283
|
+
innerText:
|
|
284
|
+
props.pageProps?.pageErrorText || "接口请求错误",
|
|
285
|
+
})
|
|
286
|
+
: h(
|
|
287
|
+
CtLoading,
|
|
288
|
+
{ "is-load": state.pageLoading, ...props.loadProps },
|
|
289
|
+
{
|
|
290
|
+
default: () => [
|
|
291
|
+
slots["content-before"]
|
|
292
|
+
? slots["content-before"]()
|
|
293
|
+
: null,
|
|
294
|
+
slots["table-top"]
|
|
295
|
+
? slots["table-top"]()
|
|
296
|
+
: h(
|
|
297
|
+
TableTitle,
|
|
298
|
+
{
|
|
299
|
+
total: state.total,
|
|
300
|
+
pageSize: state.pageSize,
|
|
301
|
+
handleList: props.tableHandleList,
|
|
302
|
+
sortList: sortList.value,
|
|
303
|
+
sortObj: state.sortObj,
|
|
304
|
+
"onUpdate:sortObj": (val) => {
|
|
305
|
+
state.sortObj = val;
|
|
306
|
+
},
|
|
307
|
+
onChangeSort: changeSort,
|
|
308
|
+
onDownload: doDownload,
|
|
309
|
+
ref: tableTitleRef,
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"table-title": slots["table-title"],
|
|
313
|
+
"table-desc": slots["table-desc"],
|
|
314
|
+
"table-handle": slots["table-handle"],
|
|
315
|
+
"table-handle-before":
|
|
316
|
+
slots["table-handle-before"],
|
|
317
|
+
"table-handle-after":
|
|
318
|
+
slots["table-handle-after"],
|
|
319
|
+
}
|
|
320
|
+
),
|
|
321
|
+
h("div", { class: ns.e("table") }, [
|
|
322
|
+
h(
|
|
323
|
+
TableBox,
|
|
324
|
+
{
|
|
325
|
+
"table-props": tableProps,
|
|
326
|
+
...props.tableProps,
|
|
327
|
+
ref: tableRef,
|
|
328
|
+
},
|
|
329
|
+
{ ...getSelfSlots("table") }
|
|
330
|
+
),
|
|
331
|
+
h(CtPagination, {
|
|
332
|
+
class: ns.e("pagination"),
|
|
333
|
+
pageSize: state.pageSize,
|
|
334
|
+
total: state.total,
|
|
335
|
+
"current-page": state.pageNo,
|
|
336
|
+
"onUpdate:current-page": changePageNo,
|
|
337
|
+
...props.paginationProps,
|
|
338
|
+
ref: paginationRef,
|
|
339
|
+
}),
|
|
340
|
+
]),
|
|
341
|
+
slots["content-after"]
|
|
342
|
+
? slots["content-after"]()
|
|
343
|
+
: null,
|
|
344
|
+
],
|
|
345
|
+
}
|
|
346
|
+
),
|
|
347
|
+
]),
|
|
348
|
+
]),
|
|
349
|
+
slots.default ? slots.default() : null,
|
|
350
|
+
]),
|
|
351
|
+
]);
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
</script>
|
|
355
|
+
<style lang="less">
|
|
356
|
+
.ct-page-component {
|
|
357
|
+
--content-spacing-horizontal: 20px;
|
|
358
|
+
&__header {
|
|
359
|
+
background-color: #fff;
|
|
360
|
+
padding: var(--content-spacing-horizontal);
|
|
361
|
+
margin-bottom: 16px;
|
|
362
|
+
border-radius: var(--ct-border-radius);
|
|
363
|
+
.ct-search-box {
|
|
364
|
+
margin-bottom: 0;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
&__content {
|
|
368
|
+
background-color: #fff;
|
|
369
|
+
padding: 0 var(--content-spacing-horizontal)
|
|
370
|
+
var(--content-spacing-horizontal);
|
|
371
|
+
border-radius: var(--ct-border-radius);
|
|
372
|
+
.ct-table-box {
|
|
373
|
+
margin-bottom: 0;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
&__pagination {
|
|
377
|
+
justify-content: flex-end;
|
|
378
|
+
margin-top: 15px;
|
|
379
|
+
margin-bottom: 0;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
</style>
|