index.js 25 KB

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