const constant = require('../../../utils/constant.js'); Page({ data: { nvabarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: '连接配网', //导航栏 中间的标题 callback: () => { console.log("返回界面3:"); } }, scopeBluetooth: false, userFuzzyLocation: true, isNotruter: false, _isFromRootPage: true, isAiDevice: false, connectDevice: {}, imageUrl: "./../../../img/c.png", }, ///定位,蓝牙权限,蓝牙适配器 // {"applicationType":"[0, 1]","deviceId":430635766251545,"img":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113416291791429.png","offlineImg":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113421204031133.png","connectImg":null,"name":"猫王音响x阿基米德 SR1 妙播收音机","bluetoothName":"SR1妙播收音机","bluetoothNames":["SR1妙播收音机","猫王XOG·CyberRadio 001"],"isChannelsPlatforms":1,"platform":0,"typeList":[{"is5g":0,"type":1,"connectType":1,"functionList":[6,1,3],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113427142232548.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113431143471942.png","icon":null,"guideUrl":null}},{"is5g":0,"type":2,"connectType":3,"functionList":[1,3],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113437930271177.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113441600058940.png","icon":null,"guideUrl":null}},{"is5g":0,"type":4,"connectType":3,"functionList":[1,3],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113446634000744.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220812113450885467009.png","icon":null,"guideUrl":null}}],"clientType":"猫王妙播黑胶音箱(BLE)","firstVersion":"1","filter":null,"guideUrl":null,"manufacturer":"ShanJing","deviceType":0} onLoad(options) { var that = this; var param = options.param ?? "{}"; // 解码URL编码的参数,例如:%7B%22%22clientType%22:%22MW-2AXD%22%7D param = decodeURIComponent(param) console.log("设备参数:", param) if (!constant.strings.isEmpty(param)) { param = JSON.parse(param); var clientType = param["clientType"] if (Object.keys(param).length <= 1) { // 扫描进来的只有一个参数 that.setData({ isAiDevice: true, }) var classifyProducts = constant.app.globalData.classifyProducts; if (!constant.strings.isEmpty(classifyProducts)) { var fullDevice = classifyProducts.filter((v) => v.clientType == clientType); console.log("找到设备1", fullDevice); that.updateDeviceUrl(fullDevice[0] ?? param); } else { ///数据请求 constant.dRequest.deviceList({ unShowLoad: true }).then((res) => { if (res) { var fullDevice = res.filter((v) => v.clientType == clientType); that.setDeviceList(res, true); that.updateDeviceUrl(fullDevice[0] ?? param); } }); } } else { that.updateDeviceUrl(param); } } wx.offAppShow(that.getSetting); wx.onAppShow(that.getSetting); that.getSetting(); if (options.isLognlink) { that.setData({ isNotruter: true, nvabarData: { showCapsule: 1, title: '连接配网', callback: () => { constant.routeUtil.goBackRoute(constant.routeRoot.index); } }, }) } }, updateDeviceUrl(param) { var that = this that.data.connectDevice = param; var typeList = param["typeList"] ?? []; if (!constant.strings.isEmpty(typeList)) { typeList = typeList.filter((v) => v.connectType == 3); if (!constant.strings.isEmpty(typeList)) { console.log("找到设备4", typeList); that.setData({ imageUrl: typeList[0].deviceLinkResp.icon1, }); } } }, callback() { // 重置小程序界面到首页 console.log("返回界面4", constant.routePath.index); if (this.data._isFromRootPage) { constant.routeUtil.goBack(); } else { console.log("返回界面4", constant.routePath.index); wx.reLaunch({ // url: '/pages/index/index', url: constant.routePath.index, }); } }, ///获取定位服务 getSetting() { var that = this; wx.getSetting({ success(res) { if (res.authSetting["scope.userFuzzyLocation"]) { constant.app.getBluetoothStatus(); that.setData({ userFuzzyLocation: true, }); } else if (res.authSetting["scope.userFuzzyLocation"] === undefined) { ///请求定位权限 wx.authorize({ scope: "scope.userFuzzyLocation", success() { that.getSetting(); } }); } else { that.setData({ userFuzzyLocation: false, }); wx.showModal({ title: '请打开系统位置获取', success(res) { if (res.confirm) { wx.openSetting({ complete() { // that.getSetting(); } }) } else if (res.cancel) { } } }); } } }) }, ///检测蓝牙权限回调 true:false getBluetoothStatusCallck(v) { var that = this; that.setData({ scopeBluetooth: v }); }, ///下一步 next() { var that = this; ///初始化蓝牙 wx.openBluetoothAdapter({ success(res) { if (that.data.scopeBluetooth && that.data.userFuzzyLocation) { var param = "?param=" + JSON.stringify(that.data.connectDevice); constant.routeUtil.jumpParam(constant.routePath.deviceConnect1, param); } }, fail(err) { if (err.errCode === 10001) { wx.showToast({ title: '手机蓝牙未打开', icon: "none", duration: 2000 }) } else { wx.showToast({ title: err, icon: "none", duration: 2000 }) } } }); }, ///手动开启定位权限 setUserFuzzyLocation() { const that = this; wx.openSetting({ complete() { // that.getSetting(); } }) }, //手动开启蓝牙 setBluetooth() { wx.openSetting({ complete() { //constant.app.getBluetoothStatus(); } }) }, ///返回到首页 notRoter() { constant.routeUtil.goBackRoute(constant.routeRoot.index); }, ///设备列表赋值 setDeviceList(res, isLoad) { var devices = res; if (isLoad) { constant.store.setStore("classifyProducts", res); constant.app.globalData.classifyProducts = devices; } }, deviceTap(e) { var device = e.currentTarget.dataset.device; console.log(device) if (!device) { console.log("设备为空") return; } var clientTypes = constant.lexinDevices.clientTypes; if (clientTypes.includes(device.clientType)) { var param = "?param=" + JSON.stringify(device); // pages/pageB/deviceConnect0/deviceConnect0?param={"clientType":"MW-Mate X(4G_WIFI)"} // ?param={"applicationType":"[0, 1]","deviceId":432698392051714,"img":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230410102304552692164.png","offlineImg":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230410102740684077340.png","connectImg":null,"name":"X2 妙播音箱","bluetoothName":"猫王音响·Mate_X2","bluetoothNames":["猫王音响·Mate_X2","猫王音响·X2妙播音箱","猫王音响·Mate_X"],"isChannelsPlatforms":0,"platform":0,"typeList":[{"is5g":0,"type":1,"connectType":1,"functionList":[1,3],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230410102357244734373.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230410102404705282697.png","icon":null,"guideUrl":null}},{"is5g":0,"type":2,"connectType":3,"functionList":[1,3,6],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230313152650116909154.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230313152717095912088.png","icon":null,"guideUrl":null}},{"is5g":0,"type":4,"connectType":3,"functionList":[1,3,6],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230313152749792939577.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230313152759963002418.png","icon":null,"guideUrl":null}}],"clientType":"MW-Mate X(4G_WIFI)","firstVersion":"0.0.1","filter":null,"guideUrl":null,"manufacturer":"ShanJing","deviceType":0} constant.routeUtil.jumpParam(constant.routePath.deviceConnect0, param); } else if (device.clientType === "MW-S2" || device.clientType === "猫王妙播黑胶音箱(BLE)") { var param = "?param=" + JSON.stringify(device); constant.routeUtil.jumpParam(constant.routePath.connectBle, param); } else { wx.showToast({ title: '暂不支持该设备', }) } }, onUnload() { var that = this; ///传入的监听函数。不传此参数则移除所有监听函数 wx.offAppShow(that.getSetting); }, })