add nav
This commit is contained in:
1 parent
17905a21e5
commit
de088445f6
7 files changed
+227
-5
No files matched your search
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -9,5 +9,9 @@ export default {
|
|||||||
category: '分类',
|
category: '分类',
|
||||||
service: '服务',
|
service: '服务',
|
||||||
document: '文档',
|
document: '文档',
|
||||||
console: '控制台'
|
console: '控制台',
|
||||||
|
clearConversations: '清除对话',
|
||||||
|
newChat: '新建对话',
|
||||||
|
logOut: '退出登录',
|
||||||
|
confirmClearConversations: '确认清除'
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<el-aside class="aside">
|
||||||
|
<left-navigator />
|
||||||
|
</el-aside>
|
||||||
<el-main class="main"> <router-view /> </el-main>
|
<el-main class="main"> <router-view /> </el-main>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -7,11 +10,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElMain, ElAside } from 'element-plus';
|
import { ElMain, ElAside } from 'element-plus';
|
||||||
|
import LeftNavigator from '@/components/common/LeftNavigator.vue';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'LayoutConversation',
|
name: 'LayoutConversation',
|
||||||
components: {
|
components: {
|
||||||
ElMain
|
ElMain,
|
||||||
|
LeftNavigator
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -33,8 +38,6 @@ $width: 300px;
|
|||||||
width: $width;
|
width: $width;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding: 15px;
|
|
||||||
padding-top: 50px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { IMessage } from '../message/models';
|
||||||
|
|
||||||
|
export interface IConversation {
|
||||||
|
messages: IMessage[];
|
||||||
|
title: string;
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
@@ -56,6 +56,7 @@ import {
|
|||||||
import { ROUTE_AUTH_LOGIN, ROUTE_CONVERSATION_DETAIL } from '@/router/constants';
|
import { ROUTE_AUTH_LOGIN, ROUTE_CONVERSATION_DETAIL } from '@/router/constants';
|
||||||
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNVERIFIED } from '@/constants';
|
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNVERIFIED } from '@/constants';
|
||||||
import { getVerificationUrl } from '@/utils';
|
import { getVerificationUrl } from '@/utils';
|
||||||
|
import { IConversation } from '@/operators/conversation/models';
|
||||||
|
|
||||||
export interface IData {
|
export interface IData {
|
||||||
input: string;
|
input: string;
|
||||||
@@ -94,6 +95,13 @@ export default defineComponent({
|
|||||||
return this.$store.getters.user;
|
return this.$store.getters.user;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
conversationId: {
|
||||||
|
handler() {
|
||||||
|
this.restoreMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
if (!this.$store.getters.authenticated) {
|
if (!this.$store.getters.authenticated) {
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
@@ -101,11 +109,24 @@ export default defineComponent({
|
|||||||
query: { redirect: this.$route.fullPath }
|
query: { redirect: this.$route.fullPath }
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
this.restoreMessages();
|
||||||
await this.onGetApiInfo();
|
await this.onGetApiInfo();
|
||||||
await this.onCheckApplication();
|
await this.onCheckApplication();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
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() {
|
async onGetApiInfo() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const id = '1d58971c-e3cd-4713-a3ce-854a731adb14';
|
const id = '1d58971c-e3cd-4713-a3ce-854a731adb14';
|
||||||
@@ -242,6 +263,26 @@ export default defineComponent({
|
|||||||
)
|
)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.answering = false;
|
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) => {
|
.catch((error) => {
|
||||||
this.answering = false;
|
this.answering = false;
|
||||||
|
|||||||
+13
-1
@@ -2,11 +2,13 @@ import { createStore, ActionContext } from 'vuex';
|
|||||||
import createPersistedState from 'vuex-persistedstate';
|
import createPersistedState from 'vuex-persistedstate';
|
||||||
import { userOperator, IUser } from '@/operators';
|
import { userOperator, IUser } from '@/operators';
|
||||||
import { removeCookies } from '@/utils/cookie';
|
import { removeCookies } from '@/utils/cookie';
|
||||||
|
import { IConversation } from '@/operators/conversation/models';
|
||||||
|
|
||||||
export interface IState {
|
export interface IState {
|
||||||
accessToken: string | undefined;
|
accessToken: string | undefined;
|
||||||
refreshToken: string | undefined;
|
refreshToken: string | undefined;
|
||||||
user: IUser | undefined;
|
user: IUser | undefined;
|
||||||
|
conversations: IConversation[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const store = createStore({
|
const store = createStore({
|
||||||
@@ -14,7 +16,8 @@ const store = createStore({
|
|||||||
return {
|
return {
|
||||||
accessToken: undefined,
|
accessToken: undefined,
|
||||||
refreshToken: undefined,
|
refreshToken: undefined,
|
||||||
user: undefined
|
user: undefined,
|
||||||
|
conversations: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
@@ -26,6 +29,9 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
setUser(state: IState, payload: IUser): void {
|
setUser(state: IState, payload: IUser): void {
|
||||||
state.user = payload;
|
state.user = payload;
|
||||||
|
},
|
||||||
|
setConversations(state: IState, payload: IConversation[]): void {
|
||||||
|
state.conversations = payload;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@@ -44,6 +50,9 @@ const store = createStore({
|
|||||||
setUser({ commit }: ActionContext<IState, IState>, payload: IUser) {
|
setUser({ commit }: ActionContext<IState, IState>, payload: IUser) {
|
||||||
commit('setUser', payload);
|
commit('setUser', payload);
|
||||||
},
|
},
|
||||||
|
setConversations({ commit }: ActionContext<IState, IState>, payload: IConversation[]) {
|
||||||
|
commit('setConversations', payload);
|
||||||
|
},
|
||||||
getMe({ commit }: ActionContext<IState, IState>) {
|
getMe({ commit }: ActionContext<IState, IState>) {
|
||||||
userOperator
|
userOperator
|
||||||
.getMe()
|
.getMe()
|
||||||
@@ -67,6 +76,9 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
user(state): IUser | undefined {
|
user(state): IUser | undefined {
|
||||||
return state.user;
|
return state.user;
|
||||||
|
},
|
||||||
|
conversations(state): IConversation[] {
|
||||||
|
return state.conversations || [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [createPersistedState()]
|
plugins: [createPersistedState()]
|
||||||
|
|||||||
Reference in new issue
Block a user