|
@@ -0,0 +1,349 @@
|
|
1
|
+<!--
|
|
2
|
+ * @Author: wrh
|
|
3
|
+ * @Date: 2025-04-07 14:14:05
|
|
4
|
+ * @LastEditors: wrh
|
|
5
|
+ * @LastEditTime: 2025-06-12 17:01:55
|
|
6
|
+-->
|
|
7
|
+<template>
|
|
8
|
+ <div class="app-container">
|
|
9
|
+ <!-- 最外层页面于窗口同宽,使聊天面板居中 -->
|
|
10
|
+ <div class="home-view">
|
|
11
|
+ <!-- 整个聊天面板 -->
|
|
12
|
+ <div class="chat-panel">
|
|
13
|
+ <!-- 左侧的会话列表 -->
|
|
14
|
+ <div class="session-panel">
|
|
15
|
+ <el-row :gutter="20">
|
|
16
|
+ <el-col :span="12" :offset="3">
|
|
17
|
+ <div class="top-plus-button">
|
|
18
|
+ <el-button :icon="Plus" type="primary">开启新对话</el-button>
|
|
19
|
+ </div>
|
|
20
|
+ </el-col>
|
|
21
|
+ </el-row>
|
|
22
|
+ <el-divider />
|
|
23
|
+ <el-scrollbar max-height="800px">
|
|
24
|
+ <div id="recent-containers">
|
|
25
|
+ <div v-if="classifiedRecent.today.length > 0">
|
|
26
|
+ <div class="category-title">今天</div>
|
|
27
|
+ <div v-for="item in classifiedRecent.today" :key="item.topicId"
|
|
28
|
+ class="record">
|
|
29
|
+ <span @click="enableEdit(item)" v-if="!item.isEditing">{{ item.topic }}</span>
|
|
30
|
+ <el-input v-else v-model="item.topic" @blur="disableEdit(item)"
|
|
31
|
+ @keyup.enter="disableEdit(item)" />
|
|
32
|
+ <el-button class="right-delete-button" :icon="Delete" style="border: none;"></el-button>
|
|
33
|
+ </div>
|
|
34
|
+ </div>
|
|
35
|
+ <div class="spacer" v-if="classifiedRecent.today.length > 0"></div>
|
|
36
|
+
|
|
37
|
+ <div v-if="classifiedRecent.yesterday.length > 0">
|
|
38
|
+ <div class="category-title">昨天</div>
|
|
39
|
+ <div v-for="item in classifiedRecent.yesterday" :key="item.topicId"
|
|
40
|
+ class="record">
|
|
41
|
+ <span @click="enableEdit(item)" v-if="!item.isEditing">{{ item.topic }}</span>
|
|
42
|
+ <el-input v-else v-model="item.topic" @blur="disableEdit(item)"
|
|
43
|
+ @keyup.enter="disableEdit(item)" />
|
|
44
|
+ <el-button class="right-delete-button" :icon="Delete" style="border: none;"></el-button>
|
|
45
|
+ </div>
|
|
46
|
+ </div>
|
|
47
|
+ <div class="spacer" v-if="classifiedRecent.yesterday.length > 0"></div>
|
|
48
|
+
|
|
49
|
+ <div v-if="classifiedRecent.dayBeforeYesterday.length > 0">
|
|
50
|
+ <div class="category-title">前天</div>
|
|
51
|
+ <div v-for="item in classifiedRecent.dayBeforeYesterday" :key="item.topicId"
|
|
52
|
+ class="record">
|
|
53
|
+ <span @click="enableEdit(item)" v-if="!item.isEditing">{{ item.topic }}</span>
|
|
54
|
+ <el-input v-else v-model="item.topic" @blur="disableEdit(item)"
|
|
55
|
+ @keyup.enter="disableEdit(item)" />
|
|
56
|
+ <el-button class="right-delete-button" :icon="Delete" style="border: none;"></el-button>
|
|
57
|
+ </div>
|
|
58
|
+ </div>
|
|
59
|
+ <div class="spacer" v-if="classifiedRecent.dayBeforeYesterday.length > 0"></div>
|
|
60
|
+
|
|
61
|
+ <div v-if="classifiedRecent.within7Days.length > 0">
|
|
62
|
+ <div class="category-title">7天内</div>
|
|
63
|
+ <div v-for="item in classifiedRecent.within7Days" :key="item.topicId"
|
|
64
|
+ class="record">
|
|
65
|
+ <span @click="enableEdit(item)" v-if="!item.isEditing">{{ item.topic }}</span>
|
|
66
|
+ <el-input v-else v-model="item.topic" @blur="disableEdit(item)"
|
|
67
|
+ @keyup.enter="disableEdit(item)" />
|
|
68
|
+ <el-button class="right-delete-button" :icon="Delete" style="border: none;"></el-button>
|
|
69
|
+ </div>
|
|
70
|
+ </div>
|
|
71
|
+ <div class="spacer" v-if="classifiedRecent.within7Days.length > 0"></div>
|
|
72
|
+
|
|
73
|
+ <div v-if="classifiedRecent.within30Days.length > 0">
|
|
74
|
+ <div class="category-title">30天内</div>
|
|
75
|
+ <div v-for="item in classifiedRecent.within30Days" :key="item.topicId"
|
|
76
|
+ class="record">
|
|
77
|
+ <span @click="enableEdit(item)" v-if="!item.isEditing">{{ item.topic }}</span>
|
|
78
|
+ <el-input v-else v-model="item.topic" @blur="disableEdit(item)"
|
|
79
|
+ @keyup.enter="disableEdit(item)" />
|
|
80
|
+ <el-button class="right-delete-button" :icon="Delete" style="border: none;"></el-button>
|
|
81
|
+ </div>
|
|
82
|
+ </div>
|
|
83
|
+ <div class="spacer" v-if="classifiedRecent.within30Days.length > 0"></div>
|
|
84
|
+ </div>
|
|
85
|
+
|
|
86
|
+ <!-- 按月记录容器 -->
|
|
87
|
+ <div v-if="sortedMonthlyKeys.length > 0">
|
|
88
|
+ <div v-for="monthKey in sortedMonthlyKeys" :key="monthKey">
|
|
89
|
+ <div class="category-title">{{ formatMonth(monthKey) }}</div>
|
|
90
|
+ <div v-for="item in classifiedMonthly[monthKey]" :key="item.topicId"
|
|
91
|
+ class="record">
|
|
92
|
+ <span @click="enableEdit(item)" v-if="!item.isEditing">{{ item.topic }}</span>
|
|
93
|
+ <el-input v-else v-model="item.topic" @blur="disableEdit(item)"
|
|
94
|
+ @keyup.enter="disableEdit(item)" />
|
|
95
|
+ <el-button class="right-delete-button" :icon="Delete" style="border: none;"></el-button>
|
|
96
|
+ </div>
|
|
97
|
+ </div>
|
|
98
|
+ <div class="spacer"></div>
|
|
99
|
+ </div>
|
|
100
|
+
|
|
101
|
+ <!-- 空状态 -->
|
|
102
|
+ <div v-if="!hasRecords" class="empty">
|
|
103
|
+ 暂无记录
|
|
104
|
+ </div>
|
|
105
|
+ </el-scrollbar>
|
|
106
|
+ </div>
|
|
107
|
+ <!-- 右侧的消息记录 -->
|
|
108
|
+
|
|
109
|
+ <div class="message-panel">
|
|
110
|
+
|
|
111
|
+ </div>
|
|
112
|
+ </div>
|
|
113
|
+ </div>
|
|
114
|
+ </div>
|
|
115
|
+</template>
|
|
116
|
+
|
|
117
|
+<script setup name=''>
|
|
118
|
+import { reactive, toRefs, onBeforeMount, onMounted } from 'vue'
|
|
119
|
+import { Plus, Delete } from '@element-plus/icons-vue'
|
|
120
|
+import { listTopic, getTopic, delTopic, addTopic, updateTopic } from "@/api/llm/topic";
|
|
121
|
+const { proxy } = getCurrentInstance();
|
|
122
|
+
|
|
123
|
+const topicList = ref([]);
|
|
124
|
+const open = ref(false);
|
|
125
|
+const loading = ref(true);
|
|
126
|
+const showSearch = ref(true);
|
|
127
|
+const ids = ref([]);
|
|
128
|
+const single = ref(true);
|
|
129
|
+const multiple = ref(true);
|
|
130
|
+const total = ref(0);
|
|
131
|
+const title = ref("");
|
|
132
|
+const hasRecords = ref(false);
|
|
133
|
+const classifiedRecent = ref({
|
|
134
|
+ today: [],
|
|
135
|
+ yesterday: [],
|
|
136
|
+ dayBeforeYesterday: [],
|
|
137
|
+ within7Days: [],
|
|
138
|
+ within30Days: []
|
|
139
|
+});
|
|
140
|
+const classifiedMonthly = ref({});
|
|
141
|
+
|
|
142
|
+const enableEdit = (item) => {
|
|
143
|
+ item.isEditing = true;
|
|
144
|
+};
|
|
145
|
+
|
|
146
|
+const disableEdit = (item) => {
|
|
147
|
+ item.isEditing = false;
|
|
148
|
+};
|
|
149
|
+const data = reactive({
|
|
150
|
+ form: {},
|
|
151
|
+ queryParams: {
|
|
152
|
+ pageNum: 1,
|
|
153
|
+ pageSize: 99999,
|
|
154
|
+ topic: null,
|
|
155
|
+ },
|
|
156
|
+ rules: {
|
|
157
|
+ }
|
|
158
|
+});
|
|
159
|
+
|
|
160
|
+const { queryParams, form, rules } = toRefs(data);
|
|
161
|
+
|
|
162
|
+/** 查询cmc聊天主题列表 */
|
|
163
|
+const getList = async () => {
|
|
164
|
+ try {
|
|
165
|
+ loading.value = true;
|
|
166
|
+ let response = await listTopic(queryParams.value);
|
|
167
|
+ if (response.total > 0) {
|
|
168
|
+ topicList.value = response.rows;
|
|
169
|
+ total.value = response.total;
|
|
170
|
+ loading.value = false;
|
|
171
|
+ hasRecords.value = true;
|
|
172
|
+ // 分类近期记录
|
|
173
|
+
|
|
174
|
+ const today = new Date()
|
|
175
|
+ today.setHours(0, 0, 0, 0)
|
|
176
|
+
|
|
177
|
+ const yesterday = new Date(today)
|
|
178
|
+ yesterday.setDate(yesterday.getDate() - 1)
|
|
179
|
+
|
|
180
|
+ const dayBeforeYesterday = new Date(today)
|
|
181
|
+ dayBeforeYesterday.setDate(dayBeforeYesterday.getDate() - 2)
|
|
182
|
+
|
|
183
|
+ const sevenDaysAgo = new Date(today)
|
|
184
|
+ sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7)
|
|
185
|
+
|
|
186
|
+ const thirtyDaysAgo = new Date(today)
|
|
187
|
+ thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30)
|
|
188
|
+
|
|
189
|
+ topicList.value.forEach(record => {
|
|
190
|
+ const recordDate = new Date(record.createTime)
|
|
191
|
+ recordDate.setHours(0, 0, 0, 0)
|
|
192
|
+
|
|
193
|
+ if (recordDate.getTime() === today.getTime()) {
|
|
194
|
+ classifiedRecent.value.today.push(record)
|
|
195
|
+ } else if (recordDate.getTime() === yesterday.getTime()) {
|
|
196
|
+ classifiedRecent.value.yesterday.push(record)
|
|
197
|
+ } else if (recordDate.getTime() === dayBeforeYesterday.getTime()) {
|
|
198
|
+ classifiedRecent.value.dayBeforeYesterday.push(record)
|
|
199
|
+ } else if (recordDate > sevenDaysAgo) {
|
|
200
|
+ classifiedRecent.value.within7Days.push(record)
|
|
201
|
+ } else if (recordDate > thirtyDaysAgo) {
|
|
202
|
+ classifiedRecent.value.within30Days.push(record)
|
|
203
|
+ } else if (recordDate <= thirtyDaysAgo) {
|
|
204
|
+ const monthKey = getMonthKey(recordDate)
|
|
205
|
+
|
|
206
|
+ if (!classifiedMonthly.value[monthKey]) {
|
|
207
|
+ classifiedMonthly.value[monthKey] = []
|
|
208
|
+ }
|
|
209
|
+
|
|
210
|
+ classifiedMonthly.value[monthKey].push(record)
|
|
211
|
+ }
|
|
212
|
+ })
|
|
213
|
+ }
|
|
214
|
+ } catch (err) {
|
|
215
|
+ console.error('获取数据失败:', err)
|
|
216
|
+ } finally {
|
|
217
|
+ loading.value = false
|
|
218
|
+ }
|
|
219
|
+}
|
|
220
|
+// 获取排序后的月份键
|
|
221
|
+const sortedMonthlyKeys = computed(() => {
|
|
222
|
+ return Object.keys(classifiedMonthly.value).sort((a, b) => new Date(b) - new Date(a))
|
|
223
|
+})
|
|
224
|
+
|
|
225
|
+// 获取月份键 (yyyy-MM)
|
|
226
|
+const getMonthKey = (date) => {
|
|
227
|
+ const year = date.getFullYear()
|
|
228
|
+ const month = (date.getMonth() + 1).toString().padStart(2, '0')
|
|
229
|
+ return `${year}-${month}`
|
|
230
|
+}
|
|
231
|
+
|
|
232
|
+// 格式化月份显示
|
|
233
|
+const formatMonth = (monthKey) => {
|
|
234
|
+ const [year, month] = monthKey.split('-')
|
|
235
|
+ return `${year}-${month}`
|
|
236
|
+}
|
|
237
|
+
|
|
238
|
+// 日期格式化
|
|
239
|
+const formatDate = (date) => {
|
|
240
|
+ const d = new Date(date)
|
|
241
|
+ return `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')}`
|
|
242
|
+}
|
|
243
|
+onMounted(() => {
|
|
244
|
+ getList();
|
|
245
|
+})
|
|
246
|
+</script>
|
|
247
|
+<style lang="scss" scoped>
|
|
248
|
+.home-view {
|
|
249
|
+ display: flex;
|
|
250
|
+ /* 与窗口同宽 */
|
|
251
|
+ width: 100vw;
|
|
252
|
+
|
|
253
|
+ .chat-panel {
|
|
254
|
+ /* 聊天面板flex布局,让会话列表和聊天记录左右展示 */
|
|
255
|
+ display: flex;
|
|
256
|
+ /* 让聊天面板圆润一些 */
|
|
257
|
+ border-radius: 4px;
|
|
258
|
+ background-color: white;
|
|
259
|
+ /* 给一些阴影 */
|
|
260
|
+ box-shadow: 0 0 4px 4px rgba(black, 0.05);
|
|
261
|
+ /* 与上方增加一些间距 */
|
|
262
|
+ margin-top: 4px;
|
|
263
|
+
|
|
264
|
+ /* 左侧聊天会话面板*/
|
|
265
|
+ .session-panel {
|
|
266
|
+ background-color: rgb(249 251 255);
|
|
267
|
+ width: 12vw;
|
|
268
|
+ border-top-left-radius: 4px;
|
|
269
|
+ border-bottom-left-radius: 4px;
|
|
270
|
+ position: relative;
|
|
271
|
+ border-right: 1px solid rgba(black, 0.07);
|
|
272
|
+ }
|
|
273
|
+
|
|
274
|
+ /* 右侧消息记录面板*/
|
|
275
|
+ .message-panel {
|
|
276
|
+ width: 88vw;
|
|
277
|
+ height: 90vh;
|
|
278
|
+ }
|
|
279
|
+ }
|
|
280
|
+}
|
|
281
|
+
|
|
282
|
+.category-title {
|
|
283
|
+ padding: 0 10px;
|
|
284
|
+ font-size: 12px;
|
|
285
|
+ font-weight: bold;
|
|
286
|
+ line-height: 30px;
|
|
287
|
+ color: #333;
|
|
288
|
+ background-color: rgb(249 251 255);
|
|
289
|
+}
|
|
290
|
+
|
|
291
|
+.record {
|
|
292
|
+ z-index: 1;
|
|
293
|
+ white-space: nowrap;
|
|
294
|
+ line-height: 30px;
|
|
295
|
+ color: #4c4c4c;
|
|
296
|
+ background-color: rgb(249 251 255);
|
|
297
|
+ cursor: pointer;
|
|
298
|
+ border-radius: 12px;
|
|
299
|
+ align-items: center;
|
|
300
|
+ padding: 0 10px;
|
|
301
|
+ font-size: 12px;
|
|
302
|
+ display: flex;
|
|
303
|
+ position: relative;
|
|
304
|
+}
|
|
305
|
+
|
|
306
|
+.spacer {
|
|
307
|
+ height: 20px;
|
|
308
|
+ clear: both;
|
|
309
|
+}
|
|
310
|
+
|
|
311
|
+.empty {
|
|
312
|
+ padding: 0 10px;
|
|
313
|
+ color: #909399;
|
|
314
|
+}
|
|
315
|
+
|
|
316
|
+.top-plus-button {
|
|
317
|
+ margin-top: 20px;
|
|
318
|
+}
|
|
319
|
+
|
|
320
|
+.right-delete-button {
|
|
321
|
+ opacity: 0;
|
|
322
|
+ z-index: 2;
|
|
323
|
+ justify-content: left;
|
|
324
|
+ align-items: center;
|
|
325
|
+ width: 12px;
|
|
326
|
+ height: 12px;
|
|
327
|
+ display: flex;
|
|
328
|
+ position: absolute;
|
|
329
|
+ top: 50%;
|
|
330
|
+ right: 0px;
|
|
331
|
+ transform: translateY(-50%);
|
|
332
|
+}
|
|
333
|
+
|
|
334
|
+.right-delete-button:hover {
|
|
335
|
+ opacity: 1;
|
|
336
|
+ z-index: 2;
|
|
337
|
+ background: linear-gradient(90deg, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 1), rgba(255, 255, 255, 1));
|
|
338
|
+ color: rgb(70, 70, 70);
|
|
339
|
+ justify-content: left;
|
|
340
|
+ align-items: center;
|
|
341
|
+ width: 12px;
|
|
342
|
+ height: 12px;
|
|
343
|
+ display: flex;
|
|
344
|
+ position: absolute;
|
|
345
|
+ top: 50%;
|
|
346
|
+ right: 0px;
|
|
347
|
+ transform: translateY(-50%);
|
|
348
|
+}
|
|
349
|
+</style>
|