123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <template>
- <pro-layout
- title="Ant Design Pro"
- :menus="menus"
- :collapsed="collapsed"
- :theme="theme"
- :layout="layout"
- :contentWidth="contentWidth"
- :auto-hide-header="autoHideHeader"
- :mediaQuery="query"
- :isMobile="isMobile"
- :handleMediaQuery="handleMediaQuery"
- :handleCollapse="handleCollapse"
- :logo="logoRender"
- :i18nRender="i18nRender"
- >
- <template v-slot:rightContentRender>
- <right-content />
- </template>
- <template v-slot:footerRender>
- <global-footer />
- </template>
- <router-view />
- </pro-layout>
- </template>
- <script>
- import { i18nRender } from '@/locales'
- import { mapState } from 'vuex'
- import ProLayout from '@ant-design-vue/pro-layout'
- import RightContent from '@/components/GlobalHeader/RightContent'
- import GlobalFooter from '@/components/GlobalFooter'
- import LogoSvg from '../assets/logo.svg?inline'
- import { SIDEBAR_TYPE, TOGGLE_MOBILE_TYPE } from '@/store/mutation-types'
- export default {
- name: 'BasicLayout',
- components: {
- ProLayout,
- RightContent,
- GlobalFooter,
- LogoSvg
- },
- data () {
- return {
- // base
- menus: [],
- // 侧栏收起状态
- collapsed: false,
- // 自动隐藏头部栏
- autoHideHeader: false,
- // 媒体查询
- query: {},
- // 布局类型
- layout: 'sidemenu', // 'sidemenu', 'topmenu'
- // 定宽: true / 流式: false
- contentWidth: true,
- // 主题 'dark' | 'light'
- theme: 'dark',
- // 是否手机模式
- isMobile: false
- }
- },
- computed: {
- ...mapState({
- // 动态主路由
- mainMenu: state => state.permission.addRouters
- })
- },
- created () {
- const routes = this.mainMenu.find(item => item.path === '/')
- this.menus = (routes && routes.children) || []
- // 处理侧栏收起状态
- this.$watch('collapsed', () => {
- this.$store.commit(SIDEBAR_TYPE, this.collapsed)
- })
- this.$watch('isMobile', () => {
- this.$store.commit(TOGGLE_MOBILE_TYPE, this.isMobile)
- })
- },
- mounted () {
- const userAgent = navigator.userAgent
- if (userAgent.indexOf('Edge') > -1) {
- this.$nextTick(() => {
- this.collapsed = !this.collapsed
- setTimeout(() => {
- this.collapsed = !this.collapsed
- }, 16)
- })
- }
- },
- methods: {
- i18nRender,
- handleMediaQuery (val) {
- this.query = val
- if (this.isMobile && !val['screen-xs']) {
- this.isMobile = false
- return
- }
- if (!this.isMobile && val['screen-xs']) {
- this.isMobile = true
- this.collapsed = false
- }
- },
- handleCollapse (val) {
- this.collapsed = val
- },
- logoRender () {
- return <LogoSvg />
- }
- }
- }
- </script>
- <style lang="less">
- @import "./BasicLayout.less";
- </style>
|