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

39 lines
772 B
Vue
Raw Normal View History

2024-04-25 16:35:10 +08:00
<script setup lang="ts">
import { ref } from 'vue';
2024-04-25 16:35:10 +08:00
defineOptions({
name: 'StatusSwitch'
});
const model = defineModel<Api.Common.EnableStatusNumber>({ default: 0 });
2024-04-25 21:29:20 +08:00
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>();
/** 状态切换过程的 loading 状态 */
2024-04-25 16:35:10 +08:00
const loading = ref(false);
2024-04-25 21:29:20 +08:00
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
:value="model"
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>