优化切换LMS状态功能:请求失败不允许切换

This commit is contained in:
tao
2025-09-30 15:46:20 +08:00
parent c8f50782af
commit 39f0d1e126

View File

@@ -10,7 +10,7 @@
<a-row :gutter="[0, 12]">
<a-col :span="8" class="modal-label">LMS 状态</a-col>
<a-col :span="16" class="modal-value">
<a-switch v-model:checked="isOnline" checked-children="在线" un-checked-children="离线" @change="handleToggleOnline" />
<a-switch v-model:checked="isOnline" checked-children="在线" un-checked-children="离线" :loading="loading" @click="handleToggleOnline" />
</a-col>
</a-row>
<a-row :gutter="[0, 12]">
@@ -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 状态');