From 67cfda12aa1ff4aaba3726164e7ace7e2a77cffe Mon Sep 17 00:00:00 2001 From: fengerli <528575642@qq.com> Date: Thu, 25 Sep 2025 15:04:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 3 +- pages/common/index/index.vue | 350 +++++++++++++++++------------------ utils/request.js | 2 +- 3 files changed, 177 insertions(+), 178 deletions(-) diff --git a/pages.json b/pages.json index 51d1e4d..75d84ba 100644 --- a/pages.json +++ b/pages.json @@ -25,8 +25,7 @@ { "path": "pages/common/index/index", "style": { - "navigationStyle": "custom", - "enablePullDownRefresh": true + "navigationStyle": "custom" } }, { diff --git a/pages/common/index/index.vue b/pages/common/index/index.vue index 2cf3a9c..9e1e405 100644 --- a/pages/common/index/index.vue +++ b/pages/common/index/index.vue @@ -9,8 +9,8 @@ - {{tab.typeName}} + :class="['tab-item', activeTab === index ? 'active' : '']" @click="switchTab(tab, index)"> + {{ tab.typeName }} @@ -18,45 +18,47 @@ - + 报警 位置 发送信息 - - + + + :style="{ border: item.communicationMode == 0 && item.onlineStatus == 1 && item.alarmStatus == 1 ? '1px solid rgba(224, 52, 52, 1)' : 'none' }"> - 设备:{{item.deviceName}} + 设备:{{ item.deviceName }} - ID:{{item.deviceImei}} + ID:{{ + item.deviceImei }} - ID:{{item.deviceMac}} + ID:{{ item.deviceMac }} 在线 + v-if="item.communicationMode == 0 && item.onlineStatus == 1">在线 + 离线 - 电量:{{item.battery || '0'}}% + v-if="item.communicationMode == 0 && item.onlineStatus == 0">离线 + + 电量:{{ item.battery || '0' }}% + v-if="item.communicationMode == 0 && item.onlineStatus == 1 && item.alarmStatus == 1"> 报警中 - + 已连接 未连接 @@ -76,7 +78,7 @@ 暂无数据 - + @@ -145,11 +147,11 @@ deviceReName } from '@/api/common/index.js' import BleHelper from '@/utils/BleHelper.js'; - var ble=null; + import MescrollUni from 'mescroll-uni/mescroll-uni.vue' + var ble = null; export default { - onPullDownRefresh() { - // 执行下拉刷新时的操作,比如重新获取数据 - this.onIntall(); + components: { + MescrollUni }, data() { return { @@ -201,9 +203,24 @@ action: 'share' } ], + mescroll: null, + downOption: { + auto: false + }, + upOption: { + auto: false, + noMoreSize: 1, + offset: 50, + isLock: false, + empty: { + tip: '暂无相关数据' + } + }, + page: 1, // 当前页码 size: 10, // 每页条数 total: 0, // 总数据量 + loadedCount: 0, // 关键:记录已加载的总条数 loading: false, finished: false, deviceId: '', @@ -212,13 +229,57 @@ } }, methods: { + mescrollInit(mescroll) { + this.mescroll = mescroll; + }, + // 下拉刷新 + downCallback() { + const currentDeviceType = this.activeTabInfo?.id === '' ? undefined : this.activeTabInfo?.id; + const tempList = [...this.deviceList]; + + // 重置分页参数 + this.page = 1; + this.finished = false; + this.loadedCount = 0; + + this.getData(currentDeviceType) + .then(() => { + + this.mescroll.endDownScroll(true); + }) + .catch(() => { + + this.deviceList = tempList; + this.mescroll.endDownScroll(false); + }); + }, + // 上拉加载 + upCallback() { + // 防止重复加载 + if (this.finished || this.loading) { + this.mescroll.endUpScroll(false); + return; + } + const currentDeviceType = this.activeTabInfo?.id === '' ? undefined : this.activeTabInfo?.id; + this.getData(currentDeviceType) + .then(() => { + const hasMore = this.loadedCount < this.total; + console.log(`上拉加载 - 已加载: ${this.loadedCount}, 总数: ${this.total}, 是否还有更多: ${hasMore}`); + this.mescroll.endUpScroll(hasMore); + }) + .catch(() => { + // 失败时回退页码 + this.page--; + this.mescroll.endUpScroll(false); + }); + }, // 更多 allMore() { this.showshare = !this.showshare; }, // 所有分享,所有类型 handleshareClick(item) { - this.showshare = false; // 关闭弹窗 + this.showshare = false; switch (item.action) { case 'type': uni.navigateTo({ @@ -236,17 +297,16 @@ closePopup(type) { if (type === 'delete') { this.deleteShow = false; - uni.showTabBar(); // 显示TabBar + uni.showTabBar(); } else if (type === 'rename') { this.RenameModel = false; - uni.showTabBar(); // 显示TabBar + uni.showTabBar(); } }, // tab导航切换栏 getTab() { deviceTypeList({}).then((res) => { if (res.code == 200) { - //console.log("deviceTypeList=" + JSON.stringify(res.data)); this.tabs = [{ id: '', name: '全部设备', @@ -266,46 +326,77 @@ switchTab(tab, index) { this.deviceList = []; this.activeTab = index; - this.activeTabInfo = tab - this.page = 1; // 重置页码 - this.finished = false; // 重 - // 明确传递参数,空字符串改为null或undefined + this.activeTabInfo = tab; + // 完全重置分页状态 + this.page = 1; + this.finished = false; + this.loadedCount = 0; + const deviceType = tab.id === '' ? undefined : tab.id; this.getData(deviceType); - }, - // 获取设备列表 - getData(deviceType = '') { - if (this.loading || this.finished) return; - this.loading = true; - let data = { - pageNum: this.page, - pageSize: this.size, - deviceType: deviceType // 使用传入的设备类型 + + if (this.mescroll) { + this.mescroll.resetUpScroll(); } - deviceInfo(data).then((res) => { - if (res.code == 200) { - const newDevices = res.rows.map(device => ({ - ...device, - showConfirm: false - })); - - // 如果是第一页或切换分类,替换数据 - this.deviceList = this.page === 1 ? newDevices : [...this.deviceList, ...newDevices]; - this.total = res.total; - // 判断是否加载完成 - if (res.rows.length < this.size || this.deviceList.length >= this.total) { - this.finished = true; - } else { - this.page++; - } - } - }).finally(() => { - this.loading = false; - }); }, - // 滚动触底事件处理 - onScrollToLower() { - this.getData(); + // 获取设备列表 - 核心修复 + getData(deviceType = '') { + return new Promise((resolve, reject) => { + if (this.loading || this.finished) { + reject('正在加载或已无更多数据'); + return; + } + + this.loading = true; + let data = { + pageNum: this.page, + pageSize: this.size, + deviceType: deviceType + } + + deviceInfo(data).then((res) => { + if (res.code == 200) { + // 第一页加载时初始化总数据量 + if (this.page === 1) { + this.total = res.total; + this.loadedCount = 0; // 重置计数 + console.log(`第1页加载 - 总数据量: ${this.total}`); + } + + const newDevices = res.rows.map(device => ({ + ...device, + showConfirm: false + })); + + // 累加已加载数量 + this.loadedCount += newDevices.length; + console.log(`第${this.page}页加载 - 新增: ${newDevices.length}, 累计: ${this.loadedCount}`); + + // 数据累加逻辑(第一页替换,其他页追加) + if (this.page === 1) { + this.deviceList = newDevices; + } else { + this.deviceList = [...this.deviceList, ...newDevices]; + } + + // 关键:正确判断是否加载完成 + if (this.loadedCount >= this.total || newDevices.length < this.size) { + this.finished = true; + console.log(`加载完成 - 已加载${this.loadedCount}/${this.total}`); + } else { + this.page++; // 只有还有数据时才增加页码 + } + resolve(); + } else { + reject(res.msg || '获取数据失败'); + } + }).catch((err) => { + console.error('获取设备列表失败:', err); + reject(err); + }).finally(() => { + this.loading = false; + }); + }); }, // 添加扫一扫图标 scan() { @@ -317,19 +408,12 @@ }, // 添加设备,扫一扫,蓝牙 handleMenuClick(item) { - this.showTooltip = false; // 关闭弹窗 + this.showTooltip = false; switch (item.action) { case 'scan': - // 扫一扫 uni.scanCode({ success: (res) => { - console.log('条码内容:', res); - // 清除之前的数据 - this.previousScanResult = null; - // 处理新的扫码结果 const cleanedResult = res.result.trim(); - console.log('扫码结果:', cleanedResult); - // 跳转并传递扫描结果 uni.navigateTo({ url: `/pages/common/qrcode/qrcode?deviceId=${encodeURIComponent(cleanedResult)}` }); @@ -352,10 +436,6 @@ }, // 右滑点击事件处理 handleSwipeClick(e, item, index) { - const { - content - } = e - console.log(item, 'eeeee'); switch (e.content.text) { case '删除': this.handleDeleteDevice(item, index) @@ -374,9 +454,6 @@ // 确认删除 handleBtn() { uni.showTabBar() - let data = { - id: this.deviceId.id - } deviceUnbind(this.deviceId.id).then((res) => { if (res.code == 200) { uni.showToast({ @@ -389,10 +466,11 @@ this.getTab() }, 500); this.deleteShow = false - // 关闭所有滑动项 - this.$refs.swipeAction.closeAll(); - - ble && ble.DropDevice(data.id); + if (this.$refs.swipeAction) { + this.$refs.swipeAction.closeAll(); + } + + ble && ble.DropDevice(this.deviceId.id); } else { uni.showToast({ title: res.msg, @@ -410,11 +488,10 @@ }, handleBtnName() { uni.showTabBar() - let data = { + deviceReName({ id: this.deviceId.id, deviceName: this.deviceName - } - deviceReName(data).then((res) => { + }).then((res) => { if (res.code == 200) { uni.showToast({ title: res.msg, @@ -426,8 +503,9 @@ }, 500); this.RenameModel = false this.deviceName = '' - // 关闭所有滑动项 - this.$refs.swipeAction.closeAll(); + if (this.$refs.swipeAction) { + this.$refs.swipeAction.closeAll(); + } } else { uni.showToast({ title: res.msg, @@ -440,13 +518,8 @@ // 报警 callpolice() { const currentTab = this.tabs[this.activeTab]; - const deviceType = currentTab.id || ''; - console.log(`跳转到发送信息页面\n当前设备类型: ${deviceType}\n设备类型名称: ${currentTab.typeName}`); uni.navigateTo({ url: '/pages/6170/callPolice/index', - events: { - ack: function(data) {} - }, success: (res) => { res.eventChannel.emit('devicePolice', { data: currentTab @@ -457,16 +530,10 @@ // 发生短信 handleSend() { const currentTab = this.tabs[this.activeTab]; - const deviceType = currentTab.id || ''; - console.log(`跳转到发送信息页面\n当前设备类型: ${deviceType}\n设备类型名称: ${currentTab.typeName}`); uni.navigateTo({ url: '/pages/common/send/index', - events: { - ack: function(data) {} - }, success: (res) => { res.eventChannel.emit('deviceSend', { - //data: deviceType, data: currentTab }); } @@ -476,11 +543,7 @@ location() { uni.navigateTo({ url: '/pages/common/map/index', - events: { - ack: function(data) {} - }, success: (res) => { - // 页面跳转成功后的回调函数 res.eventChannel.emit('Map', { data: this.deviceList, }); @@ -490,50 +553,42 @@ // 列表跳转 handleFile(item) { let url = item.detailPageUrl; - // console.log("url=",url); - // if(!url){ - //url="/pages/670/HBY670" - // } uni.navigateTo({ url: url, - events: { - ack: function(data) {} - }, success: (res) => { - // 页面跳转成功后的回调函数 res.eventChannel.emit('detailData', { data: item, deviceType: this.tabs[this.activeTab].id || '', - apiType: 'listA' //标识,根据这个参数,区分普通详情,分享跳转详情,查不一样的权限信息 + apiType: 'listA' }); - },fail(ex) { - console.log("ex=",ex); + }, + fail(ex) { + console.log("ex=", ex); } }) }, onIntall() { this.page = 1; this.finished = false; + this.loadedCount = 0; // 重置计数 const deviceType = this.activeTabInfo?.id === '' ? undefined : this.activeTabInfo?.id; - this.getData(deviceType); // 重新加载第一页数据 + this.getData(deviceType); setTimeout(() => { - // 停止下拉刷新动画 uni.stopPullDownRefresh(); }, 800); }, updateDeviceStatus(data) { this.deviceList = this.deviceList .map(item => { - if (!item) return null; // 如果 item 是 undefined/null,返回 null + if (!item) return null; if (item.communicationMode == 0) { let messageData; try { messageData = data.message; } catch (e) { - return item; // 解析失败则返回原 item + return item; } const [deviceId, onlineStatus, battery] = messageData.state || []; - console.log('我收到消息了没', item.battery); return { ...item, battery: battery ?? item.battery, @@ -549,20 +604,16 @@ onLoad() { this.getTab() this.onIntall() - // 绑定页面做了监听,新增成功,刷新页面 uni.$on('refreshDeviceList', () => { - this.getTab() // 刷新数据 + this.getTab() this.onIntall() }); - // 监听设备状态更新事件 uni.$on('deviceStatusUpdate', (data) => { - console.log('列表收到消息了么'); this.onIntall() }); - ble=BleHelper.getBleTool(); + ble = BleHelper.getBleTool(); }, beforeDestroy() { - // 组件销毁前移除监听器 uni.$off('refreshDeviceList'); }, onUnload() { @@ -573,7 +624,7 @@ \ No newline at end of file + diff --git a/utils/request.js b/utils/request.js index 9bdd4b6..7d28d86 100644 --- a/utils/request.js +++ b/utils/request.js @@ -1,5 +1,5 @@ import config from '../config/index.js'; -const env = 'development'; //production development //开发of线上 改这里就行 +const env = 'production'; //production development //开发of线上 改这里就行 const BASE = config[env]; const request = (options) => { console.log("options"+JSON.stringify(options),BASE.BASE_URL) From 511caa60d1fbbb4df940e09f915ed64bcd27d406 Mon Sep 17 00:00:00 2001 From: fengerli <528575642@qq.com> Date: Thu, 25 Sep 2025 15:07:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/common/index/index.vue | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pages/common/index/index.vue b/pages/common/index/index.vue index 9e1e405..d85e86f 100644 --- a/pages/common/index/index.vue +++ b/pages/common/index/index.vue @@ -24,7 +24,7 @@ 发送信息 + :down="downOption" :fixed="false"> @@ -210,8 +210,7 @@ upOption: { auto: false, noMoreSize: 1, - offset: 50, - isLock: false, + offset: 80, empty: { tip: '暂无相关数据' } @@ -220,7 +219,7 @@ page: 1, // 当前页码 size: 10, // 每页条数 total: 0, // 总数据量 - loadedCount: 0, // 关键:记录已加载的总条数 + loadedCount: 0, loading: false, finished: false, deviceId: '',