From b92fce8071f8f76e7ef2aa5491d0502cf051e3a8 Mon Sep 17 00:00:00 2001 From: "978184212@qq.com" <978184212@qq.com> Date: Tue, 25 Nov 2025 10:52:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packDetail/pages/sjdyj/index.vue | 382 +++++++++++++++++++------------ 1 file changed, 237 insertions(+), 145 deletions(-) diff --git a/packDetail/pages/sjdyj/index.vue b/packDetail/pages/sjdyj/index.vue index b9ff2c0..d100c96 100644 --- a/packDetail/pages/sjdyj/index.vue +++ b/packDetail/pages/sjdyj/index.vue @@ -12,8 +12,69 @@ + + + + + + + + + {{item.stationName}} + + + + {{item.alertTime}} + + + + + + + {{it}} + + + + + {{Item.name}} + + + {{Item.val}} + + + {{Item.valLow}}~{{Item.valHeight}} + + + {{Item.unit}} + + + + + + + + + + + + + + + 暂无数据 + + + + + - + @@ -42,66 +103,6 @@ - - - - - - - - - - {{item.stationName}} - - - - {{item.alertTime}} - - - - - - - {{it}} - - - - - {{Item.name}} - - - {{Item.val}} - - - {{Item.valHeight}} - - - - - {{Item.valLow}} - - - - - {{Item.unit}} - - - - - - - - - - - - - - 暂无数据 - - - - @@ -116,13 +117,13 @@ return { List: [], baseUrl: configService.apiUrl, - tabList: ['监测指标名称', '监测指标值', '高/低阈值', '计量单位'], + tabList: ['监测指标名称', '监测指标值', '阈值范围', '单位'], array: [], index: '', sampTime: '', deviceNo: '', allNum: '', - isLastpage: '', + isLastpage: false, intervalId: null, loadStatus: 'more', //加载样式:more-加载前样式,loading-加载中样式,nomore-没有数据样式 isLoadMore: false, //是否加载中 @@ -130,7 +131,7 @@ show1: false, top: 0, pageNo: 1, - pageSize: 4, + pageSize: 8, deleteUrl: '/applet/survMulchRecord/delete', stationName: '', stationCode: '', @@ -216,12 +217,18 @@ this.getList() }, onReachBottom() { - // 页面触底加载更多 - this.lower(); + // 页面触底加载更多 - 备用方案 + if (this.isActive === 0) { + this.lower(); + } }, onPullDownRefresh() { - // 页面下拉刷新 - this.refresherrefreshFun(); + // 页面下拉刷新 - 备用方案 + if (this.isActive === 0) { + this.refresherrefreshFun(); + } else { + uni.stopPullDownRefresh(); + } }, watch: { rangetime(newval) { @@ -248,119 +255,167 @@ }, // 下拉刷新被触发 refresherrefreshFun() { - this.pageNo = 1 - this.deviceNo = '' + console.log('下拉刷新触发'); + this.isRefresher = true; + this.pageNo = 1; + this.deviceNo = ''; + this.isLastpage = false; + this.loadStatus = 'more'; + this.getList().then(() => { + // 停止下拉刷新 + setTimeout(() => { + this.isRefresher = false; + uni.stopPullDownRefresh(); + }, 500); + }).catch(() => { + this.isRefresher = false; uni.stopPullDownRefresh(); }); }, // 切换类型 chooseClick(item, index) { this.isActive = index; - this.pageNo = 1 - this.deviceNo = '' - this.getList() + this.pageNo = 1; + this.deviceNo = ''; + this.isLastpage = false; + this.loadStatus = 'more'; + this.getList(); if (index == 1) { - this.sbeiList() + this.sbeiList(); } }, getList() { return new Promise((resolve, reject) => { - var params = {} - params.pageNo = this.pageNo - params.pageSize = this.pageSize + var params = { + pageNo: this.pageNo, + pageSize: this.pageSize + }; + uni.showLoading({ title: '加载中' }); - this.List = [] + + // 根据当前激活的tab设置URL + let url = ''; if (this.isActive == 0) { - var url = '/applet/wxclient/alertRecord' + url = '/applet/wxclient/alertRecord'; } else if (this.isActive == 1) { - var url = '/applet/survPestlightAlert/list' + url = '/applet/survPestlightAlert/list'; if (this.deviceNo) { - params.deviceNo = this.deviceNo + params.deviceNo = this.deviceNo; } } + this.$http.get(url, { params: params }).then(res => { + uni.hideLoading(); if (res.data.code == 0) { - var data = res.data.data.records - this.List = this.List.concat(data) - if (res.data.data.total != 0) { - this.allNum = Number(res.data.data.total) / Number(this.pageSize) + ''; - if (this.allNum.indexOf('.') == -1) { - this.allNum = this.allNum; - } else { - this.allNum = parseInt(Number(this.allNum) + 1); - } - if (this.pageNo == this.allNum) { + var data = res.data.data.records || []; + + // 如果是第一页,清空列表;否则追加 + if (this.pageNo === 1) { + this.List = data; + } else { + this.List = this.List.concat(data); + } + + // 更新分页状态 + const total = res.data.data.total || 0; + if (total > 0) { + const totalPages = Math.ceil(total / this.pageSize); + if (this.pageNo >= totalPages || data.length < this.pageSize) { this.isLastpage = true; - this.loadStatus = 'nomore' + this.loadStatus = 'nomore'; } else { this.isLastpage = false; - this.loadStatus = 'more' + this.loadStatus = 'more'; } } else { this.isLastpage = true; - this.loadStatus = 'nomore' + this.loadStatus = 'nomore'; } + } else { + // 接口返回错误 + this.isLastpage = true; + this.loadStatus = 'nomore'; } - uni.hideLoading(); - this.isRefresher = false - resolve() + this.isRefresher = false; + resolve(); }).catch(err => { uni.hideLoading(); - reject(err) - }) - }) + console.error('获取列表失败:', err); + this.isLastpage = true; + this.loadStatus = 'nomore'; + this.isRefresher = false; + reject(err); + }); + }); }, + // 上拉加载更多 lower() { - // 最后一页了,取消下拉功能 - if (this.isLastpage) { - return + console.log('上拉加载更多触发'); + // 如果是最后一页或正在加载中,直接返回 + if (this.isLastpage || this.loadStatus === 'loading') { + return; } - clearInterval(this.intervalId); - var num = 1; - this.intervalId = setInterval(() => { - num = num + 1; - }, 1000) + + this.loadStatus = 'loading'; this.pageNo = this.pageNo + 1; - var params = {} - params.pageNo = this.pageNo - params.pageSize = this.pageSize + + var params = { + pageNo: this.pageNo, + pageSize: this.pageSize + }; + + // 根据当前激活的tab设置URL + let url = ''; if (this.isActive == 0) { - var url = '/applet/survPestlightAlert/list' - if (this.deviceNo) { - params.deviceNo = this.deviceNo - } + url = '/applet/wxclient/alertRecord'; } else if (this.isActive == 1) { - var url = '/applet/wxclient/alertRecord' + url = '/applet/survPestlightAlert/list'; + if (this.deviceNo) { + params.deviceNo = this.deviceNo; + } } + this.$http.get(url, { params: params }).then(res => { if (res.data.code == 0) { - var data = res.data.data.records - this.List = this.List.concat(data) - if (res.data.data.total != 0) { - if (this.pageNo == this.allNum) { + var data = res.data.data.records || []; + this.List = this.List.concat(data); + + // 更新分页状态 + const total = res.data.data.total || 0; + if (total > 0) { + const totalPages = Math.ceil(total / this.pageSize); + if (this.pageNo >= totalPages || data.length < this.pageSize) { this.isLastpage = true; - this.loadStatus = 'nomore' + this.loadStatus = 'nomore'; } else { this.isLastpage = false; - this.loadStatus = 'more' + this.loadStatus = 'more'; } } else { this.isLastpage = true; - this.loadStatus = 'nomore' + this.loadStatus = 'nomore'; } + } else { + this.isLastpage = true; + this.loadStatus = 'nomore'; + this.pageNo = this.pageNo - 1; // 加载失败时回退页码 } - }) + }).catch(err => { + console.error('加载更多失败:', err); + this.loadStatus = 'more'; + this.pageNo = this.pageNo - 1; // 加载失败时回退页码 + }); }, changenr() { - this.pageNo = 1 - this.getList() + this.pageNo = 1; + this.getList(); }, // 趋势图接口 async qushiList() { @@ -369,21 +424,21 @@ deployId: this.deployId, startTime: this.startTime, endTime: this.endTime, - } - const res = await this.$http.post('/applet/survAlertRecord/alertSummary', data) + }; + const res = await this.$http.post('/applet/survAlertRecord/alertSummary', data); if (res.data.code === 0) { - let ovelit = res.data.data + let ovelit = res.data.data; this.resolt = ovelit.itemList.map(item => { return { ...item, data: ovelit.dataMap[item.entity] || [] - } - }) - this.timeList = ovelit.timeList || [] + }; + }); + this.timeList = ovelit.timeList || []; this.getServerData(this.resolt); } } catch (error) { - console.error("获取趋势图数据失败", error) + console.error("获取趋势图数据失败", error); } }, // 设备列表 @@ -393,37 +448,37 @@ title: '加载中' }); - const res = await this.$http.get('/applet/survDeviceDeploy/deviceList?stationCode=') + const res = await this.$http.get('/applet/survDeviceDeploy/deviceList?stationCode='); if (res.data.code === 0) { this.rangeList = res.data.data.map((lit, index) => { return { "value": index, "text": lit.deployDes, "id": lit.id, - } - }) + }; + }); if (this.rangeList.length > 0) { - this.deployId = this.rangeList[this.value].id + this.deployId = this.rangeList[this.value].id; await this.qushiList(); } } uni.hideLoading(); } catch (error) { - console.error("获取设备列表失败", error) + console.error("获取设备列表失败", error); uni.hideLoading(); } }, // 选择deployid change(e) { - this.deployId = this.rangeList[this.value].id - this.sbeiList() + this.deployId = this.rangeList[this.value].id; + this.sbeiList(); }, // 选择日期范围 maskClick(e) { - this.startTime = e[0] - this.endTime = e[1] + this.startTime = e[0]; + this.endTime = e[1]; }, // 处理图表数据(带高亮超出部分) getServerData(val) { @@ -504,6 +559,8 @@ } + + \ No newline at end of file