Files
fe-manage/src/main.js
2024-09-24 17:49:00 +08:00

136 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @Author: lixg lixg@dongwu-inc.com
* @Date: 2022-11-09 09:26:26
* @LastEditors: lixg lixg@dongwu-inc.com
* @LastEditTime: 2022-11-26 14:54:37
* @FilePath: /fe-manage/src/main.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// import zhCn from 'element-plus/es/locale/lang/zh-cn'
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_INFO, USER_PERMISSION, VALIDATE_TOKEN} from "@/api/apis";
import * as api1 from "@/api/index1";
import {getCookieForName} from "@/api/method";
import components from './components'
import axios from 'axios'
import Cookies from "vue-cookies";
// axios.defaults.withCredentials = true;
// import zhCN from 'ant-design-vue/es/locale/zh_CN';
const app = createApp(App)
//全局注册
app.use(components)
// 清理控制台warn信息
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)
return
}
//第一次进入 没有用户信息
if(!store.state.userInfo.userId){
try{
await request(VALIDATE_TOKEN)
await getUserInfo()
await getUserPermission();
init()
}catch (e){
console.log('token失效 跳转到登录页')
}
}
next();
})
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 request(USER_INFO);
store.commit("SET_USER", userInfo.data);
axios({
method: "get",
url: "/userbasic/orgHrbp/reportOrgs",
params: {
workNum:userInfo.data.userNo
},
headers: {
"XBOR-Access-token": Cookies.get("token"),
},
}).then(res=>{
store.commit("SET_USER_ORGS", res.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);
const initDictTree = (key) => {
axios({
method: "get",
url: "/systemapi/xboe/type/tree-list",
params: {
sysResType: "1",
status: "1",
},
headers: {
"XBOR-Access-token": Cookies.get("token"),
},
}).then(
(res) => {
console.log(res.data.result,'课程分类接口')
store.commit("SET_DICT", {key, data: res.data.result});
//转化为map放到状态中
let map=new Map();
res.data.result.forEach(item=>{
map.set(item.id, item.name);
if(item.children && item.children!=''){
item.children.forEach(child=>{
map.set(child.id, child.name);
if(child.children && child.children!=''){
child.children.forEach(last=>{
map.set(last.id, last.name);
})
}
})
}
});
store.commit("SET_SYSTYPEMAP", map);
},
(err) => {
message.error(err);
}
);
}
async function init() {
// initDict("content_type"); //内容分类
initDictTree("content_type"); //内容分类换成type/tree-list接口
initDict("project_level"); //项目级别
initDict("project_sys"); //培训分类
initDict("project_pic"); //项目封面
initDict("router_pic"); //路径图封面
initDict("course_pic"); //课程封面
initDict("job_type"); //岗位
initDict("band"); //band
initDict("examine_cover") //讲师认证封面图
initDict("project_number") //项目编号
}