index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div class="avue-contail"
  3. :class="{'avue--collapse':isCollapse}">
  4. <div class="avue-header">
  5. <!-- 顶部导航栏 -->
  6. <top/>
  7. </div>
  8. <div class="avue-layout">
  9. <div class="avue-left">
  10. <!-- 左侧导航栏 -->
  11. <sidebar/>
  12. </div>
  13. <div class="avue-main">
  14. <!-- 顶部标签卡 -->
  15. <tags/>
  16. <!-- 主体视图层 -->
  17. <el-scrollbar style="height:100%">
  18. <keep-alive>
  19. <router-view class="avue-view"
  20. v-if="$route.meta.$keepAlive"/>
  21. </keep-alive>
  22. <router-view class="avue-view"
  23. v-if="!$route.meta.$keepAlive"/>
  24. </el-scrollbar>
  25. </div>
  26. </div>
  27. <!-- <el-footer class="avue-footer">
  28. <img src="/svg/logo.svg"
  29. alt=""
  30. class="logo">
  31. <p class="copyright">© 2018 Avue designed by smallwei</p>
  32. </el-footer> -->
  33. <div class="avue-shade"
  34. @click="showCollapse"></div>
  35. </div>
  36. </template>
  37. <script>
  38. import {mapGetters} from 'vuex'
  39. import tags from './tags'
  40. import top from './top/'
  41. import sidebar from './sidebar/'
  42. import admin from '@/util/admin';
  43. import {validatenull} from '@/util/validate';
  44. import {calcDate} from '@/util/date.js';
  45. import {getStore} from '@/util/store.js';
  46. export default {
  47. components: {
  48. top,
  49. tags,
  50. sidebar
  51. },
  52. name: 'index',
  53. data() {
  54. return {
  55. //刷新token锁
  56. refreshLock: false,
  57. //刷新token的时间
  58. refreshTime: '',
  59. }
  60. },
  61. created() {
  62. //实时检测刷新token
  63. this.refreshToken()
  64. },
  65. destroyed() {
  66. console.log("销毁")
  67. console.log(this.refreshTime)
  68. clearInterval(this.refreshTime)
  69. },
  70. mounted() {
  71. this.init()
  72. },
  73. computed: mapGetters(['isLock', 'isCollapse', 'website', 'expires_in']),
  74. props: [],
  75. methods: {
  76. showCollapse() {
  77. this.$store.commit("SET_COLLAPSE")
  78. },
  79. // 屏幕检测
  80. init() {
  81. this.$store.commit('SET_SCREEN', admin.getScreen())
  82. window.onresize = () => {
  83. setTimeout(() => {
  84. this.$store.commit('SET_SCREEN', admin.getScreen())
  85. }, 0);
  86. }
  87. },
  88. // 实时检测刷新token
  89. refreshToken() {
  90. this.refreshTime = setInterval(() => {
  91. const token = getStore({
  92. name: 'access_token',
  93. debug: true,
  94. });
  95. if (validatenull(token)) {
  96. return;
  97. }
  98. if (this.expires_in <= 1000 && !this.refreshLock) {
  99. this.refreshLock = true
  100. this.$store
  101. .dispatch('RefeshToken')
  102. .catch(() => {
  103. clearInterval(this.refreshTime)
  104. });
  105. this.refreshLock = false
  106. }
  107. this.$store.commit("SET_EXPIRES_IN",this.expires_in - 10);
  108. }, 10000);
  109. },
  110. }
  111. }
  112. </script>