addMattresses.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. // subpages/addMattresses/addMattresses.js
  2. const app = getApp();
  3. const util = require('../../utils/util.js');
  4. const timeOut = 20; //超时时间
  5. var timeId = "";
  6. var sequenceControl = 0;
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. isEdit: false,
  13. showBluetoothList: false,
  14. showBluetoothConnected: false,//连接中
  15. isBluetoothConnected: false,//连接成功
  16. bluetoothConnectedStep: 0,
  17. placeOfUse: "",
  18. usingHuman: "",
  19. pid: "",
  20. sn: "",
  21. ssid: "",
  22. password: "",
  23. bluetoothSelectIndex: -1,
  24. activeIcon: "/subpages/images/ic_blue_radio_check.png",
  25. normalIcon: "/subpages/images/ic_blue_radio_uncheck.png",
  26. deviceList: [],
  27. deviceId: "",
  28. deviceIds: [],
  29. wifiInfo: null,
  30. deviceId: "",
  31. password: "",
  32. notice: "",
  33. value: 90,
  34. gradientColor: {
  35. '0%': '#00CEB2',
  36. '50%': '#00C7FF',
  37. '100%': '#53DAFF',
  38. },
  39. statusDefault: ['蓝牙连接...', '蓝牙连接成功', '成功获取设备信息', '获取属性信息成功', '发送配置信息...', '配置信息发送成功', '连接成功'],
  40. descFailList: ["蓝牙连接失败", "获取设备信息失败", "获取属性信息失败", "发送配置信息失败", "分配网络失败"],
  41. failure: false,
  42. value: 0,
  43. desc: "设备连接...",
  44. blueConnectNum: 0,
  45. isChecksum: true,
  46. isEncrypt: false,
  47. flagEnd: false,
  48. defaultData: 1,
  49. ssidType: 2,
  50. passwordType: 3,
  51. meshIdType: 3,
  52. deviceNo: 0,
  53. uuid: "",
  54. serviceId: "",
  55. meshId: "",
  56. processList: [],
  57. result: [],
  58. },
  59. onClose() {
  60. this.setData({ showBluetoothList: false, showBluetoothConnected: false });
  61. },
  62. closeEndDialog() {
  63. this.onClose()
  64. wx.navigateBack()
  65. },
  66. checkBluetoothSelectIndex(e) {
  67. const index = e.currentTarget.dataset.index;
  68. this.setData({ bluetoothSelectIndex: index });
  69. },
  70. commitData() {
  71. console.log(this.data.placeOfUse);
  72. console.log(this.data.usingHuman);
  73. console.log(this.data.sn);
  74. console.log(this.data.ssid);
  75. console.log(this.data.password);
  76. this.checkSn(this.data.sn);
  77. },
  78. commitUserData() {
  79. const that = this;
  80. if (that.data.isEdit) {
  81. wx.request({
  82. url: 'https://aipush.aidsleep.cn/customeredit',
  83. method: 'POST',
  84. data: {
  85. token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
  86. pid: this.data.pid,
  87. sntram: this.data.sn,
  88. per: this.data.usingHuman,
  89. loc: this.data.placeOfUse,
  90. },
  91. success: (res) => {
  92. var codes = res.data.codes;
  93. if (codes && codes == 'success') {
  94. wx.showToast({
  95. icon: 'none',
  96. title: "添加成功"
  97. });
  98. } else {
  99. wx.showToast({
  100. icon: 'none',
  101. title: "添加失败"
  102. });
  103. }
  104. },
  105. fail: () => {
  106. wx.showToast({
  107. icon: 'none',
  108. title: "添加失败"
  109. });
  110. }
  111. });
  112. return
  113. }
  114. wx.request({
  115. url: 'https://aipush.aidsleep.cn/wxsaveunionsn',
  116. method: 'POST',
  117. data: {
  118. token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
  119. unionid: wx.getStorageSync("unionid"),
  120. sntram: this.data.sn,
  121. per: this.data.usingHuman,
  122. loc: this.data.placeOfUse,
  123. },
  124. success: (res) => {
  125. var codes = res.data.codes;
  126. if (codes && codes == 'success') {
  127. wx.showToast({
  128. icon: 'none',
  129. title: "添加成功"
  130. });
  131. } else {
  132. wx.showToast({
  133. icon: 'none',
  134. title: "添加失败"
  135. });
  136. }
  137. },
  138. fail: () => {
  139. wx.showToast({
  140. icon: 'none',
  141. title: "添加失败"
  142. });
  143. }
  144. });
  145. },
  146. // 开启蓝牙
  147. bindViewBlue: function () {
  148. const that = this;
  149. wx.offBluetoothDeviceFound();
  150. wx.closeBluetoothAdapter();
  151. wx.openBluetoothAdapter({
  152. success(res) {
  153. //console.log(res);
  154. that.getBluDevice()
  155. },
  156. fail(res) {
  157. console.log(res);
  158. wx.showToast({
  159. icon: 'none',
  160. title: "请打开系统蓝牙"
  161. });
  162. }
  163. })
  164. },
  165. // 获取蓝牙设备列表
  166. getBluDevice() {
  167. var self = this;
  168. //第一步检查蓝牙适配器是否可用
  169. wx.onBluetoothAdapterStateChange(function (res) {
  170. if (!res.available) {
  171. util.showToast('蓝牙不可用');
  172. return false;
  173. }
  174. });
  175. var oldDeviceList = wx.getStorageSync('deviceList');
  176. self.setData({
  177. deviceList: oldDeviceList,
  178. showBluetoothList: true
  179. });
  180. //第二步关闭适配器,重新来搜索
  181. wx.openBluetoothAdapter({
  182. success: function (res) {
  183. wx.getBluetoothAdapterState({
  184. success: function (res) {
  185. wx.stopBluetoothDevicesDiscovery({
  186. success: function (res) {
  187. wx.startBluetoothDevicesDiscovery({
  188. services: ['0000FFF0-0000-1000-8000-00805F9B34FB'],
  189. success: function (res) {
  190. wx.onBluetoothDeviceFound(function (res) {
  191. console.log(res);
  192. var list = util.filterDevice(res.devices, "name");
  193. if (list.length > 0) {
  194. console.log('==========onBluetoothDeviceFound===========');
  195. console.log(list);
  196. var deviceList = self.data.deviceList;
  197. var doDevices = wx.getStorageSync('doDevices');
  198. if (doDevices) {
  199. } else {
  200. doDevices = [];
  201. }
  202. console.log(deviceList);
  203. console.log(doDevices);
  204. wx.setStorageSync('doDevices', doDevices);
  205. wx.hideLoading();
  206. list.forEach(function (item) {
  207. var flag = true;
  208. for (var i = 0; i < deviceList.length; i++) {
  209. var itemSub = deviceList[i];
  210. if (itemSub.deviceId === item.deviceId) {
  211. flag = false;
  212. break;
  213. }
  214. }
  215. if (flag) {
  216. var arrD = item['name'].split(' ');
  217. item['sn'] = arrD[1];
  218. // wx.request({
  219. // url: 'https://aipush.aidsleep.cn/checkbeds',
  220. // method: 'POST',
  221. // header: {
  222. // 'content-type': 'application/json' // 设置请求的 header
  223. // },
  224. // data: {
  225. // "snlists": arrD[1], // 需要发送的数据
  226. // "token": "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3"
  227. // },
  228. // success: function (res) {
  229. // //console.log(res);
  230. // if (res.data.data[arrD[1]].trim() == 'yes') {
  231. // item['beOnline'] = 'icon-deng-ok';
  232. // } else {
  233. // item['beOnline'] = '';
  234. // // if (doDevices.indexOf(item['deviceId']) >= 0) {
  235. // // item['beOnline'] = 'icon-deng-ok';
  236. // // }
  237. // }
  238. deviceList.push(item);
  239. // },
  240. // fail: function (error) {
  241. // console.error(error);
  242. // }
  243. // });
  244. }
  245. })
  246. self.setData({
  247. deviceList: deviceList,
  248. showBluetoothList: true
  249. });
  250. wx.setStorageSync('deviceList', deviceList);
  251. }
  252. })
  253. }
  254. })
  255. },
  256. fail: function (res) {
  257. console.log(res);
  258. }
  259. });
  260. },
  261. fail: function (res) {
  262. console.log(res);
  263. }
  264. });
  265. },
  266. fail: function (res) {
  267. console.log(res);
  268. }
  269. });
  270. },
  271. commitBluetooth() {
  272. this.onClose();
  273. if (this.data.bluetoothSelectIndex < 0) {
  274. util.showToast("请选择一个床垫");
  275. wx.offBluetoothDeviceFound()
  276. return false;
  277. }
  278. var deviceId = this.data.deviceList[this.data.bluetoothSelectIndex].deviceId;
  279. var name = this.data.deviceList[this.data.bluetoothSelectIndex].name;
  280. var nameList = this.data.deviceList[this.data.bluetoothSelectIndex].name.split(' ');
  281. this.setData({
  282. deviceId: deviceId,
  283. sn: nameList[1]
  284. })
  285. wx.offBluetoothDeviceFound()
  286. },
  287. // 开始配网
  288. bindViewConnect() {
  289. const that = this;
  290. if (that.data.bluetoothSelectIndex < 0) {
  291. util.showToast("没有指定要配网的设备");
  292. return false;
  293. }
  294. var deviceIds = this.data.deviceList[this.data.bluetoothSelectIndex];
  295. if (this.data.deviceList.length == 0 || deviceIds.length === 0) {
  296. util.showToast("没有指定要配网的设备");
  297. return false;
  298. }
  299. that.gotoProvision()
  300. },
  301. // 获取Wifi
  302. getWifiInfo: function () {
  303. wx.startWifi({
  304. success(res) {
  305. //console.log(' ================== startWifi ================== ');
  306. //console.log(res);
  307. wx.getConnectedWifi({
  308. success(res) {
  309. },
  310. fail: function (err) {
  311. console.log(' ================== startWifi fail ================== ');
  312. console.log(err);
  313. if (app.data.sytem == 'ios') {
  314. util.showToast("获取Wi-Fi信息失败,请更新微信到最新版");
  315. } else {
  316. util.showToast("获取Wi-Fi信息失败");
  317. }
  318. }
  319. });
  320. }
  321. });
  322. const self = this;
  323. wx.startWifi({
  324. success(res) {
  325. //console.log(res)
  326. // 先取一次,防止IOS获取不到
  327. wx.getConnectedWifi({
  328. success(res) {
  329. self.setData({
  330. wifiInfo: res.wifi,
  331. ssid: res.wifi.SSID
  332. });
  333. //console.log('== getConnectedWifi ==');
  334. //console.log(res);
  335. if (res.frequency >= 2412 && res.frequency <= 2472) { } else {
  336. self.setData({
  337. notice: "温馨提示:当前您连接的Wi-Fi网络是5G频段,建议连接2.4G频段配网"
  338. })
  339. }
  340. },
  341. fail: function (err) {
  342. util.showToast("获取Wi-Fi信息失败");
  343. }
  344. })
  345. wx.onWifiConnected(function (res) {
  346. // console.log('== onWifiConnected ==');
  347. // console.log(res);
  348. self.setData({
  349. wifiInfo: res.wifi
  350. })
  351. })
  352. },
  353. fail(res) {
  354. console.log('WIFI初始化失败', res)
  355. util.showToast("WIFI初始化失败");
  356. }
  357. })
  358. },
  359. gotoProvision: function () {
  360. const wifiInfo = this.data.wifiInfo;
  361. const ssid = wifiInfo != null ? wifiInfo.SSID : null;
  362. const bssid = wifiInfo != null ? wifiInfo.BSSID : null;
  363. const password = this.data.password;
  364. if (wifiInfo == null) {
  365. util.showToast("没有Wi-Fi连接");
  366. return;
  367. } else {
  368. if (ssid == null || ssid == '' || password == '') {
  369. util.showToast("WiFi登录名和密码不能为空");
  370. return;
  371. } else {
  372. const info = {
  373. ssid: ssid,
  374. bssid: bssid,
  375. password: password,
  376. deviceIds: this.data.deviceId
  377. }
  378. this.blueConnect();
  379. }
  380. }
  381. },
  382. // 蓝牙链接
  383. blueConnect: function (event) {
  384. //console.log(' =============== blueConnect start ===============')
  385. var self = this;
  386. sequenceControl = 0;
  387. self.setData({
  388. flagEnd: false,
  389. serviceId: "",
  390. uuid: "",
  391. showBluetoothConnected: true
  392. });
  393. self.setProcess(0, util.descSucList[0], 1);
  394. wx.offBluetoothAdapterStateChange();
  395. //第一步检查蓝牙适配器是否可用
  396. wx.onBluetoothAdapterStateChange(function (res) {
  397. if (!res.available) {
  398. util.showToast('蓝牙不可用');
  399. return false;
  400. }
  401. });
  402. //console.log(app.data);
  403. if (app.data.sytem == 'ios') {
  404. }
  405. //console.log('deviceId = ' + self.data.deviceId)
  406. wx.createBLEConnection({
  407. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  408. deviceId: self.data.deviceId,
  409. timeout: 10000,
  410. success: function (res) {
  411. wx.setBLEMTU({
  412. deviceId: self.data.deviceId,
  413. mtu: 128
  414. })
  415. //console.log("============ createBLEConnection success =============")
  416. //console.log(self.data.deviceId)
  417. self.getDeviceServices(self.data.deviceId);
  418. },
  419. fail: function (res) {
  420. console.log("============ createBLEConnection fail =============")
  421. console.log(res)
  422. console.log(self.data.blueConnectNum)
  423. var num = self.data.blueConnectNum;
  424. if (num < 3) {
  425. self.blueConnect();
  426. num++;
  427. self.setData({
  428. blueConnectNum: num
  429. })
  430. } else {
  431. self.setFailProcess(true, res.errCode + "::" + util.descFailList[0]);
  432. }
  433. }
  434. })
  435. },
  436. getDeviceServices: function (deviceId) {
  437. var self = this;
  438. wx.getBLEDeviceServices({
  439. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  440. deviceId: deviceId,
  441. success: function (res) {
  442. self.setProcess(10, util.descSucList[1], 2);
  443. var services = res.services;
  444. if (services.length > 0) {
  445. for (var i = 0; i < services.length; i++) {
  446. var uuid = services[i].uuid;
  447. if (uuid == app.data.service_uuid) {
  448. self.getDeviceCharacteristics(deviceId, uuid);
  449. return false;
  450. }
  451. }
  452. }
  453. },
  454. fail: function (res) {
  455. self.setFailProcess(true, res.errCode + "::" + util.descFailList[1]);
  456. }
  457. })
  458. },
  459. getDeviceCharacteristics: function (deviceId, serviceId) {
  460. //console.log(" ============== getDeviceCharacteristics =============== ");
  461. var self = this;
  462. wx.getBLEDeviceCharacteristics({
  463. // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
  464. deviceId: deviceId,
  465. serviceId: serviceId,
  466. success: function (res) {
  467. self.setProcess(40, util.descSucList[2], 3);
  468. var list = res.characteristics;
  469. if (list.length > 0) {
  470. for (var i = 0; i < list.length; i++) {
  471. var uuid = list[i].uuid;
  472. if (uuid == app.data.characteristic_write_uuid) {
  473. self.openNotify(deviceId, serviceId, uuid);
  474. self.setData({
  475. serviceId: serviceId,
  476. uuid: uuid,
  477. })
  478. return false;
  479. }
  480. }
  481. }
  482. },
  483. fail: function (res) {
  484. console.log(res);
  485. self.setFailProcess(true, res.errCode + "::" + util.descFailList[2]);
  486. }
  487. })
  488. },
  489. //连接超时
  490. onTimeout: function (num) {
  491. const self = this;
  492. timeId = setInterval(function () {
  493. if (num < timeOut) {
  494. num++;
  495. } else {
  496. clearInterval(timeId);
  497. self.setFailProcess(true, res.errCode + "::" + util.descFailList[4]);
  498. }
  499. }, 1000)
  500. },
  501. //启用通知
  502. openNotify: function (deviceId, serviceId, characteristicId) {
  503. //console.log("=========== openNotify ============");
  504. var self = this;
  505. wx.notifyBLECharacteristicValueChange({
  506. state: true, // 启用 notify 功能
  507. deviceId: deviceId,
  508. serviceId: serviceId,
  509. characteristicId: app.data.characteristic_read_uuid,
  510. success: function (res) {
  511. //console.log(res);
  512. self.writeDevice(deviceId, serviceId, characteristicId, null);
  513. self.onNotify();
  514. },
  515. fail: function (res) {
  516. console.log(res);
  517. }
  518. })
  519. },
  520. //监听通知
  521. onNotify: function () {
  522. //console.log("=========== onNotify ============");
  523. var self = this;
  524. wx.onBLECharacteristicValueChange(function (res) {
  525. //console.log(res);
  526. self.getResultType(util.ab2hex(res.value));
  527. })
  528. },
  529. getCharCodeat: function (str) {
  530. var list = [];
  531. for (var i = 0; i < str.length; i++) {
  532. list.push(str.charCodeAt(i));
  533. }
  534. return list;
  535. },
  536. // 设备数据开始写入
  537. writeDevice: function (deviceId, serviceId, characteristicId, data) {
  538. //console.log("===== writeDevice =====");
  539. var self = this,
  540. obj = {};
  541. self.setProcess(60, util.descSucList[4], 3);
  542. sequenceControl = parseInt(sequenceControl) + 1;
  543. if (!util._isEmpty(data)) {
  544. obj = util.isSubcontractor(data, true, sequenceControl);
  545. } else {
  546. data = util.writeData(self.getCharCodeat('"' + self.data.ssid + '","' + self.data.password + '"'));
  547. obj = util.isSubcontractor(data, self.data.isChecksum, sequenceControl);
  548. }
  549. var typedArray = new Uint8Array(obj.lenData)
  550. wx.writeBLECharacteristicValue({
  551. deviceId: deviceId,
  552. serviceId: serviceId,
  553. characteristicId: characteristicId,
  554. value: typedArray.buffer,
  555. success: function (res) {
  556. //console.log(res);
  557. if (obj.flag) {
  558. self.writeDevice(deviceId, serviceId, characteristicId, obj.laveData);
  559. } else {
  560. self.setProcess(80, util.descSucList[5], 4);
  561. }
  562. },
  563. fail: function (res) {
  564. console.log(res);
  565. self.setFailProcess(true, res.errCode + "::" + util.descFailList[3]);
  566. }
  567. })
  568. },
  569. getResultType: function (list) {
  570. console.log(' ========= getResultType ========= ');
  571. var self = this;
  572. console.log(list);
  573. var deviceList = wx.getStorageSync('deviceList');
  574. console.log(deviceList);
  575. if (list.length < 4) {
  576. self.setFailProcess(true, res.errCode + "::" + util.descFailList[4]);
  577. return false;
  578. }
  579. var val = list[4];
  580. if (val == "00") {
  581. var idx = self.data.deviceNo + 1;
  582. var doDevices = wx.getStorageSync('doDevices');
  583. if (doDevices) {
  584. if (doDevices.indexOf(self.data.deviceId) < 0) {
  585. doDevices.push(self.data.deviceId);
  586. }
  587. } else {
  588. doDevices = [self.data.deviceId];
  589. }
  590. wx.setStorageSync('doDevices', doDevices);
  591. var deviceSn = self.data.deviceId;
  592. for (var i = 0; i < deviceList.length; i++) {
  593. var itemSub = deviceList[i];
  594. if (itemSub.deviceId === self.data.deviceId) {
  595. deviceSn = itemSub.sn;
  596. break;
  597. }
  598. }
  599. if (idx < self.data.deviceIds.length) {
  600. self.setProcess(90, 'SN:' + deviceSn + ' 连接成功', 5);
  601. wx.closeBLEConnection({
  602. deviceId: self.data.deviceId,
  603. success: function (res) { }
  604. })
  605. self.setData({
  606. deviceNo: idx,
  607. deviceId: self.data.deviceIds[idx],
  608. blueConnectNum: 0
  609. });
  610. self.blueConnect();
  611. } else {
  612. self.setProcess(90, 'SN:' + deviceSn + ' 连接成功', 5);
  613. self.setProcess(100, util.descSucList[6], 7);
  614. self.setData({
  615. result: [],
  616. })
  617. }
  618. } else {
  619. self.setFailProcess(true, res.errCode + "::" + util.descFailList[4])
  620. }
  621. },
  622. setProcess: function (value, desc, step = 0) {
  623. var self = this,
  624. list = [];
  625. list = self.data.processList;
  626. if (list.indexOf(desc) == -1) {
  627. list.push(desc);
  628. }
  629. if (self.data.value <= value) {
  630. self.setData({
  631. value: value,
  632. bluetoothConnectedStep: step
  633. });
  634. }
  635. self.setData({
  636. processList: list
  637. });
  638. //console.log(value);
  639. //console.log(desc);
  640. if (value == 100) {
  641. self.closeConnect();
  642. wx.closeBluetoothAdapter();
  643. self.setData({
  644. isBluetoothConnected: true,
  645. desc: util.descSucList[6]
  646. });
  647. clearInterval(timeId);
  648. sequenceControl = 0;
  649. self.commitUserData();
  650. }
  651. },
  652. setFailProcess: function (flag, desc) {
  653. var self = this,
  654. list = [];
  655. list = self.data.processList;
  656. list.push(desc);
  657. self.setData({
  658. failure: flag,
  659. processList: list
  660. });
  661. },
  662. closeConnect: function () {
  663. var self = this;
  664. wx.closeBLEConnection({
  665. deviceId: self.data.deviceId,
  666. success: function (res) { }
  667. })
  668. },
  669. /**
  670. * 生命周期函数--监听页面加载
  671. */
  672. onLoad(options) {
  673. this.getWifiInfo();
  674. if (options.type && options.type == "edit") {
  675. wx.setNavigationBarTitle({
  676. title: "编辑床垫"
  677. })
  678. const item = wx.getStorageSync("item");
  679. if (item) {
  680. this.setData({
  681. isEdit: true,
  682. pid: item.pid,
  683. placeOfUse: item.location,
  684. usingHuman: item.person,
  685. deviceId: item.sn,
  686. sn: item.sn,
  687. ssid: "",
  688. password: "",
  689. })
  690. wx.removeStorageSync("item")
  691. }
  692. }
  693. },
  694. // 实验室
  695. // 测试
  696. // 332016850591
  697. // sleep
  698. // sleep1234
  699. checkSn(sntram) {
  700. const that = this;
  701. wx.request({
  702. url: 'https://aipush.aidsleep.cn/wxchecksn',
  703. method: 'POST',
  704. data: {
  705. token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
  706. sntram: sntram,
  707. },
  708. success: (res) => {
  709. var incustom = res.data.incustom;
  710. if (incustom == "true") {
  711. that.bindViewConnect();
  712. } else {
  713. wx.showToast({
  714. icon: 'none',
  715. title: "sn 不合法"
  716. });
  717. }
  718. },
  719. fail: () => {
  720. wx.showToast({
  721. icon: 'none',
  722. title: "sn 不合法"
  723. });
  724. }
  725. });
  726. },
  727. /**
  728. * 生命周期函数--监听页面初次渲染完成
  729. */
  730. onReady() {
  731. },
  732. /**
  733. * 生命周期函数--监听页面显示
  734. */
  735. onShow() {
  736. },
  737. /**
  738. * 生命周期函数--监听页面隐藏
  739. */
  740. onHide() {
  741. },
  742. /**
  743. * 生命周期函数--监听页面卸载
  744. */
  745. onUnload() {
  746. wx.offWifiConnected({});
  747. wx.stopWifi({})
  748. wx.offBluetoothDeviceFound()
  749. wx.removeStorageSync('deviceList')
  750. this.closeConnect()
  751. },
  752. /**
  753. * 页面相关事件处理函数--监听用户下拉动作
  754. */
  755. onPullDownRefresh() {
  756. },
  757. /**
  758. * 页面上拉触底事件的处理函数
  759. */
  760. onReachBottom() {
  761. },
  762. /**
  763. * 用户点击右上角分享
  764. */
  765. onShareAppMessage() {
  766. }
  767. })