dedsudiyu 9 hónapja
szülő
commit
1a4cad6245
5 módosított fájl, 48 hozzáadás és 22 törlés
  1. 1 0
      .gitignore
  2. 1 1
      public/index.html
  3. 34 16
      src/App.vue
  4. 7 2
      src/views/demo1.vue
  5. 5 3
      vue.config.js

+ 1 - 0
.gitignore

@@ -26,3 +26,4 @@ yarn.lock
 /.env.production
 
 /*.rar
+/public/version.txt

+ 1 - 1
public/index.html

@@ -10,7 +10,7 @@
     <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 %>">
+    <!--<meta name="renewalEncoding" content="<%= htmlWebpackPlugin.options.renewalEncoding %>">-->
     <!--[if lt IE 11]><script>window.location.href='/html/ie.html';</script><![endif]-->
 	  <style>
     html,

+ 34 - 16
src/App.vue

@@ -6,6 +6,7 @@
 </template>
 
 <script>
+  import axios from 'axios'
   import { MessageBox } from 'element-ui'
   export default  {
     name:  'App',
@@ -76,23 +77,40 @@
         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);
-                  location.reload(true);
-                }).catch(() => {});
-              }
+          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(() => {});
             }
-          });
+          })
+          // 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 = [];

+ 7 - 2
src/views/demo1.vue

@@ -5,6 +5,7 @@
   </div>
 </template>
 <script>
+  import axios from 'axios'
   export default {
     name: 'demo1',
     data () {
@@ -16,10 +17,14 @@
 
     },
     mounted () {
-
+      this.getFilesName();
     },
     methods: {
-
+      async getFilesName() {
+        axios.get('/version.txt').then((data) => {
+          console.log('版本发布时间', data.data)
+        })
+      }
     },
   }
 </script>

+ 5 - 3
vue.config.js

@@ -26,7 +26,10 @@ const buildTime = myDate.getFullYear() +'-'+ (myDate.getMonth()+1) +'-'+ myDate.
 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()
+//生成随机版本编码
+const revision = generateRandomString()
+process.env.VUE_APP_RENEWAL_ENCODING = revision
+require('fs').writeFileSync('public/version.txt', revision)
 function generateRandomString() {
   let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
   let randomString = "";
@@ -39,7 +42,6 @@ function generateRandomString() {
 
 
 
-
 function resolve(dir) {
   return path.join(__dirname, dir)
 }
@@ -120,7 +122,7 @@ module.exports = {
       args[0].buildUser = buildUser;
       args[0].buildTime = buildTime;
       args[0].buildEdition = buildEdition;
-      args[0].renewalEncoding = process.env.VUE_APP_RENEWAL_ENCODING;
+      // args[0].renewalEncoding = process.env.VUE_APP_RENEWAL_ENCODING;
       // args[0].minify.removeComments = false
       return args
     })