mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-11 11:56:46 +08:00
46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
import { isRef, reactive, ref, toRefs, unref, watch, watchEffect } from "vue";
|
|
import http from '@/api/configPublic'
|
|
|
|
const useTotalPage = (_url, params, config = {}) => {
|
|
const s = _url.split(" ");
|
|
const url = s[0];
|
|
let methods = 'post'
|
|
if (s[1]) methods = 'get'
|
|
const state = reactive({
|
|
data: [],
|
|
total: 1,
|
|
current: 1,
|
|
pages: 1,
|
|
pageNo: 1,
|
|
pageSize: 10,
|
|
loading: false
|
|
});
|
|
|
|
if (isRef(_url)) {
|
|
watchEffect(fetch);
|
|
}
|
|
|
|
function reset() {
|
|
state.data = [];
|
|
state.loading = false;
|
|
}
|
|
|
|
function fetch() {
|
|
state.loading = true;
|
|
return http[methods](unref(url), !s[1] ? unref(params) : { params: unref(params) }, { ...config }).then(r => {
|
|
state.data = r.data?.records || [];
|
|
state.total = r.data?.total || 0;
|
|
state.loading = false;
|
|
})
|
|
}
|
|
|
|
return {
|
|
...toRefs(state),
|
|
fetch,
|
|
reset,
|
|
};
|
|
}
|
|
|
|
export {
|
|
useTotalPage
|
|
} |