deviceConnect1.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. const constant = require('../../../utils/constant.js');
  2. Page({
  3. data: {
  4. nvabarData: {
  5. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  6. title: '设置网络', //导航栏 中间的标题
  7. },
  8. scopeBluetooth: constant.app.globalData.scopeBluetooth,
  9. isShowPwd: false,
  10. is5GWifi: false,
  11. ssid: "",
  12. pwdData: "",
  13. connectDevice: "",
  14. },
  15. onLoad(options) {
  16. var that = this;
  17. var param = options.param;
  18. that.data.connectDevice = param;
  19. },
  20. onShow() {
  21. var that = this;
  22. that.getWifiStatus();
  23. },
  24. getBluetoothStatus() {
  25. constant.app.getBluetoothStatus();
  26. },
  27. ///Wifi名称
  28. setSsid: function (e) {
  29. var that = this;
  30. let str = false;
  31. if (e.detail.value.indexOf("5G") !== -1) {
  32. str = true;
  33. };
  34. that.setData({
  35. ssid: e.detail.value,
  36. is5GWifi: str
  37. });
  38. },
  39. onFocus(event) {
  40. console.log("onFocus:", event)
  41. if (event.detail.value !== this.data.pwdData) {
  42. this.setPwd(event);
  43. }
  44. },
  45. onBlur(event) {
  46. console.log("onBlur", event)
  47. if (event.detail.value !== this.data.pwdData) {
  48. this.setPwd(event);
  49. }
  50. },
  51. ///Wifi名称
  52. setPwd: function (e) {
  53. console.log("设置密码:", e.detail.value)
  54. var that = this;
  55. constant.app.globalData.pwdData = e.detail.value;
  56. that.setData({
  57. pwdData: e.detail.value,
  58. });
  59. },
  60. ///获取网络状态
  61. getWifiStatus() {
  62. var that = this;
  63. wx.getNetworkType({
  64. success(res) {
  65. if (res.networkType === "wifi") {
  66. wx.startWifi({
  67. success(res) {
  68. //获取当前已连接wifi名
  69. wx.getConnectedWifi({
  70. success: function (res) {
  71. var ssid = res.wifi.SSID;
  72. // 5Gwifi
  73. if (res.wifi.SSID.indexOf("5G") !== -1) {
  74. that.setData({
  75. is5GWifi: true,
  76. ssid: ssid,
  77. });
  78. } else {
  79. that.setData({
  80. is5GWifi: false,
  81. ssid: ssid,
  82. });
  83. };
  84. constant.app.globalData.ssid = ssid;
  85. wx.getStorage({
  86. key: 'wifiInfo',
  87. success(wifiRes) {
  88. console.log("wifiInfo:", wifiRes)
  89. const resData = JSON.parse(wifiRes.data ?? "{}") ?? {};
  90. console.log("wifiInfo2:", resData)
  91. if (resData.ssid === res.wifi.SSID) {
  92. that.setData({
  93. pwdData: resData.password ?? "",
  94. });
  95. }
  96. }
  97. })
  98. },
  99. })
  100. }
  101. })
  102. }
  103. }
  104. })
  105. },
  106. ///下一步
  107. next() {
  108. var that = this;
  109. if (that.data.ssid === "") {
  110. wx.showToast({
  111. title: '请输入WIFI名称',
  112. icon: 'none',
  113. duration: 2000
  114. })
  115. return;
  116. };
  117. // if (that.data.pwdData === "") {
  118. // wx.showToast({
  119. // title: '请输入WIFI密码',
  120. // icon: 'none',
  121. // duration: 2000
  122. // })
  123. // return;
  124. // };
  125. constant.app.globalData.ssid = that.data.ssid;
  126. constant.app.globalData.pwdData = that.data.pwdData;
  127. var param = "?param=" + that.data.connectDevice;
  128. constant.routeUtil.jumpParam(constant.routePath.deviceConnect2, param);
  129. },
  130. notRoter() {
  131. wx.navigateBack({
  132. delta: 1
  133. });
  134. },
  135. showPwd() {
  136. var that = this;
  137. that.setData({
  138. isShowPwd: !that.data.isShowPwd
  139. })
  140. },
  141. })