66 lines
1.7 KiB
Vue
66 lines
1.7 KiB
Vue
<template>
|
||
<n-card title="卫星时间" class="h-full">
|
||
<n-space vertical justify="space-around" class="h-full">
|
||
<n-descriptions label-placement="left">
|
||
<n-descriptions-item label=" 日 期 ">
|
||
{{ date }}
|
||
</n-descriptions-item>
|
||
</n-descriptions>
|
||
<n-descriptions label-placement="left">
|
||
<n-descriptions-item label=" 时 间 ">
|
||
{{ time }}
|
||
</n-descriptions-item>
|
||
</n-descriptions>
|
||
</n-space>
|
||
</n-card>
|
||
</template>
|
||
|
||
<script lang="ts" setup>
|
||
import { ref } from 'vue'
|
||
import { NCard, NSpace, NDescriptions, NDescriptionsItem, useMessage } from 'naive-ui'
|
||
|
||
import { LineBreakParser } from '@/utils/parser'
|
||
|
||
const date = ref()
|
||
const time = ref()
|
||
|
||
const handle = (data: string) => {
|
||
const startMarkIndex = data.indexOf('@')
|
||
const checksumMarkIndex = data.indexOf('*')
|
||
|
||
if (startMarkIndex < 0 || checksumMarkIndex < startMarkIndex) return
|
||
|
||
// 校验和验证
|
||
const info = data.substring(startMarkIndex + 1, checksumMarkIndex)
|
||
const cs = parseInt(data.substring(checksumMarkIndex + 1))
|
||
if (cs != info.length + 2) return
|
||
|
||
const infoArr = info.split(',')
|
||
if (infoArr.length != 3 || infoArr[0] != 'TIME') return
|
||
|
||
date.value = infoArr[1]
|
||
time.value = infoArr[2]
|
||
}
|
||
|
||
const decoder = new TextDecoder()
|
||
const parser = new LineBreakParser()
|
||
const onSerialPortData = (value: Uint8Array) => {
|
||
const lineArr = parser.parse(decoder.decode(value))
|
||
lineArr.forEach(line => handle(line))
|
||
}
|
||
|
||
window.ipcRenderer.send('COM_ON')
|
||
window.ipcRenderer.receive('COM_LISTENER',onSerialPortData)
|
||
</script>
|
||
|
||
<style scoped lang="less">
|
||
:deep(.n-card-header) {
|
||
font-size: 4vh;
|
||
}
|
||
|
||
:deep(.n-descriptions) {
|
||
font-size: 3vh;
|
||
}
|
||
</style>
|
||
|