提交 6ea9bc06 authored 作者: pengxiaohui's avatar pengxiaohui

修复bug

上级 3049d783
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
id="viewport" id="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no, viewport-fit=cover" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no, viewport-fit=cover"
/> />
<script src="/static/tinymce/tinymce.min.js"></script> <script src="../static/tinymce/tinymce.min.js"></script>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<template v-slot:top-status="{ row }"> <template v-slot:top-status="{ row }">
<div class="table-col-top"> <div class="table-col-top">
<el-switch :active-value="1" :inactive-value="0" v-model="row.is_top" @change="handleTop(row)" :disabled="!hasCreate"></el-switch> <el-switch :active-value="1" :inactive-value="0" v-model="row.is_top" @change="handleTop(row)" :disabled="!hasCreate"></el-switch>
<el-select v-model="row.weight" placeholder="权重" size="mini" clearable :disabled="!hasCreate" @change="handleWeight(row)"> <el-select v-model="row.weight" placeholder="权重" size="mini" :disabled="!hasCreate" @change="handleWeight(row)">
<el-option v-for="item in 10" :label="item" :value="item" :key="item"></el-option> <el-option v-for="item in 10" :label="item" :value="item" :key="item"></el-option>
</el-select> </el-select>
</div> </div>
...@@ -148,7 +148,7 @@ export default { ...@@ -148,7 +148,7 @@ export default {
labelKey: 'name', labelKey: 'name',
valueKey: 'id' valueKey: 'id'
}, },
{ type: 'input', placeholder: 'ID', prop: 'id_title' }, { type: 'input', placeholder: '标题/ID', prop: 'id_title' },
{ {
type: 'select', type: 'select',
placeholder: '类型', placeholder: '类型',
...@@ -161,7 +161,7 @@ export default { ...@@ -161,7 +161,7 @@ export default {
columns: [ columns: [
{ type: 'selection', visible: this.hasDelete, fixed: 'left' }, { type: 'selection', visible: this.hasDelete, fixed: 'left' },
{ prop: 'image_url', label: '图片', slots: 'image', minWidth: '80px', fixed: 'left' }, { prop: 'image_url', label: '图片', slots: 'image', minWidth: '80px', fixed: 'left' },
{ prop: 'id', label: '广告ID', slots: 'table-id', minWidth: '90px', fixed: 'left' }, { prop: 'id', label: '广告ID', slots: 'table-id', minWidth: '95px', fixed: 'left' },
{ prop: 'title', label: '标题', minWidth: '100px' }, { prop: 'title', label: '标题', minWidth: '100px' },
{ {
prop: 'start_time', prop: 'start_time',
...@@ -198,7 +198,7 @@ export default { ...@@ -198,7 +198,7 @@ export default {
return dateFormat(row.created_at) || '-' return dateFormat(row.created_at) || '-'
} }
}, },
{ prop: 'audit_status', label: '审核状态', slots: 'review-status', fixed: 'right' }, { prop: 'audit_status', label: '审核状态', slots: 'review-status' },
{ prop: 'is_publish', label: '发布状态', slots: 'publish-status', fixed: 'right' }, { prop: 'is_publish', label: '发布状态', slots: 'publish-status', fixed: 'right' },
{ prop: 'is_top', label: '置顶状态/权重', slots: 'top-status', minWidth: '140px', fixed: 'right' } { prop: 'is_top', label: '置顶状态/权重', slots: 'top-status', minWidth: '140px', fixed: 'right' }
] ]
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<template v-slot:top-status="{ row }"> <template v-slot:top-status="{ row }">
<div class="table-col-top"> <div class="table-col-top">
<el-switch :active-value="1" :inactive-value="0" v-model="row.is_top" @change="handleTop(row)" :disabled="!hasCreate">></el-switch> <el-switch :active-value="1" :inactive-value="0" v-model="row.is_top" @change="handleTop(row)" :disabled="!hasCreate">></el-switch>
<el-select v-model="row.weight" placeholder="权重" size="mini" clearable :disabled="!hasCreate" @change="handleWeight(row)"> <el-select v-model="row.weight" placeholder="权重" size="mini" :disabled="!hasCreate" @change="handleWeight(row)">
<el-option v-for="item in 10" :label="item" :value="item" :key="item"></el-option> <el-option v-for="item in 10" :label="item" :value="item" :key="item"></el-option>
</el-select> </el-select>
</div> </div>
...@@ -147,7 +147,7 @@ export default { ...@@ -147,7 +147,7 @@ export default {
labelKey: 'name', labelKey: 'name',
valueKey: 'id' valueKey: 'id'
}, },
{ type: 'input', placeholder: 'ID', prop: 'id_title' }, { type: 'input', placeholder: '标题/ID', prop: 'id_title' },
{ {
type: 'select', type: 'select',
placeholder: '类型', placeholder: '类型',
...@@ -160,7 +160,7 @@ export default { ...@@ -160,7 +160,7 @@ export default {
columns: [ columns: [
{ type: 'selection', visible: this.hasDelete, fixed: 'left' }, { type: 'selection', visible: this.hasDelete, fixed: 'left' },
{ prop: 'image_url', label: '图片', slots: 'image', minWidth: '80px', fixed: 'left' }, { prop: 'image_url', label: '图片', slots: 'image', minWidth: '80px', fixed: 'left' },
{ prop: 'id', label: '文章ID', slots: 'table-id', minWidth: '90px', fixed: 'left' }, { prop: 'id', label: '文章ID', slots: 'table-id', minWidth: '95px', fixed: 'left' },
{ prop: 'title', label: '标题', minWidth: '100px' }, { prop: 'title', label: '标题', minWidth: '100px' },
{ {
prop: 'start_time', prop: 'start_time',
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</el-col> </el-col>
</el-form-item> </el-form-item>
<el-form-item label="标题:" prop="title" style="margin-right:15px;"> <el-form-item label="标题:" prop="title" style="margin-right:15px;">
<el-input v-model="form.title" placeholder="请输入题" size="small" :disabled="isDetails"/> <el-input v-model="form.title" placeholder="请输入题" size="small" :disabled="isDetails"/>
</el-form-item> </el-form-item>
<el-form-item label="跳转链接:" style="margin-right:15px;"> <el-form-item label="跳转链接:" style="margin-right:15px;">
<el-input v-model="form.uri" placeholder="请输入跳转链接" size="small" :disabled="isDetails"/> <el-input v-model="form.uri" placeholder="请输入跳转链接" size="small" :disabled="isDetails"/>
......
...@@ -129,7 +129,7 @@ export default { ...@@ -129,7 +129,7 @@ export default {
labelKey: 'name', labelKey: 'name',
valueKey: 'id' valueKey: 'id'
}, },
{ type: 'input', placeholder: 'ID', prop: 'id_title' }, { type: 'input', placeholder: '标题/ID', prop: 'id_title' },
{ {
type: 'select', type: 'select',
placeholder: '类型', placeholder: '类型',
...@@ -142,7 +142,7 @@ export default { ...@@ -142,7 +142,7 @@ export default {
columns: [ columns: [
{ type: 'selection', visible: this.hasDelete, fixed: 'left' }, { type: 'selection', visible: this.hasDelete, fixed: 'left' },
{ prop: 'image_url', label: '图片', slots: 'image', minWidth: '80px', fixed: 'left' }, { prop: 'image_url', label: '图片', slots: 'image', minWidth: '80px', fixed: 'left' },
{ prop: 'id', label: '图文ID', slots: 'table-id', minWidth: '90px', fixed: 'left' }, { prop: 'id', label: '图文ID', slots: 'table-id', minWidth: '95px', fixed: 'left' },
{ prop: 'title', label: '标题', minWidth: '100px' }, { prop: 'title', label: '标题', minWidth: '100px' },
{ {
prop: 'start_time', prop: 'start_time',
......
...@@ -199,11 +199,11 @@ export default { ...@@ -199,11 +199,11 @@ export default {
filters: [ filters: [
{ {
type: 'select', type: 'select',
placeholder: '项目', placeholder: '项目类型',
prop: 'type_id', prop: 'type_id',
options: this.projectList, options: this.projectTypeList,
labelKey: 'project_name', labelKey: 'name',
valueKey: 'project_id' valueKey: 'id'
}, },
{ type: 'input', placeholder: '项目ID/项目名称', prop: 'name' }, { type: 'input', placeholder: '项目ID/项目名称', prop: 'name' },
{ {
......
...@@ -218,8 +218,8 @@ export default { ...@@ -218,8 +218,8 @@ export default {
placeholder: '项目', placeholder: '项目',
prop: 'project_id', prop: 'project_id',
options: this.projectList, options: this.projectList,
labelKey: 'project_name', labelKey: 'name',
valueKey: 'project_id' valueKey: 'id'
}, },
{ type: 'input', placeholder: '手机号/邮箱', prop: 'id' }, { type: 'input', placeholder: '手机号/邮箱', prop: 'id' },
{ {
......
...@@ -3,6 +3,11 @@ import Router from 'vue-router' ...@@ -3,6 +3,11 @@ import Router from 'vue-router'
import routes from './routes' import routes from './routes'
Vue.use(Router) Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
export const asyncRoutes = [...routes] export const asyncRoutes = [...routes]
const createRouter = () => new Router({ const createRouter = () => new Router({
mode: 'history', // require service support mode: 'history', // require service support
......
...@@ -23,9 +23,6 @@ const user = { ...@@ -23,9 +23,6 @@ const user = {
setPermissions(state, permissions) { setPermissions(state, permissions) {
state.permissions = permissions state.permissions = permissions
}, },
setHasRolesPermissions(state, hasRolesPermissions) {
state.hasRolesPermissions = hasRolesPermissions
},
setProjects(state, projects) { setProjects(state, projects) {
state.projects = projects state.projects = projects
} }
...@@ -37,6 +34,9 @@ const user = { ...@@ -37,6 +34,9 @@ const user = {
return logout().then(response => { return logout().then(response => {
commit('setUser', {}) commit('setUser', {})
commit('setIsLogin', false) commit('setIsLogin', false)
commit('setRoles', null)
commit('setPermissions', null)
commit('projects', [])
resetRouter() resetRouter()
return response return response
}) })
...@@ -63,13 +63,14 @@ const user = { ...@@ -63,13 +63,14 @@ const user = {
}, },
// 检测角色权限 // 检测角色权限
async checkRolesPermissions({ commit }) { async checkRolesPermissions({ commit }) {
await getUserRolesPermissions().then(res => { const obj = await getUserRolesPermissions().then(res => {
if (res.code === 0) { if (res.code === 0) {
const data = res.data const data = res.data
let roles = [] let roles = []
let permissions = [] let permissions = []
let projects = []
if (data.roles && Array.isArray(data.roles)) { if (data.roles && Array.isArray(data.roles)) {
roles = data.roles.forEach(it => it.name) roles = data.roles.map(it => it.name)
} }
commit('setRoles', roles) commit('setRoles', roles)
if (data.permissions && Array.isArray(data.permissions)) { if (data.permissions && Array.isArray(data.permissions)) {
...@@ -77,18 +78,26 @@ const user = { ...@@ -77,18 +78,26 @@ const user = {
} }
commit('setPermissions', permissions) commit('setPermissions', permissions)
if (data.projects && Array.isArray(data.projects)) { if (data.projects && Array.isArray(data.projects)) {
commit('setProjects', data.projects) projects = data.projects
commit('setProjects', projects)
} else { } else {
commit('setProjects', []) commit('setProjects', [])
} }
return {
roles,
permissions,
projects
}
} else { } else {
// window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}` return {}
} }
}).catch(() => { }).catch(() => {
commit('setRoles', null) commit('setRoles', null)
commit('setPermissions', null) commit('setPermissions', null)
commit('setProjects', []) commit('setProjects', [])
return {}
}) })
return obj
} }
} }
} }
......
...@@ -9,30 +9,46 @@ export default class BeforeEnter { ...@@ -9,30 +9,46 @@ export default class BeforeEnter {
const isLogin = store.state.user.isLogin || (await store.dispatch('checkLogin')) const isLogin = store.state.user.isLogin || (await store.dispatch('checkLogin'))
if (!isLogin) { if (!isLogin) {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}` window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
return next()
} else { } else {
const hasPermissions = store.state.user.permissions const hasPermissions = store.state.user.permissions && store.state.user.permissions.length > 0
if (hasPermissions) { if (hasPermissions) {
next() const permissions = store.state.user.permissions
if (to.path.includes('error-page')) {
next()
} else {
if (!permissions.includes(to.meta.permission)) {
router.push('/error-page/401')
}
next()
}
} else { } else {
try { const { permissions } = await store.dispatch('checkRolesPermissions')
await store.dispatch('checkRolesPermissions') if (!permissions.length) {
const permissions = store.state.user.permissions window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
// 基于权限获取可接入的路由
const accessRoutes = await store.dispatch('permission/routesByPermissions', permissions)
// 重新设置路由
resetRouter()
// dynamically add accessible routes
router.addRoutes(accessRoutes)
// hack method to ensure that addRoutes is complete
// set the replace: true, so the navigation will not leave a history record
next({ ...to, replace: true })
} catch (error) {
next() next()
} else {
try {
// 基于权限获取可接入的路由
const accessRoutes = await store.dispatch('permission/routesByPermissions', permissions)
// 重新设置路由
resetRouter()
// 动态添加路由
router.addRoutes(accessRoutes)
next({ ...to, replace: true })
} catch (error) {
next()
}
if (to.path.includes('error-page')) {
next()
} else {
if (!permissions.includes(to.meta.permission)) {
router.replace('/error-page/401')
}
next()
}
} }
} }
} }
// store.dispatch('setUserRoles')
next()
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论