11
This commit is contained in:
parent
d8b37a2a3f
commit
8c39f40a65
|
@ -9,11 +9,14 @@
|
||||||
<view class="dblist" v-for="(item, index) in devicesLists" :key="index">
|
<view class="dblist" v-for="(item, index) in devicesLists" :key="index">
|
||||||
<view class="cen">
|
<view class="cen">
|
||||||
<view class="name">
|
<view class="name">
|
||||||
<view class="">
|
<view class="">
|
||||||
状态:<text v-if="item.flags == true" style="color: red;">已录入</text> <text v-else style="color:seagreen;">未录入</text>
|
状态:<text v-if="item.flags == true" style="color: red;">已录入</text> <text v-else
|
||||||
</view>
|
style="color:seagreen;">未录入</text>
|
||||||
|
</view>
|
||||||
<view class="" style="display: flex;">
|
<view class="" style="display: flex;">
|
||||||
SN码: <input style="width: 200rpx;background-color: #ccc;padding: 5rpx;box-sizing: border-box;text-align: center;" v-model="item.sn" placeholder="输入SN"/>
|
SN码: <input
|
||||||
|
style="width: 200rpx;background-color: #ccc;padding: 5rpx;box-sizing: border-box;text-align: center;"
|
||||||
|
v-model="item.sn" placeholder="输入SN" />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="mac">
|
<view class="mac">
|
||||||
|
@ -28,8 +31,8 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="rt">
|
<view class="rt">
|
||||||
<!-- <text style="margin-bottom: 10rpx;" :id="item.deviceId" @tap="createBLEConnections(item)">扫码</text> -->
|
<text style="margin-bottom: 10rpx;" :id="item.deviceId" @click="createBLEConnections(item)">开关</text>
|
||||||
<text @click="scanQRCode(item)" style="margin-bottom: 10rpx;">扫码</text>
|
<text @click="scanQRCode(item)" style="margin-bottom: 10rpx;">扫码</text>
|
||||||
<text :id="item.deviceId" @click="createBLEConnection(item)">录入</text>
|
<text :id="item.deviceId" @click="createBLEConnection(item)">录入</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -96,9 +99,12 @@
|
||||||
arrname: '',
|
arrname: '',
|
||||||
valuexh: '',
|
valuexh: '',
|
||||||
deviceId: '',
|
deviceId: '',
|
||||||
arrs: [],
|
arrs: '',
|
||||||
sn:'输入SN',
|
sn: '输入SN',
|
||||||
snname:''
|
snname: '',
|
||||||
|
qrResult:'',
|
||||||
|
name:'',
|
||||||
|
ver_data:null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(option) {
|
onLoad(option) {
|
||||||
|
@ -135,7 +141,7 @@
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 扫码sn
|
// 扫码sn
|
||||||
scanQRCode(item){
|
scanQRCode(item) {
|
||||||
this.snname = item.name
|
this.snname = item.name
|
||||||
uni.scanCode({
|
uni.scanCode({
|
||||||
onlyFromCamera: true,
|
onlyFromCamera: true,
|
||||||
|
@ -149,7 +155,7 @@
|
||||||
let sceneValue = res.result
|
let sceneValue = res.result
|
||||||
let decodedValue = decodeURIComponent(sceneValue)
|
let decodedValue = decodeURIComponent(sceneValue)
|
||||||
let id = getQueryParam(decodedValue, 's')
|
let id = getQueryParam(decodedValue, 's')
|
||||||
this.storeId = id
|
this.storeId = id
|
||||||
this.devicesLists.forEach(item => {
|
this.devicesLists.forEach(item => {
|
||||||
if (item.name == this.snname) {
|
if (item.name == this.snname) {
|
||||||
item.sn = id
|
item.sn = id
|
||||||
|
@ -164,8 +170,8 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getxingh() {
|
getxingh() {
|
||||||
this.$u.get(`/app/model/all`).then(res => {
|
this.$u.get(`/app/model/all`).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
|
@ -202,23 +208,44 @@
|
||||||
},
|
},
|
||||||
funListenDeviceMsgEvent: function(options) {
|
funListenDeviceMsgEvent: function(options) {
|
||||||
switch (options.type) {
|
switch (options.type) {
|
||||||
|
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_MY_DATA:
|
||||||
|
let loadPercent = options.data;
|
||||||
|
let loadText = '文件读取中'
|
||||||
|
// console.log("文件读取中", options.data)
|
||||||
|
break;
|
||||||
|
case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
|
||||||
|
this.ver_data = this.parseCustomData(options.data)
|
||||||
|
console.log("1收到设备发来的自定义数据结果:", this.ver_data)
|
||||||
|
break;
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
|
||||||
if (options.result) {
|
if (options.result) {
|
||||||
this.devicesList = options.data
|
this.devicesList = options.data
|
||||||
|
this.devicesList.forEach(device => {
|
||||||
|
const mac = device.name.substring(5)
|
||||||
|
if (device.name == this.qrResult) {
|
||||||
|
this.deviceId = device.deviceId
|
||||||
|
this.name = device.name
|
||||||
|
this.mac = device.name.slice(5, 17)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
|
case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
|
||||||
console.log("连接回调:" + JSON.stringify(options));
|
// console.log("连接回调:" + JSON.stringify(options))
|
||||||
if (options.result) {
|
if (options.result) {
|
||||||
{
|
setTimeout(()=>{
|
||||||
|
this.bluetoothflag = false
|
||||||
|
},3000)
|
||||||
|
uni.hideLoading(); {
|
||||||
console.log("连接回调options.data.deviceId:" + options.data.deviceId,
|
console.log("连接回调options.data.deviceId:" + options.data.deviceId,
|
||||||
"连接回调options.data.name:" + options.data.name);
|
"连接回调options.data.name:" + options.data.name)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.shibaiflag = true
|
||||||
|
this.bluetoothflag = false
|
||||||
|
uni.hideLoading()
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
|
||||||
if (!options.result) {
|
if (!options.result) {
|
||||||
this.mengcflag = false
|
this.mengcflag = false
|
||||||
|
@ -231,11 +258,8 @@
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.searching = true
|
this.searching = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
|
||||||
if (options.result) {
|
if (options.result) {
|
||||||
let uniqueDevicesList = Array.from(new Set(this.devicesList));
|
let uniqueDevicesList = Array.from(new Set(this.devicesList));
|
||||||
|
@ -248,20 +272,16 @@
|
||||||
return newDevice;
|
return newDevice;
|
||||||
})
|
})
|
||||||
let devicesarr = options.data
|
let devicesarr = options.data
|
||||||
|
|
||||||
this.devicesList.forEach(device => {
|
this.devicesList.forEach(device => {
|
||||||
if (device.name.substring(0, 4) == "CTKG" || device.name.substring(0, 4) ==
|
if (device.name.substring(0, 4) == "CTKG" || device.name.substring(0, 4) == "CTPO") {
|
||||||
"CTPO") {
|
|
||||||
this.devicesList.push(device);
|
this.devicesList.push(device);
|
||||||
let uniqueDevicesList = Array.from(new Set(this.devicesList));
|
let uniqueDevicesList = Array.from(new Set(this.devicesList));
|
||||||
this.devicesLists = uniqueDevicesList.filter(device => {
|
this.devicesLists = uniqueDevicesList.filter(device => {
|
||||||
const deviceId = device.name.substring(5);
|
const deviceId = device.name.substring(5);
|
||||||
// return !this.lurulist.includes(deviceId);
|
|
||||||
return deviceId
|
return deviceId
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// console.log('蓝牙停止搜索ok')
|
// console.log('蓝牙停止搜索ok')
|
||||||
console.log(this.devicesLists, '蓝牙停止');
|
console.log(this.devicesLists, '蓝牙停止');
|
||||||
this.mengcflag = false
|
this.mengcflag = false
|
||||||
|
@ -269,10 +289,11 @@
|
||||||
if (this.devicesLists.length == 0) {
|
if (this.devicesLists.length == 0) {
|
||||||
this.titleflag = true
|
this.titleflag = true
|
||||||
} else {
|
} else {
|
||||||
|
let arr = []
|
||||||
this.devicesLists.forEach(item => {
|
this.devicesLists.forEach(item => {
|
||||||
this.arrs.push(item.name.slice(5))
|
arr.push(item.name.slice(5))
|
||||||
})
|
})
|
||||||
this.arrs = this.arrs.join(',')
|
this.arrs = arr.join(',')
|
||||||
this.$u.get(`/app/device/getExistMac/${this.arrs}`).then(res => {
|
this.$u.get(`/app/device/getExistMac/${this.arrs}`).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
const existingDevices = new Set(res.data); // 将 res.data 转换为 Set,以提高查找效率
|
const existingDevices = new Set(res.data); // 将 res.data 转换为 Set,以提高查找效率
|
||||||
|
@ -282,11 +303,12 @@
|
||||||
return {
|
return {
|
||||||
...device,
|
...device,
|
||||||
flags, // 直接使用 flags 变量
|
flags, // 直接使用 flags 变量
|
||||||
sn:'',
|
sn: '',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
console.log(this.devicesLists,'0202');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//蓝牙停止搜索失败
|
//蓝牙停止搜索失败
|
||||||
|
@ -295,31 +317,73 @@
|
||||||
console.log('蓝牙停止搜索失败');
|
console.log('蓝牙停止搜索失败');
|
||||||
}
|
}
|
||||||
this.searching = false
|
this.searching = false
|
||||||
break;
|
break
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 发送开关
|
||||||
|
createBLEConnections(e) {
|
||||||
|
uni.showLoading({
|
||||||
|
title: '执行中...'
|
||||||
|
})
|
||||||
|
this.arrs = ''
|
||||||
|
this.qrResult = e.name //拿到所点击的mac号
|
||||||
|
if (this.ver_data == null) { //判断是否有连接蓝牙
|
||||||
|
xBlufi.initXBlufi(1)
|
||||||
|
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent)
|
||||||
|
xBlufi.notifyStartDiscoverBle({
|
||||||
|
'isStart': true
|
||||||
|
})
|
||||||
|
// 停止蓝牙搜索
|
||||||
|
setTimeout(() => {
|
||||||
|
xBlufi.notifyStartDiscoverBle({
|
||||||
|
'isStart': false
|
||||||
|
})
|
||||||
|
xBlufi.notifyConnectBle({
|
||||||
|
isStart: true,
|
||||||
|
deviceId: this.deviceId,
|
||||||
|
name: this.name
|
||||||
|
})
|
||||||
|
xBlufi.notifyInitBleEsp32({
|
||||||
|
deviceId: this.deviceId
|
||||||
|
})
|
||||||
|
}, 1000)
|
||||||
|
}else{ //有连接则发送命令
|
||||||
|
let that = this //改变this指向
|
||||||
|
uni.getNetworkType({
|
||||||
|
success(res) {
|
||||||
|
if (res.networkType !== 'none') {
|
||||||
|
uni.getConnectedBluetoothDevices({
|
||||||
|
success(res) {
|
||||||
|
setTimeout(() => { //一秒后发送开启命令
|
||||||
|
xBlufi.notifySendCustomData({
|
||||||
|
customData: 'open'
|
||||||
|
})
|
||||||
|
setTimeout(()=>{ //发送开启命令两秒后发送关闭命令
|
||||||
|
xBlufi.notifySendCustomData({
|
||||||
|
customData: 'close'
|
||||||
|
})
|
||||||
|
setTimeout(()=>{ //发送关闭命令后一秒后断开连接
|
||||||
|
uni.hideLoading()
|
||||||
|
that.ver_data = null
|
||||||
|
xBlufi.listenDeviceMsgEvent(false, that.funListenDeviceMsgEvent);
|
||||||
|
wx.closeBLEConnection({
|
||||||
|
deviceId: that.deviceId,
|
||||||
|
})
|
||||||
|
// console.log('guanbi');
|
||||||
|
},1000)
|
||||||
|
},2000)
|
||||||
|
}, 1000)
|
||||||
|
},
|
||||||
|
fail(err) {
|
||||||
|
console.error('获取已连接蓝牙设备信息失败:', err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// createBLEConnections(e) {
|
|
||||||
// xBlufi.notifyStartDiscoverBle({
|
|
||||||
// 'isStart': false
|
|
||||||
// });
|
|
||||||
// console.log(e, '蓝牙信息101010')
|
|
||||||
// const deviceId = e.deviceId
|
|
||||||
// this.Bluetoothmac = e.localName.substring(5) //从第七位开始截取 只取后面的mac号
|
|
||||||
// this.mac = e.localName.substring(5)
|
|
||||||
// let name = e.name;
|
|
||||||
// xBlufi.notifyConnectBle({
|
|
||||||
// isStart: true,
|
|
||||||
// deviceId: e.deviceId,
|
|
||||||
// name:e.name
|
|
||||||
// })
|
|
||||||
// // 发送响铃
|
|
||||||
// xBlufi.notifySendCustomData({
|
|
||||||
// customData: "BEEP2@"
|
|
||||||
// })
|
|
||||||
|
|
||||||
// let that = this
|
|
||||||
// },
|
|
||||||
// 请求已经录入设备的mac
|
// 请求已经录入设备的mac
|
||||||
getluru() {
|
getluru() {
|
||||||
// this.$u.get(`/app/device/listAllMac`).then(res => {
|
// this.$u.get(`/app/device/listAllMac`).then(res => {
|
||||||
|
@ -342,9 +406,35 @@
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
},
|
},
|
||||||
|
parseCustomData(data) {
|
||||||
|
const dataArray = data.split('@');
|
||||||
|
const parsedData = {};
|
||||||
|
const prefixMap = {
|
||||||
|
'V': 'voltage',
|
||||||
|
'S': 'switchState',
|
||||||
|
'A': 'current',
|
||||||
|
'P': 'power',
|
||||||
|
'M': 'remainingPower',
|
||||||
|
'T': 'setMode',
|
||||||
|
'W': 'temperature'
|
||||||
|
};
|
||||||
|
// 遍历数组并解析每个字段
|
||||||
|
for (let i = 0; i < dataArray.length; i++) {
|
||||||
|
const field = dataArray[i];
|
||||||
|
for (const prefix in prefixMap) {
|
||||||
|
if (field.startsWith(prefix)) {
|
||||||
|
const value = field.substring(1);
|
||||||
|
const propertyName = prefixMap[prefix];
|
||||||
|
parsedData[propertyName] = isNaN(parseFloat(value)) ? value : parseFloat(value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parsedData;
|
||||||
|
},
|
||||||
//4、建立连接
|
//4、建立连接
|
||||||
createBLEConnection(e) {
|
createBLEConnection(e) {
|
||||||
this.deviceId = e.name
|
// this.deviceId = e.name
|
||||||
this.mengcflag = true
|
this.mengcflag = true
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '录入中...'
|
title: '录入中...'
|
||||||
|
@ -371,7 +461,7 @@
|
||||||
// }, 1000)
|
// }, 1000)
|
||||||
uni.removeStorageSync('mac');
|
uni.removeStorageSync('mac');
|
||||||
} else {
|
} else {
|
||||||
this.mengcflag = false
|
this.mengcflag = false
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: res.msg,
|
title: res.msg,
|
||||||
|
@ -548,7 +638,6 @@
|
||||||
|
|
||||||
.rt {
|
.rt {
|
||||||
margin-top: 32rpx;
|
margin-top: 32rpx;
|
||||||
padding-top: 50rpx;
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
text {
|
text {
|
||||||
|
|
|
@ -230,7 +230,6 @@
|
||||||
<view v-if="btnmsk"
|
<view v-if="btnmsk"
|
||||||
style="width: 100%;height: 100vh;position: fixed;top: 0;left: 0;background-color: #000;opacity: .1;z-index: 999;">
|
style="width: 100%;height: 100vh;position: fixed;top: 0;left: 0;background-color: #000;opacity: .1;z-index: 999;">
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -296,28 +295,6 @@
|
||||||
} else {
|
} else {
|
||||||
this.opflag = true
|
this.opflag = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// xBlufi.initXBlufi(1);
|
|
||||||
// xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
|
|
||||||
// xBlufi.notifyStartDiscoverBle({
|
|
||||||
// 'isStart': true
|
|
||||||
// })
|
|
||||||
|
|
||||||
// 停止蓝牙搜索
|
|
||||||
// setTimeout(() => {
|
|
||||||
// xBlufi.notifyStartDiscoverBle({
|
|
||||||
// 'isStart': false
|
|
||||||
// });
|
|
||||||
|
|
||||||
// xBlufi.notifyConnectBle({
|
|
||||||
// isStart: true,
|
|
||||||
// deviceId: this.deviceId,
|
|
||||||
// name: this.name
|
|
||||||
// })
|
|
||||||
// xBlufi.notifyInitBleEsp32({
|
|
||||||
// deviceId: this.deviceId
|
|
||||||
// });
|
|
||||||
// }, 2000)
|
|
||||||
|
|
||||||
},
|
},
|
||||||
// 分享到好友(会话)
|
// 分享到好友(会话)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user