11<script setup lang="ts">
22import { type Chat } from ' @/api/chat.ts'
3+ import { ElIcon } from ' element-plus-secondary'
4+ import { Icon } from ' @/components/icon-custom'
5+ import { ref , computed } from ' vue'
6+ import { useI18n } from ' vue-i18n'
7+ import icon_searchOutline_outlined from ' @/assets/svg/icon_search-outline_outlined.svg'
38
4- withDefaults (
9+ const props = withDefaults (
510 defineProps <{
611 currentChatId? : number
712 chatList: Array <Chat >
@@ -11,28 +16,139 @@ withDefaults(
1116 chatList : () => [],
1217 }
1318)
14-
19+ const { t } = useI18n ()
1520const emits = defineEmits ([' chatSelected' ])
21+ const filterText = ref (' ' )
1622
1723function onClickHistory(chat : Chat ) {
1824 emits (' chatSelected' , chat )
1925}
26+
27+ // 获取当前日期和本周的开始日期
28+ const now = new Date ()
29+ const startOfWeek = new Date (now )
30+ startOfWeek .setDate (now .getDate () - now .getDay () + (now .getDay () === 0 ? - 6 : 1 )) // 设置为本周一
31+ startOfWeek .setHours (0 , 0 , 0 , 0 )
32+
33+ // 格式化日期函数
34+ const formatDate = (dateString : string ) => {
35+ const date = new Date (dateString )
36+ return date .toLocaleString ()
37+ }
38+
39+ // 过滤和分类数据
40+ const filteredAndGroupedData = computed (() => {
41+ const today: Chat [] = []
42+ const thisWeek: Chat [] = []
43+ const earlier: Chat [] = []
44+
45+ // 先过滤数据
46+ const filteredList = props .chatList .filter (
47+ (chat ) =>
48+ ! filterText .value ||
49+ (chat .brief && chat .brief .toLowerCase ().includes (filterText .value .toLowerCase ()))
50+ )
51+
52+ // 然后分类
53+ filteredList .forEach ((item ) => {
54+ const itemDate = new Date (item .create_time )
55+
56+ // 检查是否是今天
57+ if (
58+ itemDate .getDate () === now .getDate () &&
59+ itemDate .getMonth () === now .getMonth () &&
60+ itemDate .getFullYear () === now .getFullYear ()
61+ ) {
62+ today .push (item )
63+ }
64+ // 检查是否是本周但不是今天
65+ else if (itemDate >= startOfWeek && itemDate < now ) {
66+ thisWeek .push (item )
67+ }
68+ // 更早的数据
69+ else {
70+ earlier .push (item )
71+ }
72+ })
73+
74+ return { today , thisWeek , earlier }
75+ })
2076 </script >
2177
2278<template >
23- <el-scrollbar ref =" chatListRef" >
24- <div class =" chat-list-inner" >
25- <template v-for =" chat in chatList " :key =" chat .id " >
79+ <div style =" width : 100% ; height : 100% " >
80+ <el-input
81+ v-model =" filterText"
82+ :placeholder =" t('dashboard.search')"
83+ clearable
84+ class =" search-bar"
85+ >
86+ <template #prefix >
87+ <el-icon >
88+ <Icon name =" icon_search-outline_outlined" >
89+ <icon _searchOutline_outlined class =" svg-icon" />
90+ </Icon >
91+ </el-icon >
92+ </template >
93+ </el-input >
94+ <el-scrollbar ref =" chatListRef" class =" custom-chart-list" >
95+ <div class =" chat-list-inner" >
96+ <!-- today -->
97+ <div v-if =" filteredAndGroupedData.today.length > 0" class =" time-group" >
98+ <div class =" time-group-title" >{{ t('dashboard.today') }}</div >
99+ <div
100+ v-for =" chat in filteredAndGroupedData.today"
101+ :key =" chat.id"
102+ class =" chat-list-item"
103+ :class =" { active: currentChatId === chat.id }"
104+ @click =" onClickHistory(chat)"
105+ >
106+ <span class =" title" >{{ chat.brief ?? 'Untitled' }}</span >
107+ </div >
108+ </div >
109+
110+ <!-- this week -->
111+ <div v-if =" filteredAndGroupedData.thisWeek.length > 0" class =" time-group" >
112+ <div class =" time-group-title" >{{ t('dashboard.this_week') }}</div >
113+ <div
114+ v-for =" chat in filteredAndGroupedData.thisWeek"
115+ :key =" chat.id"
116+ class =" chat-list-item"
117+ :class =" { active: currentChatId === chat.id }"
118+ @click =" onClickHistory(chat)"
119+ >
120+ <span class =" title" >{{ chat.brief ?? 'Untitled' }}</span >
121+ </div >
122+ </div >
123+
124+ <!-- earlier -->
125+ <div v-if =" filteredAndGroupedData.earlier.length > 0" class =" time-group" >
126+ <div class =" time-group-title" >{{ t('dashboard.earlier') }}</div >
127+ <div
128+ v-for =" chat in filteredAndGroupedData.earlier"
129+ :key =" chat.id"
130+ class =" chat-list-item"
131+ :class =" { active: currentChatId === chat.id }"
132+ @click =" onClickHistory(chat)"
133+ >
134+ <span class =" title" >{{ chat.brief ?? 'Untitled' }}</span >
135+ </div >
136+ </div >
137+
138+ <!-- no data -->
26139 <div
27- class =" chat-list-item"
28- :class =" { active: currentChatId === chat.id }"
29- @click =" onClickHistory(chat)"
140+ v-if ="
141+ filteredAndGroupedData.today.length === 0 &&
142+ filteredAndGroupedData.thisWeek.length === 0 &&
143+ filteredAndGroupedData.earlier.length === 0
144+ "
145+ class =" no-data"
30146 >
31- < span class = " title " > {{ chat.brief ?? 'Untitled' }}</ span >
147+ {{ t('dashboard.no_chat') }}
32148 </div >
33- </template >
34- </div >
35- </el-scrollbar >
149+ </div >
150+ </el-scrollbar >
151+ </div >
36152</template >
37153
38154<style scoped lang="less">
@@ -49,6 +165,24 @@ function onClickHistory(chat: Chat) {
49165
50166 gap : 8px ;
51167
168+ .time-group {
169+ display : flex ;
170+ flex-direction : column ;
171+ gap : 8px ;
172+ margin-top : 12px ;
173+
174+ & :first-child {
175+ margin-top : 0 ;
176+ }
177+
178+ .time-group-title {
179+ font-size : 12px ;
180+ color : rgba (100 , 106 , 115 , 1 );
181+ padding : 4px 8px ;
182+ font-weight : 500 ;
183+ }
184+ }
185+
52186 .chat-list-item {
53187 width : 100% ;
54188 height : 42px ;
@@ -67,6 +201,8 @@ function onClickHistory(chat: Chat) {
67201 .title {
68202 flex : 1 ;
69203 width : 0 ;
204+ color : rgba (31 , 35 , 41 , 1 );
205+ font-size : 14px ;
70206 overflow : hidden ;
71207 text-overflow : ellipsis ;
72208 white-space : nowrap ;
@@ -80,16 +216,31 @@ function onClickHistory(chat: Chat) {
80216 }
81217
82218 & :hover {
83- background-color : var ( --hover-color );
219+ background-color : rgba ( 255 , 255 , 255 , 0.75 );
84220
85221 .icon-more {
86222 display : inline-flex ;
87223 }
88224 }
89225
90226 & .active {
91- background-color : var ( --active-color );
227+ background-color : rgba ( 255 , 255 , 255 , 1 );
92228 }
93229 }
230+
231+ .no-data {
232+ text-align : center ;
233+ padding : 16px ;
234+ color : var (--ed-text-color-placeholder );
235+ font-size : 14px ;
236+ }
237+ }
238+ .custom-chart-list {
239+ height : calc (100% - 32px );
240+ }
241+ .search-bar {
242+ padding : 0 12px 10px 12px ;
243+ width : 100% ;
244+ --ed-input-bg-color : rgba (245 , 246 , 247 , 1 );
94245}
95246 </style >
0 commit comments