12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019 |
- const app = getApp();
- const {
- login,
- listByDevice
- } = require('../../utils/api.js');
- import timeUtil from '../../utils/time_util.js';
- import strings from '../../utils/strings.js';
- import store from '../../utils/store.js';
- import route_constant from '../../utils/route_constant.js';
- import route_util from '../../utils/route_util.js';
- /// 乐鑫相关
- import lexin_util from '../../utils/lexin/util.js';
- import lexin_jump from '../../utils/lexin/jump.js';
- import lexin_add from '../../utils/lexin/add.js';
- import lexin_scan from '../../utils/lexin/scan.js';
- import lexin_subscribe from '../../utils/lexin/subscribe.js';
- import lexin_connect from '../../utils/lexin/connect.js';
- import lexin_message from '../../utils/lexin/message.js';
- import {
- BtHelper
- } from '../../devices/bt_helper.js';
- Page({
- data: {
- navBarHeight: app.globalData.navBarHeight,
- safeBottomHeight: app.globalData.safeBottomHeight,
- nvabarData: {
- showCapsule: 0, //是否显示左上角图标 1表示显示 0表示不显示
- title: 'OhPlay', //导航栏 中间的标题
- },
- ///下午好
- isLogin: false,
- greeting: "",
- bannerList: [{
- "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20241028142233669038262.png"
- },
- {
- "pic": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20240823145816541223911.png"
- }
- ],
- autoplay: true,
- interval: 3000, // 切换时间间隔
- duration: 500, // 滑动动画时长
- circular: true, // 衔接滑动
- indexPage: 0,
- ///是否展示频道
- showChannel: false,
- ////首页
- navBarHeight: app.globalData.navBarHeight,
- MenuButtonheight: app.globalData.MenuButtonheight,
- MenuButtonTop: app.globalData.MenuButtonTop,
- actionIndex: null,
- luoma: ["Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", " Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ", "Ⅺ", "Ⅻ"],
- channelData: [],
- isOneLoading: true,
- uid: null,
- isSetWake: false,
- battery: 4, // 0≤电量<20,0格
- ////我的界面
- loginStatus: true,
- nickName: "未登录",
- userPic: './../../img/head_pic.png',
- intervalId: null,
- /// 是否第一次自动连接过
- autoConnected: false,
- intervalId1: null,
- intervalId2: null,
- deviceMacId: null,
- deviceListSelect: null,
- deviceList: [],
- _willConnectBle: true,
- // deviceList: [{
- // "connectType": 3,
- // "devName": "猫王小王子OTR-X",
- // "state": "online",
- // "name": "BLUFI_7cdfa1fcbb24",
- // "deviceId": "BLUFI_7cdfa1fcbb24",
- // "mac": "BLUFI_7cdfa1fcbb24",
- // "imageUrl": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100319641863705.png",
- // "ProdModel": "MW-2AX(WIFI-N)",
- // "offlineImg": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100323674404211.png"
- // }, {
- // "connectType": 3,
- // "devName": "猫王小王子OTR-X",
- // "state": "online",
- // "name": "BLUFI_7cdfa1fcbb24",
- // "deviceId": "BLUFI_7cdfa1fcbb24",
- // "mac": "BLUFI_7cdfa1fcbb24",
- // "imageUrl": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100319641863705.png",
- // "ProdModel": "MW-2AX(WIFI-N)",
- // "offlineImg": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100323674404211.png"
- // }, {
- // "connectType": 3,
- // "devName": "猫王小王子OTR-X",
- // "state": "online",
- // "name": "BLUFI_7cdfa1fcbb24",
- // "deviceId": "BLUFI_7cdfa1fcbb24",
- // "mac": "BLUFI_7cdfa1fcbb24",
- // "imageUrl": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100319641863705.png",
- // "ProdModel": "MW-2AX(WIFI-N)",
- // "offlineImg": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100323674404211.png"
- // }, {
- // "connectType": 3,
- // "devName": "猫王小王子OTR-X",
- // "state": "online",
- // "name": "BLUFI_7cdfa1fcbb24",
- // "deviceId": "BLUFI_7cdfa1fcbb24",
- // "mac": "BLUFI_7cdfa1fcbb24",
- // "imageUrl": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100319641863705.png",
- // "ProdModel": "MW-2AX(WIFI-N)",
- // "offlineImg": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100323674404211.png"
- // }, {
- // "connectType": 3,
- // "devName": "猫王小王子OTR-X",
- // "state": "online",
- // "name": "BLUFI_7cdfa1fcbb24",
- // "deviceId": "BLUFI_7cdfa1fcbb24",
- // "mac": "BLUFI_7cdfa1fcbb24",
- // "imageUrl": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100319641863705.png",
- // "ProdModel": "MW-2AX(WIFI-N)",
- // "offlineImg": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100323674404211.png"
- // }, {
- // "connectType": 3,
- // "devName": "猫王小王子OTR-X",
- // "state": "online",
- // "name": "BLUFI_7cdfa1fcbb24",
- // "deviceId": "BLUFI_7cdfa1fcbb24",
- // "mac": "BLUFI_7cdfa1fcbb24",
- // "imageUrl": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100319641863705.png",
- // "ProdModel": "MW-2AX(WIFI-N)",
- // "offlineImg": "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230310100323674404211.png"
- // }],
- connectDeviceIding: "",
- },
- onLoad(options) {
- var that = this;
- that.onLoginLoad();
- that.onDeviceLoad();
- that.onUserInfoLoad();
- that.onBannerLoad();
- },
- onShow() {
- var that = this;
- that.onBannerShow();
- },
- onLoginLoad() {
- var that = this;
- var userInfo = wx.getStorageSync("userInfo") || "";
- if (!strings.isEmpty(userInfo)) {
- var phone = userInfo.phone;
- if (!strings.isEmpty(phone)) {
- that.loginReset(phone, null, null, null);
- };
- }
- },
- ///重新登录
- loginReset(phone, succeedCall1, succeedCall2, failCall) {
- // {"openid":"oZHPJ5JcNem2och3ToaocggmUENw","userId":933625,"deviceUid":1,"accessToken":"PUK8WVnLbIFsWYjSteitmg3OhllpbUMvIPKUtfJgwhRtpl1jx4Fm1NkHQIiZYhHz","phone":"15915390284","headUrl":"https://music-play.oss-cn-shenzhen.aliyuncs.com/user/headurl/20220316194115703366576.png","nickname":"儿子的爸爸叫啥"}
- var that = this;
- wx.login({
- success: res0 => {
- // {"openid":"oZHPJ5JcNem2och3ToaocggmUENw","unionid":null,"userId":933625,"deviceUid":1,"accessToken":"kaKdNAb9eO0iUGKsaLP18UE0wRwrvoCr4opjNC3AieaigH4Fu1IspQKi2zTPgLNG","phone":"15915390284","headUrl":"https://music-play.oss-cn-shenzhen.aliyuncs.com/user/headurl/20220316194115703366576.png","nickname":"儿子的爸爸叫啥","isNewUser":false}
- login({
- code: res0.code,
- phone: phone,
- }).then((res1) => {
- app.globalData.userInfo = res1;
- store.setStore("userInfo", res1);
- store.setStore("token", JSON.stringify({
- id: res1.userId,
- token: res1.accessToken,
- }));
- that.onUserInfoLoad();
- if (succeedCall1 != null) {
- succeedCall1();
- }
- if (succeedCall2 != null) {
- succeedCall2();
- }
- });
- },
- fail(fail4) {
- if (failCall != null) {
- failCall();
- }
- },
- });
- },
- testData() {
- return {
- "deviceId": "xxxxx",
- "deviceName": "xxxxxx",
- "deviceType": "xxxx",
- "type": 1,
- "deviceIcon": "xxxx",
- "deviceMacId": "xxxx",
- "deviceBattery": 4,
- "state": "online",
- "connectType": 1,
- "clientType": "猫王妙播黑胶音箱(BLE)",
- "deviceConnectStatus": 1,
- "deviceConnectStatusText": "xxxx",
- }
- },
- onDeviceLoad() {
- var that = this;
- var deviceList = store.getStore("deviceList");
- if (!strings.isEmpty(deviceList)) {
- // deviceList = deviceList.concat(deviceList);
- that.updateDeviceList(deviceList, true, false);
- }
- // that.addBlueDevice(that.testData())
- let hasBle = that.data.deviceList.find(item => {
- return item.connectType == 1;
- })
- if (hasBle) {
- ///监听蓝牙设备
- BtHelper.getInstance().initBluetoothAdapter();
- BtHelper.getInstance().getBluetoothDevices();
- var isFirst = true;
- console.log("开始监听蓝牙设备");
- ///再秒再对比一次
- that.stopIntervalId1();
- let count = 0;
- that.data.intervalId1 = setInterval(async function () {
- isFirst = false;
- that.compareList();
- if (count > 3) {
- that.stopIntervalId1();
- } else {
- count++;
- }
- }, isFirst ? 6 * 1000 : 12 * 1000);
- }
- },
- /// 对比蓝牙数据
- compareList() {
- var that = this;
- if (that.data.deviceList.length == 1) {
- let device = that.data.deviceList[0];
- if (device.state === 'online') {
- return;
- }
- getApp().getBluetoothStatus();
- that.data._willConnectBle = true;
- return;
- }
- lexin_scan.compareList(function (list) {
- that.updateDeviceList(list, false, false);
- }, function (item) {
- that.addBlueDevice(item);
- });
- },
- getBluetoothStatusCallck(v) {
- var that = this;
- if (!that.data._willConnectBle) {
- // true 走下面
- return;
- }
- if (v) {
- var device = that.data.deviceList[0];
- console.log("开始连接设备0", device);
- if (device.state === 'online' || device.connectType != 1) {
- return;
- }
- // });
- BtHelper.getInstance().connect(device, function (isConnected, d) {
- if (isConnected) {
- device.state = 'online';
- that.addBlueDevice(device);
- } else {
- device.state = 'offline';
- }
- });
- } else {
- // wx.showModal({
- // title: '温馨提示',
- // content: '请检查手机蓝牙是否打开',
- // showCancel: false,
- // success: function (res) { }
- // });
- }
- that.data._willConnectBle = false;
- },
- // 回调
- mqttCallback(type, option) {
- // console.log("gadsfadsfadsfa==888===" + type);
- var that = this;
- let payloads = null;
- if (option && option.payload) {
- payloads = JSON.parse(option.payload);
- };
- switch (type) {
- ///先走订阅
- case "connect":
- lexin_subscribe.subscribeAllDevice();
- break;
- ///再走有在线
- case "message_onoffline":
- lexin_connect.searchOnlineDevice(payloads, function (list) {
- that.updateDeviceList(list, false, false);
- }, function () {
- var indexPage = that.data.indexPage;
- that.setData({
- actionIndex: null,
- deviceListSelect: null,
- indexPage: indexPage == 1 ? 0 : indexPage,
- });
- }, function () {
- var indexPage = that.data.indexPage;
- that.setData({
- actionIndex: null,
- deviceListSelect: null,
- indexPage: indexPage == 1 ? 0 : indexPage,
- });
- });
- break;
- case "message":
- if (payloads) {
- var payloadType = payloads.type;
- var other = payloads.other;
- ///获取频道位置
- if (payloadType === "get_position" && other) {
- lexin_message.getPosition(other, function (actionIndex) {
- that.setData({
- actionIndex: actionIndex,
- });
- });
- }
- // 获取歌曲信息
- else if (payloadType === "get_dev_info" && other) {
- that.setDeviceInfor(other);
- lexin_message.getDeviceInfo(payloads);
- }
- ///获取电量
- else if (payloadType === "battery" && other) {
- if (other.battery) {
- var battery = lexin_message.getBattery(other.battery);
- that.setData({
- battery: battery,
- });
- }
- }
- ///获取播放状态
- else if (payloadType === "play" || payloadType === "play_state") {
- lexin_message.getPlay();
- }
- }
- break;
- default:
- }
- },
- ///去连接设备数据
- actionDevice(device) {
- var that = this;
- // 取消订阅
- var deviceMacId = that.data.deviceMacId;
- if (!strings.isEmpty(deviceMacId)) {
- var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
- app.unsubscribe(pubResponse);
- };
- that.subscribeCurrDevice(device);
- },
- ///数据处理
- subscribeCurrDevice(device) {
- var that = this;
- var isOK = app.globalData.client && app.globalData.client.connected;
- if (!isOK) {
- app.connect();
- setTimeout(() => {
- that.subscribeCurrDevice(device);
- }, 500);
- return;
- };
- var deviceId = device.deviceId;
- var deviceMacId = lexin_util.getDeviceMacId(deviceId);
- that.setData({
- deviceMacId: deviceMacId,
- });
- /// 订阅设备
- var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
- app.subscribe(pubResponse);
- /// 获取设备信息
- const obj = {
- DstDeviceName: deviceMacId
- };
- app.PubMsg({
- type: "get_dev_info",
- ...obj
- });
- },
- ///选择对应的频道
- onTapChannelIndex(e) {
- var that = this;
- var index = e.currentTarget.dataset.index;
- lexin_jump.toChannelIndex(index, function (i) {
- that.setData({
- actionIndex: i,
- });
- });
- },
- ///去频道详情
- onTapToChannel() {
- var that = this;
- var actionIndex = that.data.actionIndex;
- if (actionIndex == null) {
- return;
- }
- var channelData = that.getChannelData();
- if (channelData.length > actionIndex) {
- store.setStore("channelDeta", channelData[actionIndex]);
- wx.navigateTo({
- url: './../channelDetails/channelDetails'
- });
- }
- },
- ///选择对应的频道
- getchannelData(clientType) {
- var that = this;
- listByDevice({
- clientType: clientType,
- unShowLoad: true,
- }).then((res) => {
- store.setStore("channelData", res);
- that.setData({
- channelData: res,
- });
- // 接收设备当前播放状态
- var deviceList = that.getDeviceList();
- var deviceListSelect = that.getDeviceListSelect();
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return;
- };
- var deviceId = deviceList[deviceListSelect].deviceId;
- var deviceMacId = lexin_util.getDeviceMacId(deviceId);
- const obj = {
- DstDeviceName: deviceMacId
- }
- app.PubMsg({
- type: "get_position",
- ...obj
- });
- })
- },
- onTapIndex(e) {
- var that = this;
- var index = e.currentTarget.dataset.index;
- var indexPage = that.data.indexPage;
- if (indexPage != index) {
- that.setData({
- indexPage: index,
- });
- }
- },
- onTapLogin() {
- var that = this;
- ///退出登录
- var isLogin = that.getIsLogin();
- if (isLogin) {
- that.logOut();
- return;
- }
- route_util.jump(route_constant.login);
- },
- ///退出登录
- logOut() {
- var that = this;
- wx.removeStorageSync('userInfo');
- wx.removeStorageSync('token');
- var nickName = "未登录";
- var greeting = that.getGreetBuNickName(nickName);
- that.setData({
- isLogin: false,
- greeting: greeting,
- nickName: nickName,
- userPic: "./../../img/head_pic.png",
- });
- var deviceList = that.getDeviceList();
- var deviceListSelect = that.getDeviceListSelect();
- if (deviceList.length > 1 && (deviceListSelect === null || deviceList.length <= deviceListSelect)) {
- // 2个设备才判断,1个直接删除
- return;
- };
- deviceListSelect = deviceListSelect ?? 0
- ///有设备在线被选中,则让它不被选择
- if (deviceList[deviceListSelect].connectType == 3) {
- var deviceMacId = that.data.deviceMacId;
- if (!strings.isEmpty(deviceMacId)) {
- var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
- app.unsubscribe(pubResponse);
- var indexPage = that.data.indexPage;
- that.setData({
- deviceMacId: null,
- actionIndex: null,
- deviceListSelect: null,
- indexPage: indexPage == 1 ? 0 : indexPage,
- });
- };
- } else {
- // console.log("退出登录,断开连接", deviceList);
- // BtHelper.getInstance().disconnect(deviceList[deviceListSelect]);
- // var indexPage = that.data.indexPage;
- // that.setData({
- // deviceMacId: null,
- // actionIndex: null,
- // deviceListSelect: null,
- // indexPage: indexPage == 1 ? 0 : indexPage,
- // });
- }
- },
- ///点击item
- // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
- onTapItem(e) {
- var that = this;
- var isLogin = that.getIsLogin();
- if (!isLogin) {
- route_util.jump(route_constant.login);
- return;
- }
- var index = e.currentTarget.dataset.index;
- var device = e.currentTarget.dataset.item;
- var connectType = device.connectType;
- var deviceListSelect = that.getDeviceListSelect();
- // wifi只支持在线点击
- if (connectType == 3 && device.state === "online") {
- if (index === deviceListSelect) {
- that.goWake();
- } else {
- that.addWifiDevice(device);
- }
- return;
- }
- ///去蓝牙连接处理
- if (index === deviceListSelect) {
- route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(device))
- } else if (device.state === "offline") {
- console.log("去连接蓝牙", device)
- device.name = device.devName;
- BtHelper.getInstance().connect(device, function (isConnected, d) {
- if (isConnected) {
- device.state = "online";
- that.addBlueDevice(device);
- }
- });
- } else {
- // {"connectType":1,"deviceId":"E4:9F:80:09:40:EC","name":"E4:9F:80:09:40:EC","state":"online","ProdModel":"MW-SR1(4G_WIFI)","devName":"猫王音响x阿基米德 SR1 妙播收音机"}
- }
- },
- // 去唤醒界面
- goWake() {
- var that = this;
- var deviceList = that.getDeviceList();
- var deviceListSelect = that.getDeviceListSelect();
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return
- };
- var device = deviceList[deviceListSelect];
- wx.navigateTo({
- url: './../deviceWake/deviceWake?deviceId=' + device.deviceId + "&clientType=" + device.ProdModel,
- });
- },
- ///删除当前设备
- deleteDevice(e) {
- var that = this;
- var index = e.currentTarget.dataset.index;
- wx.showModal({
- title: '确定删除?',
- success: function (res) {
- if (res.confirm) {
- var deviceList = that.getDeviceList();
- if (deviceList[index].connectType == 3) {
- that.cancelWifi(index, false);
- } else {
- that.cancelBlue(index, false);
- }
- }
- }
- });
- },
- ///是否是同一个蓝牙
- isTheSameBlue(device) {
- var that = this;
- var deviceList = that.getDeviceList();
- var deviceListSelect = that.getDeviceListSelect();
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return false;
- };
- if (deviceList[deviceListSelect].connectType == 3) {
- return false;
- } else {
- if (deviceList[deviceListSelect].deviceId == device.deviceId) {
- return true;
- } else {
- return false;
- }
- }
- },
- ///断开当前的
- cancelCurrent() {
- var that = this;
- var deviceList = that.getDeviceList();
- var deviceListSelect = that.getDeviceListSelect();
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return;
- };
- if (deviceList[deviceListSelect].connectType == 3) {
- that.cancelWifi(deviceListSelect, true);
- } else {
- that.cancelBlue(deviceListSelect, true);
- }
- },
- /// 断开蓝牙连接
- cancelBlue(index, onlyCancel) {
- var that = this;
- if (onlyCancel) {
- return;
- }
- var deviceList = that.getDeviceList();
- var deviceListSelect = that.getDeviceListSelect();
- if (deviceList.length > 1 && (deviceListSelect === null || deviceList.length <= deviceListSelect)) {
- // 2个设备才判断,1个直接删除
- return;
- };
- ///是否删除的当前播放这个
- var isCurrentIndex = false;
- deviceListSelect = deviceListSelect ?? 0;
- if (deviceListSelect != null && deviceList.length > deviceListSelect) {
- isCurrentIndex = (deviceListSelect == index);
- };
- ///删除当前设备
- var deviceId = deviceList[index].deviceId;
- deviceList = deviceList.filter((item, i) => {
- return deviceId !== item.deviceId;
- });
- console.log("断开蓝牙连接", deviceId)
- BtHelper.getInstance().disconnect({ "deviceId": deviceId });
- store.setStore("deviceList", deviceList);
- var indexPage = that.data.indexPage;
- that.setData({
- deviceList: deviceList,
- indexPage: indexPage == 1 ? 0 : indexPage,
- deviceListSelect: isCurrentIndex ? null : deviceListSelect,
- });
- },
- /// 断开连接wifi
- cancelWifi(index, onlyCancel) {
- var that = this;
- var deviceList = that.getDeviceList();
- if (index === null || deviceList.length <= index) {
- return;
- };
- var deviceId = deviceList[index].deviceId;
- // 取消订阅
- var pubResponse = lexin_util.getResponseByDeviceId(deviceId);
- app.unsubscribe(pubResponse);
- if (onlyCancel) {
- return;
- }
- ///是否删除的当前播放这个
- var isCurrentIndex = false;
- var deviceListSelect = that.getDeviceListSelect();
- if (deviceListSelect != null && deviceList.length > deviceListSelect) {
- isCurrentIndex = (deviceListSelect == index);
- };
- deviceList = deviceList.filter((item, i) => {
- return deviceId !== item.deviceId;
- });
- store.setStore("deviceList", deviceList);
- var indexPage = that.data.indexPage;
- var deviceMacId = that.data.deviceMacId;
- var actionIndex = that.data.actionIndex;
- that.setData({
- deviceList: deviceList,
- deviceMacId: isCurrentIndex ? null : deviceMacId,
- actionIndex: isCurrentIndex ? null : actionIndex,
- deviceListSelect: isCurrentIndex ? null : deviceListSelect,
- indexPage: indexPage == 1 ? 0 : indexPage,
- });
- },
- /// 新添加蓝牙设备
- addBlueDevice(device) {
- var that = this;
- var addDeviceList = lexin_add.addBlueDevice(device);
- that.updateDeviceList(addDeviceList, false, false);
- that.setData({
- deviceListSelect: 0,
- autoConnected: true,
- });
- },
- // 新添加Wifi设备
- addWifiDevice(device) {
- var that = this;
- var isOK = app.globalData.client && app.globalData.client.connected;
- if (!isOK) {
- app.connect();
- setTimeout(() => {
- that.addWifiDevice(device);
- }, 500);
- return;
- };
- var deviceId = device.deviceId;
- var addDeviceList = lexin_add.addWifiDevice(device);
- that.updateDeviceList(addDeviceList, false, false);
- var indexPage = that.data.indexPage;
- that.setData({
- deviceListSelect: null,
- connectDeviceIding: deviceId,
- indexPage: indexPage == 1 ? 0 : indexPage,
- });
- lexin_subscribe.subscribeSingleDevice(device);
- },
- refreshCurrentDevice(device) {
- var that = this;
- var addDeviceList = lexin_add.addWifiDevice(device);
- that.updateDeviceList(addDeviceList, false, false);
- that.setData({
- autoConnected: true,
- deviceListSelect: 0,
- connectDeviceIding: "",
- });
- },
- /// 手机关闭蓝牙,所有蓝牙设备离线
- closeBlueResetOffline(isInit, closeAllBlue) {
- var that = this;
- var deviceList = that.getDeviceList();
- that.updateDeviceList(deviceList, isInit, closeAllBlue);
- },
- /// 更新列表排序
- updateDeviceList(deviceList, isInit, closeAllBlue) {
- var that = this;
- var finalList = lexin_add.updateDeviceList(deviceList, isInit, closeAllBlue);
- if (!strings.isEmpty(deviceList) || !strings.isEmpty(finalList)) {
- store.setStore("deviceList", finalList);
- // todo 测试代码
- // finalList.forEach(element => {
- // element.state = "online";
- // });
- that.setData({
- deviceList: finalList,
- });
- }
- },
- ///点击banner事件
- onTapBanner() {
- var that = this;
- var item = e.currentTarget.dataset.item;
- },
- ///添加设备
- jumpToAddDevice() {
- var that = this;
- var isLogin = that.getIsLogin();
- if (!isLogin) {
- route_util.jump(route_constant.login);
- return;
- }
- route_util.jump(route_constant.deviceList);
- },
- // 关于我们
- jumpToAboutUs() {
- lexin_jump.toAboutUs();
- },
- /// 是否已登录
- getIsLogin() {
- var that = this;
- var isLogin = that.data.isLogin;
- return isLogin;
- },
- /// 获取列表数据
- getDeviceList() {
- var that = this;
- var deviceList = that.data.deviceList;
- return deviceList;
- },
- ///获取当前选中的
- getDeviceListSelect() {
- var that = this;
- var deviceListSelect = that.data.deviceListSelect;
- return deviceListSelect;
- },
- ///获取是否已经第一次连接过
- getAutoConnected() {
- var that = this;
- var autoConnected = that.data.autoConnected;
- return autoConnected;
- },
- ///当前正在连接的设备id
- getConnectDeviceIding() {
- var that = this;
- var connectDeviceIding = that.data.connectDeviceIding
- return connectDeviceIding;
- },
- ///获取频道数据
- getChannelData() {
- var that = this;
- var channelData = that.data.channelData;
- return channelData;
- },
- /// 当前播放频道
- getActionIndex() {
- var that = this;
- var actionIndex = that.data.actionIndex;
- return actionIndex;
- },
- /// 获取当前的deviceId
- getCurrentDeviceId() {
- var that = this;
- var deviceList = that.getDeviceList();
- var deviceListSelect = that.getDeviceListSelect();
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return "";
- };
- var deviceId = deviceList[deviceListSelect].deviceId;
- return deviceId;
- },
- ///设置设备相关信息
- setDeviceInfor(other) {
- var that = this;
- // 接收设备当前信息
- that.getchannelData(other.ProdModel);
- // 电量
- if (other.Power) {
- var battery = lexin_message.getBattery(other.Power);
- that.setData({
- battery: battery,
- });
- }
- // 当前设备木有设置定时
- that.setData({
- isSetWake: false,
- });
- other.alarm.map((v) => {
- if (v.enable === "1") {
- that.setData({
- isSetWake: true
- });
- }
- });
- },
- ///******************************* 可折叠 ********************************************///
- onUserInfoLoad() {
- var that = this;
- var userInfo = wx.getStorageSync("userInfo") || "";
- if (!strings.isEmpty(userInfo)) {
- var phone = userInfo.phone;
- if (!phone) {
- return;
- };
- var nickName = userInfo.nickname || "";
- var greeting = that.getGreetBuNickName(nickName);
- // 获取缓存的频道数据
- var channelData = wx.getStorageSync("channelData") || "";
- if (!strings.isEmpty(channelData)) {
- that.setData({
- channelData: channelData,
- greeting: greeting,
- nickName: nickName,
- userPic: userInfo.headUrl || "",
- isLogin: true,
- })
- } else {
- that.setData({
- greeting: greeting,
- nickName: nickName,
- userPic: userInfo.headUrl || "",
- isLogin: true,
- });
- }
- } else {
- var greeting = that.getGreetBuNickName("");
- that.setData({
- greeting: greeting,
- })
- }
- },
- getGreetBuNickName(nickName) {
- var greeting = timeUtil.getGreet();
- if (nickName != "" && nickName != "未登录") {
- greeting = greeting + ',' + nickName;;
- }
- return greeting;
- },
- onBannerLoad() {
- var that = this;
- // var bannerList = wx.getStorageSync("homeBanner") || [];
- // if (that.data.bannerList.length > 0) {
- // that.setData({
- // bannerList: bannerList
- // });
- // }
- },
- onBannerShow() {
- var that = this;
- // getBanner({}).then((res) => {
- // that.setData({
- // bannerList: res
- // });
- // store.setStore("homeBanner", res);
- // })
- },
- stopIntervalId1: function () {
- var that = this;
- if (!strings.isEmpty(that.data.intervalId1)) {
- clearInterval(that.data.intervalId1);
- that.data.intervalId1 = null;
- }
- },
- stopIntervalId2: function () {
- var that = this;
- if (!strings.isEmpty(that.data.intervalId2)) {
- clearInterval(that.data.intervalId2);
- that.data.intervalId2 = null;
- }
- },
- ///销毁蓝牙
- onUnload() {
- var that = this;
- that.stopIntervalId1();
- that.stopIntervalId2();
- if (!strings.isEmpty(that.data.intervalId)) {
- clearInterval(that.data.intervalId);
- that.data.intervalId = null;
- }
- BtHelper.getInstance().disconnect();
- if (app.globalData.client === null) {
- return;
- };
- app.globalData.client.end(true);
- app.globalData.client.end(true);
- app.globalData.client = null;
- },
- })
|