diff --git a/src/components/LmsStatus/index.vue b/src/components/LmsStatus/index.vue index 461f945..b74eef3 100644 --- a/src/components/LmsStatus/index.vue +++ b/src/components/LmsStatus/index.vue @@ -10,7 +10,7 @@ LMS 状态 - + @@ -37,6 +37,7 @@ import { message } from 'ant-design-vue'; const { visible: dialogVisible, show, hide } = useDialog(); const isOnline = ref(false); +const loading = ref(false); const lmsStatus = computed(() => isOnline.value ? '在线' : '离线'); const onlineStatusClass = computed(() => { @@ -45,12 +46,19 @@ const onlineStatusClass = computed(() => { // 当请求发送成功后才切换状态 async function handleToggleOnline(checked: boolean | string | number) { - await updateLmsWorkMode(checked ? 1 : 0).then(() => { + console.log('checked', checked); + loading.value = true; + + try { + await updateLmsWorkMode(checked ? 1 : 0); isOnline.value = Boolean(checked); message.success('切换成功'); - }).catch((error) => { + } catch (e) { + isOnline.value = !Boolean(checked); message.error('切换失败'); - }); + } finally { + loading.value = false; + } } const modalTitle = ref('LMS 状态');