main.vue 2.2 KB

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