feat(sessions): add keyword search, user-scoped pinning, and IM source visibility
Sessions today are a flat list ordered by updated_at. Two gaps showed up in practice: - Users cannot find specific chats as the list grows beyond a screen. - IM-created sessions (WeCom/Feishu/Slack/...) are indistinguishable: every title was "IM-<platform>" or "IM-<platform>-<username>" and the list API hid the underlying im_channel_sessions mapping, so admins had no way to tell which Feishu group a session came from. Backend - Migration 000039 adds sessions.user_id (owner), is_pinned, pinned_at plus a composite index for the list query. Existing rows keep user_id NULL and stay visible at the tenant level for backward compatibility. - CreateSession now writes the caller's user_id from auth context. - GET /sessions accepts keyword / source / agent_id. When any filter is set, the response switches to enriched items that LEFT JOIN im_channel_sessions and expose im_platform / im_chat_id / im_thread_id / im_user_id / im_agent_id / im_channel_id. No filters => legacy shape, existing clients unaffected. - Ordering: is_pinned DESC, pinned_at DESC NULLS LAST, updated_at DESC. - POST/DELETE /sessions/:id/pin for user-scoped pin/unpin. - IM session titles: "[platform] <user|chat|thread>" with short ID suffixes so group/DM/thread sessions are visually distinct without needing a round-trip to fetch a display name from the IM adapter. Frontend - Search input debounced at 300ms drives the keyword filter. - Pinned chats render in a dedicated group above the time-based groups, with a pin icon and a pin/unpin entry in the per-chat dropdown. - IM chats get a short [platform] badge in the list. - Pin toggle is optimistic and guards against double-clicks. - zh/en/ko/ru i18n keys added for the new strings.
This commit is contained in:
@@ -6,8 +6,26 @@ export async function createSessions(data = {}) {
|
||||
return post("/api/v1/sessions", data);
|
||||
}
|
||||
|
||||
export async function getSessionsList(page: number, page_size: number) {
|
||||
return get(`/api/v1/sessions?page=${page}&page_size=${page_size}`);
|
||||
export async function getSessionsList(
|
||||
page: number,
|
||||
page_size: number,
|
||||
filters: { keyword?: string; source?: string; agent_id?: string } = {}
|
||||
) {
|
||||
const params = new URLSearchParams();
|
||||
params.set("page", String(page));
|
||||
params.set("page_size", String(page_size));
|
||||
if (filters.keyword) params.set("keyword", filters.keyword);
|
||||
if (filters.source) params.set("source", filters.source);
|
||||
if (filters.agent_id) params.set("agent_id", filters.agent_id);
|
||||
return get(`/api/v1/sessions?${params.toString()}`);
|
||||
}
|
||||
|
||||
export async function pinSession(session_id: string) {
|
||||
return post(`/api/v1/sessions/${session_id}/pin`, {});
|
||||
}
|
||||
|
||||
export async function unpinSession(session_id: string) {
|
||||
return del(`/api/v1/sessions/${session_id}/pin`);
|
||||
}
|
||||
|
||||
export async function generateSessionsTitle(session_id: string, data: any) {
|
||||
|
||||
@@ -61,6 +61,18 @@
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<div ref="submenuscrollContainer" @scroll="handleScroll" class="submenu" v-if="item.children && !uiStore.sidebarCollapsed">
|
||||
<!-- 搜索输入 -->
|
||||
<div class="submenu_search" v-if="!batchMode">
|
||||
<t-input
|
||||
v-model="searchKeyword"
|
||||
:placeholder="t('menu.searchPlaceholder')"
|
||||
size="small"
|
||||
clearable
|
||||
@input="onSearchKeywordChange"
|
||||
@clear="onSearchKeywordChange">
|
||||
<template #prefix-icon><t-icon name="search" /></template>
|
||||
</t-input>
|
||||
</div>
|
||||
<!-- 骨架屏占位 -->
|
||||
<template v-if="loading && groupedSessions.length === 0">
|
||||
<div v-for="n in 5" :key="'skel-'+n" class="submenu_item_p">
|
||||
@@ -83,10 +95,12 @@
|
||||
/>
|
||||
<span class="submenu_title"
|
||||
:style="batchMode ? 'margin-left:4px;max-width:170px;' : (currentSecondpath == subitem.path ? 'margin-left:18px;max-width:160px;' : 'margin-left:18px;max-width:185px;')">
|
||||
<t-icon v-if="subitem.is_pinned" name="push-pin" class="submenu_pin_icon" :title="t('menu.pinned')" />
|
||||
<span v-if="subitem.source_label" class="submenu_source_badge">{{ subitem.source_label }}</span>
|
||||
{{ subitem.title }}
|
||||
</span>
|
||||
<t-dropdown v-if="!batchMode"
|
||||
:options="[{ content: t('menu.clearMessages'), value: 'clearMessages', prefixIcon: () => h(TIcon, { name: 'clear', size: '16px' }) }, { content: t('menu.batchManage'), value: 'batchManage', prefixIcon: () => h(TIcon, { name: 'queue', size: '16px' }) }, { content: t('upload.deleteRecord'), value: 'delete', theme: 'error', prefixIcon: () => h(TIcon, { name: 'delete', size: '16px' }) }]"
|
||||
:options="buildSessionMenuOptions(subitem)"
|
||||
@click="handleSessionMenuClick($event, subitem.originalIndex, subitem)"
|
||||
placement="bottom-right"
|
||||
trigger="click">
|
||||
@@ -135,7 +149,7 @@
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { onMounted, watch, computed, ref, h } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { getSessionsList, delSession, batchDelSessions, deleteAllSessions, clearSessionMessages } from "@/api/chat/index";
|
||||
import { getSessionsList, delSession, batchDelSessions, deleteAllSessions, clearSessionMessages, pinSession, unpinSession } from "@/api/chat/index";
|
||||
import { getKnowledgeBaseById } from '@/api/knowledge-base';
|
||||
import { logout as logoutApi } from '@/api/auth';
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
@@ -281,6 +295,11 @@ const bottomMenuItems = computed<MenuItem[]>(() => {
|
||||
const currentKbName = ref<string>('')
|
||||
const currentKbInfo = ref<any>(null)
|
||||
|
||||
// 搜索关键字(节流后触发后端 keyword 过滤)
|
||||
const searchKeyword = ref<string>('')
|
||||
// 进行中的置顶/取消置顶请求,避免重复点击
|
||||
const pinningIds = ref<Set<string>>(new Set())
|
||||
|
||||
// 时间分组函数
|
||||
const getTimeCategory = (dateStr: string): string => {
|
||||
if (!dateStr) return t('time.earlier');
|
||||
@@ -310,14 +329,16 @@ const getTimeCategory = (dateStr: string): string => {
|
||||
}
|
||||
};
|
||||
|
||||
// 按时间分组Session列表
|
||||
// 按时间分组Session列表,置顶会话单独置于最上方
|
||||
const groupedSessions = computed(() => {
|
||||
const chatMenu = (menuArr.value as unknown as MenuItem[]).find((item: MenuItem) => item.path === 'creatChat');
|
||||
if (!chatMenu || !chatMenu.children || chatMenu.children.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
const pinnedLabel = t('time.pinned');
|
||||
const groups: { [key: string]: any[] } = {
|
||||
[pinnedLabel]: [],
|
||||
[t('time.today')]: [],
|
||||
[t('time.yesterday')]: [],
|
||||
[t('time.last7Days')]: [],
|
||||
@@ -325,18 +346,19 @@ const groupedSessions = computed(() => {
|
||||
[t('time.lastYear')]: [],
|
||||
[t('time.earlier')]: []
|
||||
};
|
||||
|
||||
// 将sessions按时间分组
|
||||
|
||||
(chatMenu.children as any[]).forEach((session: any, index: number) => {
|
||||
const withIndex = { ...session, originalIndex: index };
|
||||
if (session.is_pinned) {
|
||||
groups[pinnedLabel].push(withIndex);
|
||||
return;
|
||||
}
|
||||
const category = getTimeCategory(session.updated_at || session.created_at);
|
||||
groups[category].push({
|
||||
...session,
|
||||
originalIndex: index
|
||||
});
|
||||
groups[category].push(withIndex);
|
||||
});
|
||||
|
||||
// 按顺序返回非空分组
|
||||
const orderedLabels = [t('time.today'), t('time.yesterday'), t('time.last7Days'), t('time.last30Days'), t('time.lastYear'), t('time.earlier')];
|
||||
|
||||
// 按顺序返回非空分组(置顶组在最上方)
|
||||
const orderedLabels = [pinnedLabel, t('time.today'), t('time.yesterday'), t('time.last7Days'), t('time.last30Days'), t('time.lastYear'), t('time.earlier')];
|
||||
return orderedLabels
|
||||
.filter(label => groups[label].length > 0)
|
||||
.map(label => ({
|
||||
@@ -438,9 +460,76 @@ const handleSessionMenuClick = (data: { value: string }, index: number, item: an
|
||||
clearMessages(item);
|
||||
} else if (data?.value === 'batchManage') {
|
||||
enterBatchMode()
|
||||
} else if (data?.value === 'pin' || data?.value === 'unpin') {
|
||||
togglePin(item, data.value === 'pin');
|
||||
}
|
||||
};
|
||||
|
||||
// 基于会话来源推导展示用的短标签。IM 会话的 title 已经用 "[platform] ..." 前缀表达来源,
|
||||
// 这里只在列表里加一个可过滤/可见的简短标签,Web 会话保持无标签。
|
||||
const deriveSourceLabel = (item: any): string => {
|
||||
if (item?.im_platform) {
|
||||
return `[${item.im_platform}]`;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
const buildSessionMenuOptions = (item: any) => {
|
||||
const options: any[] = [];
|
||||
if (item.is_pinned) {
|
||||
options.push({
|
||||
content: t('menu.unpin'),
|
||||
value: 'unpin',
|
||||
prefixIcon: () => h(TIcon, { name: 'push-pin', size: '16px' }),
|
||||
});
|
||||
} else {
|
||||
options.push({
|
||||
content: t('menu.pin'),
|
||||
value: 'pin',
|
||||
prefixIcon: () => h(TIcon, { name: 'push-pin', size: '16px' }),
|
||||
});
|
||||
}
|
||||
options.push(
|
||||
{ content: t('menu.clearMessages'), value: 'clearMessages', prefixIcon: () => h(TIcon, { name: 'clear', size: '16px' }) },
|
||||
{ content: t('menu.batchManage'), value: 'batchManage', prefixIcon: () => h(TIcon, { name: 'queue', size: '16px' }) },
|
||||
{ content: t('upload.deleteRecord'), value: 'delete', theme: 'error', prefixIcon: () => h(TIcon, { name: 'delete', size: '16px' }) },
|
||||
);
|
||||
return options;
|
||||
};
|
||||
|
||||
const togglePin = (item: any, pin: boolean) => {
|
||||
if (pinningIds.value.has(item.id)) return;
|
||||
pinningIds.value.add(item.id);
|
||||
|
||||
const call = pin ? pinSession(item.id) : unpinSession(item.id);
|
||||
call.then((res: any) => {
|
||||
if (res && res.success) {
|
||||
// 乐观更新本地列表项,避免整表重拉引起抖动。
|
||||
const chatMenu = (menuArr.value as any[]).find((m: any) => m.path === 'creatChat');
|
||||
const target = chatMenu?.children?.find((s: any) => s.id === item.id);
|
||||
if (target) {
|
||||
target.is_pinned = pin;
|
||||
target.pinned_at = pin ? new Date().toISOString() : null;
|
||||
}
|
||||
} else {
|
||||
MessagePlugin.error(pin ? t('menu.pinFailed') : t('menu.unpinFailed'));
|
||||
}
|
||||
}).catch(() => {
|
||||
MessagePlugin.error(pin ? t('menu.pinFailed') : t('menu.unpinFailed'));
|
||||
}).finally(() => {
|
||||
pinningIds.value.delete(item.id);
|
||||
});
|
||||
};
|
||||
|
||||
// 搜索框输入节流:延迟 300ms 触发一次后端查询。
|
||||
let searchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
const onSearchKeywordChange = () => {
|
||||
if (searchTimer) clearTimeout(searchTimer);
|
||||
searchTimer = setTimeout(() => {
|
||||
getMessageList();
|
||||
}, 300);
|
||||
};
|
||||
|
||||
const clearMessages = (item: any) => {
|
||||
clearSessionMessages(item.id).then((res: any) => {
|
||||
if (res && res.success) {
|
||||
@@ -511,25 +600,33 @@ const handleScroll = debounce(checkScrollBottom, 200)
|
||||
const getMessageList = async (isLoadMore = false) => {
|
||||
if (loading.value) return Promise.resolve();
|
||||
loading.value = true;
|
||||
|
||||
|
||||
// 只有在首次加载或路由变化时才清空数组,滚动加载时不清空
|
||||
if (!isLoadMore) {
|
||||
currentPage.value = 1; // 重置页码
|
||||
usemenuStore.clearMenuArr();
|
||||
}
|
||||
|
||||
return getSessionsList(currentPage.value, page_size.value).then((res: any) => {
|
||||
|
||||
const filters: { keyword?: string } = {};
|
||||
const kw = searchKeyword.value.trim();
|
||||
if (kw) filters.keyword = kw;
|
||||
|
||||
return getSessionsList(currentPage.value, page_size.value, filters).then((res: any) => {
|
||||
if (res.data && res.data.length) {
|
||||
// Display all sessions globally without filtering
|
||||
res.data.forEach((item: any) => {
|
||||
let obj = {
|
||||
let obj = {
|
||||
title: item.title ? item.title : t('menu.newSession'),
|
||||
path: `chat/${item.id}`,
|
||||
id: item.id,
|
||||
isMore: false,
|
||||
path: `chat/${item.id}`,
|
||||
id: item.id,
|
||||
isMore: false,
|
||||
isNoTitle: item.title ? false : true,
|
||||
created_at: item.created_at,
|
||||
updated_at: item.updated_at
|
||||
updated_at: item.updated_at,
|
||||
is_pinned: !!item.is_pinned,
|
||||
pinned_at: item.pinned_at || null,
|
||||
im_platform: item.im_platform || '',
|
||||
source_label: deriveSourceLabel(item),
|
||||
}
|
||||
usemenuStore.updatemenuArr(obj)
|
||||
});
|
||||
@@ -1032,6 +1129,29 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
|
||||
min-height: 0;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.submenu_search {
|
||||
padding: 8px 12px 4px 12px;
|
||||
}
|
||||
|
||||
.submenu_pin_icon {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: 12px;
|
||||
margin-right: 4px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.submenu_source_badge {
|
||||
display: inline-block;
|
||||
padding: 0 6px;
|
||||
margin-right: 6px;
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
color: var(--td-text-color-secondary);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-radius: 4px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@keyframes menuItemFadeIn {
|
||||
from { opacity: 0; transform: translateX(-4px); }
|
||||
|
||||
@@ -15,6 +15,14 @@ export default {
|
||||
clearMessagesFailed: 'Failed to clear messages, please try again later',
|
||||
batchManage: 'Batch Manage',
|
||||
newSession: 'New Chat',
|
||||
pin: 'Pin',
|
||||
unpin: 'Unpin',
|
||||
pinned: 'Pinned',
|
||||
pinFailed: 'Failed to pin, please try again later',
|
||||
unpinFailed: 'Failed to unpin, please try again later',
|
||||
searchPlaceholder: 'Search chats',
|
||||
sourceWeb: 'Web',
|
||||
sourceIM: 'IM',
|
||||
confirmLogout: 'Are you sure you want to logout?',
|
||||
systemInfo: 'System Information',
|
||||
knowledgeSearch: 'Search',
|
||||
@@ -2576,7 +2584,8 @@ export default {
|
||||
last7Days: 'Last 7 Days',
|
||||
last30Days: 'Last 30 Days',
|
||||
lastYear: 'Last Year',
|
||||
earlier: 'Earlier'
|
||||
earlier: 'Earlier',
|
||||
pinned: 'Pinned',
|
||||
},
|
||||
upload: {
|
||||
uploadDocument: 'Upload Document',
|
||||
|
||||
@@ -15,6 +15,14 @@ export default {
|
||||
clearMessagesFailed: "메시지 지우기 실패, 나중에 다시 시도해 주세요",
|
||||
batchManage: "일괄 관리",
|
||||
newSession: "새 세션",
|
||||
pin: "고정",
|
||||
unpin: "고정 해제",
|
||||
pinned: "고정됨",
|
||||
pinFailed: "고정 실패, 나중에 다시 시도해 주세요",
|
||||
unpinFailed: "고정 해제 실패, 나중에 다시 시도해 주세요",
|
||||
searchPlaceholder: "대화 검색",
|
||||
sourceWeb: "웹",
|
||||
sourceIM: "IM",
|
||||
confirmLogout: "정말 로그아웃 하시겠습니까?",
|
||||
systemInfo: "시스템 정보",
|
||||
knowledgeSearch: "검색",
|
||||
@@ -1947,6 +1955,7 @@ export default {
|
||||
last30Days: "최근 30일",
|
||||
lastYear: "최근 1년",
|
||||
earlier: "이전",
|
||||
pinned: "고정됨",
|
||||
},
|
||||
upload: {
|
||||
uploadDocument: "문서 업로드",
|
||||
|
||||
@@ -13,6 +13,14 @@ export default {
|
||||
clearMessagesFailed: 'Не удалось очистить сообщения, попробуйте позже',
|
||||
batchManage: 'Пакетное управление',
|
||||
newSession: 'Новый диалог',
|
||||
pin: 'Закрепить',
|
||||
unpin: 'Открепить',
|
||||
pinned: 'Закреплено',
|
||||
pinFailed: 'Не удалось закрепить, попробуйте позже',
|
||||
unpinFailed: 'Не удалось открепить, попробуйте позже',
|
||||
searchPlaceholder: 'Поиск диалогов',
|
||||
sourceWeb: 'Веб',
|
||||
sourceIM: 'IM',
|
||||
confirmLogout: 'Вы уверены, что хотите выйти?',
|
||||
systemInfo: 'Информация о системе',
|
||||
knowledgeSearch: 'Поиск',
|
||||
@@ -2383,7 +2391,8 @@ export default {
|
||||
last7Days: 'Последние 7 дней',
|
||||
last30Days: 'Последние 30 дней',
|
||||
lastYear: 'Последний год',
|
||||
earlier: 'Ранее'
|
||||
earlier: 'Ранее',
|
||||
pinned: 'Закреплено',
|
||||
},
|
||||
upload: {
|
||||
uploadDocument: 'Загрузить документ',
|
||||
|
||||
@@ -15,6 +15,14 @@ export default {
|
||||
clearMessagesFailed: "清空消息失败,请稍后再试",
|
||||
batchManage: "批量管理",
|
||||
newSession: "新会话",
|
||||
pin: "置顶",
|
||||
unpin: "取消置顶",
|
||||
pinned: "已置顶",
|
||||
pinFailed: "置顶失败,请稍后再试",
|
||||
unpinFailed: "取消置顶失败,请稍后再试",
|
||||
searchPlaceholder: "搜索会话",
|
||||
sourceWeb: "网页",
|
||||
sourceIM: "IM",
|
||||
confirmLogout: "确定要退出登录吗?",
|
||||
systemInfo: "系统信息",
|
||||
knowledgeSearch: "搜索",
|
||||
@@ -1925,6 +1933,7 @@ export default {
|
||||
last30Days: "近30天",
|
||||
lastYear: "近1年",
|
||||
earlier: "更早",
|
||||
pinned: "已置顶",
|
||||
},
|
||||
upload: {
|
||||
uploadDocument: "上传文档",
|
||||
|
||||
Reference in New Issue
Block a user