deviceMode.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. var param = "?param=" + JSON.stringify(this.data.connectDevice);
  53. routeUtil.jumpParam(routePath.connectBle, param);
  54. }
  55. ///Wifi模式
  56. else if (type == 2) {
  57. routeUtil.jump(routePath.deviceConnect0);
  58. } else if (type == 3) {
  59. // btHelper.stopSearch()
  60. }
  61. ///4G模式
  62. else {
  63. }
  64. },
  65. async selectDeviceModelTap(e) {
  66. let device = e.currentTarget.dataset.device;
  67. // console.log(e)
  68. let type = device.type;
  69. if (type == 1) {
  70. // this.getConnectedDevices()
  71. } else if (type == 2) {
  72. } else if (type == 3) {
  73. // btHelper.stopSearch()
  74. } else {
  75. }
  76. var list = []
  77. list.push(device)
  78. this.data.typeList.forEach(element => {
  79. if (element.type != type) {
  80. list.push(element)
  81. }
  82. });
  83. this.setData({
  84. typeList: list,
  85. model: this.getModeName(device)
  86. })
  87. },
  88. nullTips() {
  89. if (this.data.typeList.length === 0) {
  90. wx.showToast({
  91. title: '暂不支持该设备配网',
  92. icon: 'none',
  93. })
  94. return true
  95. }
  96. return false
  97. },
  98. onLoad: function (options) {
  99. let device = JSON.parse(options.param) || {}
  100. console.log("配网配对的设备:", device)
  101. if (Object.keys(device).length === 0) {
  102. wx.showToast({
  103. title: '设备数据为空,返回刷新列表试试看',
  104. })
  105. return;
  106. }
  107. let _this = this
  108. let isWifi = device.clientType != "MW-S2";
  109. let isS2 = device.clientType === "MW-S2";
  110. let _typeList = device.typeList
  111. .filter(e => (isWifi && e.type == 2) || isS2)
  112. .map(e => ({
  113. icon: "../../../images/device/mode_" + e.type + ".png",
  114. text: _this.getModeName(e),
  115. type: e.type
  116. }));
  117. var list = []
  118. this.data.typeList.forEach(element => {
  119. if (_typeList.find(_type => _type.type === element.type)) {
  120. list.push(element)
  121. }
  122. });
  123. this.setData({
  124. typeList: list,
  125. connectDevice: device
  126. })
  127. this.nullTips()
  128. },
  129. })