deviceConnect1.js 2.8 KB

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