wifiSet.vue 7.1 KB

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