This commit is contained in:
zhu
2026-05-09 17:16:08 +08:00
parent 6587b0c1d9
commit 30f9467cc8
14 changed files with 256 additions and 181 deletions

View File

@@ -0,0 +1,35 @@
import {computed, onMounted, ref} from "vue";
import {getToken, logout, setToken} from "@/shared/auth";
export const useLogin = () => {
const token = ref<string | null>(null);
const isLoggedIn = computed(() => token.value !== null);
/**
* 登录
*/
const handleLogin = async () => {
let value = "xxx"
await setToken(value)
token.value = value
}
/**
* 退出登录
*/
const handleLogout = async () => {
await logout()
token.value = null
}
onMounted(async () => {
token.value = await getToken()
})
return {
isLoggedIn,
handleLogin,
handleLogout,
}
}