|
|
@@ -60,9 +60,10 @@
|
|
|
</div>
|
|
|
|
|
|
<list
|
|
|
- v-model:loading="loading"
|
|
|
+ :loading="loading"
|
|
|
:finished="finished"
|
|
|
finished-text="暂无更多播报"
|
|
|
+ :immediate-check="true"
|
|
|
@load="onLoad"
|
|
|
class="broadcast-list"
|
|
|
:style="{ height: !isHeaderShow ? 'calc(100vh - 460px)' : 'calc(100vh - 535px)' }"
|
|
|
@@ -109,7 +110,7 @@
|
|
|
|
|
|
<script setup>
|
|
|
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 { Badge, List } from "vant";
|
|
|
import weatherInfo from "@/components/weatherInfo.vue";
|
|
|
@@ -264,42 +265,61 @@ const finished = ref(false);
|
|
|
const currentPage = ref(1);
|
|
|
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;
|
|
|
- VE_API.monitor
|
|
|
- .broadcastPage({
|
|
|
+ try {
|
|
|
+ const res = await VE_API.monitor.broadcastPage({
|
|
|
farmId: gardenId.value,
|
|
|
limit: pageSize.value,
|
|
|
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 params = {
|
|
|
@@ -386,6 +406,18 @@ const handleMaskClick = () => {
|
|
|
};
|
|
|
|
|
|
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 }) => {
|
|
|
localStorage.setItem('isGarden', true);
|
|
|
gardenId.value = id;
|
|
|
@@ -396,7 +428,7 @@ const changeGarden = ({ id }) => {
|
|
|
finished.value = false;
|
|
|
broadcastList.value = [];
|
|
|
getStayCount();
|
|
|
- getBroadcastList();
|
|
|
+ getBroadcastList(1, false);
|
|
|
};
|
|
|
|
|
|
function handlePage(url) {
|