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
f7d31d5c
authored
Aug 08, 2024
by
YunaiV
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/GoldenZqqq/yudao-ui-admin-vue3
# Conflicts: # src/components/DictTag/src/DictTag.vue
parents
53cef8b4
b5eb9e73
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
22 deletions
+52
-22
src/components/DictTag/src/DictTag.vue
+52
-22
No files found.
src/components/DictTag/src/DictTag.vue
View file @
f7d31d5c
<
script
lang=
"tsx"
>
import
{
defineComponent
,
PropType
,
ref
}
from
'vue'
import
{
defineComponent
,
PropType
,
computed
}
from
'vue'
import
{
isHexColor
}
from
'@/utils/color'
import
{
ElTag
}
from
'element-plus'
import
{
DictDataType
,
getDictOptions
}
from
'@/utils/dict'
import
{
isArray
,
isString
,
isNumber
}
from
'@/utils/is'
export
default
defineComponent
({
name
:
'DictTag'
,
...
...
@@ -12,48 +13,77 @@ export default defineComponent({
required
:
true
},
value
:
{
type
:
[
String
,
Number
,
Boolean
]
as
PropType
<
string
|
number
|
boolean
>
,
type
:
[
String
,
Number
,
Boolean
,
Array
]
,
required
:
true
},
// 字符串分隔符 只有当 props.value 传入值为字符串时有效
sepSymbol
:
{
type
:
String
as
PropType
<
string
>
,
default
:
','
},
// 每个tag之间的间隔,默认为5px
tagSpacing
:
{
type
:
String
as
PropType
<
string
>
,
default
:
'5px'
}
},
setup
(
props
)
{
const
dictData
=
ref
<
DictDataType
>
()
const
getDictObj
=
(
dictType
:
string
,
value
:
string
)
=>
{
const
dictOptions
=
getDictOptions
(
dictType
)
dictOptions
.
forEach
((
dict
:
DictDataType
)
=>
{
if
(
dict
.
value
===
value
)
{
if
(
dict
.
colorType
+
''
===
'default'
)
{
dict
.
colorType
=
'info'
const
valueArr
:
any
=
computed
(()
=>
{
// 1.是Number类型的情况
if
(
isNumber
(
props
.
value
))
{
return
[
String
(
props
.
value
)]
}
dictData
.
value
=
dict
// 2.是字符串(进一步判断是否有包含分隔符号 -> props.sepSymbol )
else
if
(
isString
(
props
.
value
))
{
return
props
.
value
.
split
(
props
.
sepSymbol
)
}
})
// 3.数组
else
if
(
isArray
(
props
.
value
))
{
return
props
.
value
.
map
(
String
)
}
return
[]
})
const
rederDictTag
=
()
=>
{
if
(
!
props
.
type
)
{
return
null
}
// 解决自定义字典标签值为零时标签不渲染的问题
if
(
props
.
value
===
undefined
||
props
.
value
===
null
)
{
if
(
props
.
value
===
undefined
||
props
.
value
===
null
||
props
.
value
===
''
)
{
return
null
}
getDictObj
(
props
.
type
,
props
.
value
.
toString
()
)
// 添加标签的文字颜色为白色,解决自定义背景颜色时标签文字看不清的问题
const
dictOptions
=
getDictOptions
(
props
.
type
)
return
(
<
ElTag
style
=
{
dictData
.
value
?.
cssClass
?
'color: #fff'
:
''
}
type
=
{
dictData
.
value
?.
colorType
}
color
=
{
dictData
.
value
?.
cssClass
&&
isHexColor
(
dictData
.
value
?.
cssClass
)
?
dictData
.
value
?.
cssClass
:
''
<
div
class
=
"dict-tag"
style
=
{{
display
:
'flex'
,
gap
:
props
.
tagSpacing
,
justifyContent
:
'center'
,
alignItems
:
'center'
}}
>
{
dictOptions
.
map
((
dict
:
DictDataType
)
=>
{
if
(
valueArr
.
value
.
includes
(
dict
.
value
))
{
if
(
dict
.
colorType
+
''
===
'primary'
||
dict
.
colorType
+
''
===
'default'
)
{
dict
.
colorType
=
''
}
return
(
// 添加标签的文字颜色为白色,解决自定义背景颜色时标签文字看不清的问题
<
ElTag
style
=
{
dict
?.
cssClass
?
'color: #fff'
:
''
}
type
=
{
dict
?.
colorType
}
color
=
{
dict
?.
cssClass
&&
isHexColor
(
dict
?.
cssClass
)
?
dict
?.
cssClass
:
''
}
disableTransitions
=
{
true
}
>
{
dictData
.
value
?.
label
}
{
dict
?.
label
}
<
/ElTag
>
)
}
})}
<
/div
>
)
}
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