diff --git a/src/components/common/FTKeyboard/index.vue b/src/components/common/FTKeyboard/index.vue index 6a8d90c..8d60f01 100644 --- a/src/components/common/FTKeyboard/index.vue +++ b/src/components/common/FTKeyboard/index.vue @@ -3,7 +3,8 @@ import 'simple-keyboard/build/css/index.css' import Keyboard from 'simple-keyboard' import layout from 'simple-keyboard-layouts/build/layouts/chinese.js' -import { onUnmounted, ref } from 'vue' +import { useDeviceStore } from 'stores/deviceStore' +import { computed, onUnmounted, ref } from 'vue' defineOptions({ inheritAttrs: false, @@ -25,19 +26,24 @@ const props = defineProps({ }, }) const emits = defineEmits(['onChange', 'enter', 'close', 'focus']) -const model = defineModel() +const deviceStore = useDeviceStore() +const deviceType = computed(() => { + return __DEVICE_TYPE__ +}) + +const model = defineModel() const keyboard = ref(null) const visible = ref(false) const inputRef = ref() const popoverRef = ref() const entering = ref(false) -const width = ref(1000) +const width = ref(800) if (props.layoutName === 'number') width.value = 300 const displayDefault = ref({ '{bksp}': 'backspace', '{lock}': 'caps', - '{enter}': 'enter', + '{enter}': '回车', '{tab}': 'tab', '{shift}': 'shift', '{change}': 'en', @@ -56,11 +62,25 @@ const open = () => { visible.value = true } -const focusInput = () => { +const focusInput = (e: any) => { + const rect = e.target.getBoundingClientRect() + console.log('元素位置信息:', { + top: rect.top + window.scrollY, + left: rect.left + window.scrollX, + width: rect.width, + height: rect.height, + }) + if (rect.top + window.scrollY > 800) { + placement.value = 'top' + } + else { + placement.value = 'bottom' + } + console.log(rect) if (visible.value) return emits('focus') - if (props.isOpen) + if (deviceType.value !== deviceStore.deviceTypeMap.LargeSpaceDM_B) visible.value = true } @@ -80,7 +100,7 @@ const blurInput = () => { else { entering.value = false } - }, 300) + }, 100) } const afterEnter = () => { @@ -174,7 +194,7 @@ const handleChange = () => { }) } else { - displayDefault.value['{change}'] = 'cn' + displayDefault.value['{change}'] = '中' keyboard.value.setOptions({ layoutName: 'default', layoutCandidates: (layout as any).layoutCandidates, @@ -192,7 +212,7 @@ const handleEnter = () => { const handleClose = () => { if (props.layoutName === 'number') { // 处理精度 - model.value = model.value?.replace(new RegExp(`(\\d+)\\.(\\d{${props.precision}}).*$`), '$1.$2').replace(/\.$/, '') + // model.value = model.value?.replace(new RegExp(`(\\d+)\\.(\\d{${props.precision}}).*$`), '$1.$2').replace(/\.$/, '') } popoverRef.value.hide() emits('close') @@ -226,6 +246,8 @@ const close = () => { handleClose() } +const placement = ref('bottom') + onUnmounted(() => { // 某些情况下未触发动画关闭时销毁事件。此处销毁做后备处理 document.removeEventListener('click', handlePopClose) @@ -253,10 +275,10 @@ defineExpose({ inputRef, visible, open, close }) :visible="visible" :virtual-ref="inputRef" virtual-triggering - placement="bottom" :width="width" :show-arrow="false" :hide-after="0" + :placement="placement" popper-style="padding: 0px;color:#000" :persistent="false" popper-class="keyboard-popper" diff --git a/src/stores/systemStore.ts b/src/stores/systemStore.ts index 8ff973d..4c9d0fd 100644 --- a/src/stores/systemStore.ts +++ b/src/stores/systemStore.ts @@ -5,162 +5,166 @@ import { ref } from 'vue' import { sendCmd } from '@/apis/system' -export const useSystemStore = defineStore('system', () => { - const websocketConnected = ref(true) - const systemUser = ref(null) - const systemLogList = ref([]) - const insertLog = (log: System.SystemLog) => { - systemLogList.value.unshift(log) - systemLogList.value = systemLogList.value.slice(0, 200) - } - const uuids: Set = new Set() - const insertLogs = (appEvents: System.appEvent[]) => { - appEvents.forEach((item) => { - if (uuids.has(item.uuid)) { - return - } - if (uuids.size > 500) { - uuids.clear() - } - uuids.add(item.uuid) - if (item.type === 'AppCheckPointCheckFailEvent' && item.errCheckPoints) { - // 传感器检测失败弹窗事件 - item.errCheckPoints.forEach((errCheckPoint) => { +export const useSystemStore = defineStore( + 'system', + () => { + const websocketConnected = ref(true) + const systemUser = ref(null) + const systemLogList = ref([]) + const insertLog = (log: System.SystemLog) => { + systemLogList.value.unshift(log) + systemLogList.value = systemLogList.value.slice(0, 200) + } + const uuids: Set = new Set() + const insertLogs = (appEvents: System.appEvent[]) => { + appEvents.forEach((item) => { + if (uuids.has(item.uuid)) { + return + } + if (uuids.size > 500) { + uuids.clear() + } + uuids.add(item.uuid) + if (item.type === 'AppCheckPointCheckFailEvent' && item.errCheckPoints) { + // 传感器检测失败弹窗事件 + item.errCheckPoints.forEach((errCheckPoint) => { + const log: System.SystemLog = { + name: `${errCheckPoint.ecodeInfo}(${errCheckPoint.ecode})`, + status: 'check', + time: formatDateTime('YYYY-MM-DD HH:mm:ss', Date.now()), + uuid: item.uuid, + } + insertLog(log) + }) + } + if (item.type === 'AppWarningPromoptEvent') { + // 报警事件 const log: System.SystemLog = { - name: `${errCheckPoint.ecodeInfo}(${errCheckPoint.ecode})`, - status: 'check', + name: item.description || '', + status: 'warn', time: formatDateTime('YYYY-MM-DD HH:mm:ss', Date.now()), uuid: item.uuid, } + ElMessage.warning(item.description) insertLog(log) - }) - } - if (item.type === 'AppWarningPromoptEvent') { - // 报警事件 - const log: System.SystemLog = { - name: item.description || '', - status: 'warn', - time: formatDateTime('YYYY-MM-DD HH:mm:ss', Date.now()), - uuid: item.uuid, } - ElMessage.warning(item.description) - insertLog(log) - } - if (item.type === 'AppPromoptEvent') { - // 普通弹窗事件 - const log: System.SystemLog = { - name: item.message || '', - status: 'info', - time: formatDateTime('YYYY-MM-DD HH:mm:ss', Date.now()), - uuid: item.uuid, + if (item.type === 'AppPromoptEvent') { + // 普通弹窗事件 + const log: System.SystemLog = { + name: item.message || '', + status: 'info', + time: formatDateTime('YYYY-MM-DD HH:mm:ss', Date.now()), + uuid: item.uuid, + } + insertLog(log) } - insertLog(log) - } + }) + } + const loginForm = ref({ + name: import.meta.env.FT_NODE_ENV !== 'prod' ? 'admin' : '', + pwd: import.meta.env.FT_NODE_ENV !== 'prod' ? '9973' : '', }) - } - const loginForm = ref({ - name: import.meta.env.FT_NODE_ENV !== 'prod' ? 'admin' : '', - pwd: import.meta.env.FT_NODE_ENV !== 'prod' ? '9973' : '', - }) - const languages = [ - { - name: '中文', - value: 'zh-cn', - }, - // { - // name: 'English', - // value: 'en', - // }, - ] + const languages = [ + { + name: '中文', + value: 'zh-cn', + }, + // { + // name: 'English', + // value: 'en', + // }, + ] - const menuExpand = true - const isDebug = import.meta.env.FT_NODE_ENV !== 'prod' - const streamVisible = false - const systemList = ref([]) - const loading = ref(false) - const systemTime = ref(Date.now()) + const menuExpand = true + const isDebug = import.meta.env.FT_NODE_ENV !== 'prod' + const streamVisible = false + const systemList = ref([]) + const loading = ref(false) + const systemTime = ref(Date.now()) - const updateLoading = (loadVal: boolean) => { - loading.value = loadVal - // setTimeout(() => { - // loading.value = false - // }, 1500) - } + const updateLoading = (loadVal: boolean) => { + loading.value = loadVal + // setTimeout(() => { + // loading.value = false + // }, 1500) + } - const updateConnected = (isConnected: boolean) => { - websocketConnected.value = isConnected - } + const updateConnected = (isConnected: boolean) => { + websocketConnected.value = isConnected + } - const updateUser = (data: any) => { - systemUser.value = data - } + const updateUser = (data: any) => { + systemUser.value = data + } - /** - * @function subscribeDisinfectEvent - * @desc 订阅消毒状态变更事件 - */ - // const subscribeDisinfectEvent = async () => { - // // 发起订阅 - // const subParams = { - // className: 'DisinfectionCtrlServiceExt', - // fnName: 'startStateReport', - // } - // syncSendCmd(subParams) - // } + /** + * @function subscribeDisinfectEvent + * @desc 订阅消毒状态变更事件 + */ + // const subscribeDisinfectEvent = async () => { + // // 发起订阅 + // const subParams = { + // className: 'DisinfectionCtrlServiceExt', + // fnName: 'startStateReport', + // } + // syncSendCmd(subParams) + // } - /** - * @function subscribeAddLiquidEvent - * @desc 加液状态变更事件 - */ - // const subscribeAddLiquidEvent = async () => { - // // 发起订阅 - // const subParams = { - // className: 'AddLiquidService', - // fnName: 'startStateReport', - // } - // syncSendCmd(subParams) - // } + /** + * @function subscribeAddLiquidEvent + * @desc 加液状态变更事件 + */ + // const subscribeAddLiquidEvent = async () => { + // // 发起订阅 + // const subParams = { + // className: 'AddLiquidService', + // fnName: 'startStateReport', + // } + // syncSendCmd(subParams) + // } - /** - * @function subscribeDrainLiquidEvent - * @desc 排液状态变更事件 - */ - // const subscribeDrainLiquidEvent = async () => { - // // 发起订阅 - // const subParams = { - // className: 'DrainLiquidService', - // fnName: 'startStateReport', - // } - // syncSendCmd(subParams) - // } + /** + * @function subscribeDrainLiquidEvent + * @desc 排液状态变更事件 + */ + // const subscribeDrainLiquidEvent = async () => { + // // 发起订阅 + // const subParams = { + // className: 'DrainLiquidService', + // fnName: 'startStateReport', + // } + // syncSendCmd(subParams) + // } - const getSystemTime = async () => { - const timeParams = { - className: 'OsMgrService', - fnName: 'getTime', + const getSystemTime = async () => { + const timeParams = { + className: 'OsMgrService', + fnName: 'getTime', + } + const res = await sendCmd(timeParams) + systemTime.value = res.time } - const res = await sendCmd(timeParams) - systemTime.value = res.time - } - return { - systemUser, - loginForm, - languages, - menuExpand, - isDebug, - streamVisible, - systemList, - loading, - websocketConnected, - systemTime, - systemLogList, - updateUser, - updateLoading, - updateConnected, - getSystemTime, - insertLog, - insertLogs, - } -}) + return { + systemUser, + loginForm, + languages, + menuExpand, + isDebug, + streamVisible, + systemList, + loading, + websocketConnected, + systemTime, + systemLogList, + updateUser, + updateLoading, + updateConnected, + getSystemTime, + insertLog, + insertLogs, + } + }, + { persist: true }, +)