diff --git a/ui/lib/styles/common.scss b/ui/lib/styles/common.scss index bc76fefa..94cd6aa4 100644 --- a/ui/lib/styles/common.scss +++ b/ui/lib/styles/common.scss @@ -322,6 +322,10 @@ div[flex], .flex { &.normal { align-items: unset; } + + &.end { + align-items: flex-end; + } } .fill { diff --git a/ui/packages/ai/AiCopilot.vue b/ui/packages/ai/AiCopilot.vue index 2c4e0b3a..e704bd67 100644 --- a/ui/packages/ai/AiCopilot.vue +++ b/ui/packages/ai/AiCopilot.vue @@ -16,16 +16,11 @@ export default { loading: false, prompt: "", history: [], - apps: [ - {label: "日常助理", icon: "https://cdn.sinoecare.com/i/2024/07/04/66864da37fc2b.png"}, - {label: "文本助理", icon: "https://cdn.sinoecare.com/i/2024/07/04/66864da1684ad.png"}, - ], + apps: [], filter: "", - conversations: [ - {content: "请对“city不city”一词进行深入分析"}, - {content: "请对“city不city”一词进行深入分析"}, - {content: "请对“city不city”一词进行深入分析"}, - ] + conversations: [], + currentConversation: null, + app: {} } }, computed: { @@ -38,19 +33,38 @@ export default { } } ], - rowBtns: () => [ - {icon: "https://cdn.sinoecare.com/i/2024/07/04/66866edc2910a.png", click: row => 0}, - {icon: "https://cdn.sinoecare.com/i/2024/07/04/66866ed734540.png", click: row => 0}, - {icon: "https://cdn.sinoecare.com/i/2024/07/04/66866eda99e4d.png", click: row => 0}, + rowBtns: v => [ + {icon: "https://cdn.sinoecare.com/i/2024/07/04/66866edc2910a.png", label: "置顶", click: row => 0}, + {icon: "https://cdn.sinoecare.com/i/2024/07/04/66866ed734540.png", label: "编辑", click: row => 0}, + {icon: "https://cdn.sinoecare.com/i/2024/07/04/66866eda99e4d.png", label: "删除", click: row => v.handleDeleteConversation(row.id)}, ] }, components: {ThinkingBar, ChatContent}, methods: { - getHistory(cb) { - this.http.post("/app/appaicopilotinfo/list").then(res => { + getHistory(params) { + this.http.post("/app/appaicopilotinfo/list", null, {params}).then(res => { if (res?.data) { - if (cb) cb(res.data.records) - else this.history = res.data.records + this.history = res.data.records + } + }) + }, + getApps() { + return this.http.post("/app/appaiconfiginfo/list", null, { + params: { + status: 1, size: 999 + } + }).then(res => { + if (res?.data) { + return this.apps = res.data.records + } + }) + }, + getConversations() { + return this.http.post("/app/appaicopilotinfo/listHistory", null, { + params: {content: this.filter} + }).then(res => { + if (res?.data) { + return this.conversations = res.data.records || [] } }) }, @@ -66,7 +80,8 @@ export default { if (++i < content.length) setTimeout(() => concatenateStr(content, i), 50) } this.$debounce(() => { - const message = {appType: "2", userType: 0, content: this.prompt} + const {currentConversation: conversationId, app, prompt: content} = this.$data + const message = {appType: "2", userType: 0, content, conversationId, ...app} this.history.push(message) this.loading = true this.prompt = "" @@ -80,11 +95,45 @@ export default { this.loading = false }) }, 100) + }, + handleDeleteConversation(conversationId) { + this.$confirm("是否要删除该会话历史?").then(() => { + this.http.post("/app/appaicopilotinfo/deleteConversation", null, {params: {conversationId}}).then(res => { + if (res?.code == '0') { + this.$message.success("删除成功!") + this.getConversations() + } + }) + }).catch(() => 0) + }, + handleChangeApp(item) { + const {appId, id: aiConfigId} = item + this.handleChangeConversation({appId, aiConfigId}) + this.history = [{userType: 2, content: `当前应用已切换至【${item.appName}】`}] + }, + handleChangeConversation({conversationId, appId, aiConfigId} = {}) { + this.currentConversation = conversationId + this.app = {appId, aiConfigId} + }, + getIcon(item = {}) { + const icon = item.appIconUrl || "https://cdn.sinoecare.com/i/2024/07/04/66864da1684ad.png" + return { + backgroundImage: `url(${icon})` + } + } + }, + watch: { + currentConversation(v) { + v && this.getHistory({conversationId: v}) } }, created() { - this.getHistory() + Promise.all([this.getApps(), this.getConversations()]).then(() => { + const {appId, id: aiConfigId} = this.apps.at(0) + this.handleChangeConversation(this.conversations.at(0) || {appId, aiConfigId}) + }) } + } @@ -104,14 +153,14 @@ export default {