Kaynağa Gözat

切换的时候增加刷新

wzh 2 yıl önce
ebeveyn
işleme
ca9f01e229

+ 340 - 331
pages/bluetooth/index/index.vue

@@ -1,19 +1,19 @@
 <template>
-	<scroll-view class="main-container" scroll-y="true"
-		:refresher-enabled="false">
-		<view v-for="(item, index) in deviceListDataShow" :key="item.id" class="list-item" hover-class="list-item-hover"
-			hover-start-time="0" hover-stay-time="100" @click="listViewTap(item.id)">
-			<image v-if="item.manufacturer==='eciot'" src="/static/img/ecble.png" class="list-item-img"></image>
-			<image v-else src="/static/img/ble.png" class="list-item-img"></image>
-			<text class="list-item-name">{{item.name}}</text>
-			<image v-if="item.rssi >= -41" src="/static/img/s5.png" mode="aspectFit" class="list-item-rssi-img"></image>
-			<image v-else-if="item.rssi >= -55" src="/static/img/s4.png" mode="aspectFit" class="list-item-rssi-img"></image>
-			<image v-else-if="item.rssi >= -65" src="/static/img/s3.png" mode="aspectFit" class="list-item-rssi-img"></image>
-			<image v-else-if="item.rssi >= -75" src="/static/img/s2.png" mode="aspectFit" class="list-item-rssi-img"></image>
-			<image v-else="item.rssi < -75" src="/static/img/s1.png" mode="aspectFit" class="list-item-rssi-img"></image>
-			<text class="list-item-rssi">{{item.rssi}}</text>
-			<view class="list-item-line"></view>
-		</view>
+  <scroll-view class="main-container" scroll-y="true"
+               :refresher-enabled="false">
+    <view v-for="(item, index) in deviceListDataShow" :key="item.id" class="list-item" hover-class="list-item-hover"
+          hover-start-time="0" hover-stay-time="100" @click="listViewTap(item.id)">
+      <image v-if="item.manufacturer==='eciot'" src="/static/img/ecble.png" class="list-item-img"></image>
+      <image v-else src="/static/img/ble.png" class="list-item-img"></image>
+      <text class="list-item-name">{{item.name}}</text>
+      <image v-if="item.rssi >= -41" src="/static/img/s5.png" mode="aspectFit" class="list-item-rssi-img"></image>
+      <image v-else-if="item.rssi >= -55" src="/static/img/s4.png" mode="aspectFit" class="list-item-rssi-img"></image>
+      <image v-else-if="item.rssi >= -65" src="/static/img/s3.png" mode="aspectFit" class="list-item-rssi-img"></image>
+      <image v-else-if="item.rssi >= -75" src="/static/img/s2.png" mode="aspectFit" class="list-item-rssi-img"></image>
+      <image v-else="item.rssi < -75" src="/static/img/s1.png" mode="aspectFit" class="list-item-rssi-img"></image>
+      <text class="list-item-rssi">{{item.rssi}}</text>
+      <view class="list-item-line"></view>
+    </view>
     <u-modal :show="showPwd" :confirmText="i18('确认')" :cancelText="i18('取消')" @confirm="inputPwd" @cancel="cancel" :showCancelButton="true"  :title="$t('buletooth.pwdinput')" >
       <view class="slot-content">
         <view>
@@ -46,9 +46,9 @@
         </view>
       </view>
     </u-modal>
-		<view v-if="deviceListDataShow.length==0" class="notice"> - {{ $t('buletooth.nodevice') }} -</view>
-		<view class="gap"></view>
-	</scroll-view>
+    <view v-if="deviceListDataShow.length==0" class="notice"> - {{ $t('buletooth.nodevice') }} -</view>
+    <view class="gap"></view>
+  </scroll-view>
 
 
 </template>
@@ -66,351 +66,360 @@ const ecUI = require('@/utils/ecUI.js')
 const ecBLE = require('@/utils/ecBLE/ecBLE.js')
 // #endif
 import i18 from '@/utils/i18.js'
-	let ctx
-	let deviceListData = []
-	export default {
-    components: {
-      w_md5
+let ctx
+let deviceListData = []
+export default {
+  data() {
+    return {
+      showPwd:false,
+      rightPwd:"",
+      pwd:"",
+      timer:"",
+      buleid:"",
+      deviceListDataShow: [],
+      showTimer:null,
+      connected:false,
+      uuid:"",
+      showDeviceNo:false,
+      inputDeviceNo:"",
+      commonCode:""
+    }
+  },
+  onLoad() {
+    uni.setNavigationBarTitle({
+      title: this.$t('page.bluetooth')
+    })
+    ecUI.showLoading(this.$t('buletooth.init'))
+    ctx = this
+    clearInterval(this.timer);
+    this.timer = setInterval(() => {
+      ctx.deviceListDataShow = JSON.parse(JSON.stringify(deviceListData))
+    }, 800)
+    this.commonCode = this.generateUniqueNumber(this.getBeijingTime());
+    console.log(this.commonCode)
+  },
+  onUnload(){
+    ecBLE.stopBluetoothDevicesDiscovery();
+    ecBLE.closeBLEConnection()
+  },
+  onShow() {
+    if(this.showTimer!= null){
+      clearTimeout(this.showTimer);
+    }
+    this.showTimer = setTimeout(() => {
+      ctx.openBluetoothAdapter()
+    }, 100)
+  },
+  methods: {
+    forgetDeviceNo(){
+      this.$modal.showToast("请截图该页面联系售后部门");
     },
-		data() {
-			return {
-        showPwd:false,
-        rightPwd:"",
-        pwd:"",
-        timer:"",
-        buleid:"",
-				deviceListDataShow: [],
-        showTimer:null,
-        connected:false,
-        uuid:"",
-        showDeviceNo:false,
-        inputDeviceNo:"",
-        commonCode:""
-			}
-		},
-		onLoad() {
-      uni.setNavigationBarTitle({
-        title: this.$t('page.bluetooth')
-      })
-      ecUI.showLoading(this.$t('buletooth.init'))
-			ctx = this
-      clearInterval(this.timer);
-      this.timer = setInterval(() => {
-        ctx.deviceListDataShow = JSON.parse(JSON.stringify(deviceListData))
-      }, 800)
-      this.commonCode = this.generateUniqueNumber(this.getBeijingTime());
-      console.log(this.commonCode)
-		},
-    onUnload(){
-      ecBLE.stopBluetoothDevicesDiscovery();
-      ecBLE.closeBLEConnection()
+    i18(text){
+      return i18(text)
+    },
+    cancel(){
+      this.showPwd = false;
+      uni.navigateBack({
+      });
     },
-		onShow() {
-      if(this.showTimer!= null){
-        clearTimeout(this.showTimer);
+    resetPwd(){
+      let self = this;
+      if(!this.inputDeviceNo){
+        self.$modal.showToast("请输入序列号");
+        return;
       }
-			this.showTimer = setTimeout(() => {
-				ctx.openBluetoothAdapter()
-			}, 100)
-		},
-		methods: {
-      forgetDeviceNo(){
-        this.$modal.showToast("请截图该页面联系售后部门");
-      },
-      i18(text){
-        return i18(text)
-      },
-      cancel(){
-        this.showPwd = false;
-        uni.navigateBack({
-        });
-      },
-      resetPwd(){
-        let self = this;
-        if(!this.inputDeviceNo){
-          self.$modal.showToast("请输入序列号");
-          return;
-        }
-        let uuidRight = false;
-        if(this.inputDeviceNo == this.commonCode || this.uuid == this.inputDeviceNo){
-          uuidRight = true;
-        }
-        if(!uuidRight){
-          self.$modal.showToast("序列号有误");
-          return;
-        }
-        if(uuidRight){
-          this.$modal.confirm("密码将被重置为123456").then(res=>{
-            setPwd("123456")
-            self.$modal.showToast("密码修改成功");
-            this.rightPwd = "123456";
-            self.loginSuccess();
-          });
-        }
-      },
-       getBeijingTime() {
-         const date = new Date();
-         const utcTime = date.getTime() + (date.getTimezoneOffset() * 60 * 1000);
-         const beijingTime = new Date(utcTime + (8 * 60 * 60 * 1000));
-         return beijingTime;
-      },
-       generateUniqueNumber(date) {
-         let dateString = date.toISOString().slice(0, 10).replace(/-/g, '');
-         console.log(dateString)
-         let hash = w_md5.hex_md5_32(dateString);
-         console.log(hash);//32位小写
-         let str = "";
-         for (let i = 0; i < 6; i++) {
-           const c = hash.charCodeAt(i);
-           str  = str+""+c+""
-         }
-         return str.substr(0,6);
-},
-      goBack(){
-        uni.navigateBack({
+      let uuidRight = false;
+      if(this.inputDeviceNo == this.commonCode || this.uuid == this.inputDeviceNo){
+        uuidRight = true;
+      }
+      if(!uuidRight){
+        self.$modal.showToast("序列号有误");
+        return;
+      }
+      if(uuidRight){
+        this.$modal.confirm("密码将被重置为123456").then(res=>{
+          setPwd("123456")
+          self.$modal.showToast("密码修改成功");
+          this.rightPwd = "123456";
+          self.loginSuccess();
         });
-      },
-      inputPwd(){
-        if(!this.pwd ){
-          this.$modal.showToast(this.$t('buletooth.errpwd'));
+      }
+    },
+    getBeijingTime() {
+      const date = new Date();
+      const utcTime = date.getTime() + (date.getTimezoneOffset() * 60 * 1000);
+      const beijingTime = new Date(utcTime + (8 * 60 * 60 * 1000));
+      return beijingTime;
+    },
+    generateUniqueNumber(date) {
+      let dateString = date.toISOString().slice(0, 10).replace(/-/g, '');
+      console.log(dateString)
+      let hash = w_md5.hex_md5_32(dateString);
+      console.log(hash);//32位小写
+      let str = "";
+      for (let i = 0; i < 6; i++) {
+        const c = hash.charCodeAt(i);
+        str  = str+""+c+""
+      }
+      return str.substr(0,6);
+    },
+    goBack(){
+      uni.navigateBack({
+      });
+    },
+    inputPwd(){
+      if(!this.pwd ){
+        this.$modal.showToast(this.$t('buletooth.errpwd'));
+      }else{
+        if(this.rightPwd && this.rightPwd === this.pwd){
+          this.loginSuccess();
         }else{
-          if(this.rightPwd && this.rightPwd === this.pwd){
-           this.loginSuccess();
-          }else{
-            this.$modal.showToast(this.$t('buletooth.errpwd'));
-          }
-
+          this.$modal.showToast(this.$t('buletooth.errpwd'));
         }
-      },
-      loginSuccess(){
-        this.showPwd = false;
-        this.showDeviceNo = false;
-        uni.setStorageSync("pwd",this.rightPwd);
-        uni.setStorageSync('blueid', this.buleid);
-        this.pwd = "";
-        ecBLE.stopBluetoothDevicesDiscovery();
-        uni.navigateTo({
-          url: '/pages/weitiandi/bluetooth/status'
-        });
-      },
-      getLocalPwd(){
-        let pwd = uni.getStorageSync("pwd");
-        return pwd;
-      },
-			listViewTap(id){
-        let self = this;
-				ecUI.showLoading(this.$t('buletooth.connecting'))
-				ecBLE.onBLEConnectionStateChange(res => {
-          console.log(res);
-					if (res.ok) {
+
+      }
+    },
+    loginSuccess(){
+      this.showPwd = false;
+      this.showDeviceNo = false;
+      uni.setStorageSync("pwd",this.rightPwd);
+      uni.setStorageSync('blueid', this.buleid);
+      this.pwd = "";
+      ecBLE.stopBluetoothDevicesDiscovery();
+      uni.navigateTo({
+        url: '/pages/weitiandi/bluetooth/status'
+      });
+    },
+    getLocalPwd(){
+      let pwd = uni.getStorageSync("pwd");
+      return pwd;
+    },
+    listViewTap(id){
+      let self = this;
+      ecUI.showLoading(this.$t('buletooth.connecting'))
+      ecBLE.onBLEConnectionStateChange(res => {
+        console.log(res);
+        if (res.ok) {
+          self.connected = true;
+          setTimeout(function(){
+            ecUI.hideLoading()
+            getPwd();
+            self.buleid = id;
+          },500)
+          // uni.setStorageSync('blueid', id);
+          // ecBLE.stopBluetoothDevicesDiscovery();
+          //
+        } else {
+          let msg = res.errMsg;
+          console.log(msg);
+          if(msg.indexOf("already") != -1){
             self.connected = true;
             setTimeout(function(){
               ecUI.hideLoading()
               getPwd();
               self.buleid = id;
             },500)
-            // uni.setStorageSync('blueid', id);
-						// ecBLE.stopBluetoothDevicesDiscovery();
-            //
-					} else {
-            ecUI.hideLoading()
-            uni.removeStorageSync('blueid');
-						ecUI.showModal(
-                this.$t('buletooth.tip'),
-							'error,errCode=' + res.errCode + ',errMsg=' + i18(res.errMsg)
-						)
-					}
-				});
-        //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();
-          data = parseDataObj(data);
-		  console.log(data);
-          let type = data.type;
-          if(type == 253){
-            self.messageCallback(data)
-          }else{
-            let pwd =  data.real_data;
-            let localPwd = self.getLocalPwd()
-            console.log(pwd);
-            console.log("localPwd:"+localPwd)
-            self.rightPwd = pwd;
-            if(pwd != localPwd){
-              self.showInputPwd();
-            }else{
-              self.loginSuccess();
-            }
-          }
-
-        })
-        self.connected = false;
-				ecBLE.createBLEConnection(id);
-        setTimeout(function (){
-          if(!self.connected){
-            self.$modal.showToast(i18('连接失败'));
-            self.startBluetoothDevicesDiscovery()
+            return;
           }
-        },10000);
-			},
-      showInputPwd(){
-        this.showPwd = true;
-      },
-      messageCallback(data){
-        let self = this;
+          ecUI.hideLoading()
+          uni.removeStorageSync('blueid');
+          ecUI.showModal(
+              this.$t('buletooth.tip'),
+              'error,errCode=' + res.errCode + ',errMsg=' + i18(res.errMsg)
+          )
+        }
+      });
+      //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)
+        data = parseDataObj(data);
         console.log(data);
         let type = data.type;
-        let real_data = data.real_data;
         if(type == 253){
           self.$modal.closeLoading();
-          self.uuid = real_data.substr(0,6);
+          self.messageCallback(data)
+        }else if(type == 172){
+          self.$modal.closeLoading();
+          let pwd =  data.real_data;
+          let localPwd = self.getLocalPwd()
+          console.log(pwd);
+          console.log("localPwd:"+localPwd)
+          self.rightPwd = pwd;
+          if(pwd != localPwd){
+            self.showInputPwd();
+          }else{
+            self.loginSuccess();
+          }
         }
-        self.$forceUpdate();
-        console.log('收到服务器内容:' + JSON.stringify(data));
-      },
-      forgetPwd(){
-        this.$modal.loading("正在读取设备ID");
-        getUUID()
-        this.showDeviceNo = true;
-      },
-			openBluetoothAdapter() {
-        let self = this;
-				ecBLE.onBluetoothAdapterStateChange(res => {
-          ecUI.hideLoading()
-					if (res.ok) {
-            let blueid = uni.getStorageSync('blueid');
-            console.log('Bluetooth adapter ok,blueid:'+blueid)
-            if(blueid){
-              self.listViewTap(blueid);
-            }else{
-              ctx.startBluetoothDevicesDiscovery()
-            }
-					} else {
-						ecUI.showModal(
-                this.$t('buletooth.tip'),
-							`Bluetooth adapter error | ${res.errCode} | ${res.errMsg}`,
-							() => {
 
-							}
-						)
-					}
-				})
-				ecBLE.openBluetoothAdapter()
-			},
-			startBluetoothDevicesDiscovery() {
-        ecBLE.stopBluetoothDevicesDiscovery();
-				console.log('start search')
-				ecBLE.onBluetoothDeviceFound(res => {
-					// 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')){
-            isRight = true;
+      })
+      self.connected = false;
+      ecBLE.createBLEConnection(id);
+      setTimeout(function (){
+        if(!self.connected){
+          self.$modal.showToast(i18('连接失败'));
+          self.startBluetoothDevicesDiscovery()
+        }
+      },10000);
+    },
+    showInputPwd(){
+      this.showPwd = true;
+    },
+    messageCallback(data){
+      let self = this;
+      console.log(data);
+      let type = data.type;
+      let real_data = data.real_data;
+      if(type == 253){
+        self.$modal.closeLoading();
+        self.uuid = real_data.substr(0,6);
+      }
+      self.$forceUpdate();
+      console.log('收到服务器内容:' + JSON.stringify(data));
+    },
+    forgetPwd(){
+      this.$modal.loading("正在读取设备ID");
+      getUUID()
+      this.showDeviceNo = true;
+    },
+    openBluetoothAdapter() {
+      let self = this;
+      ecBLE.onBluetoothAdapterStateChange(res => {
+        ecUI.hideLoading()
+        if (res.ok) {
+          let blueid = uni.getStorageSync('blueid');
+          console.log('Bluetooth adapter ok,blueid:'+blueid)
+          if(blueid){
+            self.listViewTap(blueid);
+          }else{
+            ctx.startBluetoothDevicesDiscovery()
           }
-          if(!isRight){
-            return;
+        } else {
+          ecUI.showModal(
+              this.$t('buletooth.tip'),
+              `Bluetooth adapter error | ${res.errCode} | ${res.errMsg}`,
+              () => {
+
+              }
+          )
+        }
+      })
+      ecBLE.openBluetoothAdapter()
+    },
+    startBluetoothDevicesDiscovery() {
+      ecBLE.stopBluetoothDevicesDiscovery();
+      console.log('start search')
+      ecBLE.onBluetoothDeviceFound(res => {
+        // 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')){
+          isRight = true;
+        }
+        if(!isRight){
+          return;
+        }
+        for (const item of deviceListData) {
+          if (item.id === res.id) {
+            item.name = res.name
+            item.rssi = res.rssi
+            return
           }
-					for (const item of deviceListData) {
-						if (item.id === res.id) {
-							item.name = res.name
-							item.rssi = res.rssi
-							return
-						}
-					}
-					let manufacturer = ''
-					if (res.name.length === 11 && res.name.startsWith('@')) {
-						manufacturer = 'eciot'
-					}
-					if (res.name.length === 15 && res.name.startsWith('BT_')) {
-						manufacturer = 'eciot'
-					}
+        }
+        let manufacturer = ''
+        if (res.name.length === 11 && res.name.startsWith('@')) {
+          manufacturer = 'eciot'
+        }
+        if (res.name.length === 15 && res.name.startsWith('BT_')) {
           manufacturer = 'eciot'
-					deviceListData.push({
-						id: res.id,
-						name: res.name,
-						rssi: res.rssi,
-						manufacturer,
-					})
-				})
-				ecBLE.startBluetoothDevicesDiscovery()
-			},
-		}
-	}
+        }
+        manufacturer = 'eciot'
+        deviceListData.push({
+          id: res.id,
+          name: res.name,
+          rssi: res.rssi,
+          manufacturer,
+        })
+      })
+      ecBLE.startBluetoothDevicesDiscovery()
+    },
+  }
+}
 </script>
 
 <style>
-	.main-container {
-		height: 100vh;
-	}
+.main-container {
+  height: 100vh;
+}
 
-	.list-item {
-		height: 57px;
-		position: relative;
-	}
+.list-item {
+  height: 57px;
+  position: relative;
+}
 
-	.list-item-hover {
-		background-color: #e5e4e9;
-	}
+.list-item-hover {
+  background-color: #e5e4e9;
+}
 
-	.list-item-img {
-		position: absolute;
-		width: 36px;
-		height: 36px;
-		left: 20px;
-		top: 10px;
-	}
+.list-item-img {
+  position: absolute;
+  width: 36px;
+  height: 36px;
+  left: 20px;
+  top: 10px;
+}
 
-	.list-item-name {
-		position: absolute;
-		font-size: 22px;
-		left: 76px;
-		top: 0px;
-		line-height: 56px;
-	}
+.list-item-name {
+  position: absolute;
+  font-size: 22px;
+  left: 76px;
+  top: 0px;
+  line-height: 56px;
+}
 
-	.list-item-rssi-img {
-		position: absolute;
-		width: 20px;
-		height: 20px;
-		right: 20px;
-		top: 13px;
-	}
+.list-item-rssi-img {
+  position: absolute;
+  width: 20px;
+  height: 20px;
+  right: 20px;
+  top: 13px;
+}
 
-	.list-item-rssi {
-		position: absolute;
-		width: 40px;
-		height: 20px;
-		right: 10px;
-		top: 33px;
-		font-size: 12px;
-		font-weight: bold;
-		display: flex;
-		justify-content: center;
-	}
+.list-item-rssi {
+  position: absolute;
+  width: 40px;
+  height: 20px;
+  right: 10px;
+  top: 33px;
+  font-size: 12px;
+  font-weight: bold;
+  display: flex;
+  justify-content: center;
+}
 
-	.list-item-line {
-		position: absolute;
-		height: 1px;
-		width: 100vw;
-		left: 20px;
-		top: 56px;
-		background-color: #c6c6c8;
-	}
+.list-item-line {
+  position: absolute;
+  height: 1px;
+  width: 100vw;
+  left: 20px;
+  top: 56px;
+  background-color: #c6c6c8;
+}
 
-	.notice {
-		display: flex;
-		justify-content: center;
-		align-items: center;
-		margin-top: 10px;
-		font-size: 13px;
-		color: #909399;
-	}
+.notice {
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  margin-top: 10px;
+  font-size: 13px;
+  color: #909399;
+}
 
-	.gap {
-		height: 57px;
-	}
+.gap {
+  height: 57px;
+}
 </style>

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

@@ -234,6 +234,7 @@ export default {
    selectPort(id){
      this.choosePort = id;
      console.log(this.choosePort)
+     this.getInfo()
    },
     cancel(){
       this.showPwd = false;

+ 200 - 107
pages/weitiandi/bluetooth/status.vue

@@ -35,15 +35,15 @@
 
             <view class="p0" st="">{{i18('设备号')}}:{{uuid}}</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>
 
@@ -58,39 +58,44 @@
 
       </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>
+        <view class="item-value" >{{ chargeTime }}{{ i18('分钟') }}</view>
         <span class="item-text">{{$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" >{{ dianliang}} {{ i18('度') }}</view>
         <span class="item-text">{{$t('charge.elec')}}</span>
       </view>
 
@@ -191,47 +196,60 @@ let isCheckRevHex = false
 let isCheckSendHex = false
 let sendData = ''
 export default {
- data() {
-   return {
-     locale:"",
-     oldPwd:"",
-     pwd:"",
-     showPwd:false,
-     planCols:[ ],
-     columnData:[],
-     showPlan:false,
-     deviceInfo:{},
-     visitTime:"",
-     timer:null,
-     showPort:false,
-     portDetail:{portStatus:0,POWER:0,voltage:0},
-     statusTimer:"",
-     connected:false,
-     scriptTask:null,
-     choosePort:1,
-     portList:[[{port:1,text:"端口一"}]],
-     planInfo:null,
-     days:["","周一","周二","周三","周四","周五","周六","周日"],
-     textRevData: '',
-     picker:null,
-     firstInit:false,
-     hasRight:false,
-     startAutoCharge:true,
-     initPwd:"123456",
-     showInitPwd:false,
-     uuid:"",
-   }
- },
- computed: {
-   imgUrl() {
-     return getApp().globalData.config.imgUrl;
-   }
- },
- onLoad() {
-   this.locale = uni.getLocale();
-   console.log("status comeing")
-   this.checkPassword();
- },
+  data() {
+    return {
+      chargeTime:0,
+      deviceTemp:0,
+      deviceV:0,
+      currentValue:0,
+      gonglv:0,
+      dianliang:0,
+      portStatus:0,
+      locale:"",
+      oldPwd:"",
+      pwd:"",
+      showPwd:false,
+      planCols:[ ],
+      columnData:[],
+      showPlan:false,
+      deviceInfo:{},
+      visitTime:"",
+      timer:null,
+      showPort:false,
+      portDetail:{portStatus:0,power:0,voltage:0,time:0,dev_temper:0,elec:0,dev_temper:0},
+      statusTimer:"",
+      connected:false,
+      scriptTask:null,
+      choosePort:1,
+      portList:[[{port:1,text:"端口一"}]],
+      planInfo:null,
+      days:["","周一","周二","周三","周四","周五","周六","周日"],
+      textRevData: '',
+      picker:null,
+      firstInit:false,
+      hasRight:false,
+      startAutoCharge:true,
+      initPwd:"123456",
+      showInitPwd:false,
+      uuid:"",
+      curPort:[],
+      firstRender:false,
+    }
+  },
+  computed: {
+    imgUrl() {
+      return getApp().globalData.config.imgUrl;
+    }
+  },
+  onLoad() {
+    // #ifdef MP
+    this.firstRender = true;
+    // #endif
+    this.locale = uni.getLocale();
+    console.log("status comeing")
+    this.checkPassword();
+    // this.messageCallback({"type":103,"real_data":{"port_first_status":1,"power":0,"elec":0,"money":0,"time":0,"port_second_status":2,"power_1":0,"elec_1":3,"money_1":50000,"time_1":367,"dev_temper":17,"voltage":228,"":249,"portStatus":1,"currentValue":"0.0"}})
+  },
   onShow(){
     uni.setNavigationBarTitle({
       title: this.$t('page.detail')
@@ -240,9 +258,14 @@ export default {
 
   },
   onUnload (){
-   this.closeSocket();
+    this.closeSocket();
   },
   methods: {
+    selectPort(id){
+      this.choosePort = id;
+      console.log(this.choosePort)
+      this.getInfo();
+    },
     copyPwd(){
       uni.setClipboardData({
         data: this.uuid,
@@ -251,9 +274,9 @@ export default {
         }
       });
     },
-   i18(text){
-     return i18(text)
-   },
+    i18(text){
+      return i18(text)
+    },
     toPage(){
       uni.navigateTo({
         url: '/pages/weitiandi/bluetooth/index'
@@ -263,7 +286,7 @@ export default {
       this.showPwd = false;
     },
     modifyPwd(){
-        this.showPwd = true;
+      this.showPwd = true;
     },
     inputPwd(){
       let rightPwd = uni.getStorageSync("pwd");
@@ -283,17 +306,17 @@ export default {
         this.$modal.showToast("密码不能设置为123456");
         return;
       }
-        if(!this.pwd){
-          this.$modal.showToast("密码不能为空");
-        }else {
-          setPwd(this.pwd);
-          this.oldPwd = this.pwd;
-          uni.removeStorageSync("pwd");
-          this.$modal.showToast("密码修改成功");
-          this.showPwd = false;
-          this.showInitPwd = false;
-          // this.goBack();
-        }
+      if(!this.pwd){
+        this.$modal.showToast("密码不能为空");
+      }else {
+        setPwd(this.pwd);
+        this.oldPwd = this.pwd;
+        uni.removeStorageSync("pwd");
+        this.$modal.showToast("密码修改成功");
+        this.showPwd = false;
+        this.showInitPwd = false;
+        // this.goBack();
+      }
 
     },
     confirm(e) {
@@ -432,28 +455,74 @@ export default {
       })
       self.getInfo();
     },
-    messageCallback(data){
+    messageCallback(data,flag){
       let self = this;
-      console.log(data);
       let type = data.type;
       let real_data = data.real_data;
       if(type == 103){
-        self.portDetail = real_data
+        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;
         }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;
         }
+        self.portStatus = self.portDetail.portStatus;
+        self.deviceTemp = self.portDetail.dev_temper;
+        self.deviceV = self.portDetail.voltage;
         self.$modal.closeLoading();
       }
       if(type == 116){
@@ -471,7 +540,11 @@ export default {
         self.uuid = real_data.substr(0,6);
       }
       self.$forceUpdate();
-      console.log('收到服务器内容:' + JSON.stringify(data));
+      if(!flag){
+        console.log('收到服务器内容:' + JSON.stringify(data));
+      }
+      console.log("当前对象内容")
+      console.log(self.portDetail)
       if(!this.firstInit){
         this.firstInit = true;
         let autoCharge = self.getAutoChargeValue()
@@ -511,10 +584,10 @@ export default {
         if(data != null){
           let planType = data.planType;
           if(planType == 1){//单次预约
-              let planInfo = {};
-              planInfo.runTime = data.runTime;
-              this.planInfo = planInfo;
-              this.planInfo.id = data.id;
+            let planInfo = {};
+            planInfo.runTime = data.runTime;
+            this.planInfo = planInfo;
+            this.planInfo.id = data.id;
           }else{
             let planInfo = {};
             planInfo.runTime = data.runTime;
@@ -522,10 +595,10 @@ export default {
             let days = repeatDays.split(",")
             let strs = "";
             for (let i = 0; i < days.length; i++) {
-                if(strs.length>0){
-                  strs+=",";
-                }
-                strs +=this.days[days[i]];
+              if(strs.length>0){
+                strs+=",";
+              }
+              strs +=this.days[days[i]];
             }
             this.planInfo = planInfo;
             this.planInfo.runTime = strs+" "+data.repeatTime;
@@ -577,7 +650,7 @@ export default {
       let portStatus = this.portDetail.portStatus;
       if(portStatus == 2){//需要停止充电
         this.$modal.confirm("需要停止充电么?").then(res=>{
-              this.stopCharge();
+          this.stopCharge();
         })
       }else{
         if(portStatus == 1){
@@ -593,27 +666,37 @@ export default {
 
       }
     },
-   getInfo(flag) {
-
-      // let str = "AA 67 0D 01 00 00 00 00 00 00 00 00 00 25 E2 00 80";
-      // let data = parseDataObj(str);
-      // this.messageCallback(data);
-     //
-     //
-     this.$modal.loading("正在获取状态,请稍等...");
-     if(flag){
+    getInfo(flag) {
+      let self = this;
+      // setTimeout(function (){
+      //   self.messageCallback({"type":103,"real_data":{"port_first_status":1,"power":0,"elec":0,"money":0,"time":0,"port_second_status":2,"power_1":0,"elec_1":3,"money_1":50000,"time_1":367,"dev_temper":17,"voltage":228,"":249,"portStatus":1,"currentValue":"0.0"}})
+      //
+      // },50);
+      //
+      // setTimeout(function (){
+      //   self.messageCallback({"type":103,"real_data":{"port_first_status":1,"power":0,"elec":0,"money":0,"time":0,"port_second_status":2,"power_1":0,"elec_1":3,"money_1":50000,"time_1":367,"dev_temper":17,"voltage":228,"":249,"portStatus":1,"currentValue":"0.0"}})
+      //
+      // },150);
+      //
+      // setTimeout(function (){
+      //   self.messageCallback({"type":103,"real_data":{"port_first_status":1,"power":0,"elec":0,"money":0,"time":0,"port_second_status":2,"power_1":0,"elec_1":3,"money_1":50000,"time_1":367,"dev_temper":17,"voltage":228,"":249,"portStatus":1,"currentValue":"0.0"}})
+      //
+      // },250);
+
+      this.$modal.loading("正在获取状态,请稍等...");
+      if(flag){
         setTimeout(function (){
           sendPortDetailCmd().then(res => {
 
           })
         },500)
-     }else{
-       sendPortDetailCmd().then(res => {
+      }else{
+        sendPortDetailCmd().then(res => {
 
-       })
-     }
+        })
+      }
 
-  },
+    },
     stopCharge(){
       let self = this;
       this.deviceInfo.port = this.choosePort;
@@ -638,17 +721,17 @@ export default {
       this.startPortDetailTimer();
     },
     startPortDetailTimer(){
-     let self = this;
+      let self = this;
       this.timer = setTimeout(function (){
         getPortDetail(self.deviceInfo,self.visitTime).then(res=>{
-         let data = res.data;
-         if(data != null){
-           self.portDetail = data;
-           self.checkStatusCheck();
-           self.$modal.closeLoading();
-         }else{
-           self.startPortDetailTimer();
-         }
+          let data = res.data;
+          if(data != null){
+            self.portDetail = data;
+            self.checkStatusCheck();
+            self.$modal.closeLoading();
+          }else{
+            self.startPortDetailTimer();
+          }
         });
       },1000);
     },
@@ -677,9 +760,9 @@ export default {
     statusChangeTimer(){
       let self = this;
       this.statusTimer = setTimeout(function(){
-       if(!this.checkOnPage()){
-         return;
-       }
+        if(!this.checkOnPage()){
+          return;
+        }
         checkStatusChange(self.deviceInfo,self.visitTime).then(res=>{
           let data = res.data;
           if(data != null){
@@ -872,7 +955,7 @@ export default {
   width: 90%;
 }
 .body-bottom{
-padding:0 22px;
+  padding:0 22px;
 }
 .body-bottom .info-content{
   width: 30%;
@@ -1199,4 +1282,14 @@ padding:0 22px;
   text-align: center;
   z-index: 9999;
 }
+.port_item{
+  color: #1A87FF;
+  padding: 5px;
+  border: 1px solid #1A87FF;
+}
+.selected_item{
+  color: white !important;
+  padding: 5px;
+  background: #1A87FF !important;
+}
 </style>

+ 80 - 71
utils/weitiandi/device/device.js

@@ -146,7 +146,7 @@ function sendData(arr){
 
 function changeArr(arr){
     const hexArr = arr.map(num => {
-       let str = num.toString(16); // 将每个数字转换为16进制字符串
+        let str = num.toString(16); // 将每个数字转换为16进制字符串
         if(str.length == 1){
             return "0"+str.toUpperCase();
         }else{
@@ -157,10 +157,10 @@ function changeArr(arr){
 }
 
 const dataParser = {
-/**
- *     "data":[170,96,33,1,8,244,1,231,3,1,208,32,7,9,5,22,8,0,0,0,5,128,12,0,0,0,0,12,15,18,8,7,8,7,8,7,120]
- *     "real_data":{"card_avail":1,"peak_price":8,"cost":500,"time_limit":999,"fee_type":1,"max_power":8400,"peak_service_price":7,"volume":9,"bottom_price":5,"botton_end":22,"bottom_start":8,"qr_id_low":0,"qr_id_middle":0,"qr_id_high":0,"bottom_service_price":5,"max_current":3200,"cp_check_off":0,"fee_show_off":0,"time1_end":12,"time2_end":15,"time3_end":18,"time1_price":8,"time1_price_service":7,"time2_price":8,"time2_sercie_price":7,"time3_price":8,"time3_service_price":7},"type":96}
- */
+    /**
+     *     "data":[170,96,33,1,8,244,1,231,3,1,208,32,7,9,5,22,8,0,0,0,5,128,12,0,0,0,0,12,15,18,8,7,8,7,8,7,120]
+     *     "real_data":{"card_avail":1,"peak_price":8,"cost":500,"time_limit":999,"fee_type":1,"max_power":8400,"peak_service_price":7,"volume":9,"bottom_price":5,"botton_end":22,"bottom_start":8,"qr_id_low":0,"qr_id_middle":0,"qr_id_high":0,"bottom_service_price":5,"max_current":3200,"cp_check_off":0,"fee_show_off":0,"time1_end":12,"time2_end":15,"time3_end":18,"time1_price":8,"time1_price_service":7,"time2_price":8,"time2_sercie_price":7,"time3_price":8,"time3_service_price":7},"type":96}
+     */
     mainboard:'CARD_AVAIL\n' +
         'PEAK_PRICE\n' +
         'COST 2\n' +
@@ -204,6 +204,13 @@ const dataParser = {
             'VOLTAGE\n' +
             'DEV_TEMPER\n' +
             'WIRE_TEMPER',
+        morlsingle2:'PORT_FIRST_STATUS\n' +
+            'POWER 2\n' +
+            'ELEC 2\n' +
+            'MONEY 2\n' +
+            'TIME 2\n' +
+            'DEV_TEMPER\n' +
+            'VOLTAGE' ,
         double:'PORT_FIRST_STATUS\n' +
             'POWER 2\n' +
             'ELEC 2\n' +
@@ -235,16 +242,19 @@ function parseData(arr){
     let type = arr[1];
     let str = "";
     if(type == 96){//主板
-         str = dataParser.mainboard;
+        str = dataParser.mainboard;
     }
     if(type == 103){
-      let len =  arr[2];
+        let len =  arr[2];
         if(len == 18){
             str = dataParser.portdetail.double;
         }
         if(len == 9){
             str = dataParser.portdetail.single;
         }
+        if(len == 11){
+            str = dataParser.portdetail.morlsingle2;
+        }
         if(len == 13){
             str = dataParser.portdetail.morlsingle;
         }
@@ -266,8 +276,7 @@ function parseData(arr){
     let obj = parseProp(arr,str);
     data.type = type;
     data.real_data = obj;
-    console.log(data);
-   return data;
+    return data;
 }
 function parseUUID(arr){
     let str = "";
@@ -314,34 +323,34 @@ function parseProp(arr,str){
  * @return
  */
 function cmdToDec(cmds) {
-  if (!cmds) {
-    return -1;
-  }
-  let len = cmds.length;
-  if (len === 1) {
-    return cmds[0];
-  } else if (len === 2) {
-    let first = cmds[0];
-    let second = cmds[1];
-    let firstStr = addZero(first.toString(2));
-    let secondStr = addZero(second.toString(2));
-    let allStr = secondStr + firstStr;
-    let i = parseInt(allStr, 2);
-    return i;
-  } else if (len === 4) {
-    let first = cmds[0];
-    let second = cmds[1];
-    let third = cmds[2];
-    let forth = cmds[3];
-    let firstStr = addZero(first.toString(2));
-    let secondStr = addZero(second.toString(2));
-    let thirdStr = addZero(third.toString(2));
-    let forthStr = addZero(forth.toString(2));
-    let allStr = forthStr + thirdStr + secondStr + firstStr;
-    let i = parseInt(allStr, 2);
-    return i;
-  }
-  return 0;
+    if (!cmds) {
+        return -1;
+    }
+    let len = cmds.length;
+    if (len === 1) {
+        return cmds[0];
+    } else if (len === 2) {
+        let first = cmds[0];
+        let second = cmds[1];
+        let firstStr = addZero(first.toString(2));
+        let secondStr = addZero(second.toString(2));
+        let allStr = secondStr + firstStr;
+        let i = parseInt(allStr, 2);
+        return i;
+    } else if (len === 4) {
+        let first = cmds[0];
+        let second = cmds[1];
+        let third = cmds[2];
+        let forth = cmds[3];
+        let firstStr = addZero(first.toString(2));
+        let secondStr = addZero(second.toString(2));
+        let thirdStr = addZero(third.toString(2));
+        let forthStr = addZero(forth.toString(2));
+        let allStr = forthStr + thirdStr + secondStr + firstStr;
+        let i = parseInt(allStr, 2);
+        return i;
+    }
+    return 0;
 }
 function sendBlueData(tempSendData){
     let data = tempSendData
@@ -360,13 +369,13 @@ function sendBlueData(tempSendData){
  * @return
  */
 function addZero(value) {
-  let len = value.length;
-  if (len < 8) {
-    for (let i = 0; i < 8 - len; i++) {
-      value = "0" + value;
+    let len = value.length;
+    if (len < 8) {
+        for (let i = 0; i < 8 - len; i++) {
+            value = "0" + value;
+        }
     }
-  }
-  return value;
+    return value;
 }
 
 /**
@@ -375,31 +384,31 @@ function addZero(value) {
  * @return
  */
 function decToCmd(value) {
-  let cmds = null;
-  if (value <= 255) { //两位
-    cmds = [value];
-  } else if (value <= 65535) {
-    cmds = new Array(2);
-    let valueStr = value.toString(2);
-    let len = valueStr.length;
-    let lastEight = valueStr.substring(len - 8, len);
-    let firstEight = valueStr.substring(0, len - 8);
-    cmds[0] = parseInt(lastEight, 2);
-    cmds[1] = parseInt(firstEight, 2);
-  } else {
-    cmds = new Array(4);
-    let valueStr = value.toString(2);
-    let len = valueStr.length;
-    let lastEight = valueStr.substring(len - 8, len);
-    let firstEight = valueStr.substring(len - 16, len - 8);
-    let secondEight = valueStr.substring(len - 24, len - 16);
-    let thirdEight = valueStr.substring(0, len - 24);
-    cmds[0] = parseInt(lastEight, 2);
-    cmds[1] = parseInt(firstEight, 2);
-    cmds[2] = parseInt(secondEight, 2);
-    cmds[3] = parseInt(thirdEight, 2);
-  }
-  return cmds;
+    let cmds = null;
+    if (value <= 255) { //两位
+        cmds = [value];
+    } else if (value <= 65535) {
+        cmds = new Array(2);
+        let valueStr = value.toString(2);
+        let len = valueStr.length;
+        let lastEight = valueStr.substring(len - 8, len);
+        let firstEight = valueStr.substring(0, len - 8);
+        cmds[0] = parseInt(lastEight, 2);
+        cmds[1] = parseInt(firstEight, 2);
+    } else {
+        cmds = new Array(4);
+        let valueStr = value.toString(2);
+        let len = valueStr.length;
+        let lastEight = valueStr.substring(len - 8, len);
+        let firstEight = valueStr.substring(len - 16, len - 8);
+        let secondEight = valueStr.substring(len - 24, len - 16);
+        let thirdEight = valueStr.substring(0, len - 24);
+        cmds[0] = parseInt(lastEight, 2);
+        cmds[1] = parseInt(firstEight, 2);
+        cmds[2] = parseInt(secondEight, 2);
+        cmds[3] = parseInt(thirdEight, 2);
+    }
+    return cmds;
 }
 //parseData([170,103,18,1,0,0,54,5,0,0,0,0,2,241,25,67,3,75,0,77,0,159])
 export function sendPortDetailCmd(){
@@ -550,7 +559,7 @@ function doResetTime(delay){
 
 
 function test(){
-    let data = 'AA,67,14,02,00,00,00,00,50,C3,08,00,02,00,00,00,00,50,C3,14,00,15,E3,B9';
+    let data = 'AA,67,0B,02,00,00,15,00,4E,C3,2B,00,1C,E8,C9';
     data = data.trim();
     data = data.split(",");
 
@@ -559,7 +568,7 @@ function test(){
         arr.push(parseInt(data[i],16)) ;
     }
     console.log(arr)
-    parseData(arr)
+    console.log( parseData(arr))
 }
 
 function testQueue(){
@@ -567,5 +576,5 @@ function testQueue(){
         sendBlueData(i+"");
     }
 }
-// testQueue()
+// test()