dedsudiyu il y a 9 mois
Parent
commit
b0f43fff63
7 fichiers modifiés avec 127 ajouts et 0 suppressions
  1. 4 0
      .env.development
  2. 3 0
      .env.production
  3. 4 0
      public/index.html
  4. 53 0
      src/App.vue
  5. 1 0
      src/main.js
  6. 14 0
      src/utils/browser_patch.js
  7. 48 0
      vue.config.js

+ 4 - 0
.env.development

@@ -5,6 +5,10 @@ VUE_APP_TITLE = 实验室安全智慧化管控系统
 NODE_ENV=development
 VUE_APP_ENV = 'development'
 
+# #######################版本编码#######################
+
+VUE_APP_RENEWAL_ENCODING = ''
+
 # ####################外网接口配置####################
 # 1.8
 VUE_APP_BASE_API =  '192.168.1.8/api'

+ 3 - 0
.env.production

@@ -5,6 +5,9 @@ VUE_APP_TITLE = 实验室安全智慧化管控系统
 NODE_ENV=production
 VUE_APP_ENV = 'production'
 
+# #######################版本编码#######################
+
+VUE_APP_RENEWAL_ENCODING = ''
 
 # ####################外网接口配置####################
 

+ 4 - 0
public/index.html

@@ -6,6 +6,10 @@
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
     <title><%= htmlWebpackPlugin.options.title %></title>
+    <meta name="buildUser" content="<%= htmlWebpackPlugin.options.buildUser %>">
+    <meta name="buildTime" content="<%= htmlWebpackPlugin.options.buildTime %>">
+    <meta name="buildEdition" content="<%= htmlWebpackPlugin.options.buildEdition %>">
+    <meta name="renewalEncoding" content="<%= htmlWebpackPlugin.options.renewalEncoding %>">
   </head>
   <body>
     <noscript>

+ 53 - 0
src/App.vue

@@ -8,6 +8,7 @@
 </template>
 
 <script>
+    import { MessageBox } from 'element-ui'
     export default {
         name: 'App',
         data() {
@@ -31,6 +32,7 @@
 
                 })();
             };
+            this.inspectRenewal();
         },
         methods: {
             banZoom() {
@@ -60,6 +62,57 @@
                     passive: false
                 })
             },
+            //更新检查
+            inspectRenewal(){
+                const self = this;
+                const intervalTime = 300000;
+                checkForUpdates();
+                self.timer = window.setInterval(checkForUpdates, intervalTime);
+                async function checkForUpdates() {
+                    getFilesName().then(res=>{
+                        if(res){
+                            if(res !== process.env.VUE_APP_RENEWAL_ENCODING){
+                                MessageBox.confirm('发现新版本,是否立即刷新页面?', '系统提示', {
+                                        confirmButtonText: '确定',
+                                        showCancelButton:true,
+                                        closeOnClickModal:false,
+                                        cancelButtonText: '取消',
+                                        type: 'warning'
+                                    }
+                                ).then(() => {
+                                    clearInterval(self.timer);
+                                    window.location.reload();
+                                }).catch(() => {});
+                            }
+                        }
+                    });
+                }
+                function getMetaContent(htmlContent) {
+                    let matchContent = [];
+                    const metaTags = htmlContent.match(/<meta[^>]*>/g) || [];
+                    for (const tag of metaTags) {
+                        if(tag.indexOf('renewalEncoding') != -1){
+                            let matchName = tag.match(/content=[^]*>/g);
+                            matchName =  removeChars(matchName[0], '>', '<', '"', "'");
+                            matchContent =  matchName.split("=");
+                        }
+                    }
+                    return matchContent[1];
+                }
+                function removeChars(str, ...chars) {
+                    const pattern = new RegExp(`[${chars.join('')}]`, 'g');
+                    return str.replace(pattern, '');
+                }
+                async function getFilesName() {
+                    const response = await fetch("./index.html");
+                    const htmlContent = await response.text();
+                    return getMetaContent(htmlContent);
+                }
+            },
+        },
+        beforeDestroy() {
+            //清除定时器
+            clearInterval(this.timer);
         },
     }
 </script>

+ 1 - 0
src/main.js

@@ -7,6 +7,7 @@ import echarts from 'echarts';
 import ElementUI from 'element-ui';
 import 'element-ui/lib/theme-chalk/index.css';
 import '@/assets/styles/publicEle.scss'
+import '@/utils/browser_patch'
 import Pagination from "@/components/Pagination/index.vue";
 import {judgmentNetworkReturnAddress,parseTime,goLogin } from '@/utils/public'
 import { accAdd,accSub,accDiv,accMul } from "@/utils/index";

+ 14 - 0
src/utils/browser_patch.js

@@ -0,0 +1,14 @@
+//去除谷歌浏览器的scroll、wheel等事件警告
+(function () {
+  if (typeof EventTarget !== "undefined") {
+    let func = EventTarget.prototype.addEventListener;
+    EventTarget.prototype.addEventListener = function (type, fn, capture) {
+      this.func = func;
+      if (typeof capture !== "boolean") {
+        capture = capture || {};
+        capture.passive = false;
+      }
+      this.func(type, fn, capture);
+    };
+  }
+}())

+ 48 - 0
vue.config.js

@@ -1,3 +1,42 @@
+'use strict'
+const path = require('path')
+const ip = '192.168.1.43'
+const os = require('os')
+const fs = require("fs")
+//判断环境
+let ifaces = os.networkInterfaces()
+let localityIp = '', result = []
+for(let dev in ifaces) {
+    ifaces[dev].forEach(function(details) {
+        if(localityIp === '' && details.family === 'IPv4' && !details.internal) {
+            localityIp = details.address
+            return;
+        }
+    })
+}
+let getFile = localityIp == ip?false:true
+/******** 获取git版本信息 ********/
+const gitHEAD = getFile ? fs.readFileSync('.git/HEAD', 'utf-8').trim() : false
+const ref = getFile ? gitHEAD.split(': ')[1] : false
+const develop = getFile ? gitHEAD.split('/')[2] : false
+const gitVersion = getFile ? fs.readFileSync('.git/' + ref, 'utf-8').trim() : false
+const buildEdition = develop && gitVersion ? develop + ': ' + gitVersion : '未配置'
+const myDate = new Date()
+const buildTime = myDate.getFullYear() +'-'+ (myDate.getMonth()+1) +'-'+ myDate.getDate() +' '+ myDate.getHours() +':'+ myDate.getMinutes();
+const logsList = getFile ? fs.readFileSync('.git/logs/HEAD', 'utf-8').replace(/\r\n|\r/g, "\n").split("\n") : false
+const buildUser = getFile ? logsList[logsList.length-2].split(" ")[2] : '未配置'
+//生成随机版本编码
+process.env.VUE_APP_RENEWAL_ENCODING = generateRandomString()
+function generateRandomString() {
+    let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+    let randomString = "";
+    for (let i = 0; i < 24; i++) {
+        let randomIndex = Math.floor(Math.random() * chars.length);
+        randomString += chars.charAt(randomIndex);
+    }
+    return randomString;
+}
+
 const { defineConfig } = require('@vue/cli-service')
 module.exports = defineConfig({
   transpileDependencies: true,
@@ -22,6 +61,15 @@ module.exports = defineConfig({
         },
     },
   chainWebpack(config) {
+    //标记打包时间与当前git版本信息
+    config.plugin('html').tap(args => {
+        args[0].buildUser = buildUser;
+        args[0].buildTime = buildTime;
+        args[0].buildEdition = buildEdition;
+        args[0].renewalEncoding = process.env.VUE_APP_RENEWAL_ENCODING;
+        // args[0].minify.removeComments = false
+        return args
+    })
     config
         .when(process.env.VUE_APP_ENV !== 'www.dlc.com',
             config => {