-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathOneMenu.vue
246 lines (224 loc) · 4.95 KB
/
OneMenu.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<template>
<nav
v-outside="collapseMenu"
class="one-nav"
:class="{ expanded }"
>
<div
class="toggle"
@click="toggleMenu"
>
<veui-icon
class="expanded-icon"
name="chevron-left"
/>
<veui-icon
class="collapsed-icon"
name="hamburger"
/>
</div>
<veui-sidenav
class="one-menu"
:items="menuItems"
:expanded.sync="menuExpanded"
>
<template #item-label="{ name, label, sub, cn }">
<template v-if="name === '/components'">
{{ label }}
<veui-button
v-tooltip="t(sort ? 'unsort' : 'sort')"
class="sort"
:ui="`icon ${sort ? 'strong' : 'aux'}`"
@click.stop="sort = !sort"
>
<veui-icon name="one-alphabetical-sort"/>
</veui-button>
</template>
<template v-else>
<small
v-if="sub"
class="sub"
>⤷</small>{{ label
}}<small
v-if="cn"
class="cn"
>{{ cn }}</small>
</template>
</template>
</veui-sidenav>
</nav>
</template>
<script>
import { Button, Sidenav, Icon } from 'veui'
import i18n from '../common/i18n'
import veuiI18n from 'veui/mixins/i18n'
import tooltip from 'veui/directives/tooltip'
import outside from 'veui/directives/outside'
import { loadPref, savePref } from '../common/util'
import 'veui-theme-dls-icons/hamburger'
import 'veui-theme-dls-icons/chevron-left'
Icon.register({
'one-alphabetical-sort': {
width: 24,
height: 24,
d:
'M12 5h10v2H12m0 12v-2h10v2m-10-8h10v2H12m-3 0v2l-3.33 4H9v2H3v-2l3.33-4H3v-2M7 3H5c-1.1 0-2 .9-2 2v6h2V9h2v2h2V5a2 2 0 0 0-2-2m0 4H5V5h2Z'
}
})
export default {
name: 'one-menu',
directives: {
outside,
tooltip
},
components: {
'veui-button': Button,
'veui-sidenav': Sidenav,
'veui-icon': Icon
},
mixins: [i18n, veuiI18n],
props: {
expanded: Boolean,
nav: {
type: Array,
default () {
return []
}
}
},
data () {
return {
menuExpanded: [],
sort: false
}
},
computed: {
menuItems () {
return this.nav.map(item => this.normalizeItem(item))
}
},
watch: {
sort (val) {
savePref('sort-components', val)
}
},
created () {
this.menuExpanded = this.menuItems.map(({ name }) => name)
},
mounted () {
this.sort = loadPref('sort-components') || false
},
methods: {
getTitleDetail (title) {
let [main, cn] = title.split(' - ')
return [main, cn]
},
isActive (path) {
let { route = {} } = this.$router.resolve(path) || {}
return route.name === this.$route.name
},
normalizeItem ({ title, children, slug, sub, link, disabled }, base = '') {
const fullSlug = `${base}/${slug}`
const localePath = this.getLocalePath(fullSlug)
const to = link !== false && fullSlug && !disabled ? localePath : null
const [main, cn] = this.getTitleDetail(title)
const normalizedChildren = children
? children.map(child => this.normalizeItem(child, fullSlug))
: []
return {
label: main,
cn,
to,
name: fullSlug,
sub: this.sort ? false : sub,
disabled,
children: fullSlug === '/components' && this.sort
? normalizedChildren.sort((a, b) => a.label.localeCompare(b.label))
: normalizedChildren
}
},
toggleMenu () {
this.$emit('toggle', !this.expanded)
},
collapseMenu () {
this.$emit('toggle', false)
}
}
}
</script>
<style lang="stylus" scoped>
.one-nav
display flex
flex-direction column
background-color #fff
padding-top 24px
.one-menu
flex 1 1 auto
width 100%
overflow auto
.cn
margin-left 8px
opacity 0.7
.sub
margin-right 8px
opacity 0.3
& >>> .veui-menu-item-label
& >>> .veui-ai-menu-item-label
flex-grow 1
.sort
margin-left 8px
.toggle
display none
.disabled
opacity 0.3
pointer-events none
@media (max-width 480px)
.one-nav
position fixed
z-index 20
transition transform 0.3s, box-shadow 0.3s
transform translateX(-100%)
&.expanded
transform translateX(0)
box-shadow 0 0 48px rgba(0, 0, 0, 0.2)
header
position relative
.toggle
display flex
align-items center
justify-content center
width 36px
height 36px
position absolute
top 80px
left 100%
border 1px solid #e2e6f0
border-top-right-radius 4px
border-bottom-right-radius 4px
background-color #fff
box-shadow 0 0 12px rgba(0, 0, 0, 0.1)
font-size 20px
&::before
content ""
position absolute
top 0
bottom 0
left -19px
width 20px
background-color #fff
.expanded-icon
.collapsed-icon
position absolute
transition transform 0.3s, opacity 0.3s
.expanded-icon
margin-left -4px
opacity 0
transform translateX(-10px)
.expanded &
opacity 1
transform none
.collapsed-icon
.expanded &
opacity 0
transform translateX(10px)
</style>