1818
1919 <!-- PC端按钮组 -->
2020 <div class =" hidden md:flex items-center gap-4" >
21- <button @click =" toggleEditMode"
21+ <button v-if = " showEdit " @click =" toggleEditMode"
2222 class =" flex items-center gap-2 px-3 py-2 rounded-md bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700"
2323 :title =" editMode ? '浏览模式' : '编辑模式'" >
2424 <div
2525 :class =" [editMode ? 'i-mdi-eye text-blue-500 dark:text-blue-300' : 'i-mdi-pencil text-gray-400 dark:text-gray-300']" >
2626 </div >
2727 </button >
28- <button @click =" $emit('add')"
28+ <button v-if = " showEdit " @click =" $emit('add')"
2929 class =" flex items-center gap-2 px-3 py-2 rounded-md bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700"
3030 title =" 添加网站" >
3131 <div class =" i-mdi-plus-circle text-gray-400 dark:text-gray-300" >
3939 </div >
4040 </button >
4141
42- <button v-if =" !isNoAuthMode " @click =" $emit('logout') "
42+ <button v-if =" showLogout " @click =" handleLogout "
4343 class =" flex items-center gap-2 px-3 py-2 rounded-md bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700"
4444 title =" 退出登录" >
4545 <div class =" i-mdi-logout text-gray-400 dark:text-gray-300" >
4646 </div >
4747 </button >
48+
49+ <button v-if =" showLogin" @click =" $emit('login')"
50+ class =" flex items-center gap-2 px-3 py-2 rounded-md bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700"
51+ title =" 登录" >
52+ <div class =" i-mdi-login text-gray-400 dark:text-gray-300" >
53+ </div >
54+ </button >
4855 </div >
4956 </div >
5057
5158 <!-- 移动端菜单 -->
5259 <div v-if =" isMobileMenuOpen" class =" md:hidden bg-white dark:bg-gray-800 shadow-lg dark:shadow-gray-900" >
5360 <div class =" flex flex-col gap-2 p-4" >
54- <button @click =" toggleEditMode"
61+ <button v-if = " showEdit " @click =" toggleEditMode"
5562 class =" flex items-center gap-3 px-2 py-2 rounded-md bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700" >
5663 <div
5764 :class =" [editMode ? 'i-mdi-eye text-blue-500 dark:text-blue-300' : 'i-mdi-pencil text-gray-400 dark:text-gray-300']" >
5865 </div >
5966 {{ editMode ? '浏览模式' : '编辑模式' }}
6067 </button >
61- <button @click =" $emit('add')"
68+ <button v-if = " showEdit " @click =" $emit('add')"
6269 class =" flex items-center gap-3 px-3 py-2 rounded-md bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700" >
6370 <div class =" i-mdi-plus-circle text-gray-400 dark:text-gray-300" >
6471 </div >
7178 </div >
7279 {{ themeStore.isDarkTheme ? '浅色模式' : '深色模式' }}
7380 </button >
74- <button v-if =" !isNoAuthMode" @click =" $emit('logout')"
81+ <button v-if =" showLogout" @click =" $emit('logout')"
82+ class =" flex items-center gap-3 px-3 py-2 rounded-md bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700" >
83+ <div class =" i-mdi-logout text-gray-400 dark:text-gray-300" >
84+ </div >
85+ 登出
86+ </button >
87+ <button v-if =" showLogin" @click =" $emit('login')"
7588 class =" flex items-center gap-3 px-3 py-2 rounded-md bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700" >
7689 <div class =" i-mdi-logout text-gray-400 dark:text-gray-300" >
7790 </div >
78- 退出登录
91+ 登录
7992 </button >
8093 </div >
8194 </div >
8295 </div >
8396</template >
8497
8598<script setup lang="ts">
86- import { ref } from ' vue'
99+ import { ref , onMounted } from ' vue'
87100import { useThemeStore } from ' @/stores/themeStore'
101+ import { useMainStore } from ' @/stores'
88102
89103const themeStore = useThemeStore ()
104+ const store = useMainStore ()
90105
91106const props = defineProps <{
92107 editMode: boolean
93- isNoAuthMode: boolean
94108}>()
95109
96110const emit = defineEmits <{
97111 (e : ' update:editMode' , value : boolean ): void
98112 (e : ' add' ): void
99113 (e : ' logout' ): void
114+ (e : ' login' ): void
100115}>()
101116
102117const toggleEditMode = () => {
@@ -109,4 +124,41 @@ const toggleMobileMenu = () => {
109124 isMobileMenuOpen .value = ! isMobileMenuOpen .value
110125}
111126
127+ const showLogin = ref (false );
128+ const showLogout = ref (false );
129+ const showEdit = ref (false );
130+
131+ async function updateAuthenticationStates() {
132+ // Check if no authentication is needed
133+ if (store .config .enableNoAuth ) {
134+ showLogin .value = false ;
135+ showLogout .value = false ;
136+ showEdit .value = true ;
137+ } else {
138+ // Perform async token validation
139+ try {
140+ const isValid = await store .validateToken ();
141+ showLogin .value = ! isValid ;
142+ showLogout .value = isValid ;
143+ showEdit .value = isValid ;
144+ } catch (error ) {
145+ console .error (' Error validating token:' , error );
146+ showLogin .value = true ;
147+ showLogout .value = false ;
148+ showEdit .value = false ;
149+ }
150+ }
151+ }
152+
153+ // Call the function on component mount
154+ onMounted (() => {
155+ updateAuthenticationStates ()
156+ })
157+
158+ const handleLogout = () => {
159+ // Emit logout event
160+ emit (' logout' )
161+ updateAuthenticationStates ()
162+ }
163+
112164 </script >
0 commit comments