App.vue 4.6 KB

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