index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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: 0,
  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.deviceMode == 4) {
  41. str = "移动数据模式";
  42. } else if (curItem.deviceMode == 2) {
  43. str = "WiFi模式";
  44. } else if (curItem.deviceMode == 1) {
  45. str = "蓝牙模式";
  46. }
  47. return str;
  48. },
  49. nextTap(e) {
  50. let device = this.data.typeList[0];
  51. let type = device.type ?? 0;
  52. console.log("选择模式", type)
  53. ///蓝牙模式
  54. if (type == 1) {
  55. // let device = e.currentTarget.dataset.data
  56. let json = JSON.stringify(this.data.connectDevice)
  57. routeUtil.jumpParam(route_constant.connectBle, json)
  58. // wx.navigateTo({
  59. // url: './../deviceDetail/detail',
  60. // });
  61. }
  62. ///Wifi模式
  63. else if (type == 2) {
  64. wx.navigateTo({
  65. url: './../deviceConnect0/deviceConnect0',
  66. });
  67. } else if (type == 3) {
  68. // btHelper.stopSearch()
  69. }
  70. ///4G模式
  71. else {
  72. }
  73. },
  74. async selectDeviceModelTap(e) {
  75. let device = e.currentTarget.dataset.device;
  76. // console.log(e)
  77. let type = device.type;
  78. if (type == 1) {
  79. // this.getConnectedDevices()
  80. } else if (type == 2) {
  81. } else if (type == 3) {
  82. // btHelper.stopSearch()
  83. } else {
  84. }
  85. var list = []
  86. list.push(device)
  87. this.data.typeList.forEach(element => {
  88. if (element.type != type) {
  89. list.push(element)
  90. }
  91. });
  92. this.setData({
  93. typeList: list,
  94. })
  95. },
  96. onLoad: function (options) {
  97. let json = JSON.parse(options.param) || {}
  98. console.log(json)
  99. let device = json
  100. if (Object.keys(device).length === 0) {
  101. wx.showToast({
  102. title: '设备数据为空,返回刷新列表试试看',
  103. })
  104. return;
  105. }
  106. var list = []
  107. var typeList = device.typeList.map(element => {
  108. return element.connectType;
  109. });
  110. this.data.typeList.forEach(element => {
  111. if (typeList.find(type => type === element.type)) {
  112. list.push(element)
  113. }
  114. });
  115. this.setData({
  116. typeList: list,
  117. connectDevice: device
  118. })
  119. },
  120. })