Commit 25570e23 authored by zhangwenshuai's avatar zhangwenshuai

update tag

parent b93eb567
...@@ -3,6 +3,20 @@ import { Popover } from 'antd'; ...@@ -3,6 +3,20 @@ import { Popover } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import s from './index.less'; import s from './index.less';
const getColor = (item: any, options: any[]) => {
let color = '';
if (item.text === item.value) {
return 'transparent';
}
if (options && Array.isArray(options) && options.length > 0) {
const obj =
options.find((ls) => {
return String(ls.id) === String(item.value);
}) || {};
color = obj.color || 'e9eef9';
}
return `#${color}`;
};
export const Tags = (props: any) => { export const Tags = (props: any) => {
const { value, origin, componentAttr, columnConfig } = props; const { value, origin, componentAttr, columnConfig } = props;
if (!Array.isArray(value) || value.length === 0) return null; if (!Array.isArray(value) || value.length === 0) return null;
...@@ -18,23 +32,12 @@ export const Tags = (props: any) => { ...@@ -18,23 +32,12 @@ export const Tags = (props: any) => {
innerStyle.flexWrap = 'wrap'; innerStyle.flexWrap = 'wrap';
itemStyle.marginBottom = '5px'; itemStyle.marginBottom = '5px';
} }
const getColor = (item: any) => {
let color = '';
if (options && Array.isArray(options) && options.length > 0) {
const obj =
options.find((ls) => {
return String(ls.id) === String(item.value);
}) || {};
color = obj.color || 'e9eef9';
}
return color;
};
if (mode !== 'multiple') { if (mode !== 'multiple') {
// 单选 // 单选
return ( return (
<div className={s.container} style={{ overflow: 'hidden' }}> <div className={s.container} style={{ overflow: 'hidden' }}>
<span className={s.item} style={{ ...itemStyle, background: `#${getColor(value[0])}` }}> <span className={s.item} style={{ ...itemStyle, background: getColor(value[0], options) }}>
<div className={s.itemBgTxt}>{value[0].text}</div> <div className={s.itemBgTxt}>{value[0].text}</div>
</span> </span>
</div> </div>
...@@ -78,7 +81,7 @@ export const Tags = (props: any) => { ...@@ -78,7 +81,7 @@ export const Tags = (props: any) => {
<span <span
className={s.popItem} className={s.popItem}
key={index} key={index}
style={{ background: `#${getColor(item)}` }} style={{ background: getColor(item, options) }}
> >
<div className={s.popItemBgTxt}>{item.text}</div> <div className={s.popItemBgTxt}>{item.text}</div>
</span> </span>
...@@ -93,7 +96,7 @@ export const Tags = (props: any) => { ...@@ -93,7 +96,7 @@ export const Tags = (props: any) => {
<span <span
key={index} key={index}
className={classNames(s.item, s.multi)} className={classNames(s.item, s.multi)}
style={{ ...itemStyle, background: `#${getColor(item)}` }} style={{ ...itemStyle, background: getColor(item, options) }}
> >
<div className={s.itemBgTxt}>{item.text}</div> <div className={s.itemBgTxt}>{item.text}</div>
</span> </span>
...@@ -108,7 +111,7 @@ export const Tags = (props: any) => { ...@@ -108,7 +111,7 @@ export const Tags = (props: any) => {
<span <span
key={index} key={index}
className={classNames(s.item, s.multi)} className={classNames(s.item, s.multi)}
style={{ ...itemStyle, background: `#${getColor(item)}` }} style={{ ...itemStyle, background: getColor(item, options) }}
> >
<div className={s.itemBgTxt}>{item.text}</div> <div className={s.itemBgTxt}>{item.text}</div>
</span> </span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment