addMattresses.js 22 KB

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