index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. const app = getApp();
  2. const {
  3. getBanner,
  4. listByDevice
  5. } = require('../../utils/api.js');
  6. import timeUtil from '../../utils/time_util.js';
  7. import strings from '../../utils/strings.js';
  8. Page({
  9. data: {
  10. nvabarData: {
  11. showCapsule: 0, //是否显示左上角图标 1表示显示 0表示不显示
  12. title: 'OhPlay', //导航栏 中间的标题
  13. },
  14. ///下午好
  15. isLogin: false,
  16. greeting: "",
  17. bannerList: [],
  18. autoplay: true,
  19. interval: 3000, // 切换时间间隔
  20. duration: 500, // 滑动动画时长
  21. circular: true, // 衔接滑动
  22. indexPage: 0,
  23. ///是否展示频道
  24. showChannel: false,
  25. ////首页
  26. navBarHeight: app.globalData.navBarHeight,
  27. MenuButtonheight: app.globalData.MenuButtonheight,
  28. MenuButtonTop: app.globalData.MenuButtonTop,
  29. actionIndex: null,
  30. luoma: ["Ⅰ", "Ⅱ", "Ⅲ", "Ⅳ", "Ⅴ", "Ⅵ", " Ⅶ", "Ⅷ", "Ⅸ", "Ⅹ", "Ⅺ", "Ⅻ"],
  31. channelData: [],
  32. deviceList: [],
  33. deviceListIndex: null,
  34. isOneLoading: true,
  35. uid: null,
  36. isSetWake: false,
  37. thisDeviceMac: null,
  38. battery: 4, // 0≤电量<20,0格
  39. ////我的界面
  40. loginStatus: true,
  41. nickName: "未登录",
  42. userPic: './../../img/head_pic.png'
  43. },
  44. onLoad(options) {
  45. var that = this;
  46. that.onUserInfoLoad();
  47. that.onHomeLoad();
  48. that.onBannerLoad();
  49. },
  50. onShow() {
  51. var that = this;
  52. that.onHomeShow();
  53. that.onBannerShow();
  54. },
  55. onHomeLoad() {
  56. var that = this;
  57. const str = setTimeout(() => {
  58. clearTimeout(str);
  59. if (that.data.isOneLoading) {
  60. that.setData({
  61. isOneLoading: false,
  62. });
  63. }
  64. }, 500);
  65. },
  66. onHomeShow() {
  67. var that = this;
  68. if ((!that.data.isOneLoading)) {
  69. wx.getStorage({
  70. key: 'userInfo',
  71. fail(res) {
  72. // 取消订阅
  73. if (that.data.thisDeviceMac !== null) {
  74. app.unsubscribe(`/${that.data.thisDeviceMac}/user/pub_response`);
  75. };
  76. },
  77. success() {
  78. if (app.globalData.newDeviceId) {
  79. // 获取设备本地数据
  80. that.getDeviceData();
  81. } else if (that.data.deviceListIndex !== null) {
  82. // 更新
  83. that.actionDevice(that.data.deviceListIndex);
  84. }
  85. }
  86. });
  87. };
  88. },
  89. ////登录界面登录成功回调用
  90. loginSucceed() {
  91. },
  92. ///开始时home的
  93. getDeviceData() {
  94. var that = this;
  95. // 获取设备数据
  96. wx.getStorage({
  97. key: 'devicelist',
  98. success(res) {
  99. // wx.hideLoading();
  100. if (res.data) {
  101. const resData = JSON.parse(res.data);
  102. console.log("gadsfadsfadsfa==333===" + JSON.stringify(resData));
  103. that.setData({
  104. deviceList: resData
  105. });
  106. // 连接mqtt
  107. if (app.globalData.client === null) {
  108. app.connect();
  109. } else if (app.globalData.newDeviceId) {
  110. that.setData({
  111. actionIndex: null,
  112. deviceListIndex: null,
  113. });
  114. // 监听
  115. let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
  116. app.subscribe(topic);
  117. const Timeout = setTimeout(() => {
  118. clearTimeout(Timeout);
  119. that.actionDevice(0);
  120. }, 1000);
  121. }
  122. // // 有新设备
  123. // if(app.globalData.newDeviceId) {
  124. // that.setData({
  125. // actionIndex: null,
  126. // deviceListIndex: null,
  127. // });
  128. // let topic = `/AIrSMArT_${resData[0].name.split("BLUFI_")[1]}/status/onoffline`;
  129. // app.subscribe(topic);
  130. // }
  131. }
  132. },
  133. fail(e) {
  134. // wx.hideLoading();
  135. }
  136. });
  137. },
  138. // 回调
  139. mqttCallback(type, option) {
  140. // console.log("gadsfadsfqwerq===" + type + "===" + option);
  141. var that = this;
  142. let payloads = null;
  143. if (option) {
  144. payloads = JSON.parse(option.payload);
  145. };
  146. switch (type) {
  147. case "connect":
  148. that.connectSuccess();
  149. break;
  150. case "message_onoffline":
  151. that.online(payloads);
  152. break;
  153. case "message":
  154. // 接收设备播放信息
  155. if (payloads.type === "get_position" && payloads.other) {
  156. let actionIndex = null;
  157. that.data.channelData.map((v, index) => {
  158. if (v.channelNum === payloads.other.channel) {
  159. actionIndex = index;
  160. }
  161. });
  162. that.setData({
  163. actionIndex,
  164. });
  165. } else if (payloads.type === "play" || payloads.type === "play_state") {
  166. if (that.data.deviceListIndex === null) {
  167. return;
  168. }
  169. // 接收设备当前播放状态
  170. const obj = {
  171. DstDeviceName: that.getThisDeviceID()
  172. }
  173. app.PubMsg({
  174. type: "get_position",
  175. ...obj
  176. });
  177. } else if (payloads.type === "get_dev_info") {
  178. // 接收设备当前信息
  179. that.getchannelData(payloads.other.ProdModel);
  180. // 电量
  181. that.setData({
  182. battery: that._battery(payloads.other.Power),
  183. })
  184. // 当前设备木有设置定时
  185. that.setData({
  186. isSetWake: false,
  187. });
  188. payloads.other.alarm.map((v) => {
  189. if (v.enable === "1") {
  190. that.setData({
  191. isSetWake: true
  192. });
  193. }
  194. });
  195. // 更新信息
  196. ///连上就调用2次
  197. that.data.deviceList.map((v, index) => {
  198. // console.log("gadsfadsfadsfa==444===" + payloads.SrcDeviceName);
  199. // console.log("gadsfadsfadsfa==555===" + JSON.stringify(payloads.other));
  200. // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
  201. /// payloads.other
  202. // {"Guid":"AIrSMArT_7cdfa1fcbb24","ProdModel":"MW-2AX(WIFI-N)","sim_iccid":"","esim_iccid":"","SoftVer":"3.0.7","Firmware":"RTOS","Power":20,"lowBatteryNtf":0,"Volume":24,"Mute":0,"pauseShutdown":600,"PlayState":4,"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":"","userid":"1","user_id_white":"10000309","alarm":[{"alarm_id":"0","alarm_name":"close","current_timestamp":"2024-03-31 19:20:39","on_off_timestamp":"19:30:39","operation":"off","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":"2023-11-17 12:25:10","on_off_timestamp":"13:35:00","operation":"on","song_uri":"","weekly_repeat":"1","enable":"1","action":"update","week_actives":[1,1,1,1,1,1,1]}]}
  203. ///payloads.SrcDeviceName AIrSMArT_7cdfa1fcbb24
  204. if (payloads.SrcDeviceName && payloads.SrcDeviceName.indexOf(v.name.split("BLUFI_")[1]) !== -1) {
  205. that.data.deviceList[index].ProdModel = payloads.other.ProdModel;
  206. that.data.deviceList[index].devName = payloads.other.devName;
  207. }
  208. });
  209. // 更新缓存
  210. wx.setStorage({
  211. key: "devicelist",
  212. data: JSON.stringify(that.data.deviceList),
  213. success() {
  214. that.setData({
  215. deviceList: that.data.deviceList
  216. })
  217. }
  218. });
  219. } else if (payloads.type === "battery" && payloads.other) {
  220. that.setData({
  221. battery: that._battery(payloads.other.battery),
  222. })
  223. }
  224. break;
  225. default:
  226. }
  227. },
  228. // 格式化电量
  229. _battery(battery) {
  230. let _battery = 0;
  231. if (battery < 20) {
  232. _battery = 0
  233. } else if (20 <= battery && battery < 40) {
  234. _battery = 1
  235. } else if (40 <= battery && battery < 60) {
  236. _battery = 2
  237. } else if (60 <= battery && battery < 80) {
  238. _battery = 3
  239. } else if (80 <= battery && battery <= 100) {
  240. _battery = 4
  241. } else if (battery > 100) {
  242. _battery = 5
  243. };
  244. return _battery
  245. },
  246. connectSuccess() {
  247. // 订阅设备在线信息
  248. var that = this;
  249. that.subscribeDevicesStatus();
  250. },
  251. // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
  252. ///连上就调用2次
  253. /// payloads:{"uuid":"AIrSMArT_7cdfa1fcbb24","state":"online","userid":"1"}
  254. online(payloads) {
  255. // 设置在线状态
  256. var that = this;
  257. console.log("gadsfadsfadsfa==777===" + JSON.stringify(payloads));
  258. that.data.deviceList.map((v, index) => {
  259. if (payloads.uuid && payloads.uuid.indexOf(v.name.split("BLUFI_")[1]) !== -1) {
  260. that.data.deviceList[index].state = payloads.state;
  261. }
  262. });
  263. that.setData({
  264. deviceList: that.data.deviceList,
  265. });
  266. // 更新缓存
  267. wx.setStorage({
  268. key: "devicelist",
  269. data: JSON.stringify(that.data.deviceList)
  270. });
  271. // 如没有选中,选中最新的
  272. (() => {
  273. if (that.data.deviceListIndex === null) {
  274. let itue = false;
  275. that.data.deviceList.map((v, index) => {
  276. if (v.state === "online" && !itue) {
  277. itue = true;
  278. that.actionDevice(index);
  279. }
  280. });
  281. }
  282. // else {
  283. // that.actionDevice(that.data.deviceListIndex);
  284. // };
  285. })();
  286. // 当前播放设备离线
  287. if (that.data.deviceListIndex !== null && that.data.deviceList[that.data.deviceListIndex].state !== "online") {
  288. that.setData({
  289. actionIndex: null,
  290. deviceListIndex: null,
  291. });
  292. };
  293. },
  294. // 订阅设备在线状态
  295. subscribeDevicesStatus() {
  296. var that = this;
  297. that.data.deviceList.forEach((value) => {
  298. let topic = `/AIrSMArT_${value.name.split("BLUFI_")[1]}/status/onoffline`;
  299. app.subscribe(topic);
  300. })
  301. },
  302. subscribeCurrDevice() {
  303. var that = this;
  304. if (!(app.globalData.client && app.globalData.client.connected)) {
  305. console.log("未连接MQTT服务器");
  306. const str = setInterval(() => {
  307. clearInterval(str);
  308. that.subscribeCurrDevice();
  309. }, 500);
  310. return;
  311. };
  312. if (that.data.deviceList.length === 0 || that.data.deviceListIndex === null) {
  313. return
  314. };
  315. let topic = `/AIrSMArT_${that.data.deviceList[that.data.deviceListIndex].name.split("BLUFI_")[1]}/user/pub_response`;
  316. app.subscribe(topic);
  317. const obj = {
  318. DstDeviceName: that.getThisDeviceID()
  319. };
  320. app.PubMsg({
  321. type: "get_dev_info",
  322. ...obj
  323. });
  324. },
  325. actionMusic(e) {
  326. var that = this;
  327. if (e.currentTarget.dataset.index === that.data.actionIndex) {
  328. return;
  329. };
  330. if (that.data.deviceListIndex === null) {
  331. wx.showToast({
  332. title: '请选择设备',
  333. icon: "none"
  334. })
  335. return;
  336. };
  337. that.setData({
  338. actionIndex: e.currentTarget.dataset.index
  339. });
  340. const other = {
  341. "url": "",
  342. "media_data": "",
  343. "user_id": `${app.globalData.userInfo.deviceUid}`,
  344. "timestamp": `${Math.round(new Date() / 1000)}`,
  345. "channel_id": `${that.data.channelData[e.currentTarget.dataset.index].channelNum}`,
  346. "order": "",
  347. "resource_from": "",
  348. "songAlbumID": "",
  349. "version": 3,
  350. "is_debug": app.globalData.is_debug
  351. };
  352. app.PubMsg({
  353. type: "play",
  354. DstDeviceName: that.getThisDeviceID(),
  355. other
  356. });
  357. },
  358. getThisDeviceID() {
  359. var that = this;
  360. return `AIrSMArT_${that.data.deviceList[that.data.deviceListIndex].name.split("BLUFI_")[1]}`
  361. },
  362. getchannelData(clientType) {
  363. var that = this;
  364. console.log("gadfadsfqwwerqewrqr==000=" + clientType);
  365. if (that.data.deviceListIndex === null) {
  366. return;
  367. };
  368. listByDevice({
  369. clientType
  370. }).then((res) => {
  371. that.setData({
  372. channelData: res
  373. });
  374. // 接收设备当前播放状态
  375. const obj = {
  376. DstDeviceName: that.getThisDeviceID()
  377. }
  378. app.PubMsg({
  379. type: "get_position",
  380. ...obj
  381. });
  382. wx.setStorage({
  383. key: "channelData",
  384. data: res
  385. });
  386. // 有新设备
  387. if (app.globalData.newDeviceId) {
  388. app.globalData.newDeviceId = null;
  389. return;
  390. // 去掉此功能,先留着吧
  391. // const other= {
  392. // "url": "",
  393. // "media_data": "",
  394. // "user_id": `${app.globalData.userInfo.deviceUid}`,
  395. // "timestamp": `${Math.round(new Date() / 1000)}`,
  396. // "channel_id": `${res[1].channelNum}`,
  397. // "order": "",
  398. // "resource_from": "",
  399. // "songAlbumID":"",
  400. // "version":3,
  401. // "is_debug": app.globalData.is_debug
  402. // };
  403. // app.PubMsg({
  404. // type: "play",
  405. // DstDeviceName: that.getThisDeviceID(),
  406. // other
  407. // });
  408. }
  409. })
  410. },
  411. goChannel() {
  412. var that = this;
  413. wx.setStorage({
  414. key: "channelDeta",
  415. data: that.data.channelData[that.data.actionIndex],
  416. success() {
  417. wx.navigateTo({
  418. url: './../channelDetails/channelDetails'
  419. })
  420. }
  421. })
  422. },
  423. updata() {
  424. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  425. wx.getUpdateManager().applyUpdate()
  426. },
  427. onUnload() {
  428. if (app.globalData.client === null) {
  429. return;
  430. };
  431. app.globalData.client.end(true);
  432. app.globalData.client.end(true);
  433. app.globalData.client = null;
  434. },
  435. onTapIndex(e) {
  436. var that = this;
  437. var index = e.currentTarget.dataset.index;
  438. var indexPage = that.data.indexPage;
  439. if (indexPage != index) {
  440. that.setData({
  441. indexPage: index,
  442. });
  443. }
  444. },
  445. goMeAbout() {
  446. wx.navigateTo({
  447. url: './../about/about',
  448. })
  449. },
  450. goMeLogin() {
  451. var that = this;
  452. if (that.data.isLogin) {
  453. // 退出登录
  454. wx.removeStorage({
  455. key: 'userInfo',
  456. success(res) {
  457. var nickName = "未登录";
  458. var greeting = that.getGreetBuNickName(nickName);
  459. that.setData({
  460. isLogin: false,
  461. greeting: greeting,
  462. nickName: nickName,
  463. userPic: "./../../img/head_pic.png",
  464. });
  465. }
  466. });
  467. wx.removeStorage({
  468. key: 'token',
  469. })
  470. } else {
  471. // 登录
  472. wx.navigateTo({
  473. url: './../login/login',
  474. });
  475. }
  476. },
  477. addDevice() {
  478. var that = this;
  479. if (!that.data.isLogin) {
  480. wx.navigateTo({
  481. url: './../login/login'
  482. });
  483. return;
  484. }
  485. that.goDeviceConnect();
  486. },
  487. goDeviceConnect() {
  488. wx.navigateTo({
  489. url: './../deviceList/deviceList',
  490. });
  491. },
  492. ///点击item
  493. // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
  494. onTapItem(e) {
  495. var that = this;
  496. var item = e.currentTarget.dataset.item;
  497. var ProdModel = item.ProdModel;
  498. if (ProdModel == "MW-2AX(WIFI-N)") {
  499. console.log("gadfadsfadsfaf===aa");
  500. if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
  501. console.log("gadfadsfadsfaf===bbb");
  502. that.goWake();
  503. } else {
  504. console.log("gadfadsfadsfaf===ccc");
  505. that.actionDevice(e.currentTarget.dataset.index)
  506. }
  507. return;
  508. }
  509. ///去蓝牙连接处理
  510. that.addConnectBlueDevice({
  511. deviceId: item.deviceId,
  512. name: item.devName,
  513. state: item.state,
  514. clientType: item.ProdModel,
  515. mac: item.mac,
  516. });
  517. },
  518. actionDevice(index) {
  519. var that = this;
  520. const device = that.data.deviceList[index];
  521. if (device.state !== "online") {
  522. return;
  523. };
  524. // 取消订阅
  525. if (that.data.thisDeviceMac !== null) {
  526. app.unsubscribe(`/${that.data.thisDeviceMac}/user/pub_response`);
  527. };
  528. that.setData({
  529. deviceListIndex: index,
  530. thisDeviceMac: `AIrSMArT_${that.data.deviceList[index].name.split("BLUFI_")[1]}`
  531. });
  532. // app.PubMsg({
  533. // type: "get_dev_info",
  534. // DstDeviceName: that.getThisDeviceID()
  535. // });
  536. that.subscribeCurrDevice();
  537. },
  538. goWake() {
  539. var that = this;
  540. if (that.data.deviceListIndex === null) {
  541. return;
  542. };
  543. wx.navigateTo({
  544. url: './../deviceWake/deviceWake?deviceId=' + that.data.deviceList[that.data.deviceListIndex].deviceId + "&clientType=" + that.data.deviceList[that.data.deviceListIndex].ProdModel,
  545. });
  546. },
  547. ///点击banner事件
  548. onTapBanner() {
  549. var that = this;
  550. var item = e.currentTarget.dataset.item;
  551. },
  552. deleteDevice(e) {
  553. var that = this;
  554. wx.showModal({
  555. title: '确定删除?',
  556. success: function (res) {
  557. if (res.confirm) {
  558. if (that.data.deviceList[e.currentTarget.dataset.index].ProdModel != "MW-2AX(WIFI-N)") {
  559. const id = that.data.deviceList[e.currentTarget.dataset.index].deviceId;
  560. const deviceList = that.data.deviceList.filter((item, i) => {
  561. return id !== item.deviceId
  562. });
  563. wx.setStorage({
  564. key: "devicelist",
  565. data: JSON.stringify(deviceList),
  566. success() {
  567. that.setData({
  568. deviceList,
  569. });
  570. // 当前没有设备
  571. if (deviceList.length === 0) {
  572. that.setData({
  573. deviceListIndex: null,
  574. });
  575. }
  576. }
  577. });
  578. return;
  579. }
  580. const id = that.data.deviceList[e.currentTarget.dataset.index].deviceId;
  581. let name = that.data.deviceListIndex !== null ? that.data.deviceList[that.data.deviceListIndex].name : null;
  582. const deviceList = that.data.deviceList.filter((item, i) => {
  583. return id !== item.deviceId
  584. });
  585. // 取消订阅
  586. app.unsubscribe(`/AIrSMArT_${that.data.deviceList[e.currentTarget.dataset.index].name.split("BLUFI_")[1]}/user/pub_response`);
  587. wx.setStorage({
  588. key: "devicelist",
  589. data: JSON.stringify(deviceList),
  590. success() {
  591. that.setData({
  592. deviceList,
  593. thisDeviceMac: null
  594. });
  595. // 当前没有设备
  596. if (deviceList.length === 0) {
  597. that.setData({
  598. actionIndex: null,
  599. deviceListIndex: null,
  600. });
  601. }
  602. if (that.data.deviceListIndex === null) {
  603. return
  604. };
  605. if (e.currentTarget.dataset.index === that.data.deviceListIndex) {
  606. let index_ = null;
  607. deviceList.map((v, index) => {
  608. if (v.state === "online" && index_ === null) {
  609. index_ = index;
  610. }
  611. });
  612. if (index_ !== null) {
  613. that.actionDevice(index_);
  614. } else {
  615. that.setData({
  616. actionIndex: null,
  617. deviceListIndex: null,
  618. });
  619. };
  620. } else {
  621. deviceList.map((v, index) => {
  622. if (v.name === name) {
  623. that.setData({
  624. deviceListIndex: index,
  625. });
  626. }
  627. });
  628. }
  629. }
  630. });
  631. }
  632. }
  633. });
  634. },
  635. // {"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",
  636. /// deviceList
  637. /// 连接方式:bt-0,ble-1,upnp-2,mqtt-3
  638. /// clientType
  639. // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
  640. addConnectBlueDevice(newDevice) {
  641. var that = this;
  642. // 同一个设备
  643. var deviceList = that.data.deviceList;
  644. var tempList = deviceList.filter((v) => v.deviceId === newDevice.deviceId);
  645. if (tempList && tempList.length > 0) {
  646. deviceList = deviceList.filter((v) => v.deviceId !== newDevice.deviceId);
  647. };
  648. deviceList.unshift({
  649. /// 蓝牙ble连接
  650. connectType: 1,
  651. deviceId: newDevice.deviceId,
  652. name: newDevice.deviceId,
  653. state: "online",
  654. ProdModel: newDevice.clientType,
  655. devName: newDevice.name,
  656. mac: newDevice.mac,
  657. });
  658. var finalList = that.updateDeviceList(deviceList);
  659. var indexPage = that.data.indexPage;
  660. if (indexPage != 0) {
  661. that.setData({
  662. indexPage: 0,
  663. deviceListIndex: 0,
  664. deviceList: finalList,
  665. });
  666. } else {
  667. that.setData({
  668. deviceListIndex: 0,
  669. deviceList: finalList,
  670. });
  671. }
  672. // 更新缓存
  673. wx.setStorage({
  674. key: "devicelist",
  675. data: JSON.stringify(finalList)
  676. });
  677. },
  678. addConnectWifiDevice(deviceList) {
  679. var that = this;
  680. var finalList = that.updateDeviceList(deviceList);
  681. var indexPage = that.data.indexPage;
  682. if (indexPage != 0) {
  683. that.setData({
  684. indexPage: 0,
  685. deviceListIndex: 0,
  686. deviceList: finalList,
  687. });
  688. } else {
  689. that.setData({
  690. deviceListIndex: 0,
  691. deviceList: finalList,
  692. });
  693. }
  694. // 更新缓存
  695. wx.setStorage({
  696. key: "devicelist",
  697. data: JSON.stringify(finalList)
  698. });
  699. },
  700. updateDeviceList(deviceList) {
  701. if (deviceList.length == 0) return [];
  702. var finalList = [];
  703. finalList.push(deviceList[0]);
  704. var onLineList = [];
  705. var onNoLineList = [];
  706. for (var i = 0; i < deviceList.length; i++) {
  707. if (i > 0) {
  708. if (deviceList[i].state == "online") {
  709. onLineList.push(deviceList[i])
  710. } else {
  711. onNoLineList.push(deviceList[i])
  712. }
  713. }
  714. }
  715. onLineList.forEach(element => {
  716. if (element.ProdModel == "MW-2AX(WIFI-N)") {
  717. onLineList.push(element)
  718. } else {
  719. onNoLineList.push(element)
  720. }
  721. });
  722. var onLineWifiList = [];
  723. var onLineNoWifiList = [];
  724. onNoLineList.forEach(element => {
  725. if (element.ProdModel == "MW-2AX(WIFI-N)") {
  726. onLineWifiList.push(element)
  727. } else {
  728. onLineNoWifiList.push(element)
  729. }
  730. });
  731. finalList = finalList.concat(onLineWifiList);
  732. finalList = finalList.concat(onLineNoWifiList);
  733. var onNoLineWifiList = [];
  734. var onNoLineNoWifiList = [];
  735. onNoLineList.forEach(element => {
  736. if (element.ProdModel == "MW-2AX(WIFI-N)") {
  737. onNoLineWifiList.push(element)
  738. } else {
  739. onNoLineNoWifiList.push(element)
  740. }
  741. });
  742. finalList = finalList.concat(onNoLineWifiList);
  743. finalList = finalList.concat(onNoLineWifiList);
  744. return finalList;
  745. },
  746. ///******************************* 可折叠 ********************************************///
  747. onUserInfoLoad() {
  748. var that = this;
  749. var userInfo = wx.getStorageSync("userInfo") || "";
  750. if (!strings.isEmpty(userInfo)) {
  751. var phone = userInfo.phone;
  752. if (!phone) {
  753. return;
  754. };
  755. var nickName = userInfo.nickname || "";
  756. var greeting = that.getGreetBuNickName(nickName);
  757. // 获取缓存的频道数据
  758. var channelData = wx.getStorageSync("channelData") || "";
  759. if (!strings.isEmpty(channelData)) {
  760. that.setData({
  761. channelData: channelData,
  762. greeting: greeting,
  763. nickName: nickName,
  764. userPic: userInfo.headUrl || "",
  765. isLogin: true,
  766. })
  767. } else {
  768. that.setData({
  769. greeting: greeting,
  770. nickName: nickName,
  771. userPic: userInfo.headUrl || "",
  772. isLogin: true,
  773. });
  774. }
  775. that.getDeviceData();
  776. } else {
  777. var greeting = that.getGreetBuNickName("");
  778. that.setData({
  779. greeting: greeting,
  780. })
  781. }
  782. },
  783. getGreetBuNickName(nickName) {
  784. var greeting = timeUtil.getGreet();
  785. if (nickName != "" && nickName != "未登录") {
  786. greeting = greeting + ',' + nickName;;
  787. }
  788. return greeting;
  789. },
  790. onBannerLoad() {
  791. var that = this;
  792. var bannerList = wx.getStorageSync("homeBanner") || [];
  793. if (that.data.bannerList.length == 0) {
  794. that.setData({
  795. bannerList: bannerList
  796. });
  797. }
  798. },
  799. onBannerShow() {
  800. var that = this;
  801. getBanner({}).then((res) => {
  802. that.setData({
  803. bannerList: res
  804. });
  805. wx.setStorageSync("homeBanner", res);
  806. })
  807. },
  808. })