From 1a1deaa093e8fc64b2f37900f5a92314ac70d01b Mon Sep 17 00:00:00 2001 From: JayChou Date: Thu, 27 Mar 2025 16:11:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=80=E5=87=BA=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- src/api/user.ts | 8 +- src/layout/loginPage.vue | 63 ++-- src/layout/spacePage.vue | 790 ++++++++++++++++++++------------------- src/permissions.ts | 10 +- src/utils/auth.ts | 13 + src/utils/request.ts | 17 +- 7 files changed, 475 insertions(+), 428 deletions(-) diff --git a/.env.development b/.env.development index 0e5f525..d94137e 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ # 变量必须以 VITE_ 为前缀才能暴露给外部读取 NODE_ENV = 'development' VITE_APP_TITLE = '实验仿真' -VITE_APP_BASE_API = '//localhost:16066/jeecg-boot' \ No newline at end of file +VITE_APP_BASE_API = '//localhost:3100/jeecgboot' \ No newline at end of file diff --git a/src/api/user.ts b/src/api/user.ts index 0b83cd4..f9c9d9f 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -23,7 +23,13 @@ export const sturegister = (data: any) => { data, }) } - +// 退出登录 +export const logout = () => { + return request({ + url: '/sys/logout?_t=' + new Date().getTime(), + method: 'GET', + }) +} // 获取用户信息 export const getUserInfoService = () => { return request({ diff --git a/src/layout/loginPage.vue b/src/layout/loginPage.vue index 295af84..dda4362 100644 --- a/src/layout/loginPage.vue +++ b/src/layout/loginPage.vue @@ -424,69 +424,67 @@ const formModel = ref({ const FacultiesList = ref([]); const getFacultiesList = async (data: any) => { - const res: any = await getFaculties(data) - console.log(res, 'res11') - if (data.primaryType == 3){ - FacultiesList.value = res.result.map((res:any) => { + const res: any = await getFaculties(data); + console.log(res, "res11"); + if (data.primaryType == 3) { + FacultiesList.value = res.result.map((res: any) => { return { value: res.id, label: res.name, - isLeaf: true - } - }) - }else{ + isLeaf: true, + }; + }); + } else { FacultiesList.value = res.result.map((res: any) => { return { value: res.id, label: res.name, - isLeaf: false - } - }) + isLeaf: false, + }; + }); } - -} -const deepValues = ref([]) +}; +const deepValues = ref([]); // 配置部门级联选择器 const props = { lazy: true, checkStrictly: true, emitPath: false, - isLeaf: 'isLeaf', + isLeaf: "isLeaf", async lazyLoad(node: any, resolve: any) { console.log(node); deepValues.value = node.pathValues; await getFacultiesList({ primaryType: node.level + 1, pid: node.value, - }) + }); const nodes = FacultiesList.value.map((item: any) => { if (!item.isLeaf) { return { value: item.value, label: item.label, isLeaf: item.isLeaf, - disabled:true - } + disabled: true, + }; } else { return { value: item.value, label: item.label, - isLeaf: item.isLeaf - } + isLeaf: item.isLeaf, + }; } - }) - console.log(nodes,'nodes'); - - resolve(nodes) + }); + console.log(nodes, "nodes"); + + resolve(nodes); }, -} -const cascader = ref(null) +}; +const cascader = ref(null); const handleChange = (e: any) => { console.log(e); - formModel.value.clssid = e - cascader.value.togglePopperVisible() -} - + formModel.value.clssid = e; + cascader.value.togglePopperVisible(); +}; // 添加校验规则 const rules = { @@ -572,11 +570,6 @@ const register = async () => { studentNumb: "", mobile: "", captcha: "", - } - ElMessage.success(`注册成功`) - isRegister.value = false - - }; ElMessage.success(`注册成功`); isRegister.value = false; diff --git a/src/layout/spacePage.vue b/src/layout/spacePage.vue index c9a9a58..984bdd5 100644 --- a/src/layout/spacePage.vue +++ b/src/layout/spacePage.vue @@ -1,204 +1,223 @@ \ No newline at end of file +// } + diff --git a/src/permissions.ts b/src/permissions.ts index a7a06f1..02c14d1 100644 --- a/src/permissions.ts +++ b/src/permissions.ts @@ -2,6 +2,8 @@ import router from "./router"; import userStore from "./store/modules/user"; import { getToken } from "./utils/auth"; import pinia from "./store"; +import {clearLocalStorage } from '@/utils/auth' + const store = userStore(pinia); router.beforeEach((to: any, from: any, next: any) => { if (to.path === "/login") { @@ -21,7 +23,13 @@ router.beforeEach((to: any, from: any, next: any) => { } else { store.getUserInfo().then(() => { next(); - }); + }) + .catch((error) => { + console.log(error); + + clearLocalStorage() + next("/login"); + }) } // next(); } else { diff --git a/src/utils/auth.ts b/src/utils/auth.ts index 11e86ff..90ca42c 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -4,8 +4,21 @@ const setToken = (token: string): void => { }; const getToken = () => localStorage.getItem(TOKEN_KEY) || ""; const removeToken = () => localStorage.removeItem(TOKEN_KEY); +const clearLocalStorage = () => { + removeToken(); + localStorage.removeItem("activeStepIndex"); + localStorage.removeItem("experimentPreservation"); + localStorage.removeItem("saveRoute"); + localStorage.removeItem("isRunCode"); + localStorage.removeItem("falg"); + localStorage.removeItem("product"); + localStorage.removeItem("installationStep"); + localStorage.removeItem("stepIds"); + +} export { setToken, getToken, removeToken, + clearLocalStorage }; diff --git a/src/utils/request.ts b/src/utils/request.ts index 7887f51..e0db2b4 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -21,18 +21,13 @@ server.interceptors.request.use((config) => { }); // 创建相应拦截器 server.interceptors.response.use((response) => { - if (response.data.code === 401) { - const useuserStore = userStore(pinia); + console.log(response); - // useuserStore.clearStatus(); - // return Promise.reject(response); - } - if (response.data.code != 200 && response.data.code != 0) { - ElMessage.error(response.data.message); - return Promise.reject(response); - } if (response.data.code === 401) { + ElMessage.error(response.data.message); + removeToken(); + router.push("/login"); return Promise.reject(response); } if (response.data.code === 412) { @@ -41,6 +36,10 @@ server.interceptors.response.use((response) => { router.push("/login"); return Promise.reject(response); } + if (response.data.code != 200 && response.data.code != 0) { + ElMessage.error(response.data.message); + return Promise.reject(response); + } return response.data; });