index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // pages/deviceConMode/index.js
  2. // const btHelper = require('../../devices/bt_helper');
  3. // const toastUtil = require('../../utils/toast_util');
  4. import routeUtil from '../../utils/route_util'
  5. import route_constant from '../../utils/route_constant.js'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. scopeBluetooth: false,
  12. userFuzzyLocation: true,
  13. nvabarData: {
  14. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  15. title: '配网模式选择', //导航栏 中间的标题
  16. },
  17. isNotruter: false,
  18. model: "",
  19. connectDevice: {},
  20. typeList: [{
  21. "icon": "../../images/device/mode_2.png",
  22. "text": "WiFi模式",
  23. "type": 2,
  24. },
  25. {
  26. "icon": "../../images/device/mode_1.png",
  27. "text": "蓝牙模式",
  28. "type": 1,
  29. },
  30. {
  31. "icon": "../../images/device/mode_4.png",
  32. "text": "4G模式",
  33. "type": 4,
  34. },
  35. ],
  36. },
  37. getModeName(curItem) {
  38. // 设备类型:1-蓝牙,2-Wifi,3-传统蓝牙,4-4G
  39. var str = "";
  40. if (curItem.type == 4) {
  41. str = "移动数据模式";
  42. } else if (curItem.type == 2) {
  43. str = "WiFi模式";
  44. } else if (curItem.type == 1) {
  45. str = "蓝牙模式";
  46. }
  47. return str;
  48. },
  49. nextTap(e) {
  50. if (this.nullTips()) {
  51. return
  52. }
  53. let device = this.data.typeList[0];
  54. let type = device.type ?? 0;
  55. console.log("选择模式", type)
  56. ///蓝牙模式
  57. if (type == 1) {
  58. // let device = e.currentTarget.dataset.data
  59. let json = JSON.stringify(this.data.connectDevice)
  60. routeUtil.jumpParam(route_constant.connectBle, json)
  61. // wx.navigateTo({
  62. // url: './../deviceDetail/detail',
  63. // });
  64. }
  65. ///Wifi模式
  66. else if (type == 2) {
  67. wx.navigateTo({
  68. url: './../deviceConnect0/deviceConnect0',
  69. });
  70. } else if (type == 3) {
  71. // btHelper.stopSearch()
  72. }
  73. ///4G模式
  74. else {
  75. }
  76. },
  77. async selectDeviceModelTap(e) {
  78. let device = e.currentTarget.dataset.device;
  79. // console.log(e)
  80. let type = device.type;
  81. if (type == 1) {
  82. // this.getConnectedDevices()
  83. } else if (type == 2) {
  84. } else if (type == 3) {
  85. // btHelper.stopSearch()
  86. } else {
  87. }
  88. var list = []
  89. list.push(device)
  90. this.data.typeList.forEach(element => {
  91. if (element.type != type) {
  92. list.push(element)
  93. }
  94. });
  95. this.setData({
  96. typeList: list,
  97. model: this.getModeName(device)
  98. })
  99. },
  100. nullTips() {
  101. if (this.data.typeList.length === 0) {
  102. wx.showToast({
  103. title: '暂不支持该设备配网',
  104. icon: 'none',
  105. })
  106. return true
  107. }
  108. return false
  109. },
  110. onLoad: function (options) {
  111. let device = JSON.parse(options.param) || {}
  112. console.log("配网配对的设备:", device)
  113. if (Object.keys(device).length === 0) {
  114. wx.showToast({
  115. title: '设备数据为空,返回刷新列表试试看',
  116. })
  117. return;
  118. }
  119. let _this = this
  120. let isWifi = device.clientType != "MW-S2";
  121. let isS2 = device.clientType === "MW-S2";
  122. let _typeList = device.typeList
  123. .filter(e => (isWifi && e.type == 2) || isS2)
  124. .map(e => ({
  125. icon: "../../images/device/mode_" + e.type + ".png",
  126. text: _this.getModeName(e),
  127. type: e.type
  128. }));
  129. var list = []
  130. this.data.typeList.forEach(element => {
  131. if (_typeList.find(_type => _type.type === element.type)) {
  132. list.push(element)
  133. }
  134. });
  135. this.setData({
  136. typeList: list,
  137. connectDevice: device
  138. })
  139. this.nullTips()
  140. },
  141. })