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

@ -46,7 +46,7 @@
var these = null;
var eventChannel = null;
var ble = null;
var inteval=null;
export default {
data() {
return {
@ -118,7 +118,7 @@
onUnload() {
console.log("返回取消订阅");
clearInterval(inteval);
ble.removeAllCallback(pagePath);
},
onLoad(option) {
@ -226,7 +226,7 @@
}
})
let inteval = setInterval(this.initDevice, 10000);
inteval = setInterval(this.initDevice, 10000);
}
@ -291,6 +291,7 @@
}
}
});
clearInterval(inteval);
} else {
deviceInvalid();
}

View File

@ -120,6 +120,7 @@
var ble = null;
var these = null;
var eventChannel = null;
export default {
data() {
return {
@ -334,7 +335,7 @@
//搜索到新设备的回调 (Always active)
ble.addDeviceFound((arr) => {
console.log("--- 收到原始扫描数据 ---", JSON.stringify(arr));
// console.log("--- 收到原始扫描数据 ---", JSON.stringify(arr));
if (these.Status.isPageHidden) {
return;
}
@ -343,7 +344,7 @@
}
arr = arr.devices;
console.log(`本次扫描批次发现 ${arr.length} 个设备`);
// console.log(`本次扫描批次发现 ${arr.length} 个设备`);
for (var i = 0; i < arr.length; i++) {
let device = arr[i];
@ -351,9 +352,9 @@
let f = these.EquipMents.find((v, index) => {
if (v.deviceId == device.deviceId) {
console.log(
`更新设备信号: ${device.name || device.deviceId}, RSSI: ${device.RSSI}`
);
// console.log(
// `更新设备信号: ${device.name || device.deviceId}, RSSI: ${device.RSSI}`
// );
these.$set(these.EquipMents[index], 'RSSI', device.RSSI);
return true;
}
@ -361,7 +362,7 @@
});
if (!f) {
console.log("+++ 发现新设备,准备添加到列表:", JSON.stringify(device));
// console.log("+++ 发现新设备,准备添加到列表:", JSON.stringify(device));
if (these.device && these.device.bluetoothName && device.name) {
if (these.device.bluetoothName === device.name || (device.name && device.name
@ -417,27 +418,32 @@
//收到设备的消息回调
ble.addReceiveCallback((receivData, f, path, arr) => {
console.log("000000");
console.log("000000",receivData);
if (these.Status.isPageHidden) {
return;
}
console.log("1111111");
if (f.macAddress && these.device) {
console.log("222222");
clearInterval(this.Status.intval);
this.Status.intval = null;
this.Status.time = null;
showLoading(these, {
text: '正在验证设备'
});
setTimeout(() => {
these.DeviceVerdict(f.deviceId);
}, 0);
if(receivData.bytes[0]===0xFC && receivData.hexs.length>=7){
console.log("22222222");
}
if(receivData.str.indexOf('mac address:')>-1 || receivData.str.indexOf('sta_address')>-1
|| (receivData.bytes[0]===0xFC && receivData.bytes.length>=7))
{
console.log("1111111");
if (f.macAddress && these.device) {
console.log("222222");
clearInterval(this.Status.intval);
this.Status.intval = null;
this.Status.time = null;
showLoading(these, {
text: '正在验证设备'
});
setTimeout(() => {
these.DeviceVerdict(f.deviceId);
}, 0);
}
}
}, pagePath);
}
}
@ -452,7 +458,7 @@
}
startValidDevice();
these.refreshBleList();
});
},
@ -502,6 +508,8 @@
});
},
async refreshBleList() {
const systemInfo = uni.getSystemInfoSync();
if (systemInfo.uniPlatform == 'web') {
return;
@ -520,37 +528,42 @@
return;
}
}
ble.StopSearch().finally(() => {
let disconnectPromises = [];
if (ble.data && ble.data.LinkedList) {
ble.data.LinkedList.forEach(device => {
console.log(`Requesting disconnect for ${device.deviceId}`);
disconnectPromises.push(ble.disconnectDevice(device.deviceId));
});
}
Promise.allSettled(disconnectPromises).finally(() => {
these.EquipMents = [];
these.PairEquip = [];
ble.StartSearch().then(result => {
console.log("Fresh scan started successfully.");
}).catch(err => {
console.error("Failed to start fresh scan:", err);
if (err.code === 10001) {
these.showOpenSetting();
} else {
uni.showModal({
title: '提示',
content: '开始搜索失败:' + err.msg
});
}
ble.StopSearch().finally(() => {
let disconnectPromises = [];
if (ble.data && ble.data.LinkedList) {
ble.data.LinkedList.forEach(device => {
console.log(`Requesting disconnect for ${device.deviceId}`);
disconnectPromises.push(ble.disconnectDevice(device.deviceId));
});
}
Promise.allSettled(disconnectPromises).finally(() => {
these.EquipMents = [];
these.PairEquip = [];
ble.StartSearch().then(result => {
console.log("Fresh scan started successfully.");
}).catch(err => {
console.error("Failed to start fresh scan:", err);
if (err.code === 10001) {
these.showOpenSetting();
} else {
uni.showModal({
title: '提示',
content: '开始搜索失败:' + err.msg
});
}
});
});
});
});
},
isItemLink: function(item, index) {
let src = '/static/images/BLEAdd/noLink.png';
@ -599,8 +612,6 @@
if (index > -1) {
this.PairEquip.splice(index, 1);
}
}
console.log("f=", f);
@ -708,8 +719,8 @@
});
return;
}
console.log("验证设备")
these.DeviceVerdict(item.deviceId);
// console.log("验证设备")
// these.DeviceVerdict(item.deviceId);
}
let execLink = () => {
return new Promise((resolve, reject) => {

View File

@ -2,9 +2,9 @@
<view class="alltype">
<!-- 车辆列表 -->
<view class="vehicle-list" v-if="vehicles.length>0">
<view v-for="(item, index) in vehicles" :key="index">
<view class="typeContent" v-for="(item, index) in vehicles" :key="index">
<view class="vehicle-item" @click="alltypeInfo(item)">
<image src="/static/images/common/bip.6.png" mode="" class="IMG"></image>
<image :src="item.img" mode="aspectFit" class="IMG"></image>
</view>
<view class="plate-number">{{ item.typeName }}</view>
</view>
@ -20,30 +20,130 @@
<script>
import {
deviceTypeList,
typeAll
} from '@/api/common/index.js'
export default {
data() {
return {
vehicles: [],
typeImgs: [{
"Name": "HBY018A",
"sigName": "018A",
"url": "/static/images/common/018A.png"
},
{
"Name": "HBY102",
"sigName": "102",
"url": "/static/images/common/HBY102.png"
},
{
"Name": "BJQ6075",
"sigName": "6075",
"url": "/static/images/common/BJQ6075.png"
},
{
"Name": "HBY100",
"sigName": "100",
"url": "/static/images/common/HBY100J.png"
},
{
"Name": "BJQ4877",
"sigName": "4877",
"url": "/static/images/common/BJQ4877.png"
},
{
"Name": "BJQ7307",
"sigName": "7307",
"url": "/static/images/common/7307.png"
},
{
"Name": "BJQ7305",
"sigName": "7305",
"url": "/static/images/common/7305.png"
},
{
"Name": "HBY650",
"sigName": "650",
"url": "/static/images/common/HBY650.png"
},
{
"Name": "BJQ6155",
"sigName": "6155",
"url": "/static/images/common/HBY6155.png"
},
{
"Name": "HBY670",
"sigName": "670",
"url": "/static/images/common/HBY670.png"
},
{
"Name": "HBY210",
"sigName": "210",
"url": "/static/images/common/210.png"
},
{
"Name": "BJQ6170",
"sigName": "6170",
"url": "/static/images/common/bip.6.png"
}
]
}
},
methods: {
getTab() {
deviceTypeList({}).then((res) => {
let p1 = deviceTypeList({});
let p2 = typeAll();
Promise.allSettled([p1, p2]).then(result => {
let res = result[0].status === 'fulfilled' ? result[0].value : {};
let res1 = result[1].status === 'fulfilled' ? result[1].value : {};
if (res.code == 200) {
this.vehicles = res.data
if (res1.code != 200) {
for (let i = 0; i < res.data.length; i++) {
let f = this.typeImgs.find(v => {
if (res.data[i].typeName.toLowerCase() === v.Name.toLowerCase()) {
return true;
}
return false;
});
if (f) {
res.data[i].img = f.url;
}else{
res.data[i].img = "/static/images/common/bip.6.png";
}
}
} else {
let all = res1.data;
for (let i = 0; i < res.data.length; i++) {
let f = all.find(v => {
if (res.data[i].id === v.deviceTypeId) {
return true;
}
return false;
});
if (f && f.devicePic) {
res.data[i].img = f.devicePic;
}else{
res.data[i].img = "/static/images/common/bip.6.png";
}
}
}
this.vehicles = res.data;
}
})
});
},
alltypeInfo(item) {
uni.switchTab({
url: '/pages/common/index/index',
success: (res) => {
res.eventChannel.emit('index', {
data: item
});
let eventChannel = this.getOpenerEventChannel();
eventChannel.emit('index', item);
}
})
});
}
},
@ -65,8 +165,10 @@
.vehicle-list {
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-content: center;
justify-content: space-around;
align-items: center;
text-align: center;
}
@ -77,14 +179,17 @@
}
.vehicle-item {
padding: 24rpx 0;
background: rgba(26, 26, 26, 1);
border-radius: 16rpx;
width: 156rpx;
height: 156rpx;
margin-right: 16rpx;
margin-bottom: 16rpx;
line-height: 156rpx;
border-radius: 9px;
width: 140rpx;
height: 140rpx;
margin-bottom: 15rpx;
display: grid;
align-content: center;
justify-content: center;
}
@ -96,6 +201,9 @@
.plate-number {
color: rgba(255, 255, 255, 0.87);
font-size: 27rpx;
font-family: 'PingFang SC';
text-align: center;
}
.noDATA {
@ -103,4 +211,8 @@
color: rgba(255, 255, 255, 0.87);
transform: translate(-0%, 100%);
}
.typeContent {
padding-bottom: 15rpx;
}
</style>

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;

View File

@ -65,7 +65,7 @@
<script>
import {
deviceShareId,
deviceShareCode,
deviceShareAdd
} from '@/api/6170/share.js'