1
0
forked from dyf/APP

解决冲突

This commit is contained in:
liub
2025-09-25 16:16:49 +08:00
2 changed files with 175 additions and 177 deletions

View File

@ -25,8 +25,7 @@
{ {
"path": "pages/common/index/index", "path": "pages/common/index/index",
"style": { "style": {
"navigationStyle": "custom", "navigationStyle": "custom"
"enablePullDownRefresh": true
} }
}, },
{ {

View File

@ -9,8 +9,8 @@
<scroll-view class="tab-bar" scroll-x="true" scroll-with-animation> <scroll-view class="tab-bar" scroll-x="true" scroll-with-animation>
<view class="tab-container"> <view class="tab-container">
<view v-for="(tab, index) in tabs" :key="index" <view v-for="(tab, index) in tabs" :key="index"
:class="['tab-item', activeTab === index ? 'active' : '']" @click="switchTab(tab,index)"> :class="['tab-item', activeTab === index ? 'active' : '']" @click="switchTab(tab, index)">
{{tab.typeName}} {{ tab.typeName }}
</view> </view>
</view> </view>
</scroll-view> </scroll-view>
@ -18,45 +18,47 @@
<image src="/static/images/common/more.png" mode="aspectFit" class="more"></image> <image src="/static/images/common/more.png" mode="aspectFit" class="more"></image>
</view> </view>
</view> </view>
<view class="sendFlex" <view class="sendFlex" v-if="activeTab && activeTab.id !== '' && activeTabInfo.communicationMode == 0">
v-if="activeTab && activeTab.id !== ''&& activeTabInfo.communicationMode==0">
<view class="callpolice" @click="callpolice">报警</view> <view class="callpolice" @click="callpolice">报警</view>
<view class="Sendmessage" @click="location">位置</view> <view class="Sendmessage" @click="location">位置</view>
<view class="Sendmessage" @click="handleSend">发送信息</view> <view class="Sendmessage" @click="handleSend">发送信息</view>
</view> </view>
<scroll-view class="device-list" scroll-y @scrolltolower="onScrollToLower" :lower-threshold="100" <mescroll-uni class="device-list" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption"
style="height:80vh;"> :down="downOption" :fixed="false">
<view v-if="deviceList.length>0"> <view v-if="deviceList.length > 0">
<uni-swipe-action ref="swipeAction"> <uni-swipe-action ref="swipeAction">
<block v-for="(item, index) in deviceList" :key="index" :ref="'swipeItem_' + index"> <block v-for="(item, index) in deviceList" :key="index" :ref="'swipeItem_' + index">
<uni-swipe-action-item :right-options="Options" <uni-swipe-action-item :right-options="Options"
@click="handleSwipeClick($event, item, index)" class="device-card" @click="handleSwipeClick($event, item, index)" class="device-card"
:style="{ border: item.communicationMode==0 && item.onlineStatus==1 && item.alarmStatus==1 ? '1px solid rgba(224, 52, 52, 1)' : 'none' }"> :style="{ border: item.communicationMode == 0 && item.onlineStatus == 1 && item.alarmStatus == 1 ? '1px solid rgba(224, 52, 52, 1)' : 'none' }">
<view @click.stop="handleFile(item)"> <view @click.stop="handleFile(item)">
<view class="device-header"> <view class="device-header">
<view class="deviceIMG"> <view class="deviceIMG">
<image :src="item.devicePic" class="IMG" mode="aspectFit"></image> <image :src="item.devicePic" class="IMG" mode="aspectFit"></image>
</view> </view>
<view class="device-name"> <view class="device-name">
<view>设备:{{item.deviceName}}</view> <view>设备:{{ item.deviceName }}</view>
<view class="ID"> <view class="ID">
<view class="ID" v-if="item.communicationMode==0">ID:{{item.deviceImei}} <view class="ID" v-if="item.communicationMode == 0">ID:{{
item.deviceImei }}
</view> </view>
<view class="ID" v-else>ID:{{item.deviceMac}}</view> <view class="ID" v-else>ID:{{ item.deviceMac }}</view>
<!-- 在线状态 --> <!-- 在线状态 -->
<view class="onlines" <view class="onlines"
v-if="item.communicationMode==0 && item.onlineStatus==1">在线</view> v-if="item.communicationMode == 0 && item.onlineStatus == 1">在线
</view>
<!-- 离线状态 --> <!-- 离线状态 -->
<view class="offlines" <view class="offlines"
v-if="item.communicationMode==0 && item.onlineStatus==0">离线</view> v-if="item.communicationMode == 0 && item.onlineStatus == 0">离线
<view>电量{{item.battery || '0'}}%</view> </view>
<view>电量{{ item.battery || '0' }}%</view>
</view> </view>
</view> </view>
</view> </view>
<view class="device-callpolice" <view class="device-callpolice"
v-if="item.communicationMode==0 && item.onlineStatus==1 && item.alarmStatus==1"> v-if="item.communicationMode == 0 && item.onlineStatus == 1 && item.alarmStatus == 1">
报警中</view> 报警中</view>
<view v-if="item.communicationMode==1"> <view v-if="item.communicationMode == 1">
<view class="device-status online">已连接</view> <view class="device-status online">已连接</view>
<view class="device-status unline">未连接</view> <view class="device-status unline">未连接</view>
</view> </view>
@ -76,7 +78,7 @@
</view> </view>
暂无数据 暂无数据
</view> </view>
</scroll-view> </mescroll-uni>
</view> </view>
<!-- 删除弹框 --> <!-- 删除弹框 -->
<view class="agreement-mask" v-if="deleteShow" @click="closePopup('delete')" catchtouchmove="true"> <view class="agreement-mask" v-if="deleteShow" @click="closePopup('delete')" catchtouchmove="true">
@ -145,11 +147,11 @@
deviceReName deviceReName
} from '@/api/common/index.js' } from '@/api/common/index.js'
import BleHelper from '@/utils/BleHelper.js'; import BleHelper from '@/utils/BleHelper.js';
var ble=null; import MescrollUni from 'mescroll-uni/mescroll-uni.vue'
var ble = null;
export default { export default {
onPullDownRefresh() { components: {
// 执行下拉刷新时的操作,比如重新获取数据 MescrollUni
this.onIntall();
}, },
data() { data() {
return { return {
@ -201,9 +203,23 @@
action: 'share' action: 'share'
} }
], ],
mescroll: null,
downOption: {
auto: false
},
upOption: {
auto: false,
noMoreSize: 1,
offset: 80,
empty: {
tip: '暂无相关数据'
}
},
page: 1, // 当前页码 page: 1, // 当前页码
size: 10, // 每页条数 size: 10, // 每页条数
total: 0, // 总数据量 total: 0, // 总数据量
loadedCount: 0,
loading: false, loading: false,
finished: false, finished: false,
deviceId: '', deviceId: '',
@ -212,13 +228,57 @@
} }
}, },
methods: { 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() { allMore() {
this.showshare = !this.showshare; this.showshare = !this.showshare;
}, },
// 所有分享,所有类型 // 所有分享,所有类型
handleshareClick(item) { handleshareClick(item) {
this.showshare = false; // 关闭弹窗 this.showshare = false;
switch (item.action) { switch (item.action) {
case 'type': case 'type':
uni.navigateTo({ uni.navigateTo({
@ -236,17 +296,16 @@
closePopup(type) { closePopup(type) {
if (type === 'delete') { if (type === 'delete') {
this.deleteShow = false; this.deleteShow = false;
uni.showTabBar(); // 显示TabBar uni.showTabBar();
} else if (type === 'rename') { } else if (type === 'rename') {
this.RenameModel = false; this.RenameModel = false;
uni.showTabBar(); // 显示TabBar uni.showTabBar();
} }
}, },
// tab导航切换栏 // tab导航切换栏
getTab() { getTab() {
deviceTypeList({}).then((res) => { deviceTypeList({}).then((res) => {
if (res.code == 200) { if (res.code == 200) {
//console.log("deviceTypeList=" + JSON.stringify(res.data));
this.tabs = [{ this.tabs = [{
id: '', id: '',
name: '全部设备', name: '全部设备',
@ -266,46 +325,77 @@
switchTab(tab, index) { switchTab(tab, index) {
this.deviceList = []; this.deviceList = [];
this.activeTab = index; this.activeTab = index;
this.activeTabInfo = tab this.activeTabInfo = tab;
this.page = 1; // 重置页码 // 完全重置分页状态
this.finished = false; // 重 this.page = 1;
// 明确传递参数空字符串改为null或undefined this.finished = false;
this.loadedCount = 0;
const deviceType = tab.id === '' ? undefined : tab.id; const deviceType = tab.id === '' ? undefined : tab.id;
this.getData(deviceType); this.getData(deviceType);
},
// 获取设备列表
getData(deviceType = '') {
if (this.loading || this.finished) return;
this.loading = true;
let data = {
pageNum: this.page,
pageSize: this.size,
deviceType: deviceType // 使用传入的设备类型
}
deviceInfo(data).then((res) => {
if (res.code == 200) {
const newDevices = res.rows.map(device => ({
...device,
showConfirm: false
}));
// 如果是第一页或切换分类,替换数据 if (this.mescroll) {
this.deviceList = this.page === 1 ? newDevices : [...this.deviceList, ...newDevices]; this.mescroll.resetUpScroll();
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() { getData(deviceType = '') {
this.getData(); 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() { scan() {
@ -317,19 +407,12 @@
}, },
// 添加设备,扫一扫,蓝牙 // 添加设备,扫一扫,蓝牙
handleMenuClick(item) { handleMenuClick(item) {
this.showTooltip = false; // 关闭弹窗 this.showTooltip = false;
switch (item.action) { switch (item.action) {
case 'scan': case 'scan':
// 扫一扫
uni.scanCode({ uni.scanCode({
success: (res) => { success: (res) => {
console.log('条码内容:', res);
// 清除之前的数据
this.previousScanResult = null;
// 处理新的扫码结果
const cleanedResult = res.result.trim(); const cleanedResult = res.result.trim();
console.log('扫码结果:', cleanedResult);
// 跳转并传递扫描结果
uni.navigateTo({ uni.navigateTo({
url: `/pages/common/qrcode/qrcode?deviceId=${encodeURIComponent(cleanedResult)}` url: `/pages/common/qrcode/qrcode?deviceId=${encodeURIComponent(cleanedResult)}`
}); });
@ -352,10 +435,6 @@
}, },
// 右滑点击事件处理 // 右滑点击事件处理
handleSwipeClick(e, item, index) { handleSwipeClick(e, item, index) {
const {
content
} = e
console.log(item, 'eeeee');
switch (e.content.text) { switch (e.content.text) {
case '删除': case '删除':
this.handleDeleteDevice(item, index) this.handleDeleteDevice(item, index)
@ -374,9 +453,6 @@
// 确认删除 // 确认删除
handleBtn() { handleBtn() {
uni.showTabBar() uni.showTabBar()
let data = {
id: this.deviceId.id
}
deviceUnbind(this.deviceId.id).then((res) => { deviceUnbind(this.deviceId.id).then((res) => {
if (res.code == 200) { if (res.code == 200) {
uni.showToast({ uni.showToast({
@ -389,10 +465,11 @@
this.getTab() this.getTab()
}, 500); }, 500);
this.deleteShow = false this.deleteShow = false
// 关闭所有滑动项 if (this.$refs.swipeAction) {
this.$refs.swipeAction.closeAll(); this.$refs.swipeAction.closeAll();
}
ble && ble.DropDevice(data.id); ble && ble.DropDevice(this.deviceId.id);
} else { } else {
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
@ -410,11 +487,10 @@
}, },
handleBtnName() { handleBtnName() {
uni.showTabBar() uni.showTabBar()
let data = { deviceReName({
id: this.deviceId.id, id: this.deviceId.id,
deviceName: this.deviceName deviceName: this.deviceName
} }).then((res) => {
deviceReName(data).then((res) => {
if (res.code == 200) { if (res.code == 200) {
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
@ -426,8 +502,9 @@
}, 500); }, 500);
this.RenameModel = false this.RenameModel = false
this.deviceName = '' this.deviceName = ''
// 关闭所有滑动项 if (this.$refs.swipeAction) {
this.$refs.swipeAction.closeAll(); this.$refs.swipeAction.closeAll();
}
} else { } else {
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
@ -440,13 +517,8 @@
// 报警 // 报警
callpolice() { callpolice() {
const currentTab = this.tabs[this.activeTab]; const currentTab = this.tabs[this.activeTab];
const deviceType = currentTab.id || '';
console.log(`跳转到发送信息页面\n当前设备类型: ${deviceType}\n设备类型名称: ${currentTab.typeName}`);
uni.navigateTo({ uni.navigateTo({
url: '/pages/6170/callPolice/index', url: '/pages/6170/callPolice/index',
events: {
ack: function(data) {}
},
success: (res) => { success: (res) => {
res.eventChannel.emit('devicePolice', { res.eventChannel.emit('devicePolice', {
data: currentTab data: currentTab
@ -457,16 +529,10 @@
// 发生短信 // 发生短信
handleSend() { handleSend() {
const currentTab = this.tabs[this.activeTab]; const currentTab = this.tabs[this.activeTab];
const deviceType = currentTab.id || '';
console.log(`跳转到发送信息页面\n当前设备类型: ${deviceType}\n设备类型名称: ${currentTab.typeName}`);
uni.navigateTo({ uni.navigateTo({
url: '/pages/common/send/index', url: '/pages/common/send/index',
events: {
ack: function(data) {}
},
success: (res) => { success: (res) => {
res.eventChannel.emit('deviceSend', { res.eventChannel.emit('deviceSend', {
//data: deviceType,
data: currentTab data: currentTab
}); });
} }
@ -476,11 +542,7 @@
location() { location() {
uni.navigateTo({ uni.navigateTo({
url: '/pages/common/map/index', url: '/pages/common/map/index',
events: {
ack: function(data) {}
},
success: (res) => { success: (res) => {
// 页面跳转成功后的回调函数
res.eventChannel.emit('Map', { res.eventChannel.emit('Map', {
data: this.deviceList, data: this.deviceList,
}); });
@ -490,50 +552,42 @@
// 列表跳转 // 列表跳转
handleFile(item) { handleFile(item) {
let url = item.detailPageUrl; let url = item.detailPageUrl;
// console.log("url=",url);
// if(!url){
//url="/pages/670/HBY670"
// }
uni.navigateTo({ uni.navigateTo({
url: url, url: url,
events: {
ack: function(data) {}
},
success: (res) => { success: (res) => {
// 页面跳转成功后的回调函数
res.eventChannel.emit('detailData', { res.eventChannel.emit('detailData', {
data: item, data: item,
deviceType: this.tabs[this.activeTab].id || '', deviceType: this.tabs[this.activeTab].id || '',
apiType: 'listA' //标识,根据这个参数,区分普通详情,分享跳转详情,查不一样的权限信息 apiType: 'listA'
}); });
},fail(ex) { },
console.log("ex=",ex); fail(ex) {
console.log("ex=", ex);
} }
}) })
}, },
onIntall() { onIntall() {
this.page = 1; this.page = 1;
this.finished = false; this.finished = false;
this.loadedCount = 0; // 重置计数
const deviceType = this.activeTabInfo?.id === '' ? undefined : this.activeTabInfo?.id; const deviceType = this.activeTabInfo?.id === '' ? undefined : this.activeTabInfo?.id;
this.getData(deviceType); // 重新加载第一页数据 this.getData(deviceType);
setTimeout(() => { setTimeout(() => {
// 停止下拉刷新动画
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
}, 800); }, 800);
}, },
updateDeviceStatus(data) { updateDeviceStatus(data) {
this.deviceList = this.deviceList this.deviceList = this.deviceList
.map(item => { .map(item => {
if (!item) return null; // 如果 item 是 undefined/null返回 null if (!item) return null;
if (item.communicationMode == 0) { if (item.communicationMode == 0) {
let messageData; let messageData;
try { try {
messageData = data.message; messageData = data.message;
} catch (e) { } catch (e) {
return item; // 解析失败则返回原 item return item;
} }
const [deviceId, onlineStatus, battery] = messageData.state || []; const [deviceId, onlineStatus, battery] = messageData.state || [];
console.log('我收到消息了没', item.battery);
return { return {
...item, ...item,
battery: battery ?? item.battery, battery: battery ?? item.battery,
@ -549,20 +603,16 @@
onLoad() { onLoad() {
this.getTab() this.getTab()
this.onIntall() this.onIntall()
// 绑定页面做了监听,新增成功,刷新页面
uni.$on('refreshDeviceList', () => { uni.$on('refreshDeviceList', () => {
this.getTab() // 刷新数据 this.getTab()
this.onIntall() this.onIntall()
}); });
// 监听设备状态更新事件
uni.$on('deviceStatusUpdate', (data) => { uni.$on('deviceStatusUpdate', (data) => {
console.log('列表收到消息了么');
this.onIntall() this.onIntall()
}); });
ble=BleHelper.getBleTool(); ble = BleHelper.getBleTool();
}, },
beforeDestroy() { beforeDestroy() {
// 组件销毁前移除监听器
uni.$off('refreshDeviceList'); uni.$off('refreshDeviceList');
}, },
onUnload() { onUnload() {
@ -573,7 +623,7 @@
</script> </script>
<style> <style>
/* 页面整体样式 */ /* 保持原有样式不变 */
.device-page { .device-page {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -586,7 +636,6 @@
width: 100%; width: 100%;
color: rgb(255, 255, 255); color: rgb(255, 255, 255);
white-space: nowrap; white-space: nowrap;
/* 禁止换行 */
overflow: hidden; overflow: hidden;
position: relative; position: relative;
@ -597,17 +646,12 @@
cursor: pointer; cursor: pointer;
margin-bottom: 40rpx; margin-bottom: 40rpx;
padding-right: 80rpx; padding-right: 80rpx;
/* 预留更多按钮空间 */
} }
.tab-item { .tab-item {
font-size: 28rpx; font-size: 28rpx;
/* min-width: 120rpx; */
padding: 0 30rpx; padding: 0 30rpx;
/* 左右内边距 */
text-align: center; text-align: center;
/* 文字居中 */
/* 设置最小宽度 */
} }
.active { .active {
@ -627,16 +671,12 @@
.tab-bar-wrap { .tab-bar-wrap {
display: flex; display: flex;
/* 横向排列 */
align-items: baseline; align-items: baseline;
/* 垂直居中 */
position: relative; position: relative;
/* 可选(若需要绝对定位 fallback */
} }
.tab-more { .tab-more {
margin-left: 10rpx; margin-left: 10rpx;
/* 与Tab的间距 */
display: flex; display: flex;
align-items: center; align-items: center;
background: linear-gradient(-88.60deg, rgba(18, 18, 18, 1), rgba(18, 18, 18, 0) 100%); background: linear-gradient(-88.60deg, rgba(18, 18, 18, 1), rgba(18, 18, 18, 0) 100%);
@ -733,22 +773,6 @@
color: rgb(187, 230, 0); color: rgb(187, 230, 0);
} }
.device-id {
font-size: 26rpx;
color: #999;
margin-bottom: 20rpx;
display: block;
}
.device-info {
display: flex;
justify-content: space-evenly;
font-size: 28rpx;
color: rgba(255, 255, 255, 0.87);
position: relative;
padding: 0rpx 0rpx 30rpx 30rpx;
}
.deviceIMG { .deviceIMG {
width: 100rpx; width: 100rpx;
height: 100rpx; height: 100rpx;
@ -796,16 +820,6 @@
left: -20rpx left: -20rpx
} }
.line {
width: 2rpx;
height: 24rpx;
background: linear-gradient(90deg,
rgba(0, 0, 0, 0) 0%,
rgb(255, 255, 255) 50%,
rgba(255, 255, 255, 0) 100%);
margin-top: 12rpx;
}
.loading-status { .loading-status {
text-align: center; text-align: center;
color: rgba(255, 255, 255, 0.6); color: rgba(255, 255, 255, 0.6);
@ -844,18 +858,6 @@
text-align: center; text-align: center;
} }
/* 弹窗主体 */
.agreement-popup {
width: 100%;
height: 50%;
background-color: rgb(42, 42, 42);
border-radius: 60rpx 60rpx 0rpx 0rpx;
padding: 40rpx;
box-sizing: border-box;
position: absolute;
bottom: 0rpx;
}
.agreement-popupC { .agreement-popupC {
width: 60%; width: 60%;
background-color: rgb(42, 42, 42); background-color: rgb(42, 42, 42);
@ -907,7 +909,6 @@
} }
/* 同意按钮 */
.agreeBtn { .agreeBtn {
background: #FFC84E; background: #FFC84E;
color: #232323; color: #232323;
@ -933,7 +934,6 @@
position: fixed; position: fixed;
right: 18rpx; right: 18rpx;
top: 140rpx; top: 140rpx;
/* 根据导航栏高度调整 */
z-index: 9999; z-index: 9999;
} }
@ -941,7 +941,6 @@
position: fixed; position: fixed;
right: 18rpx; right: 18rpx;
top: 230rpx; top: 230rpx;
/* 根据导航栏高度调整 */
z-index: 9999; z-index: 9999;
} }