提交 3f8ede6a authored 作者: pengxiaohui's avatar pengxiaohui

修复权限登录

上级 2be30278
import httpRequest from '@/utils/axios'
/**
* 操作日志
*/
export function operateLog(params) {
const logMsg = `操作人:${params.user.nickname},操作:${params.type}`
const data = {
detail: logMsg
}
httpRequest.post('/api/live/admin/v2/system/log/write', data).then(res => {
}).catch(() => {})
}
/**
* 模糊搜索
*/
export function searchUserList(params) {
return httpRequest.get('/api/live/common/v1/sso-user/search', { params })
}
/**
* 创建腾讯用户
*/
export function createAccount(data) {
return httpRequest.post('/api/live/admin/v2/tencent/user', data)
}
/**
* 获取腾讯用户列表(分页)
*/
export function getAccountList(params) {
return httpRequest.get('/api/live/admin/v2/tencent/users', { params })
}
/**
* 获取腾讯用户列表(不分页)
*/
export function getAllAccountList() {
return httpRequest.get('/api/live/admin/v2/tencent/user/list')
}
/**
* 更新腾讯用户
*/
export function updateAccount(data) {
return httpRequest.put(`/api/live/admin/v2/tencent/user/${data.userid}/update`, data)
}
/**
* 删除腾讯用户
*/
export function deleteAccount(params) {
return httpRequest.delete(`/api/live/admin/v2/tencent/user/${params.userid}/delete`, params)
}
/**
* 创建会议
*/
export function createMeeting(data) {
return httpRequest.post('/api/live/admin/v2/tencent/meeting', data)
}
/**
* 创建会议
*/
export function updateMeeting(data) {
return httpRequest.put(`/api/live/admin/v2/tencent/meeting/${data.meeting_id}/update`, data)
}
/**
* 获取腾讯会议列表
*/
export function getMeetingList(params) {
return httpRequest.get('/api/live/admin/v2/tencent/meetings', { params })
}
/**
* 获取腾讯会议列表(不分页)
*/
export function getNonpagedMeetingList(params) {
return httpRequest.get('/api/live/admin/v2/tencent/meeting/list-by-day', { params })
}
/**
* 获取腾讯会议详情
*/
export function getMeetingDetails(params) {
return httpRequest.get(`/api/live/admin/v2/tencent/meeting/${params.meeting_id}/detail`, { params })
}
/**
* 通过会议code获取腾讯会议详情
*/
export function getMeetingDetailsByCode(params) {
return httpRequest.get(`/api/live/admin/v2/tencent/meeting/${params.meeting_code}/detail-code`, { params })
}
/**
* 取消(删除)会议
*/
export function cancelMeeting(params) {
return httpRequest.post(`/api/live/admin/v2/tencent/meeting/${params.meeting_id}/cancel`, params)
}
/**
* 终止会议
*/
export function stopMeeting(params) {
return httpRequest.post(`/api/live/admin/v2/tencent/meeting/${params.meeting_id}/dimiss`, params)
}
/**
* 获取回放地址
*/
export function getMeetingRecordAddr(params) {
return httpRequest.post(`/api/live/admin/v2/tencent/meeting/${params.meeting_id}/records/address`, params)
}
/**
* 导出参会人员
*/
export function exportParticipants(params) {
return httpRequest({
url: `/api/live/admin/v2/tencent/meeting/${params.meeting_id}/participants/export`,
method: 'get',
params,
responseType: 'blob'
})
}
import httpRequest from '@/utils/axios'
/**
* 获取广告列表
*/
export function getAdList(params) {
return httpRequest.get('/api/cms/api/v1/advertisements', { params })
}
import httpRequest from '@/utils/axios'
/**
* 获取角色列表
*/
export function getRoleList(params) {
return httpRequest.get('/api/cms/admin/v1/roles', { params })
}
\ No newline at end of file
<template> <template>
<div> <div v-if="!navItem.hidden">
<el-menu-item v-if="hasChild(navItem)" :index="navItem.path"> <el-menu-item v-if="!hasChild(navItem)" :index="fullPath">
<i :class="navItem.icon"></i> <i :class="navItem.meta.icon"></i>
<span slot="title">{{navItem.title}}</span> <span slot="title">{{navItem.meta.title}}</span>
</el-menu-item> </el-menu-item>
<el-submenu v-else ref="subMenu" :index="navItem.path"> <el-submenu v-else ref="subMenu" :index="fullPath">
<template slot="title"> <template slot="title">
<i :class="navItem.icon"></i> <i :class="navItem.meta.icon"></i>
<span>{{navItem.title}}</span> <span>{{navItem.meta.title}}</span>
</template> </template>
<menu-item <menu-item
v-for="child in navItem.children" v-for="child in navItem.children"
:key="child.path" :key="child.path"
:navItem="child" :navItem="child"
:parent-path="fullPath"
class="nest-menu" class="nest-menu"
/> />
</el-submenu> </el-submenu>
</div> </div>
</template> </template>
<script> <script>
import path from 'path'
/**
* @param {string} path
* @returns {Boolean}
*/
export function isExternal(path) {
return /^(https?:|mailto:|tel:)/.test(path)
}
export default { export default {
name: 'MenuItem', name: 'MenuItem',
props: { props: {
navItem: { navItem: {
type: Object, type: Object,
required: true required: true
},
parentPath: {
type: String,
default: ''
} }
}, },
data() { data() {
return {} return {}
}, },
computed: {
routePath() {
return this.navItem.path
},
fullPath() {
if (isExternal(this.routePath)) {
return this.routePath
}
if (isExternal(this.parentPath)) {
return this.parentPath
}
return path.resolve(this.parentPath, this.routePath)
}
},
methods: { methods: {
hasChild (item) { hasChild (item) {
return !item.children || (item.children && item.children.length === 0) return item.children && item.children.length > 0
} }
} }
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
:collapse="isCollapse" :collapse="isCollapse"
@select="handlleSelect" @select="handlleSelect"
> >
<menu-item v-for="item in menu" :key="item.path" :navItem="item" /> <menu-item v-for="item in permission_routes" :key="item.path" :navItem="item" :parent-path="item.path"/>
</el-menu> </el-menu>
</el-scrollbar> </el-scrollbar>
</div> </div>
...@@ -84,7 +84,7 @@ export default { ...@@ -84,7 +84,7 @@ export default {
} }
}, },
computed: { computed: {
...mapGetters(['sidebar']), ...mapGetters(['sidebar', 'permission_routes']),
isCollapse() { isCollapse() {
return !this.sidebar.opened return !this.sidebar.opened
} }
...@@ -93,6 +93,7 @@ export default { ...@@ -93,6 +93,7 @@ export default {
watch: { watch: {
$route: { $route: {
handler: function(nv) { handler: function(nv) {
console.log(nv)
if (nv && nv.path) this.defaultActive = nv.path if (nv && nv.path) this.defaultActive = nv.path
else this.defaultActive = '' else this.defaultActive = ''
}, },
......
...@@ -52,7 +52,8 @@ export default { ...@@ -52,7 +52,8 @@ export default {
}, },
async logout() { async logout() {
await this.$store.dispatch('logout') await this.$store.dispatch('logout')
this.$router.push(`/${this.$route.fullPath}`) // console.log(this.$route.fullPath)
this.$router.push(this.$route.fullPath)
} }
} }
} }
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
<script> <script>
import TableList from '@/components/TableList' import TableList from '@/components/TableList'
import { permissionList } from './permission' import { permissionList } from './permission'
import { getRoleList } from '@/api/settings.js'
function recursionData(arr) { function recursionData(arr) {
const leafArr = [] const leafArr = []
function recursion(target) { function recursion(target) {
...@@ -235,7 +236,15 @@ export default { ...@@ -235,7 +236,15 @@ export default {
} }
}) })
}, },
fetchRoleList() {}, fetchRoleList() {
const params = {
page: 1,
limit: 20
}
getRoleList(params).then((res) => {
console.log(res)
})
},
fetchPermissionList() { fetchPermissionList() {
const result = permissionList const result = permissionList
const leafNodeList = recursionData(result) const leafNodeList = recursionData(result)
......
...@@ -4,32 +4,33 @@ export default [ ...@@ -4,32 +4,33 @@ export default [
path: '/', path: '/',
name: 'Layout', name: 'Layout',
component: Layout, component: Layout,
redirect: '/content-manage' redirect: '/content-manage',
hidden: true
}, },
{ {
path: '/content-manage', path: '/content-manage',
component: Layout, component: Layout,
redirect: '/content-manage/ads', redirect: '/content-manage/ads',
name: 'System', name: 'ContentManage',
meta: { title: '内容管理', icon: 'el-icon-setting' }, meta: { title: '内容管理', icon: 'el-icon-document' },
children: [ children: [
{ {
path: 'ads', path: 'ads',
name: 'Ads', name: 'Ads',
component: () => import('@/pages/content-manage/ads/index'), component: () => import('@/pages/content-manage/ads/index'),
meta: { title: '广告列表', icon: '', roles: ['content-menu-advert-list'], permission: 'content-menu-advert-list' } meta: { title: '广告列表', icon: '', permission: 'content-menu-advert-list' }
}, },
{ {
path: 'article', path: 'article',
name: 'Article', name: 'Article',
component: () => import('@/pages/content-manage/article/index'), component: () => import('@/pages/content-manage/article/index'),
meta: { title: '文章列表', icon: '', roles: ['content-menu-acticle-list'], permission: '1' } meta: { title: '文章列表', icon: '', permission: 'content-menu-acticle-list' }
}, },
{ {
path: 'image-text', path: 'image-text',
name: 'ImageText', name: 'ImageText',
component: () => import('@/pages/content-manage/image-text/index'), component: () => import('@/pages/content-manage/image-text/index'),
meta: { title: '图文列表', icon: '', roles: ['content-menu-imgtext-list'], permission: '2' } meta: { title: '图文列表', icon: '', permission: 'content-menu-imgtext-list' }
} }
] ]
}, },
...@@ -37,32 +38,32 @@ export default [ ...@@ -37,32 +38,32 @@ export default [
path: '/settings', path: '/settings',
component: Layout, component: Layout,
redirect: '/settings/staff', redirect: '/settings/staff',
name: 'System', name: 'Settings',
meta: { title: '设置', icon: 'el-icon-setting' }, meta: { title: '设置', icon: 'el-icon-setting' },
children: [ children: [
{ {
path: 'staff', path: 'staff',
name: 'Staff', name: 'Staff',
component: () => import('@/pages/settings/staff/index'), component: () => import('@/pages/settings/staff/index'),
meta: { title: '员工管理', icon: '', roles: ['setting-menu-user-manage'], permission: '' } meta: { title: '员工管理', icon: '', permission: 'setting-menu-user-manage' }
}, },
{ {
path: 'project', path: 'project',
name: 'Project', name: 'Project',
component: () => import('@/pages/settings/project/index'), component: () => import('@/pages/settings/project/index'),
meta: { title: '项目管理', icon: '', roles: ['setting-menu-project-manage'], permission: '' } meta: { title: '项目管理', icon: '', permission: 'setting-menu-project-manage' }
}, },
{ {
path: 'type', path: 'type',
name: 'Type', name: 'Type',
component: () => import('@/pages/settings/type/index'), component: () => import('@/pages/settings/type/index'),
meta: { title: '类型管理', icon: '', roles: ['setting-menu-type-manage'], permission: '' } meta: { title: '类型管理', icon: '', permission: 'setting-menu-type-manage' }
}, },
{ {
path: 'role', path: 'role',
name: 'Role', name: 'Role',
component: () => import('@/pages/settings/role/index'), component: () => import('@/pages/settings/role/index'),
meta: { title: '高级设置', icon: '', roles: ['setting-menu-advanced-setting'], permission: '' } meta: { title: '高级设置', icon: '', permission: 'setting-menu-advanced-setting' }
} }
] ]
}, },
...@@ -72,6 +73,7 @@ export default [ ...@@ -72,6 +73,7 @@ export default [
redirect: '/error-page/404', redirect: '/error-page/404',
name: 'ErrorPage', name: 'ErrorPage',
meta: { title: '访问出错', icon: 'el-icon-setting' }, meta: { title: '访问出错', icon: 'el-icon-setting' },
hidden: true,
children: [ children: [
{ {
path: '404', path: '404',
......
const getters = { const getters = {
user: state => state.user.user, user: state => state.user.user,
roles: state => state.user.roles, roles: state => state.user.roles,
sidebar: state => state.app.sidebar sidebar: state => state.app.sidebar,
permission_routes: state => state.permission.routes
} }
export default getters export default getters
import { getUser, logout } from '@/api/account' import { getUser, logout } from '@/api/account'
import { getUserRolesPermissions } from '@/api/system' import { getUserRolesPermissions } from '@/api/system'
import router, { resetRouter } from '@/router' import { resetRouter } from '@/router'
const user = { const user = {
state: { state: {
user: {}, user: {},
isLogin: false, isLogin: false,
hasRolesPermissions: false, hasRolesPermissions: false,
roles: [], roles: null,
permissions: [] permissions: null
}, },
mutations: { mutations: {
...@@ -58,41 +58,28 @@ const user = { ...@@ -58,41 +58,28 @@ const user = {
commit('setIsLogin', isLogin) commit('setIsLogin', isLogin)
return isLogin return isLogin
}, },
// dynamically modify permissions // 检测角色权限
async asyncRouters({ commit, dispatch }, data) {
resetRouter()
const roles = this.roles
console.log(roles)
// generate accessible routes map based on roles
const accessRoutes = await dispatch('permission/routesByPermissions', roles, { root: true })
// dynamically add accessible routes
router.addRoutes(accessRoutes)
},
// 检测登录状态
async checkRolesPermissions({ commit }) { async checkRolesPermissions({ commit }) {
const hasRolesPermissions = await getUserRolesPermissions().then(res => { await getUserRolesPermissions().then(res => {
if (res.code === 0) {
const data = res.data const data = res.data
let rolePermissionCount = 0 let roles = []
let permissions = []
if (data.roles && Array.isArray(data.roles)) { if (data.roles && Array.isArray(data.roles)) {
const roles = data.roles.forEach(it => it.name) roles = data.roles.forEach(it => it.name)
commit('setRoles', roles)
rolePermissionCount++
} }
commit('setRoles', roles)
if (data.permissions && Array.isArray(data.permissions)) { if (data.permissions && Array.isArray(data.permissions)) {
rolePermissionCount++ permissions = data.permissions
commit('setPermissions', data.permissions) }
commit('setPermissions', permissions)
} else {
// window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
} }
return rolePermissionCount === 2
}).catch(() => { }).catch(() => {
commit('setRoles', []) commit('setRoles', null)
commit('setPermissions', []) commit('setPermissions', null)
return false
}) })
commit('setHasRolesPermissions', hasRolesPermissions)
// if (hasRolesPermissions) {
// this.asyncRouters()
// }
return hasRolesPermissions
} }
} }
} }
......
...@@ -2,7 +2,7 @@ import axios from 'axios' ...@@ -2,7 +2,7 @@ import axios from 'axios'
import qs from 'qs' import qs from 'qs'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import { getNonce } from '@/utils/utils' import { getNonce } from '@/utils/utils'
import router from '@/router' // import router from '@/router'
const httpRequest = axios.create({ const httpRequest = axios.create({
timeout: 60000, timeout: 60000,
withCredentials: true, withCredentials: true,
...@@ -40,11 +40,10 @@ httpRequest.interceptors.response.use( ...@@ -40,11 +40,10 @@ httpRequest.interceptors.response.use(
const { data } = response const { data } = response
if (data.code === 1 && data.msg === '请先登录') { if (data.code === 1 && data.msg === '请先登录') {
// Message.error(data.msg || data.message) // Message.error(data.msg || data.message)
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}` // window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
return Promise.reject(data) return Promise.reject(data)
} }
if (data.code === 403) { if (data.code === 403) {
// router.push('/error-page/401')
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}` window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
} }
return data return data
...@@ -56,10 +55,9 @@ httpRequest.interceptors.response.use( ...@@ -56,10 +55,9 @@ httpRequest.interceptors.response.use(
if (status === 403) { if (status === 403) {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}` window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
} else if (status === 400 && code === 401) { } else if (status === 400 && code === 401) {
router.push('/role') // router.push('/role')
} else { } else {
console.log(message) Message.error(message || error.response.data)
// Message.error(message || error.response.data)
} }
return Promise.reject(error.response) return Promise.reject(error.response)
} else if (typeof error === 'string') { } else if (typeof error === 'string') {
......
...@@ -11,7 +11,7 @@ export default class BeforeEnter { ...@@ -11,7 +11,7 @@ export default class BeforeEnter {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}` window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
return return
} else { } else {
const hasPermissions = store.state.user.permissions && store.state.user.permissions.length > 0 const hasPermissions = store.state.user.permissions
if (hasPermissions) { if (hasPermissions) {
next() next()
} else { } else {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论