deviceConnect1.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. isIOS: false,
  12. ssid: "",
  13. pwdData: "",
  14. connectDevice: "",
  15. is5gDevice: false,
  16. },
  17. onLoad(options) {
  18. var that = this;
  19. var param = options.param;
  20. that.data.connectDevice = param;
  21. var device = JSON.parse(param);
  22. var typeList = device.typeList;
  23. if (!constant.strings.isEmpty(typeList)) {
  24. var targetList = typeList.filter((v) => v.connectType == 3);
  25. if (!constant.strings.isEmpty(targetList)) {
  26. /// 字段,含义为是否支持5G:1-是 0-否;
  27. var is5g = targetList[0].is5g;
  28. if (is5g == 1) {
  29. that.setData({
  30. is5gDevice: true,
  31. });
  32. }
  33. }
  34. }
  35. const res = wx.getSystemInfoSync(); // 获取系统信息
  36. /// android ios
  37. const platform = res.platform; // 获取平台类型
  38. this.setData({
  39. isIOS: platform === 'ios',
  40. isShowPwd: true,
  41. });
  42. },
  43. onShow() {
  44. var that = this;
  45. that.getWifiStatus();
  46. },
  47. getBluetoothStatus() {
  48. constant.app.getBluetoothStatus();
  49. },
  50. ///Wifi名称
  51. setSsid: function (e) {
  52. var that = this;
  53. let str = false;
  54. if (e.detail.value.indexOf("5G") !== -1) {
  55. str = true;
  56. };
  57. that.setData({
  58. ssid: e.detail.value,
  59. is5GWifi: str
  60. });
  61. },
  62. onFocus(event) {
  63. console.log("onFocus:", event)
  64. if (event.detail.value !== this.data.pwdData) {
  65. this.setPwd(event);
  66. }
  67. },
  68. ///Wifi名称
  69. setPwd: function (e) {
  70. console.log("设置密码:", e.detail.value)
  71. var that = this;
  72. that.setData({
  73. pwdData: e.detail.value,
  74. });
  75. },
  76. ///获取网络状态
  77. getWifiStatus() {
  78. var that = this;
  79. wx.getNetworkType({
  80. success(res) {
  81. if (res.networkType === "wifi") {
  82. wx.startWifi({
  83. success(res) {
  84. //获取当前已连接wifi名
  85. wx.getConnectedWifi({
  86. success: function (res) {
  87. var ssid = res.wifi.SSID;
  88. // 5Gwifi
  89. if (res.wifi.SSID.indexOf("5G") !== -1) {
  90. that.setData({
  91. is5GWifi: true,
  92. ssid: ssid,
  93. });
  94. } else {
  95. that.setData({
  96. is5GWifi: false,
  97. ssid: ssid,
  98. });
  99. };
  100. constant.app.globalData.ssid = ssid;
  101. wx.getStorage({
  102. key: 'wifiInfo',
  103. success(wifiRes) {
  104. console.log("wifiInfo:", wifiRes)
  105. const resData = JSON.parse(wifiRes.data ?? "{}") ?? {};
  106. console.log("wifiInfo2:", resData)
  107. if (resData.ssid === res.wifi.SSID) {
  108. that.setData({
  109. pwdData: resData.password ?? "",
  110. });
  111. }
  112. }
  113. })
  114. },
  115. })
  116. }
  117. })
  118. }
  119. }
  120. })
  121. },
  122. ///下一步
  123. next() {
  124. var that = this;
  125. if (that.data.ssid === "") {
  126. wx.showToast({
  127. title: '请输入WIFI名称',
  128. icon: 'none',
  129. duration: 2000
  130. })
  131. return;
  132. };
  133. if (that.data.pwdData === "") {
  134. wx.showToast({
  135. title: '请输入WIFI密码',
  136. icon: 'none',
  137. duration: 2000
  138. })
  139. return;
  140. };
  141. constant.app.globalData.ssid = that.data.ssid;
  142. constant.app.globalData.pwdData = that.data.pwdData;
  143. var param = "?param=" + that.data.connectDevice;
  144. constant.routeUtil.jumpParam(constant.routePath.deviceConnect2, param);
  145. },
  146. notRoter() {
  147. wx.navigateBack({
  148. delta: 1
  149. });
  150. },
  151. showPwd() {
  152. var that = this;
  153. that.setData({
  154. isShowPwd: !that.data.isShowPwd
  155. })
  156. },
  157. onUnload: function () {
  158. var that = this;
  159. },
  160. })