dedsudiyu hai 9 meses
pai
achega
00044aa18e
Modificáronse 1 ficheiros con 20 adicións e 55 borrados
  1. 20 55
      src/App.vue

+ 20 - 55
src/App.vue

@@ -6,7 +6,6 @@
 </template>
 
 <script>
-  import axios from 'axios'
   import { MessageBox } from 'element-ui'
   export default  {
     name:  'App',
@@ -77,61 +76,27 @@
         checkForUpdates();
         self.timer = window.setInterval(checkForUpdates, intervalTime);
         async function checkForUpdates() {
-          axios.get('/version.txt').then((data) => {
-            console.log('process.env.VUE_APP_RENEWAL_ENCODING>>',process.env.VUE_APP_RENEWAL_ENCODING)
-            console.log('version.txt>>', data.data)
-            if (data.data !== process.env.VUE_APP_RENEWAL_ENCODING){
-              MessageBox.confirm('发现新版本,是否立即刷新页面?', '系统提示', {
-                  confirmButtonText: '确定',
-                  showCancelButton:true,
-                  closeOnClickModal:false,
-                  cancelButtonText: '取消',
-                  type: 'warning'
-                }
-              ).then(() => {
-                clearInterval(self.timer);
-                location.reload(true);
-              }).catch(() => {});
+          let xhr = new XMLHttpRequest();
+          xhr.open('GET', 'version.txt', true); // 替换为你要读取的txt文件路径
+          xhr.onreadystatechange = function() {
+            if (xhr.readyState === 4 && xhr.status === 200) {
+              let version = xhr.responseText;
+              if (version !== process.env.VUE_APP_RENEWAL_ENCODING){
+                MessageBox.confirm('发现新版本,是否立即刷新页面?', '系统提示', {
+                    confirmButtonText: '确定',
+                    showCancelButton:true,
+                    closeOnClickModal:false,
+                    cancelButtonText: '取消',
+                    type: 'warning'
+                  }
+                ).then(() => {
+                  clearInterval(self.timer);
+                  location.reload(true);
+                }).catch(() => {});
+              }
             }
-          })
-          // 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);
-          //         location.reload(true);
-          //       }).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);
+          };
+          xhr.send();
         }
       },
     },