提交 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>
<div>
<el-menu-item v-if="hasChild(navItem)" :index="navItem.path">
<i :class="navItem.icon"></i>
<span slot="title">{{navItem.title}}</span>
<div v-if="!navItem.hidden">
<el-menu-item v-if="!hasChild(navItem)" :index="fullPath">
<i :class="navItem.meta.icon"></i>
<span slot="title">{{navItem.meta.title}}</span>
</el-menu-item>
<el-submenu v-else ref="subMenu" :index="navItem.path">
<el-submenu v-else ref="subMenu" :index="fullPath">
<template slot="title">
<i :class="navItem.icon"></i>
<span>{{navItem.title}}</span>
<i :class="navItem.meta.icon"></i>
<span>{{navItem.meta.title}}</span>
</template>
<menu-item
v-for="child in navItem.children"
:key="child.path"
:navItem="child"
:parent-path="fullPath"
class="nest-menu"
/>
</el-submenu>
</div>
</template>
<script>
import path from 'path'
/**
* @param {string} path
* @returns {Boolean}
*/
export function isExternal(path) {
return /^(https?:|mailto:|tel:)/.test(path)
}
export default {
name: 'MenuItem',
props: {
navItem: {
type: Object,
required: true
},
parentPath: {
type: String,
default: ''
}
},
data() {
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: {
hasChild (item) {
return !item.children || (item.children && item.children.length === 0)
return item.children && item.children.length > 0
}
}
}
......
......@@ -18,7 +18,7 @@
:collapse="isCollapse"
@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-scrollbar>
</div>
......@@ -84,7 +84,7 @@ export default {
}
},
computed: {
...mapGetters(['sidebar']),
...mapGetters(['sidebar', 'permission_routes']),
isCollapse() {
return !this.sidebar.opened
}
......@@ -93,6 +93,7 @@ export default {
watch: {
$route: {
handler: function(nv) {
console.log(nv)
if (nv && nv.path) this.defaultActive = nv.path
else this.defaultActive = ''
},
......
......@@ -52,7 +52,8 @@ export default {
},
async 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 @@
<script>
import TableList from '@/components/TableList'
import { permissionList } from './permission'
import { getRoleList } from '@/api/settings.js'
function recursionData(arr) {
const leafArr = []
function recursion(target) {
......@@ -235,7 +236,15 @@ export default {
}
})
},
fetchRoleList() {},
fetchRoleList() {
const params = {
page: 1,
limit: 20
}
getRoleList(params).then((res) => {
console.log(res)
})
},
fetchPermissionList() {
const result = permissionList
const leafNodeList = recursionData(result)
......
......@@ -4,32 +4,33 @@ export default [
path: '/',
name: 'Layout',
component: Layout,
redirect: '/content-manage'
redirect: '/content-manage',
hidden: true
},
{
path: '/content-manage',
component: Layout,
redirect: '/content-manage/ads',
name: 'System',
meta: { title: '内容管理', icon: 'el-icon-setting' },
name: 'ContentManage',
meta: { title: '内容管理', icon: 'el-icon-document' },
children: [
{
path: 'ads',
name: 'Ads',
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',
name: 'Article',
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',
name: 'ImageText',
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 [
path: '/settings',
component: Layout,
redirect: '/settings/staff',
name: 'System',
name: 'Settings',
meta: { title: '设置', icon: 'el-icon-setting' },
children: [
{
path: 'staff',
name: 'Staff',
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',
name: 'Project',
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',
name: 'Type',
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',
name: 'Role',
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 [
redirect: '/error-page/404',
name: 'ErrorPage',
meta: { title: '访问出错', icon: 'el-icon-setting' },
hidden: true,
children: [
{
path: '404',
......
const getters = {
user: state => state.user.user,
roles: state => state.user.roles,
sidebar: state => state.app.sidebar
sidebar: state => state.app.sidebar,
permission_routes: state => state.permission.routes
}
export default getters
import { getUser, logout } from '@/api/account'
import { getUserRolesPermissions } from '@/api/system'
import router, { resetRouter } from '@/router'
import { resetRouter } from '@/router'
const user = {
state: {
user: {},
isLogin: false,
hasRolesPermissions: false,
roles: [],
permissions: []
roles: null,
permissions: null
},
mutations: {
......@@ -58,41 +58,28 @@ const user = {
commit('setIsLogin', 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 }) {
const hasRolesPermissions = await getUserRolesPermissions().then(res => {
const data = res.data
let rolePermissionCount = 0
if (data.roles && Array.isArray(data.roles)) {
const roles = data.roles.forEach(it => it.name)
await getUserRolesPermissions().then(res => {
if (res.code === 0) {
const data = res.data
let roles = []
let permissions = []
if (data.roles && Array.isArray(data.roles)) {
roles = data.roles.forEach(it => it.name)
}
commit('setRoles', roles)
rolePermissionCount++
}
if (data.permissions && Array.isArray(data.permissions)) {
rolePermissionCount++
commit('setPermissions', data.permissions)
if (data.permissions && Array.isArray(data.permissions)) {
permissions = data.permissions
}
commit('setPermissions', permissions)
} else {
// window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
}
return rolePermissionCount === 2
}).catch(() => {
commit('setRoles', [])
commit('setPermissions', [])
return false
commit('setRoles', null)
commit('setPermissions', null)
})
commit('setHasRolesPermissions', hasRolesPermissions)
// if (hasRolesPermissions) {
// this.asyncRouters()
// }
return hasRolesPermissions
}
}
}
......
......@@ -2,7 +2,7 @@ import axios from 'axios'
import qs from 'qs'
import { Message } from 'element-ui'
import { getNonce } from '@/utils/utils'
import router from '@/router'
// import router from '@/router'
const httpRequest = axios.create({
timeout: 60000,
withCredentials: true,
......@@ -40,11 +40,10 @@ httpRequest.interceptors.response.use(
const { data } = response
if (data.code === 1 && data.msg === '请先登录') {
// 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)
}
if (data.code === 403) {
// router.push('/error-page/401')
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
}
return data
......@@ -56,10 +55,9 @@ httpRequest.interceptors.response.use(
if (status === 403) {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
} else if (status === 400 && code === 401) {
router.push('/role')
// router.push('/role')
} else {
console.log(message)
// Message.error(message || error.response.data)
Message.error(message || error.response.data)
}
return Promise.reject(error.response)
} else if (typeof error === 'string') {
......
......@@ -11,7 +11,7 @@ export default class BeforeEnter {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
return
} else {
const hasPermissions = store.state.user.permissions && store.state.user.permissions.length > 0
const hasPermissions = store.state.user.permissions
if (hasPermissions) {
next()
} else {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论