2016-07-27 06:15:02 +00:00
|
|
|
<template>
|
|
|
|
<label class="el-checkbox">
|
|
|
|
<span class="el-checkbox__input">
|
|
|
|
<span class="el-checkbox__inner"
|
|
|
|
:class="{
|
2016-08-15 03:59:11 +00:00
|
|
|
'is-disabled': disabled,
|
2016-07-27 06:15:02 +00:00
|
|
|
'is-checked': checked,
|
|
|
|
'is-indeterminate': indeterminate,
|
|
|
|
'is-focus': focus
|
|
|
|
}"
|
|
|
|
></span>
|
|
|
|
<input
|
|
|
|
v-if="trueLabel || falseLabel"
|
|
|
|
class="el-checkbox__original"
|
|
|
|
:true-value="trueLabel"
|
|
|
|
:false-value="falseLabel"
|
|
|
|
v-model="_value"
|
|
|
|
type="checkbox"
|
|
|
|
@focus="focus = true"
|
|
|
|
@blur="focus = false"
|
2016-08-15 03:59:11 +00:00
|
|
|
:disabled="disabled"
|
2016-08-12 06:45:06 +00:00
|
|
|
ref="checkbox">
|
2016-07-27 06:15:02 +00:00
|
|
|
<input
|
|
|
|
v-else
|
|
|
|
class="el-checkbox__original"
|
|
|
|
:value="label"
|
|
|
|
v-model="_value"
|
|
|
|
@focus="focus = true"
|
|
|
|
@blur="focus = false"
|
|
|
|
type="checkbox"
|
2016-08-15 03:59:11 +00:00
|
|
|
:disabled="disabled">
|
2016-07-27 06:15:02 +00:00
|
|
|
</span>
|
|
|
|
<span class="el-checkbox__label">
|
|
|
|
<slot></slot>
|
2016-08-12 06:45:06 +00:00
|
|
|
<template v-if="!$slots || !$slots.default">{{label}}</template>
|
2016-07-27 06:15:02 +00:00
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
</template>
|
|
|
|
<script>
|
2016-08-12 06:45:06 +00:00
|
|
|
import Emitter from 'main/mixins/emitter';
|
2016-08-15 03:59:11 +00:00
|
|
|
|
2016-07-27 06:15:02 +00:00
|
|
|
export default {
|
|
|
|
name: 'ElCheckbox',
|
|
|
|
|
2016-08-12 06:45:06 +00:00
|
|
|
mixins: [Emitter],
|
|
|
|
|
2016-07-27 06:15:02 +00:00
|
|
|
props: {
|
2016-08-12 06:45:06 +00:00
|
|
|
value: {},
|
2016-07-27 06:15:02 +00:00
|
|
|
label: {
|
|
|
|
type: String
|
|
|
|
},
|
|
|
|
indeterminate: Boolean,
|
|
|
|
disabled: Boolean,
|
2016-08-15 03:59:11 +00:00
|
|
|
trueLabel: [String, Number],
|
|
|
|
falseLabel: [String, Number]
|
2016-07-27 06:15:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
_value: {
|
|
|
|
get() {
|
|
|
|
return this.value !== undefined ? this.value : this.$parent.value;
|
|
|
|
},
|
|
|
|
set(newValue) {
|
|
|
|
if (this.value !== undefined) {
|
2016-08-12 06:45:06 +00:00
|
|
|
this.$emit('input', newValue);
|
2016-07-27 06:15:02 +00:00
|
|
|
} else {
|
2016-08-12 06:45:06 +00:00
|
|
|
this.$parent.$emit('input', newValue);
|
2016-07-27 06:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
checked() {
|
|
|
|
var type = Object.prototype.toString.call(this._value);
|
|
|
|
|
|
|
|
if (type === '[object Boolean]') {
|
|
|
|
return this._value;
|
|
|
|
} else if (type === '[object Array]') {
|
|
|
|
return this._value.indexOf(this.label) > -1;
|
2016-08-15 03:59:11 +00:00
|
|
|
} else if (type === '[object String]' || type === '[object Number]') {
|
2016-07-27 06:15:02 +00:00
|
|
|
return this._value === this.trueLabel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
focus: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
checked(sure) {
|
2016-08-15 03:59:11 +00:00
|
|
|
this.$emit('change', sure);
|
2016-07-27 06:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|