2023-10-13 16:43:53 +08:00
|
|
|
<template>
|
|
|
|
|
<!-- TODO: 使用form grid替换 -->
|
|
|
|
|
<n-descriptions :column="1">
|
2023-11-29 16:08:12 +08:00
|
|
|
<n-descriptions-item label="串口号">
|
|
|
|
|
<n-select v-model:value="serialPortOptions.path" :options="PATH_OPTIONS" />
|
2023-10-13 16:43:53 +08:00
|
|
|
</n-descriptions-item>
|
|
|
|
|
<n-descriptions-item label="波特率">
|
2023-11-29 16:08:12 +08:00
|
|
|
<n-select v-model:value="serialPortOptions.baudRate" :options="BAUDRATE_OPTIONS" />
|
2023-10-13 16:43:53 +08:00
|
|
|
</n-descriptions-item>
|
|
|
|
|
<n-descriptions-item label="数据位">
|
2023-11-29 16:08:12 +08:00
|
|
|
<n-select v-model:value="serialPortOptions.dataBits" :options="DATA_BITS_OPTIONS" />
|
2023-10-13 16:43:53 +08:00
|
|
|
</n-descriptions-item>
|
|
|
|
|
<n-descriptions-item label="停止位">
|
2023-11-29 16:08:12 +08:00
|
|
|
<n-select v-model:value="serialPortOptions.stopBits" :options="STOPBITS_OPTIONS" />
|
2023-10-13 16:43:53 +08:00
|
|
|
</n-descriptions-item>
|
|
|
|
|
<n-descriptions-item label="奇偶校验">
|
2023-11-29 16:08:12 +08:00
|
|
|
<n-select v-model:value="serialPortOptions.parity" :options="PARITY_OPTIONS" />
|
2023-10-13 16:43:53 +08:00
|
|
|
</n-descriptions-item>
|
|
|
|
|
</n-descriptions>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2023-11-29 16:08:12 +08:00
|
|
|
import { ref, onMounted, watch } from 'vue'
|
2024-04-16 10:01:04 +08:00
|
|
|
import { NDescriptions, NDescriptionsItem, NSelect } from 'naive-ui'
|
2023-10-13 16:43:53 +08:00
|
|
|
import { BAUDRATE_OPTIONS, DATA_BITS_OPTIONS, STOPBITS_OPTIONS, PARITY_OPTIONS } from './data'
|
|
|
|
|
|
2023-11-29 16:08:12 +08:00
|
|
|
const PATH_OPTIONS = ref<any[]>([])
|
2023-10-13 16:43:53 +08:00
|
|
|
|
2023-11-29 16:08:12 +08:00
|
|
|
const showfirst = ref(false)
|
2023-10-13 16:43:53 +08:00
|
|
|
|
|
|
|
|
const serialPortOptions = ref({
|
2023-11-29 16:08:12 +08:00
|
|
|
path : PATH_OPTIONS.value[0],
|
2023-10-13 16:43:53 +08:00
|
|
|
baudRate: BAUDRATE_OPTIONS[BAUDRATE_OPTIONS.length - 1].value,
|
|
|
|
|
dataBits: DATA_BITS_OPTIONS[0].value,
|
|
|
|
|
stopBits: STOPBITS_OPTIONS[0].value,
|
|
|
|
|
parity : PARITY_OPTIONS[0].value,
|
|
|
|
|
})
|
|
|
|
|
|
2023-11-29 16:08:12 +08:00
|
|
|
const beforOption = (value) => {
|
|
|
|
|
if(value.comoptions !== undefined && value.comports !== undefined){
|
|
|
|
|
console.log(value)
|
|
|
|
|
serialPortOptions.value.path = value.comoptions.path
|
|
|
|
|
serialPortOptions.value.baudRate = value.comoptions.baudRate
|
|
|
|
|
serialPortOptions.value.dataBits = value.comoptions.dataBits
|
|
|
|
|
serialPortOptions.value.stopBits = value.comoptions.stopBits
|
|
|
|
|
serialPortOptions.value.parity = value.comoptions.parity
|
|
|
|
|
PATH_OPTIONS.value = []
|
|
|
|
|
value.comports.forEach(element => {
|
|
|
|
|
PATH_OPTIONS.value.push({ label: element.path+`${element.msg==undefined?'':'('+element.msg+')'}`, value: element.path })
|
|
|
|
|
})
|
2023-10-13 16:43:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 16:08:12 +08:00
|
|
|
onMounted(() => {
|
|
|
|
|
window.ipcRenderer.send('OPTION_READY')
|
|
|
|
|
window.ipcRenderer.receive('OPEN_OPTION',beforOption)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
watch(serialPortOptions.value, () => {
|
|
|
|
|
if(showfirst.value){
|
|
|
|
|
let setcom = {
|
|
|
|
|
path:serialPortOptions.value.path,
|
|
|
|
|
baudRate:serialPortOptions.value.baudRate,
|
|
|
|
|
dataBits:serialPortOptions.value.dataBits,
|
|
|
|
|
stopBits:serialPortOptions.value.stopBits,
|
|
|
|
|
parity:serialPortOptions.value.parity
|
|
|
|
|
}
|
|
|
|
|
console.log(setcom)
|
|
|
|
|
window.ipcRenderer.send('SET_OPTION',setcom)
|
2023-10-13 16:43:53 +08:00
|
|
|
}
|
2023-11-29 16:08:12 +08:00
|
|
|
showfirst.value = true
|
|
|
|
|
})
|
2023-10-13 16:43:53 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="less">
|
|
|
|
|
.n-button {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
</style>
|