增加退出登录

main
JayChou 1 week ago
parent 7bba4f5e05
commit 1a1deaa093
  1. 2
      .env.development
  2. 8
      src/api/user.ts
  3. 61
      src/layout/loginPage.vue
  4. 178
      src/layout/spacePage.vue
  5. 10
      src/permissions.ts
  6. 13
      src/utils/auth.ts
  7. 17
      src/utils/request.ts

@ -1,4 +1,4 @@
# 变量必须以 VITE_ 为前缀才能暴露给外部读取 # 变量必须以 VITE_ 为前缀才能暴露给外部读取
NODE_ENV = 'development' NODE_ENV = 'development'
VITE_APP_TITLE = '实验仿真' VITE_APP_TITLE = '实验仿真'
VITE_APP_BASE_API = '//localhost:16066/jeecg-boot' VITE_APP_BASE_API = '//localhost:3100/jeecgboot'

@ -23,7 +23,13 @@ export const sturegister = (data: any) => {
data, data,
}) })
} }
// 退出登录
export const logout = () => {
return request({
url: '/sys/logout?_t=' + new Date().getTime(),
method: 'GET',
})
}
// 获取用户信息 // 获取用户信息
export const getUserInfoService = () => { export const getUserInfoService = () => {
return request({ return request({

@ -424,69 +424,67 @@ const formModel = ref({
const FacultiesList = ref([]); const FacultiesList = ref([]);
const getFacultiesList = async (data: any) => { const getFacultiesList = async (data: any) => {
const res: any = await getFaculties(data) const res: any = await getFaculties(data);
console.log(res, 'res11') console.log(res, "res11");
if (data.primaryType == 3){ if (data.primaryType == 3) {
FacultiesList.value = res.result.map((res:any) => { FacultiesList.value = res.result.map((res: any) => {
return { return {
value: res.id, value: res.id,
label: res.name, label: res.name,
isLeaf: true isLeaf: true,
} };
}) });
}else{ } else {
FacultiesList.value = res.result.map((res: any) => { FacultiesList.value = res.result.map((res: any) => {
return { return {
value: res.id, value: res.id,
label: res.name, label: res.name,
isLeaf: false isLeaf: false,
} };
}) });
} }
};
} const deepValues = ref([]);
const deepValues = ref([])
// //
const props = { const props = {
lazy: true, lazy: true,
checkStrictly: true, checkStrictly: true,
emitPath: false, emitPath: false,
isLeaf: 'isLeaf', isLeaf: "isLeaf",
async lazyLoad(node: any, resolve: any) { async lazyLoad(node: any, resolve: any) {
console.log(node); console.log(node);
deepValues.value = node.pathValues; deepValues.value = node.pathValues;
await getFacultiesList({ await getFacultiesList({
primaryType: node.level + 1, primaryType: node.level + 1,
pid: node.value, pid: node.value,
}) });
const nodes = FacultiesList.value.map((item: any) => { const nodes = FacultiesList.value.map((item: any) => {
if (!item.isLeaf) { if (!item.isLeaf) {
return { return {
value: item.value, value: item.value,
label: item.label, label: item.label,
isLeaf: item.isLeaf, isLeaf: item.isLeaf,
disabled:true disabled: true,
} };
} else { } else {
return { return {
value: item.value, value: item.value,
label: item.label, label: item.label,
isLeaf: item.isLeaf isLeaf: item.isLeaf,
} };
} }
}) });
console.log(nodes,'nodes'); console.log(nodes, "nodes");
resolve(nodes) resolve(nodes);
}, },
} };
const cascader = ref(null) const cascader = ref(null);
const handleChange = (e: any) => { const handleChange = (e: any) => {
console.log(e); console.log(e);
formModel.value.clssid = e formModel.value.clssid = e;
cascader.value.togglePopperVisible() cascader.value.togglePopperVisible();
} };
// //
const rules = { const rules = {
@ -572,11 +570,6 @@ const register = async () => {
studentNumb: "", studentNumb: "",
mobile: "", mobile: "",
captcha: "", captcha: "",
}
ElMessage.success(`注册成功`)
isRegister.value = false
}; };
ElMessage.success(`注册成功`); ElMessage.success(`注册成功`);
isRegister.value = false; isRegister.value = false;

@ -2,7 +2,7 @@
<div class="login_container"> <div class="login_container">
<div class="top"> <div class="top">
<div class="loginBtn"> <div class="loginBtn">
<p @click="loginFn">{{ user.token ? '已登录' : '登录/注册' }}</p> <p @click="loginFn">{{ user.token ? "已登录" : "登录/注册" }}</p>
</div> </div>
<div class="title">{{ setting.title }}</div> <div class="title">{{ setting.title }}</div>
</div> </div>
@ -15,12 +15,18 @@
<button class="btn1" @click="handleHomeClick">返回首页</button> <button class="btn1" @click="handleHomeClick">返回首页</button>
<button class="btn2" disabled>个人中心</button> <button class="btn2" disabled>个人中心</button>
<button class="btn3" @click="handlePasswordClick">重置密码</button> <button class="btn3" @click="handlePasswordClick">重置密码</button>
<button class="btn4" @click="logoutEvent">退出登录</button>
</div> </div>
<div class="rightBoxes"> <div class="rightBoxes">
<div class="topBox"> <div class="topBox">
<el-form style="margin:30px 0 0 200px;" :model="formModel" size="large" autocomplete="off"> <el-form
style="margin: 30px 0 0 200px"
:model="formModel"
size="large"
autocomplete="off"
>
<el-form-item> <el-form-item>
<div class="left" style="width: 60px;color: #fbfdfd;"> <div class="left" style="width: 60px; color: #fbfdfd">
用户账号 用户账号
</div> </div>
<div class="right"> <div class="right">
@ -29,7 +35,7 @@
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<div style="display: flex; align-items: center; color: pink"> <div style="display: flex; align-items: center; color: pink">
<div class="left" style="width: 60px;color: #fbfdfd;"> <div class="left" style="width: 60px; color: #fbfdfd">
姓名 姓名
</div> </div>
<div class="right"> <div class="right">
@ -38,9 +44,7 @@
</div> </div>
</el-form-item> </el-form-item>
<el-form-item prop="clssid"> <el-form-item prop="clssid">
<div class="left" style="width: 60px;color: #fbfdfd;"> <div class="left" style="width: 60px; color: #fbfdfd">班级</div>
班级
</div>
<div class="right"> <div class="right">
<el-input disabled v-model="formModel.className"></el-input> <el-input disabled v-model="formModel.className"></el-input>
</div> </div>
@ -48,10 +52,14 @@
</el-form> </el-form>
</div> </div>
<div class="bottomBox"> <div class="bottomBox">
<el-form size="large" style="margin:30px 0 0 265px;" :model="formModel"> <el-form
size="large"
style="margin: 30px 0 0 265px"
:model="formModel"
>
<el-form-item> <el-form-item>
<div style="display: flex; align-items: center;"> <div style="display: flex; align-items: center">
<div class="left" style="width: 60px;color: #fbfdfd;"> <div class="left" style="width: 60px; color: #fbfdfd">
学号 学号
</div> </div>
<div class="right"> <div class="right">
@ -60,8 +68,8 @@
</div> </div>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<div style="display: flex; align-items: center;"> <div style="display: flex; align-items: center">
<div class="left" style="width: 60px;color: #fbfdfd;"> <div class="left" style="width: 60px; color: #fbfdfd">
手机号 手机号
</div> </div>
<div class="right"> <div class="right">
@ -70,16 +78,28 @@
</div> </div>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<div style="display: flex; align-items: center;"> <div style="display: flex; align-items: center">
<div class="left" style="width: 60px;color: #fbfdfd;"> <div class="left" style="width: 60px; color: #fbfdfd">
成绩 成绩
</div> </div>
<div class="right"> <div class="right">
<el-input-number disabled v-model="formModel.score"></el-input-number> <el-input-number
disabled
v-model="formModel.score"
></el-input-number>
</div> </div>
<el-button <el-button
style="color: #333333; margin: 5px 3px 0 83px; font-size: 15px; font-weight: 700; background-color: #e9ddab;" style="
size="large" @click="openDialog">更改个人信息</el-button> color: #333333;
margin: 5px 3px 0 83px;
font-size: 15px;
font-weight: 700;
background-color: #e9ddab;
"
size="large"
@click="openDialog"
>更改个人信息</el-button
>
</div> </div>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -92,7 +112,7 @@
<!-- 弹框 --> <!-- 弹框 -->
<el-dialog v-model="dialog" title="更改个人信息" width="500"> <el-dialog v-model="dialog" title="更改个人信息" width="500">
<el-form :model="dialogForm" :rules="rules" ref="formRef"> <el-form :model="dialogForm" :rules="rules" ref="formRef">
<el-form-item prop="username" label="用户账号" style="margin-top: 30px;"> <el-form-item prop="username" label="用户账号" style="margin-top: 30px">
<el-input v-model="dialogForm.username" disabled></el-input> <el-input v-model="dialogForm.username" disabled></el-input>
</el-form-item> </el-form-item>
<el-form-item prop="name" label="姓名" label-width="58px"> <el-form-item prop="name" label="姓名" label-width="58px">
@ -118,50 +138,50 @@
</template> </template>
<script setup lang="ts" name="spacePage"> <script setup lang="ts" name="spacePage">
import { ElMessage } from 'element-plus' import { ElMessage } from "element-plus";
import { ref,onMounted} from "vue" import { ref, onMounted } from "vue";
import { useRouter } from 'vue-router' import { useRouter } from "vue-router";
import settingStore from "@/store/modules/setting"; import settingStore from "@/store/modules/setting";
const setting = settingStore(); const setting = settingStore();
import userStore from '@/store/modules/user'; import userStore from "@/store/modules/user";
import { getUserInfoService,userChangeService } from '@/api/user' import { getUserInfoService, userChangeService, logout } from "@/api/user";
// import {getFaculties } from '@/api/user' // import {getFaculties } from '@/api/user'
const router = useRouter()
import { clearLocalStorage } from "@/utils/auth";
const router = useRouter();
const user = userStore(); const user = userStore();
const loginFn = () => { const loginFn = () => {
router.push('/login') router.push("/login");
} };
const handleHomeClick = () => { const handleHomeClick = () => {
router.push("/studyPage");
router.push('/studyPage')
}; };
const handlePasswordClick = () => { const handlePasswordClick = () => {
console.log('密码管理'); console.log("密码管理");
router.push('/passwordPage') router.push("/passwordPage");
}; };
const formRef = ref(); const formRef = ref();
const formModel = ref({ const formModel = ref({
username: "", username: "",
realname: "", realname: "",
className: '', className: "",
workNo: "", workNo: "",
phone: '', phone: "",
score: '' score: "",
}); });
const dialogForm=ref({ const dialogForm = ref({
username: "", username: "",
name: "", name: "",
phone: '', phone: "",
}) });
const getUser=async()=>{ const getUser = async () => {
const res: any = await getUserInfoService(); const res: any = await getUserInfoService();
// console.log(res.result,'aaaaa'); // console.log(res.result,'aaaaa');
formModel.value = res.result; formModel.value = res.result;
// console.log(formModel, 'formModel'); // console.log(formModel, 'formModel');
dialogForm.value.username=res.result.username dialogForm.value.username = res.result.username;
} };
const rules = { const rules = {
username: [ username: [
@ -193,12 +213,11 @@ const rules = {
// message: "", // message: "",
// trigger: ["change", "blur"], // trigger: ["change", "blur"],
// }, // },
] ],
}; };
onMounted(()=>{ onMounted(() => {
getUser() getUser();
}) });
// // // //
// const FacultiesList = ref([]) // const FacultiesList = ref([])
@ -232,38 +251,43 @@ onMounted(()=>{
// dialogForm.value.clssid = e // dialogForm.value.clssid = e
// } // }
const loading = ref(false);
const loading = ref(false) const dialog = ref(false);
const dialog = ref(false) const changeInformation = async () => {
const changeInformation =async() => {
await formRef.value.validate(); await formRef.value.validate();
await userChangeService({ await userChangeService({
realname: dialogForm.value.name, realname: dialogForm.value.name,
phone: dialogForm.value.phone, phone: dialogForm.value.phone,
}) })
.then(() => { .then(() => {
ElMessage.success('修改成功') ElMessage.success("修改成功");
}) })
.catch((error) => { .catch((error) => {
// console.log(error, 'error') // console.log(error, 'error')
ElMessage.error(error.response.data.message) ElMessage.error(error.response.data.message);
}) });
loading.value = true loading.value = true;
setTimeout(() => { setTimeout(() => {
dialog.value = false dialog.value = false;
}, 400) }, 400);
getUser() getUser();
} };
const openDialog = () => { const openDialog = () => {
dialog.value = true dialog.value = true;
dialogForm.value.name = formModel.value.realname dialogForm.value.name = formModel.value.realname;
dialogForm.value.phone = formModel.value.phone dialogForm.value.phone = formModel.value.phone;
} };
const handleClose = () => { const handleClose = () => {
dialog.value = false dialog.value = false;
} };
// 退
const logoutEvent = async () => {
await logout();
clearLocalStorage();
router.push("/login");
};
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@ -298,12 +322,12 @@ const handleClose = () => {
/* 向左浮动 */ /* 向左浮动 */
top: 10px; top: 10px;
left: 230px; left: 230px;
border: 1px solid #33FEFE; border: 1px solid #33fefe;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
width: 142px; width: 142px;
height: 40px; height: 40px;
line-height: 37px; line-height: 37px;
background: linear-gradient(to bottom, #08B9C1, #0758B8); background: linear-gradient(to bottom, #08b9c1, #0758b8);
transform: skew(-30deg); transform: skew(-30deg);
cursor: pointer; cursor: pointer;
/* 在X轴方向倾斜 -30 度 */ /* 在X轴方向倾斜 -30 度 */
@ -368,7 +392,8 @@ const handleClose = () => {
.btn1, .btn1,
.btn2, .btn2,
.btn3 { .btn3,
.btn4 {
display: block; display: block;
width: 200px; width: 200px;
height: 55px; height: 55px;
@ -384,21 +409,26 @@ const handleClose = () => {
.btn1 { .btn1 {
position: absolute; position: absolute;
top: 268px; top: 238px;
left: 31%; left: 31%;
} }
.btn2 { .btn2 {
position: absolute; position: absolute;
left: 26%; left: 26%;
top: 360px; top: 320px;
background-color:#e2c04f ; background-color: #e2c04f;
} }
.btn3 { .btn3 {
position: absolute; position: absolute;
left: 22%; left: 22%;
top: 453px; top: 403px;
}
.btn4 {
position: absolute;
left: 18%;
top: 483px;
} }
} }
@ -456,8 +486,6 @@ const handleClose = () => {
left: 90px; left: 90px;
} }
} }
} }
} }
} }
@ -470,5 +498,5 @@ const handleClose = () => {
// transform: skewX(-15deg); // transform: skewX(-15deg);
// display: flex; // display: flex;
// }
// }</style> </style>

@ -2,6 +2,8 @@ import router from "./router";
import userStore from "./store/modules/user"; import userStore from "./store/modules/user";
import { getToken } from "./utils/auth"; import { getToken } from "./utils/auth";
import pinia from "./store"; import pinia from "./store";
import {clearLocalStorage } from '@/utils/auth'
const store = userStore(pinia); const store = userStore(pinia);
router.beforeEach((to: any, from: any, next: any) => { router.beforeEach((to: any, from: any, next: any) => {
if (to.path === "/login") { if (to.path === "/login") {
@ -21,7 +23,13 @@ router.beforeEach((to: any, from: any, next: any) => {
} else { } else {
store.getUserInfo().then(() => { store.getUserInfo().then(() => {
next(); next();
}); })
.catch((error) => {
console.log(error);
clearLocalStorage()
next("/login");
})
} }
// next(); // next();
} else { } else {

@ -4,8 +4,21 @@ const setToken = (token: string): void => {
}; };
const getToken = () => localStorage.getItem(TOKEN_KEY) || ""; const getToken = () => localStorage.getItem(TOKEN_KEY) || "";
const removeToken = () => localStorage.removeItem(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 { export {
setToken, setToken,
getToken, getToken,
removeToken, removeToken,
clearLocalStorage
}; };

@ -21,18 +21,13 @@ server.interceptors.request.use((config) => {
}); });
// 创建相应拦截器 // 创建相应拦截器
server.interceptors.response.use((response) => { server.interceptors.response.use((response) => {
if (response.data.code === 401) { console.log(response);
const useuserStore = userStore(pinia);
// 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) { if (response.data.code === 401) {
ElMessage.error(response.data.message); ElMessage.error(response.data.message);
removeToken();
router.push("/login");
return Promise.reject(response); return Promise.reject(response);
} }
if (response.data.code === 412) { if (response.data.code === 412) {
@ -41,6 +36,10 @@ server.interceptors.response.use((response) => {
router.push("/login"); router.push("/login");
return Promise.reject(response); 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; return response.data;
}); });

Loading…
Cancel
Save