mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-03-15 15:36:44 +08:00
fix: 修复了确认对话框操作的变量在点击时被重置的bug
This commit is contained in:
@@ -33,7 +33,9 @@ const activeTab = ref('atx')
|
||||
|
||||
// ATX state
|
||||
const powerState = ref<'on' | 'off' | 'unknown'>('unknown')
|
||||
const confirmAction = ref<'short' | 'long' | 'reset' | null>(null)
|
||||
// Decouple action data from dialog visibility to prevent race conditions
|
||||
const pendingAction = ref<'short' | 'long' | 'reset' | null>(null)
|
||||
const confirmDialogOpen = ref(false)
|
||||
|
||||
// WOL state
|
||||
const wolMacAddress = ref('')
|
||||
@@ -56,15 +58,21 @@ const powerStateText = computed(() => {
|
||||
}
|
||||
})
|
||||
|
||||
function requestAction(action: 'short' | 'long' | 'reset') {
|
||||
pendingAction.value = action
|
||||
confirmDialogOpen.value = true
|
||||
}
|
||||
|
||||
function handleAction() {
|
||||
if (confirmAction.value === 'short') emit('powerShort')
|
||||
else if (confirmAction.value === 'long') emit('powerLong')
|
||||
else if (confirmAction.value === 'reset') emit('reset')
|
||||
confirmAction.value = null
|
||||
console.log('[AtxPopover] Confirming action:', pendingAction.value)
|
||||
if (pendingAction.value === 'short') emit('powerShort')
|
||||
else if (pendingAction.value === 'long') emit('powerLong')
|
||||
else if (pendingAction.value === 'reset') emit('reset')
|
||||
confirmDialogOpen.value = false
|
||||
}
|
||||
|
||||
const confirmTitle = computed(() => {
|
||||
switch (confirmAction.value) {
|
||||
switch (pendingAction.value) {
|
||||
case 'short': return t('atx.confirmShortTitle')
|
||||
case 'long': return t('atx.confirmLongTitle')
|
||||
case 'reset': return t('atx.confirmResetTitle')
|
||||
@@ -73,14 +81,13 @@ const confirmTitle = computed(() => {
|
||||
})
|
||||
|
||||
const confirmDescription = computed(() => {
|
||||
switch (confirmAction.value) {
|
||||
switch (pendingAction.value) {
|
||||
case 'short': return t('atx.confirmShortDesc')
|
||||
case 'long': return t('atx.confirmLongDesc')
|
||||
case 'reset': return t('atx.confirmResetDesc')
|
||||
default: return ''
|
||||
}
|
||||
})
|
||||
|
||||
// MAC address validation
|
||||
const isValidMac = computed(() => {
|
||||
const mac = wolMacAddress.value.trim()
|
||||
@@ -169,7 +176,7 @@ if (savedHistory) {
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="w-full justify-start gap-2 h-8 text-xs"
|
||||
@click="confirmAction = 'short'"
|
||||
@click="requestAction('short')"
|
||||
>
|
||||
<Power class="h-3.5 w-3.5" />
|
||||
{{ t('atx.shortPress') }}
|
||||
@@ -179,7 +186,7 @@ if (savedHistory) {
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="w-full justify-start gap-2 h-8 text-xs text-orange-600 hover:text-orange-700 hover:bg-orange-50 dark:hover:bg-orange-950"
|
||||
@click="confirmAction = 'long'"
|
||||
@click="requestAction('long')"
|
||||
>
|
||||
<CircleDot class="h-3.5 w-3.5" />
|
||||
{{ t('atx.longPress') }}
|
||||
@@ -189,7 +196,7 @@ if (savedHistory) {
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="w-full justify-start gap-2 h-8 text-xs text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950"
|
||||
@click="confirmAction = 'reset'"
|
||||
@click="requestAction('reset')"
|
||||
>
|
||||
<RotateCcw class="h-3.5 w-3.5" />
|
||||
{{ t('atx.reset') }}
|
||||
@@ -247,7 +254,7 @@ if (savedHistory) {
|
||||
</div>
|
||||
|
||||
<!-- Confirm Dialog -->
|
||||
<AlertDialog :open="!!confirmAction" @update:open="confirmAction = null">
|
||||
<AlertDialog :open="confirmDialogOpen" @update:open="confirmDialogOpen = $event">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{{ confirmTitle }}</AlertDialogTitle>
|
||||
|
||||
@@ -1310,15 +1310,19 @@ function openTerminalInNewTab() {
|
||||
|
||||
// ATX actions
|
||||
async function handlePowerShort() {
|
||||
console.log('[ConsoleView] Handling power short press')
|
||||
try {
|
||||
await atxApi.power('short')
|
||||
const res = await atxApi.power('short')
|
||||
console.log('[ConsoleView] Power short API result:', res)
|
||||
await systemStore.fetchAtxState()
|
||||
} catch {
|
||||
} catch (e) {
|
||||
console.error('[ConsoleView] Power short API failed:', e)
|
||||
// ATX action failed
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePowerLong() {
|
||||
console.log('[ConsoleView] Handling power long press')
|
||||
try {
|
||||
await atxApi.power('long')
|
||||
await systemStore.fetchAtxState()
|
||||
|
||||
@@ -930,6 +930,7 @@ async function saveAtxConfig() {
|
||||
driver: atxConfig.value.power.driver,
|
||||
device: atxConfig.value.power.device || undefined,
|
||||
pin: atxConfig.value.power.pin,
|
||||
active_level: atxConfig.value.power.active_level,
|
||||
baud_rate: atxConfig.value.power.baud_rate,
|
||||
},
|
||||
reset: {
|
||||
@@ -937,8 +938,7 @@ async function saveAtxConfig() {
|
||||
device: atxConfig.value.reset.device || undefined,
|
||||
pin: atxConfig.value.reset.pin,
|
||||
active_level: atxConfig.value.reset.active_level,
|
||||
baud_rate: atxConfig.value.reset.baud_rate
|
||||
active_level: atxConfig.value.reset.active_level,
|
||||
baud_rate: atxConfig.value.reset.baud_rate,
|
||||
},
|
||||
led: {
|
||||
enabled: atxConfig.value.led.enabled,
|
||||
|
||||
Reference in New Issue
Block a user