流程改版

This commit is contained in:
17792275749
2025-05-29 08:45:04 +08:00
parent ba54f14735
commit f9c22f1da4
83 changed files with 1831 additions and 2603 deletions
+122 -121
View File
@@ -10,110 +10,136 @@ Page({
},
onLoad(options) {
this.initBluetooth();
this.checkBluetoothPermissionAndInit();
},
onShow() {
if (this.data.getDeviceSetting) {
this.getDeviceSettingList();
}
} else {
this.checkBluetoothPermissionAndInit();
}
},
// 初始化蓝牙
initBluetooth() {
this.setData({
initText: "正在初始化蓝牙..."
})
wx.openBluetoothAdapter({
success: () => {
this.setData({
initText: "蓝牙初始化成功"
})
this.getDeviceSettingList();
},
fail: (err) => {
this.setData({
initText: "蓝牙初始化失败"
})
if (err.errCode === 10001) {
wx.showModal({
title: "提示",
content: "请打开手机蓝牙",
});
}
},
});
},
// async refreshToken(fn, flag) {
// let bodyToken = wx.getStorageSync('bodyToken');
// let bodyTokenTime = wx.getStorageSync('bodyTokenTime');
// if (!bodyToken || bodyTokenTime * 1000 < +new Date() || flag) {
// let res = await app.globalData.ppScale.plugin.refreshToken({
// url: "https://uniquehealth.lefuenergy.com",
// data: {
// "appKey": app.globalData.ppScale.options.key,
// "appSecret": app.globalData.ppScale.options.secret
// }
// });
// if (res.data.code == 200) {
// wx.setStorageSync('bodyToken', res.data.data.token);
// wx.setStorageSync('bodyTokenTime', res.data.data.expireTime);
// fn();
// }
// } else {
// fn();
// }
// },
// getDeviceSettingList() {
// this.setData({
// initText: "获取设备配置中..."
// })
// let bodyToken = wx.getStorageSync("bodyToken");
// app.globalData.ppScale.plugin.getDeviceSettingList({
// url: "https://uniquehealth.lefuenergy.com",
// data: {
// appKey: app.globalData.ppScale.options.key
// },
// header: {
// "token": bodyToken,
// "Accept-Language": wx.getStorageSync("lang") || 'zh'
// }
// }).then((res) => {
// if (res.data.code == 200) {
// this.setData({
// initText: "设备搜索中..."
// });
// app.globalData.ppScale.plugin.Blue.setDeviceSetting(res.data.data);
// app.globalData.ppScale.device.setting = res.data.data;
// let deviceNames = res.data.data.map(item => item.deviceName);
// app.globalData.ppScale.plugin.Blue.start(deviceNames, false);
// app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res_) => {
// console.log("searchDevice ===> devicesList", res_);
// this.setData({
// getDeviceSetting: false,
// initText: "设备搜索完成"
// });
// app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
// app.globalData.ppScale.device.list = res_;
// app.globalData.ppScale.device.connection = res_[0];
// wx.navigateTo({
// url: "/pages/connectedDevice/connectedDevice"
// })
// });
// } else if (res.data.code == 401 || res.data.code == 4008) {
// this.refreshToken(() => {
// this.getDeviceSettingList();
// }, true);
// }
// });
// },
checkBluetoothPermissionAndInit() {
this.setData({
initText: "正在检查蓝牙权限..."
});
wx.getSetting({
success: (res) => {
if (res.authSetting['scope.bluetooth']) {
this.openBluetoothAdapter();
} else {
wx.authorize({
scope: 'scope.bluetooth',
success: () => {
this.openBluetoothAdapter();
},
fail: (err) => {
this.setData({
initText: "蓝牙权限被拒绝。"
});
wx.showModal({
title: '提示',
content: '您拒绝了蓝牙权限,将无法连接蓝牙秤。是否前往设置开启?',
confirmText: '去开启',
cancelText: '不开启',
success: (modalRes) => {
if (modalRes.confirm) {
wx.openSetting({
success: (settingRes) => {
console.log('openSetting success', settingRes);
},
fail: (settingErr) => {
wx.navigateBack({
delta: 1
});
}
});
} else {
wx.navigateBack({
delta: 1
});
}
}
});
}
});
}
},
fail: (err) => {
this.setData({
initText: "获取权限设置失败。"
});
wx.showToast({
title: '获取权限设置失败',
icon: 'none'
});
wx.navigateBack({
delta: 1
});
}
});
},
openBluetoothAdapter() {
this.setData({
initText: "正在初始化蓝牙..."
});
wx.openBluetoothAdapter({
success: () => {
this.setData({
initText: "蓝牙初始化成功"
});
this.getDeviceSettingList();
},
fail: (err) => {
this.setData({
initText: "蓝牙初始化失败。"
});
if (err.errCode === 10001) {
wx.showModal({
title: "提示",
content: "请确保手机蓝牙已开启。",
showCancel: false,
success: () => {
wx.navigateBack({
delta: 1
});
}
});
} else if (err.errMsg && err.errMsg.includes('permission denied')) {
wx.showModal({
title: '提示',
content: '蓝牙权限仍被拒绝,无法使用蓝牙功能。',
showCancel: false,
success: () => {
wx.navigateBack({
delta: 1
});
}
});
} else {
wx.showToast({
title: `蓝牙适配器打开失败: ${err.errMsg || err.errCode}`,
icon: 'none',
success: () => {
wx.navigateBack({
delta: 1
});
}
});
}
},
});
},
getDeviceSettingList() {
// app.globalData.ppScale.plugin.Blue.visibleLog(true);
this.setData({
initText: "设备搜索中..."
});
app.globalData.ppScale.device.list = [];
let seviceList = app.globalData.ppScale.device.setting;
app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
let deviceNames = seviceList.map(item => item.deviceName);
@@ -125,12 +151,7 @@ Page({
devicesList: res
});
this.selectDevice();
});
app.globalData.ppScale.plugin.bus.subscribe("devicesModel", (res) => {
console.log("searchDevice ===》devicesModel", res);
app.globalData.ppScale.device.mac = res.deviceMac;
});
});
},
selectDevice() {
@@ -141,30 +162,10 @@ Page({
setTimeout(() => {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
app.globalData.ppScale.device.list = this.data.devicesList;
if(this.data.devicesList.length === 1) {
app.globalData.ppScale.device.connection = this.data.devicesList[0];
wx.redirectTo({
url: "/pages/connectedDevice/connectedDevice"
})
} else {
let itemLists = this.data.devicesList.map(item => item.name);
wx.showActionSheet({
itemList: itemLists,
alertText: "请选择你要使用的设备",
success: (res) => {
app.globalData.ppScale.device.connection = this.data.devicesList[res.tapIndex];
wx.redirectTo({
url: "/pages/connectedDevice/connectedDevice"
})
},
fail: () => {
wx.navigateBack({
delta: 1
})
}
})
}
}, 3000);
wx.redirectTo({
url: "/pages/configureDevice/configureDevice"
})
}, 1000);
}
}
})