-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathOneToc.vue
144 lines (132 loc) · 2.48 KB
/
OneToc.vue
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<template>
<nav
v-if="toc.length"
v-outside="collapseToc"
class="one-toc"
:class="{ expanded }"
>
<veui-anchor
ui="s"
target-offset="120px"
:items="toc"
/>
<div
class="toggle"
@click="toggleToc"
>
<veui-icon
class="collapsed-icon"
name="list-unordered"
/>
</div>
</nav>
</template>
<script>
import { Anchor, Icon } from 'veui'
import outside from 'veui/directives/outside'
import 'veui-theme-dls-icons/list-unordered'
const flattenRe = /(?:^|\/)(?:components|directives)\//
export default {
name: 'one-toc',
directives: {
outside
},
components: {
'veui-anchor': Anchor,
'veui-icon': Icon
},
props: {
items: {
type: Array,
default: () => []
}
},
data () {
return {
expanded: false
}
},
computed: {
flattenItems () {
return this.items.flatMap(
({ children }) => (children || []).map(({ children, ...child }) => child) || []
)
},
toc () {
if (flattenRe.test(this.$route.path)) {
return this.flattenItems
}
return this.items
}
},
methods: {
toggleToc () {
this.expanded = !this.expanded
},
collapseToc () {
if (this.expanded) {
this.expanded = false
}
}
}
}
</script>
<style lang="stylus" scoped>
.toggle
display none
/deep/
.veui-anchor-wrapper[ui~=s] .veui-tree-item
.veui-ai-anchor-wrapper[ui~=s] .veui-ai-tree-item
height 16.8px
@media (max-width 480px)
.one-toc
position fixed
background-color #fff
z-index 20
top 0
right 0
bottom 0
left auto
padding 40px 60px 40px 0
transition transform 0.3s
transform translateX(100%)
&::before
content ""
position absolute
top 0
bottom 0
left 0
width 1px
background-color #e2e6f0
&.expanded
transform translateX(0)
box-shadow 0 0 36px rgba(0, 0, 0, 0.1)
.toggle
z-index -1
display flex
align-items center
justify-content center
width 36px
height 36px
position absolute
top 80px
right 100%
border 1px solid #e2e6f0
border-top-left-radius 4px
border-bottom-left-radius 4px
background-color #fff
box-shadow 0 0 12px rgba(0, 0, 0, 0.1)
font-size 20px
z-index 1
&::before
content ""
position absolute
top 0
bottom 0
right -19px
width 20px
background-color #fff
&.expanded .toggle
transform translateX(100%)
opacity 0
</style>