Browse Source

feat:修改bug

wangsisi 1 week ago
parent
commit
5a90b9bcd9

+ 2 - 3
src/views/old_mini/agri_services/components/servicesHall.vue

@@ -235,7 +235,6 @@ const getStoreList = async (isLoadMore = false) => {
     
     
     // 生成请求的唯一标识
     // 生成请求的唯一标识
     const requestKey = generateRequestKey(params);
     const requestKey = generateRequestKey(params);
-    
     // 如果正在加载相同的请求,直接返回
     // 如果正在加载相同的请求,直接返回
     if (loading.value && currentRequestKey.value === requestKey) {
     if (loading.value && currentRequestKey.value === requestKey) {
         return;
         return;
@@ -245,7 +244,6 @@ const getStoreList = async (isLoadMore = false) => {
     if (loading.value) {
     if (loading.value) {
         return;
         return;
     }
     }
-    
     // 设置当前请求标识和加载状态
     // 设置当前请求标识和加载状态
     currentRequestKey.value = requestKey;
     currentRequestKey.value = requestKey;
     loading.value = true;
     loading.value = true;
@@ -304,6 +302,7 @@ const getStoreList = async (isLoadMore = false) => {
 const onLoad = async () => {
 const onLoad = async () => {
     if (finished.value) return;
     if (finished.value) return;
     const isLoadMore = page.value > 1;
     const isLoadMore = page.value > 1;
+    loading.value = false;
     await getStoreList(isLoadMore);
     await getStoreList(isLoadMore);
     // 加载完成后再增加页码
     // 加载完成后再增加页码
     if (!finished.value) {
     if (!finished.value) {
@@ -361,7 +360,7 @@ function handleLocationChange(data) {
     } else {
     } else {
         // 重置为初始位置
         // 重置为初始位置
         mapPoint.value = store.state.home.miniUserLocationPoint;
         mapPoint.value = store.state.home.miniUserLocationPoint;
-        paramsPage.value.distance = "";
+        paramsPage.value.distance = "不限范围";
         
         
         // 获取初始位置的坐标
         // 获取初始位置的坐标
         const initialPoint = util.wktCastGeom(mapPoint.value).getFirstCoordinate();
         const initialPoint = util.wktCastGeom(mapPoint.value).getFirstCoordinate();

+ 62 - 30
src/views/old_mini/monitor/index.vue

@@ -60,9 +60,10 @@
             </div>
             </div>
 
 
             <list
             <list
-                v-model:loading="loading"
+                :loading="loading"
                 :finished="finished"
                 :finished="finished"
                 finished-text="暂无更多播报"
                 finished-text="暂无更多播报"
+                :immediate-check="true"
                 @load="onLoad"
                 @load="onLoad"
                 class="broadcast-list"
                 class="broadcast-list"
                 :style="{ height: !isHeaderShow ? 'calc(100vh - 460px)' : 'calc(100vh - 535px)' }"
                 :style="{ height: !isHeaderShow ? 'calc(100vh - 460px)' : 'calc(100vh - 535px)' }"
@@ -109,7 +110,7 @@
 
 
 <script setup>
 <script setup>
 import customHeader from "@/components/customHeader.vue";
 import customHeader from "@/components/customHeader.vue";
-import { ref, computed, onActivated, onDeactivated } from "vue";
+import { ref, computed, onActivated, onDeactivated, onMounted } from "vue";
 import { useStore } from "vuex";
 import { useStore } from "vuex";
 import { Badge, List } from "vant";
 import { Badge, List } from "vant";
 import weatherInfo from "@/components/weatherInfo.vue";
 import weatherInfo from "@/components/weatherInfo.vue";
@@ -264,42 +265,61 @@ const finished = ref(false);
 const currentPage = ref(1);
 const currentPage = ref(1);
 const pageSize = ref(10);
 const pageSize = ref(10);
 
 
-const getBroadcastList = (page = 1, isLoadMore = false) => {
-    if (!gardenId.value) return;
+const getBroadcastList = async (page = 1, isLoadMore = false) => {
+    if (!gardenId.value) {
+        loading.value = false;
+        return;
+    }
+    
+    // 如果正在加载,直接返回(避免重复请求)
+    if (loading.value) {
+        return;
+    }
+    
     loading.value = true;
     loading.value = true;
-    VE_API.monitor
-        .broadcastPage({
+    try {
+        const res = await VE_API.monitor.broadcastPage({
             farmId: gardenId.value,
             farmId: gardenId.value,
             limit: pageSize.value,
             limit: pageSize.value,
             page: page,
             page: page,
-        })
-        .then((res) => {
-            const newData = res.data || [];
-            if (isLoadMore) {
-                broadcastList.value = [...broadcastList.value, ...newData];
-            } else {
-                broadcastList.value = newData;
-            }
-
-            // 判断是否还有更多数据
-            if (newData.length < pageSize.value) {
-                finished.value = true;
-            }
-
-            loading.value = false;
-        })
-        .finally(() => {
-            loading.value = true;
         });
         });
+        
+        const newData = res.data || [];
+        if (isLoadMore) {
+            broadcastList.value = [...broadcastList.value, ...newData];
+        } else {
+            broadcastList.value = newData;
+        }
+
+        // 判断是否还有更多数据
+        if (newData.length < pageSize.value) {
+            finished.value = true;
+        } else {
+            finished.value = false;
+            // 如果未完成,页码+1,为下次加载做准备
+            currentPage.value = page + 1;
+        }
+    } catch (error) {
+        console.error('获取播报列表失败:', error);
+        finished.value = true;
+    } finally {
+        // 确保 loading 状态被正确设置为 false
+        loading.value = false;
+    }
 };
 };
 
 
 // 滚动加载更多
 // 滚动加载更多
-const onLoad = () => {
-    if (finished.value) return;
-
-    currentPage.value += 1;
-    getBroadcastList(currentPage.value, true);
+const onLoad = async () => {
+    if (finished.value || loading.value) return;
+
+    // 判断是否是首次加载(页码为1)
+    const isLoadMore = currentPage.value > 1;
+    const pageToLoad = currentPage.value;
+    
+    // 加载数据(页码会在 getBroadcastList 成功后自动更新)
+    await getBroadcastList(pageToLoad, isLoadMore);
 };
 };
+
 // 卡片点击事件
 // 卡片点击事件
 const handleCardClick = (card) => {
 const handleCardClick = (card) => {
     const params = {
     const params = {
@@ -386,6 +406,18 @@ const handleMaskClick = () => {
 };
 };
 
 
 const gardenId = ref(store.state.home.gardenId);
 const gardenId = ref(store.state.home.gardenId);
+
+// 初始化加载数据
+onMounted(() => {
+    if (gardenId.value) {
+        currentPage.value = 1;
+        finished.value = false;
+        broadcastList.value = [];
+        getStayCount();
+        // 不在这里手动加载,让 List 组件的 immediate-check 自动触发首次加载
+    }
+});
+
 const changeGarden = ({ id }) => {
 const changeGarden = ({ id }) => {
     localStorage.setItem('isGarden', true);
     localStorage.setItem('isGarden', true);
     gardenId.value = id;
     gardenId.value = id;
@@ -396,7 +428,7 @@ const changeGarden = ({ id }) => {
     finished.value = false;
     finished.value = false;
     broadcastList.value = [];
     broadcastList.value = [];
     getStayCount();
     getStayCount();
-    getBroadcastList();
+    getBroadcastList(1, false);
 };
 };
 
 
 function handlePage(url) {
 function handlePage(url) {