mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-06 17:36:44 +08:00
---fix bug
This commit is contained in:
39
src/App.vue
39
src/App.vue
@@ -42,7 +42,6 @@ let time1 = ref(0);
|
||||
let time2 = ref(0);
|
||||
|
||||
onMounted(() => {
|
||||
init()
|
||||
window.addEventListener('beforeunload', e => beforeunloadHandler(e));
|
||||
window.addEventListener('unload', e => unloadHandler(e));
|
||||
})
|
||||
@@ -52,28 +51,7 @@ function beforeunloadHandler() {
|
||||
time1.value = new Date().getTime();
|
||||
}
|
||||
|
||||
async function init() {
|
||||
await validateToken();
|
||||
initDict("content_type"); //内容分类
|
||||
initDict("project_level"); //项目级别
|
||||
initDict("project_sys"); //培训分类
|
||||
initDict("project_pic"); //项目封面
|
||||
initDict("router_pic"); //路径图封面
|
||||
initDict("course_pic"); //课程封面
|
||||
initDict("job_type"); //岗位
|
||||
initDict("band"); //band
|
||||
}
|
||||
|
||||
async function validateToken() {
|
||||
try{
|
||||
await request(VALIDATE_TOKEN)
|
||||
await getUserInfo();
|
||||
await getUserPermission();
|
||||
}catch (e) {
|
||||
console.log('token失效 跳转到登录页')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function unloadHandler() {
|
||||
time2.value = new Date().getTime() - time1.value;
|
||||
@@ -83,23 +61,6 @@ function unloadHandler() {
|
||||
}
|
||||
}
|
||||
|
||||
async function getUserInfo() {
|
||||
const userInfo = await api2.userInfo();
|
||||
store.commit("SET_USER", userInfo.data.data);
|
||||
}
|
||||
|
||||
async function initDict(key) {
|
||||
const list = await getDictList(key);
|
||||
store.commit("SET_DICT", {key, data: list});
|
||||
}
|
||||
|
||||
async function getUserPermission() {
|
||||
return request(USER_PERMISSION, {permissionType: 'PAGE'}).then(res => {
|
||||
store.commit("SET_PERMISSION", res.data?.map(s => s.url));
|
||||
})
|
||||
}
|
||||
|
||||
const getDictList = (param) => api1.getDictTree({code: param,}).then((res) => res.data.data);
|
||||
</script>
|
||||
<style lang="scss">
|
||||
#app {
|
||||
|
||||
48
src/main.js
48
src/main.js
@@ -16,6 +16,11 @@ import 'element-plus/dist/index.css'
|
||||
import "@/assets/scss/common.scss"
|
||||
import Antd from 'ant-design-vue';
|
||||
import 'ant-design-vue/dist/antd.css';
|
||||
import {request} from "@/api/request";
|
||||
import {USER_PERMISSION, VALIDATE_TOKEN} from "@/api/apis";
|
||||
import * as api2 from "@/api";
|
||||
import * as api1 from "@/api/index1";
|
||||
import {getCookieForName} from "@/api/method";
|
||||
// import axios from 'axios'
|
||||
// axios.defaults.withCredentials = true;
|
||||
// import zhCN from 'ant-design-vue/es/locale/zh_CN';
|
||||
@@ -25,7 +30,50 @@ app.config.warnHandler = () => null;
|
||||
// app.use(ElementPlus, {
|
||||
// locale: zhCn,
|
||||
// })
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (!getCookieForName("token")) {
|
||||
window.location.href = process.env.VUE_APP_LOGIN_URL + encodeURIComponent(window.location.protocol + process.env.VUE_APP_BOE_API_URL + process.env.VUE_APP_BASE + router.currentRoute.value.fullPath)
|
||||
}
|
||||
//第一次进入 没有用户信息
|
||||
if(!store.state.userInfo.userId){
|
||||
try{
|
||||
await request(VALIDATE_TOKEN)
|
||||
await getUserInfo();
|
||||
await getUserPermission();
|
||||
init()
|
||||
next();
|
||||
}catch (e){
|
||||
console.log('token失效 跳转到登录页')
|
||||
}
|
||||
}
|
||||
})
|
||||
app.use(Antd);
|
||||
app.use(router);
|
||||
app.use(store);
|
||||
app.mount('#app');
|
||||
async function getUserPermission() {
|
||||
return request(USER_PERMISSION, {permissionType: 'PAGE'}).then(res => {
|
||||
store.commit("SET_PERMISSION", res.data?.map(s => s.url));
|
||||
})
|
||||
}
|
||||
async function getUserInfo() {
|
||||
const userInfo = await api2.userInfo();
|
||||
store.commit("SET_USER", userInfo.data.data);
|
||||
}
|
||||
async function initDict(key) {
|
||||
const list = await getDictList(key);
|
||||
store.commit("SET_DICT", {key, data: list});
|
||||
}
|
||||
const getDictList = (param) => api1.getDictTree({code: param,}).then((res) => res.data.data);
|
||||
|
||||
async function init() {
|
||||
initDict("content_type"); //内容分类
|
||||
initDict("project_level"); //项目级别
|
||||
initDict("project_sys"); //培训分类
|
||||
initDict("project_pic"); //项目封面
|
||||
initDict("router_pic"); //路径图封面
|
||||
initDict("course_pic"); //课程封面
|
||||
initDict("job_type"); //岗位
|
||||
initDict("band"); //band
|
||||
}
|
||||
@@ -16,7 +16,7 @@ module.exports = defineConfig({
|
||||
port: 8070,
|
||||
proxy: {
|
||||
"/manageApi": {
|
||||
target: 'http:' + process.env.VUE_APP_PROXY_URL,
|
||||
target: 'https:' + process.env.VUE_APP_PROXY_URL,
|
||||
changeOrigin: true, //表示是否改变原域名
|
||||
pathRewrite: {
|
||||
"^/manageApi": "",
|
||||
|
||||
Reference in New Issue
Block a user