From 9cdd638b998e85eef3e813cb724c639df719089b Mon Sep 17 00:00:00 2001 From: git_rabbit Date: Thu, 18 Dec 2025 17:09:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor(touchScreen):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=B9=B6=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整代码缩进和格式以提高可读性 - 移除底部版权链接注释 - 简化全屏功能相关代码 - 统一字符串引号风格 --- src/views/touchScreen/main/index.vue | 112 +++++++++++++-------------- 1 file changed, 53 insertions(+), 59 deletions(-) diff --git a/src/views/touchScreen/main/index.vue b/src/views/touchScreen/main/index.vue index fbc2ebe..cd86e1d 100644 --- a/src/views/touchScreen/main/index.vue +++ b/src/views/touchScreen/main/index.vue @@ -17,13 +17,18 @@ - + @@ -34,12 +39,11 @@ - 版权所有:苏州道安自动化技术有限公司 - + --> - @@ -55,7 +59,7 @@ const goBack = () => { } /// =========================== 全屏监听 ========================== // 定义全屏状态 -const isFullScreen = ref(false); +const isFullScreen = ref(false) function doScreen() { if (isFullScreen.value) { exitFullScreen() @@ -64,56 +68,51 @@ function doScreen() { } } - // 检查当前是否为全屏模式 const checkIsFullScreen = () => { - isFullScreen.value = document.fullscreenElement !== null; -}; + isFullScreen.value = document.fullscreenElement !== null +} // 进入全屏 const goFullScreen = () => { - const appEl = document.documentElement; + const appEl = document.documentElement if (appEl) { - appEl.requestFullscreen(); - checkIsFullScreen(); // 更新状态 + appEl.requestFullscreen() + checkIsFullScreen() // 更新状态 } -}; +} // 退出全屏 const exitFullScreen = () => { - document.exitFullscreen() - .catch(() => { - console.error('退出全屏失败'); - }); - checkIsFullScreen(); // 更新状态 -}; + document.exitFullscreen().catch(() => { + console.error('退出全屏失败') + }) + checkIsFullScreen() // 更新状态 +} // 监听全屏状态变化 const fullScreenChangeHandler = () => { - checkIsFullScreen(); -}; + checkIsFullScreen() +} // 在组件挂载时设置事件监听 onMounted(() => { - document.addEventListener('fullscreenchange', fullScreenChangeHandler); -}); + document.addEventListener('fullscreenchange', fullScreenChangeHandler) +}) // 在组件卸载时移除事件监听 onUnmounted(() => { - document.removeEventListener('fullscreenchange', fullScreenChangeHandler); -}); + document.removeEventListener('fullscreenchange', fullScreenChangeHandler) +}) /// ================================================================================== - - - // 右侧菜单 const listItems = ref([ { title: '报工', value: '报工', icon: 'mdi-clipboard-file-outline' }, { title: '质量', value: '质量', icon: 'mdi-application-edit' }, { title: '报警', value: '报警', icon: 'mdi-bell-alert' }, { title: '打印', value: '打印', icon: 'mdi-printer' }, - { title: '设置', value: '设置', icon: 'mdi-tools' }, + { title: '设置', value: '设置', icon: 'mdi-tools' } ]) const menuActivated = ref('报工') function selectItem(val) { @@ -128,8 +127,7 @@ const userInfo = ref({ avatar: '', isAdmin: '' }, - roles: [], - + roles: [] }) function getUser() { getUserProfile().then((response) => { @@ -141,47 +139,43 @@ function getUser() { } getUser() -import { onMounted } from "vue"; -import { useDisplay } from "vuetify"; +import { onMounted } from 'vue' +import { useDisplay } from 'vuetify' -const { mobile, name } = useDisplay(); +const { mobile, name } = useDisplay() onMounted(() => { checkSerial() - console.log('是否是移动设备', mobile.value); // false - console.log('桌面大小', name.value); // false -}); - - + console.log('是否是移动设备', mobile.value) // false + console.log('桌面大小', name.value) // false +}) /// ================= 串口通讯 ================= function checkSerial() { - if ("serial" in navigator) { - console.log(true); + if ('serial' in navigator) { + console.log(true) } else { - console.log(false); + console.log(false) } } const port = ref(null) const ports = ref([]) async function doGetPort() { try { - const portInfo = await navigator.serial.requestPort(); - port.value = await portInfo.open({ baudRate: 9600 }); + const portInfo = await navigator.serial.requestPort() + port.value = await portInfo.open({ baudRate: 9600 }) port.value.addEventListener('data', (event) => { - const decoder = new TextDecoder('utf-8'); - const data = decoder.decode(event.data); - console.log('接收到串口数据:', data); - }); - console.log('串口已打开'); + const decoder = new TextDecoder('utf-8') + const data = decoder.decode(event.data) + console.log('接收到串口数据:', data) + }) + console.log('串口已打开') } catch (error) { - console.error('串口请求或打开失败:', error); + console.error('串口请求或打开失败:', error) } } /// ========================================== - - \ No newline at end of file +