uniapp 小程序获取WiFi列表

<template><view ><button @click="getWifiList">获取WiFi列表</button><scroll-view:scroll-top="scrollTop"scroll-yclass="content-pop"><viewclass="itemInfo"v-for="(item, index) in wifiList":key="index"><text>{{ item.SSID }}</text></view></scroll-view></view>
</template><script>export default {data() {return {wifiList: [],};},methods: {getWifiList() {// 获取手机型号const sys = uni.getSystemInfoSync();if (sys.platform == "android" && sys.parseInt(sys.system.substr(8) < 6) {this.$tip.error("手机版本不支持");return;}if (sys.platform == "ios" && sys.parseInt(sys.system.substr(4)) < 11.2) {this.$tip.error("手机版本不支持");return;}//初始wifi模块this.start_wifi();},start_wifi() {uni.startWifi({success: (res) => {this.getWifi();},fail: (err) => {this.$tip.toast("WIFI启动失败");},});},getWifi() {let that = this;uni.getWifiList({//成功后,就可以获取列表了success(res) {//列表获取成功后,要到事件里提取uni.onGetWifiList((res) => {that.onGetWifiListFun(res);});},fail(err) {console.log(err, "err");},});},// 监听获取到的WiFi列表函数 进行处理onGetWifiListFun(info) {this.wifiList = [];let wifiList = [];// 过滤掉没有SSID的 还有我个人对信号的处理,用来渲染对应的样式的wifiList = info.wifiList.filter((item) => {if (item.signalStrength >= -55) {item["signalDefine"] = [true, true, true];} else if (item.signalStrength >= -66) {item["signalDefine"] = [false, true, true];} else if (item.signalStrength >= -88) {item["signalDefine"] = [false, false, true];} else if (item.signalStrength >= -100) {item["signalDefine"] = [false, false, false];}return item.SSID;});// 按信号强度排序wifiList = wifiList.sort((a, b) => {return b.signalStrength - a.signalStrength;});// 取当前连接的WiFi的信号const connectResIndex = wifiList.findIndex((item) => item.SSID === this.connectWifi);const connectRes = wifiList[connectResIndex];if (connectRes) {this.connectWifiSignal = connectRes["signalDefine"];this.connectRes = connectRes;}wifiList.splice(connectResIndex, 1);this.wifiList = this.uniqueByField(wifiList, "SSID");this.$tip.loaded();},uniqueByField(list, field) {const seen = new Set();const result = [];for (let item of list) {const value = item[field];if (!seen.has(value)) {seen.add(value);result.push(item);}}return result;},},};
</script><style scoped>.itemInfo {height: 96rpx;line-height: 96rpx;font-size: 28rpx;border-bottom: 1rpx solid #f4f4f4;text-align: left;} .content-pop {width: 100vw;max-height: 55vh;padding: 0 30rpx;}
</style>

   提示:iphone刷新会跳转至手机wifi设置中连接网络

使用方法:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/611243.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

JetBrains RubyMine 2024.1 发布 - 最智能的 Ruby 与 Rails IDE

JetBrains RubyMine 2024.1 发布 - 最智能的 Ruby 与 Rails IDE 请访问原文链接&#xff1a;JetBrains RubyMine 2024.1 (macOS, Linux, Windows) - 最智能的 Ruby 与 Rails IDE&#xff0c;查看最新版。原创作品&#xff0c;转载请保留出处。 作者主页&#xff1a;sysin.org…

Excel·VBA二维数组S形排列

与之前的文章《ExcelVBA螺旋数组函数》将一维数组转为二维螺旋数组 本文将数组转为S形排列的二维数组&#xff0c;类似考场座位S形顺序 Function S形排列(ByVal arr, ByVal num_rows&, ByVal num_cols&, Optional ByVal mode$ "row")将数组arr转为num_rows…

跟TED演讲学英文:The inside story of ChatGPT‘s astonishing potential by Greg Brockman

The inside story of ChatGPT’s astonishing potential Link: https://www.ted.com/talks/greg_brockman_the_inside_story_of_chatgpt_s_astonishing_potential Speaker: Greg Brockman Date:April 2023 文章目录 The inside story of ChatGPTs astonishing potentialIntro…

Linux/October

October Enumeration Nmap 扫描发现对外开放了22和80端口&#xff0c;使用nmap详细扫描这两个端口 ┌──(kali㉿kali)-[~/vegetable/HTB/October] └─$ nmap -sC -sV -p 22,80 -oA nmap 10.10.10.16 Starting Nmap 7.…

Unity Shader之数学篇

一、坐标系 1、二维笛卡尔坐标系 屏幕坐标系是二维笛卡尔坐标系&#xff0c;OpenGL的屏幕坐标系原点在左下角&#xff0c;DirectX的屏幕坐标系原点在左上角。 2、三维笛卡尔坐标系 三维笛卡尔坐标系要区分是左手坐标系还是右手坐标系。 左手坐标系&#xff1a;举起你的左手…

ELK日志

​​​​​​​

2024年租用阿里云服务器多少钱?最新价格表

阿里云服务器租用价格表2024年最新&#xff0c;云服务器ECS经济型e实例2核2G、3M固定带宽99元一年&#xff0c;轻量应用服务器2核2G3M带宽轻量服务器一年61元&#xff0c;ECS u1服务器2核4G5M固定带宽199元一年&#xff0c;2核4G4M带宽轻量服务器一年165元12个月&#xff0c;2核…

物联网实战--驱动篇之(七)RTC时钟(DS1302)

目录 一、RTC简介 二、DS1302介绍 三、初始化 四、字节读写 五、功能函数 一、RTC简介 实时时钟&#xff0c;简称RTC&#xff0c;这个在STM32的外设里也有&#xff0c;不过STM32F1系列的RTC实际上只有一个计数器功能&#xff0c;如果需要年月日要自己写软件计算 &#xff…

转行项目经理,考软考还是PMP?

这两者择其一&#xff0c;或者有条件的两个都可以考虑一下&#xff0c;因为国内对这两个证书的需求都很大。 从企业环境来看 PMP适用于各行各业&#xff0c;在外企更受欢迎。 软考适用于计算机领域&#xff0c;而且在国企和政府部门比较受欢迎。 因此&#xff0c;可以综合考…

Github 2024-04-12 Java开源项目日报Top9

根据Github Trendings的统计,今日(2024-04-12统计)共有9个项目上榜。根据开发语言中项目的数量,汇总情况如下: 开发语言项目数量Java项目9TypeScript项目3强大易用的开源建站工具 创建周期:2214 天开发语言:Java, TypeScript协议类型:GNU General Public License v3.0Sta…

集群开发学习(一)(安装GO和MySQL,K8S基础概念)

完成gin小任务 参考文档&#xff1a; https://www.kancloud.cn/jiajunxi/ginweb100/1801414 https://github.com/hanjialeOK/going 最终代码地址&#xff1a;https://github.com/qinliangql/gin_mini_test.git 学习 1.安装go wget https://dl.google.com/go/go1.20.2.linu…

第6章 6.3.1 正则表达式的语法(MATLAB入门课程)

讲解视频&#xff1a;可以在bilibili搜索《MATLAB教程新手入门篇——数学建模清风主讲》。​ MATLAB教程新手入门篇&#xff08;数学建模清风主讲&#xff0c;适合零基础同学观看&#xff09;_哔哩哔哩_bilibili 正则表达式可以由一般的字符、转义字符、元字符、限定符等元素组…