App.vue 4.2 KB

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