This commit is contained in:
2023-09-13 18:29:35 +08:00
commit 4ac8391a9a
126 changed files with 15555 additions and 0 deletions

44
src/store/user.js Normal file
View File

@@ -0,0 +1,44 @@
import { defineStore } from "pinia";
import _hook from "@/hooks/index.js";
import { login, getUserInfo } from "@/api/user.js";
export const useUser = defineStore("useUser", {
state: () => {
return {
userInfo: {},
token: _hook.useLocalStorage.get("token") || "",
};
},
getters: {},
actions: {
// 设置用户信息
async setUserInfo() {
if (_hook.useLocalStorage.get("userInfo")) {
this.userInfo = _hook.useLocalStorage.get("userInfo");
} else {
this.userInfo = await this.getUserInfo();
}
},
/**
* @description: 用户登录
* @param {*} param: 登录的参数
*/
userlogin(param) {
return login(param).then((res) => {
// console.log(res);
this.userInfo = res;
_hook.useLocalStorage.set("token", this.userInfo.token);
_hook.useLocalStorage.set("userInfo", this.userInfo.user);
return this.userInfo;
});
},
/**
* @description: 获取用户信息
*/
getUserInfo() {
return getUserInfo().then((res) => {
return res.userInfo;
});
},
},
});