deviceConnect1.js 3.8 KB

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