-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
base.vue
174 lines (151 loc) · 3.85 KB
/
base.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
<script setup lang="ts">
const props = defineProps({
footerCatalog: {
type: Boolean,
default: false
},
})
const route = useRoute()
const appConfig = useAppConfig()
/**
*
* set head meta for almost all page
*
*/
useHead({
style: [
'body { overflow: overlay }'
],
link: [
{
rel: 'icon',
href: appConfig?.bloginote?.favicon
}
]
})
if(appConfig.bloginote.scrollSmooth) {
useHead({
style: [
'html, body { scroll-behavior: smooth }'
]
})
}
/**
*
* listen page resize
*
*/
let resizeTimer:(null | ReturnType<typeof setTimeout>) = null
const windowSize = useWindowSize()
onMounted(() => {
if (document) {
windowSize.value.width = document.documentElement.clientWidth
windowSize.value.height = document.documentElement.clientHeight
}
window.addEventListener('resize', () => {
if (resizeTimer) {
clearTimeout(resizeTimer)
}
resizeTimer = setTimeout(() => {
windowSize.value.width = document.documentElement.clientWidth
windowSize.value.height = document.documentElement.clientHeight
resizeTimer = null
}, 300)
})
})
/**
* listen page scroll
*/
const pageScrollTop = usePageScrollTop()
let scrollTimer:(null | ReturnType<typeof setTimeout>)
onMounted(() => {
if (document) {
// get the init page scroll top value
pageScrollTop.value = document.body.scrollTop || document.documentElement.scrollTop
document.addEventListener('scroll', () => {
if (scrollTimer) {
clearTimeout(scrollTimer)
scrollTimer = null
}
scrollTimer = setTimeout(() => {
pageScrollTop.value = document.body.scrollTop || document.documentElement.scrollTop
scrollTimer = null
}, 100)
})
}
})
const showSearchModal = useState('showSearchModal')
// keyboard shortcuts for search modal
const ModalKeyListener = function (event: KeyboardEvent) {
if(event.ctrlKey && event.key ==='k') {
event.preventDefault()
showSearchModal.value = !showSearchModal.value
} else if (showSearchModal.value && event.key === 'Escape') {
showSearchModal.value = false
}
}
onMounted(() => {
if (document) {
document.addEventListener('keydown', ModalKeyListener)
}
})
onUnmounted(() => {
document.removeEventListener('keydown', ModalKeyListener)
})
</script>
<template>
<div class="pb-20 sm:pb-0 bg-gray-50 flex flex-col min-h-screen">
<header
class="hidden sm:block shrink-0"
:class="route.path === '/' ? 'sm:sticky top-0 inset-x-0 z-30' : 'relative z-40'"
>
<HeaderNav>
<template #header-nav-right>
<slot name="header-nav-right" />
</template>
</HeaderNav>
</header>
<div class="grow flex flex-col">
<slot />
</div>
<hr class="p-4 w-1/5 mx-auto">
<FooterContent />
<Transition
enter-from-class="translate-y-36 md:translate-y-10"
enter-active-class="transition-transform duration-500 ease"
enter-to-class="translate-y-0"
leave-from-class="translate-y-0"
leave-active-class="transition-transform duration-75 ease"
leave-to-class="translate-y-36 md:translate-y-10"
>
<BackToTop v-show="pageScrollTop > 600" />
</Transition>
<nav class="sm:hidden fixed bottom-0 left-0 right-0 z-50">
<FooterNav
:footer-catalog="props.footerCatalog"
>
<template #footer-nav-right>
<slot name="footer-nav-right" />
</template>
</FooterNav>
</nav>
<ClientOnly>
<SearchModal v-show="showSearchModal" />
</ClientOnly>
</div>
</template>
<style lang="scss">
::-webkit-scrollbar {
width: 12px;
height: 12px;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: rgba(156, 163, 175, 1);
border: 3px solid transparent;
background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
background-color: rgba(107, 114, 128, 1);
}
</style>