From aa1f56d5ef2d48b980a2fab3e88379efbe09b0d1 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期二, 26 十二月 2023 17:04:27 +0800 Subject: [PATCH] 评估任务模块新增任务状态管理逻辑 --- src/composables/fetchData.js | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/composables/fetchData.js b/src/composables/fetchData.js index 3598753..4b5458e 100644 --- a/src/composables/fetchData.js +++ b/src/composables/fetchData.js @@ -1,13 +1,13 @@ // 鎺ュ彛鏁版嵁鐨勮幏鍙� -import { onActivated, onDeactivated, ref, watch } from 'vue'; +import { ref, watch, computed } from 'vue'; -export function useFetchData(fetch) { +export function useFetchData() { // 鍒嗛〉淇℃伅 - const currentPage = ref(1); - const totalPage = ref(1); + const page = ref(1); + const pageNum = ref(1); const pageSize = ref(20); const total = ref(0); - watch(currentPage, (nValue, oValue) => { + watch(page, (nValue, oValue) => { if (nValue != oValue) { fetchData(); } @@ -21,14 +21,20 @@ // 鍔犺浇鐘舵��, 0: 鍔犺浇瀹屾垚; 1: 鍔犺浇涓�; 2: 宸插叏閮ㄥ姞杞�; 3: 鍔犺浇澶辫触; const loadStatus = ref(0); + const loading = computed(() => { + return loadStatus.value == 1; + }); + // 鏁版嵁鑾峰彇 - function fetchData() { + function fetchData(fetch) { loadStatus.value = 1; - fetch(currentPage.value, pageSize.value) + fetch(page.value, pageSize.value) .then((pageInfo) => { - currentPage.value = pageInfo.currentPage; - totalPage.value = pageInfo.totalPage; - total.value = pageInfo.total; + if (pageInfo) { + page.value = pageInfo.page ? pageInfo.page : 1; + pageNum.value = pageInfo.pageNum ? pageInfo.pageNum : 1; + total.value = pageInfo.total ? pageInfo.total : 0; + } loadStatus.value = 0; }) @@ -40,5 +46,5 @@ }); } - return {currentPage, totalPage, pageSize, total, loadStatus, fetchData} + return { page, pageNum, pageSize, total, loadStatus, loading, fetchData }; } -- Gitblit v1.9.3