App.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <router-view />
  3. </template>
  4. <script>
  5. import api from "@/api/common";
  6. export default {
  7. name: "App",
  8. data() {
  9. return {
  10. loadedScripts: [],
  11. }
  12. },
  13. mounted() {
  14. let that = this;
  15. window.loadScripts = this.loadScripts
  16. // document.querySelector("#app").style.transform = `scale(${this.getScale()}) translate(-50%, 0%)`
  17. // document.querySelector("#app").style.height = window.innerHeight / this.getScale() + "px"
  18. // window.onresize = () => {
  19. // document.querySelector("#app").style.transform = `scale(${this.getScale()}) translate(-50%, 0%)`
  20. // document.querySelector("#app").style.height = window.innerHeight / this.getScale() + "px"
  21. // }
  22. // this.$nextTick(() => {
  23. // this.scrollUpdate();
  24. // });
  25. // 默认登录
  26. api.login({
  27. userName: systemConfig.defaultAccount.userName,
  28. password: AesEncryptUtil.getPassword(),
  29. clientId: "1",
  30. }).then((result) => {
  31. if (result.code == 200) {
  32. that.$store.commit("setUserInfo", result.content);
  33. that.$store.commit("setToken", result.message);
  34. that.$store.commit("setUserState", true);
  35. } else {
  36. that.$message({
  37. type: "error",
  38. message: result.content,
  39. });
  40. }
  41. }).catch((err) => {
  42. that.$message({
  43. type: "error",
  44. message: "服务器忙碌,请稍后重试!",
  45. });
  46. });
  47. },
  48. methods: {
  49. // scrollUpdate() {
  50. // let that = this;
  51. // setTimeout(() => {
  52. // that.$refs.pagescrollbar.update();
  53. // }, 1000);
  54. // },
  55. getScale() {
  56. const ww = window.innerWidth / 1920
  57. // const wh = window.innerHeight / 945
  58. // return ww < wh ? ww : wh;
  59. return ww
  60. },
  61. initScript() {
  62. let that = this;
  63. window.SkySceneryConfig = {
  64. authUrl: systemConfig.oauthServiceUrlOrigin,
  65. token: localStorage.getItem("token")
  66. };
  67. return new Promise((resolve, reject) => {
  68. const str = systemConfig.scriptMain;
  69. let strArr = str.split("/")
  70. if (that.loadedScripts.indexOf(strArr[strArr.length - 1]) == -1) {
  71. // SkyScenery.js
  72. that.loadedScripts.push(strArr[strArr.length - 1]);
  73. that.addScripts(systemConfig.scriptMain).then(function () {
  74. resolve();
  75. })
  76. } else {
  77. resolve();
  78. }
  79. })
  80. },
  81. loadScripts(scriptArr) {
  82. // 初始化 SkyScenery.js
  83. let that = this;
  84. return new Promise((resolve, reject) => {
  85. that.initScript().then(function () {
  86. let arr = []
  87. for (let i = 0; i < scriptArr.length; i++) {
  88. const str = scriptArr[i];
  89. let strArr = str.split("/")
  90. if (that.loadedScripts.indexOf(strArr[strArr.length - 1]) == -1) {
  91. let pro = that.addScripts(str);
  92. that.loadedScripts.push(strArr[strArr.length - 1]);
  93. arr.push(pro)
  94. }
  95. }
  96. Promise.all(arr).then(function () {
  97. resolve()
  98. });
  99. })
  100. })
  101. },
  102. addScripts(src) {
  103. return new Promise((resolve, reject) => {
  104. // 创建一个新的script标签
  105. var script = document.createElement("script");
  106. // 设置script标签的src属性为要引入的JavaScript文件的URL
  107. script.src = src;
  108. // 将script标签添加到页面的head部分或者其他合适的位置
  109. document.head.appendChild(script);
  110. if (script.readyState) {
  111. // IE
  112. script.onreadystatechange = function () {
  113. if (
  114. script.readyState === "loaded" ||
  115. script.readyState === "complete"
  116. ) {
  117. script.onreadystatechange = null;
  118. resolve();
  119. }
  120. };
  121. } else {
  122. // 其他浏览器
  123. script.onload = function () {
  124. resolve();
  125. };
  126. }
  127. });
  128. },
  129. }
  130. };
  131. </script>
  132. <style lang="less">
  133. body,
  134. html {
  135. width: 100vw;
  136. height: 100vh;
  137. margin: 0 0;
  138. padding: 0 0;
  139. overflow: hidden;
  140. }
  141. #app {
  142. width: 1920px;
  143. height: 100%;
  144. position: fixed;
  145. left: 50%;
  146. top: 0%;
  147. transform-origin: left top;
  148. transform: translate(-50%, 0%);
  149. }
  150. </style>