Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
npm
/
glsx-components
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2cedecaf
authored
Dec 07, 2021
by
limin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
权限按钮重构
1 parent
e693f436
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
80 deletions
package.json
src/App.vue
src/main.js
src/packages/Button/index.js
src/packages/Button/src/index.js
package.json
View file @
2cedeca
{
"name"
:
"glsx-components"
,
"description"
:
"glsx vue components"
,
"version"
:
"1.2.
3
"
,
"version"
:
"1.2.
4
"
,
"author"
:
"limin <17653212@qq.com>"
,
"license"
:
"MIT"
,
"main"
:
"dist/glsx-components.common.js"
,
...
...
src/App.vue
View file @
2cedeca
<
template
>
<div
id=
"app"
>
<
img
alt=
"Vue logo"
src=
"./assets/logo.png"
/
>
<HelloWorld
msg=
"Welcome to Your Vue.js App"
/>
<GLExternal
url=
"//localhost:8080/html/employee/index.html"
:subscribe=
"subscribe"
></GLExternal>
<GLButton
@
click=
"click"
id=
"1-1-1-1"
mode=
"
button"
>
232321321
</GLButton>
<
!--
<img
alt=
"Vue logo"
src=
"./assets/logo.png"
/>
--
>
<
!--
<
HelloWorld
msg=
"Welcome to Your Vue.js App"
/>
<GLExternal
url=
"//localhost:8080/html/employee/index.html"
:subscribe=
"subscribe"
></GLExternal>
-->
<GLButton
@
click=
"click"
fn=
"1-1-1-1"
mode=
"el-
button"
>
232321321
</GLButton>
<el-button
type=
"primary"
>
aaa
</el-button>
<el-button
type=
"primary"
size=
"small"
>
aaa
</el-button>
<el-button
type=
"primary"
size=
"mini"
>
aaa
</el-button>
<GLDialog
:visible
.
sync=
"visible"
title=
"aaaaaaaaa"
>
<
!--
<
GLDialog
:visible
.
sync=
"visible"
title=
"aaaaaaaaa"
>
<div
slot=
"footer"
>
<el-button
size=
"small"
@
click=
"visible = false"
>
取消
</el-button>
<el-button
type=
"primary"
size=
"small"
>
aaa
</el-button>
...
...
@@ -23,7 +23,7 @@
<el-button
v-if=
"scope.scope.liveStatus == '102'"
type=
"text"
@
click=
"handleEdit(2, scope.scope)"
>
编辑
</el-button>
<el-button
v-if=
"scope.scope.liveStatus != '101'"
type=
"text"
@
click=
"handleDelete(scope.scope)"
>
删除
</el-button>
</span>
</GLTable>
</GLTable>
-->
<el-table
:data=
"tableData"
style=
"width: 100%"
>
<el-table-column
prop=
"date"
label=
"序号"
align=
"center"
></el-table-column>
<el-table-column
label=
"订单信息"
align=
"center"
>
...
...
@@ -116,6 +116,7 @@ export default {
})
},
click
()
{
console
.
log
(
111111111111
)
this
.
visible
=
true
}
}
...
...
src/main.js
View file @
2cedeca
...
...
@@ -8,7 +8,14 @@ Vue.use(GLDialog)
Vue
.
use
(
GLTable
)
Vue
.
use
(
Table
)
Vue
.
use
(
TableColumn
)
Vue
.
use
(
GLButton
,
{
permissions
:
[
'1-1-1-1'
,
'2-1-1-1'
,
'3-1-1-1'
],
a
:
'1111'
})
const
permissions
=
{
routes
:
[
{
path
:
'/'
,
meta
:
{
permissions
:
[
'1-1-1-1'
,
'2-1-1-1'
,
'3-1-1-1'
]
}
},
{
path
:
'/a'
,
meta
:
{}
}
],
routerBase
:
''
}
Vue
.
use
(
GLButton
,
permissions
)
Vue
.
config
.
productionTip
=
false
new
Vue
({
...
...
src/packages/Button/index.js
View file @
2cedeca
import
GLButton
from
"./src/index.js"
;
import
GLButton
from
'./src/index.js'
// 为组件提供 install 安装方法,供按需引入
GLButton
.
install
=
function
(
Vue
,
{
permissions
}
=
{}
)
{
Vue
.
prototype
.
permissions
=
permissions
;
Vue
.
component
(
GLButton
.
name
,
GLButton
)
;
}
;
GLButton
.
install
=
function
(
Vue
,
permissions
)
{
Vue
.
prototype
.
$GLBUTTION_PERMISSIONS
=
permissions
Vue
.
component
(
GLButton
.
name
,
GLButton
)
}
// 默认导出组件
export
default
GLButton
;
export
default
GLButton
src/packages/Button/src/index.js
View file @
2cedeca
/**
* type : primary,success,default,error,danger
* size: 按钮大小,参照elementui
* id: 权限判断id
* mode:按钮类型 是a标签还是button,可选值为:button、link
*/
const
TYPE
=
Object
.
freeze
({
none
:
''
})
// 权限校验
function
judgePermissions
(
options
)
{
if
(
!
options
)
{
return
false
}
let
_list
=
options
.
parent
.
permissions
||
[]
function
permission
(
ctx
)
{
if
(
!
ctx
)
return
TYPE
.
none
const
{
props
:
{
id
,
mode
}
}
=
options
let
idx
=
_list
.
some
(
k
=>
k
==
id
)
// 如果没有权限,则返回空标签
if
(
!
idx
)
{
return
''
}
if
(
mode
==
'link'
)
{
return
'a'
}
return
'button'
}
// 获取class
function
getClass
(
context
)
{
let
o
=
context
.
props
let
_class
=
[]
_class
.
push
(
'el-'
+
o
.
mode
)
_class
.
push
(
'el-'
+
o
.
mode
+
'--'
+
o
.
type
)
if
(
o
.
size
)
{
_class
.
push
(
'el-'
+
o
.
mode
+
'--'
+
o
.
size
)
}
if
(
o
.
class
)
{
_class
.
push
(
o
.
class
)
props
:
{
fn
,
mode
},
parent
:
{
$GLBUTTION_PERMISSIONS
:
{
routes
=
[],
routerBase
}
}
}
=
ctx
const
router
=
routes
.
find
(
route
=>
location
.
pathname
===
`
${
routerBase
}${
route
.
path
.
split
(
':/'
)[
0
]}
`
)
if
(
router
&&
router
.
meta
&&
router
.
meta
.
permissions
&&
router
.
meta
.
permissions
.
includes
(
fn
))
{
return
mode
}
return
_class
return
TYPE
.
none
}
export
default
{
functional
:
true
,
name
:
'GLButton'
,
props
:
{
a
:
String
,
type
:
{
type
:
String
,
default
:
'default'
},
size
:
{
type
:
String
,
default
:
'medium'
},
id
:
{
type
:
[
String
,
Number
]
fn
:
{
type
:
String
},
mode
:
{
type
:
String
,
default
:
'button'
},
class
:
{
type
:
String
,
default
:
''
default
:
'el-button'
}
},
render
:
function
(
createElement
,
context
)
{
let
_props
=
context
.
props
let
options
=
{
props
:
_props
,
attrs
:
context
.
props
,
class
:
getClass
(
context
),
on
:
{
click
:
event
=>
{
context
.
listeners
.
click
&&
context
.
listeners
.
click
(
'click'
,
event
)
}
}
}
return
createElement
(
judgePermissions
(
context
),
options
,
context
.
children
)
return
createElement
(
permission
(
context
),
context
.
data
,
context
.
children
)
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment