xy 3 days ago
commit 8d10a89e72
  1. 2
      .env.development
  2. 2
      src/api/user.ts
  3. 2
      src/layout/index.vue
  4. 1
      src/layout/knowledgePage.vue
  5. 8
      src/layout/spacePage.vue
  6. 12
      src/layout/studyPage.vue
  7. 55
      src/permissions.ts
  8. 6
      src/store/modules/user.ts
  9. 3
      src/utils/auth.ts
  10. 67
      src/utils/request.ts
  11. 10
      src/views/largeDataScreen/home.vue
  12. 2
      src/views/program/index.vue

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

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

@ -2,7 +2,7 @@
<div class="container-bgc">
<div class="top">
<div class="loginBtn">
<p @click="loginFn">{{ user.token ? "已登录" : "登录/注册" }}</p>
<p @click="loginFn">{{ user.token ? "个人中心" : "登录/注册" }}</p>
</div>
<div class="title">{{ setting.title }}</div>

@ -94,6 +94,7 @@ const enter = () => {
const allStudied = Knowledges.value.every(item => item.isStudy);
if (allStudied) {
router.push('/studyPage');
localStorage.setItem('isStudy', 'true');
} else {
ElMessage.error('请先完成所有学习内容')
}

@ -141,7 +141,7 @@
import { ElMessage } from "element-plus";
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import settingStore from "@/store/modules/setting";
import settingStore from "@/store/modules/setting";;
const setting = settingStore();
import userStore from "@/store/modules/user";
import { getUserInfoService, userChangeService, logout } from "@/api/user";
@ -283,10 +283,14 @@ const handleClose = () => {
// 退
const logoutEvent = async () => {
await logout();
await logout().then(res => {
console.log(res,'111');
clearLocalStorage();
user.token = ''
router.push("/login");
})
};
</script>

@ -2,7 +2,7 @@
<div class="login_container">
<div class="top">
<div class="loginBtn">
<p @click="loginFn">{{ user.token ? "已登录" : "登录/注册" }}</p>
<p @click="loginFn">{{ user.token ? "个人中心" : "登录/注册" }}</p>
</div>
<div class="submit">
<p @click="submit">提交</p>
@ -13,7 +13,11 @@
<div
class="box"
:style="{
backgroundImage: isBox1Clicked ? `url(${btn1})` : `url(${btn2})`,
backgroundImage: isStudy
? `url(${btn1})`
: isBox2Clicked
? `url(${btn1})`
: `url(${btn2})`,
}"
@click="handleBoxClick(1)"
>
@ -22,7 +26,7 @@
<div
class="box"
:style="{
backgroundImage: isBox2Clicked ? `url(${btn1})` : `url(${btn2})`,
backgroundImage: complete ? `url(${btn1})` : `url(${btn2})`,
}"
@click="handleBoxClick(2)"
>
@ -98,7 +102,9 @@ import { submitExperiment, getScore } from "@/api";
import { ElMessage, ElMessageBox } from "element-plus";
const isShowExperiment =
Number(localStorage.getItem("activeStepIndex")) == 12 ? true : false;
const isStudy = Boolean(localStorage.getItem("isStudy")) || false;
const router = useRouter();
const complete = localStorage.getItem("complete");
const user = userStore();
const loginFn = () => {
// user.token ? router.push("/spacePage") : "";

@ -1,40 +1,41 @@
import router from "./router";
import userStore from "./store/modules/user";
import { getToken } from "./utils/auth";
import pinia from "./store";
import {clearLocalStorage } from '@/utils/auth'
import userStore from "./store/modules/user";
import { getToken, clearLocalStorage } from "@/utils/auth";
const store = userStore(pinia);
router.beforeEach((to: any, from: any, next: any) => {
router.beforeEach(async (to:any, from:any, next:any) => {
const { token, userInfo, getUserInfo } = store;
if (to.path === "/login") {
if (store.token) {
next("/studyPage");
} else {
next();
token ? next("/studyPage") : next();
return;
}
// next();
} else {
const token = getToken();
if (token) {
console.log(store.userInfo);
if (store.userInfo) {
next();
} else {
store.getUserInfo().then(() => {
next();
})
.catch((error) => {
console.log(error);
const authToken = getToken();
clearLocalStorage()
next("/login");
})
if (!authToken) {
return redirectToLogin(next);
}
// next();
} else {
next("/login");
if (userInfo) {
return next();
}
try {
await getUserInfo();
next();
} catch (error) {
console.error("获取用户信息失败:", error);
redirectToLogin(next);
}
});
const redirectToLogin = (next: any) => {
clearLocalStorage();
next("/login");
};
export default router;

@ -32,9 +32,15 @@ const userStore = defineStore("userStore", {
this.userInfo = null;
},
async getUserInfo() {
try {
const res:any = await getUserInfo();
this.userInfo = res.result.userInfo;
console.log(res);
} catch (error) {
console.log(error);
}
// this.userInfo = res.result;
},

@ -14,6 +14,9 @@ const clearLocalStorage = () => {
localStorage.removeItem("product");
localStorage.removeItem("installationStep");
localStorage.removeItem("stepIds");
// localStorage.removeItem("wenduCode");
// localStorage.removeItem("shiduCode");
localStorage.removeItem('isStudy')
}
export {

@ -5,44 +5,71 @@ import { ElMessage } from "element-plus";
import { removeToken } from "@/utils/auth";
import userStore from "@/store/modules/user";
import router from "@/router";
// 创建axios实例
const server = axios.create({
baseURL: import.meta.env.VITE_APP_BASE_API,
timeout: 30000,
});
// 创建请求拦截器
// 获取用户状态
// 创建请求拦截器
server.interceptors.request.use((config) => {
const useuserStore = userStore(pinia);
const useUserStore = userStore(pinia);
config.headers.Authorization = useuserStore.token;
config.headers["x-access-token"] = useuserStore.token;
if (useUserStore.token) {
config.headers.Authorization = useUserStore.token;
config.headers["x-access-token"] = useUserStore.token;
}
return config;
});
// 创建相应拦截器
server.interceptors.response.use((response) => {
console.log(response);
if (response.data.code === 401) {
// 处理错误的通用方法
const handleAuthError = (message:string) => {
const useUserStore = userStore(pinia);
ElMessage.error(response.data.message);
ElMessage.error(message);
removeToken();
useUserStore.token = "";
router.push("/login");
};
// 创建相应拦截器
server.interceptors.response.use(
(response) => {
const { code, message } = response.data;
switch (code) {
case 401:
case 412:
handleAuthError(message);
return Promise.reject(response);
}
if (response.data.code === 412) {
ElMessage.error(response.data.message);
removeToken();
router.push("/login");
case 200:
case 0:
return response.data;
default:
ElMessage.error(message);
return Promise.reject(response);
}
if (response.data.code != 200 && response.data.code != 0) {
ElMessage.error(response.data.message);
return Promise.reject(response);
},
(error) => {
if (error.response) {
const { status, data } = error.response;
switch (status) {
case 401:
case 403:
case 500:
handleAuthError(data.message);
break;
default:
ElMessage.error(data.message || "请求出错,请稍后再试");
}
}
return response.data;
});
// 暴露axios实例
return Promise.reject(error);
}
);
export default server;

@ -749,6 +749,7 @@
</div>
</template>
</el-dialog>
<div class="setting"><el-button @click="router.back()">返回</el-button></div>
</template>
<script setup lang="ts">
@ -756,7 +757,7 @@ import { ref } from "vue";
import { setStepEvent } from "@/utils/setStep";
import { formatDate } from "@/utils";
import { useRouter, useRoute } from "vue-router";
import { onMounted } from "vue";
import { onMounted,onActivated } from "vue";
import settingStore from "@/store/modules/setting";
type Falg = boolean;
type Step = number;
@ -777,7 +778,7 @@ const router = useRouter();
const useSettingStore = settingStore();
const isShowIdea = ref<Boolean>(false);
console.log(route);
onMounted(() => {
onActivated(() => {
if (route.query.idea) {
isShowIdea.value = true;
installationStep.value = 10;
@ -1262,4 +1263,9 @@ const insatIdea = () => {
:deep(.el-input__inner) {
color: rgba(0, 0, 0, 0.6);
}
.setting{
position: absolute;
top: 20px;
right: 50px;
}
</style>

@ -236,7 +236,7 @@ onMounted(() => {
// #endregion
//
graph.on("node:click", ({ cell }: any) => {
if(isShowStrring) return
if(!isShowStrring) return
// console.log(cell.store.previous.name);
console.log(cell);
if (!useSettingStore.saveRoute) {

Loading…
Cancel
Save