|
|
@@ -232,87 +232,95 @@ export default {
|
|
|
});
|
|
|
break;
|
|
|
case 1:
|
|
|
- /* uni.openBluetoothAdapter({
|
|
|
- mode: "peripheral",
|
|
|
- }); */
|
|
|
- uni.openBluetoothAdapter({
|
|
|
- success: (result) => {
|
|
|
- if (result.errno == 0) {
|
|
|
- uni.navigateTo({
|
|
|
- url:
|
|
|
- "/Bluetooth/index/index?services=" +
|
|
|
- JSON.stringify([
|
|
|
- that.detail.prodnum,
|
|
|
- that.detail.w_productid,
|
|
|
- ]),
|
|
|
- });
|
|
|
- this.$Http.setBluetooth = function (Bluetooth) {
|
|
|
- this.mode = mode;
|
|
|
- let curPages = getCurrentPages();
|
|
|
- if (
|
|
|
- curPages[curPages.length - 1].__route__ ==
|
|
|
- "Bluetooth/index/index"
|
|
|
- )
|
|
|
- uni.navigateBack();
|
|
|
- this.$Http.setDetailMode = function (mode1) {
|
|
|
- this.mode = mode1;
|
|
|
- delete this.$Http.setDetailMode;
|
|
|
- uni.closeBluetoothAdapter();
|
|
|
- }.bind(this);
|
|
|
- this.$Http.Bluetooth = Bluetooth;
|
|
|
- delete this.$Http.setBluetooth;
|
|
|
- }.bind(this);
|
|
|
- } else {
|
|
|
- uni.showModal({
|
|
|
- title: result.errno,
|
|
|
- content: result.Msg,
|
|
|
- showCancel: false,
|
|
|
- confirmText: "确定",
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- fail: (fail) => {
|
|
|
- console.log("蓝牙初始化fail:", fail);
|
|
|
- if (fail.errno == "103") {
|
|
|
- uni.showModal({
|
|
|
- title: "提示",
|
|
|
- content: "未获取使用蓝牙功能授权,请授权后使用",
|
|
|
- showCancel: false,
|
|
|
- confirmText: "前去授权",
|
|
|
- success() {
|
|
|
- uni.openSetting({
|
|
|
- success({ authSetting }) {
|
|
|
- if (authSetting["scope.bluetooth"])
|
|
|
- that.changeMode(mode);
|
|
|
+ try {
|
|
|
+ if (that.$Http.Bluetooth.device.deviceId)
|
|
|
+ uni.closeBLEConnection({
|
|
|
+ deviceId: that.$Http.Bluetooth.device.deviceId,
|
|
|
+ });
|
|
|
+ } catch (error) {}
|
|
|
+ uni.closeBluetoothAdapter({
|
|
|
+ complete: (complete) => {
|
|
|
+ console.log("closeBluetoothAdapterComplete", complete);
|
|
|
+ uni.openBluetoothAdapter({
|
|
|
+ success: (result) => {
|
|
|
+ if (result.errno == 0) {
|
|
|
+ uni.navigateTo({
|
|
|
+ url:
|
|
|
+ "/Bluetooth/index/index?services=" +
|
|
|
+ JSON.stringify([
|
|
|
+ that.detail.prodnum,
|
|
|
+ that.detail.w_productid,
|
|
|
+ ]),
|
|
|
+ });
|
|
|
+ this.$Http.setBluetooth = function (Bluetooth) {
|
|
|
+ this.mode = mode;
|
|
|
+ let curPages = getCurrentPages();
|
|
|
+ if (
|
|
|
+ curPages[curPages.length - 1].__route__ ==
|
|
|
+ "Bluetooth/index/index"
|
|
|
+ )
|
|
|
+ uni.navigateBack();
|
|
|
+ this.$Http.setDetailMode = function (mode1) {
|
|
|
+ this.mode = mode1;
|
|
|
+ delete this.$Http.setDetailMode;
|
|
|
+ uni.closeBluetoothAdapter();
|
|
|
+ }.bind(this);
|
|
|
+ this.$Http.Bluetooth = Bluetooth;
|
|
|
+ delete this.$Http.setBluetooth;
|
|
|
+ }.bind(this);
|
|
|
+ } else {
|
|
|
+ uni.showModal({
|
|
|
+ title: result.errno,
|
|
|
+ content: result.Msg,
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: "确定",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: (fail) => {
|
|
|
+ console.log("蓝牙初始化fail:", fail);
|
|
|
+ if (fail.errno == "103") {
|
|
|
+ uni.showModal({
|
|
|
+ title: "提示",
|
|
|
+ content: "未获取使用蓝牙功能授权,请授权后使用",
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: "前去授权",
|
|
|
+ success() {
|
|
|
+ uni.openSetting({
|
|
|
+ success({ authSetting }) {
|
|
|
+ if (authSetting["scope.bluetooth"])
|
|
|
+ that.changeMode(mode);
|
|
|
+ },
|
|
|
+ });
|
|
|
},
|
|
|
});
|
|
|
- },
|
|
|
- });
|
|
|
- } else {
|
|
|
- const codes = {
|
|
|
- 0: "ok",
|
|
|
- "-1": "已连接 ",
|
|
|
- 10000: "未初始化蓝牙适配器",
|
|
|
- 10001: "当前蓝牙适配器不可用",
|
|
|
- 10002: "没有找到指定设备",
|
|
|
- 10003: "连接失败",
|
|
|
- 10004: "没有找到指定服务",
|
|
|
- 10005: "没有找到指定特征值",
|
|
|
- 10006: "当前连接已断开",
|
|
|
- 10007: "当前特征值不支持此操作",
|
|
|
- 10008: "其余所有系统上报的异常",
|
|
|
- 10009: "系统版本低于 4.3 不支持 BLE",
|
|
|
- 10010: "已连接",
|
|
|
- 10011: "配对设备需要配对码",
|
|
|
- 10012: "连接超时",
|
|
|
- 10013: "连接 deviceId 为空或者是格式不正确",
|
|
|
- };
|
|
|
- uni.showModal({
|
|
|
- content: codes[fail.errCode] || fail.errMsg,
|
|
|
- showCancel: false,
|
|
|
- confirmText: "确认",
|
|
|
- });
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ const codes = {
|
|
|
+ 0: "ok",
|
|
|
+ "-1": "已连接 ",
|
|
|
+ 10000: "未初始化蓝牙适配器",
|
|
|
+ 10001: "当前蓝牙适配器不可用",
|
|
|
+ 10002: "没有找到指定设备",
|
|
|
+ 10003: "连接失败",
|
|
|
+ 10004: "没有找到指定服务",
|
|
|
+ 10005: "没有找到指定特征值",
|
|
|
+ 10006: "当前连接已断开",
|
|
|
+ 10007: "当前特征值不支持此操作",
|
|
|
+ 10008: "其余所有系统上报的异常",
|
|
|
+ 10009: "系统版本低于 4.3 不支持 BLE",
|
|
|
+ 10010: "已连接",
|
|
|
+ 10011: "配对设备需要配对码",
|
|
|
+ 10012: "连接超时",
|
|
|
+ 10013: "连接 deviceId 为空或者是格式不正确",
|
|
|
+ };
|
|
|
+ uni.showModal({
|
|
|
+ content: codes[fail.errCode] || fail.errMsg,
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: "确认",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
},
|
|
|
});
|
|
|
break;
|