Blame view

src/components/select/option.vue 2.15 KB
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
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  </template>
  <script>
      const prefixCls = 'ivu-select-item';
  
      export default {
          props: {
              value: {
                  type: [String, Number],
                  required: true
              },
              label: {
                  type: [String, Number]
              },
              disabled: {
                  type: Boolean,
                  default: false
              }
          },
          componentName: 'select-item',
          data () {
              return {
                  selected: false,
                  index: 0,    // for up and down to focus
e4ebd304   梁灏   update Select com...
26
27
28
                  isFocus: false,
                  hidden: false,    // for search
                  searchLabel: ''    // the value is slot,only for search
b0893113   jingsam   :art: add eslint
29
              };
e355dd49   梁灏   add Select Component
30
31
32
33
34
35
36
37
38
39
          },
          computed: {
              classes () {
                  return [
                      `${prefixCls}`,
                      {
                          [`${prefixCls}-disabled`]: this.disabled,
                          [`${prefixCls}-selected`]: this.selected,
                          [`${prefixCls}-focus`]: this.isFocus
                      }
b0893113   jingsam   :art: add eslint
40
                  ];
e355dd49   梁灏   add Select Component
41
42
              },
              showLabel () {
b0893113   jingsam   :art: add eslint
43
                  return (this.label) ? this.label : this.value;
e355dd49   梁灏   add Select Component
44
45
46
47
48
49
50
51
52
53
54
55
              }
          },
          methods: {
              select () {
                  if (this.disabled) {
                      return false;
                  }
  
                  this.$dispatch('on-select-selected', this.value);
              },
              blur () {
                  this.isFocus = false;
e4ebd304   梁灏   update Select com...
56
57
              },
              queryChange (val) {
d94d98c4   梁灏   fixed #215
58
59
                  const parsedQuery = val.replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, '\\$1');
                  this.hidden = !new RegExp(parsedQuery, 'i').test(this.searchLabel);
e355dd49   梁灏   add Select Component
60
61
              }
          },
54a83aa5   梁灏   fixed #211
62
          compiled () {
e4ebd304   梁灏   update Select com...
63
              this.searchLabel = this.$el.innerHTML;
e355dd49   梁灏   add Select Component
64
65
66
67
          },
          events: {
              'on-select-close' () {
                  this.isFocus = false;
e4ebd304   梁灏   update Select com...
68
69
70
              },
              'on-query-change' (val) {
                  this.queryChange(val);
e355dd49   梁灏   add Select Component
71
72
              }
          }
b0893113   jingsam   :art: add eslint
73
74
      };
  </script>