wifi.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='无线局域网' bgColor="transparent"></cus-header>
  4. <div class="box">
  5. <div class="info adffcacjc">
  6. <image src="http://106.54.209.120:8188/static/wifi.png"></image>
  7. <text>无线局域网</text>
  8. <p>接入无线局域网、查看可用网络,并管理加入网络及附近热点设置。</p>
  9. </div>
  10. <div class="pre adfacjb">
  11. <div class="p_l">无线局域网</div>
  12. <div class="p_r">
  13. <u-switch v-model="openWifi" size="46" activeColor="#5AC725"></u-switch>
  14. </div>
  15. </div>
  16. <div class="pre adfacjb" v-for="(item,index) in wifiList" :key="index" @tap="toSet(item)">
  17. <div class="p_l">
  18. <p>{{item.SSID}}</p>
  19. <span>{{item.secure?'高安全性':'低安全性'}}</span>
  20. </div>
  21. <div class="p_r"></div>
  22. </div>
  23. </div>
  24. <div class="box" v-if="myWifi">
  25. <div class="title">我的网络</div>
  26. <div class="pre adfacjb">
  27. <div class="p_l">{{myWifi}}</div>
  28. <div class="p_r"></div>
  29. </div>
  30. </div>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data(){
  36. return {
  37. openWifi:false,
  38. wifiList:[],
  39. myWifi:'111'
  40. }
  41. },
  42. watch:{
  43. openWifi:{
  44. handler(newval,oldval){
  45. if(newval!==oldval){
  46. this.dealWifi(newval)
  47. }
  48. }
  49. }
  50. },
  51. onLoad() {
  52. this.getCurrentWifi();
  53. },
  54. methods:{
  55. getCurrentWifi(){
  56. wx.startWifi({
  57. success(res){
  58. wx.getConnectedWifi({
  59. success(res){
  60. }
  61. })
  62. },
  63. fail: (err) => {
  64. console.log(err,'err');
  65. if(err.errMsg.indexOf('wifi is disable')>-1) that.$showToast('WiFi未开启')
  66. }
  67. })
  68. },
  69. dealWifi(flag){
  70. uni.navigateTo({
  71. url:'/pagesMy/wifiSet'
  72. })
  73. return
  74. let that = this;
  75. if(flag){
  76. uni.showLoading({
  77. title:'获取WiFi列表中'
  78. })
  79. wx.startWifi({
  80. success (res) {
  81. wx.getWifiList({
  82. success(res2) {
  83. wx.onGetWifiList(res3 => {
  84. let temp = [];
  85. res3.wifiList.forEach(w=>{
  86. if(w.SSID){
  87. let exit = temp.find(t=>t.SSID===w.SSID);
  88. if(!exit) temp = [...temp,w]
  89. }
  90. })
  91. that.$nextTick(()=>{
  92. that.wifiList = temp;
  93. that.$forceUpdate();
  94. uni.hideLoading();
  95. })
  96. })
  97. },
  98. fail(err) {
  99. console.log(err,'err')
  100. }
  101. })
  102. },
  103. fail: (err) => {
  104. console.log(err,'err');
  105. if(err.errMsg.indexOf('wifi is disable')>-1) that.$showToast('WiFi未开启')
  106. }
  107. })
  108. }else{
  109. this.wifiList = [];
  110. }
  111. },
  112. toSet(item){
  113. if(item.SSID.indexOf('Xiaozhi-')>-1){
  114. uni.connectWifi({
  115. SSID: item.SSID,
  116. password: '',
  117. success: (resu) => {
  118. console.log(resu,'resu');
  119. wx.request({
  120. url:'http://192.168.4.1/scan',
  121. success:res=>{
  122. console.log(res,'res');
  123. wx.request({
  124. url:'http://192.168.4.1/submit',
  125. method:'POST',
  126. data:{
  127. ssid:'传秀科技',
  128. password:'cx868688'
  129. },
  130. success:res2=>{
  131. console.log(res2,'res2');
  132. wx.request({
  133. url:'http://192.168.4.1/reboot',
  134. method:'POST',
  135. success:res3=>{
  136. console.log(res3,'res3');
  137. },
  138. fail:err3=>{
  139. console.log(err3,'err3');
  140. }
  141. })
  142. },
  143. fail:err2=>{
  144. console.log(err2,'err2');
  145. }
  146. })
  147. },
  148. fail:err=>{
  149. console.log(err,'err');
  150. }
  151. })
  152. // setTimeout(()=>{
  153. // uni.navigateTo({
  154. // url:'/pages/wifiSet'
  155. // })
  156. // },1500)
  157. },
  158. fail: (err) => {
  159. console.log(err,'err');
  160. }
  161. });
  162. }else this.$showToast('请选择Xiaozhi开头的热点')
  163. }
  164. }
  165. }
  166. </script>
  167. <style scoped lang="less">
  168. .page{
  169. background: #FFFFFF;
  170. padding: 0 31rpx 30rpx;
  171. box-sizing: border-box;
  172. .box{
  173. width: 100%;
  174. padding: 50rpx 30rpx 0;
  175. box-sizing: border-box;
  176. background: #FFFFFF;
  177. .info{
  178. margin-bottom: 60rpx;
  179. image{
  180. width: 114rpx;
  181. height: 114rpx;
  182. }
  183. text{
  184. font-family: PingFang-SC, PingFang-SC;
  185. font-weight: bold;
  186. font-size: 40rpx;
  187. color: #111111;
  188. line-height: 40rpx;
  189. margin-top: 20rpx;
  190. }
  191. p{
  192. font-family: PingFang-SC, PingFang-SC;
  193. font-weight: 400;
  194. font-size: 34rpx;
  195. color: #111111;
  196. line-height: 40rpx;
  197. text-align: center;
  198. margin-top: 20rpx;
  199. }
  200. }
  201. .pre{
  202. padding: 20rpx 30rpx;
  203. border-top:1rpx solid #E5E5E5;
  204. .p_l{
  205. font-family: PingFang-SC, PingFang-SC;
  206. font-weight: 400;
  207. font-size: 32rpx;
  208. color: #111111;
  209. line-height: 40rpx;
  210. display: flex;
  211. flex-direction: column;
  212. span{
  213. font-size: 26rpx;
  214. }
  215. }
  216. }
  217. .title{
  218. color: #666666;
  219. margin-bottom: 40rpx;
  220. }
  221. }
  222. }
  223. </style>