/
App.vue
144 lines (137 loc) · 3.75 KB
/
App.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>
<main class="w-full text-gray-700" x-data="layout">
<header
class="flex w-full items-center justify-between border-b-2 border-gray-200 bg-white p-2"
>
<div class="container px-4">
<div class="flex items-center space-x-2 justify-between">
<div class="flex justify-center items-center">
<img src="/vite.svg" alt="" />
<h1 class="text-sm font-bold" id="demo">範例Demo</h1>
</div>
<div class="flex items-center">
<button
type="button"
class="bg-yellow-500 text-white p-2"
@click="goToSignIn"
v-if="!isLoggedIn"
>
登入
</button>
<button
type="button"
class="bg-yellow-500 text-white p-2"
@click="handleSignOut"
v-if="isLoggedIn"
>
登出
</button>
<button
type="button"
class="bg-purple-500 text-white p-2"
@click="goToSignUP"
>
註冊
</button>
<button
type="button"
class="hover:border-green-600"
@click="asideOpen = !asideOpen"
>
<img src="/src/assets/icon/menu.png" alt="" width="20" />
</button>
</div>
</div>
</div>
</header>
<div class="container flex min-h-screen">
<!-- aside -->
<aside
class="flex w-72 flex-col space-y-2 border-r-2 border-gray-100 bg-white p-2"
v-show="asideOpen"
>
<router-link v-for="link in links" :key="link.to" :to="link.to">
{{ link.text }}
</router-link>
</aside>
<!-- main content page -->
<div class="w-full p-4">
<router-view />
</div>
</div>
</main>
</template>
<script setup>
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { getAuth, onAuthStateChanged, signOut } from 'firebase/auth';
const auth = getAuth();
const router = useRouter();
const asideOpen = ref(true);
const links = ref([
{ text: 'PhotoDraggable', to: '/' },
{ text: 'v-easy-lightbox', to: '/lightbox' },
{ text: 'vueFinalModal', to: '/vueFinalModal' },
{ text: 'windowResize', to: '/windowResize' },
{ text: 'resizeObserver', to: '/resizeObserver' },
{ text: 'vueEllipsis', to: '/vueEllipsis' },
{ text: 'resizeTextarea', to: '/resizeTextarea' },
{ text: 'TextToSpeech', to: '/textToSpeech' },
{ text: 'speechToText', to: '/speechToText' },
{ text: 'CompressorImg', to: '/CompressorImg' },
{ text: 'toastify', to: '/Toastify' },
{ text: 'intersectionObserverImg', to: '/intersectionObserverImg' },
{ text: 'AsyncComponent', to: '/asyncComponent' },
{
text: 'intersectionObserverComponent',
to: '/intersectionObserverComponent'
},
{
text: 'Onboarding',
to: '/onboarding'
},
{
text: 'Vmemo',
to: '/vmemo'
},
{
text: 'UseMemoize',
to: '/useMemoize'
},
{
text: 'SuccessSign',
to: '/successSign'
}
]);
const goToSignUP = () => {
router.push('/signUp');
};
const goToSignIn = () => {
router.push('/signIn');
};
const isLoggedIn = ref(false);
const handleSignOut = () => {
signOut(auth)
.then(() => {
console.log('已登出');
isLoggedIn.value = false;
router.push('/');
})
.catch(error => {
console.log('登出失敗', error);
});
};
onMounted(() => {
onAuthStateChanged(auth, user => {
user ? (isLoggedIn.value = true) : (isLoggedIn.value = false);
});
});
</script>
<style scoped>
a {
@apply flex items-center text-gray-800 space-x-1 text-sm py-2 px-2 hover:text-green-600;
}
.router-link-active {
@apply text-green-600;
}
</style>