From a3a09ed70bd2acfd1375f920fa2db3d9b0325b6b Mon Sep 17 00:00:00 2001 From: yuping <82253452@qq.com> Date: Fri, 4 Aug 2023 11:32:47 +0800 Subject: [PATCH] fix bug --- src/api/apis.js | 2 +- src/api/request.js | 57 +++++++++++++++++++- src/components/project/ProjectManagerNew.vue | 10 ++-- src/components/student/CommonStudent.vue | 12 +---- 4 files changed, 63 insertions(+), 18 deletions(-) diff --git a/src/api/apis.js b/src/api/apis.js index e7d25dd1..658a6a91 100644 --- a/src/api/apis.js +++ b/src/api/apis.js @@ -26,7 +26,7 @@ export const ASSESSMENT_DETAIL = (assessmentId)=>`/assessment/queryAssessmentDet export const USER_LIST_PAGE = "/admin/thirdApi/user/list"; //学员列表 没有分页数据 只能通过名称检索 速度较快 -export const USER_LIST = "/admin/thirdApi/user/searchList"; +export const USER_LIST = "/admin/thirdApi/user/list"; export const ORG_LIST = "/admin/thirdApi/org/list"; export const ORG_CHILD_LIST = "/admin/thirdApi/org/info"; diff --git a/src/api/request.js b/src/api/request.js index 302ef562..401d5a72 100644 --- a/src/api/request.js +++ b/src/api/request.js @@ -248,6 +248,58 @@ export function useRowsPage(_url, params, init = true) { }; } +/** + * 分页只返回 total 无分页信息 + * @param _url + * @param params + * @param init + * @param listing + */ +export function useTotalPage(_url, params, init = true,listing = false) { + + const state = reactive({ + data: [], + total: 1, + current: 1, + pages: 1, + pageNo: 1, + pageSize: 10, + loading: false + }); + + if (isRef(params) && listing) { + watch(params.value, () => { + fetch(); + }); + } + + if (isRef(_url)) { + watchEffect(fetch); + } else { + init && fetch(); + } + + function reset() { + state.data = []; + state.loading = false; + } + + function fetch() { + state.loading = true; + return request(unref(_url), unref(params)).then(r => { + state.data = r.data.list; + state.pages = r.data.total/state.pageSize || 1; + state.total = r.data.total; + state.loading = false; + }); + } + + return { + ...toRefs(state), + fetch, + reset, + }; +} export function usePage(_url, params, init = true,listing = false) { const state = reactive({ @@ -300,6 +352,7 @@ export function usePage(_url, params, init = true,listing = false) { total: 0, totalPage: 0, page: 1, + pageNo: 1, ...params }); @@ -313,8 +366,8 @@ export function usePage(_url, params, init = true,listing = 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.data = params.pageNo === 1 ? r.data.list : [...state.data, ...r.data.list]; + state.totalPage = r.data.total/10 || 1; state.total = r.data.total; state.loading = false; }); diff --git a/src/components/project/ProjectManagerNew.vue b/src/components/project/ProjectManagerNew.vue index c7c91771..027e2f02 100644 --- a/src/components/project/ProjectManagerNew.vue +++ b/src/components/project/ProjectManagerNew.vue @@ -56,7 +56,7 @@ const emit = defineEmits({}) const isOpen = ref(false) -const memberParam = ref({keyword: '', page: 1, pageSize: 20}) +const memberParam = ref({keyword: '', pageNo:1, pageSize: 20}) const {data: userList, loading} = useThrottlePage(USER_LIST, memberParam.value, false) @@ -83,7 +83,7 @@ onMounted(() => { const memberScroll = ({target: {scrollHeight, scrollTop, clientHeight}}) => { - scrollHeight === (clientHeight + scrollTop) && memberParam.value.page++ + scrollHeight === (clientHeight + scrollTop) && memberParam.value.pageNo++ }; //搜索学员 @@ -92,7 +92,7 @@ const searchMember = (keyword) => { loading.value = true isOpen.value = true userList.value = [] - memberParam.value.page = 1 + memberParam.value.pageNo = 1 memberParam.value.keyword = keyword console.log('searchMember', memberParam.value) }; @@ -100,12 +100,12 @@ const searchMember = (keyword) => { function blur() { isOpen.value = false memberParam.value.keyword = '' - memberParam.value.page = 1 + memberParam.value.pageNo = 1 } function change(e, l) { memberParam.value.keyword = '' - memberParam.value.page = 1 + memberParam.value.pageNo = 1 isOpen.value = false Array.isArray(l) && (selectOptions.value = l) Array.isArray(selectOptions.value) && emit('onChange', e, l, selectOptions.value.find(e => e.departId)?.departId, selectOptions.value.find(e => e.departId)?.departName, selectOptions.value.find(e => e.departId)?.orgName) diff --git a/src/components/student/CommonStudent.vue b/src/components/student/CommonStudent.vue index 462a4d58..40f1e64b 100644 --- a/src/components/student/CommonStudent.vue +++ b/src/components/student/CommonStudent.vue @@ -132,7 +132,7 @@
@@ -296,7 +296,7 @@