【修改】修复返回窗口不是全屏的问题
This commit is contained in:
@@ -412,6 +412,9 @@ const usbAlertVisible = ref(false)
|
|||||||
const fileAlertVisible = ref(false)
|
const fileAlertVisible = ref(false)
|
||||||
const usbAlertMsg = ref('')
|
const usbAlertMsg = ref('')
|
||||||
const fileAlertMsg = ref('')
|
const fileAlertMsg = ref('')
|
||||||
|
// 用于保持全屏的定时器 id(检测到 U 盘 / 文件共享后周期性确保全屏)
|
||||||
|
const usbFullscreenInterval = ref(null)
|
||||||
|
const fileFullscreenInterval = ref(null)
|
||||||
const networkStatus = ref('强') // 网络信号强度
|
const networkStatus = ref('强') // 网络信号强度
|
||||||
const uploadStatus = ref(1) // 上传状态 (0: 上传; 1: 不上传)
|
const uploadStatus = ref(1) // 上传状态 (0: 上传; 1: 不上传)
|
||||||
const isMinView = computed(() => examStore.isMinView)
|
const isMinView = computed(() => examStore.isMinView)
|
||||||
@@ -467,13 +470,24 @@ const connectUsbWs = (server = 'localhost:48082') => {
|
|||||||
if (msg.includes('检测到') && msg.includes('U盘')) {
|
if (msg.includes('检测到') && msg.includes('U盘')) {
|
||||||
usbAlertMsg.value = msg
|
usbAlertMsg.value = msg
|
||||||
usbAlertVisible.value = true
|
usbAlertVisible.value = true
|
||||||
|
// 立即尝试设置全屏,并启动定时器持续确保全屏状态
|
||||||
;(async () => {
|
;(async () => {
|
||||||
try {
|
try {
|
||||||
await WindowManager.setAlwaysOnTop(true)
|
await getCurrentWindow().setFullscreen(true)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('设置全屏/置顶失败:', e)
|
console.warn('设置全屏/置顶失败:', e)
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
if (!usbFullscreenInterval.value) {
|
||||||
|
// 每 3 秒重复确保全屏,直到收到关闭消息
|
||||||
|
usbFullscreenInterval.value = setInterval(() => {
|
||||||
|
getCurrentWindow()
|
||||||
|
.setFullscreen(true)
|
||||||
|
.catch(() => {
|
||||||
|
/* 忽略失败,下一次重试 */
|
||||||
|
})
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 关闭提示的协议(后端返回 COLSEUSB)
|
// 关闭提示的协议(后端返回 COLSEUSB)
|
||||||
if (msg.includes('COLSEUSB') || msg.includes('CLOSEUSB')) {
|
if (msg.includes('COLSEUSB') || msg.includes('CLOSEUSB')) {
|
||||||
@@ -481,7 +495,14 @@ const connectUsbWs = (server = 'localhost:48082') => {
|
|||||||
usbAlertMsg.value = ''
|
usbAlertMsg.value = ''
|
||||||
;(async () => {
|
;(async () => {
|
||||||
try {
|
try {
|
||||||
await WindowManager.setAlwaysOnTop(false)
|
// 停止保持全屏的定时器
|
||||||
|
if (usbFullscreenInterval.value) {
|
||||||
|
clearInterval(usbFullscreenInterval.value)
|
||||||
|
usbFullscreenInterval.value = null
|
||||||
|
}
|
||||||
|
if (examStore.isAnswerView) {
|
||||||
|
await getCurrentWindow().setFullscreen(false)
|
||||||
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
@@ -507,20 +528,37 @@ const connectFileWs = (server = 'localhost:48082') => {
|
|||||||
if (msg.includes('检测到') && msg.includes('文件共享')) {
|
if (msg.includes('检测到') && msg.includes('文件共享')) {
|
||||||
fileAlertMsg.value = msg
|
fileAlertMsg.value = msg
|
||||||
fileAlertVisible.value = true
|
fileAlertVisible.value = true
|
||||||
|
// 立即尝试设置全屏,并启动定时器持续确保全屏状态
|
||||||
;(async () => {
|
;(async () => {
|
||||||
try {
|
try {
|
||||||
await WindowManager.setAlwaysOnTop(true)
|
await getCurrentWindow().setFullscreen(true)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('设置全屏/置顶失败:', e)
|
console.warn('设置全屏/置顶失败:', e)
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
if (!fileFullscreenInterval.value) {
|
||||||
|
fileFullscreenInterval.value = setInterval(() => {
|
||||||
|
getCurrentWindow()
|
||||||
|
.setFullscreen(true)
|
||||||
|
.catch(() => {
|
||||||
|
/* 忽略失败,下一次重试 */
|
||||||
|
})
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (msg.includes('COLSEFILE') || msg.includes('CLOSEFILE')) {
|
if (msg.includes('COLSEFILE') || msg.includes('CLOSEFILE')) {
|
||||||
fileAlertVisible.value = false
|
fileAlertVisible.value = false
|
||||||
fileAlertMsg.value = ''
|
fileAlertMsg.value = ''
|
||||||
;(async () => {
|
;(async () => {
|
||||||
try {
|
try {
|
||||||
await WindowManager.setAlwaysOnTop(false)
|
// 停止保持全屏的定时器
|
||||||
|
if (fileFullscreenInterval.value) {
|
||||||
|
clearInterval(fileFullscreenInterval.value)
|
||||||
|
fileFullscreenInterval.value = null
|
||||||
|
}
|
||||||
|
if (examStore.isAnswerView) {
|
||||||
|
await getCurrentWindow().setFullscreen(false)
|
||||||
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
@@ -1768,7 +1806,7 @@ const openQuestionFile = async () => {
|
|||||||
// 检测无关环境
|
// 检测无关环境
|
||||||
try {
|
try {
|
||||||
const whitelist = await AppCloseWhitelistApi()
|
const whitelist = await AppCloseWhitelistApi()
|
||||||
AppAllApi().then(({ data: { data } }) => {
|
AppAllApi().then(async ({ data: { data } }) => {
|
||||||
// 将data过滤掉checkCloseWhitelist中的值
|
// 将data过滤掉checkCloseWhitelist中的值
|
||||||
const newData = JSON.parse(data)
|
const newData = JSON.parse(data)
|
||||||
|
|
||||||
@@ -2128,7 +2166,7 @@ const checkCloseWhitelist = ref([])
|
|||||||
const handleBackView = async () => {
|
const handleBackView = async () => {
|
||||||
try {
|
try {
|
||||||
const whitelist = await AppCloseWhitelistApi()
|
const whitelist = await AppCloseWhitelistApi()
|
||||||
AppAllApi().then(({ data: { data } }) => {
|
AppAllApi().then(async ({ data: { data } }) => {
|
||||||
// 将data过滤掉checkCloseWhitelist中的值
|
// 将data过滤掉checkCloseWhitelist中的值
|
||||||
const newData = JSON.parse(data)
|
const newData = JSON.parse(data)
|
||||||
|
|
||||||
@@ -2160,11 +2198,35 @@ const handleBackView = async () => {
|
|||||||
openDialog() // 打开对话框
|
openDialog() // 打开对话框
|
||||||
} else {
|
} else {
|
||||||
// 在这里执行确定按钮的逻辑
|
// 在这里执行确定按钮的逻辑
|
||||||
examStore.setIsAnswerView(false) // 设置为非答题模式
|
// 先清理可能存在的保持全屏定时器,避免竞态(例如刚收到 COLSEUSB 后遗留)
|
||||||
// 当前窗口全屏
|
try {
|
||||||
getCurrentWindow().setSize(new LogicalSize(1280, 720))
|
if (usbFullscreenInterval.value) {
|
||||||
getCurrentWindow().setFullscreen(!examStore.isAnswerView)
|
clearInterval(usbFullscreenInterval.value)
|
||||||
WindowManager.setAlwaysOnTop(false) // 设置窗口在最上层
|
usbFullscreenInterval.value = null
|
||||||
|
}
|
||||||
|
if (fileFullscreenInterval.value) {
|
||||||
|
clearInterval(fileFullscreenInterval.value)
|
||||||
|
fileFullscreenInterval.value = null
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('清理保持全屏定时器失败:', e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置为非答题模式并确保窗口为全屏
|
||||||
|
examStore.setIsAnswerView(false)
|
||||||
|
// 先设置窗口大小再进入全屏,使用 await 保证顺序
|
||||||
|
await getCurrentWindow().setSize(new LogicalSize(1280, 720))
|
||||||
|
try {
|
||||||
|
await getCurrentWindow().setFullscreen(true)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('设置全屏失败 in handleBackView:', e)
|
||||||
|
}
|
||||||
|
// 确保取消置顶(若有)
|
||||||
|
try {
|
||||||
|
await WindowManager.setAlwaysOnTop(false)
|
||||||
|
} catch (e) {
|
||||||
|
// 忽略 WindowManager 的错误
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -2566,6 +2628,20 @@ onUnmounted(() => {
|
|||||||
console.warn('关闭检测 WS 时出错:', e)
|
console.warn('关闭检测 WS 时出错:', e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清理保持全屏的定时器(如果存在)
|
||||||
|
try {
|
||||||
|
if (usbFullscreenInterval.value) {
|
||||||
|
clearInterval(usbFullscreenInterval.value)
|
||||||
|
usbFullscreenInterval.value = null
|
||||||
|
}
|
||||||
|
if (fileFullscreenInterval.value) {
|
||||||
|
clearInterval(fileFullscreenInterval.value)
|
||||||
|
fileFullscreenInterval.value = null
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('清理全屏定时器时出错:', e)
|
||||||
|
}
|
||||||
|
|
||||||
// 恢复安全模式默认(取消强制全屏、取消截屏拦截)
|
// 恢复安全模式默认(取消强制全屏、取消截屏拦截)
|
||||||
try {
|
try {
|
||||||
keyboardDisabler.updateConfig({ enableSecurityMode: false })
|
keyboardDisabler.updateConfig({ enableSecurityMode: false })
|
||||||
|
|||||||
Reference in New Issue
Block a user