File was renamed from src/store/modules/user.ts |
| | |
| | | import tagsViewStore from './tagsView'; |
| | | import permissionStore from './permission'; |
| | | |
| | | export interface IUserState { |
| | | token: string; |
| | | userId: string, |
| | | name: string; |
| | | avatar: string; |
| | | introduction: string; |
| | | roles: string[]; |
| | | } |
| | | |
| | | export default defineStore({ |
| | | id: 'user', |
| | | state: ():IUserState => ({ |
| | | state: () => ({ |
| | | token: getToken(), |
| | | userId: '', |
| | | name: '', |
| | |
| | | getters: {}, |
| | | actions: { |
| | | // user login |
| | | login(userInfo):Promise<void> { |
| | | login(userInfo) { |
| | | const { username, password } = userInfo; |
| | | return new Promise((resolve, reject) => { |
| | | apiLogin(username.trim(), password).then(response => { |
| | | apiLogin(username.trim(), password).then((response) => { |
| | | if (response.code === 1 && response.data) { |
| | | this.token = 'admin'; |
| | | setToken('admin'); |
| | | console.log(response); |
| | | resolve(); |
| | | resolve(response); |
| | | } else { |
| | | reject('用户名/密码错误'); |
| | | } |
| | | }).catch(error => { |
| | | reject(error); |
| | | }); |
| | |
| | | }, |
| | | |
| | | // user logout |
| | | logout():Promise<void> { |
| | | logout() { |
| | | return new Promise((resolve, reject) => { |
| | | apiLogout().then(() => { |
| | | this.token = ''; |
| | |
| | | setToken(token); |
| | | |
| | | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| | | const infoRes = await this.getInfo() as any; |
| | | const infoRes = await this.getInfo(); |
| | | let roles = []; |
| | | if (infoRes.roles) { |
| | | roles = infoRes.roles; |