wzh 2 rokov pred
rodič
commit
8ecffc613b
3 zmenil súbory, kde vykonal 89 pridanie a 4 odobranie
  1. 9 0
      api/login.js
  2. 4 1
      locale/en.json
  3. 76 3
      pages/login.vue

+ 9 - 0
api/login.js

@@ -41,6 +41,15 @@ export function getInfo() {
   })
 }
 
+// 获取用户详细信息
+export function checkVersion(obj) {
+  return request({
+    'url': '/device/checkVersion?versionCode='+obj.versionCode,
+    data:obj,
+    'method': 'post'
+  })
+}
+
 // 退出方法
 export function logout() {
   return request({

+ 4 - 1
locale/en.json

@@ -114,7 +114,10 @@
     "连接自动充电": "Automatically charges when connected",
     "开启": "Turn On",
     "关闭": "Turn off",
-    "设置成功":"Successfully set"
+    "设置成功":"Successfully set",
+    "检测到有新版本,请点击下载": "A new version has been detected. Please click to download",
+    "立即下载": "Download now",
+    "文件下载中,请稍后......": "The file is downloading. Please wait..."
   },
   "locale.auto": "System",
   "locale.en": "English",

+ 76 - 3
pages/login.vue

@@ -98,11 +98,29 @@
 	</view>
 	</view>
     <u-picker @cancel="cancelLocale" :show="showLocale" keyName="label" :columns="localeList" @confirm="changeLanguage"></u-picker>
+    <u-popup :zoom="false" :show="showStatus" :mask-close-able="false" mode="center" :closeable="false"  border-radius="14" height="150rpx">
+      <view style="margin:20rpx">
+        检测到有新版本,请点击下载
+      </view>
+      <view style="text-align: center;text-decoration: underline;margin:10px" @click="downloadFile">
+        立即下载
+
+      </view>
+
+
+      <view class="progress-container" v-if="isShowProgress">
+        <view class="progress-box">
+          <view class="text">文件下载中,请稍后......</view>
+          <progress :percent="progress" show-info stroke-width="3" />
+        </view>
+      </view>
+    </u-popup>
   </view>
+
 </template>
 
 <script>
-  import getCodeImg from '@/api/login'
+  import {checkVersion} from '@/api/login'
   import {getToken} from "@/utils/auth";
   export default {
     data() {
@@ -124,8 +142,12 @@
 		username: "",
 		password: "",
     locale:"",
-
 		},
+        appVersionCode:"",
+        showStatus:false,
+        downloadUrl:"",
+        isShowProgress:false,
+        progress:0,
 		isLogin: true, // 是否为登录模式
        }
     },
@@ -146,10 +168,61 @@
 				console.log('当前位置的纬度:' + res.latitude);
 			}
 		});
-
+      this.checkVersion();
       this.checkLogin();
     },
     methods: {
+      downloadFile(){
+        let self = this;
+        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();
+                });
+          }
+        })
+
+        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();
+        let appVersionCode = appBaseInfo.appVersionCode;
+        this.appVersionCode = appVersionCode;
+        let self = this;
+        checkVersion({"versionCode":appVersionCode}).then(res=>{
+          let cz_app_version =res.data;
+          if(cz_app_version != null){
+            let onlineVersion = cz_app_version.version;
+            let isForce = cz_app_version.isForce;
+            let url = cz_app_version.downUrl;
+            self.downloadUrl = url;
+            if(onlineVersion>appVersionCode){
+              self.showStatus = true;
+            }
+          }
+        });
+
+      },
       cancelLocale(){
         this.showLocale = false;
       },