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
|
import Emitter from '../../mixins/emitter';
|
fed3e09d
梁灏
add AutoComplete ...
|
6
|
import { findComponentUpward } from '../../utils/assist';
|
4aec6a66
梁灏
support Select
|
7
|
|
e355dd49
梁灏
add Select Component
|
8
9
10
|
const prefixCls = 'ivu-select-item';
export default {
|
4aec6a66
梁灏
support Select
|
11
12
13
|
name: 'iOption',
componentName: 'select-item',
mixins: [ Emitter ],
|
e355dd49
梁灏
add Select Component
|
14
15
16
17
18
19
20
21
22
23
24
25
26
|
props: {
value: {
type: [String, Number],
required: true
},
label: {
type: [String, Number]
},
disabled: {
type: Boolean,
default: false
}
},
|
e355dd49
梁灏
add Select Component
|
27
28
29
30
|
data () {
return {
selected: false,
index: 0, // for up and down to focus
|
e4ebd304
梁灏
update Select com...
|
31
32
|
isFocus: false,
hidden: false, // for search
|
fed3e09d
梁灏
add AutoComplete ...
|
33
34
|
searchLabel: '', // the value is slot,only for search
autoComplete: false
|
b0893113
jingsam
add eslint
|
35
|
};
|
e355dd49
梁灏
add Select Component
|
36
37
38
39
40
41
42
|
},
computed: {
classes () {
return [
`${prefixCls}`,
{
[`${prefixCls}-disabled`]: this.disabled,
|
fed3e09d
梁灏
add AutoComplete ...
|
43
|
[`${prefixCls}-selected`]: this.selected && !this.autoComplete,
|
e355dd49
梁灏
add Select Component
|
44
45
|
[`${prefixCls}-focus`]: this.isFocus
}
|
b0893113
jingsam
add eslint
|
46
|
];
|
e355dd49
梁灏
add Select Component
|
47
48
|
},
showLabel () {
|
b0893113
jingsam
add eslint
|
49
|
return (this.label) ? this.label : this.value;
|
e355dd49
梁灏
add Select Component
|
50
51
52
53
54
55
56
57
|
}
},
methods: {
select () {
if (this.disabled) {
return false;
}
|
4aec6a66
梁灏
support Select
|
58
|
this.dispatch('iSelect', 'on-select-selected', this.value);
|
e355dd49
梁灏
add Select Component
|
59
60
61
|
},
blur () {
this.isFocus = false;
|
e4ebd304
梁灏
update Select com...
|
62
63
|
},
queryChange (val) {
|
d94d98c4
梁灏
fixed #215
|
64
65
|
const parsedQuery = val.replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, '\\$1');
this.hidden = !new RegExp(parsedQuery, 'i').test(this.searchLabel);
|
e1b86bcf
梁灏
fixed #1865
|
66
67
68
|
},
// 在使用函数防抖后,设置 key 后,不更新组件了,导致SearchLabel 不更新 #1865
updateSearchLabel () {
|
dfae43a7
Sergio Crisostomo
correct input val...
|
69
|
this.searchLabel = this.$el.textContent;
|
6d017f5a
yangdan8
解决select-item引起的大...
|
70
71
72
73
74
75
|
},
onSelectClose(){
this.isFocus = false;
},
onQueryChange(val){
this.queryChange(val);
|
e355dd49
梁灏
add Select Component
|
76
77
|
}
},
|
4aec6a66
梁灏
support Select
|
78
|
mounted () {
|
e1b86bcf
梁灏
fixed #1865
|
79
|
this.updateSearchLabel();
|
ed91d9b0
梁灏
update Select
|
80
|
this.dispatch('iSelect', 'append');
|
6d017f5a
yangdan8
解决select-item引起的大...
|
81
82
|
this.$on('on-select-close', this.onSelectClose);
this.$on('on-query-change',this.onQueryChange);
|
fed3e09d
梁灏
add AutoComplete ...
|
83
84
85
|
const Select = findComponentUpward(this, 'iSelect');
if (Select) this.autoComplete = Select.autoComplete;
|
ed91d9b0
梁灏
update Select
|
86
87
88
|
},
beforeDestroy () {
this.dispatch('iSelect', 'remove');
|
6d017f5a
yangdan8
解决select-item引起的大...
|
89
90
|
this.$off('on-select-close', this.onSelectClose);
this.$off('on-query-change',this.onQueryChange);
|
e355dd49
梁灏
add Select Component
|
91
|
}
|
b0893113
jingsam
add eslint
|
92
93
|
};
</script>
|