fix: 解决添加主题后进行连接,或已连接时添加主题,订阅主题列表的内容会出现错乱的问题

This commit is contained in:
2026-07-19 20:03:06 +08:00
parent 21683cb790
commit 089bfaacf7
2 changed files with 6 additions and 5 deletions

View File

@@ -450,15 +450,16 @@ class MqttManager {
addTopic(serverId, topic, qos = 1) {
let server = this.servers.get(serverId);
if (!server) {
return false;
return null;
}
if (server.topics.find((t) => t.topic === topic)) {
return false;
return null;
}
let topicId = 'topic_' + Date.now() + '_' + Math.random().toString(36).slice(2, 6);
server.topics.push({ id: topicId, topic, qos, subscribed: false });
let newTopic = { id: topicId, topic, qos, subscribed: false };
server.topics.push(newTopic);
this.saveData();
@@ -467,7 +468,7 @@ class MqttManager {
this._doSubscribe(serverId, topic, { qos });
}
return true;
return newTopic;
}

View File

@@ -191,7 +191,7 @@ export function useMqttStore() {
if (result) {
let srv = servers.value.find((s) => s.id === serverId);
if (srv) {
srv.topics.push({ topic, qos, subscribed: false });
srv.topics.push(result);
}
}