index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="avue-contail" :class="{'avue--collapse':isCollapse}">
  3. <div class="avue-header">
  4. <!-- 顶部导航栏 -->
  5. <!-- <top ref="top"/> -->
  6. <tags/>
  7. </div>
  8. <div class="avue-layout">
  9. <div class="avue-left">
  10. <!-- 左侧导航栏 -->
  11. <sidebar/>
  12. </div>
  13. <div class="avue-main">
  14. <!-- 顶部标签卡 -->
  15. <transition name="fade-scale">
  16. <search class="avue-view" v-show="isSearch"></search>
  17. </transition>
  18. <!-- 主体视图层 -->
  19. <div style="height:100%;overflow-y:auto;overflow-x:hidden;" id="avue-view" v-show="!isSearch">
  20. <keep-alive>
  21. <router-view class="avue-view" v-if="$route.meta.keepAlive"/>
  22. </keep-alive>
  23. <router-view class="avue-view" v-if="!$route.meta.keepAlive"/>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="avue-shade" @click="showCollapse"></div>
  28. </div>
  29. </template>
  30. <script>
  31. import {mapGetters} from "vuex";
  32. import tags from "./tags";
  33. import search from "./search";
  34. import top from "./top/";
  35. import sidebar from "./sidebar/";
  36. import admin from "@/util/admin";
  37. import {validatenull} from "@/util/validate";
  38. import {calcDate} from "@/util/date.js";
  39. import {getStore} from "@/util/store.js";
  40. export default {
  41. components: {
  42. top,
  43. tags,
  44. search,
  45. sidebar
  46. },
  47. name: "index",
  48. provide() {
  49. return {
  50. index: this
  51. };
  52. },
  53. data() {
  54. return {
  55. //搜索控制
  56. isSearch: false,
  57. //刷新token锁
  58. refreshLock: false,
  59. //刷新token的时间
  60. refreshTime: ""
  61. };
  62. },
  63. created() {
  64. //实时检测刷新token
  65. this.refreshToken();
  66. },
  67. mounted() {
  68. this.init();
  69. },
  70. computed: mapGetters(["isMenu", "isLock", "isCollapse", "website", "menu"]),
  71. props: [],
  72. methods: {
  73. showCollapse() {
  74. this.$store.commit("SET_COLLAPSE");
  75. },
  76. // 初始化
  77. init() {
  78. this.$store.commit("SET_SCREEN", admin.getScreen());
  79. window.onresize = () => {
  80. setTimeout(() => {
  81. this.$store.commit("SET_SCREEN", admin.getScreen());
  82. }, 0);
  83. };
  84. this.$store.dispatch("FlowRoutes").then(() => {
  85. });
  86. },
  87. //打开菜单
  88. openMenu(item = {}) {
  89. this.$store.dispatch("GetMenu", item.id).then(data => {
  90. if (data.length !== 0) {
  91. this.$router.$avueRouter.formatRoutes(data, true);
  92. }
  93. //当点击顶部菜单后默认打开第一个菜单
  94. /*if (!this.validatenull(item)) {
  95. let itemActive = {},
  96. childItemActive = 0;
  97. if (item.path) {
  98. itemActive = item;
  99. } else {
  100. if (this.menu[childItemActive].length === 0) {
  101. itemActive = this.menu[childItemActive];
  102. } else {
  103. itemActive = this.menu[childItemActive].children[childItemActive];
  104. }
  105. }
  106. this.$store.commit('SET_MENU_ID', item);
  107. this.$router.push({
  108. path: this.$router.$avueRouter.getPath({
  109. name: (itemActive.label || itemActive.name),
  110. src: itemActive.path
  111. }, itemActive.meta)
  112. });
  113. }*/
  114. });
  115. },
  116. // 定时检测token
  117. refreshToken() {
  118. this.refreshTime = setInterval(() => {
  119. const token = getStore({
  120. name: "token",
  121. debug: true
  122. }) || {};
  123. const date = calcDate(token.datetime, new Date().getTime());
  124. if (validatenull(date)) return;
  125. if (date.seconds >= this.website.tokenTime && !this.refreshLock) {
  126. this.refreshLock = true;
  127. this.$store
  128. .dispatch("refreshToken")
  129. .then(() => {
  130. this.refreshLock = false;
  131. })
  132. .catch(() => {
  133. this.refreshLock = false;
  134. });
  135. }
  136. }, 10000);
  137. }
  138. }
  139. };
  140. </script>