main.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div
  3. v-loading.fullscreen.lock="loading"
  4. :element-loading-text="$t('loading')"
  5. class="aui-wrapper"
  6. >
  7. <template v-if="!loading">
  8. <main-sidebar />
  9. <div
  10. class="aui-content__wrapper"
  11. :style="{
  12. 'margin-left': '240px',
  13. width: 'calc(100% - 240px)',
  14. 'overflow-y':'auto'
  15. }"
  16. >
  17. <main-content v-if="!$store.state.contentIsNeedRefresh" />
  18. </div>
  19. </template>
  20. </div>
  21. </template>
  22. <script>
  23. import MainNavbar from "./main-navbar";
  24. import MainSidebar from "./main-sidebar";
  25. import MainContent from "./main-content";
  26. import debounce from "lodash/debounce";
  27. export default {
  28. provide() {
  29. return {
  30. num: "",
  31. // 刷新
  32. refresh() {
  33. this.$store.state.contentIsNeedRefresh = true;
  34. this.$nextTick(() => {
  35. this.$store.state.contentIsNeedRefresh = false;
  36. });
  37. },
  38. };
  39. },
  40. data() {
  41. return {
  42. loading: true,
  43. };
  44. },
  45. components: {
  46. MainNavbar,
  47. MainSidebar,
  48. MainContent,
  49. },
  50. watch: {
  51. $route: "routeHandle",
  52. "$store.state.currentMenuIndex": "changeMenuIndex",
  53. },
  54. created() {
  55. //在页面加载时读取sessionStorage里的状态信息
  56. if (sessionStorage.getItem("tags")) {
  57. this.$store.state.stateTagsList= JSON.parse(sessionStorage.getItem("tags"))
  58. //replaceState,替换store的根状态
  59. }
  60. //在页面刷新时将vuex里的信息保存到sessionStorage里
  61. window.addEventListener("beforeunload", () => {
  62. sessionStorage.setItem("tags", JSON.stringify(this.$store.state.stateTagsList));
  63. });
  64. //工作台和态势感知不显示左边菜单栏
  65. this.windowResizeHandle();
  66. this.routeHandle(this.$route);
  67. Promise.all([this.getUserInfo(), this.getPermissions()]).then(() => {
  68. this.loading = false;
  69. });
  70. },
  71. mounted() {
  72. let currentMenuIndex = localStorage.getItem("currentMenuIndex");
  73. this.$store.state.sidebarMenuList = window.SITE_CONFIG["menuList"];
  74. },
  75. methods: {
  76. changeMenuIndex(newval, oldval) {
  77. this.$store.state.sidebarMenuList = window.SITE_CONFIG["menuList"];
  78. localStorage.setItem("currentMenuIndex", newval);
  79. this.$store.state.erjismenu =
  80. this.$store.state.sidebarMenuList[newval].children;
  81. },
  82. //工作台和态势感知不显示左边菜单栏
  83. changeyijiInd(v) {
  84. this.$store.state.sidebarMenuList = window.SITE_CONFIG["menuList"];
  85. localStorage.setItem("currentMenuIndex", v);
  86. this.$store.state.currentMenuIndex = v;
  87. this.$store.state.erjismenu =
  88. this.$store.state.sidebarMenuList[v].children;
  89. //默认跳转第一个自己路由
  90. let eledom = this.$store.state.sidebarMenuList[v].children[0];
  91. let url = "";
  92. var route = "";
  93. if (eledom.url == "") {
  94. //这是个三级菜单
  95. url = eledom.children[0].url;
  96. route = window.SITE_CONFIG["dynamicMenuRoutes"].filter(
  97. (item) => item.meta.menuId === eledom.children[0].id
  98. )[0];
  99. localStorage.setItem("currentMenuId", route.meta.menuId);
  100. } else {
  101. url = eledom.url;
  102. route = window.SITE_CONFIG["dynamicMenuRoutes"].filter(
  103. (item) => item.meta.menuId === eledom.id
  104. )[0];
  105. localStorage.setItem("currentMenuId", route.meta.menuId);
  106. }
  107. if (url) {
  108. let urls = "/" + url.split("/")[0] + "-" + url.split("/")[1];
  109. this.$nextTick(() => {
  110. this.$router.push({ path: urls });
  111. if(url!='workbench/index'&&url!='situational/index'){
  112. this.$store.commit("mutationSelectTags", route);
  113. }
  114. });
  115. }
  116. },
  117. // 窗口改变大小
  118. windowResizeHandle() {
  119. this.$store.state.sidebarFold =
  120. document.documentElement["clientWidth"] <= 992 || false;
  121. window.addEventListener(
  122. "resize",
  123. debounce(() => {
  124. this.$store.state.sidebarFold =
  125. document.documentElement["clientWidth"] <= 992 || false;
  126. }, 150)
  127. );
  128. },
  129. // 路由, 监听
  130. routeHandle(route) {
  131. if (!route.meta.isTab) {
  132. return false;
  133. }
  134. var tab = this.$store.state.contentTabs.filter(
  135. (item) => item.name === route.name
  136. )[0];
  137. if (!tab) {
  138. tab = {
  139. ...window.SITE_CONFIG["contentTabDefault"],
  140. ...route.meta,
  141. name: route.name,
  142. params: { ...route.params },
  143. query: { ...route.query },
  144. };
  145. this.$store.state.contentTabs =
  146. this.$store.state.contentTabs.concat(tab);
  147. }
  148. this.$store.state.sidebarMenuActiveName = tab.menuId;
  149. this.$store.state.contentTabsActiveName = tab.name;
  150. },
  151. // 获取当前管理员信息
  152. getUserInfo() {
  153. return this.$http
  154. .get("/sys/user/info")
  155. .then(({ data: res }) => {
  156. if (res.code !== 0) {
  157. return this.$message.error(res.msg);
  158. }
  159. this.$store.state.user.id = res.data.id;
  160. this.$store.state.user.name = res.data.username;
  161. this.$store.state.user.realName = res.data.realName;
  162. this.$store.state.user.qualificationType = res.data.qualificationType;
  163. this.$store.state.user.superAdmin = res.data.superAdmin;
  164. this.$store.state.user.roleCodes = res.data.roleCodes;
  165. this.$store.state.user.enterpriseId=res.data.enterpriseId;
  166. })
  167. .catch(() => {});
  168. },
  169. // 获取权限
  170. getPermissions() {
  171. return this.$http
  172. .get("/sys/menu/permissions")
  173. .then(({ data: res }) => {
  174. if (res.code !== 0) {
  175. return this.$message.error(res.msg);
  176. }
  177. window.SITE_CONFIG["permissions"] = res.data;
  178. })
  179. .catch(() => {});
  180. },
  181. },
  182. };
  183. </script>