Skip to content

Commit 49e2e5f

Browse files
committed
docs: update site #101
1 parent d298225 commit 49e2e5f

File tree

5 files changed

+167
-12
lines changed

5 files changed

+167
-12
lines changed

site/components/header.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ export default {
3232
return (
3333
<header id='header'>
3434
<a-row>
35-
<a-col xxl={4} xl={5} lg={5} md={6} sm={24} xs={24}>
35+
<a-col class='header-left' xxl={4} xl={5} lg={5} md={6} sm={24} xs={24}>
3636
<router-link to={{ path: '/ant-design-vue' }} id='logo'>
3737
<img alt='logo' height='32' src='https://raw.githubusercontent.com/vueComponent/ant-design-vue/master/logo.png' />
3838
<span> Ant Design Vue</span>
3939
</router-link>
40+
<a-button ghost size='small' onClick={this.handleClick} class='header-lang-button' key='lang-button'>
41+
{isCN ? 'English' : '中文'}
42+
</a-button>
4043
</a-col>
4144
<a-col xxl={20} xl={19} lg={19} md={18} sm={0} xs={0}>
4245
<div id='search-box' style='display: block'>

site/components/layout.vue

+67-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import sortBy from 'lodash/sortBy'
77
import { isZhCN } from '../util'
88
import { Provider, create } from '../../components/_util/store'
99
import NProgress from 'nprogress'
10+
import debounce from 'lodash/debounce'
11+
import addDOMEventListener from 'add-dom-event-listener'
1012
1113
const docsList = [
1214
{ key: 'introduce', enTitle: 'Ant Design of Vue', title: 'Ant Design of Vue' },
@@ -16,6 +18,27 @@ const docsList = [
1618
{ key: 'changelog', enTitle: 'Change Log', title: '更新日志' },
1719
{ key: 'i18n', enTitle: 'Internationalization', title: '国际化' },
1820
]
21+
function getOffsetTop (element, container = window) {
22+
if (!element) {
23+
return 0
24+
}
25+
26+
if (!element.getClientRects().length) {
27+
return 0
28+
}
29+
30+
const rect = element.getBoundingClientRect()
31+
32+
if (rect.width || rect.height) {
33+
if (container === window) {
34+
container = element.ownerDocument.documentElement
35+
return rect.top - container.clientTop
36+
}
37+
return rect.top - container.getBoundingClientRect().top
38+
}
39+
40+
return rect.top
41+
}
1942
2043
export default {
2144
props: {
@@ -29,7 +52,9 @@ export default {
2952
})
3053
this.subscribe()
3154
return {
55+
showSideBars: true,
3256
currentSubMenu: [],
57+
sidebarHeight: document.documentElement.offsetHeight,
3358
}
3459
},
3560
provide () {
@@ -42,15 +67,29 @@ export default {
4267
this.unsubscribe()
4368
}
4469
clearTimeout(this.timer)
70+
if (this.resizeEvent) {
71+
this.resizeEvent.remove()
72+
}
73+
if (this.debouncedResize && this.debouncedResize.cancel) {
74+
this.debouncedResize.cancel()
75+
}
4576
},
4677
mounted () {
47-
this.addSubMenu()
48-
const nprogressHiddenStyle = document.getElementById('nprogress-style')
49-
if (nprogressHiddenStyle) {
50-
this.timer = setTimeout(() => {
51-
nprogressHiddenStyle.parentNode.removeChild(nprogressHiddenStyle)
52-
}, 0)
53-
}
78+
this.$nextTick(() => {
79+
this.addSubMenu()
80+
const nprogressHiddenStyle = document.getElementById('nprogress-style')
81+
if (nprogressHiddenStyle) {
82+
this.timer = setTimeout(() => {
83+
nprogressHiddenStyle.parentNode.removeChild(nprogressHiddenStyle)
84+
}, 0)
85+
}
86+
87+
this.updateHeight()
88+
this.debouncedResize = debounce(() => {
89+
this.updateHeight()
90+
}, 200)
91+
this.resizeEvent = addDOMEventListener(window, 'resize', this.debouncedResize)
92+
})
5493
},
5594
watch: {
5695
'$route.path': function () {
@@ -59,6 +98,12 @@ export default {
5998
},
6099
},
61100
methods: {
101+
updateHeight () {
102+
const el = this.$refs.sidebar.$el
103+
const offsetTop = getOffsetTop(el)
104+
const docHeight = document.documentElement.offsetHeight
105+
this.sidebarHeight = docHeight - offsetTop
106+
},
62107
addSubMenu () {
63108
if (this.$route.path.indexOf('/docs/vue/') !== -1) {
64109
this.$nextTick(() => {
@@ -90,7 +135,7 @@ export default {
90135
})
91136
const showApi = this.$route.path.indexOf('/components/') !== -1
92137
return (
93-
<a-anchor>
138+
<a-anchor offsetTop={70} class='demo-anchor'>
94139
{lis}
95140
{showApi ? <a-anchor-link title='API' href='#API' /> : ''}
96141
</a-anchor>
@@ -124,6 +169,7 @@ export default {
124169
},
125170
mountedCallback () {
126171
NProgress.done()
172+
document.documentElement.scrollTop = 0
127173
},
128174
},
129175
@@ -186,14 +232,17 @@ export default {
186232
}
187233
const config = AllDemo[titleMap[reName]]
188234
this.resetDocumentTitle(config, reName, isCN)
235+
const { showSideBars, sidebarHeight } = this
189236
return (
190237
<div class='page-wrapper'>
191238
<Header searchData={searchData} name={name}/>
192239
<a-locale-provider locale={locale}>
193240
<div class='main-wrapper'>
194241
<a-row>
195-
<a-col span={6} style={{ maxWidth: '260px' }}>
242+
<a-col v-show={showSideBars} style={{ height: `${sidebarHeight}px` }} ref='sidebar' class='site-sidebar' xxl={4} xl={5} lg={5} md={6} sm={8} xs={12}>
243+
<div class='drawer-mask' onClick={() => { this.showSideBars = false }}></div>
196244
<a-menu
245+
197246
class='aside-container menu-site'
198247
selectedKeys={[name]}
199248
defaultOpenKeys={['Components']}
@@ -204,8 +253,14 @@ export default {
204253
{MenuGroup}
205254
</a-sub-menu>
206255
</a-menu>
256+
<div class='close-drawer' onClick={() => { this.showSideBars = false }}>
257+
<a-icon type='close'/>
258+
</div>
207259
</a-col>
208-
<a-col span={18}>
260+
<div v-show={!showSideBars} class='open-drawer' onClick={() => { this.showSideBars = true }}>
261+
<a-icon type='bars'/>
262+
</div>
263+
<a-col style='float: right;' xxl={20} xl={19} lg={19} md={18} sm={24} xs={24}>
209264
<div class='content main-container'>
210265
<div class='toc-affix' style='width: 120px;'>
211266
{this.getSubMenu(isCN)}
@@ -234,8 +289,10 @@ export default {
234289
</div>
235290
</a-col>
236291
</a-row>
292+
237293
</div>
238294
</a-locale-provider>
295+
239296
{ name.indexOf('back-top') === -1 ? <a-back-top /> : null }
240297
</div>
241298
)

site/index.less

+94
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,97 @@
8787
.toc-affix .ant-affix {
8888
overflow: visible;
8989
}
90+
.main-wrapper {
91+
margin-top: 64px;
92+
}
93+
.demo-anchor {
94+
.ant-anchor-link-title {
95+
font-size: 12px;
96+
}
97+
}
98+
.site-sidebar{
99+
position: fixed;
100+
z-index: 1;
101+
overflow-y: scroll;
102+
}
103+
@media (min-width: 576px) and (max-width: 768px) {
104+
.main-wrapper {
105+
z-index: 11;
106+
}
107+
.site-sidebar{
108+
width: 100%;
109+
top: 0;
110+
left: 0;
111+
.aside-container{
112+
width: 80%;
113+
z-index: 1;
114+
position: relative;
115+
}
116+
}
117+
.drawer-mask{
118+
background: #000;
119+
opacity: 0;
120+
width: 100%;
121+
height: 100%;
122+
position: fixed;
123+
top: 0;
124+
opacity: 0.3;
125+
}
126+
.close-drawer{
127+
position: absolute;
128+
top: 72px;
129+
width: 41px;
130+
height: 40px;
131+
cursor: pointer;
132+
pointer-events: auto;
133+
z-index: 0;
134+
text-align: center;
135+
line-height: 40px;
136+
font-size: 16px;
137+
left: 80%;
138+
align-items: center;
139+
background: #fff;
140+
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
141+
border-radius: 0 4px 4px 0;
142+
}
143+
.open-drawer{
144+
position: absolute;
145+
top: 72px;
146+
width: 41px;
147+
height: 40px;
148+
cursor: pointer;
149+
pointer-events: auto;
150+
z-index: 1;
151+
text-align: center;
152+
line-height: 40px;
153+
font-size: 16px;
154+
left: 0;
155+
align-items: center;
156+
background: #fff;
157+
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
158+
border-radius: 0 4px 4px 0;
159+
}
160+
.toc-affix {
161+
display: none !important;
162+
}
163+
}
164+
@media (min-width: 768px) {
165+
.site-sidebar {
166+
display: block !important;
167+
}
168+
.header-left .header-lang-button{
169+
display: none;
170+
}
171+
.site-sidebar{
172+
top: 104px;
173+
}
174+
.drawer-mask{
175+
display: none !important;
176+
}
177+
.close-drawer{
178+
display: none !important;
179+
}
180+
.open-drawer{
181+
display: none !important;
182+
}
183+
}

site/theme/static/header.less

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
position: relative;
99
z-index: 10;
1010
max-width: 100%;
11+
width: 100%;
12+
position: fixed;
1113
&.home-nav-bottom {
1214
background: rgba(255, 255, 255, 0.9);
1315
border-bottom-color: #ebedee;

site/theme/static/responsive.less

-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
.main-wrapper {
159159
width: 100%;
160160
border-radius: 0;
161-
margin: 0;
162161
}
163162

164163
#footer {

0 commit comments

Comments
 (0)