update conversation navigator
This commit is contained in:
1 parent
1b5efc6cb5
commit
d91f5ed5cb
6 files changed
+159
-7
No files matched your search
@@ -2,11 +2,13 @@
|
|||||||
<div class="navigator">
|
<div class="navigator">
|
||||||
<div class="conversations">
|
<div class="conversations">
|
||||||
<navigator-item icon="fa-solid fa-plus" :title="$t('common.nav.newChat')" @click="onNewConversation" />
|
<navigator-item icon="fa-solid fa-plus" :title="$t('common.nav.newChat')" @click="onNewConversation" />
|
||||||
<navigator-item
|
<conversation-navigator-item
|
||||||
v-for="(conversation, conversationIndex) in conversations"
|
v-for="(conversation, conversationIndex) in conversations"
|
||||||
:key="conversationIndex"
|
:key="conversationIndex"
|
||||||
icon="fa-regular fa-comment"
|
|
||||||
:title="conversation.title"
|
:title="conversation.title"
|
||||||
|
icon="fa-regular fa-comment"
|
||||||
|
@update:title="onUpdateTitle(conversation, $event)"
|
||||||
|
@delete="onDeleteConversation(conversation.id)"
|
||||||
@click="onSelectConversation(conversation.id)"
|
@click="onSelectConversation(conversation.id)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -32,11 +34,14 @@
|
|||||||
import { ROUTE_CONVERSATION_DETAIL, ROUTE_CONVERSATION_NEW } from '@/router';
|
import { ROUTE_CONVERSATION_DETAIL, ROUTE_CONVERSATION_NEW } from '@/router';
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import NavigatorItem from './NavigatorItem.vue';
|
import NavigatorItem from './NavigatorItem.vue';
|
||||||
|
import ConversationNavigatorItem from '../conversation/ConversationNavigatorItem.vue';
|
||||||
|
import { IConversation } from '@/operators/conversation/models';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'LeftNavigator',
|
name: 'LeftNavigator',
|
||||||
components: {
|
components: {
|
||||||
NavigatorItem
|
NavigatorItem,
|
||||||
|
ConversationNavigatorItem
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -72,6 +77,14 @@ export default defineComponent({
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
},
|
||||||
|
onUpdateTitle(conversation: IConversation, val: string) {
|
||||||
|
conversation.title = val;
|
||||||
|
this.$store.dispatch('setConversations', this.conversations);
|
||||||
|
},
|
||||||
|
onDeleteConversation(id: string) {
|
||||||
|
const newConversations = this.conversations.filter((i: IConversation) => i.id !== id);
|
||||||
|
this.$store.dispatch('setConversations', newConversations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,117 @@
|
|||||||
|
<template>
|
||||||
|
<div class="navigation-item">
|
||||||
|
<div class="icon">
|
||||||
|
<font-awesome-icon :icon="icon" class="icon-rotate" />
|
||||||
|
</div>
|
||||||
|
<div v-if="!editing && !deleting" class="title">
|
||||||
|
{{ title }}
|
||||||
|
</div>
|
||||||
|
<div v-if="deleting && !editing" class="title">
|
||||||
|
{{ `${$t('conversation.message.confirmDelete')}"${title}"?` }}
|
||||||
|
</div>
|
||||||
|
<div v-if="editing && !deleting" class="title">
|
||||||
|
<el-input v-model="newTitle" @keydown.enter="onConfirm" />
|
||||||
|
</div>
|
||||||
|
<div v-if="!editing && !deleting" class="edit">
|
||||||
|
<font-awesome-icon icon="fa-solid fa-pen-to-square" class="icon-edit" @click="editing = true" />
|
||||||
|
</div>
|
||||||
|
<div v-if="!editing && !deleting" class="delete">
|
||||||
|
<font-awesome-icon icon="fa-solid fa-trash" class="icon-delete" @click="deleting = true" />
|
||||||
|
</div>
|
||||||
|
<div v-if="editing || deleting" class="confirm">
|
||||||
|
<font-awesome-icon icon="fa-solid fa-check" class="icon-confirm" @click="onConfirm" />
|
||||||
|
</div>
|
||||||
|
<div v-if="editing || deleting" class="cancel">
|
||||||
|
<font-awesome-icon icon="fa-solid fa-xmark" class="icon-cancel" @click="onCancel" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||||
|
import { ElInput } from 'element-plus';
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'ConversationNavigatorItem',
|
||||||
|
components: {
|
||||||
|
FontAwesomeIcon,
|
||||||
|
ElInput
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
icon: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['update:title', 'delete'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
deleting: false,
|
||||||
|
editing: false,
|
||||||
|
newTitle: this.title
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onChangeTitle(val: string) {
|
||||||
|
this.newTitle = val;
|
||||||
|
},
|
||||||
|
onConfirm() {
|
||||||
|
if (this.editing) {
|
||||||
|
this.$emit('update:title', this.newTitle);
|
||||||
|
this.editing = false;
|
||||||
|
} else if (this.deleting) {
|
||||||
|
this.$emit('delete');
|
||||||
|
this.deleting = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCancel() {
|
||||||
|
if (this.editing) {
|
||||||
|
this.editing = false;
|
||||||
|
} else if (this.deleting) {
|
||||||
|
this.deleting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.navigation-item {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
cursor: pointer;
|
||||||
|
height: 44px;
|
||||||
|
margin-top: 5px;
|
||||||
|
padding: 0 15px;
|
||||||
|
line-height: 44px;
|
||||||
|
border-radius: 3px;
|
||||||
|
&:hover {
|
||||||
|
background-color: hsla(240, 9%, 59%, 0.1);
|
||||||
|
}
|
||||||
|
.icon {
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
min-width: 30px;
|
||||||
|
}
|
||||||
|
.title {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.edit,
|
||||||
|
.delete,
|
||||||
|
.confirm,
|
||||||
|
.cancel {
|
||||||
|
width: 25px;
|
||||||
|
height: 30px;
|
||||||
|
min-width: 25px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<markdown-renderer :content="content?.value" />
|
<markdown-renderer :content="content?.value" class="content" />
|
||||||
<answering-mark v-if="shouldShowAnsweringMark" />
|
<answering-mark v-if="shouldShowAnsweringMark" />
|
||||||
<el-alert v-if="errorText" :title="errorText" type="error" :closable="false" />
|
<el-alert v-if="errorText" :title="errorText" type="error" :closable="false" />
|
||||||
</template>
|
</template>
|
||||||
@@ -65,3 +65,9 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.content {
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -17,5 +17,6 @@ export default {
|
|||||||
errorBusy: 'Worker正在忙碌中,请稍后重试',
|
errorBusy: 'Worker正在忙碌中,请稍后重试',
|
||||||
errorApiError: '回答失败,请稍后重试',
|
errorApiError: '回答失败,请稍后重试',
|
||||||
errorBadRequest: '请求内容不规范,请重新提问',
|
errorBadRequest: '请求内容不规范,请重新提问',
|
||||||
errorNoConversation: '对话内容不存在或者已经过期,请发起新的会话'
|
errorNoConversation: '对话内容不存在或者已经过期,请发起新的会话',
|
||||||
|
confirmDelete: '确定删除'
|
||||||
};
|
};
|
||||||
@@ -128,6 +128,10 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
scrollDown() {
|
||||||
|
const container = document.querySelector('.main') as HTMLDivElement;
|
||||||
|
container.scrollTop = container.scrollHeight;
|
||||||
|
},
|
||||||
restoreMessages() {
|
restoreMessages() {
|
||||||
if (this.conversationId) {
|
if (this.conversationId) {
|
||||||
const conversations = this.$store.getters.conversations;
|
const conversations = this.$store.getters.conversations;
|
||||||
@@ -209,6 +213,7 @@ export default defineComponent({
|
|||||||
onDraft(content: string) {
|
onDraft(content: string) {
|
||||||
this.input = content;
|
this.input = content;
|
||||||
},
|
},
|
||||||
|
|
||||||
onSend() {
|
onSend() {
|
||||||
if (this.answering) {
|
if (this.answering) {
|
||||||
return;
|
return;
|
||||||
@@ -246,6 +251,9 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
this.answering = true;
|
this.answering = true;
|
||||||
this.input = '';
|
this.input = '';
|
||||||
|
setTimeout(() => {
|
||||||
|
this.scrollDown();
|
||||||
|
}, 100);
|
||||||
chatgptOperator
|
chatgptOperator
|
||||||
.post(
|
.post(
|
||||||
{
|
{
|
||||||
@@ -271,6 +279,7 @@ export default defineComponent({
|
|||||||
const lines = response.split('\r\n').filter((line: string) => !!line);
|
const lines = response.split('\r\n').filter((line: string) => !!line);
|
||||||
const lastLine = lines[lines.length - 1];
|
const lastLine = lines[lines.length - 1];
|
||||||
if (lastLine) {
|
if (lastLine) {
|
||||||
|
this.scrollDown();
|
||||||
const jsonData = JSON.parse(lastLine);
|
const jsonData = JSON.parse(lastLine);
|
||||||
const answer = jsonData.answer;
|
const answer = jsonData.answer;
|
||||||
const conversationId = jsonData.conversation_id;
|
const conversationId = jsonData.conversation_id;
|
||||||
@@ -309,7 +318,9 @@ export default defineComponent({
|
|||||||
} else {
|
} else {
|
||||||
// update one of existing conversations
|
// update one of existing conversations
|
||||||
conversations.forEach((conversation: IConversation) => {
|
conversations.forEach((conversation: IConversation) => {
|
||||||
conversation.messages = this.messages;
|
if (conversation.id === this.conversationId) {
|
||||||
|
conversation.messages = this.messages;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
this.$store.dispatch('setConversations', conversations);
|
this.$store.dispatch('setConversations', conversations);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,14 @@ import {
|
|||||||
faArrowsRotate as faSolidArrowsRotate,
|
faArrowsRotate as faSolidArrowsRotate,
|
||||||
faUpRightFromSquare as faSolidUpRightFromSquare,
|
faUpRightFromSquare as faSolidUpRightFromSquare,
|
||||||
faArrowRightFromBracket as faSolidArrowRightFromBracket,
|
faArrowRightFromBracket as faSolidArrowRightFromBracket,
|
||||||
faTriangleExclamation as faSolidTriangleExclamation
|
faTriangleExclamation as faSolidTriangleExclamation,
|
||||||
|
faPenToSquare as faSolidPenToSquare,
|
||||||
|
faXmark as faSolidXmark
|
||||||
} from '@fortawesome/free-solid-svg-icons';
|
} from '@fortawesome/free-solid-svg-icons';
|
||||||
library.add(faRegularCopy);
|
library.add(faRegularCopy);
|
||||||
|
library.add(faSolidXmark);
|
||||||
library.add(faSolidRotateRight);
|
library.add(faSolidRotateRight);
|
||||||
|
library.add(faSolidPenToSquare);
|
||||||
library.add(faSolidCheck);
|
library.add(faSolidCheck);
|
||||||
library.add(faRegularUser);
|
library.add(faRegularUser);
|
||||||
library.add(faRegularSun);
|
library.add(faRegularSun);
|
||||||
|
|||||||
Reference in new issue
Block a user