fix: login temp error
This commit is contained in:
+3
-1
@@ -24,6 +24,7 @@
|
|||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
"lucide-react": "^0.562.0",
|
"lucide-react": "^0.562.0",
|
||||||
"lucide-vue-next": "^0.562.0",
|
"lucide-vue-next": "^0.562.0",
|
||||||
|
"monaco-editor": "^0.52.0",
|
||||||
"pako": "^2.1.0",
|
"pako": "^2.1.0",
|
||||||
"radix-vue": "^1.9.17",
|
"radix-vue": "^1.9.17",
|
||||||
"reka-ui": "^2.6.1",
|
"reka-ui": "^2.6.1",
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
"tw-animate-css": "^1.4.0",
|
"tw-animate-css": "^1.4.0",
|
||||||
"typescript": "~5.9.3",
|
"typescript": "~5.9.3",
|
||||||
"vite": "^7.2.4",
|
"vite": "^7.2.4",
|
||||||
|
"vite-plugin-static-copy": "^2.3.0",
|
||||||
"vue-tsc": "^3.1.4"
|
"vue-tsc": "^3.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,12 +17,18 @@ async function getAuthStatus(force = false): Promise<boolean> {
|
|||||||
return isAuth
|
return isAuth
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重置认证状态(登录/登出时调用)
|
// 重置认证状态(登出时调用)
|
||||||
export function resetAuthCache() {
|
export function resetAuthCache() {
|
||||||
authChecked = false
|
authChecked = false
|
||||||
isAuth = false
|
isAuth = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 直接设置认证状态(登录成功时调用,避免多余请求)
|
||||||
|
export function setAuthCache(status: boolean) {
|
||||||
|
authChecked = true
|
||||||
|
isAuth = status
|
||||||
|
}
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(BASE_URL),
|
history: createWebHistory(BASE_URL),
|
||||||
routes: [
|
routes: [
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import ThemeToggle from '@/components/ThemeToggle.vue'
|
import ThemeToggle from '@/components/ThemeToggle.vue'
|
||||||
|
import { Loader2 } from 'lucide-vue-next'
|
||||||
import { api } from '@/api'
|
import { api } from '@/api'
|
||||||
import { toast } from 'vue-sonner'
|
import { toast } from 'vue-sonner'
|
||||||
import { resetAuthCache } from '@/router'
|
import { setAuthCache } from '@/router'
|
||||||
|
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
const username = ref('')
|
const username = ref('')
|
||||||
const password = ref('')
|
const password = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@@ -106,9 +107,12 @@ async function handleLogin() {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
await api.auth.login({ username: username.value, password: password.value })
|
await api.auth.login({ username: username.value, password: password.value })
|
||||||
resetAuthCache() // 重置认证缓存
|
setAuthCache(true) // 直接设置登录状态,避免多余请求
|
||||||
toast.success('登录成功')
|
toast.success('登录成功')
|
||||||
router.push('/')
|
|
||||||
|
// 使用 window.location.href 替代 router.push,确保应用状态完全重新初始化,解决偶发的路由卡死/白屏问题
|
||||||
|
const baseUrl = (window as any).__BASE_URL__ || ''
|
||||||
|
window.location.href = baseUrl + '/'
|
||||||
} catch {
|
} catch {
|
||||||
toast.error('登录失败,请检查用户名和密码')
|
toast.error('登录失败,请检查用户名和密码')
|
||||||
} finally {
|
} finally {
|
||||||
@@ -177,6 +181,7 @@ onMounted(loadSiteSettings)
|
|||||||
<Button type="submit"
|
<Button type="submit"
|
||||||
class="w-full h-12 text-base font-bold rounded-2xl bg-gradient-to-r from-primary/90 to-primary shadow-lg shadow-primary/20 hover:shadow-primary/30 hover:scale-[1.02] active:scale-[0.98] transition-all"
|
class="w-full h-12 text-base font-bold rounded-2xl bg-gradient-to-r from-primary/90 to-primary shadow-lg shadow-primary/20 hover:shadow-primary/30 hover:scale-[1.02] active:scale-[0.98] transition-all"
|
||||||
:disabled="loading">
|
:disabled="loading">
|
||||||
|
<Loader2 v-if="loading" class="mr-2 h-4 w-4 animate-spin" />
|
||||||
{{ loading ? '验证中...' : '立即登录' }}
|
{{ loading ? '验证中...' : '立即登录' }}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user