Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
251a98df
authored
Jul 26, 2024
by
黄兆琦
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: DictTag组件兼容传入多个字典值展示多个标签的情况
parent
46da7e28
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
29 deletions
+40
-29
src/components/DictTag/src/DictTag.vue
+40
-29
No files found.
src/components/DictTag/src/DictTag.vue
View file @
251a98df
<
script
lang=
"tsx"
>
<
script
lang=
"tsx"
>
import
{
defineComponent
,
PropType
,
ref
}
from
'vue'
import
{
defineComponent
,
PropType
,
computed
}
from
'vue'
import
{
isHexColor
}
from
'@/utils/color'
import
{
isHexColor
}
from
'@/utils/color'
import
{
ElTag
}
from
'element-plus'
import
{
ElTag
}
from
'element-plus'
import
{
DictDataType
,
getDictOptions
}
from
'@/utils/dict'
import
{
DictDataType
,
getDictOptions
}
from
'@/utils/dict'
import
{
isArray
,
isString
,
isNumber
}
from
'@/utils/is'
export
default
defineComponent
({
export
default
defineComponent
({
name
:
'DictTag'
,
name
:
'DictTag'
,
...
@@ -12,46 +13,56 @@ export default defineComponent({
...
@@ -12,46 +13,56 @@ export default defineComponent({
required
:
true
required
:
true
},
},
value
:
{
value
:
{
type
:
[
String
,
Number
,
Boolean
]
as
PropType
<
string
|
number
|
boolean
>
,
type
:
[
String
,
Number
,
Boolean
,
Array
]
,
required
:
true
required
:
true
}
}
},
},
setup
(
props
)
{
setup
(
props
)
{
const
dictData
=
ref
<
DictDataType
>
()
const
valueArr
:
any
=
computed
(()
=>
{
const
getDictObj
=
(
dictType
:
string
,
value
:
string
)
=>
{
// 1.是Number类型的情况
const
dictOptions
=
getDictOptions
(
dictType
)
if
(
isNumber
(
props
.
value
))
{
dictOptions
.
forEach
((
dict
:
DictDataType
)
=>
{
return
[
String
(
props
.
value
)]
if
(
dict
.
value
===
value
)
{
}
if
(
dict
.
colorType
+
''
===
'primary'
||
dict
.
colorType
+
''
===
'default'
)
{
// 2.是字符串(进一步判断是否有',')
dict
.
colorType
=
''
else
if
(
isString
(
props
.
value
))
{
}
return
props
.
value
.
includes
(
','
)
?
props
.
value
.
split
(
','
)
:
[
String
(
props
.
value
)]
dictData
.
value
=
dict
}
}
// 3.数组
})
else
if
(
isArray
(
props
.
value
))
{
}
return
props
.
value
.
map
(
String
)
}
})
const
rederDictTag
=
()
=>
{
const
rederDictTag
=
()
=>
{
if
(
!
props
.
type
)
{
if
(
!
props
.
type
)
{
return
null
return
null
}
}
// 解决自定义字典标签值为零时标签不渲染的问题
// 解决自定义字典标签值为零时标签不渲染的问题
if
(
props
.
value
===
undefined
||
props
.
value
===
null
)
{
if
(
props
.
value
===
undefined
||
props
.
value
===
null
||
props
.
value
===
''
)
{
return
null
return
null
}
}
getDictObj
(
props
.
type
,
props
.
value
.
toString
()
)
const
dictOptions
=
getDictOptions
(
props
.
type
)
// 添加标签的文字颜色为白色,解决自定义背景颜色时标签文字看不清的问题
return
(
return
(
<
ElTag
<
div
class
=
"dict-tag"
>
style
=
{
dictData
.
value
?.
cssClass
?
'color: #fff'
:
''
}
{
dictOptions
.
map
((
dict
:
DictDataType
)
=>
{
type
=
{
dictData
.
value
?.
colorType
}
if
(
valueArr
.
value
.
includes
(
dict
.
value
))
{
color
=
{
if
(
dict
.
colorType
+
''
===
'primary'
||
dict
.
colorType
+
''
===
'default'
)
{
dictData
.
value
?.
cssClass
&&
isHexColor
(
dictData
.
value
?.
cssClass
)
dict
.
colorType
=
''
?
dictData
.
value
?.
cssClass
}
:
''
return
(
}
// 添加标签的文字颜色为白色,解决自定义背景颜色时标签文字看不清的问题
disableTransitions
=
{
true
}
<
ElTag
>
style
=
{
dict
?.
cssClass
?
'color: #fff'
:
''
}
{
dictData
.
value
?.
label
}
type
=
{
dict
?.
colorType
}
<
/ElTag
>
color
=
{
dict
?.
cssClass
&&
isHexColor
(
dict
?.
cssClass
)
?
dict
?.
cssClass
:
''
}
disableTransitions
=
{
true
}
>
{
dict
?.
label
}
<
/ElTag
>
)
}
})}
<
/div
>
)
)
}
}
return
()
=>
rederDictTag
()
return
()
=>
rederDictTag
()
...
...
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