<template>
  <span v-if="_readonly" v-text="myVal"></span>
  <KSwitch v-else v-model="value" :disabled="disabled" v-bind="_fieldProps">
    <template v-if="$Attrs.on" #on>
      {{ $Attrs.on }}
    </template>
    <template v-else #on>开</template>
    <template v-if="$Attrs.off" #off>
      {{ $Attrs.off }}
    </template>
    <template v-else #off>关</template>
  </KSwitch>
</template>
<script setup>
import { inject, useAttrs,  computed,onMounted } from 'vue';
import { useFieldBasics } from '../usefieldBasics';
import { Switch as KSwitch } from '@king-design/vue';
import { useRoute } from 'vue-router';
const route = useRoute();
const $Attrs = useAttrs();
const formInfo = inject('formInfo');
const emit = defineEmits(['change']);

const { value, _readonly, disabled,_fieldProps,onLinkage } = useFieldBasics($Attrs, formInfo, route, emit);
const myVal = computed(()=>{
	const on = $Attrs.on || '开'
	const off = $Attrs.off || '关'
	return value.value ? on: off;
})
onMounted(async () => {
	onLinkage();
});
</script>
<style lang="less">
</style>
