e355dd49
梁灏
add Select Component
|
1
|
<template>
|
e4ebd304
梁灏
update Select com...
|
2
|
<li :class="classes" @click.stop="select" @mouseout.stop="blur" v-show="!hidden"><slot>{{ showLabel }}</slot></li>
|
e355dd49
梁灏
add Select Component
|
3
4
|
</template>
<script>
|
4aec6a66
梁灏
support Select
|
5
6
|
import Emitter from '../../mixins/emitter';
|
e355dd49
梁灏
add Select Component
|
7
8
9
|
const prefixCls = 'ivu-select-item';
export default {
|
4aec6a66
梁灏
support Select
|
10
11
12
|
name: 'iOption',
componentName: 'select-item',
mixins: [ Emitter ],
|
e355dd49
梁灏
add Select Component
|
13
14
15
16
17
18
19
20
21
22
23
24
25
|
props: {
value: {
type: [String, Number],
required: true
},
label: {
type: [String, Number]
},
disabled: {
type: Boolean,
default: false
}
},
|
e355dd49
梁灏
add Select Component
|
26
27
28
29
|
data () {
return {
selected: false,
index: 0, // for up and down to focus
|
e4ebd304
梁灏
update Select com...
|
30
31
32
|
isFocus: false,
hidden: false, // for search
searchLabel: '' // the value is slot,only for search
|
b0893113
jingsam
add eslint
|
33
|
};
|
e355dd49
梁灏
add Select Component
|
34
35
36
37
38
39
40
41
42
43
|
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-disabled`]: this.disabled,
[`${prefixCls}-selected`]: this.selected,
[`${prefixCls}-focus`]: this.isFocus
}
|
b0893113
jingsam
add eslint
|
44
|
];
|
e355dd49
梁灏
add Select Component
|
45
46
|
},
showLabel () {
|
b0893113
jingsam
add eslint
|
47
|
return (this.label) ? this.label : this.value;
|
e355dd49
梁灏
add Select Component
|
48
49
50
51
52
53
54
55
|
}
},
methods: {
select () {
if (this.disabled) {
return false;
}
|
4aec6a66
梁灏
support Select
|
56
|
this.dispatch('iSelect', 'on-select-selected', this.value);
|
e355dd49
梁灏
add Select Component
|
57
58
59
|
},
blur () {
this.isFocus = false;
|
e4ebd304
梁灏
update Select com...
|
60
61
|
},
queryChange (val) {
|
d94d98c4
梁灏
fixed #215
|
62
63
|
const parsedQuery = val.replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, '\\$1');
this.hidden = !new RegExp(parsedQuery, 'i').test(this.searchLabel);
|
e355dd49
梁灏
add Select Component
|
64
65
|
}
},
|
4aec6a66
梁灏
support Select
|
66
|
mounted () {
|
e4ebd304
梁灏
update Select com...
|
67
|
this.searchLabel = this.$el.innerHTML;
|
ed91d9b0
梁灏
update Select
|
68
|
this.dispatch('iSelect', 'append');
|
4aec6a66
梁灏
support Select
|
69
|
this.$on('on-select-close', () => {
|
e355dd49
梁灏
add Select Component
|
70
|
this.isFocus = false;
|
4aec6a66
梁灏
support Select
|
71
72
|
});
this.$on('on-query-change', (val) => {
|
e4ebd304
梁灏
update Select com...
|
73
|
this.queryChange(val);
|
4aec6a66
梁灏
support Select
|
74
|
});
|
ed91d9b0
梁灏
update Select
|
75
76
77
|
},
beforeDestroy () {
this.dispatch('iSelect', 'remove');
|
e355dd49
梁灏
add Select Component
|
78
|
}
|
b0893113
jingsam
add eslint
|
79
80
|
};
</script>
|