Commit d0c6244a authored by jiangqihao's avatar jiangqihao

权限管理菜单

parent ee984843
...@@ -14,5 +14,6 @@ export const role = { ...@@ -14,5 +14,6 @@ export const role = {
searchUrl: '/roleToMenu/search', searchUrl: '/roleToMenu/search',
detailUrl: '/roleToMenu/getOne', detailUrl: '/roleToMenu/getOne',
updateUrl: '/roleToMenu/update', updateUrl: '/roleToMenu/update',
deleteUrl: '/roleToMenu/delete' deleteUrl: '/roleToMenu/delete',
searchOneUrl: '/roleToMenu/searchOne',
} }
/*
* @Descripttion:
* @Author: 薛泽展
* @Date: 2021-10-12 12:29:05
* @Since: JDK1.8
*/
import router from './router' import router from './router'
import store from './store' import store from './store'
import { Message } from 'element-ui' import { Message } from 'element-ui'
...@@ -14,9 +8,9 @@ import getPageTitle from '@/utils/get-page-title' ...@@ -14,9 +8,9 @@ import getPageTitle from '@/utils/get-page-title'
NProgress.configure({ showSpinner: false }) // NProgress Configuration NProgress.configure({ showSpinner: false }) // NProgress Configuration
const whiteList = ['/prov-register', '/city-register','/prov-progress','/city-progress' ,'/login', '/auth-redirect'] // no redirect whitelist const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist
router.beforeEach(async(to, from, next) => { router.beforeEach(async (to, from, next) => {
// start progress bar // start progress bar
NProgress.start() NProgress.start()
// set page title // set page title
...@@ -34,7 +28,6 @@ router.beforeEach(async(to, from, next) => { ...@@ -34,7 +28,6 @@ router.beforeEach(async(to, from, next) => {
// determine whether the user has obtained his permission roles through getInfo // determine whether the user has obtained his permission roles through getInfo
const hasRoles = store.getters.roles && store.getters.roles.length > 0 const hasRoles = store.getters.roles && store.getters.roles.length > 0
if (hasRoles) { if (hasRoles) {
console.log(to)
store.commit('permission/SET_CURRENTTOPNAVPATH', to.matched[0].path) store.commit('permission/SET_CURRENTTOPNAVPATH', to.matched[0].path)
const routes = store.getters.permission_routes const routes = store.getters.permission_routes
routes.forEach(route => { routes.forEach(route => {
...@@ -47,10 +40,12 @@ router.beforeEach(async(to, from, next) => { ...@@ -47,10 +40,12 @@ router.beforeEach(async(to, from, next) => {
try { try {
// get user info // get user info
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor'] // note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
const { roles } = await store.dispatch('user/getInfo') const { ExtRoleCode_SDK } = await store.dispatch('user/getInfo')
// generate accessible routes map based on roles // 获取按钮权限
const accessRoutes = await store.dispatch('permission/generateRoutes', roles) await store.dispatch('permission/getPermissions', ExtRoleCode_SDK)
// 获取路由权限
const accessRoutes = await store.dispatch('permission/generateRoutes')
// dynamically add accessible routes // dynamically add accessible routes
router.addRoutes(accessRoutes) router.addRoutes(accessRoutes)
...@@ -62,31 +57,21 @@ router.beforeEach(async(to, from, next) => { ...@@ -62,31 +57,21 @@ router.beforeEach(async(to, from, next) => {
// remove token and go to login page to re-login // remove token and go to login page to re-login
await store.dispatch('user/resetToken') await store.dispatch('user/resetToken')
Message.error(error || 'Has Error') Message.error(error || 'Has Error')
next(`/login?redirect=${to.path}`) next(`/login?redirect=${to.fullPath}`)
NProgress.done() NProgress.done()
} }
} }
} }
} else { } else {
/* has no token*/ /* has no token*/
console.info('=========================111' + to.path)
if (whiteList.indexOf(to.path) !== -1) { if (whiteList.indexOf(to.path) !== -1) {
// in the free login whitelist, go directly // in the free login whitelist, go directly
console.info('=========================2222')
next() next()
} else { } else {
console.info('=========================3333')
// other pages that do not have permission to access are redirected to the login page. // other pages that do not have permission to access are redirected to the login page.
if (to.path === '/city-register') { next(`/login?redirect=${to.fullPath}`)
next({ path: '/city-register'}) NProgress.done()
} else if (to.path === '/prov-register') {
next({ path : '/prov-register'})
} else {
next(`/login?redirect=${to.path}`)
NProgress.done()
}
// next(`/login?redirect=${to.path}`)
// NProgress.done()
} }
} }
}) })
......
...@@ -64,19 +64,19 @@ const customersRouter = { ...@@ -64,19 +64,19 @@ const customersRouter = {
{ {
path: '/Provincial-agentList', path: '/Provincial-agentList',
component: () => import('@/views/customers/provincial-agentList'), component: () => import('@/views/customers/provincial-agentList'),
name: 'ProvincialAgentList', name: 'CustomersProvince',
meta: { title: '省级代理商' } meta: { title: '省级代理商' }
}, },
{ {
path: '/Municipal-agentList', path: '/Municipal-agentList',
component: () => import('@/views/customers/municipal-agentList'), component: () => import('@/views/customers/municipal-agentList'),
name: 'MunicipalAgentList', name: 'CustomersCity',
meta: { title: '城市代理商' } meta: { title: '城市代理商' }
}, },
{ {
path: '/potential', path: '/potential',
component: () => import('@/views/customers/potential-customers'), component: () => import('@/views/customers/potential-customers'),
name: 'PotentialCustomers', name: 'CustomersProcess',
meta: { title: 'potentialCustomers' } meta: { title: 'potentialCustomers' }
}, },
{ {
...@@ -88,7 +88,7 @@ const customersRouter = { ...@@ -88,7 +88,7 @@ const customersRouter = {
}, { }, {
path: '/Personal-customers', path: '/Personal-customers',
component: () => import('@/views/customers/personal-customers'), component: () => import('@/views/customers/personal-customers'),
name: 'PersonalCustomers', name: 'CustomersMessage',
meta: { title: '代理商信息' } meta: { title: '代理商信息' }
}, },
// { // {
......
...@@ -6,7 +6,7 @@ const modelsRouter = { ...@@ -6,7 +6,7 @@ const modelsRouter = {
path: '/models', path: '/models',
component: Layout, component: Layout,
redirect: '/models/potential', redirect: '/models/potential',
name: 'Models', name: 'Templates',
meta: { meta: {
topTitle: '模板', topTitle: '模板',
title: '模板管理', title: '模板管理',
...@@ -16,25 +16,25 @@ const modelsRouter = { ...@@ -16,25 +16,25 @@ const modelsRouter = {
{ {
path: 'total', path: 'total',
component: () => import('@/views/models/total-models'), component: () => import('@/views/models/total-models'),
name: 'TotalModels', name: 'TemplatesOverview',
meta: { title: '总代模板' } meta: { title: '总代模板' }
}, },
{ {
path: 'prov', path: 'prov',
component: () => import('@/views/models/prov-models'), component: () => import('@/views/models/prov-models'),
name: 'ProvModels', name: 'TemplatesProvince',
meta: { title: '省代模板' } meta: { title: '省代模板' }
}, },
{ {
path: 'city', path: 'city',
component: () => import('@/views/models/city-models'), component: () => import('@/views/models/city-models'),
name: 'CityModels', name: 'TemplatesCity',
meta: { title: '城市模板' } meta: { title: '城市模板' }
}, },
{ {
path: 'all', path: 'all',
component: () => import('@/views/models/all-models'), component: () => import('@/views/models/all-models'),
name: 'AllModels', name: 'TemplatesAll',
meta: { title: '模板' } meta: { title: '模板' }
}, },
{ {
......
import { asyncRoutes, constantRoutes } from '@/router' import { asyncRoutes, constantRoutes } from '@/router'
import normalRequest from '@/utils/normal-request'
import { role } from '@/api/account'
/** /**
* Use meta.role to determine if the current user has permission * Use meta.role to determine if the current user has permission
* @param roles * @param roles
* @param route * @param route
*/ */
function hasPermission(roles, route) { function hasPermission(route, paths) {
if (route.meta && route.meta.roles) { if (route.name) {
return roles.some(role => route.meta.roles.includes(role)) return paths.includes(route.name)
} else {
return true
} }
} }
function treeToArray(menus, permissions, paths) {
// if (menus && Array.isArray(menus)) {
menus.forEach(item => {
// if (item.isTrue) {
permissions.push(item.ID)
// if (item.path) {
paths.push(item.Path)
// }
// }
// treeToArray(item.subMenus, permissions, paths)
})
// }
}
/** /**
* Filter asynchronous routing tables by recursion * Filter asynchronous routing tables by recursion
* @param routes asyncRoutes * @param routes asyncRoutes
* @param roles * @param permissions
*/ */
export function filterAsyncRoutes(routes, roles) { export function filterAsyncRoutes(routes, paths) {
const res = [] const res = []
routes.forEach(route => { routes.forEach(route => {
const tmp = { ...route } const tmp = { ...route }
if (hasPermission(roles, tmp)) { if (hasPermission(route, paths)) {
if (tmp.children) { if (tmp.children) {
tmp.children = filterAsyncRoutes(tmp.children, roles) tmp.children = filterAsyncRoutes(tmp.children, paths)
} }
res.push(tmp) res.push(tmp)
} }
}) })
// console.log(res)
return res return res
} }
const state = { const state = {
routes: [], // 项目所有的路由 routes: [], // 项目所有的路由
addRoutes: [], addRoutes: [],
paths: JSON.parse(localStorage.getItem('PATHS')) || [], // 菜单路由
permissions: JSON.parse(localStorage.getItem('PERMISSIONS')) || [], // 按钮权限
sideRoutes: [], // 侧边栏路由,用于渲染侧边菜单栏 sideRoutes: [], // 侧边栏路由,用于渲染侧边菜单栏
currentTopNavPath: '' // 当前一级路由地址,用于刷新时回显当前选中的顶端菜单栏 currentTopNavPath: '' // 当前一级路由地址,用于刷新时回显当前选中的顶端菜单栏
} }
...@@ -46,6 +61,12 @@ const mutations = { ...@@ -46,6 +61,12 @@ const mutations = {
state.addRoutes = routes state.addRoutes = routes
state.routes = constantRoutes.concat(routes) state.routes = constantRoutes.concat(routes)
}, },
SET_PERMISSIONS: (state, permissions) => {
state.permissions = permissions
},
SET_PATHS: (state, paths) => {
state.paths = paths
},
SET_CURRENTTOPNAVPATH: (state, path) => { SET_CURRENTTOPNAVPATH: (state, path) => {
state.currentTopNavPath = path state.currentTopNavPath = path
}, },
...@@ -55,17 +76,32 @@ const mutations = { ...@@ -55,17 +76,32 @@ const mutations = {
} }
const actions = { const actions = {
generateRoutes({ commit }, roles) { generateRoutes({ commit }) {
return new Promise(resolve => { return new Promise(resolve => {
const paths = JSON.parse(localStorage.getItem('PATHS'))
let accessedRoutes let accessedRoutes
if (roles.includes('admin')) { const test = false // 是否测试阶段
accessedRoutes = asyncRoutes || [] if (test) {
accessedRoutes = asyncRoutes
} else { } else {
accessedRoutes = filterAsyncRoutes(asyncRoutes, roles) accessedRoutes = filterAsyncRoutes(asyncRoutes, paths)
} }
commit('SET_ROUTES', accessedRoutes) commit('SET_ROUTES', accessedRoutes)
resolve(accessedRoutes) resolve(accessedRoutes)
}) })
},
getPermissions({ commit }, roleId) {
console.log(roleId)
normalRequest(role.searchOneUrl, { id: roleId }).then(res => {
var menus = res.results.data.results[0].RoleToMenuMenuList
var permissions = []
var paths = []
treeToArray(menus, permissions, paths)
localStorage.setItem('PERMISSIONS', JSON.stringify(permissions))
localStorage.setItem('PATHS', JSON.stringify(paths))
commit('SET_PERMISSIONS', permissions)
commit('SET_PATHS', paths)
})
} }
} }
......
import { provinceSearch, citySearch, districtSearch } from '@/api/customers';
const sections = [
{
title: '基本信息',
formDesc: {
Name: {
type: 'lov',
label: '公司全称',
layout: 16,
code: 'qcc',
displayKey:'Name',
btnTitle: '获取企查查信息',
disabled:true,
returnFn: function(row) {
return {
Name: row.Name,
ExtSocialUnifiedCreditCode_SDK: row.CreditCode,
ExtCorporateName_SDK: row.OperName
}
},
},
ExtSecondName_SDK: {
type: 'input',
label: '公司全称曾用名',
layout: 12,
disabled:true,
},
ExtSocialUnifiedCreditCode_SDK: {
type: 'input',
label: '社会统一信用代码',
layout: 12,
disabled: true
},
ExtRegisteredCapital_SDK: {
type: 'input',
label: '注册资本(万元)',
layout: 12,
default: '',
disabled: true
},
ExtCorporateName_SDK: {
type: 'input',
label: '法人',
layout: 12,
disabled: true
},
// Ext_QuoteOppotunity_KUT: {
// type: 'input',
// label: '税务登记编号',
// layout: 12
// },
}
},
{
title: '地址信息',
formDesc: {
ExtProvince_SDK: {
type: 'select',
label: '省份',
layout: 12,
options: async data => {
const res = await provinceSearch({})
var result = res.results.map(item => {
return {
text: item.Name,
value: item.Code
}
})
return result
},
disabled:true,
},
ExtCity_SDK: {
type: 'select',
label: '地市',
layout: 12,
isOptions: true,
optionsLinkageFields: ['ExtProvince_SDK'],
options: async data => {
if (!data.ExtProvince_SDK) {
return []
}
const res = await citySearch({
provinceCode: data.ExtProvince_SDK
})
var result = res.results.map(item => {
return {
text: item.Name,
value: item.Code
}
})
return result
},
disabled:true,
},
ExtDistrict_SDK: {
type: 'select',
label: '县市',
layout: 12,
isOptions: true,
optionsLinkageFields: ['ExtProvince_SDK', 'ExtCity_SDK'],
options: async data => {
if (!data.ExtCity_SDK) {
return []
}
const res = await districtSearch({
cityCode: data.ExtCity_SDK
})
var result = res.results.map(item => {
return {
text: item.Name,
value: item.Code
}
})
return result
},
disabled:true,
},
ExtAddressDetail_SDK: {
type: 'input',
label: '详细经营地址',
layout: 12,
disabled:true,
},
}
},
{
title: '联系信息',
formDesc: {
ExtLeader_SDK: {
type: 'input',
label: '公司负责人姓名',
layout: 12,
disabled:true,
},
ExtLeaderPhone_SDK: {
type: 'input',
label: '公司负责人联系方式',
layout: 12,
disabled:true,
},
ExtLeaderEmail_SDK: {
type: 'input',
label: '公司负责人邮箱',
layout: 12,
disabled:true,
},
ExtUnis_SDK: {
type: 'input',
layout: 12,
label: 'Unis业务负责人姓名',
disabled:true,
break: true,
},
ExtUnisPhone_SDK: {
type: 'input',
layout: 12,
label: 'Unis业务负责人联系方式',
disabled:true,
},
ExtUnisEmail_SDK: {
type: 'input',
label: 'Unis业务负责人邮箱',
layout: 12,
disabled:true,
},
ExtBusiness_SDK: {
type: 'input',
layout: 12,
label: '商务负责人姓名',
disabled:true,
break: true,
},
ExtBusinessPhone_SDK: {
type: 'input',
layout: 12,
label: '商务负责人联系方式',
disabled:true,
},
ExtBusinessEmail_SDK: {
type: 'input',
label: '商务负责人邮箱',
layout: 12,
disabled:true,
},
}
}
]
export default sections
\ No newline at end of file
...@@ -25,6 +25,7 @@ import { customerCreate, provinceSearch, citySearch, districtSearch } from '@/ap ...@@ -25,6 +25,7 @@ import { customerCreate, provinceSearch, citySearch, districtSearch } from '@/ap
import customerAddAddress from './components/customersAdd-adress/index' import customerAddAddress from './components/customersAdd-adress/index'
import customerAddAccessory from './components/customersAdd-accessory/index' import customerAddAccessory from './components/customersAdd-accessory/index'
import { qccGetOne } from '@/api/qcc' import { qccGetOne } from '@/api/qcc'
import constant from './constant'
export default { export default {
components: { components: {
...@@ -42,6 +43,7 @@ export default { ...@@ -42,6 +43,7 @@ export default {
title: '代理商新增', title: '代理商新增',
loading: false, loading: false,
addBtnStart: false, addBtnStart: false,
displayBtn: false,
objectId: '', objectId: '',
formData: {}, formData: {},
sections: [ sections: [
...@@ -74,7 +76,7 @@ export default { ...@@ -74,7 +76,7 @@ export default {
type: 'input', type: 'input',
label: '社会统一信用代码', label: '社会统一信用代码',
layout: 12, layout: 12,
disabled: true disabled: this.displayBtn
}, },
ExtRegisteredCapital_SDK: { ExtRegisteredCapital_SDK: {
type: 'input', type: 'input',
...@@ -195,6 +197,7 @@ export default { ...@@ -195,6 +197,7 @@ export default {
layout: 12, layout: 12,
label: 'Unis业务负责人姓名', label: 'Unis业务负责人姓名',
disabled:false, disabled:false,
break: true,
}, },
ExtUnisPhone_SDK: { ExtUnisPhone_SDK: {
type: 'input', type: 'input',
...@@ -213,6 +216,7 @@ export default { ...@@ -213,6 +216,7 @@ export default {
layout: 12, layout: 12,
label: '商务负责人姓名', label: '商务负责人姓名',
disabled:false, disabled:false,
break: true,
}, },
ExtBusinessPhone_SDK: { ExtBusinessPhone_SDK: {
type: 'input', type: 'input',
...@@ -262,12 +266,12 @@ export default { ...@@ -262,12 +266,12 @@ export default {
handleSubmit (data) { handleSubmit (data) {
const formData = this.$translateToC4CData(data) const formData = this.$translateToC4CData(data)
formData.extCustomerType_SDK = '121' formData.extCustomerType_SDK = '121'
console.log(formData)
this.loading = true this.loading = true
customerCreate(this.paramsToFormData(formData)).then(res => { customerCreate(this.paramsToFormData(formData)).then(res => {
this.addBtnStart = true this.addBtnStart = true
this.objectId = res.results this.objectId = res.results
const objectID = res.results const objectID = res.results
this.sections = constant
this.$router.push({ this.$router.push({
path: '/customersAdd', path: '/customersAdd',
query: { objectID: objectID, addBtnStart: false} query: { objectID: objectID, addBtnStart: false}
...@@ -275,7 +279,6 @@ export default { ...@@ -275,7 +279,6 @@ export default {
this.$message.success('创建成功') this.$message.success('创建成功')
this.loading = false this.loading = false
}) })
// return Promise.resolve()
}, },
handleSuccess () { handleSuccess () {
// this.$message.success('创建成功') // this.$message.success('创建成功')
......
...@@ -213,7 +213,8 @@ export default { ...@@ -213,7 +213,8 @@ export default {
type: 'input', type: 'input',
layout: 12, layout: 12,
label: 'Unis业务负责人姓名', label: 'Unis业务负责人姓名',
disabled: true disabled: true,
break: true,
}, },
ExtUnisPhone_SDK: { ExtUnisPhone_SDK: {
type: 'input', type: 'input',
...@@ -231,7 +232,8 @@ export default { ...@@ -231,7 +232,8 @@ export default {
type: 'input', type: 'input',
layout: 12, layout: 12,
label: '商务负责人姓名', label: '商务负责人姓名',
disabled: true disabled: true,
break: true,
}, },
ExtBusinessPhone_SDK: { ExtBusinessPhone_SDK: {
type: 'input', type: 'input',
......
...@@ -195,7 +195,8 @@ export default { ...@@ -195,7 +195,8 @@ export default {
type: 'input', type: 'input',
layout: 12, layout: 12,
label: 'Unis业务负责人姓名', label: 'Unis业务负责人姓名',
disabled: true disabled: true,
break: true,
}, },
ExtUnisPhone_SDK: { ExtUnisPhone_SDK: {
type: 'input', type: 'input',
...@@ -213,7 +214,8 @@ export default { ...@@ -213,7 +214,8 @@ export default {
type: 'input', type: 'input',
layout: 12, layout: 12,
label: '商务负责人姓名', label: '商务负责人姓名',
disabled: true disabled: true,
break: true,
}, },
ExtBusinessPhone_SDK: { ExtBusinessPhone_SDK: {
type: 'input', type: 'input',
......
...@@ -195,7 +195,8 @@ export default { ...@@ -195,7 +195,8 @@ export default {
type: 'input', type: 'input',
layout: 12, layout: 12,
label: 'Unis业务负责人姓名', label: 'Unis业务负责人姓名',
disabled: true disabled: true,
break: true,
}, },
ExtUnisPhone_SDK: { ExtUnisPhone_SDK: {
type: 'input', type: 'input',
...@@ -213,7 +214,8 @@ export default { ...@@ -213,7 +214,8 @@ export default {
type: 'input', type: 'input',
layout: 12, layout: 12,
label: '商务负责人姓名', label: '商务负责人姓名',
disabled: true disabled: true,
break: true,
}, },
ExtBusinessPhone_SDK: { ExtBusinessPhone_SDK: {
type: 'input', type: 'input',
......
...@@ -198,8 +198,9 @@ export default { ...@@ -198,8 +198,9 @@ export default {
max: 16, max: 16,
type: "string", type: "string",
trigger: "blur", trigger: "blur",
message: "密码由字母(区分大小写)和数字组成,长度不能小于8位" } message: "请按照密码规则输入!!" }
], ],
tip: "密码由字母(区分大小写)和数字组成,长度8-16位",
attrs: { attrs: {
size: "mini", size: "mini",
clearable: false, clearable: false,
...@@ -217,9 +218,10 @@ export default { ...@@ -217,9 +218,10 @@ export default {
max: 16, max: 16,
type: "string", type: "string",
trigger: "blur", trigger: "blur",
message: "密码由字母(区分大小写)和数字组成,长度不能小于8位" message: "请按照密码规则输入!!"
} }
], ],
tip: "密码由字母(区分大小写)和数字组成,长度8-16位",
attrs: { attrs: {
size: "mini", size: "mini",
clearable: false, clearable: false,
......
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