From 53fa1addcd22557f6541092a151a3064779d3f93 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期五, 12 十二月 2025 13:28:42 +0800
Subject: [PATCH] #AI

---
 src/main/webapp/views/ai/diagnosis.html |   62 ++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/src/main/webapp/views/ai/diagnosis.html b/src/main/webapp/views/ai/diagnosis.html
index e087e17..612b817 100644
--- a/src/main/webapp/views/ai/diagnosis.html
+++ b/src/main/webapp/views/ai/diagnosis.html
@@ -9,7 +9,7 @@
     body { background: #f5f7fa; }
     .container { max-width: 1100px; margin: 24px auto; }
     .actions { display: flex; gap: 12px; align-items: center; }
-    .output { height: 65vh; }
+    .output { height: 60vh; }
     .markdown-body { font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
     .markdown-body p { margin: 4px 0; }
     .markdown-body ul, .markdown-body ol { margin: 4px 0 4px 16px; padding: 0; }
@@ -37,11 +37,16 @@
         <span>WCS AI 鍔╂墜</span>
       </div>
 
-      <div class="actions">
+      <div class="actions" style="flex-wrap: wrap;">
         <el-button type="primary" :loading="loading" :disabled="streaming" @click="start">涓�閿瘖鏂郴缁�</el-button>
         <el-button type="warning" :disabled="!streaming" @click="stop">鍋滄</el-button>
-        <el-button @click="clear">娓呯┖</el-button>
-        <span class="status">{{ statusText }}</span>
+        <el-button @click="clear">娓呯┖褰撳墠鑱婂ぉ</el-button>
+        <span class="status" style="margin-right: 12px;">{{ statusText }}</span>
+        <el-select v-model="currentChatId" placeholder="閫夋嫨浼氳瘽" style="min-width:240px;" @change="switchChat" :disabled="streaming">
+          <el-option v-for="c in chats" :key="c.chatId" :label="(c.title||('浼氳瘽 '+c.chatId)) + '锛�'+(c.size||0)+'锛�'" :value="c.chatId" />
+        </el-select>
+        <el-button type="success" plain icon="el-icon-plus" @click="newChat" :disabled="streaming">鏂颁細璇�</el-button>
+        <el-button type="danger" plain icon="el-icon-delete" @click="deleteChat" :disabled="!currentChatId || streaming">鍒犻櫎浼氳瘽</el-button>
       </div>
 
       <el-divider></el-divider>
@@ -102,7 +107,10 @@
           renderIntervalMs: 120,
           stepChars: 6,
           userInput: '',
-          autoScrollThreshold: 80
+          autoScrollThreshold: 80,
+          chats: [],
+          currentChatId: '',
+          resetting: false
         };
       },
       computed: {
@@ -117,6 +125,42 @@
         }
       },
       methods: {
+        loadChats: function() {
+          var self = this;
+          fetch(baseUrl + '/ai/diagnose/chats', { headers: { 'token': localStorage.getItem('token') } })
+            .then(function(r){ return r.json(); })
+            .then(function(arr){ if (Array.isArray(arr)) { self.chats = arr; } });
+        },
+        switchChat: function() {
+          var self = this;
+          if (!self.currentChatId) { self.clear(); return; }
+          fetch(baseUrl + '/ai/diagnose/chats/' + encodeURIComponent(self.currentChatId) + '/history', { headers: { 'token': localStorage.getItem('token') } })
+            .then(function(r){ return r.json(); })
+            .then(function(arr){
+              if (!Array.isArray(arr)) return;
+              var msgs = [];
+              for (var i=0;i<arr.length;i++) {
+                var m = arr[i];
+                if (m.role === 'assistant') msgs.push({ role: 'assistant', md: m.content || '', html: DOMPurify.sanitize(marked.parse((m.content||'').replace(/\\n/g,'\n'))), ts: self.nowStr() });
+                else msgs.push({ role: 'user', text: m.content || '', ts: self.nowStr() });
+              }
+              self.messages = msgs;
+              self.$nextTick(function(){ self.scrollToBottom(true); });
+            });
+        },
+        newChat: function() {
+          var id = Date.now() + '_' + Math.random().toString(36).substr(2,8);
+          this.currentChatId = id;
+          this.resetting = true;
+          this.clear();
+        },
+        deleteChat: function() {
+          var self = this;
+          if (!self.currentChatId) return;
+          fetch(baseUrl + '/ai/diagnose/chats/' + encodeURIComponent(self.currentChatId), { method: 'DELETE', headers: { 'token': localStorage.getItem('token') } })
+            .then(function(r){ return r.json(); })
+            .then(function(ok){ if (ok === true) { self.currentChatId = ''; self.clear(); self.loadChats(); self.newChat(); } });
+        },
         shouldAutoScroll: function() {
           var el = this.$refs.chat;
           if (!el) return false;
@@ -150,6 +194,8 @@
           this.messages.push({ role: 'assistant', md: '', html: '', ts: this.nowStr() });
           this.scrollToBottom(true);
           var url = baseUrl + '/ai/diagnose/askStream?prompt=' + encodeURIComponent(msg);
+          if (this.currentChatId) url += '&chatId=' + encodeURIComponent(this.currentChatId);
+          if (this.resetting) url += '&reset=true';
           this.source = new EventSource(url);
           var self = this;
           this.source.onopen = function() {
@@ -169,6 +215,7 @@
             self.stop();
           };
           this.userInput = '';
+          this.resetting = false;
         },
         start: function() {
           if (this.streaming) return;
@@ -246,12 +293,17 @@
             last.html = DOMPurify.sanitize(marked.parse(renderSource));
           }
           this.$nextTick(function() { this.scrollToBottom(true); }.bind(this));
+          this.loadChats();
         },
         clear: function() {
           this.messages = [];
           this.pendingText = '';
         }
       }
+      ,mounted: function() {
+        this.loadChats();
+        this.newChat();
+      }
     });
   </script>
 </body>

--
Gitblit v1.9.1