From d7d7da5c09340eafcd2e2c672e6b2c001a4cc0be Mon Sep 17 00:00:00 2001
From: hcong <1050828145@qq.com>
Date: 星期五, 08 十一月 2024 08:38:40 +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