Blame view

src/components/checkbox/checkbox-group.vue 1.71 KB
7fa943eb   梁灏   init
1
2
3
4
5
6
  <template>
      <div :class="classes">
          <slot></slot>
      </div>
  </template>
  <script>
99cde29d   梁灏   update Checkbox
7
      import { findComponentsDownward } 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
                  }
7fa943eb   梁灏   init
20
21
              }
          },
cbe03a12   梁灏   support Checkbox
22
23
          data () {
              return {
99cde29d   梁灏   update Checkbox
24
25
                  currentValue: this.value,
                  childrens: []
cbe03a12   梁灏   support Checkbox
26
27
              };
          },
7fa943eb   梁灏   init
28
29
30
31
32
          computed: {
              classes () {
                  return `${prefixCls}`;
              }
          },
cbe03a12   梁灏   support Checkbox
33
          mounted () {
7fa943eb   梁灏   init
34
35
36
37
              this.updateModel(true);
          },
          methods: {
              updateModel (update) {
cbe03a12   梁灏   support Checkbox
38
                  const value = this.value;
99cde29d   梁灏   update Checkbox
39
                  this.childrens = findComponentsDownward(this, 'Checkbox');
7fa943eb   梁灏   init
40
  
99cde29d   梁灏   update Checkbox
41
42
43
                  if (this.childrens) {
                      this.childrens.forEach(child => {
                          child.model = value;
7fa943eb   梁灏   init
44
  
99cde29d   梁灏   update Checkbox
45
46
47
48
49
50
                          if (update) {
                              child.currentValue = value.indexOf(child.label) >= 0;
                              child.group = true;
                          }
                      });
                  }
7fa943eb   梁灏   init
51
52
              },
              change (data) {
cbe03a12   梁灏   support Checkbox
53
54
                  this.currentValue = data;
                  this.$emit('input', data);
7fa943eb   梁灏   init
55
                  this.$emit('on-change', data);
cd78c9c4   梁灏   some comps suppor...
56
                  this.dispatch('FormItem', 'on-form-change', data);
7fa943eb   梁灏   init
57
58
59
              }
          },
          watch: {
cbe03a12   梁灏   support Checkbox
60
              value () {
c1f6da1f   梁灏   fixed CheckboxGro...
61
                  this.updateModel(true);
7fa943eb   梁灏   init
62
63
              }
          }
b0893113   jingsam   :art: add eslint
64
65
      };
  </script>