Blame view

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