This commit is contained in:
AceDataCloud committed 2023-04-07 11:25:49 +08:00
1 parent 17905a21e5
commit de088445f6
7 files changed
+227 -5

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
<template>
<div class="navigator">
<div class="conversations">
<navigator-item icon="fa-regular fa-user" :title="$t('common.nav.newChat')" @click="onNewConversation" />
<navigator-item
v-for="(conversation, conversationIndex) in conversations"
:key="conversationIndex"
icon="fa-regular fa-user"
:title="conversation.title"
@click="onSelectConversation(conversation.id)"
/>
</div>
<div class="operators">
<navigator-item
v-show="!confirming"
icon="fa-regular fa-user"
:title="$t('common.nav.clearConversations')"
@click="confirming = true"
/>
<navigator-item
v-show="confirming"
icon="fa-regular fa-user"
:title="$t('common.nav.confirmClearConversations')"
@click="onClearConversations"
/>
<navigator-item icon="fa-regular fa-user" :title="$t('common.nav.logOut')" @click="onLogout" />
</div>
</div>
</template>
<script lang="ts">
import { ROUTE_CONVERSATION_DETAIL, ROUTE_CONVERSATION_NEW } from '@/router';
import { defineComponent } from 'vue';
import NavigatorItem from './NavigatorItem.vue';
export default defineComponent({
name: 'LeftNavigator',
components: {
NavigatorItem
},
data() {
return {
confirming: false
};
},
computed: {
conversations() {
return this.$store.getters.conversations;
}
},
methods: {
onNewConversation() {
this.$router.push({
name: ROUTE_CONVERSATION_NEW
});
},
onClearConversations() {
this.$store.dispatch('setConversations', []);
this.confirming = false;
this.onNewConversation();
},
onSelectConversation(id: string) {
this.$router.push({
name: ROUTE_CONVERSATION_DETAIL,
params: {
id
}
});
},
onLogout() {
this.$store.dispatch('resetAuth');
setTimeout(() => {
window.location.reload();
}, 1000);
}
}
});
</script>
<style lang="scss" scoped>
.navigator {
display: flex;
flex-direction: column;
background-color: #202123;
color: white;
height: 100vh;
padding: 15px 5px;
font-size: 14px;
.conversations {
flex: 1;
}
.operators {
height: fit-content;
}
}
</style>
+59
View File
@@ -0,0 +1,59 @@
<template>
<div class="navigation-item">
<div class="icon">
<font-awesome-icon :icon="icon" class="icon-rotate" />
</div>
<div class="title">
{{ title }}
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
export default defineComponent({
name: 'NavigatorItem',
components: {
FontAwesomeIcon
},
props: {
icon: {
type: String,
required: true
},
title: {
type: String,
required: true
}
}
});
</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;
}
}
</style>
+5 -1
View File
@@ -9,5 +9,9 @@ export default {
category: '分类',
service: '服务',
document: '文档',
console: '控制台'
console: '控制台',
clearConversations: '清除对话',
newChat: '新建对话',
logOut: '退出登录',
confirmClearConversations: '确认清除'
};
+6 -3
View File
@@ -1,5 +1,8 @@
<template>
<div class="container">
<el-aside class="aside">
<left-navigator />
</el-aside>
<el-main class="main"> <router-view /> </el-main>
</div>
</template>
@@ -7,11 +10,13 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { ElMain, ElAside } from 'element-plus';
import LeftNavigator from '@/components/common/LeftNavigator.vue';
export default defineComponent({
name: 'LayoutConversation',
components: {
ElMain
ElMain,
LeftNavigator
}
});
</script>
@@ -33,8 +38,6 @@ $width: 300px;
width: $width;
height: 100%;
background-color: white;
padding: 15px;
padding-top: 50px;
}
.header {
+7
View File
@@ -0,0 +1,7 @@
import { IMessage } from '../message/models';
export interface IConversation {
messages: IMessage[];
title: string;
id: string;
}
+41
View File
@@ -56,6 +56,7 @@ import {
import { ROUTE_AUTH_LOGIN, ROUTE_CONVERSATION_DETAIL } from '@/router/constants';
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNVERIFIED } from '@/constants';
import { getVerificationUrl } from '@/utils';
import { IConversation } from '@/operators/conversation/models';
export interface IData {
input: string;
@@ -94,6 +95,13 @@ export default defineComponent({
return this.$store.getters.user;
}
},
watch: {
conversationId: {
handler() {
this.restoreMessages();
}
}
},
async mounted() {
if (!this.$store.getters.authenticated) {
this.$router.push({
@@ -101,11 +109,24 @@ export default defineComponent({
query: { redirect: this.$route.fullPath }
});
} else {
this.restoreMessages();
await this.onGetApiInfo();
await this.onCheckApplication();
}
},
methods: {
restoreMessages() {
if (this.conversationId) {
const conversations = this.$store.getters.conversations;
const hitConversations = conversations.filter((c: IConversation) => c.id === this.conversationId);
if (hitConversations && hitConversations.length > 0) {
const hitConversation = hitConversations[0];
this.messages = hitConversation.messages;
}
} else {
this.messages = [];
}
},
async onGetApiInfo() {
return new Promise((resolve, reject) => {
const id = '1d58971c-e3cd-4713-a3ce-854a731adb14';
@@ -242,6 +263,26 @@ export default defineComponent({
)
.then(() => {
this.answering = false;
const conversations: IConversation[] = this.$store.getters.conversations;
const hitConversations = conversations.filter((c: IConversation) => c.id === this.conversationId);
if (!hitConversations || hitConversations.length === 0) {
// append a new conversation to conversations
const newConversations = [
...conversations,
{
id: this.conversationId,
messages: this.messages,
title: this.conversationId
}
];
this.$store.dispatch('setConversations', newConversations);
} else {
// update one of existing conversations
conversations.forEach((conversation: IConversation) => {
conversation.messages = this.messages;
});
this.$store.dispatch('setConversations', conversations);
}
})
.catch((error) => {
this.answering = false;
+13 -1
View File
@@ -2,11 +2,13 @@ import { createStore, ActionContext } from 'vuex';
import createPersistedState from 'vuex-persistedstate';
import { userOperator, IUser } from '@/operators';
import { removeCookies } from '@/utils/cookie';
import { IConversation } from '@/operators/conversation/models';
export interface IState {
accessToken: string | undefined;
refreshToken: string | undefined;
user: IUser | undefined;
conversations: IConversation[];
}
const store = createStore({
@@ -14,7 +16,8 @@ const store = createStore({
return {
accessToken: undefined,
refreshToken: undefined,
user: undefined
user: undefined,
conversations: []
};
},
mutations: {
@@ -26,6 +29,9 @@ const store = createStore({
},
setUser(state: IState, payload: IUser): void {
state.user = payload;
},
setConversations(state: IState, payload: IConversation[]): void {
state.conversations = payload;
}
},
actions: {
@@ -44,6 +50,9 @@ const store = createStore({
setUser({ commit }: ActionContext<IState, IState>, payload: IUser) {
commit('setUser', payload);
},
setConversations({ commit }: ActionContext<IState, IState>, payload: IConversation[]) {
commit('setConversations', payload);
},
getMe({ commit }: ActionContext<IState, IState>) {
userOperator
.getMe()
@@ -67,6 +76,9 @@ const store = createStore({
},
user(state): IUser | undefined {
return state.user;
},
conversations(state): IConversation[] {
return state.conversations || [];
}
},
plugins: [createPersistedState()]