From 91aa97249042ca3a1a06c6f4be5408380d250c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B4=9B=E5=B8=8C=E9=9B=85?= Date: Wed, 8 May 2024 17:51:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=89=E6=8B=A9=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/mqtt/index.vue | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/views/mqtt/index.vue b/src/views/mqtt/index.vue index 7ce8fb2..19957b3 100644 --- a/src/views/mqtt/index.vue +++ b/src/views/mqtt/index.vue @@ -5,8 +5,9 @@ import { delay } from '@/utils/common-util' import type { Ref } from 'vue' import { useMqttStore } from '@/store/mqtt' import type { DataLib, DataLibContent } from '@/views/mqtt/dataLib' -import dataLib from '@/views/mqtt/dataLib' +import dataLib0 from '@/views/mqtt/dataLib' import { ElMessage } from 'element-plus' +import { add } from 'xe-utils' let mqttClient: MqttClient | null = $ref(null) const jobCancel: Ref<(() => void) | null> = ref() as any @@ -19,6 +20,7 @@ const password = $toRef(mqttStore, 'password') const clientId = $toRef(mqttStore, 'clientId') let loading = $ref(false) +const dataLib = reactive(dataLib0) type CarPos = { name: string x: number @@ -48,6 +50,25 @@ const publish = reactive({ }) const active = $ref('CLC_track') +function addData() { + const input = document.createElement('input') + input.accept = 'application/json' + input.type = 'file' + input.onchange = () => { + if (input.files?.[0]) { + const file = input.files[0] + dataLib[file.name.replace('.json', '')] = { + title: '', + async data() { + const text = await file.text() + return JSON.parse(text) + } + } as DataLib + } + } + input.click() +} + function connect() { mqttClient = mqtt.connect(url, { username, @@ -195,6 +216,9 @@ function move(tick: number) { {{ key }} {{ it.title }} +
+ 添加 +