From b83e8417c341636a6da3a8eb7db7c151ef3c00cd Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期二, 04 十一月 2025 15:34:40 +0800
Subject: [PATCH] 巡查菜单权限设置
---
src/pages/index/index.vue | 125 +++++++++++++++++++++++++++++++++++++++--
1 files changed, 119 insertions(+), 6 deletions(-)
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 844ab8b..4e045ba 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -18,8 +18,8 @@
</wd-notice-bar>
<!-- 蹇嵎瀵艰埅 -->
<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 v-for="(item, index) in navList" :key="index">
+ <wd-grid-item v-if="item.show" use-slot link-type="navigateTo" :url="item.url">
<view class="p-2">
<image class="w-72rpx h-72rpx rounded-8rpx" :src="item.icon" />
</view>
@@ -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">
@@ -80,11 +87,12 @@
</template>
<script setup lang="ts">
-import { reactive } from "vue";
-import { dayjs } from "wot-design-uni";
+import { reactive, computed } 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";
+import { useUserStore } from "@/store/modules/user";
const visitStatsData = ref<VisitStatsVO>({
todayUvCount: 0,
@@ -93,6 +101,31 @@
todayPvCount: 0,
pvGrowthRate: 0,
totalPvCount: 0,
+});
+
+const message = useMessage();
+const toast = useToast();
+
+// 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛淇℃伅
+const userStore = useUserStore();
+const userInfo: any = computed(() => userStore.userInfo);
+
+// 鍒ゆ柇鏄惁涓哄贰妫�鍛樿鑹�
+const isInspector = computed(() => {
+ if (!userInfo.value || !userInfo.value.roles || !Array.isArray(userInfo.value.roles)) {
+ return false;
+ }
+ console.log(
+ "userInfo.value.roles",
+ userInfo.value.roles.some((role: any) => role.roleKey === "qualitative-inspector")
+ );
+ return userInfo.value.roles.some((role: any) => role.roleKey === "qualitative-inspector");
+});
+
+const fileProgress = reactive({
+ show: false,
+ progress: 0,
+ status: undefined,
});
// 鍥捐〃鏁版嵁
@@ -161,6 +194,12 @@
url: "/pages/timely/index",
show: false,
},
+ {
+ icon: "/static/icons/routingInspection.png",
+ title: "宸℃",
+ url: "/pages/routingInspection/index",
+ show: false,
+ },
]);
// 鍔犺浇璁块棶缁熻鏁版嵁
@@ -207,12 +246,74 @@
};
const init = async () => {
+ checkVersion();
const { data } = await HomeApi.getIndex();
- if (data.deviceGroupName == "鏃舵晥缁�") {
+
+ // 鍒ゆ柇鏄惁涓哄贰妫�鍛樿鑹�
+ if (isInspector.value) {
+ // 濡傛灉鏄贰妫�鍛橈紝鏄剧ず宸℃鑿滃崟
+ navList[2].show = true;
+ } else 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 +338,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