update conversation ui
This commit is contained in:
1 parent
297dd3ef2f
commit
b98f8de879
8 files changed
+108
-29
No files matched your search
@@ -4,7 +4,7 @@
|
|||||||
v-model="value"
|
v-model="value"
|
||||||
:rows="2"
|
:rows="2"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
placeholder="Please input"
|
:placeholder="$t('chat.message.newMessagePlaceholder')"
|
||||||
@keydown.enter.exact.prevent="onSubmit"
|
@keydown.enter.exact.prevent="onSubmit"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -12,16 +12,12 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElInput, ElButton } from 'element-plus';
|
import { ElInput } from 'element-plus';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
|
||||||
import { ROUTE_CHAT_INDEX } from '@/router/constants';
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'InputBox',
|
name: 'InputBox',
|
||||||
components: {
|
components: {
|
||||||
ElInput,
|
ElInput
|
||||||
ElButton,
|
|
||||||
FontAwesomeIcon
|
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
modelValue: {
|
modelValue: {
|
||||||
|
|||||||
@@ -11,10 +11,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { IContent, IError, IMessage } from '@/operators/message/models';
|
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import AnsweringMark from './AnsweringMark.vue';
|
import AnsweringMark from './AnsweringMark.vue';
|
||||||
// import MessageContent from './MessageContent.vue';
|
|
||||||
import { ElImage, ElButton } from 'element-plus';
|
import { ElImage, ElButton } from 'element-plus';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||||
import copy from 'copy-to-clipboard';
|
import copy from 'copy-to-clipboard';
|
||||||
@@ -29,11 +27,7 @@ interface IData {
|
|||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'Message',
|
name: 'Message',
|
||||||
components: {
|
components: {
|
||||||
// MessageContent,
|
|
||||||
// ElImage,
|
|
||||||
ElButton,
|
|
||||||
CopyToClipboard,
|
CopyToClipboard,
|
||||||
// FontAwesomeIcon,
|
|
||||||
AnsweringMark,
|
AnsweringMark,
|
||||||
MarkdownRenderer
|
MarkdownRenderer
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,13 +12,44 @@
|
|||||||
<font-awesome-icon icon="fa-regular fa-comment" class="icon" />
|
<font-awesome-icon icon="fa-regular fa-comment" class="icon" />
|
||||||
</div>
|
</div>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<span v-if="conversation?.messages">{{
|
<span v-if="conversation?.deleting">
|
||||||
conversation?.messages[conversation?.messages.length - 1]?.content
|
{{ `${$t('chat.message.confirmDelete')}?` }}
|
||||||
|
</span>
|
||||||
|
<span v-else-if="conversation?.editing">
|
||||||
|
<el-input v-model="conversation.title" @keydown.enter="onConfirm(conversation)" />
|
||||||
|
</span>
|
||||||
|
<span v-else-if="conversation?.title || conversation?.messages">{{
|
||||||
|
conversation?.title || conversation?.messages[conversation?.messages.length - 1]?.content
|
||||||
}}</span>
|
}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="operations">
|
<div class="operations">
|
||||||
<font-awesome-icon icon="fa-solid fa-edit" class="icon icon-edit" />
|
<font-awesome-icon
|
||||||
<font-awesome-icon icon="fa-solid fa-trash" class="icon icon-delete" />
|
v-if="!conversation?.editing && !conversation.deleting"
|
||||||
|
icon="fa-solid fa-edit"
|
||||||
|
class="icon icon-edit"
|
||||||
|
@click.stop="conversation.editing = true"
|
||||||
|
/>
|
||||||
|
<font-awesome-icon
|
||||||
|
v-if="!conversation?.editing && !conversation.deleting"
|
||||||
|
icon="fa-solid fa-trash"
|
||||||
|
class="icon icon-delete"
|
||||||
|
@click.stop="conversation.deleting = true"
|
||||||
|
/>
|
||||||
|
<font-awesome-icon
|
||||||
|
v-if="conversation?.editing || conversation.deleting"
|
||||||
|
icon="fa-solid fa-check"
|
||||||
|
class="icon icon-confirm"
|
||||||
|
@click.stop="onConfirm(conversation)"
|
||||||
|
/>
|
||||||
|
<font-awesome-icon
|
||||||
|
v-if="conversation?.editing || conversation.deleting"
|
||||||
|
icon="fa-solid fa-xmark"
|
||||||
|
class="icon icon-cancel"
|
||||||
|
@click.stop="
|
||||||
|
conversation.editing = false;
|
||||||
|
conversation.deleting = false;
|
||||||
|
"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -27,7 +58,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElTooltip, ElButton, ElSkeleton } from 'element-plus';
|
import { ElTooltip, ElButton, ElSkeleton, ElInput } from 'element-plus';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||||
import { ROUTE_CHAT_CONVERSATION } from '@/router/constants';
|
import { ROUTE_CHAT_CONVERSATION } from '@/router/constants';
|
||||||
import { apiUsageOperator, IApplication, chatOperator } from '@/operators';
|
import { apiUsageOperator, IApplication, chatOperator } from '@/operators';
|
||||||
@@ -42,6 +73,7 @@ export default defineComponent({
|
|||||||
name: 'Sidebar',
|
name: 'Sidebar',
|
||||||
components: {
|
components: {
|
||||||
ElButton,
|
ElButton,
|
||||||
|
ElInput,
|
||||||
FontAwesomeIcon,
|
FontAwesomeIcon,
|
||||||
ElSkeleton
|
ElSkeleton
|
||||||
},
|
},
|
||||||
@@ -67,6 +99,17 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
mounted() {},
|
mounted() {},
|
||||||
methods: {
|
methods: {
|
||||||
|
async onConfirm(conversation: IChatConversation) {
|
||||||
|
if (conversation?.deleting) {
|
||||||
|
await chatOperator.deleteConversation(conversation.id);
|
||||||
|
await this.onFetchAllConversations();
|
||||||
|
} else if (conversation?.editing) {
|
||||||
|
await chatOperator.updateConversation(conversation);
|
||||||
|
this.onFetchAllConversations();
|
||||||
|
} else {
|
||||||
|
conversation.editing = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
async onFetchAllConversations() {
|
async onFetchAllConversations() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
const {
|
const {
|
||||||
@@ -84,7 +127,7 @@ export default defineComponent({
|
|||||||
.map((apiUsage) => apiUsage.metadata?.conversation_id)
|
.map((apiUsage) => apiUsage.metadata?.conversation_id)
|
||||||
.filter((id) => id);
|
.filter((id) => id);
|
||||||
const uniqueConversationIds = [...new Set(conversationIds)];
|
const uniqueConversationIds = [...new Set(conversationIds)];
|
||||||
const conversations = (await chatOperator.conversations(uniqueConversationIds)).data;
|
const conversations = (await chatOperator.getConversations(uniqueConversationIds)).data;
|
||||||
this.conversations = conversations;
|
this.conversations = conversations;
|
||||||
},
|
},
|
||||||
onClick(id: string) {
|
onClick(id: string) {
|
||||||
@@ -116,7 +159,7 @@ export default defineComponent({
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
.conversation {
|
.conversation {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 50px;
|
height: 55px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
@@ -138,13 +181,16 @@ export default defineComponent({
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
padding-right: 8px;
|
||||||
|
color: #666;
|
||||||
}
|
}
|
||||||
.operations {
|
.operations {
|
||||||
width: 45px;
|
width: 40px;
|
||||||
.icon {
|
.icon {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
margin-right: 8px;
|
margin-right: 6px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,5 @@ export default {
|
|||||||
errorUsedUp: '您的套餐次数已经用完,请购买更多次数继续使用',
|
errorUsedUp: '您的套餐次数已经用完,请购买更多次数继续使用',
|
||||||
errorUnknown: '服务器出现未知错误,请稍后重试或联系客服',
|
errorUnknown: '服务器出现未知错误,请稍后重试或联系客服',
|
||||||
errorTimeout: '回答问题超时,请稍后重试',
|
errorTimeout: '回答问题超时,请稍后重试',
|
||||||
howToBreakLine: '按 Shift+Enter 键可以换行',
|
howToBreakLine: '按 Shift+Enter 键可以换行'
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -44,6 +44,9 @@ export interface IChatMessage {
|
|||||||
export interface IChatConversation {
|
export interface IChatConversation {
|
||||||
id: string;
|
id: string;
|
||||||
messages: IChatMessage[];
|
messages: IChatMessage[];
|
||||||
|
title?: string;
|
||||||
|
deleting?: boolean;
|
||||||
|
editing?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IChatAskOptions {
|
export interface IChatAskOptions {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
import { ENDPOINT_API } from '../common/contants';
|
import { ENDPOINT_API } from '../common/contants';
|
||||||
|
|
||||||
class ChatOperator {
|
class ChatOperator {
|
||||||
async ask(data: IChatAskRequest, options: IChatAskOptions): Promise<AxiosResponse<IChatAskResponse>> {
|
async askQuestion(data: IChatAskRequest, options: IChatAskOptions): Promise<AxiosResponse<IChatAskResponse>> {
|
||||||
return await axios.post(options.path, data, {
|
return await axios.post(options.path, data, {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: `Bearer ${options.token}`,
|
authorization: `Bearer ${options.token}`,
|
||||||
@@ -32,7 +32,7 @@ class ChatOperator {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async conversation(id: string | undefined): Promise<AxiosResponse<IChatConversation>> {
|
async getConversation(id: string | undefined): Promise<AxiosResponse<IChatConversation>> {
|
||||||
return await axios.post(
|
return await axios.post(
|
||||||
`/chatgpt/conversations`,
|
`/chatgpt/conversations`,
|
||||||
{
|
{
|
||||||
@@ -48,7 +48,7 @@ class ChatOperator {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async conversations(ids: string[]): Promise<AxiosResponse<IChatConversation[]>> {
|
async getConversations(ids: string[]): Promise<AxiosResponse<IChatConversation[]>> {
|
||||||
return await axios.post(
|
return await axios.post(
|
||||||
`/chatgpt/conversations`,
|
`/chatgpt/conversations`,
|
||||||
{
|
{
|
||||||
@@ -63,6 +63,38 @@ class ChatOperator {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deleteConversation(id: string): Promise<AxiosResponse<IChatConversation>> {
|
||||||
|
return await axios.post(
|
||||||
|
`/chatgpt/conversations`,
|
||||||
|
{
|
||||||
|
action: IChatConversationAction.DELETE,
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
baseURL: ENDPOINT_API
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateConversation(payload: IChatConversation): Promise<AxiosResponse<IChatConversation>> {
|
||||||
|
return await axios.post(
|
||||||
|
`/chatgpt/conversations`,
|
||||||
|
{
|
||||||
|
action: IChatConversationAction.UPDATE,
|
||||||
|
...payload
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
baseURL: ENDPOINT_API
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const chatOperator = new ChatOperator();
|
export const chatOperator = new ChatOperator();
|
||||||
@@ -122,7 +122,7 @@ export default defineComponent({
|
|||||||
await this.onFetchAnswer();
|
await this.onFetchAnswer();
|
||||||
},
|
},
|
||||||
async onFetchHistory(id?: string) {
|
async onFetchHistory(id?: string) {
|
||||||
const { data: data } = await chatOperator.conversation(id || this.conversationId);
|
const { data: data } = await chatOperator.getConversation(id || this.conversationId);
|
||||||
this.messages = data.messages || [];
|
this.messages = data.messages || [];
|
||||||
},
|
},
|
||||||
async onFetchAnswer() {
|
async onFetchAnswer() {
|
||||||
@@ -141,7 +141,7 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
// request server to get answer
|
// request server to get answer
|
||||||
chatOperator
|
chatOperator
|
||||||
.ask(
|
.askQuestion(
|
||||||
{
|
{
|
||||||
question,
|
question,
|
||||||
conversation_id: this.conversationId,
|
conversation_id: this.conversationId,
|
||||||
@@ -231,6 +231,8 @@ export default defineComponent({
|
|||||||
|
|
||||||
.dialogue {
|
.dialogue {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
overflow-y: scroll;
|
||||||
|
margin: 20px 0;
|
||||||
.messages {
|
.messages {
|
||||||
padding-top: 30px;
|
padding-top: 30px;
|
||||||
.message {
|
.message {
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ import {
|
|||||||
} from '@/operators/chat/constants';
|
} from '@/operators/chat/constants';
|
||||||
|
|
||||||
interface IData {
|
interface IData {
|
||||||
|
model: string;
|
||||||
|
drawer: boolean;
|
||||||
|
question: string;
|
||||||
initializing: boolean;
|
initializing: boolean;
|
||||||
applications: IApplication[];
|
applications: IApplication[];
|
||||||
}
|
}
|
||||||
@@ -108,6 +111,10 @@ export default defineComponent({
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
margin-bottom: 15px;
|
margin-bottom: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.el-button {
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user