From 45b4ff5c0b824d2e5b51a6af3c44076d05f0214d Mon Sep 17 00:00:00 2001 From: whychdw <496960745@qq.com> Date: 星期三, 18 十二月 2024 13:21:28 +0800 Subject: [PATCH] 内容提交 --- src/store/modules/user.js | 30 ++++++++++++------------------ 1 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/store/modules/user.ts b/src/store/modules/user.js similarity index 84% rename from src/store/modules/user.ts rename to src/store/modules/user.js index c6cb312..6746b34 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.js @@ -5,18 +5,9 @@ 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: '', @@ -27,14 +18,17 @@ 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 => { - this.token = 'admin'; - setToken('admin'); - console.log(response); - resolve(); + apiLogin(username.trim(), password).then((response) => { + if (response.code === 1 && response.data) { + this.token = 'admin'; + setToken('admin'); + resolve(response); + } else { + reject('鐢ㄦ埛鍚�/瀵嗙爜閿欒'); + } }).catch(error => { reject(error); }); @@ -60,7 +54,7 @@ }, // user logout - logout():Promise<void> { + logout() { return new Promise((resolve, reject) => { apiLogout().then(() => { this.token = ''; @@ -94,7 +88,7 @@ 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; -- Gitblit v1.9.1