1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<script>
import { h } from 'vue';
let uuid = 0;
export default {
name: 'studip-proxy-checkbox',
emits: ['update:selected'],
props: {
name: String,
id: String,
total: {
type: Array,
required: true
},
selected: {
type: Array,
required: true,
},
},
methods: {
changeProxy () {
this.$emit('update:selected', this.checked ? [] : [...this.total] );
}
},
computed: {
proxyId () {
return this.id ?? `proxy-checkbox-${uuid++}`;
},
checked () {
return this.selected.length === this.total.length;
},
indeterminate () {
return this.selected.length > 0 && this.selected.length !== this.total.length;
}
},
render () {
return h('input', {
type: 'checkbox',
name: this.name,
id: this.proxyId,
checked: this.checked ? true : null,
indeterminate: this.indeterminate ? true : null,
onChange: this.changeProxy,
});
}
};
</script>
|