This commit is contained in:
fengerli
2026-01-30 13:29:15 +08:00
53 changed files with 8008 additions and 2154 deletions

View File

@ -24,7 +24,7 @@
<view class="Sendmessage" @click="handleSend">发送信息</view>
</view>
<!-- <scroll-view class="device-list" scroll-y @scrolltolower="onScrollToLower" :lower-threshold="100" style="height:80vh;"> -->
<mescroll-uni class="device-list" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption"
<mescroll-uni class="device-list" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption"
:down="downOption" :fixed="false" :style="{ height: mescrollHeight + 'px' }">
<view v-if="deviceList.length>0">
<uni-swipe-action ref="swipeAction">
@ -146,16 +146,17 @@
} from '@/api/common/index.js'
import bleTool from '@/utils/BleHelper.js';
import MescrollUni from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-uni.vue'
import BleReceive from '@/utils/BleReceive';
var pagePath = 'pages/common/index';
var ble = null;
var timeout = null;
var recei=null;
export default {
components: {
MescrollUni
},
data() {
return {
mescroll: null,
@ -224,7 +225,7 @@
textNoMore: '没有更多数据了'
},
mescrollHeight: 0,
size: 10, // 每页条数
total: 0, // 总数据量
@ -251,31 +252,31 @@
},
// 下拉刷新
downCallback() {
console.log("下拉加载")
if(this.mescroll){
if (this.mescroll) {
this.mescroll.resetUpScroll(false);
this.mescroll.scrollTo(0,0);
}
this.mescroll.scrollTo(0, 0);
}
this.getData();
},
// 上拉加载
upCallback() {
console.log("上拉加载")
this.getData();
},
bleStateBreak(){
bleStateBreak() {
console.error("蓝牙适配器不可用");
this.updateBleStatu();
},
bleStateRecovery() {
console.log("蓝牙适配器恢复可用,重连断开的设备");
ble.linkAllDevices();
},
bleBreak(res) {
console.error("蓝牙断开连接", res);
@ -292,28 +293,39 @@
},
updateBleStatu(deviceId) { //更新列表的蓝牙连接状态
updateBleStatu() { //更新列表的蓝牙连接状态,电池 电量
if (ble) {
for (var i = 0; i < this.deviceList.length; i++) {
let bleStatu = false;
let f = null;
if (ble.data && ble.data.LinkedList) {
ble.data.LinkedList.find(v => {
if (deviceId && v.deviceId != deviceId) {
return false;
}
f = ble.data.LinkedList.find(v => {
if (v.macAddress && v.device && v.device.id) {
if (v.device.id == this.deviceList[i].id && v.Linked) {
bleStatu = true;
return true;
}
return v.device.id == this.deviceList[i].id;
}
return false;
});
}
this.$set(this.deviceList[i], 'bleStatu', bleStatu);
if (f) {
this.$set(this.deviceList[i], 'bleStatu', f.Linked);
if (f.formData) {
let battary = 0;
if ('battary' in f.formData) {
battary = f.formData.battary;
} else if ('sta_PowerPercent' in f.formData) {
battary = f.formData.sta_PowerPercent;
} else if ('sta_battery' in f.formData) {
battary = f.formData.sta_battery;
}
this.$set(this.deviceList[i], 'battery', battary);
}
}
@ -329,22 +341,37 @@
// 所有分享,所有类型
handleshareClick(item) {
this.showshare = false; // 关闭弹窗
var that = this;
switch (item.action) {
case 'type':
uni.navigateTo({
url: '/pages/common/allType/index'
url: '/pages/common/allType/index',
events: {
index(data) {
if (data && data.id) {
that.tabs.find((v, i) => {
if (v.id === data.id) {
that.switchTab(v, i);
return true;
}
return false;
})
}
}
}
});
break;
case 'share':
uni.navigateTo({
url: "/pages/common/allShare/index"
url: "/pages/common/allShare/index",
})
break;
}
},
// 点击弹框外的区域关闭
closePopup(type) {
if (type === 'delete') {
this.deleteShow = false;
uni.showTabBar(); // 显示TabBar
@ -378,7 +405,7 @@
this.deviceList = [];
this.activeTab = index;
this.activeTabInfo = tab
this.downCallback();
@ -393,10 +420,10 @@
pageNum: this.mescroll.num,
pageSize: this.size,
deviceType: this.activeTabInfo ? this.activeTabInfo.id : '', // 使用传入的设备类型
isAsc:'desc',
orderByColumn:'bindingTime'
isAsc: 'desc',
orderByColumn: 'bindingTime'
}
if(!data.pageNum){
if (!data.pageNum) {
this.mescroll.endSuccess(0, false);
resolve();
return;
@ -410,33 +437,34 @@
}));
// 如果是第一页或切换分类,替换数据
if(data.pageNum === 1){
this.deviceList =newDevices
}else{
if (data.pageNum === 1) {
this.deviceList = newDevices
} else {
//防止后端返回的数据包含已有数据
for (var i = 0; i < newDevices.length; i++) {
let device=newDevices[i];
let f=this.deviceList.find(v=>{
return v.id===device.id;
let device = newDevices[i];
let f = this.deviceList.find(v => {
return v.id === device.id;
});
if(!f){
if (!f) {
this.deviceList.push(device);
}
}
}
}
this.updateBleStatu();
this.total = res.total;
// 判断是否加载完成
let hasNext = true;
if (res.rows.length < this.size || this.deviceList.length >= this.total) {
if (res.rows.length < this.size || this.deviceList.length >= this
.total) {
hasNext = false;
} else {
hasNext = true;
}
this.mescroll.endSuccess(res.rows.length, hasNext);
}else{
} else {
this.mescroll.endSuccess(0, false);
}
}).finally(() => {
@ -448,16 +476,16 @@
//防止下拉刷新的同时会调用一次上拉加载的问题
timeout = setTimeout(task, 50);
},
// 添加扫一扫图标
scan() {
this.showTooltip = !this.showTooltip;
},
closePopMenu(){
setTimeout(()=>{
closePopMenu() {
setTimeout(() => {
this.showTooltip = false;
this.showshare = false;
},100);
}, 100);
},
closePopupTooltip() {
this.showTooltip = !this.showTooltip
@ -470,6 +498,9 @@
case 'scan':
// 扫一扫
uni.scanCode({
autoDecodeCharset:true,
autoZoom:true,
barCodeInput:true,
success: (res) => {
console.log('条码内容:', res);
// 清除之前的数据
@ -484,14 +515,19 @@
if ('imei' in json) {
url =
`/pages/common/qrcode/qrcode?deviceId=${encodeURIComponent(json.imei)}`;
} else if ('blue' in json) {
if (!json.blue.includes(':')) {
json.blue = json.blue.replace(
/(.{2})/g, '$1:')
.slice(0, -1)
} else if ('blue' in json || 'ble' in json) {
if(json.ble){
json.blue=json.ble;
}
url =
`/pages/common/addBLE/LinkBle?mac=${encodeURIComponent(json.blue)}`;
if(json.blue){
if (!json.blue.includes(':')) {
json.blue = json.blue.replace(
/(.{2})/g, '$1:')
.slice(0, -1)
}
}
url =`/pages/common/addBLE/LinkBle?mac=${encodeURIComponent(json.blue)}`;
}
} catch (ex) {
@ -519,7 +555,9 @@
},
// 右滑点击事件处理
handleSwipeClick(e, item, index) {
const {content} = e
const {
content
} = e
setTimeout(() => {
console.log(item, 'eeeee');
switch (e.content.text) {
@ -554,10 +592,10 @@
icon: 'none',
duration: 1000
});
this.deviceList.find((v,i)=>{
if(v.id==data.id){
this.deviceList.splice(i,1);
this.deviceList.find((v, i) => {
if (v.id == data.id) {
this.deviceList.splice(i, 1);
return true;
}
return false;
@ -595,10 +633,10 @@
icon: 'none',
duration: 1000
});
this.deviceList.find((v,i)=>{
if(v.id===data.id){
this.$set(this.deviceList[i],'deviceName',data.deviceName);
this.deviceList.find((v, i) => {
if (v.id === data.id) {
this.$set(this.deviceList[i], 'deviceName', data.deviceName);
return true;
}
return false;
@ -671,7 +709,7 @@
let url = item.detailPageUrl;
// console.log("url=",url);
// if(!url){
//url="/pages/670/HBY670"
// url="/pages/6075/BJQ6075"
// }
uni.navigateTo({
url: url,
@ -691,7 +729,7 @@
}
})
},
updateDeviceStatus(data) {
this.deviceList = this.deviceList
.map(item => {
@ -717,7 +755,16 @@
.filter(Boolean);
},
},
onShow() {
if (ble) {
//因为vue视图只能后退不能隐藏后再显示
//所以回到首页后将其他所有页面的订阅都删除
ble.removeAllCallbackByRetain(pagePath);
}
},
onLoad() {
console.error("首页加载");
this.getTab()
this.downCallback();
@ -732,7 +779,7 @@
this.downCallback();
});
ble = bleTool.getBleTool();
recei = BleReceive.getBleReceive();
//蓝牙连接成功的回调
ble.addRecoveryCallback((res) => {
console.log("蓝牙连接成功的回调");
@ -750,12 +797,19 @@
console.log("蓝牙适配器恢复可用的回调");
this.bleStateRecovery();
}, pagePath);
//蓝牙适配器不可用的回调
ble.addStateBreakCallback(res=>{
ble.addStateBreakCallback(res => {
console.error("蓝牙适配器不可用的回调");
this.bleStateBreak();
},pagePath);
}, pagePath);
//接收到消息的回调
ble.addReceiveCallback((receive, device, path, recArr) => {
console.error("首页收到消息了");
recei.ReceiveData(receive, device, path, recArr);
this.updateBleStatu();
}, pagePath);
this.getSystemInfoSyncH();
},
@ -765,8 +819,9 @@
uni.$off('refreshDeviceList');
},
onUnload() {
console.log("onUnload...");
uni.$off('deviceStatusUpdate');
ble && ble.removeAllCallback();
ble && ble.removeAllCallback(pagePath);
}
}
@ -1139,13 +1194,15 @@
background-color: rgba(35, 35, 35, 0.87);
color: rgba(255, 255, 255, 1);
}
.mask{
.mask {
position: fixed;
width: 100%;
height: 100%;
z-index: 9998;
background-color: #00000000;
}
/* 提示框样式 */
.tooltip-box {
position: fixed;