Blame view

src/components/checkbox/checkbox-group.vue 2.02 KB
7fa943eb   梁灏   init
1
2
3
4
5
6
  <template>
      <div :class="classes">
          <slot></slot>
      </div>
  </template>
  <script>
77f1cc2e   梁灏   Checkbox add size...
7
      import { findComponentsDownward, oneOf } from '../../utils/assist';
cd78c9c4   梁灏   some comps suppor...
8
      import Emitter from '../../mixins/emitter';
7fa943eb   梁灏   init
9
10
11
      const prefixCls = 'ivu-checkbox-group';
  
      export default {
34ee7b4a   梁灏   support Tree & ad...
12
          name: 'CheckboxGroup',
cd78c9c4   梁灏   some comps suppor...
13
          mixins: [ Emitter ],
7fa943eb   梁灏   init
14
          props: {
cbe03a12   梁灏   support Checkbox
15
              value: {
7fa943eb   梁灏   init
16
                  type: Array,
6ff31952   梁灏   optimize Input sh...
17
                  default () {
b0893113   jingsam   :art: add eslint
18
                      return [];
6ff31952   梁灏   optimize Input sh...
19
                  }
77f1cc2e   梁灏   Checkbox add size...
20
21
22
23
24
              },
              size: {
                  validator (value) {
                      return oneOf(value, ['small', 'large', 'default']);
                  }
7fa943eb   梁灏   init
25
26
              }
          },
cbe03a12   梁灏   support Checkbox
27
28
          data () {
              return {
99cde29d   梁灏   update Checkbox
29
30
                  currentValue: this.value,
                  childrens: []
cbe03a12   梁灏   support Checkbox
31
32
              };
          },
7fa943eb   梁灏   init
33
34
          computed: {
              classes () {
77f1cc2e   梁灏   Checkbox add size...
35
36
37
38
39
40
                  return [
                      `${prefixCls}`,
                      {
                          [`ivu-checkbox-${this.size}`]: !!this.size
                      }
                  ];
7fa943eb   梁灏   init
41
42
              }
          },
cbe03a12   梁灏   support Checkbox
43
          mounted () {
7fa943eb   梁灏   init
44
45
46
47
              this.updateModel(true);
          },
          methods: {
              updateModel (update) {
cbe03a12   梁灏   support Checkbox
48
                  const value = this.value;
99cde29d   梁灏   update Checkbox
49
                  this.childrens = findComponentsDownward(this, 'Checkbox');
7fa943eb   梁灏   init
50
  
99cde29d   梁灏   update Checkbox
51
52
53
                  if (this.childrens) {
                      this.childrens.forEach(child => {
                          child.model = value;
7fa943eb   梁灏   init
54
  
99cde29d   梁灏   update Checkbox
55
56
57
58
59
60
                          if (update) {
                              child.currentValue = value.indexOf(child.label) >= 0;
                              child.group = true;
                          }
                      });
                  }
7fa943eb   梁灏   init
61
62
              },
              change (data) {
cbe03a12   梁灏   support Checkbox
63
64
                  this.currentValue = data;
                  this.$emit('input', data);
7fa943eb   梁灏   init
65
                  this.$emit('on-change', data);
cd78c9c4   梁灏   some comps suppor...
66
                  this.dispatch('FormItem', 'on-form-change', data);
7fa943eb   梁灏   init
67
68
69
              }
          },
          watch: {
cbe03a12   梁灏   support Checkbox
70
              value () {
c1f6da1f   梁灏   fixed CheckboxGro...
71
                  this.updateModel(true);
7fa943eb   梁灏   init
72
73
              }
          }
b0893113   jingsam   :art: add eslint
74
75
      };
  </script>