Commit 7d4b325be875de8222bbbbfdb74e8a27126f5788

Authored by zhigang.li
1 parent e6508e27

close #2406

examples/routers/tag.vue
@@ -14,6 +14,11 @@ @@ -14,6 +14,11 @@
14 <Tag closable color="red" checkable>标签三</Tag> 14 <Tag closable color="red" checkable>标签三</Tag>
15 <Tag closable color="yellow" checkable>标签四</Tag> 15 <Tag closable color="yellow" checkable>标签四</Tag>
16 <br><br> 16 <br><br>
  17 + <Tag closable color="#EF6AFF" checkable>标签一</Tag>
  18 + <Tag type="border" closable color="#EF6AFF" checkable>标签二</Tag>
  19 + <Tag type="dot" closable color="#EF6AFF" checkable>标签三</Tag>
  20 + <Tag closable color="default" checkable>标签四</Tag>
  21 + <br><br>
17 <Tag type="border" closable color="blue" checkable>标签一</Tag> 22 <Tag type="border" closable color="blue" checkable>标签一</Tag>
18 <Tag type="border" closable color="green">标签二</Tag> 23 <Tag type="border" closable color="green">标签二</Tag>
19 <Tag type="border" closable color="red">标签三</Tag> 24 <Tag type="border" closable color="red">标签三</Tag>
src/components/tag/tag.vue
1 <template> 1 <template>
2 <transition name="fade"> 2 <transition name="fade">
3 - <div :class="classes" @click.stop="check">  
4 - <span :class="dotClasses" v-if="showDot"></span><span :class="textClasses"><slot></slot></span><Icon v-if="closable" type="ios-close-empty" @click.native.stop="close"></Icon> 3 + <div :class="classes" @click.stop="check" :style="wraperStyles">
  4 + <span :class="dotClasses" v-if="showDot" :style="bgColorStyle"></span>
  5 + <span :class="textClasses" :style="textColorStyle"><slot></slot></span>
  6 + <Icon v-if="closable" type="ios-close-empty" :color="lineColor" @click.native.stop="close"></Icon>
5 </div> 7 </div>
6 </transition> 8 </transition>
7 </template> 9 </template>
8 <script> 10 <script>
9 import Icon from '../icon'; 11 import Icon from '../icon';
10 import { oneOf } from '../../utils/assist'; 12 import { oneOf } from '../../utils/assist';
11 -  
12 const prefixCls = 'ivu-tag'; 13 const prefixCls = 'ivu-tag';
13 - 14 + const initColorList = ['blue', 'green', 'red', 'yellow', 'default'];
14 export default { 15 export default {
15 name: 'Tag', 16 name: 'Tag',
16 components: { Icon }, 17 components: { Icon },
@@ -28,9 +29,8 @@ @@ -28,9 +29,8 @@
28 default: true 29 default: true
29 }, 30 },
30 color: { 31 color: {
31 - validator (value) {  
32 - return oneOf(value, ['blue', 'green', 'red', 'yellow', 'default']);  
33 - } 32 + type: String,
  33 + default: 'default'
34 }, 34 },
35 type: { 35 type: {
36 validator (value) { 36 validator (value) {
@@ -58,14 +58,51 @@ @@ -58,14 +58,51 @@
58 } 58 }
59 ]; 59 ];
60 }, 60 },
  61 + wraperStyles () {
  62 + return oneOf(this.color, initColorList) ? {} : {background: this.defaultTypeColor, borderColor: this.lineColor, color: this.lineColor};
  63 + },
61 textClasses () { 64 textClasses () {
62 - return `${prefixCls}-text`; 65 + return [
  66 + `${prefixCls}-text`,
  67 + this.type === 'border' ? (oneOf(this.color, initColorList) ? `${prefixCls}-color-${this.color}` : '') : '',
  68 + (this.type !== 'dot' && this.type !== 'border' && this.color !== 'default') ? `${prefixCls}-color-white` : ''
  69 + ];
63 }, 70 },
64 dotClasses () { 71 dotClasses () {
65 return `${prefixCls}-dot-inner`; 72 return `${prefixCls}-dot-inner`;
66 }, 73 },
67 showDot () { 74 showDot () {
68 return !!this.type && this.type === 'dot'; 75 return !!this.type && this.type === 'dot';
  76 + },
  77 + lineColor () {
  78 + if (this.type === 'dot') {
  79 + return '';
  80 + } else if (this.type === 'border') {
  81 + return this.color !== undefined ? this.transferColor(this.color) : '';
  82 + } else {
  83 + return this.color !== undefined ? (this.color === 'default' ? '' : 'rgb(255, 255, 255)') : '';
  84 + }
  85 + },
  86 + borderColor () {
  87 + if (this.type === 'dot') {
  88 + return '';
  89 + } else if (this.type === 'border') {
  90 + return this.color !== undefined ? this.transferColor(this.color) : '';
  91 + } else {
  92 + return '';
  93 + }
  94 + },
  95 + textColorStyle () {
  96 + return oneOf(this.color, initColorList) ? {} : {color: this.lineColor};
  97 + },
  98 + mainColor () {
  99 + return this.color !== undefined ? this.transferColor(this.color) : '';
  100 + },
  101 + bgColorStyle () {
  102 + return oneOf(this.color, initColorList) ? {} : {background: this.mainColor};
  103 + },
  104 + defaultTypeColor () {
  105 + return (this.type !== 'dot' && this.type !== 'border') ? (this.color !== undefined ? this.transferColor(this.color) : '') : '';
69 } 106 }
70 }, 107 },
71 methods: { 108 methods: {
@@ -85,7 +122,20 @@ @@ -85,7 +122,20 @@
85 } else { 122 } else {
86 this.$emit('on-change', checked, this.name); 123 this.$emit('on-change', checked, this.name);
87 } 124 }
  125 + },
  126 + transferColor (name) {
  127 + if (oneOf(name, initColorList)) {
  128 + switch (name) {
  129 + case 'red': return '#ed3f14';
  130 + case 'green': return '#19be6b';
  131 + case 'yellow': return '#ff9900';
  132 + case 'blue': return '#2d8cf0';
  133 + case 'default': return '';
  134 + }
  135 + } else {
  136 + return name;
  137 + }
88 } 138 }
89 } 139 }
90 }; 140 };
91 -</script> 141 -</script>
  142 +</script>
92 \ No newline at end of file 143 \ No newline at end of file
src/styles/components/tag.less
@@ -27,6 +27,24 @@ @@ -27,6 +27,24 @@
27 } 27 }
28 } 28 }
29 29
  30 + &-color{
  31 + &-red{
  32 + color: @error-color !important;
  33 + }
  34 + &-green{
  35 + color: @success-color !important;
  36 + }
  37 + &-blue{
  38 + color: @link-color !important;
  39 + }
  40 + &-yellow{
  41 + color: @warning-color !important;
  42 + }
  43 + &-white{
  44 + color: rgb(255, 255, 255) !important;
  45 + }
  46 + }
  47 +
30 &-dot{ 48 &-dot{
31 height: 32px; 49 height: 32px;
32 line-height: 32px; 50 line-height: 32px;
@@ -54,13 +72,13 @@ @@ -54,13 +72,13 @@
54 &-border{ 72 &-border{
55 height: 24px; 73 height: 24px;
56 line-height: 24px; 74 line-height: 24px;
57 - border: 1px solid @border-color-split !important;  
58 - color: @text-color !important; 75 + border: 1px solid @border-color-split;
  76 + color: @border-color-split;
59 background: #fff !important; 77 background: #fff !important;
60 position: relative; 78 position: relative;
61 79
62 .@{tag-close-prefix-cls} { 80 .@{tag-close-prefix-cls} {
63 - color: #666 !important; 81 + color: #666;
64 margin-left: 12px !important; 82 margin-left: 12px !important;
65 } 83 }
66 84
@@ -68,7 +86,7 @@ @@ -68,7 +86,7 @@
68 content: ""; 86 content: "";
69 display: none; 87 display: none;
70 width: 1px; 88 width: 1px;
71 - background: @border-color-split; 89 + background: currentColor;
72 position: absolute; 90 position: absolute;
73 top: 0; 91 top: 0;
74 bottom: 0; 92 bottom: 0;
@@ -137,7 +155,7 @@ @@ -137,7 +155,7 @@
137 &, 155 &,
138 a, 156 a,
139 a:hover { 157 a:hover {
140 - color: @text-color; 158 + // color: @text-color;
141 } 159 }
142 160
143 &-text { 161 &-text {
@@ -146,6 +164,7 @@ @@ -146,6 +164,7 @@
146 margin: 0 -8px; 164 margin: 0 -8px;
147 padding: 0 8px; 165 padding: 0 8px;
148 } 166 }
  167 + color: @text-color;
149 } 168 }
150 169
151 .@{tag-close-prefix-cls} { 170 .@{tag-close-prefix-cls} {