gtsoft-snail-job-admin/src/components/common/status-switch.vue

52 lines
898 B
Vue
Raw Normal View History

2024-04-25 16:35:10 +08:00
<script setup lang="ts">
2024-04-25 21:29:20 +08:00
import { ref, watch } from 'vue';
2024-04-25 16:35:10 +08:00
defineOptions({
name: 'StatusSwitch'
});
2024-04-25 21:29:20 +08:00
interface Props {
2024-04-25 23:39:42 +08:00
value?: Api.Common.EnableStatusNumber;
2024-04-25 21:29:20 +08:00
}
const props = withDefaults(defineProps<Props>(), {
value: 0
});
2024-04-25 16:35:10 +08:00
interface Emits {
2024-04-25 22:14:58 +08:00
(e: 'fetch', value: Api.Common.EnableStatusNumber, callback: () => void): void;
2024-04-25 16:35:10 +08:00
}
const emit = defineEmits<Emits>();
2024-04-25 21:29:20 +08:00
const active = ref(props.value);
2024-04-25 16:35:10 +08:00
const loading = ref(false);
2024-04-25 21:29:20 +08:00
watch(
() => props.value,
value => {
active.value = value;
}
);
const handleUpdateValue = (value: Api.Common.EnableStatusNumber) => {
loading.value = true;
2024-04-25 22:14:58 +08:00
emit('fetch', value, () => {
loading.value = false;
});
2024-04-25 16:35:10 +08:00
};
</script>
<template>
<NSwitch
2024-04-25 21:29:20 +08:00
:value="active"
2024-04-25 16:35:10 +08:00
:loading="loading"
2024-04-25 22:14:58 +08:00
:rubber-band="false"
2024-04-25 16:35:10 +08:00
:checked-value="1"
:unchecked-value="0"
2024-04-25 21:29:20 +08:00
@update:value="handleUpdateValue"
/>
2024-04-25 16:35:10 +08:00
</template>
<style scoped></style>