forked from vueComponent/pro-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Header.jsx
111 lines (100 loc) · 3.14 KB
/
Header.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import './Header.less'
import 'ant-design-vue/es/layout/style'
import Layout from 'ant-design-vue/es/layout'
import PropTypes from 'ant-design-vue/es/_util/vue-types'
import BaseMenu from './components/RouteMenu/BaseMenu'
import { defaultRenderLogoAntTitle, SiderMenuProps } from './components/SiderMenu/SiderMenu'
import GlobalHeader, { GlobalHeaderProps } from './components/GlobalHeader'
import { VueFragment } from './components'
import { isFun } from './utils/util'
const { Header } = Layout
export const HeaderViewProps = {
...GlobalHeaderProps,
...SiderMenuProps,
isMobile: PropTypes.bool.def(false),
collapsed: PropTypes.bool,
logo: PropTypes.any,
hasSiderMenu: PropTypes.bool,
autoHideHeader: PropTypes.bool,
menuRender: PropTypes.any,
headerRender: PropTypes.any,
rightContentRender: PropTypes.any,
visible: PropTypes.bool.def(true),
}
const renderContent = (h, props) => {
const isTop = props.layout === 'topmenu'
const maxWidth = 1200 - 280 - 120
const contentWidth = props.contentWidth === 'Fixed'
const baseCls = 'ant-pro-top-nav-header'
const { logo, title, theme, isMobile, headerRender, rightContentRender, menuHeaderRender } = props
const rightContentProps = { theme, isTop, isMobile }
let defaultDom = <GlobalHeader {...{ props: props }} />
if (isTop && !isMobile) {
defaultDom = (
<div class={[baseCls, theme]}>
<div class={[`${baseCls}-main`, contentWidth ? 'wide' : '']}>
{menuHeaderRender && (
<div class={`${baseCls}-left`}>
<div class={`${baseCls}-logo`} key="logo" id="logo">
{defaultRenderLogoAntTitle(h, { logo, title, menuHeaderRender })}
</div>
</div>
)}
<div class={`${baseCls}-menu`} style={{ maxWidth: `${maxWidth}px`, flex: 1 }}>
<BaseMenu {...{ props: props }} />
</div>
{isFun(rightContentRender) && rightContentRender(h, rightContentProps) || rightContentRender}
</div>
</div>
)
}
if (headerRender) {
return headerRender(h, props)
}
return defaultDom
}
const HeaderView = {
name: 'HeaderView',
props: HeaderViewProps,
render (h) {
const {
visible,
isMobile,
layout,
collapsed,
siderWidth,
fixedHeader,
autoHideHeader,
hasSiderMenu,
} = this.$props
const props = this.$props
const isTop = layout === 'topmenu'
const needSettingWidth = fixedHeader && hasSiderMenu && !isTop && !isMobile
const className = {
'ant-pro-fixed-header': fixedHeader,
'ant-pro-top-menu': isTop,
}
// 没有 <></> 暂时代替写法
return (
visible ? (
<VueFragment>
{ fixedHeader && <Header />}
<Header
style={{
padding: 0,
width: needSettingWidth
? `calc(100% - ${collapsed ? 80 : siderWidth}px)`
: '100%',
zIndex: 9,
right: fixedHeader ? 0 : undefined
}}
class={className}
>
{renderContent(h, props)}
</Header>
</VueFragment>
) : null
)
}
}
export default HeaderView