Files
CKB-DataSourceCenter/TaskShow/src/store/user.ts
2026-01-05 10:20:08 +08:00

36 lines
704 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useUserStore = defineStore('user', () => {
// 用户 token
const token = ref<string | null>(null)
// 初始化 token从 localStorage 读取)
const initToken = () => {
const storedToken = localStorage.getItem('token')
if (storedToken) {
token.value = storedToken
}
}
// 设置 token
const setToken = (newToken: string) => {
token.value = newToken
localStorage.setItem('token', newToken)
}
// 清除用户信息
const clearUser = () => {
token.value = null
localStorage.removeItem('token')
}
return {
token,
initToken,
setToken,
clearUser
}
})