配置语言
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
<span class="title" v-show="!isCollapse">{{ $t('Home.home') }}</span>
|
||||
</div> -->
|
||||
<div class="menu-item" @click="onTest">
|
||||
<span class="title" v-show="!isCollapse">TEST</span>
|
||||
<span class="title">TEST</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="onHistory" :class="{ active: showHistory }">
|
||||
<span class="icon"><svg-icon name="history" size="24" /></span>
|
||||
@@ -34,18 +34,33 @@
|
||||
@click="onClickHistoryItem(item)"
|
||||
:class="{ active: item.id == id }"
|
||||
>
|
||||
<span>{{ item.name }}</span>
|
||||
<input
|
||||
v-show="item.edit"
|
||||
type="text"
|
||||
:value="item.name"
|
||||
ref="inputRef"
|
||||
:input-id="item.id"
|
||||
@click.stop
|
||||
@keyup.enter="(e) => onEnterHistoryItem(e, item)"
|
||||
@blur="(e) => onBlurHistoryItem(e, item)"
|
||||
/>
|
||||
<span class="label" v-show="!item.edit">{{ item.name }}</span>
|
||||
<el-popover
|
||||
placement="right"
|
||||
trigger="click"
|
||||
popper-style="padding: 1rem 0.5rem;"
|
||||
v-model:visible="item.visible"
|
||||
>
|
||||
<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 class="rename" @click="onRenameHistoryItem(item)">
|
||||
{{ $t('Home.rename') }}
|
||||
</div>
|
||||
<div class="delete" @click="onDeleteHistoryItem(item)">
|
||||
{{ $t('Home.delete') }}
|
||||
</div>
|
||||
</div>
|
||||
</el-popover>
|
||||
</div>
|
||||
@@ -55,10 +70,10 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, ref, nextTick } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { getProjectList } from '@/api/agent'
|
||||
import { getProjectList, updateProject, deleteProject } from '@/api/agent'
|
||||
import { FormatDate } from '@/utils/tools'
|
||||
import MyEvent from '@/utils/myEvent'
|
||||
const { t: $t } = useI18n()
|
||||
@@ -72,34 +87,47 @@
|
||||
globalStore.setHomeLeftNavCollapse(!isCollapse.value)
|
||||
}
|
||||
const showHistory = ref(true)
|
||||
|
||||
const todayList = ref([])
|
||||
const yesterdayList = ref([])
|
||||
const earlierChatList = ref([])
|
||||
const list = ref([])
|
||||
const historyList = computed(() => {
|
||||
const list = []
|
||||
if (todayList.value.length > 0) {
|
||||
list.push({
|
||||
const str = 'yyyyMMdd'
|
||||
const today = FormatDate(Date.now(), str)
|
||||
const yesterday = FormatDate(Date.now() - 24 * 60 * 60 * 1000, str)
|
||||
const todayList = []
|
||||
const yesterdayList = []
|
||||
const earlierChatList = []
|
||||
list.value.forEach((item: any) => {
|
||||
const date = FormatDate(item.updateTime * 1000, str)
|
||||
if (date == today) {
|
||||
todayList.push(item)
|
||||
} else if (date == yesterday) {
|
||||
yesterdayList.push(item)
|
||||
} else {
|
||||
earlierChatList.push(item)
|
||||
}
|
||||
})
|
||||
const arr = []
|
||||
if (todayList.length > 0) {
|
||||
arr.push({
|
||||
title: true,
|
||||
name: $t('Home.today')
|
||||
})
|
||||
list.push(...todayList.value)
|
||||
arr.push(...todayList)
|
||||
}
|
||||
if (yesterdayList.value.length > 0) {
|
||||
list.push({
|
||||
if (yesterdayList.length > 0) {
|
||||
arr.push({
|
||||
title: true,
|
||||
name: $t('Home.yesterday')
|
||||
})
|
||||
list.push(...yesterdayList.value)
|
||||
arr.push(...yesterdayList)
|
||||
}
|
||||
if (earlierChatList.value.length > 0) {
|
||||
list.push({
|
||||
if (earlierChatList.length > 0) {
|
||||
arr.push({
|
||||
title: true,
|
||||
name: $t('Home.earlierChat')
|
||||
})
|
||||
list.push(...earlierChatList.value)
|
||||
arr.push(...earlierChatList)
|
||||
}
|
||||
return list
|
||||
return arr
|
||||
})
|
||||
|
||||
const onCreateProject = () => {
|
||||
@@ -120,16 +148,37 @@
|
||||
const onClickHistoryItem = (item: any) => {
|
||||
router.push({ name: 'agent', params: { id: item.id } })
|
||||
}
|
||||
const inputRef = ref(null)
|
||||
const onRenameHistoryItem = (item: any) => {
|
||||
// const index = historyList.value.findIndex((i: any) => i.id == item.id)
|
||||
// if (index != -1) {
|
||||
// }
|
||||
item.visible = false
|
||||
item.edit = true
|
||||
nextTick(() => {
|
||||
inputRef.value.forEach((v: any) => {
|
||||
const id = v.getAttribute('input-id')
|
||||
if (id == item.id) v.focus()
|
||||
})
|
||||
})
|
||||
}
|
||||
const onEnterHistoryItem = (e: any, item: any) => {
|
||||
e.target.blur()
|
||||
}
|
||||
const onBlurHistoryItem = (e: any, item: any) => {
|
||||
item.edit = false
|
||||
const name = e.target.value
|
||||
if (!name) return console.warn('未输入名称,不允许重命名')
|
||||
item.name = name
|
||||
updateProject(item.id, { name }).then(() => {
|
||||
GetProjectList()
|
||||
})
|
||||
}
|
||||
const onDeleteHistoryItem = (item: any) => {
|
||||
// const index = historyList.value.findIndex((i: any) => i.id == item.id)
|
||||
// if (index != -1) {
|
||||
// historyList.value.splice(index, 1)
|
||||
// }
|
||||
item.visible = false
|
||||
deleteProject(item.id).then(() => {
|
||||
GetProjectList()
|
||||
if (item.id == id.value) {
|
||||
router.push({ name: 'mainInput' })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const GetProjectList = async () => {
|
||||
@@ -137,25 +186,13 @@
|
||||
page: 1,
|
||||
size: 100
|
||||
})
|
||||
const str = 'yyyyMMdd'
|
||||
const today = FormatDate(Date.now(), str)
|
||||
const yesterday = FormatDate(Date.now() - 24 * 60 * 60 * 1000, str)
|
||||
todayList.value = []
|
||||
yesterdayList.value = []
|
||||
earlierChatList.value = []
|
||||
const list = res.records || []
|
||||
list.forEach((item: any) => {
|
||||
const obj = { ...item }
|
||||
const date = FormatDate(obj.createTime * 1000, str)
|
||||
if (date == today) {
|
||||
todayList.value.push(obj)
|
||||
} else if (date == yesterday) {
|
||||
yesterdayList.value.push(obj)
|
||||
} else {
|
||||
earlierChatList.value.push(obj)
|
||||
}
|
||||
list.value = []
|
||||
const arr = res.records || []
|
||||
arr.forEach((item: any) => {
|
||||
const obj = { ...item, edit: false, visible: false }
|
||||
list.value.push(obj)
|
||||
})
|
||||
}
|
||||
}
|
||||
MyEvent.add('updateProjectList', GetProjectList)
|
||||
GetProjectList()
|
||||
</script>
|
||||
@@ -177,6 +214,7 @@
|
||||
--collapse-top-padding: 4.6rem 0 0 0;
|
||||
--collapse-create-btn-width: 5.1rem;
|
||||
--collapse-menu-item-width: 50%;
|
||||
--collapse-menu-item-icon-margin-right: 0;
|
||||
}
|
||||
> .top {
|
||||
display: flex;
|
||||
@@ -242,6 +280,7 @@
|
||||
}
|
||||
> .icon {
|
||||
transition: transform 0.2s ease-in-out;
|
||||
margin-right: var(--collapse-menu-item-icon-margin-right, 1.6rem);
|
||||
}
|
||||
&.active > .jiantou {
|
||||
transform: rotate(90deg);
|
||||
@@ -288,6 +327,14 @@
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
> input {
|
||||
flex: 1;
|
||||
width: 0;
|
||||
height: 100%;
|
||||
border: none;
|
||||
outline: none;
|
||||
background-color: transparent;
|
||||
}
|
||||
> .icon {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
|
||||
Reference in New Issue
Block a user