From 515fc2158b43d2b0f4933b405208092ed555ad21 Mon Sep 17 00:00:00 2001 From: Frost-ZX Date: Mon, 20 Jul 2026 00:38:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E2=80=9C=E5=B7=B2?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E4=B8=BB=E9=A2=98=E5=88=97=E8=A1=A8=E2=80=9D?= =?UTF-8?q?=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=AF=B9=E6=95=B0=E6=8D=AE=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=8C=89=E4=B8=BB=E9=A2=98=E5=90=8D=E7=A7=B0=E5=8D=87?= =?UTF-8?q?=E5=BA=8F=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/renderer/src/stores/mqtt.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/renderer/src/stores/mqtt.js b/app/src/renderer/src/stores/mqtt.js index 59bfd2e..1fe391c 100644 --- a/app/src/renderer/src/stores/mqtt.js +++ b/app/src/renderer/src/stores/mqtt.js @@ -108,6 +108,17 @@ const loading = ref(false); */ let cleanupFns = []; +/** + * 对指定服务器的主题列表按主题名称升序排序 + * @param {MqttServer} server - 服务器对象 + * @returns {void} + */ +function sortTopics(server) { + if (server && server.topics) { + server.topics.sort((a, b) => a.topic.localeCompare(b.topic)); + } +} + /** * 设置主进程事件监听器 * 包括状态变化、消息接收、订阅变化等事件 @@ -172,6 +183,7 @@ function setupListeners() { t.subscribed = data.subscribed; if (data.topic && data.topic !== t.topic) { t.topic = data.topic; + sortTopics(srv); } } @@ -252,6 +264,7 @@ export function useMqttStore() { servers.value = data; sortServers(); + servers.value.forEach((srv) => sortTopics(srv)); setupListeners(); } catch (e) { @@ -355,6 +368,7 @@ export function useMqttStore() { let data = await window.api.importServers(serverList); servers.value = data; sortServers(); + servers.value.forEach((srv) => sortTopics(srv)); if (servers.value.length > 0 && !activeServerId.value) { activeServerId.value = servers.value[0].id; } @@ -396,6 +410,7 @@ export function useMqttStore() { let srv = servers.value.find((s) => s.id === serverId); if (srv) { srv.topics.push(result); + sortTopics(srv); } } @@ -417,6 +432,7 @@ export function useMqttStore() { if (srv) { srv.topics = srv.topics.filter((t) => t.topic !== topic); + sortTopics(srv); } }