diff --git a/.env.development b/.env.development index 63e06a2..acfda19 100644 --- a/.env.development +++ b/.env.development @@ -3,9 +3,9 @@ VITE_APP_PORT = 3000 # 代理前缀 VITE_APP_BASE_API = '/api' -VITE_APP_API_URL = http://62.234.3.186/mk/ai/api +# VITE_APP_API_URL = http://62.234.3.186/mk/ai/api # 线上接口地址 -# VITE_APP_API_URL = http://62.234.3.186 +VITE_APP_API_URL = http://10.5.1.137:8800 # 开发接口地址 # VITE_APP_API_URL = http://localhost:8989 diff --git a/src/api/auth/index.ts b/src/api/auth/index.ts index b4e7a89..4b371c2 100644 --- a/src/api/auth/index.ts +++ b/src/api/auth/index.ts @@ -8,48 +8,45 @@ class AuthAPI { * @param data {LoginData} * @returns */ - static login(data: LoginData) { - /* + static login(data: LoginData) { const formData = new FormData(); formData.append("username", data.username); formData.append("password", data.password); formData.append("captchaKey", data.captchaKey || ""); formData.append("captchaCode", data.captchaCode || ""); return request({ - url: "/api/v1/auth/login", + url: "/session/login", method: "post", data: formData, headers: { "Content-Type": "multipart/form-data", }, - });*/ - return new Promise((resolve,reject)=>{ - if(data.username!='admin' || data.password!='123456'){ - reject("用户名或密码错误"); - }else{ - resolve( { - "accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImRlcHRJZCI6MSwiZGF0YVNjb3BlIjoxLCJleHAiOjE3MTYyMjY0OTksInVzZXJJZCI6MiwiaWF0IjoxNzE2MjE5Mjk5LCJhdXRob3JpdGllcyI6WyJST0xFX0FETUlOIl0sImp0aSI6IjVmMWIwNTExNmZjZDQxZmE5YTVlNjU4ZjQ5YmRmNmEyIn0.BBCWh3-bffEtgT0zhxSQ0ncithh9iIGDtbg1DPN0TvA", - "tokenType": "Bearer", - "refreshToken": null, - "expires": null - }); - } }); + // return new Promise((resolve,reject)=>{ + // if(data.username!='admin' || data.password!='123456'){ + // reject("用户名或密码错误"); + // }else{ + // resolve( { + // "accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsImRlcHRJZCI6MSwiZGF0YVNjb3BlIjoxLCJleHAiOjE3MTYyMjY0OTksInVzZXJJZCI6MiwiaWF0IjoxNzE2MjE5Mjk5LCJhdXRob3JpdGllcyI6WyJST0xFX0FETUlOIl0sImp0aSI6IjVmMWIwNTExNmZjZDQxZmE5YTVlNjU4ZjQ5YmRmNmEyIn0.BBCWh3-bffEtgT0zhxSQ0ncithh9iIGDtbg1DPN0TvA", + // "tokenType": "Bearer", + // "refreshToken": null, + // "expires": null + // }); + // } + // }); } /** * 注销API */ static logout() { - return new Promise(r=>{ - r({}); - }); - /* return request({ - url: "/api/v1/auth/logout", - method: "delete", + url: "/session/logout", + method: "post", }); - */ + // return new Promise(r=>{ + // r({}); + // }); } /** diff --git a/src/enums/CacheEnum.ts b/src/enums/CacheEnum.ts index f3c434b..bce4257 100644 --- a/src/enums/CacheEnum.ts +++ b/src/enums/CacheEnum.ts @@ -2,3 +2,7 @@ * 令牌缓存Key */ export const TOKEN_KEY = "accessToken"; + +export const UNAME_KEY = "userNameKey"; + +export const UROLE_KEY = "userRoleKey"; diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index c604ffc..bb13f6d 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -5,7 +5,7 @@ import { store } from "@/store"; import { LoginData } from "@/api/auth/model"; import { UserInfo } from "@/api/user/model"; -import { TOKEN_KEY } from "@/enums/CacheEnum"; +import { TOKEN_KEY,UNAME_KEY,UROLE_KEY } from "@/enums/CacheEnum"; export const useUserStore = defineStore("user", () => { const user = ref({ @@ -24,8 +24,11 @@ export const useUserStore = defineStore("user", () => { AuthAPI.login(loginData) .then((data) => { const { tokenType, accessToken } = data; + localStorage.setItem(UNAME_KEY, loginData.username); + localStorage.setItem(UROLE_KEY, data.role); localStorage.setItem(TOKEN_KEY, tokenType + " " + accessToken); // Bearer eyJhbGciOiJIUzI1NiJ9.xxx.xxx resolve(); + resolve(); }) .catch((error) => { reject(error); diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 55a047c..80fc724 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -95,7 +95,7 @@ const { height } = useWindowSize(); const loginData = ref({ username: "admin", - password: "123456", + password: "12345678", }); const loginRules = computed(() => {