App.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div id="app">
  3. <transition name="fade"
  4. mode="out-in">
  5. <router-view></router-view>
  6. </transition>
  7. </div>
  8. </template>
  9. <script>
  10. import axios from 'axios'
  11. import { MessageBox } from 'element-ui'
  12. export default {
  13. name: 'App',
  14. data() {
  15. return {
  16. innerHeight: window.innerHeight,
  17. innerWidth: window.innerWidth,
  18. }
  19. },
  20. mounted() {
  21. document.title = process.env.VUE_APP_TITLE;
  22. this.banZoom();
  23. //根据当前浏览器宽度与额定尺寸计算transform缩放值
  24. document.getElementById('app').style.transform = `scale(${document.documentElement.clientWidth / 1920})`;
  25. //根据当前浏览器宽度与额定尺寸计算当前浏览器可观看尺寸高度
  26. document.getElementById('app').style.height = (window.innerHeight / (document.documentElement.clientWidth / 1920 * 100)) * 100 + 'px';
  27. //当尺寸改变后从新计算
  28. window.onresize = () => {
  29. return (() => {
  30. document.getElementById('app').style.transform = `scale(${document.documentElement.clientWidth / 1920})`;
  31. document.getElementById('app').style.height = (window.innerHeight / (document.documentElement.clientWidth / 1920 * 100)) * 100 + 'px';
  32. })();
  33. };
  34. this.inspectRenewal();
  35. },
  36. methods: {
  37. banZoom() {
  38. // 禁止通过 ctrl + +/- 和 ctrl + 滚轮 对页面进行缩放
  39. document.addEventListener('keydown', function (event) {
  40. if ((event.ctrlKey === true || event.metaKey === true) &&
  41. (event.which === 61 || event.which === 107 ||
  42. event.which === 173 || event.which === 109 ||
  43. event.which === 187 || event.which === 189)) {
  44. event.preventDefault()
  45. }
  46. }, false)
  47. // Chrome IE 360
  48. window.addEventListener('mousewheel', function (event) {
  49. if (event.ctrlKey === true || event.metaKey) {
  50. event.preventDefault()
  51. }
  52. }, {
  53. passive: false
  54. })
  55. // firefox
  56. window.addEventListener('DOMMouseScroll', function (event) {
  57. if (event.ctrlKey === true || event.metaKey) {
  58. event.preventDefault()
  59. }
  60. }, {
  61. passive: false
  62. })
  63. },
  64. //更新检查
  65. inspectRenewal(){
  66. const self = this;
  67. const intervalTime = 300000;
  68. checkForUpdates();
  69. self.timer = window.setInterval(checkForUpdates, intervalTime);
  70. async function checkForUpdates() {
  71. axios.get('/version.txt').then((data) => {
  72. if (data.data !== process.env.VUE_APP_RENEWAL_ENCODING){
  73. MessageBox.confirm('发现新版本,是否立即刷新页面?', '系统提示', {
  74. confirmButtonText: '确定',
  75. showCancelButton:true,
  76. closeOnClickModal:false,
  77. cancelButtonText: '取消',
  78. type: 'warning'
  79. }
  80. ).then(() => {
  81. clearInterval(self.timer);
  82. location.reload(true);
  83. }).catch(() => {});
  84. }
  85. })
  86. // getFilesName().then(res=>{
  87. // if(res){
  88. // if(res !== process.env.VUE_APP_RENEWAL_ENCODING){
  89. // MessageBox.confirm('发现新版本,是否立即刷新页面?', '系统提示', {
  90. // confirmButtonText: '确定',
  91. // showCancelButton:true,
  92. // closeOnClickModal:false,
  93. // cancelButtonText: '取消',
  94. // type: 'warning'
  95. // }
  96. // ).then(() => {
  97. // clearInterval(self.timer);
  98. // location.reload(true);
  99. // }).catch(() => {});
  100. // }
  101. // }
  102. // });
  103. }
  104. function getMetaContent(htmlContent) {
  105. let matchContent = [];
  106. const metaTags = htmlContent.match(/<meta[^>]*>/g) || [];
  107. for (const tag of metaTags) {
  108. if(tag.indexOf('renewalEncoding') != -1){
  109. let matchName = tag.match(/content=[^]*>/g);
  110. matchName = removeChars(matchName[0], '>', '<', '"', "'");
  111. matchContent = matchName.split("=");
  112. }
  113. }
  114. return matchContent[1];
  115. }
  116. function removeChars(str, ...chars) {
  117. const pattern = new RegExp(`[${chars.join('')}]`, 'g');
  118. return str.replace(pattern, '');
  119. }
  120. async function getFilesName() {
  121. const response = await fetch("./index.html");
  122. const htmlContent = await response.text();
  123. return getMetaContent(htmlContent);
  124. }
  125. },
  126. },
  127. beforeDestroy() {
  128. //清除定时器
  129. clearInterval(this.timer);
  130. },
  131. }
  132. </script>
  133. <style>
  134. html{
  135. background-color: #062338;
  136. overflow: hidden;
  137. }
  138. #app {
  139. overflow: hidden;
  140. height: 100%;
  141. transform-origin: left top;
  142. width: 1920px;
  143. display: flex;
  144. flex-direction: column;
  145. flex: 1;
  146. }
  147. .el-loading-mask{
  148. background-color: rgba(255, 255, 255, 0)!important;
  149. }
  150. .el-loading-spinner{
  151. display: none;
  152. }
  153. </style>