u
This commit is contained in:
1 parent
bcc4722efc
commit
f48536774f
403 files changed
+34776
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
type IUserInfo = {
|
||||
id: string;
|
||||
account?: string;
|
||||
email?: string;
|
||||
name?: string;
|
||||
token?: string;
|
||||
avatar?: string;
|
||||
};
|
||||
|
||||
const initState = { id: "", account: "", email: "", name: "", token: "" };
|
||||
|
||||
export const useUserStore = defineStore(
|
||||
"user",
|
||||
() => {
|
||||
const userInfo = ref<IUserInfo>({ ...initState });
|
||||
|
||||
const setUserInfo = (val: IUserInfo) => {
|
||||
userInfo.value = val;
|
||||
};
|
||||
|
||||
const clearUserInfo = () => {
|
||||
reset();
|
||||
};
|
||||
// 一般没有reset需求,不需要的可以删除
|
||||
const reset = () => {
|
||||
userInfo.value = {
|
||||
id: "",
|
||||
account: "",
|
||||
email: "",
|
||||
name: "",
|
||||
token: "",
|
||||
avatar: ""
|
||||
};
|
||||
};
|
||||
// ✅ 如果需要同时验证多个字段
|
||||
const isLogined = computed(() => {
|
||||
return !!(
|
||||
(
|
||||
userInfo.value.token && // 用户令牌
|
||||
userInfo.value.id && // 用户ID
|
||||
// userInfo.value.email && // 邮箱
|
||||
userInfo.value.account // 账户名
|
||||
)
|
||||
// userInfo.value.name // 名称
|
||||
);
|
||||
});
|
||||
|
||||
return {
|
||||
userInfo,
|
||||
setUserInfo,
|
||||
clearUserInfo,
|
||||
isLogined,
|
||||
reset
|
||||
};
|
||||
},
|
||||
{
|
||||
persist: true
|
||||
}
|
||||
);
|
||||
Reference in new issue
Block a user