deviceConnect1.js 3.1 KB

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