wifi.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/f1cc6aee-2d47-46f0-ae29-3ef4923777cb.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. onShow() {
  56. let sysInfo = wx.getSystemInfoSync();
  57. console.log(sysInfo,'sysInfo');
  58. let platform = sysInfo.platform;
  59. console.log(platform,'platform');
  60. if(platform == "ios"){
  61. wx.onGetWifiList(res => {
  62. console.log(res,'res:onShow');
  63. })
  64. }
  65. },
  66. methods:{
  67. getCurrentWifi(){
  68. let that = this;
  69. wx.startWifi({
  70. success(res){
  71. wx.getConnectedWifi({
  72. success(res){
  73. if(res.errCode===0){
  74. that.myWifi = res.wifi?.SSID;
  75. }
  76. },
  77. fail: (err) => {
  78. if(err.errMsg.indexOf('getConnectedWifi:fail:wifi is disable')>-1) that.$showToast('WiFi未开启')
  79. }
  80. })
  81. }
  82. })
  83. },
  84. dealWifi(flag){
  85. let that = this;
  86. if(flag){
  87. uni.showLoading({
  88. title:'获取WiFi列表中'
  89. })
  90. wx.startWifi({
  91. success (res) {
  92. console.log(res,'res');
  93. wx.getWifiList({
  94. success(res2) {
  95. console.log(res2,'res2');
  96. wx.onGetWifiList(res3 => {
  97. let temp = [];
  98. console.log(res3,'res3');
  99. console.log(res3.wifiList,'res3.wifiList');
  100. res3.wifiList.forEach(w=>{
  101. if(w.SSID){
  102. let exit = temp.find(t=>t.SSID===w.SSID);
  103. if(!exit) temp = [...temp,w]
  104. }
  105. })
  106. that.$nextTick(()=>{
  107. that.wifiList = temp;
  108. that.$forceUpdate();
  109. uni.hideLoading();
  110. })
  111. })
  112. },
  113. fail: (err2) => {
  114. console.log(err2,'err2');
  115. }
  116. })
  117. },
  118. fail: (err) => {
  119. console.log(err,'err');
  120. }
  121. })
  122. }else{
  123. this.wifiList = [];
  124. }
  125. },
  126. toSet(item){
  127. let that = this;
  128. if(item.SSID.indexOf('Xiaozhi-')>-1){
  129. uni.showLoading({
  130. title:'热点连接中'
  131. })
  132. wx.connectWifi({
  133. SSID: item.SSID,
  134. password: '',
  135. success: (resu) => {
  136. console.log(resu,'resu');
  137. uni.hideLoading();
  138. // if(resu.errCode===0||resu.errMsg==='connectWifi:ok'){
  139. setTimeout(()=>{
  140. uni.navigateTo({
  141. url:'/pagesMy/wifiSet'
  142. })
  143. },2000)
  144. // }
  145. },
  146. fail: (err) => {
  147. uni.hideLoading();
  148. console.log(err,'err:connectWifi');
  149. }
  150. });
  151. }else this.$showToast('请选择Xiaozhi开头的热点')
  152. }
  153. }
  154. }
  155. </script>
  156. <style scoped lang="less">
  157. .page{
  158. background: #FFFFFF;
  159. padding: 0 31rpx 30rpx;
  160. box-sizing: border-box;
  161. .box{
  162. width: 100%;
  163. padding: 50rpx 30rpx 0;
  164. box-sizing: border-box;
  165. background: #FFFFFF;
  166. .info{
  167. margin-bottom: 60rpx;
  168. image{
  169. width: 114rpx;
  170. height: 114rpx;
  171. }
  172. text{
  173. font-family: PingFang-SC, PingFang-SC;
  174. font-weight: bold;
  175. font-size: 40rpx;
  176. color: #111111;
  177. line-height: 40rpx;
  178. margin-top: 20rpx;
  179. }
  180. p{
  181. font-family: PingFang-SC, PingFang-SC;
  182. font-weight: 400;
  183. font-size: 34rpx;
  184. color: #111111;
  185. line-height: 40rpx;
  186. text-align: center;
  187. margin-top: 20rpx;
  188. }
  189. }
  190. .pre{
  191. padding: 20rpx 30rpx;
  192. border-top:1rpx solid #E5E5E5;
  193. .p_l{
  194. font-family: PingFang-SC, PingFang-SC;
  195. font-weight: 400;
  196. font-size: 32rpx;
  197. color: #111111;
  198. line-height: 40rpx;
  199. display: flex;
  200. flex-direction: column;
  201. span{
  202. font-size: 26rpx;
  203. }
  204. }
  205. }
  206. .title{
  207. color: #666666;
  208. margin-bottom: 40rpx;
  209. }
  210. }
  211. }
  212. </style>