deviceConnect1.js 2.9 KB

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