From 55955f56fdae8977e6372c333a13e0d60ecb3397 Mon Sep 17 00:00:00 2001
From: qx <1084500556@qq.com>
Date: 星期三, 07 五月 2025 15:23:04 +0800
Subject: [PATCH] qx

---
 src/views/login.vue     |    2 +
 src/main.js             |   14 +++++++
 src/utils/AutoUpdate.js |   66 +++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/src/main.js b/src/main.js
index 302cecd..7e6eb69 100644
--- a/src/main.js
+++ b/src/main.js
@@ -14,6 +14,20 @@
 import plugins from "./plugins"; // plugins
 import { download } from "@/utils/request";
 import Print from "vue-print-nb";
+ 
+import Updater from "./utils/AutoUpdate.js";
+ 
+//鍓嶇閲嶆柊閮ㄧ讲閫氱煡鐢ㄦ埛鍒锋柊缃戦〉
+const AutoUpdate = new Updater()
+AutoUpdate.on('update',()=>{
+  setTimeout(async()=>{
+      const result = confirm('褰撳墠鐗堟湰宸叉洿鏂帮紝璇风偣鍑荤‘瀹氬埛鏂伴〉闈綋楠�');
+      if(result){
+        location.reload();
+      }
+  },500)
+})
+ 
 
 import JsonExcel from "vue-json-excel";
 
diff --git a/src/utils/AutoUpdate.js b/src/utils/AutoUpdate.js
new file mode 100644
index 0000000..50d4e95
--- /dev/null
+++ b/src/utils/AutoUpdate.js
@@ -0,0 +1,66 @@
+ 
+/**
+ * 鍓嶇閲嶆柊閮ㄧ讲閫氱煡鐢ㄦ埛鍒锋柊缃戦〉
+ */
+ 
+class Updater {
+    oldScript = []; // 瀛樺偍绗竴娆″�间篃灏辨槸script 鐨刪ash 淇℃伅
+    newScript = []; // 鑾峰彇鏂扮殑鍊� 涔熷氨鏄柊鐨剆cript 鐨刪ash淇℃伅
+    dispatch = {}; // 灏忓瀷鍙戝竷璁㈤槄閫氱煡鐢ㄦ埛鏇存柊浜�
+ 
+    constructor() {
+        this.oldScript = [];
+        this.newScript = [];
+        this.dispatch = {};
+        this.init(); // 鍒濆鍖�
+        this.timing();
+    }
+ 
+    async init() {
+        const html = await this.getHtml();
+        this.oldScript = this.parserScript(html);
+    };
+ 
+    async getHtml() {
+        const html = await fetch('/').then(res => res.text());//璇诲彇index html
+        return html
+    };
+ 
+    parserScript(html) {
+        const reg = new RegExp(/<script(?:\s+[^>]*)?>(.*?)<\/script\s*>/ig) //script姝e垯
+        return html.match(reg) //鍖归厤script鏍囩
+    }
+ 
+    //鍙戝竷璁㈤槄閫氱煡
+    on(key, fn) {
+        (this.dispatch[key] || (this.dispatch[key] = [])).push(fn)
+        return this;
+    }
+ 
+    compare(oldArr, newArr) {
+        const base = oldArr.length;
+        const arr = Array.from(new Set(oldArr.concat(newArr)));
+        //濡傛灉鏂版棫length 涓�鏍锋棤鏇存柊
+        if (arr.length === base) {
+            // this.dispatch['no-update'].forEach(fn => {
+            //     fn();
+            // })
+        } else {
+            // 鍚﹀垯閫氱煡鏇存柊
+            this.dispatch['update'].forEach(fn => {
+                fn();
+            })
+        }
+    };
+ 
+    async timing() {
+        setInterval(async () => {
+            const newHtml = await this.getHtml();
+            this.newScript = this.parserScript(newHtml);
+            this.compare(this.oldScript, this.newScript)
+            //杩欒竟缁欑殑鏄粯璁ゅ��15000,涔熷彲浠ヨ嚜瀹氫箟绉掓暟
+        }, 15000);
+    };
+}
+ 
+export default Updater;
\ No newline at end of file
diff --git a/src/views/login.vue b/src/views/login.vue
index fad4749..a461429 100644
--- a/src/views/login.vue
+++ b/src/views/login.vue
@@ -233,6 +233,8 @@
                 }
               }
               this.$router.push({ path: this.redirect || "/" }).catch(() => { });
+              console.log(11115555)
+              location.reload();
             }
 
           }).catch(() => {

--
Gitblit v1.8.0