This commit is contained in:
oneao committed 2025-06-10 21:27:20 +08:00
commit c570ec514c
550 files changed
+152597

No files matched your search

@@ -0,0 +1,52 @@
import { defineStore } from "pinia";
import { computed, ref } from "vue";
type IUserInfo = {
id: string;
email: string;
displayName: string;
token: string;
};
const initState: IUserInfo = { id: "", email: "", displayName: "", token: "" };
export const useUserStore = defineStore(
"user",
() => {
const userInfo = ref<IUserInfo>({ ...initState });
const setUserInfo = (val: IUserInfo) => {
userInfo.value = val;
};
const clearUserInfo = () => {
userInfo.value.displayName = "";
userInfo.value.id = "";
userInfo.value.token = "";
};
const reset = () => {
userInfo.value = { ...initState }; // 使用initState确保一致性
};
// 判断是否已登录
const isLogined = computed(() => {
return !!(
userInfo.value.token && // 用户令牌
userInfo.value.id && // 用户ID
userInfo.value.email // 邮箱
);
});
return {
userInfo,
setUserInfo,
clearUserInfo,
isLogined,
reset
};
},
{
persist: true
}
);