mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-30 06:20:50 +00:00
Merge branch 'v5.0.0dev' of https://gitee.com/ZhongBangKeJi/CRMEB into v5.0.0dev
This commit is contained in:
commit
13f1669ecd
@ -199,23 +199,21 @@ export default {
|
||||
instance.confirmButtonText = this.$t('message.user.logOutExit');
|
||||
setTimeout(() => {
|
||||
AccountLogout().then((res) => {
|
||||
that.$Message.success('您已成功退出');
|
||||
that.$router.replace({ path: `${settings.routePre}/login` });
|
||||
localStorage.clear();
|
||||
this.$Message.success('您已成功退出');
|
||||
this.$router.replace({ path: `${settings.routePre}/login` });
|
||||
removeCookies('token');
|
||||
removeCookies('expires_time');
|
||||
removeCookies('uuid');
|
||||
sessionStorage.clear();
|
||||
// window.location.reload()
|
||||
setTimeout(() => {
|
||||
done();
|
||||
setTimeout(() => {
|
||||
instance.confirmButtonLoading = false;
|
||||
}, 300);
|
||||
}, 3000);
|
||||
});
|
||||
done();
|
||||
setTimeout(() => {
|
||||
instance.confirmButtonLoading = false;
|
||||
}, 300);
|
||||
}, 700);
|
||||
} else {
|
||||
console.log('您已成功退出1');
|
||||
|
||||
done();
|
||||
}
|
||||
},
|
||||
|
||||
@ -221,9 +221,6 @@ export default {
|
||||
this.$store.commit('userInfo/version', data.version);
|
||||
this.$store.commit('userInfo/newOrderAudioLink', data.newOrderAudioLink);
|
||||
this.login_captcha = 0;
|
||||
|
||||
// if (this.jigsaw) this.jigsaw.reset();
|
||||
|
||||
try {
|
||||
if (data.queue === false) {
|
||||
this.$Notice.warning({
|
||||
@ -242,7 +239,6 @@ export default {
|
||||
|
||||
this.checkSocket();
|
||||
} catch (e) {}
|
||||
// console.log(this.findFirstNonNullChildren(res.data.menus), 1111);
|
||||
PrevLoading.start();
|
||||
|
||||
return this.$router.replace({
|
||||
@ -259,6 +255,29 @@ export default {
|
||||
this.loading = false;
|
||||
}, 1000);
|
||||
},
|
||||
formatTwoStageRoutes(arr) {
|
||||
if (arr.length <= 0) return false;
|
||||
const newArr = [];
|
||||
const cacheList = [];
|
||||
arr.forEach((v) => {
|
||||
if (v?.meta?.keepAlive) {
|
||||
newArr.push({ ...v });
|
||||
cacheList.push(v.name);
|
||||
this.$store.dispatch('keepAliveNames/setCacheKeepAlive', cacheList);
|
||||
}
|
||||
});
|
||||
return newArr;
|
||||
},
|
||||
// 多级嵌套数组处理成一维数组
|
||||
formatFlatteningRoutes(arr) {
|
||||
if (arr.length <= 0) return false;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
if (arr[i].children) {
|
||||
arr = arr.slice(0, i + 1).concat(arr[i].children, arr.slice(i + 1));
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
},
|
||||
findFirstNonNullChildren(arr) {
|
||||
// 如果数组为空,返回null
|
||||
if (!arr || arr.length === 0) {
|
||||
@ -315,6 +334,7 @@ export default {
|
||||
let expiresTimeNum = expiresTime - nowTimeNum;
|
||||
return parseFloat(parseFloat(parseFloat(expiresTimeNum / 60) / 60) / 24);
|
||||
},
|
||||
|
||||
closefail() {
|
||||
// if (this.jigsaw) this.jigsaw.reset();
|
||||
this.$Message.error('校验错误');
|
||||
|
||||
@ -37,31 +37,6 @@ const router = new Router({
|
||||
mode: Setting.routerMode,
|
||||
});
|
||||
|
||||
// 多级嵌套数组处理成一维数组
|
||||
export function formatFlatteningRoutes(arr) {
|
||||
if (arr.length <= 0) return false;
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
if (arr[i].children) {
|
||||
arr = arr.slice(0, i + 1).concat(arr[i].children, arr.slice(i + 1));
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
// 处理 tagsViewList 数据,默认路由全部缓存
|
||||
// isKeepAlive 处理 `name` 值,进行路由缓存
|
||||
export function formatTwoStageRoutes(arr) {
|
||||
if (arr.length <= 0) return false;
|
||||
const newArr = [];
|
||||
const cacheList = [];
|
||||
arr.forEach((v) => {
|
||||
newArr.push({ ...v });
|
||||
cacheList.push(v.name);
|
||||
store.dispatch('keepAliveNames/setCacheKeepAlive', cacheList);
|
||||
});
|
||||
return newArr;
|
||||
}
|
||||
|
||||
// 判断路由 meta.roles 中是否包含当前登录用户权限字段
|
||||
export function hasAuth(roles, route) {
|
||||
if (route.meta && route.meta.auth) return roles.some((role) => route.meta.auth.includes(role));
|
||||
@ -81,14 +56,6 @@ export function setFilterMenuFun(routes, role) {
|
||||
return menu;
|
||||
}
|
||||
|
||||
// 缓存多级嵌套数组处理后的一维数组(tagsView、菜单搜索中使用:未过滤隐藏的(isHide))
|
||||
export function setCacheTagsViewRoutes(arr) {
|
||||
// 先处理有权限的路由,否则 tagsView、菜单搜索中无权限的路由也将显示
|
||||
let rolesRoutes = setFilterMenuFun(arr, store.state.userInfo.access);
|
||||
// 添加到 vuex setTagsViewRoutes 中
|
||||
store.dispatch('tagsViewRoutes/setTagsViewRoutes', formatTwoStageRoutes(formatFlatteningRoutes(rolesRoutes)));
|
||||
}
|
||||
|
||||
// 递归处理多余的 layout : <router-view>,让需要访问的组件保持在第一层 layout 层。
|
||||
// 因为 `keep-alive` 只能缓存二级路由
|
||||
// 默认初始化时就执行
|
||||
@ -113,72 +80,6 @@ export function keepAliveSplice(to) {
|
||||
}
|
||||
}
|
||||
|
||||
// 处理后端返回的 `component` 路径,拼装实现懒加载
|
||||
export function loadView(path) {
|
||||
/**
|
||||
* 打包成一个 js、一个 css
|
||||
*/
|
||||
// if (path.indexOf('layout') > -1) return () => Promise.resolve(require(`@/${path}`));
|
||||
// else return () => Promise.resolve(require(`@/views/${path}`));
|
||||
|
||||
/**
|
||||
* 打包成多个 js、多个 css
|
||||
*/
|
||||
if (path.indexOf('layout') > -1) return () => import(`@/${path}`);
|
||||
else return () => import(`@/pages/${path}`);
|
||||
}
|
||||
|
||||
// 递归处理每一项 `component` 中的路径
|
||||
export function dynamicRouter(routes) {
|
||||
return routes.map((view) => {
|
||||
if (view.component) view.component = loadView(view.component);
|
||||
if (view.children) dynamicRouter(view.children);
|
||||
return view;
|
||||
});
|
||||
}
|
||||
|
||||
// 添加路由,模拟数据与方法,可自行进行修改 admin
|
||||
// 添加动态路由,`{ path: '*', redirect: '/404' }` 防止页面刷新,静态路由丢失问题
|
||||
// next({ ...to, replace: true }) 动态路由 addRoute 完毕后才放行,防止刷新时 NProgress 进度条加载2次
|
||||
// 文档地址:https://router.vuejs.org/zh/api/#router-addroutes
|
||||
export async function adminUser(router, to, next) {
|
||||
resetRouter();
|
||||
let menus = this.$store.state.menus.menusName;
|
||||
// 读取用户信息,获取对应权限进行判断
|
||||
store.dispatch('userInfos/setUserInfos');
|
||||
store.dispatch('routesList/setRoutesList', setFilterMenuFun(menus, store.state.userInfos.userInfos.roles));
|
||||
dynamicRoutes[0].children = menus;
|
||||
const awaitRoute = await dynamicRouter(dynamicRoutes);
|
||||
[...awaitRoute, { path: '*', redirect: '/404' }].forEach((route) => {
|
||||
router.addRoute({ ...route });
|
||||
});
|
||||
setCacheTagsViewRoutes(JSON.parse(JSON.stringify(menus)));
|
||||
next({ ...to, replace: true });
|
||||
}
|
||||
|
||||
// 添加路由,模拟数据与方法,可自行进行修改 test
|
||||
// 添加动态路由,`{ path: '*', redirect: '/404' }` 防止页面刷新,静态路由丢失问题
|
||||
export async function testUser(router, to, next) {
|
||||
resetRouter();
|
||||
let menus = this.$store.state.menus.menusName;
|
||||
|
||||
// 读取用户信息,获取对应权限进行判断
|
||||
store.dispatch('userInfos/setUserInfos');
|
||||
store.dispatch('routesList/setRoutesList', setFilterMenuFun(menus, store.state.userInfo.userInfo.access));
|
||||
dynamicRoutes[0].children = menus;
|
||||
const awaitRoute = await dynamicRouter(dynamicRoutes);
|
||||
[...awaitRoute, { path: '*', redirect: '/404' }].forEach((route) => {
|
||||
router.addRoute({ ...route });
|
||||
});
|
||||
setCacheTagsViewRoutes(JSON.parse(JSON.stringify(menus)));
|
||||
next({ ...to, replace: true });
|
||||
}
|
||||
|
||||
// 重置路由
|
||||
export function resetRouter() {
|
||||
router.matcher = router().matcher;
|
||||
}
|
||||
|
||||
// 延迟关闭进度条
|
||||
export function delayNProgressDone(time = 300) {
|
||||
setTimeout(() => {
|
||||
@ -186,13 +87,6 @@ export function delayNProgressDone(time = 300) {
|
||||
}, time);
|
||||
}
|
||||
|
||||
// 动态加载后端返回路由路由(模拟数据)
|
||||
export function getRouterList(router, to, next) {
|
||||
if (!Session.get('userInfo')) return false;
|
||||
if (Session.get('userInfo').userName === 'admin') adminUser(router, to, next);
|
||||
else if (Session.get('userInfo').userName === 'test') testUser(router, to, next);
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由拦截
|
||||
* 权限验证
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user