diff --git a/src/api/request.js b/src/api/request.js index 709be19d..e71270fa 100644 --- a/src/api/request.js +++ b/src/api/request.js @@ -292,6 +292,41 @@ export function usePage(_url, params, init = true,listing = false) { reset, }; } + export function useThrottlePage(_url, params = {}, init = true) { + + const state = reactive({ + data: [], + loading: false, + total: 0, + totalPage: 0, + page: 1, + ...params + }); + + watch(() => params.keyword, throttle(fetch, 600)); + watch(() => params.page, fetch); + + function fetch() { + state.loading = true; + if (!params.keyword) { + state.loading = false; + return; + } + return request(_url, params).then(r => { + state.data = params.page === 1 ? r.data.records : [...state.data, ...r.data.records]; + state.totalPage = r.data.pages; + state.total = r.data.total; + state.loading = false; + }); + } + + init && fetch(); + return { + ...toRefs(state), + fetch, + }; +} + export function useRequest(_url, params, init = true) { diff --git a/src/components/project/ProjectManagerNew.vue b/src/components/project/ProjectManagerNew.vue index f0fb9816..c7c91771 100644 --- a/src/components/project/ProjectManagerNew.vue +++ b/src/components/project/ProjectManagerNew.vue @@ -28,7 +28,7 @@