wifiSet.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='配置网络'></cus-header>
  4. <div class="title">选择设备要加入的Wi-Fi</div>
  5. <div class="tip">设备仅支持使用2.4Hz Wi-Fi连接使用</div>
  6. <div class="items">
  7. <div class="item adfacjb">
  8. <div class="il">
  9. <input type="text" v-model="wifiSSID" placeholder="网络名称" placeholder-class="ph">
  10. </div>
  11. <div class="ir" @tap="toSelectWifi">选择Wi-Fi</div>
  12. </div>
  13. <div class="item adfacjb">
  14. <div class="il">
  15. <input :password="isPwd" v-model="wifiPWD" placeholder="请输入Wi-Fi密码" placeholder-class="ph">
  16. </div>
  17. <div class="iimgs">
  18. <image @tap="changePwd" src="@/static/pwd_hide.png" v-if="isPwd"></image>
  19. <image @tap="changePwd" src="@/static/pwd_show.png" v-else></image>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="zt_btn" @tap="connectWifi">连接</div>
  24. <div class="memo">
  25. <p>Wi-Fi密码名称和密码输入错误是最常见的失败原因之一,请仔细检查。</p>
  26. <p class="tip">密码必须至少包含8个字符</p>
  27. </div>
  28. <u-popup :show="show" :round="56" mode="center" @close="show=false">
  29. <div class="wifis">
  30. <div class="top adfacjb">
  31. <div class="tl">选择WiFi</div>
  32. <div class="tr adfac" @tap="initWiFi">
  33. <image src="@/static/refreash.png"></image>
  34. <text>刷新</text>
  35. </div>
  36. </div>
  37. <div class="list" v-if="wifiList.length">
  38. <div class="item adfacjb" v-for="(item,index) in wifiList" :key="index">
  39. <div class="il adfac">
  40. <image src="@/static/wifi.png"></image>
  41. <text>{{item.ssid}}</text>
  42. </div>
  43. <div class="ir" @tap="selectWifi(item)">选择</div>
  44. </div>
  45. </div>
  46. <template v-else>
  47. <page-empty></page-empty>
  48. </template>
  49. </div>
  50. </u-popup>
  51. </view>
  52. </template>
  53. <script>
  54. import pageEmpty from '@/components/pageEmpty/index.vue'
  55. export default {
  56. components:{pageEmpty},
  57. data(){
  58. return {
  59. wifiSSID:'',
  60. wifiPWD:'',
  61. isPwd:true,
  62. show:false,
  63. wifiList:[]
  64. }
  65. },
  66. methods:{
  67. changePwd(){
  68. this.isPwd = !this.isPwd;
  69. },
  70. connectWifi(){
  71. if(!this.wifiSSID) return this.$showToast('请选择Wi-Fi')
  72. if(!this.wifiPWD) return this.$showToast('请输入Wi-Fi密码')
  73. uni.navigateTo({
  74. url:`/pagesMy/wifiConnect?wifiSSID=${this.wifiSSID}&wifiPWD=${this.wifiPWD}`
  75. })
  76. },
  77. toSelectWifi(){
  78. this.show = true;
  79. this.initWiFi();
  80. },
  81. initWiFi(){
  82. uni.showLoading({
  83. title:'获取WiFi列表中'
  84. })
  85. let that = this;
  86. wx.request({
  87. url:'http://192.168.4.1/scan',
  88. success:res=>{
  89. uni.hideLoading();
  90. if(res.errMsg==='request:ok'){
  91. let temp = [];
  92. res.data.forEach(w=>{
  93. if(w.ssid&&w.ssid.indexOf('Xiaozhi')<0){
  94. let exit = temp.find(t=>t.ssid===w.ssid);
  95. if(!exit) temp = [...temp,w]
  96. }
  97. })
  98. that.$nextTick(()=>{
  99. that.wifiList = temp;
  100. that.$forceUpdate();
  101. uni.hideLoading();
  102. })
  103. }
  104. },
  105. fail:err=>{
  106. uni.hideLoading();
  107. }
  108. })
  109. },
  110. selectWifi(item){
  111. this.wifiSSID = item.ssid;
  112. this.show = false;
  113. }
  114. }
  115. }
  116. </script>
  117. <style scoped lang="less">
  118. .page{
  119. padding: 0 40rpx 250rpx;
  120. box-sizing: border-box;
  121. background: #FFFFFF;
  122. &>.title{
  123. font-family: PingFang-SC, PingFang-SC;
  124. font-weight: bold;
  125. font-size: 36rpx;
  126. color: #111111;
  127. line-height: 36rpx;
  128. margin-top: 64rpx;
  129. }
  130. &>.tip{
  131. font-family: PingFangSC, PingFang SC;
  132. font-weight: 400;
  133. font-size: 26rpx;
  134. color: #111111;
  135. line-height: 32rpx;
  136. margin-top: 36rpx;
  137. }
  138. .items{
  139. margin-top: 96rpx;
  140. .item{
  141. margin-top: 80rpx;
  142. padding-bottom: 30rpx;
  143. border-bottom: 1rpx solid #E2E2E2;
  144. .il{
  145. width: calc(100% - 180rpx);
  146. input{
  147. border: none;
  148. font-family: PingFangSC, PingFang SC;
  149. font-weight: 400;
  150. font-size: 28rpx;
  151. color: #333333;
  152. line-height: 42rpx;
  153. }
  154. }
  155. .ir{
  156. width: 160rpx;
  157. height: 64rpx;
  158. background: #D9F159;
  159. border-radius: 32rpx;
  160. font-family: PingFang-SC, PingFang-SC;
  161. font-weight: bold;
  162. font-size: 26rpx;
  163. color: #252525;
  164. line-height: 64rpx;
  165. text-align: center;
  166. }
  167. .iimgs{
  168. image{
  169. width: 36rpx;
  170. height: 36rpx;
  171. }
  172. }
  173. }
  174. }
  175. .zt_btn{
  176. margin-top: 100rpx;
  177. }
  178. .memo{
  179. width: calc(100% - 80rpx);
  180. position: fixed;
  181. left: 40rpx;
  182. bottom: 100rpx;
  183. p{
  184. font-family: PingFangSC, PingFang SC;
  185. font-weight: 600;
  186. font-size: 26rpx;
  187. color: #111111;
  188. line-height: 40rpx;
  189. &.tip{
  190. font-weight: 400;
  191. color: #7C8592;
  192. line-height: 42rpx;
  193. margin-top: 8rpx;
  194. }
  195. }
  196. }
  197. .ph{
  198. color: #7C8592;
  199. }
  200. .wifis{
  201. width: 670rpx;
  202. max-height: 740rpx;
  203. overflow: hidden;
  204. .top{
  205. margin-top: 14rpx;
  206. padding: 40rpx;
  207. border-bottom: 1rpx solid #E2E2E2;
  208. .tl{
  209. font-family: PingFang-SC, PingFang-SC;
  210. font-weight: bold;
  211. font-size: 36rpx;
  212. color: #111111;
  213. line-height: 36rpx;
  214. }
  215. .tr{
  216. image{
  217. width: 36rpx;
  218. height: 36rpx;
  219. }
  220. text{
  221. font-family: PingFangSC, PingFang SC;
  222. font-weight: 400;
  223. font-size: 32rpx;
  224. color: #7C8592;
  225. line-height: 36rpx;
  226. margin-left: 10rpx;
  227. }
  228. }
  229. }
  230. .list{
  231. height: 609rpx;
  232. overflow-y: auto;
  233. padding: 30rpx 40rpx;
  234. .item{
  235. width: 100%;
  236. height: 120rpx;
  237. border-radius: 16rpx;
  238. border: 1rpx solid #E2E2E2;
  239. margin-top: 20rpx;
  240. padding: 0 24rpx;
  241. box-sizing: border-box;
  242. &:first-child{
  243. margin-top: 0;
  244. }
  245. .il{
  246. width: calc(100% - 134rpx);
  247. image{
  248. width: 42rpx;
  249. height: 42rpx;
  250. }
  251. text{
  252. font-family: PingFangSC, PingFang SC;
  253. font-weight: 400;
  254. font-size: 30rpx;
  255. color: #252525;
  256. line-height: 30rpx;
  257. margin-left: 20rpx;
  258. width: calc(100% - 62rpx);
  259. overflow: hidden;
  260. text-overflow: ellipsis;
  261. white-space: nowrap;
  262. }
  263. }
  264. .ir{
  265. width: 114rpx;
  266. height: 60rpx;
  267. background: #D9F159;
  268. border-radius: 32rpx;
  269. font-family: PingFangSC, PingFang SC;
  270. font-weight: 400;
  271. font-size: 28rpx;
  272. color: #252525;
  273. line-height: 60rpx;
  274. text-align: center;
  275. }
  276. }
  277. }
  278. }
  279. }
  280. </style>