123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062 |
- const app = getApp();
- const {
- getBanner,
- 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_service from '../../utils/lexin/service.js';
- import {
- BtHelper
- } from '../../devices/bt_helper.js';
- Page({
- data: {
- 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: [],
- },
- onLoad(options) {
- var that = this;
- that.onDeviceLoad();
- that.onUserInfoLoad();
- that.onBannerLoad();
- },
- onShow() {
- var that = this;
- that.onHomeShow();
- that.onBannerShow();
- },
- onHomeShow() {
- var that = this;
- // var autoConnected = that.data.autoConnected;
- // var deviceListSelect = that.data.deviceListSelect;
- // if (!autoConnected && deviceListSelect == null) {
- // that.actionDevice(0);
- // }
- },
- onDeviceLoad() {
- var that = this;
- BtHelper.getInstance().initBluetoothAdapter();
- var l = store.getStore("deviceList");
- if (!strings.isEmpty(l)) {
- that.updateDeviceList(l, true, false);
- }
- ///监听蓝牙设备
- BtHelper.getInstance().getBluetoothDevices();
- ///3秒去处理一下
- BtHelper.getInstance().startScan(null, null, null);
- var isFirst = true;
- ///再秒再对比一次
- that.stopIntervalId1();
- that.data.intervalId1 = setInterval(async function () {
- isFirst = false;
- that.compareList();
- }, isFirst ? 6 * 1000 : 12 * 1000);
- },
- async compareList() {
- var that = this;
- var deviceList = that.data.deviceList;
- if (deviceList.length > 0) {
- if (BtHelper.getInstance().getCallBackConnect() == null) {
- var compareList = BtHelper.getInstance().getCompareList();
- var dissmissDevice = BtHelper.getInstance().getDissmissDevice();
- ///去掉未连接的离线的
- for (var i = 0; i < dissmissDevice.length; i++) {
- for (var j = 0; j < compareList.length; j++) {
- if (compareList[j].deviceId == dissmissDevice[i].deviceId) {
- compareList.splice(j, 1);
- break;
- }
- }
- }
- if (compareList.length > 0) {
- ///对比在线的蓝牙设备
- var isChanged = false;
- for (var i = 0; i < deviceList.length; i++) {
- var tempItem = deviceList[i];
- if (tempItem.connectType != 3) {
- var has = false;
- for (var j = 0; j < compareList.length; j++) {
- // "state":"online" "offline" MW-SR1(4G_WIFI)
- if (tempItem.deviceId === compareList[j].deviceId) {
- has = true;
- break;
- }
- }
- if (has) {
- if (tempItem.state != "online") {
- isChanged = true;
- tempItem.state = "online";
- }
- } else {
- if (tempItem.state != "offline") {
- isChanged = true;
- tempItem.state = "offline";
- }
- }
- }
- }
- if (isChanged) {
- that.updateDeviceList(deviceList, false, false);
- }
- var autoConnected = that.data.autoConnected;
- var deviceListSelect = that.data.deviceListSelect;
- ///没有连接则连接第一个在线的蓝牙
- if (!autoConnected && deviceListSelect == null) {
- deviceList = that.data.deviceList;
- for (var i = 0; i < deviceList.length; i++) {
- var item = deviceList[i];
- if (item.connectType == 1 && item.state == "online") {
- item.name = item.devName;
- BtHelper.getInstance().connect(item, function (data) {
- if (data) {
- that.addConnectBlueDevice(item);
- }
- });
- break;
- }
- }
- }
- }
- BtHelper.getInstance().startScan(null, null, null);
- }
- }
- },
- // 回调
- 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":
- that.subscribeDevicesStatus();
- break;
- ///再走有在线
- case "message_onoffline":
- that.onlineDevice(payloads);
- break;
- // PlayState: ///播放状态:0默认状态,1播放状态,2暂停状态, 3停止状态,4缓冲状态。
- case "message":
- if (payloads) {
- // payloads.other: {"songInfoID":"843265795768623127","songFrom":"4","songAlbumID":"","artist":"巴洛克古典乐","title":"巴洛克古典乐","url":"http://speed.radio1964.cn/hls/1fmottosbaroquemusicradiozug.m3u8","albumURI":"http://airsmart-photo1.oss-cn-shanghai.aliyuncs.com/img/20211122/98101225b3cb4a0fb5728159ce4ca6d5.png","realUrl":"http://speed.radio1964.cn/hls/1fmottosbaroquemusicradiozug.m3u8","channel":5,"Duration":0,"RelTime":0,"PlayState":1,"PlayMode":0,"SongType":2,"userid":"1","channelType":1,"platformId":4,"platformName":"海外电台","isVip":0,"playable":1,"unplayableMsg":"","unplayableCode":0,"vipIconType":0,"vipIconTypeName":""}
- if (payloads.type === "get_position" && payloads.other) {
- let actionIndex = null;
- that.data.channelData.map((v, index) => {
- if (v.channelNum === payloads.other.channel) {
- actionIndex = index;
- }
- });
- that.setData({
- actionIndex,
- });
- }
- // payloads.other: {"Guid":"AIrSMArT_7cdfa1fd3af0","ProdModel":"MW-2AX(WIFI)","sim_iccid":"","esim_iccid":"","SoftVer":"3.0.7","Firmware":"RTOS","Power":50,"lowBatteryNtf":0,"Volume":27,"Mute":0,"pauseShutdown":0,"PlayState":1,"PlayMode":0,"devName":"猫王小王子OTR-X","deviceId":"","deviceSecret":"","is_tts_enable":1,"SignalQuality":100,"CardIndex":0,"CardSum":0,"NetModel":2,"is_netmode_auto":2,"Imei":"","mid":"","deviceDSN":"1044250776739909632","userid":"1","user_id_white":"1039072","alarm":[{"alarm_id":"0","alarm_name":"open","current_timestamp":"2024-12-12 00:00:00","on_off_timestamp":"16:19:25","operation":"on","song_uri":"","weekly_repeat":"0","enable":"0","action":"update","week_actives":[0,0,0,0,0,0,0]},{"alarm_id":"1","alarm_name":"open","current_timestamp":"2024-12-11 20:00:48","on_off_timestamp":"07:00:00","operation":"on","song_uri":"","weekly_repeat":"0","enable":"1","action":"update","week_actives":[0,0,0,0,0,0,0]}]}
- // 更新信息
- else if (payloads.type === "get_dev_info" && payloads.other) {
- // 接收设备当前信息
- that.getchannelData(payloads.other.ProdModel);
- // 电量
- that.setData({
- battery: that._battery(payloads.other.Power),
- })
- // 当前设备木有设置定时
- that.setData({
- isSetWake: false,
- });
- payloads.other.alarm.map((v) => {
- if (v.enable === "1") {
- that.setData({
- isSetWake: true
- });
- }
- });
- ///连上就调用2次 payloads.SrcDeviceName:AIrSMArT_7cdfa1fcbb24
- var isUpdate = false;
- var deviceList = that.data.deviceList;
- if (!strings.isEmpty(deviceList)) {
- for (var i = 0; i < deviceList.length; i++) {
- if (payloads.SrcDeviceName) {
- var deviceId = deviceList[i].deviceId;
- var splitDeviceId = deviceId.split("BLUFI_");
- if (splitDeviceId.length == 2) {
- var index = payloads.SrcDeviceName.indexOf(splitDeviceId[1]);
- if (index !== -1 && (deviceList[i].ProdModel != payloads.other.ProdModel || deviceList[i].devName != payloads.other.devName)) {
- isUpdate = true;
- deviceList[i].ProdModel = payloads.other.ProdModel;
- deviceList[i].devName = payloads.other.devName;
- break;
- }
- }
- }
- }
- }
- ///数据有更新
- if (isUpdate) {
- that.updateDeviceList(deviceList, false, false);
- }
- }
- ///获取电量
- else if (payloads.type === "battery" && payloads.other) {
- that.setData({
- battery: that._battery(payloads.other.battery),
- })
- }
- ///获取播放状态
- else if (payloads.type === "play" || payloads.type === "play_state") {
- var deviceList = that.data.deviceList;
- var deviceListSelect = that.data.deviceListSelect;
- 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
- });
- }
- }
- break;
- default:
- }
- },
- // 订阅设备在线状态
- subscribeDevicesStatus() {
- var that = this;
- var deviceList = that.data.deviceList;
- if (!strings.isEmpty(deviceList)) {
- for (var i = 0; i < deviceList.length; i++) {
- var device = deviceList[i];
- if (device.connectType == 3) {
- var topic = `/AIrSMArT_${device.deviceId.split("BLUFI_")[1]}/status/onoffline`;
- app.subscribe(topic);
- break;
- }
- }
- }
- },
- // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
- ///连上就调用2次 处理离线在线问题 wifi设备 BLUFI_
- /// payloads:{"uuid":"AIrSMArT_7cdfa1fcbb24","state":"online","userid":"1"}
- // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
- onlineDevice(payloads) {
- // 设置在线状态
- var that = this;
- // console.log("gadsfadsfadsfa==777===" + JSON.stringify(payloads));
- ///是否更新过在线离线状态
- var isUpdate = false;
- var deviceList = that.data.deviceList;
- if (!strings.isEmpty(deviceList)) {
- for (var i = 0; i < deviceList.length; i++) {
- if (payloads && payloads.uuid) {
- var deviceId = deviceList[i].deviceId;
- var splitDeviceId = deviceId.split("BLUFI_");
- if (splitDeviceId.length == 2) {
- var index = payloads.uuid.indexOf(splitDeviceId[1]);
- if (index !== -1) {
- if (deviceList[i].state != payloads.state) {
- isUpdate = true;
- deviceList[i].state = payloads.state;
- break;
- }
- }
- }
- }
- }
- }
- ///数据有更新
- if (isUpdate) {
- that.updateDeviceList(deviceList, false, false);
- }
- deviceList = that.data.deviceList;
- ///当前没有连接设备,则去连接第一个wifi设备
- var deviceListSelect = that.data.deviceListSelect;
- if (deviceListSelect === null) {
- for (var i = 0; i < deviceList.length; i++) {
- if (deviceList[i].state === "online" && deviceList[i].connectType == 3) {
- if (that.data.isLogin) {
- that.actionDevice(i);
- }
- break;
- }
- }
- } else {
- // 当前播放设备离线
- if (deviceList.length > deviceListSelect && deviceList[deviceListSelect].state !== "online") {
- that.setData({
- actionIndex: null,
- deviceListSelect: null,
- });
- };
- }
- },
- ///去连接设备数据
- actionDevice(index) {
- var that = this;
- var isLogin = that.data.isLogin;
- if (!isLogin) {
- return;
- }
- var deviceList = that.data.deviceList;
- if (deviceList.length <= index) {
- return;
- };
- ///限制蓝牙设备和不在线wifi设备
- var device = deviceList[index];
- if (device.connectType != 3 || device.state != "online") {
- return;
- }
- // 取消订阅
- var deviceMacId = that.data.deviceMacId;
- if (!strings.isEmpty(deviceMacId)) {
- var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
- app.unsubscribe(pubResponse);
- };
- var deviceId = device.deviceId;
- deviceMacId = lexin_util.getDeviceMacId(deviceId);
- that.setData({
- deviceListSelect: index,
- deviceMacId: deviceMacId,
- });
- that.subscribeCurrDevice();
- },
- ///数据处理
- subscribeCurrDevice() {
- var that = this;
- if (!(app.globalData.client && app.globalData.client.connected)) {
- app.connect();
- setTimeout(() => {
- that.subscribeCurrDevice();
- }, 500);
- return;
- };
- var deviceList = that.data.deviceList;
- var deviceListSelect = that.data.deviceListSelect;
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return
- };
- var device = deviceList[deviceListSelect];
- if (device.connectType != 3 || device.state != "online") {
- return;
- }
- var deviceId = device.deviceId;
- ///删除当前选中这个
- deviceList.splice(deviceListSelect, 1);
- ///添加到第一个去
- deviceList.unshift(device);
- that.setData({
- deviceListSelect: 0,
- autoConnected: true,
- deviceList: deviceList,
- });
- var deviceMacId = lexin_util.getDeviceMacId(deviceId);
- const obj = {
- DstDeviceName: deviceMacId
- };
- /// /AIrSMArT_7cdfa1fd3af0/user/pub_response
- var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
- app.subscribe(pubResponse);
- app.PubMsg({
- type: "get_dev_info",
- ...obj
- });
- },
- // 格式化电量
- _battery(battery) {
- let _battery = 0;
- if (battery < 20) {
- _battery = 0
- } else if (20 <= battery && battery < 40) {
- _battery = 1
- } else if (40 <= battery && battery < 60) {
- _battery = 2
- } else if (60 <= battery && battery < 80) {
- _battery = 3
- } else if (80 <= battery && battery <= 100) {
- _battery = 4
- } else if (battery > 100) {
- _battery = 5
- };
- return _battery
- },
- actionMusic(e) {
- var that = this;
- if (e.currentTarget.dataset.index === that.data.actionIndex) {
- return;
- };
- var deviceList = that.data.deviceList;
- var deviceListSelect = that.data.deviceListSelect;
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- wx.showToast({
- title: '请选择设备',
- icon: "none"
- });
- return;
- };
- that.setData({
- actionIndex: e.currentTarget.dataset.index,
- });
- var channelData = that.data.channelData;
- var index = e.currentTarget.dataset.index;
- var deviceId = deviceList[deviceListSelect].deviceId;
- const other = {
- "url": "",
- "media_data": "",
- "user_id": `${app.globalData.userInfo.deviceUid}`,
- "timestamp": `${Math.round(new Date() / 1000)}`,
- "channel_id": `${channelData[index].channelNum}`,
- "order": "",
- "resource_from": "",
- "songAlbumID": "",
- "version": 3,
- "is_debug": app.globalData.is_debug
- };
- var deviceMacId = lexin_util.getDeviceMacId(deviceId);
- app.PubMsg({
- type: "play",
- DstDeviceName: deviceMacId,
- other
- });
- },
- getchannelData(clientType) {
- var that = this;
- var deviceList = that.data.deviceList;
- var deviceListSelect = that.data.deviceListSelect;
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return;
- };
- var deviceId = deviceList[deviceListSelect].deviceId;
- listByDevice({
- clientType: clientType,
- unShowLoad: true,
- }).then((res) => {
- that.setData({
- channelData: res
- });
- // 接收设备当前播放状态
- var deviceMacId = lexin_util.getDeviceMacId(deviceId);
- const obj = {
- DstDeviceName: deviceMacId
- }
- app.PubMsg({
- type: "get_position",
- ...obj
- });
- wx.setStorageSync("channelData", res);
- })
- },
- ///去频道详情
- onTapToChannel() {
- var that = this;
- if (that.data.channelData.length > that.data.actionIndex) {
- wx.setStorageSync("channelDeta", that.data.channelData[that.data.actionIndex]);
- wx.navigateTo({
- url: './../channelDetails/channelDetails'
- });
- }
- },
- 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;
- ///退出登录
- if (that.data.isLogin) {
- that.logOut();
- }
- // 登录
- else {
- 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.data.deviceList;
- var deviceListSelect = that.data.deviceListSelect;
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return;
- };
- ///有设备在线被选中,则让它不被选择
- var deviceList = that.data.deviceList;
- if (deviceList[deviceListSelect].connectType == 3) {
- var deviceMacId = that.data.deviceMacId;
- if (!strings.isEmpty(deviceMacId)) {
- var pubResponse = lexin_util.getResponseByDeviceMacId(deviceMacId);
- app.unsubscribe(pubResponse);
- that.setData({
- actionIndex: null,
- deviceListSelect: null,
- });
- };
- }
- },
- ///添加设备
- addDevice() {
- var that = this;
- if (!that.data.isLogin) {
- route_util.jump(route_constant.login);
- return;
- }
- ///跳转设备列表
- route_util.jump(route_constant.deviceList);
- },
- ///点击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.data.isLogin;
- if (!isLogin) {
- route_util.jump(route_constant.login);
- return;
- }
- var item = e.currentTarget.dataset.item;
- var index = e.currentTarget.dataset.index;
- var connectType = item.connectType;
- var deviceListSelect = that.data.deviceListSelect;
- // wifi只支持在线点击
- if (connectType == 3 && item.state === "online") {
- if (index === deviceListSelect) {
- that.goWake();
- } else {
- that.setData({
- deviceListSelect: null,
- });
- that.subscribeDevicesStatus();
- }
- return;
- }
- ///去蓝牙连接处理
- if (index === deviceListSelect) {
- route_util.jumpParam('/pages/deviceDetail/detail', JSON.stringify(item))
- } else if (item.state === "offline") {
- console.log("去连接蓝牙")
- } else {
- ///item
- // {"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 妙播收音机"}
- item.name = item.devName;
- BtHelper.getInstance().connect(item, function (data) {
- if (data) {
- that.addConnectBlueDevice(item);
- }
- });
- }
- },
- // 去唤醒界面
- goWake() {
- var that = this;
- var deviceList = that.data.deviceList;
- var deviceListSelect = that.data.deviceListSelect;
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return
- };
- var device = deviceList[deviceListSelect];
- console.log("gadsfadsfadsfa==999===" + JSON.stringify(device));
- wx.navigateTo({
- url: './../deviceWake/deviceWake?deviceId=' + device.deviceId + "&clientType=" + device.ProdModel,
- });
- },
- ///点击banner事件
- onTapBanner() {
- var that = this;
- var item = e.currentTarget.dataset.item;
- },
- ///删除当前设备
- deleteDevice(e) {
- var that = this;
- var index = e.currentTarget.dataset.index;
- wx.showModal({
- title: '确定删除?',
- success: function (res) {
- if (res.confirm) {
- if (that.data.deviceList[index].connectType == 3) {
- that.cancelWifi(index, false);
- } else {
- that.cancelBlue(index, false);
- }
- }
- }
- });
- },
- ///是否是同一个蓝牙
- isTheSameBlue(connectDevice) {
- var that = this;
- var deviceList = that.data.deviceList;
- var deviceListSelect = that.data.deviceListSelect;
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return false;
- };
- if (deviceList[deviceListSelect].connectType == 3) {
- return false;
- } else {
- if (deviceList[deviceListSelect].deviceId == connectDevice.deviceId) {
- return true;
- } else {
- return false;
- }
- }
- },
- ///断开当前的
- async cancelCurrent() {
- var that = this;
- var deviceList = that.data.deviceList;
- var deviceListSelect = that.data.deviceListSelect;
- if (deviceListSelect === null || deviceList.length <= deviceListSelect) {
- return;
- };
- if (deviceList[deviceListSelect].connectType == 3) {
- await that.cancelWifi(deviceListSelect, true);
- } else {
- await that.cancelBlue(deviceListSelect, true);
- }
- },
- /// 断开蓝牙连接
- async cancelBlue(index, onlyCancel) {
- var that = this;
- if (onlyCancel) {
- return;
- }
- var deviceList = that.data.deviceList;
- var deviceId = deviceList[index].deviceId;
- ///删除当前设备
- deviceList = deviceList.filter((item, i) => {
- return deviceId !== item.deviceId;
- });
- store.setStore("deviceList", deviceList);
- that.setData({
- deviceListSelect: null,
- deviceList: deviceList,
- });
- },
- /// 断开连接wifi
- async cancelWifi(index, onlyCancel) {
- var that = this;
- var deviceList = that.data.deviceList;
- if (index === null || deviceList.length <= index) {
- return;
- };
- var deviceId = deviceList[index].deviceId;
- // 取消订阅
- var pubResponse = lexin_util.getResponseByDeviceId(deviceId);
- app.unsubscribe(pubResponse);
- if (onlyCancel) {
- return;
- }
- deviceList = deviceList.filter((item, i) => {
- return deviceId !== item.deviceId;
- });
- store.setStore("deviceList", deviceList);
- that.setData({
- deviceList: deviceList,
- deviceMacId: null,
- actionIndex: null,
- deviceListSelect: null,
- });
- },
- // {"applicationType":"[0, 1]","deviceId":"DB:45:DD:76:42:15","img":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220909100711728016597.png","offlineImg":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220909100714667384264.png","connectImg":null,"name":"猫王音响·小王子 OTR-X","bluetoothName":"猫王音响·小王子 OTR-X","bluetoothNames":["猫王音响·小王子 OTR-X"],"isChannelsPlatforms":0,"platform":-1,"typeList":[{"is5g":0,"type":1,"connectType":1,"functionList":[1,3,6],"deviceLinkResp":{"icon1":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220909100644913162836.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20220909100648938942906.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/20230313155903515728925.png","icon2":"https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20230313155910706032704.png","icon":null,"guideUrl":null}}],"clientType":"MW-2AX(WIFI)","firstVersion":"0.0.1","filter":null,"guideUrl":null,"manufacturer":"ShanJing","deviceType":0,"mac":"9b45dd76e2150000",
- /// deviceList
- /// 连接方式:bt-0,ble-1,upnp-2,mqtt-3
- /// clientType
- // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
- ///新添加蓝牙设备
- addConnectBlueDevice(newDevice) {
- var that = this;
- // 同一个设备
- var deviceList = that.data.deviceList;
- var tempList = deviceList.filter((v) => v.deviceId === newDevice.deviceId);
- if (tempList && tempList.length > 0) {
- deviceList = deviceList.filter((v) => v.deviceId !== newDevice.deviceId);
- };
- deviceList.unshift({
- /// 蓝牙ble连接
- connectType: 1,
- deviceId: newDevice.deviceId,
- name: newDevice.name,
- state: "online",
- ProdModel: newDevice.ProdModel || newDevice.clientType,
- clientType: newDevice.clientType || newDevice.ProdModel,
- devName: newDevice.name,
- mac: newDevice.mac,
- img: newDevice.img,
- });
- ///在线排序前面,wifi设备排序前面
- that.updateDeviceList(deviceList, false, false);
- var indexPage = that.data.indexPage;
- if (indexPage != 0) {
- that.setData({
- indexPage: 0,
- deviceListSelect: 0,
- autoConnected: true,
- });
- } else {
- that.setData({
- deviceListSelect: 0,
- autoConnected: true,
- });
- }
- },
- // 新添加Wifi设备
- addWifiDevice(device) {
- var that = this;
- var deviceList = that.data.deviceList;
- var addDeviceList = lexin_service.addWifiDevice(device, deviceList);
- that.updateDeviceList(addDeviceList, false, false);
- var indexPage = that.data.indexPage;
- if (indexPage != 0) {
- that.setData({
- indexPage: 0,
- deviceListSelect: null,
- });
- } else {
- that.setData({
- deviceListSelect: null,
- });
- }
- that.subscribeDevicesStatus();
- },
- /// 手机关闭蓝牙,所有蓝牙设备离线
- closeBlueResetOffline(isInit, closeAllBlue) {
- var that = this;
- var deviceList = that.data.deviceList;
- that.updateDeviceList(deviceList, isInit, closeAllBlue);
- },
- /// 更新列表排序
- updateDeviceList(deviceList, isInit, closeAllBlue) {
- var that = this;
- var finalList = lexin_service.updateDeviceList(deviceList, isInit, closeAllBlue);
- if (!strings.isEmpty(deviceList) || !strings.isEmpty(finalList)) {
- store.setStore("deviceList", finalList);
- that.setData({
- deviceList: finalList,
- });
- }
- },
- // 关于我们
- jumpToAboutUs() {
- lexin_jump.toAboutUs();
- },
- ///******************************* 可折叠 ********************************************///
- 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
- // });
- // wx.setStorageSync("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;
- },
- })
- // that.stopIntervalId2();
- // that.data.intervalId2 = setInterval(() => {
- // clearInterval(str);
- // that.subscribeCurrDevice();
- // }, 500);
- // tryConnectBle() {
- // var hasBle = false;
- // var hasConnectBle = false;
- // var hasWifi = false;
- // var bleDevice;
- // let that = this
- // that.data.deviceList.forEach(device => {
- // if (device.connectType == 1) {
- // hasBle = true
- // if (device.state == "online") {
- // hasConnectBle = true
- // }
- // bleDevice = device
- // } else if (device.connectType == 3 && device.state == "online") {
- // // wifi
- // hasWifi = true;
- // }
- // });
- // if (!hasWifi && !hasConnectBle && hasBle) {
- // // 没有wifi 没有连接的ble 有未连接的ble
- // console.log("去连接蓝牙")
- // let bt_helper = BtHelper.getInstance()
- // bt_helper.initBluetooth(function (adapterState, hasPermission) {
- // console.log("蓝牙状态", adapterState, hasPermission)
- // if (adapterState && hasPermission) {
- // bt_helper.connect(bleDevice, function (data) {
- // console.log("连接成功:", data)
- // if (data == true) {
- // // 蓝牙模式
- // bleDevice.connectType = 1
- // // 在线
- // bleDevice.state = 'online'
- // bleDevice.ProdModel = bleDevice.clientType
- // that.addConnectBlueDevice(connectDevice);
- // }
- // })
- // } else {}
- // })
- // }
- // },
- // 去掉此功能,先留着吧
- // const other= {
- // "url": "",
- // "media_data": "",
- // "user_id": `${app.globalData.userInfo.deviceUid}`,
- // "timestamp": `${Math.round(new Date() / 1000)}`,
- // "channel_id": `${res[1].channelNum}`,
- // "order": "",
- // "resource_from": "",
- // "songAlbumID":"",
- // "version":3,
- // "is_debug": app.globalData.is_debug
- // };
- // app.PubMsg({
- // type: "play",
- // DstDeviceName: that.getThisDeviceID(),
- // other
- // });
|