const load = () => { | const load = () => { | ||||
deviceList.value = []; | deviceList.value = []; | ||||
console.log("****************蓝牙getsetting******************"); | console.log("****************蓝牙getsetting******************"); | ||||
//断开蓝牙 | |||||
bluetoothUtil.disconnectDevice(); | |||||
uni.getSetting({ | uni.getSetting({ | ||||
success(res) { | success(res) { | ||||
console.log("****************成功******************"); | console.log("****************成功******************"); | ||||
const openBluetooth = () => { | const openBluetooth = () => { | ||||
let foundDevices = []; //扫描到的蓝牙列表 | let foundDevices = []; //扫描到的蓝牙列表 | ||||
uni.closeBluetoothAdapter(); //先关闭蓝牙 | uni.closeBluetoothAdapter(); //先关闭蓝牙 | ||||
//打开蓝牙 | //打开蓝牙 | ||||
uni.openBluetoothAdapter({ | uni.openBluetoothAdapter({ | ||||
success: function (res) { | success: function (res) { | ||||
// delete device._name | // delete device._name | ||||
console.log(item); | console.log(item); | ||||
datas.setData("deviceId", device.deviceId); | |||||
tools.showLoadingAlert("蓝牙连接中"); | tools.showLoadingAlert("蓝牙连接中"); | ||||
console.info("连接的是" + prefixName); | console.info("连接的是" + prefixName); | ||||
switch (prefixName) { | switch (prefixName) { | ||||
* 监听蓝牙状态 | * 监听蓝牙状态 | ||||
*/ | */ | ||||
const listenStatus = (res) => { | const listenStatus = (res) => { | ||||
console.log("时时监听蓝牙状态func2"); | |||||
console.log("时时监听蓝牙状态func234"); | |||||
console.log(res); | console.log(res); | ||||
if (res.code == 0) { | if (res.code == 0) { | ||||
datas.setData("bluLinkStatus", true); | datas.setData("bluLinkStatus", true); | ||||
datas.setData("connectPrefixName", connectPrefixName.value); | datas.setData("connectPrefixName", connectPrefixName.value); | ||||
} else { | } else { | ||||
console.log('输出内容','=====================================') | |||||
datas.setData("bluLinkStatus", false); | datas.setData("bluLinkStatus", false); | ||||
datas.setData("connectPrefixName", ""); | datas.setData("connectPrefixName", ""); | ||||
tools.showToastAlert("蓝牙已断开"); | tools.showToastAlert("蓝牙已断开"); | ||||
} | } | ||||
}; | }; | ||||
//断开蓝牙 | //断开蓝牙 | ||||
bluetoothUtil.disconnectDevice(); | bluetoothUtil.disconnectDevice(); | ||||
//提示对话框 | //提示对话框 | ||||
tools.showModalAlert(msg); | tools.showModalAlert(msg); |
let prefixName = item.prefixName; | let prefixName = item.prefixName; | ||||
connectPrefixName.value = item.prefixName; | connectPrefixName.value = item.prefixName; | ||||
console.log(item); | console.log(item); | ||||
// datas.setData("connectPrefixName", connectPrefixName.value); | |||||
// //断开蓝牙 | |||||
// bluetoothUtil.disconnectDevice(); | |||||
tools.showLoadingAlert("蓝牙连接中"); | tools.showLoadingAlert("蓝牙连接中"); | ||||
console.info("连接的是" + prefixName); | console.info("连接的是" + prefixName); | ||||
switch (prefixName) { | switch (prefixName) { | ||||
datas.setData("bluLinkStatus", true); | datas.setData("bluLinkStatus", true); | ||||
datas.setData("connectPrefixName", connectPrefixName.value); | datas.setData("connectPrefixName", connectPrefixName.value); | ||||
//routeType 1.激活(订单来) 2.圈存 (/pages/recharge/recharge来)3.信息重写 4.信息读取 5从哪里来回哪里去监听bluetoothLink | |||||
if (routeType.value == "1") { | |||||
uni.navigateTo({ | |||||
url: "/subpackage/after-sale/activation/activate", | |||||
}); | |||||
} else if (routeType.value == "2") { | |||||
uni.navigateTo({ | |||||
url: `/pages/recharge/recharge?connectSuccess=1&&cardId=${state.cardId}&&fee=${state.fee}`, | |||||
}); | |||||
} else if (routeType.value == "3") { | |||||
} else if (routeType.value == "4") { | |||||
uni.navigateTo({ | |||||
url: "/subpackage/after-sale/deviceInfo/deviceInfo", | |||||
}); | |||||
} | |||||
else if (routeType.value == "5") { | |||||
uni.$emit('bluetoothLink', { status: true }) | |||||
uni.navigateBack({ | |||||
delta: 1 | |||||
}) | |||||
} else { | |||||
return; | |||||
} | |||||
oks(); | |||||
} else { | } else { | ||||
alertF(res.msg); | alertF(res.msg); | ||||
} | } | ||||
}; | }; | ||||
function oks(){ | |||||
//routeType 1.激活(订单来) 2.圈存 (/pages/recharge/recharge来)3.信息重写 4.信息读取 5从哪里来回哪里去监听bluetoothLink | |||||
if (routeType.value == "1") { | |||||
uni.navigateTo({ | |||||
url: "/subpackage/after-sale/activation/activate", | |||||
}); | |||||
} else if (routeType.value == "2") { | |||||
uni.navigateTo({ | |||||
url: `/pages/recharge/recharge?connectSuccess=1&&cardId=${state.cardId}&&fee=${state.fee}`, | |||||
}); | |||||
} else if (routeType.value == "3") { | |||||
} else if (routeType.value == "4") { | |||||
uni.navigateTo({ | |||||
url: "/subpackage/after-sale/deviceInfo/deviceInfo", | |||||
}); | |||||
} else if (routeType.value == "5") { | |||||
uni.$emit('bluetoothLink', { status: true }) | |||||
uni.navigateBack({ | |||||
delta: 1 | |||||
}) | |||||
} else { | |||||
return; | |||||
} | |||||
} | |||||
/** | /** | ||||
* 前装设备 | * 前装设备 | ||||
if (res.code == 0) { | if (res.code == 0) { | ||||
datas.setData("bluLinkStatus", true); | datas.setData("bluLinkStatus", true); | ||||
datas.setData("connectPrefixName", connectPrefixName.value); | datas.setData("connectPrefixName", connectPrefixName.value); | ||||
// oks(); | |||||
} else { | } else { | ||||
//断开蓝牙 | |||||
// bluetoothUtil.disconnectDevice(); | |||||
datas.setData("bluLinkStatus", false); | datas.setData("bluLinkStatus", false); | ||||
datas.setData("connectPrefixName", ""); | datas.setData("connectPrefixName", ""); | ||||
tools.showToastAlert("蓝牙已断开"); | tools.showToastAlert("蓝牙已断开"); | ||||
// #ifdef MP-ALIPAY | |||||
my.closeBluetoothAdapter({ | |||||
success(res) { | |||||
// 关闭蓝牙适配器成功 | |||||
}, | |||||
fail(err) { | |||||
// 处理关闭蓝牙适配器失败的情况 | |||||
} | |||||
}) | |||||
// #endif | |||||
} | } | ||||
}; | }; | ||||
const jlApi = require("../../static/etc/JLAPI/JLObuSDK.js"); //聚力SDK | const jlApi = require("../../static/etc/JLAPI/JLObuSDK.js"); //聚力SDK | ||||
const wjApi = require("../etc/WJAPI/wjBleAPI"); | const wjApi = require("../etc/WJAPI/wjBleAPI"); | ||||
let tdApi = require("../etc/TDAPI/TDRObuSDK.js"); | let tdApi = require("../etc/TDAPI/TDRObuSDK.js"); | ||||
const datas = require("../../static/etcUtil/datas.js"); | |||||
// #ifdef MP-ALIPAY | // #ifdef MP-ALIPAY | ||||
// 这部分代码将仅在支付宝小程序平台下执行 | // 这部分代码将仅在支付宝小程序平台下执行 | ||||
// jlApi = require("../../static/etc/JLObuSDK/JLObuSDK.js"); | // jlApi = require("../../static/etc/JLObuSDK/JLObuSDK.js"); | ||||
* 断开蓝牙 | * 断开蓝牙 | ||||
*/ | */ | ||||
function disconnectDevice() { | function disconnectDevice() { | ||||
// #ifdef MP-ALIPAY | |||||
my.cancelBluetoothPair({ | |||||
deviceId: device.deviceId, | |||||
success: (res) => { | |||||
console.log('解除蓝牙配对123', res); | |||||
my.disconnectBLEDevice({ | |||||
deviceId: device.deviceId, | |||||
success: (res) => { | |||||
console.log(res, "连接情况"); | |||||
my.alert({ content: "断开成功" }); | |||||
}, | |||||
fail: (error) => { | |||||
console.log(error, "断开情况"); | |||||
my.alert({ content: JSON.stringify(error) }); | |||||
} | |||||
}); | |||||
}, | |||||
fail: (err) => { | |||||
console.log('解除蓝牙配对456', err); | |||||
}, | |||||
}); | |||||
// #endif | |||||
var connectPrefixName = datas.getData("connectPrefixName"); | var connectPrefixName = datas.getData("connectPrefixName"); | ||||
switch (connectPrefixName) { | switch (connectPrefixName) { | ||||
case "WJ": | case "WJ": | ||||
tdApi.disConnectDevice(function(res) { | tdApi.disConnectDevice(function(res) { | ||||
datas.setData("bluLinkStatus", false); | datas.setData("bluLinkStatus", false); | ||||
datas.setData("connectPrefixName", ""); | datas.setData("connectPrefixName", ""); | ||||
// console.log(res) | |||||
console.log(res,'=============') | |||||
}); | }); | ||||
break; | break; | ||||
case "ZZ": | case "ZZ": |