123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <template>
- <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
- <cus-header title='WiFi配置' bgColor="transparent"></cus-header>
- <div class="box">
- <div class="b_top adffcacjc">
- <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/f1cc6aee-2d47-46f0-ae29-3ef4923777cb.png"></image>
- <text>WiFi配置</text>
- </div>
- <div class="b_pre">
- <div class="bp_text">SSID:</div>
- <div class="bp_inp">
- <input type="text" v-model="wifiSSID">
- </div>
- </div>
- <div class="b_pre">
- <div class="bp_text">密码:</div>
- <div class="bp_inp">
- <input type="password" v-model="wifiPwd">
- </div>
- </div>
- <div class="zt_btn" @tap="toConnectWiFi">连接</div>
- </div>
- <div class="box">
- <div class="b_title">从下面列表选择2.4GWiFi:</div>
- <div class="b_wifi adfac" v-for="(item,index) in wifi2gList" :key="index" @tap="toCode(item)">
- <text>{{item.ssid}}</text>
- <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/c303f95d-ecd9-449e-bdc6-fc79a54de338.png"></image>
- </div>
- </div>
- <u-popup :show="show" mode="center" @close="close">
- <div class="fail_box adffcacjc">
- <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/f62889e7-ebdd-4351-b4b2-d6d82070d202.png"></image>
- <text>网络连接失败</text>
- <p>请检查你的网络设置或密码后刷新</p>
- <div class="zt_btn" @tap="toTryAgain">重试</div>
- </div>
- </u-popup>
- </view>
- </template>
- <script>
- export default {
- data(){
- return {
- wifiSSID:'',
- wifiPwd:'',
- wifi2gList:[],
- show:false,
- tcp:'',
- flag:true
- }
- },
- onLoad() {
- this.initWiFi();
- },
- methods:{
- initWiFi(){
- uni.showLoading({
- title:'获取WiFi列表中'
- })
- let that = this;
- wx.request({
- url:'http://192.168.4.1/scan',
- success:res=>{
- console.log(res,'res');
- uni.hideLoading();
- if(res.errMsg==='request:ok'){
- let temp = [];
- res.data.forEach(w=>{
- if(w.ssid&&w.ssid.indexOf('Xiaozhi')<0){
- let exit = temp.find(t=>t.ssid===w.ssid);
- if(!exit) temp = [...temp,w]
- }
- })
- that.$nextTick(()=>{
- that.wifi2gList = temp;
- that.$forceUpdate();
- uni.hideLoading();
- })
- }
- },
- fail:err=>{
- uni.hideLoading();
- }
- })
- },
- toConnectWiFi(){
- if(!this.wifiSSID) return this.$showToast('请从下方选择一个wifi进行连接')
- if(!this.wifiPwd) return this.$showToast('请输入密码')
- if(!this.flag) return
- this.flag = false;
- uni.showLoading({
- title:'联网中...'
- })
- let that = this;
- wx.request({
- url:'http://192.168.4.1/submit',
- method:'POST',
- data:{
- ssid:this.wifiSSID,
- password:this.wifiPwd
- },
- success:res2=>{
- console.log(res2,'res2');
- if(res2.errMsg!=='request:ok'||!res2.data.success){
- uni.hideLoading();
- that.show = true;
- that.flag = true;
- return
- }
- wx.request({
- url:'http://192.168.4.1/reboot',
- method:'POST',
- success:res3=>{
- if(res3.errMsg!=='request:ok'){
- that.$showToast('设备重启失败')
- return
- }
- that.flag = true;
- uni.hideLoading();
- setTimeout(()=>{
- uni.navigateTo({
- url:'/pagesMy/wifiSuccess'
- })
- },2000)
- },
- fail:err3=>{
- console.log(err3,'err3');
- that.flag = true;
- that.$showModal(JSON.stringify(err3));
- uni.hideLoading();
- }
- })
- },
- fail:err2=>{
- console.log(err2,'err2');
- that.flag = true;
- that.$showModal(JSON.stringify(err2));
- uni.hideLoading();
- }
- })
- },
- close(){
- this.show = false;
- },
- toCode(item){
- this.wifiSSID = item.ssid;
- },
- toTryAgain(){
- this.show = false;
- this.flag = true;
- this.toConnectWiFi();
- }
- }
- }
- </script>
- <style scoped lang="less">
- .page{
- background: #F7F7F7;
- padding: 0 30rpx 30rpx;
- box-sizing: border-box;
- .box{
- background: #FFFFFF;
- border-radius: 16rpx;
- padding: 40rpx 30rpx;
- margin-top: 20rpx;
- .b_top{
- image{
- width: 114rpx;
- height: 114rpx;
- }
- text{
- font-family: PingFang-SC, PingFang-SC;
- font-weight: bold;
- font-size: 40rpx;
- color: #111111;
- line-height: 40rpx;
- text-align: center;
- margin-top: 30rpx;
- }
- }
- .b_pre{
- margin-top: 40rpx;
- .bp_text{
- font-family: PingFang-SC, PingFang-SC;
- font-weight: bold;
- font-size: 30rpx;
- color: #111111;
- line-height: 32rpx;
- }
- .bp_inp{
- width: 100%;
- height: 90rpx;
- border-radius: 16rpx;
- border: 1rpx solid #E2E2E2;
- margin-top: 24rpx;
- padding: 24rpx 40rpx;
- box-sizing: border-box;
- input{
- border: none;
- }
- }
- }
- .zt_btn{
- margin-top: 40rpx;
- }
-
- .b_title{
- font-family: PingFang-SC, PingFang-SC;
- font-weight: bold;
- font-size: 32rpx;
- color: #111111;
- line-height: 45rpx;
- }
- .b_wifi{
- margin-top: 48rpx;
- text{
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 30rpx;
- color: #0066FE;
- line-height: 30rpx;
- }
- image{
- width: 36rpx;
- height: 36rpx;
- margin-left: 10rpx;
- }
- }
- }
-
- .fail_box{
- width: 570rpx;
- background: #FFFFFF;
- border-radius: 28rpx;
- padding: 34rpx 125rpx 54rpx;
- box-sizing: border-box;
- image{
- width: 232rpx;
- height: 232rpx;
- }
- text{
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 30rpx;
- color: #333333;
- line-height: 42rpx;
- margin-top: 10rpx;
- }
- p{
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 24rpx;
- color: #A6A6A6;
- line-height: 24rpx;
- margin-top: 24rpx;
- text-align: center;
- }
- .zt_btn{
- margin-top: 40rpx;
- }
- }
- }
- </style>
|