deviceConnect1.js 3.1 KB

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