This commit is contained in:
3321822538@qq.com 2024-05-21 15:07:11 +08:00
parent 23197daaca
commit ceb9558de4
13 changed files with 126 additions and 84 deletions

View File

@ -63,7 +63,9 @@ BLEDevice.prototype.getBluetoothAdapterState = function () {
if (res.discovering) { if (res.discovering) {
this.onBluetoothDeviceFound() this.onBluetoothDeviceFound()
} else if (res.available) { } else if (res.available) {
setTimeout(()=>{
this.startBluetoothDevicesDiscovery(state.servicesId, state.key); this.startBluetoothDevicesDiscovery(state.servicesId, state.key);
},500)
} }
} }
}) })

View File

@ -971,6 +971,7 @@ function writeCutomsData(deviceId, serviceId, characteristicId, data) {
console.log("送数据成功") console.log("送数据成功")
}, },
fail: function (res) { //console.log(257); fail: function (res) { //console.log(257);
console.log("送数据成功",res)
} }
}); });
} }
@ -1108,12 +1109,12 @@ function init() {
uni.closeBluetoothAdapter({ uni.closeBluetoothAdapter({
complete: function (res) complete: function (res)
{ {
console.log("这里蓝牙数据") // console.log("这里蓝牙数据")
uni.openBluetoothAdapter({ uni.openBluetoothAdapter({
success: function (res) { success: function (res) {
uni.getBluetoothAdapterState({ uni.getBluetoothAdapterState({
success: function (res) { success: function (res) {
console.log("这里蓝牙数据222") // console.log("这里蓝牙数据222")
{ {
let devicesList = []; let devicesList = [];
let countsTimes = 0; let countsTimes = 0;
@ -1140,13 +1141,20 @@ function init() {
} }
} else if (devices.devices) { } else if (devices.devices) {
// console.log(devices.devices[0]) // console.log(devices.devices[0])
if (devices.devices[0].name != '开发板' // if (devices.devices[0].name != '开发板'
&& devices.devices[0].name != 'SMART_R2XS' // && devices.devices[0].name != 'SMART_R2XS'
) { // && devices.devices[0].name != 'SMART_R2XS'
// console.log("跳过") // )
if (devices.devices[0].name.indexOf("CTKG") != -1){
// console.log("跳过",devices.devices[0].name)
// isnotexist = false;
isnotexist = true;
}
else
{
isnotexist = false; isnotexist = false;
} }
isnotexist = true; // isnotexist = true;
if (devices.devices[0].advertisData) { if (devices.devices[0].advertisData) {
devices.devices[0].advertisData = buf2hex(devices.devices[0].advertisData); devices.devices[0].advertisData = buf2hex(devices.devices[0].advertisData);
@ -1188,9 +1196,11 @@ function init() {
}; };
mDeviceEvent.notifyDeviceMsgEvent(obj); mDeviceEvent.notifyDeviceMsgEvent(obj);
}); });
uni.startBluetoothDevicesDiscovery({ uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true, allowDuplicatesKey: true,
success: function (res) { success: function (res) {
console.log(res,'true');
let obj = { let obj = {
'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START, 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
'result': true, 'result': true,
@ -1201,6 +1211,7 @@ function init() {
devicesList.length = 0; devicesList.length = 0;
}, },
fail: function (res) { fail: function (res) {
console.log(res,'false');
let obj = { let obj = {
'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START, 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
'result': false, 'result': false,
@ -1209,6 +1220,7 @@ function init() {
mDeviceEvent.notifyDeviceMsgEvent(obj); mDeviceEvent.notifyDeviceMsgEvent(obj);
} }
}); });
} }
// uni.stopBluetoothDevicesDiscovery({ // uni.stopBluetoothDevicesDiscovery({
// success: function (res) // success: function (res)
@ -1266,10 +1278,12 @@ function init() {
} }
}); });
mDeviceEvent.listenConnectBle(true, function (options) { mDeviceEvent.listenConnectBle(true, function (options) {
console.log("我要连接?", options.isStart); console.log("我要连接?", options.isStart,options);
if (options.isStart) uni.createBLEConnection({ if (options.isStart){
uni.createBLEConnection({
deviceId: options.deviceId, deviceId: options.deviceId,
success: function (res) { success: (res) =>{
// console.log(res,'100');
self.data.deviceId = options.deviceId; self.data.deviceId = options.deviceId;
mDeviceEvent.notifyDeviceMsgEvent({ mDeviceEvent.notifyDeviceMsgEvent({
'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECTED, 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECTED,
@ -1277,10 +1291,11 @@ function init() {
'data': { 'data': {
deviceId: options.deviceId, deviceId: options.deviceId,
name: options.name name: options.name
} },
}); });
}, },
fail: function (res) { fail: (res) =>{
// console.log(res,'1112');
self.data.deviceId = null; self.data.deviceId = null;
mDeviceEvent.notifyDeviceMsgEvent({ mDeviceEvent.notifyDeviceMsgEvent({
'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECTED, 'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECTED,
@ -1289,6 +1304,7 @@ function init() {
}); });
} }
}); });
}
else uni.closeBLEConnection({ else uni.closeBLEConnection({
deviceId: options.deviceId, deviceId: options.deviceId,
success: function (res) { success: function (res) {
@ -1351,19 +1367,18 @@ function init() {
mac_id = options.deviceId; mac_id = options.deviceId;
setTimeout(() => { setTimeout(() => {
console.log(deviceId,'deviceIddeviceId');
uni.getBLEDeviceServices({ uni.getBLEDeviceServices({
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接 // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
deviceId: deviceId, deviceId: deviceId,
success: function(res) { success: function(res) {
console.log("服务发现456", res) console.log("服务发现456", res)
var services = res.services; var services = res.services;
if (services.length > 0) { if (services.length > 0) {
for (var i = 0; i < services.length; i++) { for (var i = 0; i < services.length; i++) {
if (services[i].uuid === self.data.service_uuid) { if (services[i].uuid === self.data.service_uuid) {
var serviceId = services[i].uuid; var serviceId = services[i].uuid;
uni.getBLEDeviceCharacteristics({ uni.getBLEDeviceCharacteristics({
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接 // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
deviceId: deviceId, deviceId: deviceId,
serviceId: serviceId, serviceId: serviceId,

View File

@ -43,14 +43,19 @@ let OnFireEvent = {
* 初始化 * 初始化
* @param type 参考 XMQTT_SYSTEM * @param type 参考 XMQTT_SYSTEM
*/ */
let once = 0
function initXBlufi(type) { function initXBlufi(type) {
switch (type) { switch (type) {
case XMQTT_SYSTEM.Alis: case XMQTT_SYSTEM.Alis:
break; break;
case XMQTT_SYSTEM.WeChat: case XMQTT_SYSTEM.WeChat:
if(once==0)
{
once = 1;
$wxBlufiImpl.init(); $wxBlufiImpl.init();
}
break; break;
} }
} }
@ -103,7 +108,7 @@ function listenStartDiscoverBle(isSetListener, funtion) {
function notifyConnectBle(options) { function notifyConnectBle(options) {
console.log('notifyConnectBle 蓝牙准备连接的deviceId --------------'); // console.log('notifyConnectBle 蓝牙准备连接的deviceId --------------');
mOnFire.fire(OnFireEvent.EVENT_CONNECT_DISCONNECT, options); mOnFire.fire(OnFireEvent.EVENT_CONNECT_DISCONNECT, options);
} }
/** /**
@ -170,7 +175,7 @@ function listenSendRouterSsidAndPassword(isSetListener, funtion) {
function notifySendCustomData(options) { function notifySendCustomData(options) {
console.log("设备数据",options) // console.log("设备数据",options)
mOnFire.fire(OnFireEvent.EVENT_NOFITY_SEND_CUSTON_DATA, options); mOnFire.fire(OnFireEvent.EVENT_NOFITY_SEND_CUSTON_DATA, options);
} }
/** /**

View File

@ -68,10 +68,12 @@
timer: null, timer: null,
expireTimeStr: '', expireTimeStr: '',
zfobj: {}, zfobj: {},
orderno: '' orderno: '',
id:''
} }
}, },
onLoad() { onLoad(option) {
this.id = option.id
this.startTimer() this.startTimer()
this.gettaoc() this.gettaoc()
}, },
@ -85,7 +87,7 @@
}, 30000); // 30 }, 30000); // 30
}, },
gettaoc() { gettaoc() {
this.$u.get(`/app/device/${this.deviceid}/withSuitList`).then((res) => { this.$u.get(`/app/device/${this.id}/withSuitList`).then((res) => {
if (res.code == 200) { if (res.code == 200) {
this.deviceobj = res.data; this.deviceobj = res.data;
this.indexactive = res.data.suitList[0].suitId; this.indexactive = res.data.suitList[0].suitId;
@ -110,7 +112,7 @@
}); });
} else { } else {
let data = { let data = {
deviceNo: 'DS-000002', deviceNo: this.id,
suitId: this.zfobj.suitId, suitId: this.zfobj.suitId,
money: this.zfobj.price, money: this.zfobj.price,
suitTime: this.zfobj.value suitTime: this.zfobj.value

View File

@ -347,7 +347,7 @@
// "CTPOW" // "CTPOW"
let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 5) === let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 5) ===
"CTPOW"); "CTKG");
// this.devicesList // this.devicesList
this.devicesList = filteredDevices; this.devicesList = filteredDevices;

View File

@ -140,7 +140,7 @@
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS: case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
if (options.result) { if (options.result) {
let devicesarr = options.data let devicesarr = options.data
console.log(devicesarr,100100);
devicesarr.forEach(device => { devicesarr.forEach(device => {
const mac = device.name.substring(6); const mac = device.name.substring(6);
@ -235,27 +235,27 @@
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));
console.log(uniqueDevicesList,'uniqueDevicesListuniqueDevicesList');
// this.devicesList // this.devicesList
this.devicesList = uniqueDevicesList; this.devicesList = uniqueDevicesList;
let list = [] let list = []
filteredDevices.forEach(device => { // this.devicesList.forEach(device => {
// MAC MAC 6 // MAC MAC 6
let macFromName = device.name.substring(device.name.length - 12); // let macFromName = device.name.substring(device.name.length - 12);
// console.log(macFromName); // console.log(macFromName);
// this.mac // this.mac
this.$u.get(`/app/device/${macFromName}/isBind`).then((res) => { // this.$u.get(`/app/device/${macFromName}/isBind`).then((res) => {
if (res.data == false) { // if (res.data == false) {
list.push(device) // list.push(device)
} else { // } else {
} // }
}) // })
}); // });
setTimeout(() => { // setTimeout(() => {
this.devicesList = list // this.devicesList = list
}, 200) // }, 200)
console.log('蓝牙停止搜索ok'); console.log('蓝牙停止搜索ok');
} else { } else {

View File

@ -303,7 +303,7 @@
let uniqueDevicesList = Array.from(new Set(this.devicesList)); let uniqueDevicesList = Array.from(new Set(this.devicesList));
// "CTPOW" // "CTPOW"
let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 5) === "CTPOW"); let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 5) === "CTKG");
// this.devicesList // this.devicesList
this.devicesList = filteredDevices; this.devicesList = filteredDevices;

View File

@ -292,7 +292,7 @@
let uniqueDevicesList = Array.from(new Set(this.devicesList)); let uniqueDevicesList = Array.from(new Set(this.devicesList));
// "CTPOW" // "CTPOW"
let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 5) === "CTPOW"); let filteredDevices = uniqueDevicesList.filter(device => device.name.substring(0, 5) === "CTKG");
// this.devicesList // this.devicesList
this.devicesList = filteredDevices; this.devicesList = filteredDevices;

View File

@ -121,10 +121,14 @@
scanType: ['qrCode'], scanType: ['qrCode'],
success: res => { success: res => {
console.log('扫描结果:', res); console.log('扫描结果:', res);
this.qrResult = res.result; this.$u.get(`/app/device/${res.result}/bySn`).then((res) =>{
if(res.code == 200){
this.qrResult = res.data.mac
uni.navigateTo({ uni.navigateTo({
url:'/page_fenbao/device/lianjie?mac=' + this.qrResult + '&storeId=' + this.storeId url:'/page_fenbao/device/lianjie?mac=' + this.qrResult + '&storeId=' + this.storeId
}) })
}
})
}, },
fail: err => { fail: err => {
console.error('扫描失败:', err); console.error('扫描失败:', err);

View File

@ -81,23 +81,28 @@
}, },
methods: { methods: {
scanQRCode() { scanQRCode() {
uni.scanCode({
onlyFromCamera: true,
scanType: ['qrCode'],
success: res => {
console.log('扫描结果:', res);
let id = res.result
this.$u.get(`/app/device/${res.result}/withSuitList`).then((res) =>{
if(res.code == 200){
uni.navigateTo({ uni.navigateTo({
url: '/page_components/fuwu/index' url: '/page_components/fuwu/index?id=' + id
}) })
// uni.scanCode({ }
// onlyFromCamera: true, })
// scanType: ['qrCode'], },
// success: res => { fail: err => {
// console.log('', res); console.error('扫描失败:', err);
// }, uni.showToast({
// fail: err => { title: '扫描失败',
// console.error('', err); icon: 'none'
// uni.showToast({ });
// title: '', }
// icon: 'none' });
// });
// }
// });
}, },
btnchak(id){ btnchak(id){

View File

@ -130,7 +130,7 @@
</view> </view>
<view class="cont" style="width: 60rpx;" @click="topage(5)"> <view class="cont" style="width: 60rpx;" @click="topage(5)">
<view class="top"> <view class="top">
<image src="https://api.ccttiot.com/smartmeter/img/static/ubxoYVnbIK1rk0cfoL3j" mode=""> <image src="https://api.ccttiot.com/smartmeter/img/static/uWaQjL7vph474LWTyGfs" mode="">
</image> </image>
</view> </view>
<view class="bot">配网</view> <view class="bot">配网</view>

View File

@ -102,8 +102,7 @@
</view> </view>
</view> </view>
<!-- <view <!-- <view style="margin-left:200rpx; color: #ccc;font-size: 36rpx;margin-top: 200rpx;width: 750rpx;">
style="margin-left:200rpx; color: #ccc;font-size: 36rpx;margin-top: 200rpx;width: 750rpx;">
该店铺暂无设备...</view> --> 该店铺暂无设备...</view> -->
</view> </view>
@ -181,7 +180,6 @@
showtip: false, showtip: false,
orderinfo: [], orderinfo: [],
storeId: '', storeId: '',
pagenum: 1, pagenum: 1,
wateringList: [], wateringList: [],
pagesize: 10, pagesize: 10,
@ -468,6 +466,11 @@
success: res => { success: res => {
console.log('扫描结果:', res); console.log('扫描结果:', res);
this.qrResult = res.result; this.qrResult = res.result;
// this.$u.get(`/app/device/${this.qrResult}/withSuitList`).then((res) =>{
// if(res.code == 200){
// console.log(res);
// }
// })
}, },
fail: err => { fail: err => {
console.error('扫描失败:', err); console.error('扫描失败:', err);

View File

@ -87,23 +87,29 @@
scanQRCode() { scanQRCode() {
uni.navigateTo({
url: '/page_components/fuwu/index' uni.scanCode({
}) onlyFromCamera: true,
// uni.scanCode({ scanType: ['qrCode'],
// onlyFromCamera: true, success: res => {
// scanType: ['qrCode'],
// success: res => {
// console.log('', res); // console.log('', res);
// }, let id = res.result
// fail: err => { this.$u.get(`/app/device/${res.result}/withSuitList`).then((res) =>{
// console.error('', err); if(res.code == 200){
// uni.showToast({ uni.navigateTo({
// title: '', url: '/page_components/fuwu/index?id=' + id
// icon: 'none' })
// }); }
// } })
// }); },
fail: err => {
console.error('扫描失败:', err);
uni.showToast({
title: '扫描失败',
icon: 'none'
});
}
});
}, },
getad(){ getad(){