ソースを参照

todo
版本检测
蓝牙功能

wzh 2 年 前
コミット
303e6fc49b

+ 13 - 1
locale/en.json

@@ -118,7 +118,19 @@
     "检测到有新版本,请点击下载": "A new version has been detected. Please click to download",
     "立即下载": "Download now",
     "文件下载中,请稍后......": "The file is downloading. Please wait...",
-	"版本":"Version"
+	"版本":"Version",
+    "连接失败":"Connected fail",
+    "密码不能设置为000000": "The  password cannot be '000000'",
+    "密码不能设置为123456": "The  password cannot be '123456'",
+    "设备序列号": "Device No",
+    "请保存好设备序列号。可用于找回密码": "Please save the device no to find the password",
+    "忘记密码": "Forget password",
+    "正在读取设备ID": "Getting the device no",
+    "重置密码": "Reset password",
+    "请输入序列号": "Please input the device no",
+    "密码将被重置为123456": "The password will be '123456'",
+    "序列号有误": "The device no is wrong",
+    "当前密码为初始密码,请修改": "Please change the pawssword"
   },
   "locale.auto": "System",
   "locale.en": "English",

+ 99 - 20
pages/bluetooth/index/index.vue

@@ -16,12 +16,32 @@
 		</view>
     <u-modal :show="showPwd" :confirmText="i18('确认')" :cancelText="i18('取消')" @confirm="inputPwd" @cancel="cancel" :showCancelButton="true"  :title="$t('buletooth.pwdinput')" >
       <view class="slot-content">
-        <u--input
-            type="number"
-            :placeholder="$t('buletooth.pwdtip')"
-            border="surround"
-            v-model="pwd"
-        ></u--input>
+        <view>
+          <u--input
+              type="number"
+              :placeholder="$t('buletooth.pwdtip')"
+              border="surround"
+              v-model="pwd"
+          ></u--input>
+        </view>
+
+        <view style="margin:10px;text-decoration: underline;margin-bottom: 0px" @click="forgetPwd">
+          {{i18('忘记密码')}}?
+        </view>
+      </view>
+    </u-modal>
+
+    <u-modal :show="showDeviceNo" :confirmText="i18('确认')" :cancelText="i18('取消')" @confirm="resetPwd" @cancel="cancel" :showCancelButton="true"  :title="i18('重置密码')" >
+      <view class="slot-content">
+        <view>
+          <u--input
+              type="number"
+              :placeholder="i18('请输入序列号')"
+              border="surround"
+              v-model="inputDeviceNo"
+          ></u--input>
+        </view>
+
       </view>
     </u-modal>
 		<view v-if="deviceListDataShow.length==0" class="notice"> - {{ $t('buletooth.nodevice') }} -</view>
@@ -32,7 +52,7 @@
 </template>
 
 <script>
-import {getPwd,setPwd,parsePwd,sendPortDetailCmd} from "@/utils/weitiandi/device/device.js";
+import {getPwd,setPwd,parsePwd,sendPortDetailCmd,getUUID,parseDataObj} from "@/utils/weitiandi/device/device.js";
 // #ifdef APP
 import ecUI from '@/utils/ecUI.js'
 import ecBLE from '@/utils/ecBLE/ecBLE.js'
@@ -54,6 +74,10 @@ import i18 from '@/utils/i18.js'
         buleid:"",
 				deviceListDataShow: [],
         showTimer:null,
+        connected:false,
+        uuid:"",
+        showDeviceNo:false,
+        inputDeviceNo:""
 			}
 		},
 		onLoad() {
@@ -88,6 +112,29 @@ import i18 from '@/utils/i18.js'
         uni.navigateBack({
         });
       },
+      resetPwd(){
+        let self = this;
+        if(!this.inputDeviceNo){
+          self.$modal.showToast("请输入序列号");
+          return;
+        }
+        if(this.uuid != this.inputDeviceNo){
+          self.$modal.showToast("序列号有误");
+          return;
+        }
+        if(this.uuid == this.inputDeviceNo){
+          this.$modal.confirm("密码将被重置为123456").then(res=>{
+            setPwd("123456")
+            self.$modal.showToast("密码修改成功");
+            this.rightPwd = "123456";
+            self.loginSuccess();
+          });
+        }
+      },
+      goBack(){
+        uni.navigateBack({
+        });
+      },
       inputPwd(){
         if(!this.pwd ){
           this.$modal.showToast(this.$t('buletooth.nopwd'));
@@ -102,6 +149,7 @@ import i18 from '@/utils/i18.js'
       },
       loginSuccess(){
         this.showPwd = false;
+        this.showDeviceNo = false;
         uni.setStorageSync("pwd",this.rightPwd);
         uni.setStorageSync('blueid', this.buleid);
         this.pwd = "";
@@ -120,6 +168,7 @@ import i18 from '@/utils/i18.js'
 				ecBLE.onBLEConnectionStateChange(res => {
           console.log(res);
 					if (res.ok) {
+            self.connected = true;
             setTimeout(function(){
               ecUI.hideLoading()
               getPwd();
@@ -143,33 +192,63 @@ import i18 from '@/utils/i18.js'
           let isCheckRevHex = true;
           let data =
               (isCheckRevHex ? strHex.replace(/[0-9a-fA-F]{2}/g, ' $&') : str)
-          // console.log(data)
+          console.log(data)
           self.$modal.closeLoading();
-          console.log("settting:"+data);
-          //AA 67 0D 05 00 00 00 00 00 00 00 00 00 25 E2 00 80
-          let pwd =  parsePwd(data);
-          let localPwd = self.getLocalPwd()
-          console.log("pwd:"+pwd);
-          console.log("localPwd:"+localPwd)
-          self.rightPwd = pwd;
-          if(pwd != localPwd){
-            self.showInputPwd();
+          data = parseDataObj(data);
+		  console.log(data);
+          let type = data.type;
+          if(type == 253){
+            self.messageCallback(data)
           }else{
-            self.loginSuccess();
+            let pwd =  data.real_data;
+            let localPwd = self.getLocalPwd()
+            console.log("pwd:"+pwd);
+            console.log("localPwd:"+localPwd)
+            self.rightPwd = pwd;
+            if(pwd != localPwd){
+              self.showInputPwd();
+            }else{
+              self.loginSuccess();
+            }
           }
+
         })
-				ecBLE.createBLEConnection(id)
+        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) {
-						console.log('Bluetooth adapter ok')
             let blueid = uni.getStorageSync('blueid');
+            console.log('Bluetooth adapter ok,blueid:'+blueid)
             if(blueid){
               self.listViewTap(blueid);
             }else{

+ 33 - 29
pages/login.vue

@@ -181,35 +181,39 @@
       downloadFile(){
         let self = this;
         let downUrl = self.downloadUrl;
-        self.isShowProgress = true;
-        const downloadTask = uni.downloadFile({
-          url: self.downloadUrl,
-          success: res => {
-            if (res.statusCode === 200) {
-              this.isShowProgress = false;
-              console.log('下载成功');
-            }
-            let that = this;
-            plus.runtime.install(res
-                    .tempFilePath, {
-                  force: false
-                },
-                function() {
-                  plus.runtime
-                      .restart();
-                });
-          }
-        })
-        console.log(downloadTask)
-        downloadTask.onProgressUpdate((res) => {
-          if(res.progress > 0) {
-            this.isShowProgress = true;
-          }
-          this.progress = res.progress;
-          console.log('下载进度:' + res.progress);
-          console.log('已下载长度:' + res.totalBytesWritten);
-          console.log('文件总长度:' + res.totalBytesExpectedToWrite);
-        })
+        if(true){
+          plus.runtime.openURL(downUrl);
+          return;
+        }
+        // self.isShowProgress = true;
+        // const downloadTask = uni.downloadFile({
+        //   url: self.downloadUrl,
+        //   success: res => {
+        //     if (res.statusCode === 200) {
+        //       this.isShowProgress = false;
+        //       console.log('下载成功');
+        //     }
+        //     let that = this;
+        //     plus.runtime.install(res
+        //             .tempFilePath, {
+        //           force: false
+        //         },
+        //         function() {
+        //           plus.runtime
+        //               .restart();
+        //         });
+        //   }
+        // })
+        // console.log(downloadTask)
+        // downloadTask.onProgressUpdate((res) => {
+        //   if(res.progress > 0) {
+        //     this.isShowProgress = true;
+        //   }
+        //   this.progress = res.progress;
+        //   console.log('下载进度:' + res.progress);
+        //   console.log('已下载长度:' + res.totalBytesWritten);
+        //   console.log('文件总长度:' + res.totalBytesExpectedToWrite);
+        // })
       },
       checkVersion(){
         let appBaseInfo = uni.getAppBaseInfo();

+ 63 - 2
pages/weitiandi/bluetooth/status.vue

@@ -142,11 +142,40 @@
 
       </view>
     </u-modal>
+
+    <u-modal :show="showInitPwd" :confirmText="i18('确认')" :cancelText="i18('取消')" @confirm="inputPwd" @cancel="cancel" :showCancelButton="true"  :title="i18('当前密码为初始密码,请修改')" >
+      <view class="slot-content">
+        <view style="margin-bottom:10px;">
+          {{i18('请保存好设备序列号。可用于找回密码')}}
+        </view>
+        <view style="margin-bottom:10px;text-decoration: underline" @click="copyPwd">
+          {{i18('设备序列号')}} :{{uuid}}
+        </view>
+        <view>
+          <u--input
+              type="number"
+              :placeholder="$t('charge.oldpwd')"
+              border="surround"
+              v-model="oldPwd"
+          ></u--input>
+        </view>
+
+        <view style="margin-top:5px">
+          <u--input
+              type="number"
+              :placeholder="$t('charge.newpwd')"
+              border="surround"
+              v-model="pwd"
+          ></u--input>
+        </view>
+
+      </view>
+    </u-modal>
   </view>
 </template>
 
 <script>
-import {getDeviceInfo,getPortDetail,startCharge,stopCharge,sendPortDetailCmd,checkStatusChange,getPlanInfo,cancelPlan,parseDataObj,planCharge,getPwd,setPwd} from "@/utils/weitiandi/device/device.js";
+import {getDeviceInfo,getPortDetail,startCharge,stopCharge,sendPortDetailCmd,checkStatusChange,getPlanInfo,cancelPlan,parseDataObj,planCharge,getPwd,setPwd,getUUID} from "@/utils/weitiandi/device/device.js";
 // #ifdef APP
 import ecUI from '@/utils/ecUI.js'
 import ecBLE from '@/utils/ecBLE/ecBLE.js'
@@ -188,6 +217,9 @@ export default {
      firstInit:false,
      hasRight:false,
      startAutoCharge:true,
+     initPwd:"123456",
+     showInitPwd:false,
+     uuid:"",
    }
  },
  computed: {
@@ -211,6 +243,14 @@ export default {
    this.closeSocket();
   },
   methods: {
+    copyPwd(){
+      uni.setClipboardData({
+        data: this.uuid,
+        success: function () {
+          this.$modal.showToast("复制成功");
+        }
+      });
+    },
    i18(text){
      return i18(text)
    },
@@ -234,13 +274,23 @@ export default {
       if(rightPwd != this.oldPwd){
         this.$modal.showToast("原密码不对");
         return;
+      }
+      if(this.pwd == "000000"){
+        this.$modal.showToast("密码不能设置为000000");
+        return;
+      }
+      if(this.pwd == "123456"){
+        this.$modal.showToast("密码不能设置为123456");
+        return;
       }
         if(!this.pwd){
           this.$modal.showToast("密码不能为空");
         }else {
           setPwd(this.pwd);
           this.$modal.showToast("密码修改成功");
-          this.goBack();
+          this.showPwd = false;
+          this.showInitPwd = false;
+          // this.goBack();
         }
 
     },
@@ -313,6 +363,13 @@ export default {
       }
     },
     checkPassword(){
+      let rightPwd = uni.getStorageSync("pwd");
+      if(rightPwd === this.initPwd){
+        this.showInitPwd = true;
+        this.$modal.loading("正在读取设备ID");
+        this.oldPwd = rightPwd;
+        getUUID();
+      }
     },
     recon(){
       let self = this;
@@ -406,6 +463,10 @@ export default {
       }
       if(type == 96){
       }
+      if(type == 253){
+        self.$modal.closeLoading();
+        self.uuid = real_data.substr(0,6);
+      }
       self.$forceUpdate();
       console.log('收到服务器内容:' + JSON.stringify(data));
       if(!this.firstInit){

+ 28 - 6
utils/weitiandi/device/device.js

@@ -218,12 +218,37 @@ function parseData(arr){
             str = dataParser.portdetail.morlsingle;
         }
     }
-    let obj = parseProp(arr,str);
     let data = {};
+    if(type == 253){
+        data.type = type;
+        data.real_data = parseUUID(arr);
+        return data;
+    }
+    if(type == 172){
+        data.type = type;
+        data.real_data = parsePwd(arr);
+        return data;
+    }
+    let obj = parseProp(arr,str);
     data.type = type;
     data.real_data = obj;
    return data;
 }
+function parseUUID(arr){
+    let str = "";
+    for (let i = 2; i < arr.length; i++) {
+        let key = arr[i]+"";
+        if(key.length == 1){
+            key = "00"+key;
+        }
+        if(key.length == 2){
+            key = "0"+key;
+        }
+        str = str+""+key;
+    }
+    return str;
+}
+
 function parseProp(arr,str){
     let obj = {};
     let keys = str.split("\n")
@@ -361,9 +386,6 @@ export function parseDataObj(data){
     return parseData(arr)
 }
 export function parsePwd(data){
-    data = data.trim();
-    data = data.split(" ");
-    console.log(data)
     let pwd = "";
     for (let i = 3; i < 9; i++) {
         pwd = pwd+""+parseInt(data[i],16) ;
@@ -447,7 +469,7 @@ export function getUUID(){
 }
 
 function test(){
-   console.log( parseDataObj("AA 67 0D 05 00 00 00 00 00 00 00 00 00 25 E2 00 80"))
+   console.log( parseDataObj("AA AC 06 01 01 01 01 01 01 B8"))
 }
-// test()
+test()