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 |  185 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 142 insertions(+), 43 deletions(-)

diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 152aa6e..2df7101 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -2,37 +2,41 @@
   <view style="width: 100%; height: var(--status-bar-height)" />
   <view class="home">
     <!-- 褰撳墠鐢ㄦ埛 -->
-    <view class="text-[#0D867F] font-medium py-2 text-lg">浜ㄦ椇鐗瑰绾跨紗涓婃姤绯荤粺</view>
+    <view class="flex items-center justify-between">
+      <view class="text-[#0D867F] font-medium py-2 text-lg">
+        <text>浜ㄦ椇鐗瑰绾跨紗涓婃姤绯荤粺</text>
+      </view>
+    </view>
     <WorkerCallingCard />
 
     <!-- 閫氱煡鍏憡 -->
-    <wd-notice-bar
-      text="vue-uniapp-template 鏄竴涓熀浜� Vue3 + UniApp 鐨勫墠绔ā鏉块」鐩紝鎻愪緵浜嗕竴濂楀畬鏁寸殑鍓嶇瑙e喅鏂规锛屽寘鎷櫥褰曘�佹潈闄愩�佸瓧鍏搞�佹帴鍙h姹傘�佺姸鎬佺鐞嗐�侀〉闈㈠竷灞�銆佺粍浠跺皝瑁呯瓑鍔熻兘銆�"
-      custom-class="space"
-    >
+    <wd-notice-bar text="杩欐槸涓�鏉℃祴璇曢�氱煡鐨勬暟鎹�" custom-class="space">
       <template #prefix>
         <wd-icon class="prefix" name="warn-bold" size="14px"></wd-icon>
         <text class="text-xs">閫氱煡</text>
       </template>
     </wd-notice-bar>
     <!-- 蹇嵎瀵艰埅 -->
-    <wd-grid clickable :column="4" class="mt-2">
-      <wd-grid-item
-        v-for="(item, index) in navList"
-        :key="index"
-        use-slot
-        link-type="navigateTo"
-        :url="item.url"
-      >
-        <view class="p-2">
-          <image class="w-72rpx h-72rpx rounded-8rpx" :src="item.icon" />
-        </view>
-        <view class="text">{{ item.title }}</view>
-      </wd-grid-item>
+    <wd-grid clickable :column="1" class="mt-2">
+      <view v-for="(item, index) in navList">
+        <wd-grid-item v-if="item.show" :key="index" use-slot link-type="navigateTo" :url="item.url">
+          <view class="p-2">
+            <image class="w-72rpx h-72rpx rounded-8rpx" :src="item.icon" />
+          </view>
+          <view class="text">{{ item.title }}</view>
+        </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 :column="2" :gutter="2">
       <wd-grid-item use-slot custom-class="custom-item">
         <view class="flex justify-start pl-5">
           <view class="flex-center">
@@ -55,9 +59,9 @@
           </view>
         </view>
       </wd-grid-item>
-    </wd-grid>
+    </wd-grid> -->
 
-    <wd-card>
+    <!-- <wd-card>
       <template #title>
         <view class="flex-between">
           <view>璁块棶瓒嬪娍</view>
@@ -78,14 +82,16 @@
       <view class="charts-box">
         <qiun-data-charts type="area" :chartData="chartData" :opts="chartOpts" />
       </view>
-    </wd-card>
+    </wd-card> -->
   </view>
 </template>
 
 <script setup lang="ts">
-import { dayjs } from "wot-design-uni";
+import { reactive } from "vue";
+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";
 
 const visitStatsData = ref<VisitStatsVO>({
   todayUvCount: 0,
@@ -94,6 +100,15 @@
   todayPvCount: 0,
   pvGrowthRate: 0,
   totalPvCount: 0,
+});
+
+const message = useMessage();
+const toast = useToast();
+
+const fileProgress = reactive({
+  show: false,
+  progress: 0,
+  status: undefined,
 });
 
 // 鍥捐〃鏁版嵁
@@ -136,24 +151,31 @@
     icon: "/static/icons/user.png",
     title: "鐢熶骇绠$悊",
     url: "/pages/production/index",
+    show: false,
   },
+  // {
+  //   icon: "/static/icons/role.png",
+  //   title: "瑙掕壊绠$悊",
+  //   url: "/pages/work/role/index",
+  //   prem: "sys:role:query",
+  // },
+  // {
+  //   icon: "/static/icons/notice.png",
+  //   title: "閫氱煡鍏憡",
+  //   url: "/pages/work/notice/index",
+  //   prem: "sys:notice:query",
+  // },
+  // {
+  //   icon: "/static/icons/setting.png",
+  //   title: "绯荤粺閰嶇疆",
+  //   url: "/pages/work/config/index",
+  //   prem: "sys:config:query",
+  // },
   {
-    icon: "/static/icons/role.png",
-    title: "瑙掕壊绠$悊",
-    url: "/pages/work/role/index",
-    prem: "sys:role:query",
-  },
-  {
-    icon: "/static/icons/notice.png",
-    title: "閫氱煡鍏憡",
-    url: "/pages/work/notice/index",
-    prem: "sys:notice:query",
-  },
-  {
-    icon: "/static/icons/setting.png",
-    title: "绯荤粺閰嶇疆",
-    url: "/pages/work/config/index",
-    prem: "sys:config:query",
+    icon: "/static/icons/log.png",
+    title: "鏃舵晥鎶ュ伐",
+    url: "/pages/timely/index",
+    show: false,
   },
 ]);
 
@@ -200,9 +222,74 @@
   loadVisitTrendData();
 };
 
-onReady(() => {
-  loadVisitStatsData();
-  loadVisitTrendData();
+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(() => {
+  init();
 });
 </script>
 
@@ -223,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