From 95b85a1942d41541025ec781f16b229108f75e65 Mon Sep 17 00:00:00 2001
From: 曹睿 <360930172@qq.com>
Date: 星期三, 02 七月 2025 09:38:00 +0800
Subject: [PATCH] feat: PDA添加增量更新
---
src/pages/index/index.vue | 89 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 844ab8b..2df7101 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -27,7 +27,14 @@
</wd-grid-item>
</view>
</wd-grid>
-
+ <wd-message-box />
+ <wd-popup v-model="fileProgress.show" custom-style="width: 300px; border-radius: 32rpx;">
+ <view class="download_box">
+ <view class="download_box_title">涓嬭浇涓�...</view>
+ <wd-progress :percentage="fileProgress.progress" hide-text :status="fileProgress.status" />
+ </view>
+ </wd-popup>
+ <wd-toast />
<!-- 鏁版嵁缁熻 -->
<!-- <wd-grid :column="2" :gutter="2">
<wd-grid-item use-slot custom-class="custom-item">
@@ -81,7 +88,7 @@
<script setup lang="ts">
import { reactive } from "vue";
-import { dayjs } from "wot-design-uni";
+import { dayjs, useMessage, useToast } from "wot-design-uni";
import LogAPI, { VisitStatsVO } from "@/api/system/log";
import WorkerCallingCard from "@/components/worker-calling-card/index.vue";
import HomeApi from "@/api/home";
@@ -93,6 +100,15 @@
todayPvCount: 0,
pvGrowthRate: 0,
totalPvCount: 0,
+});
+
+const message = useMessage();
+const toast = useToast();
+
+const fileProgress = reactive({
+ show: false,
+ progress: 0,
+ status: undefined,
});
// 鍥捐〃鏁版嵁
@@ -207,12 +223,69 @@
};
const init = async () => {
+ checkVersion();
const { data } = await HomeApi.getIndex();
if (data.deviceGroupName == "鏃舵晥缁�") {
navList[1].show = true;
} else {
navList[0].show = true;
}
+};
+
+/**
+ * @description 妫�鏌ョ増鏈彿
+ */
+const checkVersion = async () => {
+ const systemInfo = uni.getSystemInfoSync();
+ const { code, data } = await HomeApi.getVersion({ version: systemInfo.appVersion });
+ if (code == 200 && data.isUpdate) {
+ message
+ .confirm({
+ title: "鍙戠幇鏂扮増鏈�",
+ confirmButtonText: "涓嬭浇",
+ cancelButtonText: "蹇界暐",
+ })
+ .then(() => {
+ downloadApk(data.url, data.fileSize);
+ })
+ .catch(() => {});
+ }
+};
+
+/**
+ * @desc 鍙戣捣涓嬭浇APK
+ */
+const downloadApk = (url: string, fileSize: number) => {
+ fileProgress.show = true;
+ let dtask: any = downloadFile(url);
+ // 涓嬭浇浠诲姟寮�濮嬩笅杞�
+ dtask.start();
+ // 鍏充簬杩涘害鐨勮幏鍙栨槸浣跨敤瀹氭椂鍣ㄤ笉鏂幏鍙栧凡缁忎笅杞界殑鏂囦欢鐨勫ぇ灏忥紝鍐嶅姣旀�诲ぇ灏忓嵆鍙�
+ let timer = setInterval(() => {
+ let percent: any = (dtask.downloadedSize / fileSize).toFixed(2); // fileSize鏂囦欢鎬诲ぇ灏忥紝鍚庣杩斿洖鐨�
+ console.log("鍙戣捣涓嬭浇APK", dtask.downloadedSize);
+ fileProgress.progress = Math.floor(percent * 100); // 杞垚鏁存暟灞曠ず
+ if (percent >= 1) {
+ // 娉ㄦ剰鐧惧垎姣旓紝鍙婃椂娓呴櫎瀹氭椂鍣ㄥ嵆鍙�
+ clearInterval(timer);
+ fileProgress.show = false;
+ }
+ }, 18);
+};
+
+// uniapp涓嬭浇APK瀹炰緥
+const downloadFile = (url: string) => {
+ return plus.downloader.createDownload(url, {}, (d, status) => {
+ console.log(d);
+ if (status == 200) {
+ fileProgress.show = true;
+ plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, (error) => {
+ toast.error("瀹夎澶辫触");
+ });
+ } else {
+ toast.error("鏇存柊澶辫触");
+ }
+ });
};
onMounted(() => {
@@ -237,4 +310,16 @@
width: 100%;
height: 300px;
}
+.download_box {
+ padding: 24px;
+ .download_box_title {
+ text-align: center;
+ font-size: 16px;
+ color: #000000d9;
+ line-height: 20px;
+ font-weight: 500;
+ padding-top: 5px;
+ padding-bottom: 10px;
+ }
+}
</style>
--
Gitblit v1.9.3