|
@@ -1,111 +1,163 @@
|
|
|
// pages/bluConnect/bleconnect.js
|
|
|
Page(
|
|
|
{
|
|
|
- /**
|
|
|
- * 页面的初始数据
|
|
|
- */
|
|
|
- data: {
|
|
|
- scopeBluetooth: false,
|
|
|
- isScaning: false,
|
|
|
- connectStatus: 0,
|
|
|
- connectText: "连接中",
|
|
|
- connectTips: "确保手机蓝牙已经打开",
|
|
|
- userFuzzyLocation: true,
|
|
|
- nvabarData: {
|
|
|
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
|
- title: '设备连接', //导航栏 中间的标题
|
|
|
- callback() {
|
|
|
- wx.navigateBack({
|
|
|
- delta: 1,
|
|
|
- })
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ scopeBluetooth: false,
|
|
|
+ isScaning: false,
|
|
|
+ connectStatus: 0,
|
|
|
+ connectText: "连接中",
|
|
|
+ connectPic: "",
|
|
|
+ connectTips: "正在搜索设备,请保持开机状态...",
|
|
|
+ buttonTips: "正在搜索设备",
|
|
|
+
|
|
|
+ userFuzzyLocation: true,
|
|
|
+ nvabarData: {
|
|
|
+ showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
|
|
+ title: '设备连接', //导航栏 中间的标题
|
|
|
+ callback: () => {
|
|
|
+ wx.switchTab({
|
|
|
+ url: '../home/home',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ isNotruter: false,
|
|
|
+ deviceItem: {
|
|
|
+ "pic": "../../img/g.png",
|
|
|
+ "address": "",
|
|
|
+ "name": "猫王钢琴音箱",
|
|
|
+ "devName": "名称1", "state": "online", "power": 40
|
|
|
}
|
|
|
+ }, getBluetoothStatusCallck(v) {
|
|
|
+ this.setData({
|
|
|
+ scopeBluetooth: v
|
|
|
+ })
|
|
|
},
|
|
|
- isNotruter: false,
|
|
|
- deviceItem: {
|
|
|
- "pic":"../../img/g.png",
|
|
|
- "address":"",
|
|
|
- "name":"钢琴音箱"
|
|
|
- }
|
|
|
- }, getBluetoothStatusCallck(v) {
|
|
|
- this.setData({
|
|
|
- scopeBluetooth: v
|
|
|
- })
|
|
|
- },
|
|
|
- setBluetooth(){
|
|
|
- wx.openSetting({
|
|
|
- complete () {
|
|
|
- // app.getBluetoothStatus();
|
|
|
+ setBluetooth() {
|
|
|
+ wx.openSetting({
|
|
|
+ complete() {
|
|
|
+ // app.getBluetoothStatus();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, connectDeviceTap() {
|
|
|
+var _this = this;
|
|
|
+ // var curPage = getCurrentPages();
|
|
|
+ // var homePage = curPage[curPage.length - 1];
|
|
|
+ var key = 'home_device_list'+wx.getUserInfo().userId;
|
|
|
+ var saveStr = wx.getStorageSync(key) ?? "[]";
|
|
|
+ console.log("返回数据: "+saveStr);
|
|
|
+
|
|
|
+ var oldList = JSON.parse(saveStr);
|
|
|
+
|
|
|
+ oldList.push(_this.deviceItem);
|
|
|
+ console.log("返回数据:2\n"+JSON.stringify(oldList));
|
|
|
+
|
|
|
+wx.setStorageSync(key, JSON.stringify(oldList));
|
|
|
+ // homePage.setData({deviceList:[_this.deviceItem]});
|
|
|
+wx.navigateBack();
|
|
|
+ if (!_this.isScaning) {
|
|
|
+ return;
|
|
|
}
|
|
|
- })
|
|
|
- },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- onLoad(options) {
|
|
|
+ }, scanDevice() {
|
|
|
+ this.isScaning = true;
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ onLoad(options) {
|
|
|
|
|
|
- if(options.isLognlink) {
|
|
|
- this.setData({
|
|
|
- isNotruter: true,
|
|
|
- nvabarData: {
|
|
|
- showCapsule: 1,
|
|
|
- title: '设备连接',
|
|
|
- callback: ()=> {
|
|
|
- wx.switchTab({
|
|
|
- url: '../home/home',
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
+ if (options.isLognlink) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.buttonTips = this.isScaning ? "正在搜索设备" : "连接";
|
|
|
+
|
|
|
+ this.connectStatus = 4;
|
|
|
+ switch (this.connectStatus) {
|
|
|
+ case 1:
|
|
|
+ // 搜索中
|
|
|
+ this.connectTips = "正在搜索设备,请保持开机状态...";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ // 连接中
|
|
|
+ this.connectText = "连接中...";
|
|
|
+ this.connectPic = "";
|
|
|
+ case 3:
|
|
|
+ // 连接失败
|
|
|
+ this.connectText = "连接失败";
|
|
|
+ this.connectPic = "../../img/i.png";
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ // 连接成功
|
|
|
+ this.connectText = "连接成功";
|
|
|
+ this.connectPic = "../../img/h.png";
|
|
|
+ this.deviceItem = {
|
|
|
+ "pic": "../../img/g.png",
|
|
|
+ "address": "xxxxxx",
|
|
|
+ "name": "猫王钢琴音箱",
|
|
|
+ "devName": "名称1", "state": "online", "power": 40
|
|
|
+ };
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ // 搜索成功
|
|
|
+ this.connectTips = "搜索到" + this.deviceItem.name;
|
|
|
+ var curPage = getCurrentPages();
|
|
|
+ var homePage = curPage[curPage.length - 1];
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面初次渲染完成
|
|
|
- */
|
|
|
- onReady() {
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面初次渲染完成
|
|
|
+ */
|
|
|
+ onReady() {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面显示
|
|
|
- */
|
|
|
- onShow() {
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面显示
|
|
|
+ */
|
|
|
+ onShow() {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面隐藏
|
|
|
- */
|
|
|
- onHide() {
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面隐藏
|
|
|
+ */
|
|
|
+ onHide() {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面卸载
|
|
|
- */
|
|
|
- onUnload() {
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面卸载
|
|
|
+ */
|
|
|
+ onUnload() {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
- */
|
|
|
- onPullDownRefresh() {
|
|
|
+ /**
|
|
|
+ * 页面相关事件处理函数--监听用户下拉动作
|
|
|
+ */
|
|
|
+ onPullDownRefresh() {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
- */
|
|
|
- onReachBottom() {
|
|
|
+ /**
|
|
|
+ * 页面上拉触底事件的处理函数
|
|
|
+ */
|
|
|
+ onReachBottom() {
|
|
|
|
|
|
- },
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage() {
|
|
|
+ /**
|
|
|
+ * 用户点击右上角分享
|
|
|
+ */
|
|
|
+ onShareAppMessage() {
|
|
|
|
|
|
- }
|
|
|
-})
|
|
|
+ }
|
|
|
+ })
|