Files
FiDA_Front/src/views/home/left-nav.vue
2026-02-06 16:23:22 +08:00

281 lines
6.5 KiB
Vue

<template>
<div class="left-nav" :class="{ collapse: isCollapse }">
<div class="top">
<img class="logo-img" src="@/assets/images/logo.png" alt="FiDA" v-show="!isCollapse" />
<span class="logo-text" v-show="!isCollapse">FiDA</span>
<div class="close" @click="onCollapse">
<svg-icon name="shouqi" size="24" />
</div>
</div>
<button class="create-btn">
<span class="icon"><svg-icon name="add" size="16" /></span>
<span v-show="!isCollapse" class="text">{{ $t('Home.newProject') }}</span>
</button>
<!-- <div class="menu-item" @click="onHome">
<span class="icon"><svg-icon name="home" size="24" /></span>
<span class="title" v-show="!isCollapse">{{ $t('Home.home') }}</span>
</div> -->
<div class="menu-item" @click="onCanvas">
<!-- <span class="icon"><svg-icon name="home" size="24" /></span> -->
<span class="title">画布</span>
</div>
<div class="menu-item" @click="onHistory" :class="{ active: showHistory }">
<span class="icon"><svg-icon name="history" size="24" /></span>
<span class="title" v-show="!isCollapse">{{ $t('Home.history') }}</span>
<span class="icon jiantou" v-show="!isCollapse"
><svg-icon name="arrow-right" size="14" />
</span>
</div>
<div class="history-list" v-show="!isCollapse && showHistory">
<div v-for="item in historyList" :key="item.name" class="history-item">
<div v-if="item.title" class="title">{{ item.name }}</div>
<div
v-else
class="box"
@click="onClickHistoryItem(item)"
:class="{ active: item.id == id }"
>
<span>{{ item.name }}</span>
<el-popover
placement="right"
trigger="click"
popper-style="padding: 1rem 0.5rem;"
>
<template #reference>
<span @click.stop class="icon"><svg-icon name="more" size="16" /></span>
</template>
<div class="history-item-menu">
<div class="rename" @click="onRenameHistoryItem(item)">Rename</div>
<div class="delete" @click="onDeleteHistoryItem(item)">Delete</div>
</div>
</el-popover>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
const { t: $t } = useI18n()
const route = useRoute()
const router = useRouter()
import { useGlobalStore } from '@/stores'
const id = computed(() => route.params.id)
const globalStore = useGlobalStore()
const isCollapse = computed(() => globalStore.state.homeLeftNavCollapse)
const onCollapse = () => {
globalStore.setHomeLeftNavCollapse(!isCollapse.value)
}
const showHistory = ref(true)
const historyList = ref([
{
title: true,
name: $t('Home.today')
},
{
id: 1,
name: 'Conversation Item 1'
},
{
id: 2,
name: 'Conversation Item 2'
},
{
title: true,
name: $t('Home.yesterday')
},
{
id: 3,
name: 'Conversation Item 3'
},
{
title: true,
name: $t('Home.earlierChat')
},
{
id: 4,
name: 'Conversation Item 4'
},
{
id: 5,
name: 'Conversation Item 5'
}
])
const onHome = () => {
console.log('onHome')
}
const onCanvas = () => {
router.push({ name: 'canvas' })
}
const onHistory = () => {
showHistory.value = !showHistory.value
}
const onClickHistoryItem = (item: any) => {
router.push({ name: 'test', params: { id: item.id } })
}
const onRenameHistoryItem = (item: any) => {
// const index = historyList.value.findIndex((i: any) => i.id == item.id)
// if (index != -1) {
// }
}
const onDeleteHistoryItem = (item: any) => {
console.log(item)
const index = historyList.value.findIndex((i: any) => i.id == item.id)
if (index != -1) {
historyList.value.splice(index, 1)
}
}
</script>
<style lang="less" scoped>
.left-nav {
width: var(--left-nav-collapse-width, 30rem);
height: 100%;
background-color: #fff;
overflow: hidden;
display: flex;
flex-direction: column;
&,
& * {
transition: width 0.2s ease-in-out;
}
&.collapse {
--left-nav-collapse-width: 9.4rem;
--collapse-top-padding: 4.6rem 0 0 0;
--collapse-create-btn-width: 5.1rem;
--collapse-menu-item-width: 50%;
}
> .top {
display: flex;
align-items: center;
justify-content: center;
padding: var(--collapse-top-padding, 2.6rem 1.6rem 0 3.6rem);
> .logo-img {
width: 3.4rem;
height: auto;
margin-right: 1rem;
}
> .logo-text {
font-family: SemiBold;
font-weight: 600;
font-size: 3rem;
margin-right: auto;
}
}
> .create-btn {
margin: 4.5rem auto 2.5rem;
width: var(--collapse-create-btn-width, 23rem);
height: 5.1rem;
border-radius: 5rem;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
background-color: rgba(255, 122, 81, 1);
border: none;
outline: none;
&:active {
background-color: rgba(255, 122, 81, 0.8);
}
> .text {
font-weight: 500;
font-size: 1.8rem;
margin-left: 1rem;
}
}
> .menu-item {
width: var(--collapse-menu-item-width, 23rem);
margin: 2.5rem auto 0;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
border-radius: 8px;
padding: 0.9rem 0.8rem;
&:hover {
background-color: rgba(0, 0, 0, 0.06);
}
> .title {
flex: 1;
font-weight: 500;
font-size: 2rem;
margin: 0 1.6rem;
}
> .icon {
transition: transform 0.2s ease-in-out;
}
&.active > .jiantou {
transform: rotate(90deg);
}
}
> .history-list {
flex: 1;
overflow-y: auto;
width: 23.2rem;
margin: 1rem auto 0;
> .history-item {
width: 100%;
height: 4rem;
margin-bottom: 0.4rem;
> div {
width: 100%;
height: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 0.8rem;
}
> .title {
font-weight: 600;
font-size: 1.6rem;
font-family: SemiBold;
}
> .box {
font-family: Regular;
border-radius: 0.8rem;
cursor: pointer;
&.active,
&:hover {
background-color: rgba(0, 0, 0, 0.06);
}
&.active {
font-family: SemiBold;
}
> .label {
flex: 1;
font-weight: 400;
font-size: 1.6rem;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
> .icon {
width: 2.5rem;
height: 2.5rem;
}
}
}
}
}
.history-item-menu {
user-select: none;
> div {
cursor: pointer;
padding: 0.5rem 1rem;
&:hover {
background-color: rgba(0, 0, 0, 0.06);
}
}
> .rename {
color: #409eff;
}
> .delete {
color: #ff4d4f;
}
}
</style>