BasicLayout.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <pro-layout
  3. title="Ant Design Pro"
  4. :menus="menus"
  5. :collapsed="collapsed"
  6. :theme="theme"
  7. :layout="layout"
  8. :contentWidth="contentWidth"
  9. :auto-hide-header="autoHideHeader"
  10. :mediaQuery="query"
  11. :isMobile="isMobile"
  12. :handleMediaQuery="handleMediaQuery"
  13. :handleCollapse="handleCollapse"
  14. :logo="logoRender"
  15. :i18nRender="i18nRender"
  16. >
  17. <template v-slot:rightContentRender>
  18. <right-content />
  19. </template>
  20. <template v-slot:footerRender>
  21. <global-footer />
  22. </template>
  23. <router-view />
  24. </pro-layout>
  25. </template>
  26. <script>
  27. import { i18nRender } from '@/locales'
  28. import { mapState } from 'vuex'
  29. import ProLayout from '@ant-design-vue/pro-layout'
  30. import RightContent from '@/components/GlobalHeader/RightContent'
  31. import GlobalFooter from '@/components/GlobalFooter'
  32. import LogoSvg from '../assets/logo.svg?inline'
  33. import { SIDEBAR_TYPE, TOGGLE_MOBILE_TYPE } from '@/store/mutation-types'
  34. export default {
  35. name: 'BasicLayout',
  36. components: {
  37. ProLayout,
  38. RightContent,
  39. GlobalFooter,
  40. LogoSvg
  41. },
  42. data () {
  43. return {
  44. // base
  45. menus: [],
  46. // 侧栏收起状态
  47. collapsed: false,
  48. // 自动隐藏头部栏
  49. autoHideHeader: false,
  50. // 媒体查询
  51. query: {},
  52. // 布局类型
  53. layout: 'sidemenu', // 'sidemenu', 'topmenu'
  54. // 定宽: true / 流式: false
  55. contentWidth: true,
  56. // 主题 'dark' | 'light'
  57. theme: 'dark',
  58. // 是否手机模式
  59. isMobile: false
  60. }
  61. },
  62. computed: {
  63. ...mapState({
  64. // 动态主路由
  65. mainMenu: state => state.permission.addRouters
  66. })
  67. },
  68. created () {
  69. const routes = this.mainMenu.find(item => item.path === '/')
  70. this.menus = (routes && routes.children) || []
  71. // 处理侧栏收起状态
  72. this.$watch('collapsed', () => {
  73. this.$store.commit(SIDEBAR_TYPE, this.collapsed)
  74. })
  75. this.$watch('isMobile', () => {
  76. this.$store.commit(TOGGLE_MOBILE_TYPE, this.isMobile)
  77. })
  78. },
  79. mounted () {
  80. const userAgent = navigator.userAgent
  81. if (userAgent.indexOf('Edge') > -1) {
  82. this.$nextTick(() => {
  83. this.collapsed = !this.collapsed
  84. setTimeout(() => {
  85. this.collapsed = !this.collapsed
  86. }, 16)
  87. })
  88. }
  89. },
  90. methods: {
  91. i18nRender,
  92. handleMediaQuery (val) {
  93. this.query = val
  94. if (this.isMobile && !val['screen-xs']) {
  95. this.isMobile = false
  96. return
  97. }
  98. if (!this.isMobile && val['screen-xs']) {
  99. this.isMobile = true
  100. this.collapsed = false
  101. }
  102. },
  103. handleCollapse (val) {
  104. this.collapsed = val
  105. },
  106. logoRender () {
  107. return <LogoSvg />
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="less">
  113. @import "./BasicLayout.less";
  114. </style>