4
4
@mouseleave =" hoverLeftBar(false)"
5
5
aria-labelledby =" primary-heading"
6
6
class =" transition-all duration-300 fixed z-20 w-62.5 bg-white flex-shrink-0 overflow-hidden overflow-y-auto h-full items-center drop-shadow-xl"
7
- :class =" { 'hidden-aside w-15.5': !isHover && !isPin }"
7
+ :class =" { 'hidden-aside w-15.5': !isSBOpen && !isSBPin }"
8
8
>
9
9
<div class =" container flex flex-col mx-auto items-stretch" >
10
10
<div class =" h-19.5 flex items-center relative" >
11
11
<small class =" absolute left-36 top-10 italic text-cyan-800" >v{{ version }}</small >
12
12
<a
13
- v-if =" (isHover && !isPin ) || isPin "
14
- :class =" { 'opacity-0': !isHover && !isPin }"
13
+ v-if =" (isSBOpen && !isSBPin ) || isSBPin "
14
+ :class =" { 'opacity-0': !isSBOpen && !isSBPin }"
15
15
class =" transition-opacity duration-300 opacity-1 p-6 block"
16
16
href =" #index"
17
17
>
25
25
<div class =" lg:col-span-10 xl:col-span-10 flex" >
26
26
<div class =" hidden lg:block flex-grow" >
27
27
<div class =" flex items-center space-x-2 2xl:space-x-4 text-black px-5" >
28
- <MenuIcon v-if =" !isPin" class =" cursor-pointer h-6 w-5" @click =" setIsPin(true)" />
29
- <MenuAlt1Icon
30
- v-if =" isPin"
31
- class =" cursor-pointer h-6 w-5"
32
- @click =" setIsPin(false)"
33
- />
28
+ <MenuIcon v-if =" !isSBPin" class =" cursor-pointer h-6 w-5" @click =" handleMenuClick" />
29
+ <MenuAlt1Icon v-else class =" cursor-pointer h-6 w-5" @click =" handleMenuClick" />
34
30
</div >
35
31
</div >
36
32
</div >
42
38
>
43
39
<ul class =" flex flex-col -mx-6" >
44
40
<li
45
- class =" relative flex flex-row mx-2 px-4 h-11 rounded-lg mb-px mt-0.5"
41
+ class =" relative flex flex-row mx-2 h-11 rounded-lg mb-px mt-0.5"
46
42
:class =" { ' bg-slate-100/50 ': route.name === item.name }"
47
43
v-for =" (item, index) in menuItems"
48
44
:key =" index"
53
49
aria-hidden =" true"
54
50
></span >
55
51
<router-link
56
- class =" inline-flex items-center w-full text-sm my-0.5 font-normal transition-colors duration-150 hover:text-gray-600 focus:text-gray-800"
52
+ class =" inline-flex px-4 items-center w-full text-sm my-0.5 font-normal transition-colors duration-150 hover:text-gray-600 focus:text-gray-800"
57
53
:class =" { ' text-gray-800 ': route.name === item.name }"
58
54
:to =" { name: item.name }"
59
55
:title =" item.title"
67
63
</div >
68
64
<span
69
65
class =" transition-opacity duration-300 opacity-1 ml-4 text-sm font-normal"
70
- :class =" { 'opacity-0': !isHover && !isPin }"
66
+ :class =" { 'opacity-0': !isSBOpen && !isSBPin }"
71
67
>{{ item.title }}</span
72
68
>
73
69
</router-link >
79
75
</template >
80
76
81
77
<script lang="ts">
82
- import { defineComponent , ref , computed , onMounted } from ' vue'
78
+ import { defineComponent , ref , computed , onMounted , watch } from ' vue'
83
79
import { useRoute } from ' vue-router'
84
80
import navigation from ' ./SidebarNav'
85
81
import { BellIcon , MenuIcon , MenuAlt1Icon } from ' @heroicons/vue/outline'
86
82
import { useDashboardStore } from ' ../../modules/dashboard/store'
87
83
import { onClickOutside } from ' @vueuse/core'
88
84
import env from ' core/env'
85
+ import { checkIsMobile } from ' utils/index'
89
86
90
87
interface MenuItem {
91
88
title: string
@@ -108,52 +105,49 @@ export default defineComponent({
108
105
const menuItems = ref <MenuItem []>(navigation )
109
106
const isPagesMenuOpen = ref (false )
110
107
const isSideMenuOpen = ref (false )
111
- const isHover = ref <boolean >(false )
112
108
const target = ref (null )
113
109
const version = ref (env (' VITE_APP_VERSION' ))
110
+ const isMobile = checkIsMobile ()
114
111
115
112
onClickOutside (target , (_ ) => {
116
- const winWidth = ref <number >(window .innerWidth )
117
- if (winWidth .value < 1024 && isPin ) {
118
- store .setSideBar (false )
119
- }
113
+ if (window .innerWidth < 640 ) store .setIsSBOpen (false )
120
114
})
121
115
122
116
onMounted (() => {
123
- if (window .innerWidth < 640 ) store .setSideBar (false )
117
+ window .addEventListener (' resize' , () => {
118
+ if (window .innerWidth < 1024 ) {
119
+ store .setIsSBOpen (false )
120
+ store .setIsSBPin (false )
121
+ }
122
+ })
124
123
})
125
124
126
- const isPin = computed <boolean >(() => store .isPin )
127
-
128
- const setIsPin = (value : boolean ) => {
129
- store .setSideBar (value )
130
- }
125
+ const isSBPin = computed <boolean >(() => store .isSBPin )
126
+ const isSBOpen = computed <boolean >(() => store .isSBOpen )
131
127
132
- const togglePagesMenu = () => {
133
- isSideMenuOpen . value = ! isSideMenuOpen . value
128
+ const hoverLeftBar = (v : boolean ) => {
129
+ if ( ! isMobile ) store . setIsSBOpen ( v )
134
130
}
135
131
136
- const closeSideMenu = () => {
137
- isSideMenuOpen . value = false
132
+ const handleMenuClick = () => {
133
+ store . toggleMenu ()
138
134
}
139
135
140
- const hoverLeftBar = ( b : boolean ) => {
141
- isHover . value = b
142
- }
136
+ watch ( route , ( ) => {
137
+ store . setIsSBOpen ( false )
138
+ })
143
139
144
140
return {
145
141
isPagesMenuOpen ,
146
- isHover ,
147
142
isSideMenuOpen ,
148
143
menuItems ,
149
144
route ,
150
- isPin ,
145
+ isSBPin ,
146
+ isSBOpen ,
151
147
target ,
152
148
version ,
153
- setIsPin ,
154
149
hoverLeftBar ,
155
- togglePagesMenu ,
156
- closeSideMenu ,
150
+ handleMenuClick ,
157
151
}
158
152
},
159
153
})
0 commit comments