Browse Source

Merge branch 'master' of http://192.168.101.4:3000/jiaxiaoqiang/SynthesisManagement

jiaxiaoqiang 10 months ago
parent
commit
a476d8ce04

+ 57 - 57
index.html

@@ -1,66 +1,66 @@
 <!doctype html>
 <html lang="en">
-<head>
-  <meta charset="UTF-8"/>
-  <link href="/favicon.ico" rel="icon"/>
-  <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
-  <meta
-    content="Vue3 + Vite5 + TypeScript5 + Element-Plus 的后台管理模板,配套接口文档和后端源码,vue-element-admin 的 Vue3 版本"
-    name="description"
-  />
-  <meta
-    content="vue,element-plus,typescript,vue-element-admin,vue3-element-admin"
-    name="keywords"
-  />
-  <title>晶格智汇</title>
-</head>
+  <head>
+    <meta charset="UTF-8" />
+    <link href="/favicon.ico" rel="icon" />
+    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
+    <meta
+      content="Vue3 + Vite5 + TypeScript5 + Element-Plus 的后台管理模板,配套接口文档和后端源码,vue-element-admin 的 Vue3 版本"
+      name="description"
+    />
+    <meta
+      content="vue,element-plus,typescript,vue-element-admin,vue3-element-admin"
+      name="keywords"
+    />
+    <title>综合管理平台</title>
+  </head>
 
-<body>
-<div id="app">
-  <div class="loader"></div>
-</div>
-</body>
-<script src="/src/main.ts" type="module"></script>
+  <body>
+    <div id="app">
+      <div class="loader"></div>
+    </div>
+  </body>
+  <script src="/src/main.ts" type="module"></script>
 
-<style>
-  html,
-  body,
-  #app {
-    position: relative;
-    display: flex;
-    align-items: center;
-    justify-content: center;
-    width: 100%;
-    height: 100%;
-  }
+  <style>
+    html,
+    body,
+    #app {
+      position: relative;
+      display: flex;
+      align-items: center;
+      justify-content: center;
+      width: 100%;
+      height: 100%;
+    }
 
-  .loader {
-    position: relative;
-    width: 40px;
-    aspect-ratio: 0.577;
-    overflow: hidden;
-    clip-path: polygon(0 0, 100% 100%, 0 100%, 100% 0);
-    animation: l19 2s infinite linear;
-  }
+    .loader {
+      position: relative;
+      width: 40px;
+      aspect-ratio: 0.577;
+      overflow: hidden;
+      clip-path: polygon(0 0, 100% 100%, 0 100%, 100% 0);
+      animation: l19 2s infinite linear;
+    }
 
-  .loader::before {
-    position: absolute;
-    inset: -150%;
-    content: "";
-    background: repeating-conic-gradient(
-      from 30deg,
-      #ffabab 0 60deg,
-      #abe4ff 0 120deg,
-      #ff7373 0 180deg
-    );
-    animation: inherit;
-    animation-direction: reverse;
-  }
+    .loader::before {
+      position: absolute;
+      inset: -150%;
+      content: "";
+      background: repeating-conic-gradient(
+        from 30deg,
+        #ffabab 0 60deg,
+        #abe4ff 0 120deg,
+        #ff7373 0 180deg
+      );
+      animation: inherit;
+      animation-direction: reverse;
+    }
 
-  @keyframes l19 {
-    100% {
-      transform: rotate(360deg);
+    @keyframes l19 {
+      100% {
+        transform: rotate(360deg);
+      }
     }
-  }
-</style>
+  </style>
 </html>

+ 1 - 0
package.json

@@ -52,6 +52,7 @@
     "echarts": "^5.5.0",
     "element-plus": "^2.6.0",
     "lodash-es": "^4.17.21",
+    "nanoid": "^5.0.7",
     "net": "^1.0.2",
     "nprogress": "^0.2.0",
     "path-browserify": "^1.0.1",

+ 3 - 0
public/version.json

@@ -0,0 +1,3 @@
+{
+  "version": "1.8"
+}

BIN
src/assets/images/deviceScreen.png


BIN
src/assets/images/mainScreen.png


BIN
src/assets/images/qualityScreen.png


BIN
src/assets/images/workScreen.png


+ 2 - 1
src/plugins/permission.ts

@@ -1,12 +1,13 @@
 import router from "@/router";
 import NProgress from "@/utils/nprogress";
-
+import { isNewVersion } from "@/utils/version.js";
 export function setupPermission() {
   // 白名单路由
   const whiteList = ["/login"];
 
   router.beforeEach(async (to, from, next) => {
     NProgress.start();
+    isNewVersion();
     const hasToken = localStorage.getItem("token");
     if (hasToken) {
       if (to.path === "/login") {

+ 40 - 0
src/utils/version.js

@@ -0,0 +1,40 @@
+// utils/version.js
+
+import axios from "axios";
+// 生成一个随机的字符串作为请求的查询参数
+import { nanoid } from "nanoid";
+import { ElMessageBox } from "element-plus";
+
+export async function isNewVersion() {
+  // 构建了一个 URL,用于请求版本信息的 JSON 文件。这个 URL 包括当前页面的主机名和一个随机生成的长度为 10 的字符串作为查询参数。
+  const url = `//${window.location.host}/version.json?id=${nanoid(10)}`;
+  // 使用 Axios 发起了一个 get 请求,获取版本信息的 json 文件。
+  try {
+    const res = await axios.get(url);
+    //   从响应数据中获取了版本号。
+    const version = res.data.version;
+    //   从本地存储中获取了之前保存的版本号
+    const localVersion = localStorage.getItem("version");
+    //   检查本地存储的版本号是否存在且与当前版本号不一致
+    if (localVersion && localVersion !== version) {
+      ElMessageBox.confirm("发现新的版本,请刷新页面后使用!", "系统提示", {
+        confirmButtonText: "立即刷新",
+        // cancelButtonText: this.$t('btn.cancel'),
+        showCancelButton: false,
+        closeOnClickModal: false,
+        type: "warning",
+      })
+        .then(() => {
+          localStorage.setItem("version", version);
+          window.location.reload();
+        })
+        .catch(() => {});
+    } else {
+      // 如果没有发现新版本,则仅将当前版本号保存到本地存储中。
+      // 这段代码的作用是在页面加载时检查是否有新版本可用,如果有新版本则重新加载页面以获取最新版本
+      localStorage.setItem("version", version);
+    }
+  } catch (error) {
+    console.log(error);
+  }
+}

+ 29 - 8
src/views/main/screenEntry.vue

@@ -8,7 +8,7 @@
         class="sys-item"
         @click="gotoScreen(item.routeName)"
       >
-        <img alt="" class="sys-item-img" />
+        <img :src="item.src" class="sys-item-img" />
         <h3 class="sys-item-title">{{ item.name }}</h3>
       </div>
     </div>
@@ -22,11 +22,31 @@ import { useFullscreen } from "@vueuse/core";
 const el = ref<HTMLElement>();
 const { isFullscreen, toggle, enter, exit } = useFullscreen(el);
 const screenData = ref([
-  { name: "综合监控大屏", routeName: "mainScreen" },
-  { name: "质量综合大屏", routeName: "qualityScreen" },
-  { name: "总装车间看板", routeName: "workScreen" },
-  { name: "设备监控看板", routeName: "deviceScreen" },
-  { name: "测试大屏", routeName: "totalScreen" },
+  {
+    name: "综合监控大屏",
+    routeName: "mainScreen",
+    src: new URL("@/assets/images/mainScreen.png", import.meta.url),
+  },
+  {
+    name: "质量综合大屏",
+    routeName: "qualityScreen",
+    src: new URL("@/assets/images/qualityScreen.png", import.meta.url),
+  },
+  {
+    name: "总装车间看板",
+    routeName: "workScreen",
+    src: new URL("@/assets/images/workScreen.png", import.meta.url),
+  },
+  {
+    name: "设备监控看板",
+    routeName: "deviceScreen",
+    src: new URL("@/assets/images/deviceScreen.png", import.meta.url),
+  },
+  {
+    name: "测试大屏",
+    routeName: "totalScreen",
+    src: new URL("@/assets/images/deviceScreen.png", import.meta.url),
+  },
 ]);
 
 const router = useRouter();
@@ -57,8 +77,9 @@ const gotoScreen = (routeName: string) => {
   align-items: center;
 
   .sys-item-img {
-    width: 120px;
-    height: 100px;
+    width: 160px;
+    height: 90px;
+    border-radius: 5px;
   }
 
   .sys-item-title {

+ 26 - 1
vite.config.ts

@@ -1,7 +1,7 @@
 import vue from "@vitejs/plugin-vue";
 import vueJsx from "@vitejs/plugin-vue-jsx";
 import { ConfigEnv, defineConfig, loadEnv, UserConfig } from "vite";
-
+import fs from "fs";
 import AutoImport from "unplugin-auto-import/vite";
 import Components from "unplugin-vue-components/vite";
 import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
@@ -126,6 +126,7 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
         // 指定symbolId格式
         symbolId: "icon-[dir]-[name]",
       }),
+      process.env.NODE_ENV === "production" && updateVersion(),
     ],
     // 预加载项目必需的组件
     optimizeDeps: {
@@ -245,3 +246,27 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
     },
   };
 });
+function updateVersion() {
+  return {
+    name: "update-version",
+    buildStart() {
+      let version = "";
+      try {
+        // 读取 json 文件里面版本号
+        const packageJson = JSON.parse(
+          fs.readFileSync("public/version.json", "utf-8")
+        );
+        version = Number(packageJson.version);
+        version = (version + 0.1).toFixed(1); // 增加0.1并保留1位小数
+      } catch (error) {
+        console.log(error);
+      }
+      const versionData = { version: version.toString() }; // 根据需要生成新版本号
+      // 写入 json 文件里面版本号
+      fs.writeFileSync(
+        "public/version.json",
+        JSON.stringify(versionData, null, 2)
+      );
+    },
+  };
+}