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. 10
      src/layout/spacePage.vue
  6. 12
      src/layout/studyPage.vue
  7. 65
      src/permissions.ts
  8. 12
      src/store/modules/user.ts
  9. 3
      src/utils/auth.ts
  10. 81
      src/utils/request.ts
  11. 10
      src/views/largeDataScreen/home.vue
  12. 2
      src/views/program/index.vue

@ -1,4 +1,4 @@
# 变量必须以 VITE_ 为前缀才能暴露给外部读取 # 变量必须以 VITE_ 为前缀才能暴露给外部读取
NODE_ENV = 'development' NODE_ENV = 'development'
VITE_APP_TITLE = '实验仿真' 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 = () => { export const logout = () => {
return request({ return request({
url: '/sys/logout?_t=' + new Date().getTime(), url: '/sys/logout?_t=' + new Date().getTime(),
method: 'GET', method: 'PUT',
}) })
} }
// 获取用户信息 // 获取用户信息

@ -2,7 +2,7 @@
<div class="container-bgc"> <div class="container-bgc">
<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>

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

@ -141,7 +141,7 @@
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, logout } from "@/api/user"; import { getUserInfoService, userChangeService, logout } from "@/api/user";
@ -283,10 +283,14 @@ const handleClose = () => {
// 退 // 退
const logoutEvent = async () => { const logoutEvent = async () => {
await logout(); await logout().then(res => {
clearLocalStorage(); console.log(res,'111');
clearLocalStorage();
user.token = ''
router.push("/login"); router.push("/login");
})
}; };
</script> </script>

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

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

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

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

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

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

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

Loading…
Cancel
Save