@@ -7,6 +7,8 @@ import sortBy from 'lodash/sortBy'
7
7
import { isZhCN } from ' ../util'
8
8
import { Provider , create } from ' ../../components/_util/store'
9
9
import NProgress from ' nprogress'
10
+ import debounce from ' lodash/debounce'
11
+ import addDOMEventListener from ' add-dom-event-listener'
10
12
11
13
const docsList = [
12
14
{ key: ' introduce' , enTitle: ' Ant Design of Vue' , title: ' Ant Design of Vue' },
@@ -16,6 +18,27 @@ const docsList = [
16
18
{ key: ' changelog' , enTitle: ' Change Log' , title: ' 更新日志' },
17
19
{ key: ' i18n' , enTitle: ' Internationalization' , title: ' 国际化' },
18
20
]
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
+ }
19
42
20
43
export default {
21
44
props: {
@@ -29,7 +52,9 @@ export default {
29
52
})
30
53
this .subscribe ()
31
54
return {
55
+ showSideBars: true ,
32
56
currentSubMenu: [],
57
+ sidebarHeight: document .documentElement .offsetHeight ,
33
58
}
34
59
},
35
60
provide () {
@@ -42,15 +67,29 @@ export default {
42
67
this .unsubscribe ()
43
68
}
44
69
clearTimeout (this .timer )
70
+ if (this .resizeEvent ) {
71
+ this .resizeEvent .remove ()
72
+ }
73
+ if (this .debouncedResize && this .debouncedResize .cancel ) {
74
+ this .debouncedResize .cancel ()
75
+ }
45
76
},
46
77
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
+ })
54
93
},
55
94
watch: {
56
95
' $route.path ' : function () {
@@ -59,6 +98,12 @@ export default {
59
98
},
60
99
},
61
100
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
+ },
62
107
addSubMenu () {
63
108
if (this .$route .path .indexOf (' /docs/vue/' ) !== - 1 ) {
64
109
this .$nextTick (() => {
@@ -90,7 +135,7 @@ export default {
90
135
})
91
136
const showApi = this .$route .path .indexOf (' /components/' ) !== - 1
92
137
return (
93
- < a- anchor>
138
+ < a- anchor offsetTop = { 70 } class = ' demo-anchor ' >
94
139
{lis}
95
140
{showApi ? < a- anchor- link title= ' API' href= ' #API' / > : ' ' }
96
141
< / a- anchor>
@@ -124,6 +169,7 @@ export default {
124
169
},
125
170
mountedCallback () {
126
171
NProgress .done ()
172
+ document .documentElement .scrollTop = 0
127
173
},
128
174
},
129
175
@@ -186,14 +232,17 @@ export default {
186
232
}
187
233
const config = AllDemo[titleMap[reName]]
188
234
this .resetDocumentTitle (config, reName, isCN)
235
+ const { showSideBars , sidebarHeight } = this
189
236
return (
190
237
< div class = ' page-wrapper' >
191
238
< Header searchData= {searchData} name= {name}/ >
192
239
< a- locale- provider locale= {locale}>
193
240
< div class = ' main-wrapper' >
194
241
< 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>
196
244
< a- menu
245
+
197
246
class = ' aside-container menu-site'
198
247
selectedKeys= {[name]}
199
248
defaultOpenKeys= {[' Components' ]}
@@ -204,8 +253,14 @@ export default {
204
253
{MenuGroup}
205
254
< / a- sub- menu>
206
255
< / a- menu>
256
+ < div class = ' close-drawer' onClick= {() => { this .showSideBars = false }}>
257
+ < a- icon type= ' close' / >
258
+ < / div>
207
259
< / 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 }>
209
264
< div class = ' content main-container' >
210
265
< div class = ' toc-affix' style= ' width: 120px;' >
211
266
{this .getSubMenu (isCN)}
@@ -234,8 +289,10 @@ export default {
234
289
< / div>
235
290
< / a- col>
236
291
< / a- row>
292
+
237
293
< / div>
238
294
< / a- locale- provider>
295
+
239
296
{ name .indexOf (' back-top' ) === - 1 ? < a- back- top / > : null }
240
297
< / div>
241
298
)
0 commit comments