@@ -7,6 +7,8 @@ import sortBy from 'lodash/sortBy'
77import { isZhCN } from ' ../util'
88import { Provider , create } from ' ../../components/_util/store'
99import NProgress from ' nprogress'
10+ import debounce from ' lodash/debounce'
11+ import addDOMEventListener from ' add-dom-event-listener'
1012
1113const 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
2043export 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 )
0 commit comments