From 1b8a4677f362d234d834120deac4880d7ae89a50 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 12 三月 2026 17:03:59 +0800
Subject: [PATCH] #
---
src/main/webapp/views/ai/diagnosis.html | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/src/main/webapp/views/ai/diagnosis.html b/src/main/webapp/views/ai/diagnosis.html
index c613791..d8ed943 100644
--- a/src/main/webapp/views/ai/diagnosis.html
+++ b/src/main/webapp/views/ai/diagnosis.html
@@ -747,6 +747,38 @@
}
},
methods: {
+ stateHost: function() {
+ try {
+ if (window.top && window.top !== window) {
+ return window.top;
+ }
+ } catch (e) {}
+ return window;
+ },
+ getAssistantState: function() {
+ var host = this.stateHost();
+ if (!host.__WCS_AI_ASSISTANT_STATE__) {
+ host.__WCS_AI_ASSISTANT_STATE__ = {};
+ }
+ return host.__WCS_AI_ASSISTANT_STATE__;
+ },
+ restoreAssistantState: function() {
+ var state = this.getAssistantState();
+ return {
+ chatId: state.currentChatId || '',
+ resetting: state.resetting === true
+ };
+ },
+ persistAssistantState: function() {
+ var state = this.getAssistantState();
+ state.currentChatId = this.currentChatId || '';
+ state.resetting = this.resetting === true;
+ },
+ clearAssistantState: function() {
+ var state = this.getAssistantState();
+ state.currentChatId = '';
+ state.resetting = false;
+ },
authHeaders: function() {
var token = localStorage.getItem('token');
return token ? { token: token } : {};
@@ -850,6 +882,8 @@
if (!chatId || this.streaming) return;
this.currentChatId = chatId;
this.runTokenUsage = null;
+ this.resetting = false;
+ this.persistAssistantState();
this.switchChat();
},
switchChat: function() {
@@ -883,6 +917,7 @@
self.messages = msgs;
self.pendingText = '';
self.resetting = false;
+ self.persistAssistantState();
self.$nextTick(function() { self.scrollToBottom(true); });
})
.catch(function() {
@@ -896,6 +931,7 @@
this.resetting = true;
this.runTokenUsage = null;
this.clear();
+ this.persistAssistantState();
},
deleteChat: function() {
var self = this;
@@ -907,6 +943,7 @@
.then(function(r) { return r.json(); })
.then(function(ok) {
if (ok === true) {
+ self.clearAssistantState();
self.currentChatId = '';
self.clear();
self.loadChats(false);
@@ -966,6 +1003,7 @@
var url = baseUrl + '/ai/diagnose/askStream?prompt=' + encodeURIComponent(message);
if (this.currentChatId) url += '&chatId=' + encodeURIComponent(this.currentChatId);
if (this.resetting) url += '&reset=true';
+ this.persistAssistantState();
this.source = new EventSource(url);
var self = this;
@@ -993,6 +1031,7 @@
};
this.userInput = '';
this.resetting = false;
+ this.persistAssistantState();
},
start: function() {
if (this.streaming) return;
@@ -1087,9 +1126,23 @@
}
},
mounted: function() {
- this.loadChats(false);
+ var restored = this.restoreAssistantState();
+ if (restored.chatId) {
+ this.currentChatId = restored.chatId;
+ this.resetting = restored.resetting;
+ if (this.resetting) {
+ this.clear();
+ } else {
+ this.switchChat();
+ }
+ this.loadChats(true);
+ return;
+ }
+ this.newChat();
+ this.loadChats(true);
},
beforeDestroy: function() {
+ this.persistAssistantState();
this.stop(true);
}
});
--
Gitblit v1.9.1