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