Unverified Commit 8db595b2 authored by Sendya's avatar Sendya

fix: mobile sider menu

parent d900f29d
...@@ -68,11 +68,13 @@ export default { ...@@ -68,11 +68,13 @@ export default {
// 媒体查询 // 媒体查询
query: {}, query: {},
// 布局类型 // 布局类型
layout: 'sidemenu', // 'sidemenu', 'topmenu' layout: 'topmenu', // 'sidemenu', 'topmenu'
// 定宽: true / 流式: false // 定宽: true / 流式: false
contentWidth: true, contentWidth: true,
// 主题 'dark' | 'light' // 主题 'dark' | 'light'
theme: 'dark' theme: 'light',
// 是否手机模式
isMobile: false
} }
}, },
render (h) { render (h) {
...@@ -86,6 +88,14 @@ export default { ...@@ -86,6 +88,14 @@ export default {
const handleMediaQuery = (val) => { const handleMediaQuery = (val) => {
this.query = 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
}
} }
const handleCollapse = (val) => { const handleCollapse = (val) => {
this.collapsed = val this.collapsed = val
...@@ -103,6 +113,7 @@ export default { ...@@ -103,6 +113,7 @@ export default {
layout, layout,
contentWidth, contentWidth,
theme, theme,
isMobile: this.isMobile,
rightContentRender, rightContentRender,
footerRender, footerRender,
i18nRender, i18nRender,
......
...@@ -45,7 +45,8 @@ export default { ...@@ -45,7 +45,8 @@ export default {
<style lang="less" scoped> <style lang="less" scoped>
.page-test-wrapper { .page-test-wrapper {
width: 400px; width: 100%;
max-width: 400px;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>
...@@ -31,7 +31,8 @@ export default { ...@@ -31,7 +31,8 @@ export default {
<style lang="less" scoped> <style lang="less" scoped>
.page-test-wrapper { .page-test-wrapper {
width: 400px; width: 100%;
max-width: 400px;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>
...@@ -97,17 +97,15 @@ const BasicLayout = { ...@@ -97,17 +97,15 @@ const BasicLayout = {
<div> <div>
<ContainerQuery query={MediaQueryEnum} onChange={handleMediaQuery}> <ContainerQuery query={MediaQueryEnum} onChange={handleMediaQuery}>
<Layout class={{ 'basicLayout': true, ...mediaQuery }}> <Layout class={{ 'basicLayout': true, ...mediaQuery }}>
{layout !== 'topmenu' && ( <SiderMenuWrapper
<SiderMenuWrapper { ...{ props: props } }
{ ...{ props: props } } menus={menus}
menus={menus} mode={'inline'}
mode={'inline'} logo={logo}
logo={logo} collapsed={collapsed}
collapsed={collapsed} onCollapse={handleCollapse}
onCollapse={handleCollapse} handleCollapse={handleCollapse}
handleCollapse={handleCollapse} />
/>
)}
<Layout class={[layout]} style={{ paddingLeft: '0', minHeight: '100vh' }}> <Layout class={[layout]} style={{ paddingLeft: '0', minHeight: '100vh' }}>
{headerRender(h, { {headerRender(h, {
...props, ...props,
......
...@@ -47,11 +47,10 @@ export const HeaderViewProps = { ...@@ -47,11 +47,10 @@ export const HeaderViewProps = {
const renderContent = (h, props) => { const renderContent = (h, props) => {
const isTop = props.layout === 'topmenu' const isTop = props.layout === 'topmenu'
const isMobile = false
const maxWidth = 1200 - 280 - 120 const maxWidth = 1200 - 280 - 120
const contentWidth = props.contentWidth const contentWidth = props.contentWidth
const baseCls = 'ant-pro-top-nav-header' const baseCls = 'ant-pro-top-nav-header'
const { logo, title, theme, headerRender, rightContentRender } = props const { logo, title, theme, isMobile, headerRender, rightContentRender } = props
const rightContentProps = { theme } const rightContentProps = { theme }
let defaultDom = <GlobalHeader {...{ props: props }} /> let defaultDom = <GlobalHeader {...{ props: props }} />
if (isTop && !isMobile) { if (isTop && !isMobile) {
......
@import "~ant-design-vue/es/style/themes/default"; @import "~ant-design-vue/es/style/themes/default";
@global-header-prefix-cls: ~'@{ant-prefix}-pro-global-header';
@top-nav-header-prefix-cls: ~'@{ant-prefix}-pro-top-nav-header'; @top-nav-header-prefix-cls: ~'@{ant-prefix}-pro-top-nav-header';
@pro-header-bg: @component-background;
@pro-header-hover-bg: @component-background;
@pro-header-box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
.@{top-nav-header-prefix-cls} { .@{top-nav-header-prefix-cls} {
position: relative; position: relative;
width: 100%; width: 100%;
...@@ -77,85 +72,6 @@ ...@@ -77,85 +72,6 @@
} }
} }
.@{global-header-prefix-cls} {
position: relative;
height: @layout-header-height;
padding: 0;
background: @pro-header-bg;
box-shadow: @pro-header-box-shadow;
&-index-right {
float: right;
height: 100%;
margin-left: auto;
overflow: hidden;
.@{global-header-prefix-cls}-index-action {
display: inline-block;
height: 100%;
padding: 0 12px;
cursor: pointer;
transition: all .3s;
&:hover {
background: rgba(0,0,0,.025);
}
}
}
&-logo {
display: inline-block;
height: @layout-header-height;
padding: 0 0 0 24px;
font-size: 20px;
line-height: @layout-header-height;
vertical-align: top;
cursor: pointer;
img {
display: inline-block;
width: 32px;
vertical-align: middle;
}
}
&-menu {
.anticon {
margin-right: 8px;
}
.ant-dropdown-menu-item {
min-width: 160px;
}
}
&-trigger {
height: @layout-header-height;
padding: ~'calc((@{layout-header-height} - 26px) / 2)' 24px;
font-size: 20px;
cursor: pointer;
transition: all 0.3s, padding 0s;
&:hover {
background: @pro-header-hover-bg;
}
}
.dark {
height: @layout-header-height;
.action {
color: rgba(255, 255, 255, 0.85);
> i {
color: rgba(255, 255, 255, 0.85);
}
&:hover,
&.opened {
background: @primary-color;
}
.ant-badge {
color: rgba(255, 255, 255, 0.85);
}
}
}
}
.drop-down { .drop-down {
&.menu { &.menu {
.anticon { .anticon {
......
/* eslint-disable */
import './index.less' import './index.less'
import debounce from 'lodash/debounce' import debounce from 'lodash/debounce'
...@@ -74,7 +73,7 @@ const GlobalHeader = { ...@@ -74,7 +73,7 @@ const GlobalHeader = {
return ( return (
<div class={headerCls}> <div class={headerCls}>
{isMobile && ( {isMobile && (
<a class={`${headerCls}-logo`} key="logo"> <a class={`${headerCls}-logo`} key="logo" href={'/'}>
{defaultRenderLogo(h, logo)} {defaultRenderLogo(h, logo)}
</a> </a>
)} )}
...@@ -89,7 +88,7 @@ const GlobalHeader = { ...@@ -89,7 +88,7 @@ const GlobalHeader = {
}) })
}, },
beforeDestroy () { beforeDestroy () {
this.triggerResizeEvent.cancel() this.triggerResizeEvent.cancel && this.triggerResizeEvent.cancel()
} }
} }
......
@import "~ant-design-vue/es/style/themes/default";
@global-header-prefix-cls: ~'@{ant-prefix}-pro-global-header';
@pro-header-bg: @component-background;
@pro-header-hover-bg: @component-background;
@pro-header-box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
@pro-header-hover-trigger-action-bg: rgba(0,0,0,.025);
.@{global-header-prefix-cls} {
position: relative;
height: @layout-header-height;
padding: 0;
background: @pro-header-bg;
box-shadow: @pro-header-box-shadow;
&-index-right {
float: right;
height: 100%;
margin-left: auto;
overflow: hidden;
.@{global-header-prefix-cls}-index-action {
display: inline-block;
height: 100%;
padding: 0 12px;
cursor: pointer;
transition: all .3s;
&:hover {
background: @pro-header-hover-trigger-action-bg;
}
}
}
&-logo {
display: inline-block;
height: @layout-header-height;
padding: 0 0 0 24px;
font-size: 20px;
line-height: @layout-header-height;
vertical-align: top;
cursor: pointer;
img, svg {
display: inline-block;
width: 32px;
height: 32px;
vertical-align: middle;
}
}
&-menu {
.anticon {
margin-right: 8px;
}
.ant-dropdown-menu-item {
min-width: 160px;
}
}
&-trigger {
height: @layout-header-height;
padding: ~'calc((@{layout-header-height} - 26px) / 2)' 24px;
font-size: 20px;
cursor: pointer;
transition: all 0.3s, padding 0s;
&:hover {
background: @pro-header-hover-trigger-action-bg;
}
}
.dark {
height: @layout-header-height;
.action {
color: rgba(255, 255, 255, 0.85);
> i {
color: rgba(255, 255, 255, 0.85);
}
&:hover,
&.opened {
background: @primary-color;
}
.ant-badge {
color: rgba(255, 255, 255, 0.85);
}
}
}
.ant-pro-global-header {
.ant-pro-global-header-index-action { .ant-pro-global-header-index-action {
i { i {
color: rgba(0,0,0,.65); color: rgba(0,0,0,.65);
vertical-align: middle; vertical-align: middle;
} }
} }
} }
...@@ -10,10 +10,12 @@ const SiderMenuWrapper = { ...@@ -10,10 +10,12 @@ const SiderMenuWrapper = {
props: SiderMenuProps, props: SiderMenuProps,
render () { render () {
const { const {
layout,
isMobile, isMobile,
collapsed, collapsed,
handleCollapse: onCollapse handleCollapse: onCollapse
} = this } = this
const isTopMenu = layout === 'topmenu'
return isMobile ? ( return isMobile ? (
<Drawer <Drawer
class="ant-pro-sider-menu" class="ant-pro-sider-menu"
...@@ -26,9 +28,9 @@ const SiderMenuWrapper = { ...@@ -26,9 +28,9 @@ const SiderMenuWrapper = {
height: '100vh' height: '100vh'
}} }}
> >
<SiderMenu {...{ props: this.$props }} collapsed={isMobile ? false : collapsed} /> <SiderMenu {...{ props: {...this.$props, collapsed: isMobile ? false : collapsed} }} />
</Drawer> </Drawer>
) : ( ) : !isTopMenu && (
<SiderMenu class="ant-pro-sider-menu" {...{ props: this.$props }} /> <SiderMenu class="ant-pro-sider-menu" {...{ props: this.$props }} />
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment