Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
template_vue
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
胡宝山
template_vue
Commits
c0e36fad
Commit
c0e36fad
authored
Jul 19, 2023
by
杨硕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化中间页面权限问题
parent
10a3db53
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
31 deletions
+56
-31
permission.js
src/permission.js
+11
-7
user.js
src/store/modules/user.js
+10
-0
home.vue
src/views/home.vue
+6
-0
data.vue
src/views/system/dict/data.vue
+12
-12
index.vue
src/views/system/dict/index.vue
+12
-12
index.vue
src/views/system/user/index.vue
+5
-0
No files found.
src/permission.js
View file @
c0e36fad
...
...
@@ -4,6 +4,7 @@ import { Message } from 'element-ui'
import
NProgress
from
'nprogress'
// progress bar
import
'nprogress/nprogress.css'
// progress bar style
import
{
getToken
}
from
'@/utils/auth'
import
Cookies
from
'js-cookie'
import
de
from
'element-ui/src/locale/lang/de'
// get token from cookie
// import getPageTitle from '@/utils/get-page-title'
...
...
@@ -21,6 +22,8 @@ router.beforeEach((to, from, next) => {
}
else
if
(
to
.
path
===
'/home'
)
{
next
()
NProgress
.
done
()
}
else
if
(
to
.
path
===
'/'
)
{
next
({
path
:
'/login'
})
}
else
{
if
(
store
.
getters
.
roles
.
length
===
0
)
{
// 判断当前用户是否已拉取完user_info信息
...
...
@@ -31,7 +34,7 @@ router.beforeEach((to, from, next) => {
if
(
res
.
data
.
permissions
&&
res
.
data
.
permissions
.
length
>
0
)
{
// 拉取user_info
const
roles
=
res
.
data
.
roles
const
menuName
=
store
.
getters
.
menuName
const
menuName
=
Cookies
.
get
(
'menuname'
)
store
.
dispatch
(
'GenerateRoutes'
,
{
roles
,
menuName
}).
then
((
routers
)
=>
{
// 判断用户是否有路由
if
(
routers
.
accessedRoutes
&&
routers
.
accessedRoutes
.
length
>
0
&&
routers
.
getRouters
&&
routers
.
getRouters
.
length
>
0
)
{
...
...
@@ -40,13 +43,14 @@ router.beforeEach((to, from, next) => {
// 根据roles权限生成可访问的路由表
router
.
addRoutes
(
routers
.
accessedRoutes
)
// 动态添加可访问路由表
next
({
...
to
,
replace
:
true
})
// hack方法 确保addRoutes已完成
}
else
{
alert
(
'用户无权限'
)
store
.
dispatch
(
'FedLogOut'
).
then
(()
=>
{
next
({
path
:
'/login'
})
// window.location.href = `${process.env.VUE_APP_LOGIN}?redirect=${to.fullPath}&reLocation=${process.env.VUE_APP_NQ}`
})
}
// else {
// alert('用户无权限')
// store.dispatch('FedLogOut').then(() => {
// next({ path: '/login' })
// // window.location.href = `${process.env.VUE_APP_LOGIN}?redirect=${to.fullPath}&reLocation=${process.env.VUE_APP_NQ}`
// })
// }
})
}
else
{
alert
(
'用户无权限'
)
...
...
src/store/modules/user.js
View file @
c0e36fad
...
...
@@ -2,6 +2,8 @@ import { login, logout, getInfo } from '@/api/login'
import
{
getToken
,
setToken
,
removeToken
}
from
'@/utils/auth'
import
Layout
from
'@/layout'
import
{
loadView
}
from
'@/store/modules/permission'
import
store
from
'@/store'
import
Cookies
from
'js-cookie'
const
user
=
{
state
:
{
...
...
@@ -72,6 +74,7 @@ const user = {
commit
(
'SET_NAME'
,
user
.
username
)
commit
(
'SET_SPECIALTAG'
,
user
.
specialTag
)
commit
(
'SET_AVATAR'
,
avatar
)
res
.
menuName
=
store
.
getters
.
menuName
resolve
(
res
)
}).
catch
(
error
=>
{
reject
(
error
)
...
...
@@ -84,9 +87,16 @@ const user = {
// TODO: clear this log
console
.
log
(
`menuName-getInfo`
,
menuName
)
commit
(
'SET_MENUNAME'
,
menuName
)
// 存入菜单名
Cookies
.
set
(
'menuname'
,
menuName
)
resolve
(
menuName
)
})
},
removeRole
({
commit
,
state
})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
commit
(
'SET_ROLES'
,
''
)
resolve
()
})
},
// 退出系统
LogOut
({
commit
,
state
})
{
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
src/views/home.vue
View file @
c0e36fad
...
...
@@ -49,7 +49,13 @@ export default {
}
},
created
()
{
this
.
removeRole
()
},
methods
:
{
removeRole
()
{
this
.
$store
.
dispatch
(
'removeRole'
)
},
gotoIndex
(
menuName
)
{
getInfo
().
then
(
res
=>
{
if
(
res
.
data
.
permissions
)
{
...
...
src/views/system/dict/data.vue
View file @
c0e36fad
...
...
@@ -58,7 +58,7 @@
<!-- @click="handleUpdate"-->
<!-- >修改-->
<!--
</el-button>
-->
<coolbutton
:type=
"typeSuccess"
:name=
"updataName"
:icon=
"updateIcon"
:size=
"size"
:haspermi=
"updateHaspermi"
@
btn-click=
"handleUpdate"
/
>
<!--
<coolbutton
:type=
"typeSuccess"
:name=
"updataName"
:icon=
"updateIcon"
:size=
"size"
:haspermi=
"updateHaspermi"
@
btn-click=
"handleUpdate"
/>
--
>
</el-col>
<el-col
:span=
"1.5"
>
<!--
<el-button-->
...
...
@@ -70,12 +70,12 @@
<!-- @click="handleDelete"-->
<!-- >删除-->
<!--
</el-button>
-->
<coolbutton
:type=
"typeDanger"
:name=
"nameParent"
:icon=
"delicon"
:size=
"size"
:haspermi=
"delHaspermi"
@
btn-click=
"handleDelete"
/
>
<!--
<coolbutton
:type=
"typeDanger"
:name=
"nameParent"
:icon=
"delicon"
:size=
"size"
:haspermi=
"delHaspermi"
@
btn-click=
"handleDelete"
/>
--
>
</el-col>
<el-col
:span=
"1.5"
>
<el-button
v-has-permi=
"['sys:dict:export']"
type=
"
warning
"
type=
"
success
"
icon=
"el-icon-download"
size=
"mini"
@
click=
"handleExport"
...
...
@@ -184,15 +184,15 @@
<el-form-item
label=
"参数排序"
prop=
"dictSort"
>
<el-input-number
v-model=
"form.dictSort"
style=
"width: 100%"
controls-position=
"right"
:min=
"0"
/>
</el-form-item>
<
el-form-item
label=
"参数状态"
prop=
"status"
>
<el-radio-group
v-model=
"form.status"
>
<el-radio
v-for=
"dict in statusOptions.filter(item => { return item.dictValue })"
:key=
"dict.dictValue"
:label=
"dict.dictValue"
>
{{ dict.dictLabel }}
</el-radio
>
</el-radio-group
>
<
/el-form-item
>
<
!-- <el-form-item label="参数状态" prop="status">--
>
<!-- <el-radio-group v-model="form.status">--
>
<!-- <el-radio-->
<!-- v-for="dict in statusOptions.filter(item => { return item.dictValue })"-->
<!-- :key="dict.dictValue"-->
<!-- :label="dict.dictValue"-->
<!-- >{{ dict.dictLabel }}</el-radio>--
>
<!-- </el-radio-group>--
>
<
!-- </el-form-item>--
>
<el-form-item
label=
"备注"
prop=
"remarks"
>
<el-input
v-model
.
trim=
"form.remarks"
type=
"textarea"
show-word-limit
maxlength=
"200"
placeholder=
"请输入内容"
/>
</el-form-item>
...
...
src/views/system/dict/index.vue
View file @
c0e36fad
...
...
@@ -76,7 +76,7 @@
<!-- @click="handleUpdate"-->
<!-- >修改-->
<!--
</el-button>
-->
<
coolbutton
:type=
"typeSuccess"
:name=
"updataName"
:icon=
"updateIcon"
:size=
"size"
:haspermi=
"updateHaspermi"
@
btn-click=
"handleUpdate"
/
>
<
!--
<coolbutton
:type=
"typeSuccess"
:name=
"updataName"
:icon=
"updateIcon"
:size=
"size"
:haspermi=
"updateHaspermi"
@
btn-click=
"handleUpdate"
/>
--
>
</el-col>
<el-col
:span=
"1.5"
>
<!--
<el-button-->
...
...
@@ -88,7 +88,7 @@
<!-- @click="handleDelete"-->
<!-- >删除-->
<!--
</el-button>
-->
<
coolbutton
:type=
"typeDanger"
:name=
"nameParent"
:icon=
"delicon"
:size=
"size"
:haspermi=
"delHaspermi"
@
btn-click=
"handleDelete"
/
>
<
!--
<coolbutton
:type=
"typeDanger"
:name=
"nameParent"
:icon=
"delicon"
:size=
"size"
:haspermi=
"delHaspermi"
@
btn-click=
"handleDelete"
/>
--
>
</el-col>
<el-col
:span=
"1.5"
>
<!--
<el-button-->
...
...
@@ -185,16 +185,16 @@
<el-form-item
label=
"字典类型"
prop=
"dictType"
>
<el-input
v-model
.
trim=
"form.dictType"
:maxlength=
"30"
placeholder=
"请输入字典类型"
/>
</el-form-item>
<
el-form-item
label=
"状态"
prop=
"flag"
>
<el-radio-group
v-model=
"form.flag"
>
<el-radio
v-for=
"dict in statusOptions"
:key=
"dict.dictValue"
:label=
"dict.dictValue"
>
{{ dict.dictLabel }}
</el-radio
>
</el-radio-group
>
<
/el-form-item
>
<
!-- <el-form-item label="状态" prop="flag">--
>
<!-- <el-radio-group v-model="form.flag">--
>
<!-- <el-radio-->
<!-- v-for="dict in statusOptions"-->
<!-- :key="dict.dictValue"-->
<!-- :label="dict.dictValue"-->
<!-- >{{ dict.dictLabel }}-->
<!-- </el-radio>--
>
<!-- </el-radio-group>--
>
<
!-- </el-form-item>--
>
<el-form-item
label=
"父字典名称"
>
<el-select
v-model=
"form.parentId"
style=
"width: 100%"
clearable
placeholder=
"请选择父字典类型"
@
change=
"getOptions"
>
<el-option
...
...
src/views/system/user/index.vue
View file @
c0e36fad
...
...
@@ -986,17 +986,22 @@ export default {
downloadElement
.
click
()
// 点击下载
document
.
body
.
removeChild
(
downloadElement
)
// 下载完成移除元素
window
.
URL
.
revokeObjectURL
(
href
)
// 释放掉blob对象
this
.
importLoading
=
false
})
}
this
.
importLoading
=
false
}
else
if
(
res
.
code
===
41020
)
{
this
.
$message
.
info
(
'上传超时,请重新上传'
)
this
.
importLoading
=
false
}
else
{
this
.
$message
.
error
(
res
.
message
)
this
.
importLoading
=
false
}
}).
catch
(
err
=>
{
this
.
$message
.
success
(
err
.
message
)
this
.
importLoading
=
false
})
this
.
importLoading
=
false
}
},
employeeUpload
(
file
,
fileList
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment