Commit 3631a794 by caoyanzhi

权限控制

parent cfe1690f
...@@ -17,13 +17,14 @@ import axios from 'axios'; ...@@ -17,13 +17,14 @@ import axios from 'axios';
import ElementUI from 'element-ui'; import ElementUI from 'element-ui';
import App from './App.vue'; import App from './App.vue';
import router from './router'; import router from './router';
import { routes } from './router/routes.js';
import filters from '@/filters/index.js'; import filters from '@/filters/index.js';
// import { isRequest, itemCode } from '@/config'; // eslint-disable-next-line
import { permission, itemPerm } from '@/utils/permission.js';
Vue.use(VueRouter); Vue.use(VueRouter);
Vue.use(ElementUI); Vue.use(ElementUI);
// 请求头这种添加请求标识 // 请求头这种添加请求标识
// Object.assign(axios.defaults.headers.common, isRequest);
axios.defaults.withCredentials = true; axios.defaults.withCredentials = true;
Vue.prototype.axios = axios; Vue.prototype.axios = axios;
...@@ -37,8 +38,16 @@ Vue.config.productionTip = false; ...@@ -37,8 +38,16 @@ Vue.config.productionTip = false;
Object.keys(filters).forEach(key => { Object.keys(filters).forEach(key => {
Vue.filter(key, filters[key]); Vue.filter(key, filters[key]);
}); });
permission({
new Vue({ whiteRoute: ['/login', '/gic-error', '/403', '/404', '/500'],
router, router,
render: h => h(App) routes,
}).$mount('#app') createApp() {
new Vue({
router,
render: h => h(App)
}).$mount('#app')
}
});
...@@ -9,10 +9,10 @@ let accessPath = []; ...@@ -9,10 +9,10 @@ let accessPath = [];
let itemPermission = {}; let itemPermission = {};
function getGicMenu() { function getGicMenu() {
const getUserMenu = request({ url: '/hb-manage-web/list-menus-auth' }).then(res => { const getUserMenu = request({ url: '/hb-manage-web//list-staff-role-menu' }).then(res => {
accessPath = getProjectMenu(res.result || []); accessPath = getProjectMenu(res.result || []);
}); });
const getUserOperation = request({ url: '/hb-manage-web/list-operation-auth' }).then(res => { const getUserOperation = request({ url: '/hb-manage-web/list-staff-role-opeation' }).then(res => {
itemPermission = getItemPerm(res.result || []); itemPermission = getItemPerm(res.result || []);
}) })
return Promise.all([getUserMenu, getUserOperation]); return Promise.all([getUserMenu, getUserOperation]);
...@@ -75,7 +75,7 @@ function itemPerm(itemPermCode) { ...@@ -75,7 +75,7 @@ function itemPerm(itemPermCode) {
} }
let permission = function(config) { let permission = function(config) {
const { writeRoute, router, routes, createApp } = config; const { whiteRoute, router, routes, createApp } = config;
window.onload = async function() { window.onload = async function() {
// 获取菜单数据 // 获取菜单数据
...@@ -84,8 +84,8 @@ let permission = function(config) { ...@@ -84,8 +84,8 @@ let permission = function(config) {
if (path.indexOf('/login') == -1) { if (path.indexOf('/login') == -1) {
await getGicMenu(); await getGicMenu();
} }
if (Array.isArray(writeRoute)) { if (Array.isArray(whiteRoute)) {
accessPath = accessPath.concat(writeRoute); accessPath = accessPath.concat(whiteRoute);
} }
if (Array.isArray(routes)) { if (Array.isArray(routes)) {
// 项目中路由文件配置的路径 // 项目中路由文件配置的路径
......
...@@ -100,7 +100,7 @@ export default { ...@@ -100,7 +100,7 @@ export default {
// appType 1好办后台2应用后台3好办小程序4小程序应用 // appType 1好办后台2应用后台3好办小程序4小程序应用
// roleType 1管理员角色 2门店角色 // roleType 1管理员角色 2门店角色
prom.push(menuList(Object.assign({}, params, { appType: el.appType, roleType: 1 })).then(res => { prom.push(menuList(Object.assign({}, params, { appType: el.appType, roleType: 1 })).then(res => {
el.menuList = res.result || []; el.menuList = this.flatDataToTree(res.result || []);
el.menuList.forEach(item => { el.menuList.forEach(item => {
this.$set(el.checkedId, item.menuId, []); this.$set(el.checkedId, item.menuId, []);
}); });
...@@ -141,11 +141,11 @@ export default { ...@@ -141,11 +141,11 @@ export default {
flatDataToTree(data) { flatDataToTree(data) {
return data.filter(el => { return data.filter(el => {
// 返回当前节点下的子节点 // 返回当前节点下的子节点
const children = data.filter(item => item.parentId == el.menuId); const children = data.filter(item => item.parentCode == el.menuCode);
if (children.length > 0) { if (children.length > 0) {
el.children = children; // 如果存在子级,则给父级添加一个children属性,并赋值 el.children = children; // 如果存在子级,则给父级添加一个children属性,并赋值
} }
return el.parentId == 0; return el.parentCode == '';
}) })
}, },
getActiveMenuList() { getActiveMenuList() {
......
...@@ -173,11 +173,11 @@ export default { ...@@ -173,11 +173,11 @@ export default {
flatDataToTree(data) { flatDataToTree(data) {
return data.filter(el => { return data.filter(el => {
// 返回当前节点下的子节点 // 返回当前节点下的子节点
const children = data.filter(item => item.parentId == el.menuId); const children = data.filter(item => item.parentCode == el.menuCode);
if (children.length > 0) { if (children.length > 0) {
el.children = children; // 如果存在子级,则给父级添加一个children属性,并赋值 el.children = children; // 如果存在子级,则给父级添加一个children属性,并赋值
} }
return el.parentId == 0; return el.parentCode == '';
}) })
}, },
// 保存选中的子节点id // 保存选中的子节点id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment