|
28 | 28 | <button v-if="showEdit" @click="$emit('add')" |
29 | 29 | 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" |
30 | 30 | title="添加网站"> |
31 | | - <div class="i-mdi-plus-circle text-gray-400 dark:text-gray-300"> |
32 | | - </div> |
| 31 | + <div class="i-mdi-plus-circle text-gray-400 dark:text-gray-300"></div> |
33 | 32 | </button> |
| 33 | + |
| 34 | + <!-- ✅ 改好的主题切换按钮 --> |
34 | 35 | <button @click="themeStore.toggleTheme" |
35 | 36 | 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" |
36 | | - :title="themeStore.isDarkTheme ? '浅色模式' : '深色模式'"> |
37 | | - <div |
38 | | - :class="themeStore.isDarkTheme ? 'i-mdi-white-balance-sunny text-blue-500 dark:text-blue-300' : 'i-mdi-moon-waxing-crescent text-gray-400 dark:text-gray-300'"> |
39 | | - </div> |
| 37 | + :title="themeTitle"> |
| 38 | + <div :class="themeIcon"></div> |
40 | 39 | </button> |
41 | 40 |
|
42 | 41 | <button v-if="showLogout" @click="handleLogout" |
43 | 42 | 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" |
44 | 43 | title="退出登录"> |
45 | | - <div class="i-mdi-logout text-gray-400 dark:text-gray-300"> |
46 | | - </div> |
| 44 | + <div class="i-mdi-logout text-gray-400 dark:text-gray-300"></div> |
47 | 45 | </button> |
48 | 46 |
|
49 | 47 | <button v-if="showLogin" @click="$emit('login')" |
50 | 48 | 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 | 49 | title="登录"> |
52 | | - <div class="i-mdi-login text-gray-400 dark:text-gray-300"> |
53 | | - </div> |
| 50 | + <div class="i-mdi-login text-gray-400 dark:text-gray-300"></div> |
54 | 51 | </button> |
55 | 52 | </div> |
56 | 53 | </div> |
|
67 | 64 | </button> |
68 | 65 | <button v-if="showEdit" @click="$emit('add')" |
69 | 66 | 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"> |
70 | | - <div class="i-mdi-plus-circle text-gray-400 dark:text-gray-300"> |
71 | | - </div> |
| 67 | + <div class="i-mdi-plus-circle text-gray-400 dark:text-gray-300"></div> |
72 | 68 | 添加网站 |
73 | 69 | </button> |
| 70 | + |
| 71 | + <!-- ✅ 移动端的主题按钮 --> |
74 | 72 | <button @click="themeStore.toggleTheme" |
75 | 73 | 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"> |
76 | | - <div |
77 | | - :class="themeStore.isDarkTheme ? 'i-mdi-white-balance-sunny text-blue-500 dark:text-blue-300' : 'i-mdi-moon-waxing-crescent text-gray-400 dark:text-gray-300'"> |
78 | | - </div> |
79 | | - {{ themeStore.isDarkTheme ? '浅色模式' : '深色模式' }} |
| 74 | + <div :class="themeIcon"></div> |
| 75 | + {{ themeTitle }} |
80 | 76 | </button> |
| 77 | + |
81 | 78 | <button v-if="showLogout" @click="handleLogout" |
82 | 79 | 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> |
| 80 | + <div class="i-mdi-logout text-gray-400 dark:text-gray-300"></div> |
85 | 81 | 登出 |
86 | 82 | </button> |
87 | 83 | <button v-if="showLogin" @click="$emit('login')" |
88 | 84 | 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"> |
89 | | - <div class="i-mdi-logout text-gray-400 dark:text-gray-300"> |
90 | | - </div> |
| 85 | + <div class="i-mdi-login text-gray-400 dark:text-gray-300"></div> |
91 | 86 | 登录 |
92 | 87 | </button> |
93 | 88 | </div> |
|
96 | 91 | </template> |
97 | 92 |
|
98 | 93 | <script setup lang="ts"> |
99 | | -import { ref, onMounted } from 'vue' |
| 94 | +import { ref, onMounted, computed } from 'vue' |
100 | 95 | import { useThemeStore } from '@/stores/themeStore' |
101 | 96 | import { useMainStore } from '@/stores' |
102 | 97 |
|
@@ -126,41 +121,49 @@ const toggleMobileMenu = () => { |
126 | 121 | isMobileMenuOpen.value = !isMobileMenuOpen.value |
127 | 122 | } |
128 | 123 |
|
129 | | -const showLogin = ref(false); |
130 | | -const showLogout = ref(false); |
131 | | -const showEdit = ref(false); |
| 124 | +const showLogin = ref(false) |
| 125 | +const showLogout = ref(false) |
| 126 | +const showEdit = ref(false) |
132 | 127 |
|
133 | 128 | async function updateAuthenticationStates() { |
134 | | - // Check if no authentication is needed |
135 | 129 | if (store.config.enableNoAuth) { |
136 | | - showLogin.value = false; |
137 | | - showLogout.value = false; |
138 | | - showEdit.value = true; |
| 130 | + showLogin.value = false |
| 131 | + showLogout.value = false |
| 132 | + showEdit.value = true |
139 | 133 | } else { |
140 | | - // Perform async token validation |
141 | 134 | try { |
142 | | - const isValid = await store.validateToken(); |
143 | | - showLogin.value = !isValid; |
144 | | - showLogout.value = isValid; |
145 | | - showEdit.value = isValid; |
| 135 | + const isValid = await store.validateToken() |
| 136 | + showLogin.value = !isValid |
| 137 | + showLogout.value = isValid |
| 138 | + showEdit.value = isValid |
146 | 139 | } catch (error) { |
147 | | - console.error('Error validating token:', error); |
148 | | - showLogin.value = true; |
149 | | - showLogout.value = false; |
150 | | - showEdit.value = false; |
| 140 | + console.error('Error validating token:', error) |
| 141 | + showLogin.value = true |
| 142 | + showLogout.value = false |
| 143 | + showEdit.value = false |
151 | 144 | } |
152 | 145 | } |
153 | 146 | } |
154 | 147 |
|
155 | | -// Call the function on component mount |
156 | 148 | onMounted(() => { |
157 | 149 | updateAuthenticationStates() |
158 | 150 | }) |
159 | 151 |
|
160 | 152 | const handleLogout = () => { |
161 | | - // Emit logout event |
162 | 153 | emit('logout') |
163 | 154 | updateAuthenticationStates() |
164 | 155 | } |
165 | 156 |
|
| 157 | +/* ====== 新增:主题模式按钮显示逻辑 ====== */ |
| 158 | +const themeIcon = computed(() => { |
| 159 | + if (themeStore.mode === 'system') return 'i-mdi-monitor text-blue-400' |
| 160 | + return themeStore.isDarkTheme |
| 161 | + ? 'i-mdi-moon-waxing-crescent text-gray-300' |
| 162 | + : 'i-mdi-white-balance-sunny text-yellow-500' |
| 163 | +}) |
| 164 | +
|
| 165 | +const themeTitle = computed(() => { |
| 166 | + if (themeStore.mode === 'system') return '跟随系统' |
| 167 | + return themeStore.isDarkTheme ? '深色模式' : '浅色模式' |
| 168 | +}) |
166 | 169 | </script> |
0 commit comments