index.js 3.4 KB

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