wifi.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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:true,
  38. wifiList:[],
  39. myWifi:''
  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. this.dealWifi(true)
  54. },
  55. methods:{
  56. getCurrentWifi(){
  57. let that = this;
  58. wx.startWifi({
  59. success(res){
  60. wx.getConnectedWifi({
  61. success(res){
  62. if(res.errCode===0){
  63. that.myWifi = res.wifi?.SSID;
  64. }
  65. },
  66. fail: (err) => {
  67. if(err.errMsg.indexOf('getConnectedWifi:fail:wifi is disable')>-1) that.$showToast('WiFi未开启')
  68. }
  69. })
  70. }
  71. })
  72. },
  73. dealWifi(flag){
  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. })
  99. }
  100. })
  101. }else{
  102. this.wifiList = [];
  103. }
  104. },
  105. toSet(item){
  106. let that = this;
  107. if(item.SSID.indexOf('Xiaozhi-')>-1){
  108. uni.connectWifi({
  109. SSID: item.SSID,
  110. password: '',
  111. success: (resu) => {
  112. if(resu.errCode===0){
  113. setTimeout(()=>{
  114. uni.navigateTo({
  115. url:'/pagesMy/wifiSet'
  116. })
  117. },2000)
  118. }
  119. }
  120. });
  121. }else this.$showToast('请选择Xiaozhi开头的热点')
  122. }
  123. }
  124. }
  125. </script>
  126. <style scoped lang="less">
  127. .page{
  128. background: #FFFFFF;
  129. padding: 0 31rpx 30rpx;
  130. box-sizing: border-box;
  131. .box{
  132. width: 100%;
  133. padding: 50rpx 30rpx 0;
  134. box-sizing: border-box;
  135. background: #FFFFFF;
  136. .info{
  137. margin-bottom: 60rpx;
  138. image{
  139. width: 114rpx;
  140. height: 114rpx;
  141. }
  142. text{
  143. font-family: PingFang-SC, PingFang-SC;
  144. font-weight: bold;
  145. font-size: 40rpx;
  146. color: #111111;
  147. line-height: 40rpx;
  148. margin-top: 20rpx;
  149. }
  150. p{
  151. font-family: PingFang-SC, PingFang-SC;
  152. font-weight: 400;
  153. font-size: 34rpx;
  154. color: #111111;
  155. line-height: 40rpx;
  156. text-align: center;
  157. margin-top: 20rpx;
  158. }
  159. }
  160. .pre{
  161. padding: 20rpx 30rpx;
  162. border-top:1rpx solid #E5E5E5;
  163. .p_l{
  164. font-family: PingFang-SC, PingFang-SC;
  165. font-weight: 400;
  166. font-size: 32rpx;
  167. color: #111111;
  168. line-height: 40rpx;
  169. display: flex;
  170. flex-direction: column;
  171. span{
  172. font-size: 26rpx;
  173. }
  174. }
  175. }
  176. .title{
  177. color: #666666;
  178. margin-bottom: 40rpx;
  179. }
  180. }
  181. }
  182. </style>