forked from N3-components/N3-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
n3Tags.vue
85 lines (78 loc) · 1.54 KB
/
n3Tags.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
<div :class="classObj">
<label
v-for="i in value"
:class="tagClass(i)">
{{i.label}}
<a name="remove" v-if="removable" @click="del(i)"><n3-icon type="times"></n3-icon></a>
</label>
</div>
</template>
<script>
import n3Icon from './n3Icon'
export default{
props: {
type: {
type: String,
default: 'default'
},
value: {
type: Array,
twoway: true
},
size: {
type: String,
default: ''
},
removable: {
type: Boolean,
default: false
},
prefixCls: {
type: String,
default: 'n3'
}
},
components: {
n3Icon
},
computed: {
classObj () {
let {prefixCls, size, type} = this
let klass = {}
klass[prefixCls + '-tag-group'] = true
size ? klass[prefixCls + '-tag-' + size] = true : ''
type ? klass[prefixCls + '-tag-' + type] = true : ''
return klass
},
active () {
return this.type === 'default' ? 'tag-primary' : 'tag-' + this.type
}
},
methods: {
tagClass (i) {
let {prefixCls} = this
let klass = {}
klass[prefixCls + '-tag'] = true
klass[prefixCls + '-tag-disabled'] = i.disabled
return klass
},
find (i, target) {
let ret = -1
target.forEach((e, index) => {
if (e.value === i.value) {
ret = index
}
})
return ret
},
del (i) {
if (i.disabled) return
let index = this.find(i, this.value)
if (index > -1) {
this.value.splice(index, 1)
}
}
}
}
</script>