main.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div
  3. class="site-wrapper"
  4. :class="{ 'site-sidebar--fold': sidebarFold }"
  5. v-loading.fullscreen.lock="loading"
  6. element-loading-text="拼命加载中">
  7. <template v-if="!loading">
  8. <main-navbar />
  9. <main-sidebar />
  10. <div class="site-content__wrapper" :style="{ 'min-height': documentClientHeight + 'px' }">
  11. <main-content v-if="!$store.state.common.contentIsNeedRefresh" />
  12. </div>
  13. </template>
  14. </div>
  15. </template>
  16. <script>
  17. import MainNavbar from './main-navbar'
  18. import MainSidebar from './main-sidebar'
  19. import MainContent from './main-content'
  20. export default {
  21. provide () {
  22. return {
  23. // 刷新
  24. refresh () {
  25. this.$store.commit('common/updateContentIsNeedRefresh', true)
  26. this.$nextTick(() => {
  27. this.$store.commit('common/updateContentIsNeedRefresh', false)
  28. })
  29. }
  30. }
  31. },
  32. data () {
  33. return {
  34. loading: true
  35. }
  36. },
  37. components: {
  38. MainNavbar,
  39. MainSidebar,
  40. MainContent
  41. },
  42. computed: {
  43. documentClientHeight: {
  44. get () { return this.$store.state.common.documentClientHeight },
  45. set (val) { this.$store.commit('common/updateDocumentClientHeight', val) }
  46. },
  47. sidebarFold: {
  48. get () { return this.$store.state.common.sidebarFold }
  49. },
  50. userId: {
  51. get () { return this.$store.state.user.id },
  52. set (val) { this.$store.commit('user/updateId', val) }
  53. },
  54. userName: {
  55. get () { return this.$store.state.user.name },
  56. set (val) { this.$store.commit('user/updateName', val) }
  57. }
  58. },
  59. created () {
  60. this.getUserInfo()
  61. },
  62. mounted () {
  63. this.resetDocumentClientHeight()
  64. },
  65. methods: {
  66. // 重置窗口可视高度
  67. resetDocumentClientHeight () {
  68. this.documentClientHeight = document.documentElement['clientHeight']
  69. window.onresize = () => {
  70. this.documentClientHeight = document.documentElement['clientHeight']
  71. }
  72. },
  73. // 获取当前管理员信息
  74. getUserInfo () {
  75. this.$http({
  76. url: this.$http.adornUrl('/sys/user/info'),
  77. method: 'get',
  78. params: this.$http.adornParams()
  79. }).then(({data}) => {
  80. if (data && data.code === 0) {
  81. this.loading = false
  82. this.userId = data.user.userId
  83. this.userName = data.user.username
  84. }
  85. })
  86. }
  87. }
  88. }
  89. </script>