修复switch 选择问题

This commit is contained in:
吕金泽 2022-08-06 17:55:50 +08:00
parent f338e97208
commit 4fe228fdcb
2 changed files with 13 additions and 14 deletions

View File

@ -16,12 +16,10 @@
</span>
<slot v-else-if="col.type == 'dynamic'" :name="col.field" :row="scope.row" :index="scope.$index" />
<div v-else-if="col.type == 'switch'">
<el-switch
v-if="col.if === undefined ? true : col.if(scope.row)"
v-model="scope.row[col.field]"
:active-value="(col.activeValue || 1) + ''"
:inactive-value="(col.inactiveValue || 0) + ''"
@change="col.change(scope.row)"
<mb-switch
v-if="col.if === undefined ? true : col.if(scope.row)"
v-model="scope.row[col.field]"
@change="col.change(scope.row)"
/>
</div>
<div v-else-if="col.type == 'btns'">

View File

@ -4,12 +4,13 @@
:active-value="_activeValue"
:inactive-value="_inactiveValue"
v-bind="props.props"
@change="change"
/>
</template>
<script setup>
import {ref, watch} from 'vue'
const emit = defineEmits(['update:modelValue'])
const emit = defineEmits(['update:modelValue', 'change'])
const selectValue = ref('')
const props = defineProps({
modelValue: Boolean | String | Number,
@ -20,15 +21,15 @@ const props = defineProps({
const _activeValue = ref(true)
const _inactiveValue = ref(false)
function change(){
emit('update:modelValue', selectValue.value)
emit('change', selectValue.value)
}
function setActive(value){
if(typeof(value) == 'boolean'){
if(props.activeValue == undefined && props.inactiveValue == undefined){
_activeValue.value = true
_inactiveValue.value = false
}else{
_activeValue.value = props.activeValue
_inactiveValue.value = props.inactiveValue
}
_activeValue.value = true
_inactiveValue.value = false
}else{
if(value || value == 0){
if(props.activeValue == undefined && props.inactiveValue == undefined){