7fa943eb
梁灏
init
|
1
|
<template>
|
456daf34
梁灏
support Tag
|
2
|
<transition name="fade">
|
7d4b325b
zhigang.li
close #2406
|
3
4
5
|
<div :class="classes" @click.stop="check" :style="wraperStyles">
<span :class="dotClasses" v-if="showDot" :style="bgColorStyle"></span>
<span :class="textClasses" :style="textColorStyle"><slot></slot></span>
|
78fc1e14
zhigang.li
update tag custom...
|
6
|
<Icon v-if="closable" :class="iconClass" :color="lineColor" type="ios-close-empty" @click.native.stop="close"></Icon>
|
456daf34
梁灏
support Tag
|
7
8
|
</div>
</transition>
|
7fa943eb
梁灏
init
|
9
10
11
12
|
</template>
<script>
import Icon from '../icon';
import { oneOf } from '../../utils/assist';
|
7fa943eb
梁灏
init
|
13
|
const prefixCls = 'ivu-tag';
|
7d4b325b
zhigang.li
close #2406
|
14
|
const initColorList = ['blue', 'green', 'red', 'yellow', 'default'];
|
7fa943eb
梁灏
init
|
15
|
export default {
|
34ee7b4a
梁灏
support Tree & ad...
|
16
|
name: 'Tag',
|
7fa943eb
梁灏
init
|
17
18
19
20
21
22
|
components: { Icon },
props: {
closable: {
type: Boolean,
default: false
},
|
dc39cc31
daiyanze
Feature: Checkabl...
|
23
24
25
26
27
28
29
30
|
checkable: {
type: Boolean,
default: false
},
checked: {
type: Boolean,
default: true
},
|
7fa943eb
梁灏
init
|
31
|
color: {
|
7d4b325b
zhigang.li
close #2406
|
32
33
|
type: String,
default: 'default'
|
382c000c
梁灏
Tag add type prop...
|
34
35
36
37
38
|
},
type: {
validator (value) {
return oneOf(value, ['border', 'dot']);
}
|
ec4117cb
梁灏
tag add prop: name
|
39
40
41
|
},
name: {
type: [String, Number]
|
7fa943eb
梁灏
init
|
42
43
|
}
},
|
dc39cc31
daiyanze
Feature: Checkabl...
|
44
45
46
47
48
|
data () {
return {
isChecked: this.checked
};
},
|
7fa943eb
梁灏
init
|
49
50
51
52
53
|
computed: {
classes () {
return [
`${prefixCls}`,
{
|
2079c47b
梁灏
update Tag
|
54
|
[`${prefixCls}-${this.color}`]: !!this.color,
|
382c000c
梁灏
Tag add type prop...
|
55
|
[`${prefixCls}-${this.type}`]: !!this.type,
|
dc39cc31
daiyanze
Feature: Checkabl...
|
56
|
[`${prefixCls}-closable`]: this.closable,
|
fd79f102
Aresn
Update tag.vue
|
57
|
[`${prefixCls}-checked`]: this.isChecked
|
7fa943eb
梁灏
init
|
58
|
}
|
b0893113
jingsam
add eslint
|
59
|
];
|
7fa943eb
梁灏
init
|
60
|
},
|
7d4b325b
zhigang.li
close #2406
|
61
62
63
|
wraperStyles () {
return oneOf(this.color, initColorList) ? {} : {background: this.defaultTypeColor, borderColor: this.lineColor, color: this.lineColor};
},
|
7fa943eb
梁灏
init
|
64
|
textClasses () {
|
7d4b325b
zhigang.li
close #2406
|
65
66
67
68
69
|
return [
`${prefixCls}-text`,
this.type === 'border' ? (oneOf(this.color, initColorList) ? `${prefixCls}-color-${this.color}` : '') : '',
(this.type !== 'dot' && this.type !== 'border' && this.color !== 'default') ? `${prefixCls}-color-white` : ''
];
|
382c000c
梁灏
Tag add type prop...
|
70
71
72
73
|
},
dotClasses () {
return `${prefixCls}-dot-inner`;
},
|
78fc1e14
zhigang.li
update tag custom...
|
74
|
iconClass () {
|
7d4b325b
zhigang.li
close #2406
|
75
76
77
|
if (this.type === 'dot') {
return '';
} else if (this.type === 'border') {
|
78fc1e14
zhigang.li
update tag custom...
|
78
|
return `${prefixCls}-color-${this.color}`;
|
7d4b325b
zhigang.li
close #2406
|
79
80
81
82
|
} else {
return this.color !== undefined ? (this.color === 'default' ? '' : 'rgb(255, 255, 255)') : '';
}
},
|
78fc1e14
zhigang.li
update tag custom...
|
83
84
85
86
|
showDot () {
return !!this.type && this.type === 'dot';
},
lineColor () {
|
7d4b325b
zhigang.li
close #2406
|
87
88
89
|
if (this.type === 'dot') {
return '';
} else if (this.type === 'border') {
|
78fc1e14
zhigang.li
update tag custom...
|
90
|
return this.color !== undefined ? (oneOf(this.color, initColorList) ? '' : this.color) : '';
|
7d4b325b
zhigang.li
close #2406
|
91
|
} else {
|
78fc1e14
zhigang.li
update tag custom...
|
92
|
return this.color !== undefined ? (this.color === 'default' ? '' : 'rgb(255, 255, 255)') : '';
|
7d4b325b
zhigang.li
close #2406
|
93
94
|
}
},
|
78fc1e14
zhigang.li
update tag custom...
|
95
96
97
|
dotColor () {
return this.color !== undefined ? (oneOf(this.color, initColorList) ? '' : this.color) : '';
},
|
7d4b325b
zhigang.li
close #2406
|
98
99
100
|
textColorStyle () {
return oneOf(this.color, initColorList) ? {} : {color: this.lineColor};
},
|
7d4b325b
zhigang.li
close #2406
|
101
|
bgColorStyle () {
|
78fc1e14
zhigang.li
update tag custom...
|
102
|
return oneOf(this.color, initColorList) ? {} : {background: this.dotColor};
|
7d4b325b
zhigang.li
close #2406
|
103
104
|
},
defaultTypeColor () {
|
78fc1e14
zhigang.li
update tag custom...
|
105
|
return (this.type !== 'dot' && this.type !== 'border') ? (this.color !== undefined ? (oneOf(this.color, initColorList) ? '' : this.color) : '') : '';
|
7fa943eb
梁灏
init
|
106
107
108
|
}
},
methods: {
|
ec4117cb
梁灏
tag add prop: name
|
109
|
close (event) {
|
4c6d9962
Aresn
Update tag.vue
|
110
111
112
113
114
|
if (this.name === undefined) {
this.$emit('on-close', event);
} else {
this.$emit('on-close', event, this.name);
}
|
dc39cc31
daiyanze
Feature: Checkabl...
|
115
|
},
|
4c6d9962
Aresn
Update tag.vue
|
116
117
118
119
|
check () {
if (!this.checkable) return;
const checked = !this.isChecked;
this.isChecked = checked;
|
ec4117cb
梁灏
tag add prop: name
|
120
|
if (this.name === undefined) {
|
4c6d9962
Aresn
Update tag.vue
|
121
|
this.$emit('on-change', checked);
|
ec4117cb
梁灏
tag add prop: name
|
122
|
} else {
|
4c6d9962
Aresn
Update tag.vue
|
123
|
this.$emit('on-change', checked, this.name);
|
ec4117cb
梁灏
tag add prop: name
|
124
|
}
|
7fa943eb
梁灏
init
|
125
126
|
}
}
|
b0893113
jingsam
add eslint
|
127
|
};
|
7d4b325b
zhigang.li
close #2406
|
128
|
</script>
|