Explorar el Código

wifi模板调整

wzh hace 2 años
padre
commit
2a35c8344b

+ 2 - 2
config.js

@@ -1,9 +1,9 @@
 // 应用全局配置
 module.exports = {
   //baseUrl: 'https://vue.ruoyi.vip/prod-api',
-  //baseUrl: 'https://ev.weguyun.com',
   baseUrl: 'https://ev.weguyun.com',
-  socketUrl: 'ws://ev.weguyun.com/websocket',
+  // baseUrl: 'http://47.110.79.155:5090',
+  socketUrl: 'wss://ev.weguyun.com/websocket',
   imgUrl:'/static/images/new/start',
   // 应用信息
   appInfo: {

+ 6 - 2
locale/en.json

@@ -147,8 +147,12 @@
     "请打开系统蓝牙开关": "Please turn on the system Bluetooth switch.",
     "请打开系统定位开关": "Please turn on the system location switch.",
     "蓝牙适配器不可用": "Bluetooth adapter is not available.",
-    "请打开应用定位权限,允许应用使用您的位置信息": "Please open the app's location permission and allow the app to use your location information."
-
+    "请打开应用定位权限,允许应用使用您的位置信息": "Please open the app's location permission and allow the app to use your location information.",
+    "剩余时间" : "Time Left",
+    "WIFI配网" : "WIFI Config",
+    "正在连接蓝牙": "",
+    "配网成功,请扫码绑定设备" : "Successfully,Please scan to bind device.",
+    "正在配置网络信息": "Configuring network information."
 
   },
   "locale.auto": "System",

+ 17 - 0
pages.json

@@ -184,6 +184,23 @@
             }
 
       }
+    ],
+  "tabBar": {
+    "color": "#000000",
+    "selectedColor": "#000000",
+    "borderStyle": "white",
+    "backgroundColor": "#ffffff",
+    "list": [{
+      "pagePath": "pages/index",
+      "iconPath": "static/images/icons/menu-off.png",
+      "selectedIconPath": "static/images/icons/menu-on.png",
+      "text": "%index%"
+    }, {
+      "pagePath": "pages/mine/index",
+      "iconPath": "static/images/icons/mine-off.png",
+      "selectedIconPath": "static/images/icons/mine-on.png",
+      "text": "%mine%"
+    }
     ]
   },
   "globalStyle": {

+ 1 - 1
pages/bluetooth/index/index.vue

@@ -317,7 +317,7 @@ export default {
         // if(res.id==="EC:22:05:13:78:49")
         // console.log(`id:${res.id},name:${res.name},rssi:${res.rssi}`)
         let isRight = false;
-        if(res.name.startsWith('BT_') || res.name.startsWith('FC41D')){
+        if(res.name.startsWith('BT_') || res.name.startsWith('WGD')){
           isRight = true;
         }
         if(!isRight){

+ 50 - 30
pages/bluetooth/index/wifi.vue

@@ -42,7 +42,7 @@
                   ref="uForm"
         >
           <u-form-item
-              label="WIFI名称:"
+              label="WIFI Name:"
               borderBottom
               labelWidth="auto"
               @click="openChooseWifi"
@@ -52,8 +52,9 @@
                 v-model="SSID"
                 disabled
                 disabledColor="#ffffff"
-                placeholder="请选择wifi:"
+                placeholder="Choose wifi:"
                 border="none"
+                labelWidth="auto"
             ></u--input>
             <u-icon
                 slot="right"
@@ -61,13 +62,15 @@
             ></u-icon>
           </u-form-item>
           <u-form-item
-              label="密码:"
+              label="Password:"
               borderBottom
               ref="item1"
+              labelWidth="auto"
           >
             <u--input
                 v-model="password"
                 border="none"
+                labelWidth="auto"
             ></u--input>
           </u-form-item>
 
@@ -135,7 +138,7 @@
         </u--form>
       </view>
       <view style="margin:10px">
-        <u-button text="开始配网" v-if="isCompanyUser()" @click="doConnectUser(1)" size="small" type="primary"></u-button>
+        <u-button text="Confirm" v-if="isCompanyUser()" @click="doConnectUser(1)" size="small" type="primary"></u-button>
 
         <u-button text="开始配网" v-else @click="doConnect(2)" size="small" type="primary"></u-button>
 
@@ -201,15 +204,16 @@ export default {
       wifiList: [
         []
       ],
+      peiwangTimer:null,
 
     }
   },
   onLoad() {
     uni.setNavigationBarTitle({
-      title: "蓝牙配网"
+      title: i18('WIFI配网')
     })
     this.deviceno  = this.generateTimestamp();
-    ecUI.showLoading("正在初始化蓝牙模块")
+    ecUI.showLoading("Bluetooth initing")
     ctx = this
     clearInterval(this.timer);
     this.timer = setInterval(() => {
@@ -283,8 +287,7 @@ export default {
     },
     openWifi(){
       let self = this;
-      // #ifdef MP-WEIXIN
-      wx.startWifi({
+      uni.startWifi({
         success(res) {
           console.log(res);
           // self.getWifiList();
@@ -292,14 +295,13 @@ export default {
         fail(res) {
           console.log(res)
           uni.showToast({
-            title: '请打开WIFI',
+            title: i18('请打开WIFI'),
             icon: 'none',
             duration: 3000
           });
 
-        },
+        }
       })
-      // #endif
 
     },
     getWifi(){
@@ -319,14 +321,12 @@ export default {
       // #endif
 
     },
-    getWifiList(){
-      // #ifdef MP-WEIXIN
+    getWifiList() {
       var that = this
-      uni.showLoading();
-      wx.getWifiList({
-        success(res) {
-          console.log(res)
-          wx.onGetWifiList(function(res) {
+      uni.getWifiList({
+        success: res => {
+          console.log('res', res);
+          uni.onGetWifiList((res) => {
             that.showWiftList = true;
             uni.hideLoading();
             console.log("获取wifi列表");
@@ -336,24 +336,22 @@ export default {
             for (var i = 0; i < res.wifiList.length; i++) {
               that.wifiList[0].push(res.wifiList[i].SSID)
             }
-          })
+          });
         },
         fail(res) {
           console.log(res)
           uni.showToast({
-            title: '获取wifi失败,请检查wifi',
+            title: i18('获取wifi失败,请检查wifi'),
             icon: 'none',
             duration: 2000
           });
         },
-      })
-      // #endif
-
+      });
     },
     doConnectUser(){
       if(this.SSID == ""){
         uni.showToast({
-          title: '请选择WIFI',
+          title: i18('请选择WIFI'),
           icon: 'none',
           duration: 3000
         });
@@ -361,7 +359,7 @@ export default {
       }
       if(this.password == ""){
         uni.showToast({
-          title: '请输入wifi密码',
+          title: i18('请输入wifi密码'),
           icon: 'none',
           duration: 3000
         });
@@ -392,6 +390,10 @@ export default {
         sendEnd("OK"+endStr);
       },800);
 
+      this.peiwangTimer = setTimeout(function(){
+        ecUI.hideLoading();
+        self.$modal.showToast("配网失败,请检查状态");
+      },30000);
 
 
     },
@@ -589,7 +591,7 @@ export default {
     },
     listViewTap(id){
       let self = this;
-      ecUI.showLoading("正在连接蓝牙")
+      ecUI.showLoading("Bluetooth connectting")
       ecBLE.onBLEConnectionStateChange(res => {
         console.log(res);
         if (res.ok) {
@@ -601,17 +603,35 @@ export default {
           //
         } else {
           ecUI.hideLoading()
-          this.$modal.showToast("请检查是否配置成功");
+          this.$modal.showToast("蓝牙断开");
+          self.goBack();
         }
       });
       //receive data
       ecBLE.onBLECharacteristicValueChange((str, strHex) => {
-        console.log("数据来了")
         let isCheckRevHex = true;
         let data =
             (isCheckRevHex ? strHex.replace(/[0-9a-fA-F]{2}/g, ' $&') : str)
-        console.log(data)
-        self.$modal.closeLoading();
+        console.log(data);
+        data = data.trim();
+        data = data.split(" ")
+        if(data[1] == 'A3' && data[3] == '01' ){
+          self.$modal.closeLoading();
+          clearTimeout(self.peiwangTimer);
+          self.peiwangTimer = null;
+          uni.showModal({
+            title: i18('提示'),
+            content: i18('配网成功,请扫码绑定设备'),
+            showCancel: false,
+            confirmText: i18('确认'),
+            success: function(res) {
+              if (res.confirm) {
+                self.goBack();
+              }
+            }
+          })
+        }
+
 
       })
       self.connected = false;

+ 10 - 1
pages/index.vue

@@ -26,6 +26,10 @@
         <image :src = "imgUrl+'/index/device-2.png'"/>
         <view class="item-text">{{i18('设备列表')}}</view>
       </view>
+        <view class="item" @click="wifi">
+          <image :src = "imgUrl+'/index/bluetooth.png'"/>
+          <view class="item-text">{{i18('WIFI配网')}}</view>
+        </view>
     </view>
   </view>
 </template>
@@ -70,6 +74,11 @@ import i18 from '@/utils/i18.js'
           url: '/pages/bluetooth/index/index'
         });
       },
+      wifi(){
+        uni.navigateTo({
+          url: '/pages/bluetooth/index/wifi'
+        });
+      },
       toBind(qrcode){
         bindDevice(qrcode).then(res=>{
           let data = res.data;
@@ -115,7 +124,7 @@ import i18 from '@/utils/i18.js'
       },
       scan2(){
         let self = this;
-        getDeviceInfoFromQrcode("http://wetiandi.com/app/index.php?i=1&j=1&c=entry&m=wdl_shopping&do=wepay&sn=GD1B342399").then(res=>{
+        getDeviceInfoFromQrcode("http://wetiandi.com/index.php?do=wepay&sn=GD1B388803").then(res=>{
             if(res.data != null){
                   let imei = res.data.imei;
                   let ccid = res.data.ccid;

+ 45 - 29
pages/weitiandi/device/index.vue

@@ -226,6 +226,38 @@ export default {
       this.showPort = false;
       this.getInfo()
     },
+
+    parsePortCmd(real_data) {
+      let self = this;
+      self.portDetail = real_data
+      self.curPort = [];
+      let port_first_status = self.portDetail["port_first_status"];
+      let port_second_status = self.portDetail["port_second_status"]
+      if (port_first_status) {
+        self.portList[0].push({port: 1, text: i18("端口一")});
+        self.curPort.push({
+          text: i18("端口一"),
+          status: port_first_status,
+          id: 1,
+        })
+      }
+      if (port_second_status) {
+        self.portList[0].push({port: 2, text: i18("端口二")});
+        self.curPort.push({
+          text: i18("端口二"),
+          status: port_second_status,
+          id: 2
+        })
+      }
+      let choosePort = self.choosePort
+      if (choosePort == 1) {
+        self.portDetail.portStatus = port_first_status;
+      } else if (choosePort == 2) {
+        self.portDetail.portStatus = port_second_status;
+      }
+
+      self.$modal.closeLoading();
+    },
     initSocket(key){
       let self = this;
       let socketUrl =  getApp().globalData.config.socketUrl
@@ -245,35 +277,10 @@ export default {
         let data = JSON.parse(res.data);
         let type = data.type;
         let real_data = data.real_data;
-        if(type == 103){
-          self.portDetail = real_data
-          self.curPort = [];
-          let port_first_status = self.portDetail["port_first_status"];
-          let port_second_status = self.portDetail["port_second_status"]
-          if(port_first_status){
-            self.portList[0].push({port:1,text:i18("端口一")});
-            self.curPort.push({
-              text:i18("端口一"),
-              status:port_first_status,
-              id:1,
-            })
-          }
-          if(port_second_status){
-            self.portList[0].push({port:2,text:i18("端口二")});
-            self.curPort.push({
-              text:i18("端口二"),
-              status:port_second_status,
-              id:2
-            })
-          }
-          let choosePort = self.choosePort
-          if(choosePort == 1){
-            self.portDetail.portStatus = port_first_status;
-          }else if(choosePort == 2){
-            self.portDetail.portStatus = port_second_status;
-          }
 
-          self.$modal.closeLoading();
+
+        if(type == 103){
+          self.parsePortCmd(real_data);
         }
         if(type == 116){
           self.$modal.closeLoading();
@@ -325,6 +332,7 @@ export default {
       }
     },
    getInfo() {
+      let self = this;
     this.$modal.loading("正在获取状态,请稍等...");
      sendPortDetailCmd(this.deviceInfo).then(res => {
        this.$modal.loading("正在获取状态,请稍等...");
@@ -336,7 +344,15 @@ export default {
         if(!this.scriptTask){
           this.initSocket(this.deviceInfo.deviceId);
         }
-       // this.getPortInfo()
+       setTimeout(function (){
+         getPortDetail(self.deviceInfo,self.visitTime).then(res=>{
+           let data = res.data;
+           if(data != null){
+             self.parsePortCmd(data);
+           }else{
+           }
+         });
+       },500)
     })
   },
     stopCharge(){

+ 137 - 30
pages/weitiandi/device/status.vue

@@ -27,14 +27,14 @@
 
             <view class="p0" st="">{{ deviceInfo.qrcode}}</view>
             <view class="p1">
-              <view v-if="portDetail.portStatus == 2">
+              <view v-if="portStatus  == 2">
                 {{$t('charge.charging')}}
               </view>
-              <view v-else-if="portDetail.portStatus == 6">
+              <view v-else-if="portStatus  == 6">
                 {{$t('charge.planed')}}
               </view>
 
-              <view v-else-if="portDetail.portStatus == 5">
+              <view v-else-if="portStatus  == 5">
                 {{$t('charge.connected')}}
               </view>
 
@@ -49,39 +49,45 @@
 
       </view>
     </view>
+    <view style="display: flex;flex-direction: row;margin:0 33%;" v-if="curPort.length>1">
+      <view  class="port_item" :class="item.id==choosePort?'selected_item':''" v-for="item in curPort" @click="selectPort(item.id);">{{ i18(item.text )}}</view>
+    </view>
     <view class="dstatus">
       <view class="ditem">
         <image class="itemimg" src="/static/images/new/tmp.png"/>
-        <view class="item-value">{{portDetail.dev_temper}}℃</view>
+        <view class="item-value">{{deviceTemp}}℃</view>
         <span class="item-text">{{$t('charge.devtemper')}}</span>
       </view>
       <view class="ditem">
         <image class="itemimg" src="/static/images/new/dianya.png"/>
-        <view class="item-value">{{ portDetail.voltage }}V</view>
+        <view class="item-value">{{ deviceV  }}V</view>
         <span class="item-text">{{$t('charge.voltage')}}</span>
       </view>
       <view class="ditem">
         <image class="itemimg" src="/static/images/new/dianliu.png"/>
-        <view class="item-value" v-if="portDetail.voltage == 0">0A</view>
-        <view class="item-value" v-else>{{portDetail.POWER/portDetail.voltage}}A</view>
+        <view class="item-value" v-if="deviceV  == 0">0A</view>
+        <view class="item-value" v-else>{{currentValue}}A</view>
         <span class="item-text">{{$t('charge.current')}}</span>
       </view>
 
       <view class="ditem">
         <image class="itemimg" src="/static/images/new/shjian.png"/>
-        <view class="item-value">{{ portDetail.time }}{{ i18('分钟') }}</view>
-        <span class="item-text">{{$t('charge.chargetime')}}</span>
+        <view class="item-value">{{ chargeTime  }}{{ i18('分钟') }}</view>
+        <span class="item-text"  v-if="portDetail.portStatus == 6">{{i18('剩余时间')}}</span>
+        <span class="item-text" v-else>{{$t('charge.chargetime')}}</span>
+
       </view>
 
       <view class="ditem">
         <image class="itemimg" src="/static/images/new/gonglv.png"/>
-        <view class="item-value">{{ portDetail.power }}W</view>
+        <view class="item-value">{{ gonglv  }}W</view>
         <span class="item-text">{{$t('charge.power')}}</span>
       </view>
 
       <view class="ditem">
         <image class="itemimg" src="/static/images/new/dianliang.png"/>
-        <view class="item-value">{{ portDetail.elec }} {{ i18('度') }}</view>
+        <view class="item-value" v-if="portDetail.voltage == 0">0 {{ i18('度') }}</view>
+        <view class="item-value" v-else>{{ dianliang }} {{ i18('度') }}</view>
         <span class="item-text">{{$t('charge.elec')}}</span>
       </view>
 
@@ -116,6 +122,15 @@ import i18 from '@/utils/i18.js'
 export default {
  data() {
    return {
+     refreshTimer:null,
+     curPort:[],
+     chargeTime:0,
+     deviceTemp:0,
+     deviceV:0,
+     currentValue:0,
+     gonglv:0,
+     dianliang:0,
+     portStatus:0,
      deviceInfo:{},
      visitTime:"",
      timer:null,
@@ -139,6 +154,7 @@ export default {
    this.deviceInfo.deviceId = opt.id;
    this.deviceInfo.ccid = opt.ccid;
    this.deviceInfo.qrcode = opt.qrcode;
+   this.startTimer();
  },
   onShow(){
     this.getInfo();
@@ -146,6 +162,9 @@ export default {
   },
   onUnload (){
    this.closeSocket();
+    if(this.refreshTimer != null){
+      clearTimeout(this.refreshTimer)
+    }
   },
   methods: {
     toPage(){
@@ -204,12 +223,107 @@ export default {
         }
       })
     },
+    startTimer(){
+      let self = this;
+      if(this.refreshTimer != null){
+        clearTimeout(this.refreshTimer);
+      }
+      self.refreshTimer = setTimeout(function(){
+        self.getInfo();
+        self.startTimer();
+      },30000);
+    },
     confirmPort(e){
       let value = e.value[0]
       this.choosePort = value.port;
       this.showPort = false;
       this.getInfo()
     },
+    parsePortCmd(real_data) {
+      let self = this;
+      self.portDetail = real_data;
+      self.portList = [[]];
+      self.curPort = [];
+      let port_first_status = self.portDetail["port_first_status"];
+      let port_second_status = self.portDetail["port_second_status"]
+      if(port_first_status){
+        self.portList[0].push({port:1,text:"端口一"});
+        self.curPort.push({
+          text:"端口一",
+          status:port_first_status,
+          id:1,
+        })
+        let power = self.portDetail.power;
+        let voltage = parseInt(self.portDetail.voltage);
+        if(voltage >0){
+          let current = power/voltage;
+          current = current.toFixed(1);
+          self.portDetail.currentValue = current;
+
+        }
+      }
+      if(port_second_status){
+        self.portList[0].push({port:2,text:"端口二"});
+        self.curPort.push({
+          text:"端口二",
+          status:port_second_status,
+          id:2
+        })
+        let power = self.portDetail.power_1;
+        let voltage = parseInt(self.portDetail.voltage);
+        if(voltage >0){
+          let current = power/voltage;
+          current = current.toFixed(1);
+          self.portDetail.currentValue_1 = current;
+
+        }
+      }
+      let choosePort = self.choosePort
+      /**
+       *  chargeTime:0,
+       *      deviceTemp:0,
+       *      deviceV:0,
+       *      currentValue:0,
+       *      gonglv:0,
+       *      dianliang:0,
+       *      portStatus:0,
+       */
+      if(choosePort == 1){
+        self.portDetail.portStatus = port_first_status;
+        self.chargeTime = self.portDetail.time;
+        self.gonglv = self.portDetail.power;
+        self.dianliang = self.portDetail.elec/100;
+        self.currentValue =  self.portDetail.currentValue;
+        if(port_first_status != 2){
+          self.chargeTime = 0;
+          if(port_first_status == 6){
+            self.chargeTime = self.portDetail.time;
+          }
+          self.gonglv = 0;
+          self.dianliang = 0;
+          self.currentValue =  0;
+        }
+      }else if(choosePort == 2){
+        self.portDetail.portStatus = port_second_status;
+        self.chargeTime = self.portDetail.time_1;
+        self.gonglv = self.portDetail.power_1;
+        self.dianliang = self.portDetail.elec_1/100;
+        self.currentValue =  self.portDetail.currentValue_1;
+        if(port_second_status != 2){
+          self.chargeTime = 0;
+          if(port_first_status == 6){
+            self.chargeTime = self.portDetail.time_1;
+          }
+          self.gonglv = 0;
+          self.dianliang = 0;
+          self.currentValue =  0;
+        }
+      }
+      self.portStatus = self.portDetail.portStatus;
+      self.deviceTemp = self.portDetail.dev_temper;
+      self.deviceV = self.portDetail.voltage;
+      self.$modal.closeLoading();
+    },
     initSocket(key){
       let self = this;
       let socketUrl =  getApp().globalData.config.socketUrl
@@ -229,25 +343,9 @@ export default {
         let data = JSON.parse(res.data);
         let type = data.type;
         let real_data = data.real_data;
-        if(type == 103){
-          self.portDetail = real_data
-          self.portList = [[]];
-          let port_first_status = self.portDetail["port_first_status"];
-          let port_second_status = self.portDetail["port_second_status"]
-          if(port_first_status){
-            self.portList[0].push({port:1,text:"端口一"});
-          }
-          if(port_second_status){
-            self.portList[0].push({port:2,text:"端口二"});
-          }
-          let choosePort = self.choosePort
-          if(choosePort == 1){
-            self.portDetail.portStatus = port_first_status;
-          }else if(choosePort == 2){
-            self.portDetail.portStatus = port_second_status;
-          }
 
-          self.$modal.closeLoading();
+        if(type == 103){
+          self.parsePortCmd(real_data);
         }
         if(type == 116){
           self.$modal.closeLoading();
@@ -299,6 +397,7 @@ export default {
       }
     },
    getInfo() {
+      let self= this;
     this.$modal.loading("正在获取状态,请稍等...");
      sendPortDetailCmd(this.deviceInfo).then(res => {
        this.$modal.loading("正在获取状态,请稍等...");
@@ -310,7 +409,15 @@ export default {
         if(!this.scriptTask){
           this.initSocket(this.deviceInfo.deviceId);
         }
-       // this.getPortInfo()
+       setTimeout(function (){
+         getPortDetail(self.deviceInfo,self.visitTime).then(res=>{
+           let data = res.data;
+           if(data != null){
+             self.parsePortCmd(data);
+           }else{
+           }
+         });
+       },500)
     })
   },
     stopCharge(){

+ 5 - 1
utils/weitiandi/device/device.js

@@ -476,6 +476,9 @@ export function parseDataObj(data){
 }
 export function parsePwd(data){
     let pwd = "";
+    if(data[3] == '255'){
+        return '123456';
+    }
     for (let i = 3; i < 9; i++) {
         pwd = pwd+""+parseInt(data[i],16) ;
     }
@@ -640,7 +643,8 @@ function testQueue(){
 }
 
 function testWifi(){
-deviceTool.sendWifi("MERCURY_D8BC8A$$")
+    let str = parseDataObj("AA AC 06 FF FF FF FF FF FF AC");
+    console.log(str)
 }
 // testWifi()