mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 05:09:19 +08:00
Compare commits
3
Commits
0b460e22b0
...
883a1d0cfe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
883a1d0cfe | ||
|
|
67d01c678a | ||
|
|
a72a43cffc |
@@ -1,7 +1,8 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { Tooltip, message } from 'ant-design-vue';
|
||||
import { ChatSender } from '@tdesign-vue-next/chat';
|
||||
|
||||
import { getProductPageApi } from '#/api/ec/product';
|
||||
@@ -19,11 +20,15 @@ import {
|
||||
type CatalogCiteKind,
|
||||
} from './catalog-cite';
|
||||
|
||||
const ArrowUpIcon = createIconifyIcon('lucide:arrow-up');
|
||||
const ExpandIcon = createIconifyIcon('lucide:maximize-2');
|
||||
const CollapseIcon = createIconifyIcon('lucide:minimize-2');
|
||||
|
||||
/** 包一层 ChatSender:@ 先选分类,选中后在输入行内嵌标签。 */
|
||||
const draft = defineModel<string>({ required: true });
|
||||
const cites = defineModel<CatalogCite[]>('cites', { required: true });
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
loading?: boolean;
|
||||
}>();
|
||||
|
||||
@@ -39,6 +44,10 @@ const dismissed = ref(false);
|
||||
const loadingList = ref(false);
|
||||
const activeKey = ref('');
|
||||
const items = ref<CatalogCite[]>([]);
|
||||
/** 输入框是否已手动展开 */
|
||||
const expanded = ref(false);
|
||||
/** 内容是否超过 1 行(用于显示右上角展开按钮) */
|
||||
const multiLine = ref(false);
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
let seq = 0;
|
||||
|
||||
@@ -47,6 +56,19 @@ const menuOpen = computed(
|
||||
() => mentionQuery.value !== null && !dismissed.value,
|
||||
);
|
||||
|
||||
/** 未展开:1~14 行自动增高;展开后再抬高上限 */
|
||||
const textareaAutosize = computed(() =>
|
||||
expanded.value
|
||||
? { minRows: 8, maxRows: 28 }
|
||||
: { minRows: 1, maxRows: 14 },
|
||||
);
|
||||
|
||||
const showExpandToggle = computed(() => expanded.value || multiLine.value);
|
||||
|
||||
const canSend = computed(
|
||||
() => !props.loading && !!(draft.value || '').trim(),
|
||||
);
|
||||
|
||||
watch(mentionQuery, (query, prev) => {
|
||||
if (query !== prev) {
|
||||
dismissed.value = false;
|
||||
@@ -67,6 +89,14 @@ watch(kind, () => {
|
||||
scheduleSearch(mentionQuery.value);
|
||||
});
|
||||
|
||||
watch(draft, () => {
|
||||
checkMultiLine();
|
||||
});
|
||||
|
||||
watch(expanded, () => {
|
||||
void nextTick(() => checkMultiLine());
|
||||
});
|
||||
|
||||
function scheduleSearch(query: string) {
|
||||
if (timer) clearTimeout(timer);
|
||||
loadingList.value = true;
|
||||
@@ -131,7 +161,93 @@ async function safeList(task: Promise<CatalogCite[]>) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 按可视行数判断:超过 1 行就稳定显示展开按钮(不依赖 scroll overflow,避免 autosize 时闪烁消失) */
|
||||
function checkMultiLine() {
|
||||
const run = () => {
|
||||
const el = rootRef.value?.querySelector('textarea');
|
||||
if (!el) {
|
||||
multiLine.value = false;
|
||||
return;
|
||||
}
|
||||
if (expanded.value) {
|
||||
multiLine.value = true;
|
||||
return;
|
||||
}
|
||||
const text = draft.value || '';
|
||||
if (!text) {
|
||||
multiLine.value = false;
|
||||
return;
|
||||
}
|
||||
// 显式换行
|
||||
if (text.includes('\n')) {
|
||||
multiLine.value = true;
|
||||
return;
|
||||
}
|
||||
const style = window.getComputedStyle(el);
|
||||
const lineHeight = parseFloat(style.lineHeight);
|
||||
const fontSize = parseFloat(style.fontSize) || 14;
|
||||
const lh =
|
||||
Number.isFinite(lineHeight) && lineHeight > 0 ? lineHeight : fontSize * 1.5;
|
||||
const padY =
|
||||
(parseFloat(style.paddingTop) || 0) +
|
||||
(parseFloat(style.paddingBottom) || 0);
|
||||
// scrollHeight 在 autosize 下仍反映内容总高度
|
||||
const rows = Math.max(1, Math.round((el.scrollHeight - padY) / lh));
|
||||
multiLine.value = rows > 1;
|
||||
};
|
||||
// 等 autosize 改完高度再量,避免中间态误判
|
||||
void nextTick(() => {
|
||||
requestAnimationFrame(run);
|
||||
});
|
||||
}
|
||||
|
||||
function toggleExpand() {
|
||||
expanded.value = !expanded.value;
|
||||
focusInput();
|
||||
}
|
||||
|
||||
function onSendClick() {
|
||||
const text = draft.value;
|
||||
if (!text?.trim() || props.loading) return;
|
||||
emit('send', text);
|
||||
resetExpandAfterSend();
|
||||
}
|
||||
|
||||
function onChatSend(value: string) {
|
||||
emit('send', value);
|
||||
resetExpandAfterSend();
|
||||
}
|
||||
|
||||
function resetExpandAfterSend() {
|
||||
expanded.value = false;
|
||||
multiLine.value = false;
|
||||
}
|
||||
|
||||
function onStopClick() {
|
||||
emit('stop');
|
||||
}
|
||||
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
// 光标在输入框开头(或内容为空)时,Backspace 删掉最后一个引用 chip
|
||||
if (
|
||||
event.key === 'Backspace' &&
|
||||
!event.isComposing &&
|
||||
event.keyCode !== 229 &&
|
||||
cites.value.length > 0
|
||||
) {
|
||||
const el = rootRef.value?.querySelector('textarea');
|
||||
if (el) {
|
||||
const atStart = el.selectionStart === 0 && el.selectionEnd === 0;
|
||||
if (atStart || !draft.value) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const last = cites.value[cites.value.length - 1];
|
||||
if (last) removeCite(last.key);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!menuOpen.value || event.isComposing || event.keyCode === 229) return;
|
||||
if (event.key === 'ArrowDown') {
|
||||
event.preventDefault();
|
||||
@@ -228,17 +344,40 @@ onBeforeUnmount(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="rootRef" class="catalog-cite-sender relative" @keydown.capture="onKeydown">
|
||||
<div
|
||||
ref="rootRef"
|
||||
class="catalog-cite-sender relative"
|
||||
:class="{ 'catalog-cite-sender--expandable': showExpandToggle }"
|
||||
@keydown.capture="onKeydown"
|
||||
>
|
||||
<!-- 展开/收起固定在输入框右上角 -->
|
||||
<Tooltip
|
||||
v-if="showExpandToggle"
|
||||
:title="expanded ? '收起输入框' : '展开输入框'"
|
||||
placement="top"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="sender-expand-corner text-muted-foreground hover:text-foreground hover:bg-muted"
|
||||
:aria-label="expanded ? '收起输入框' : '展开输入框'"
|
||||
@mousedown.prevent
|
||||
@click="toggleExpand"
|
||||
>
|
||||
<CollapseIcon v-if="expanded" class="size-4" />
|
||||
<ExpandIcon v-else class="size-4" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
<div
|
||||
v-if="menuOpen"
|
||||
class="border-border bg-card absolute bottom-full left-0 z-20 mb-2 w-80 overflow-hidden rounded-lg border shadow-lg"
|
||||
class="border-border bg-popover absolute bottom-full left-0 z-20 mb-2 w-80 overflow-hidden rounded-lg border shadow-lg"
|
||||
>
|
||||
<div class="flex gap-1 p-1.5">
|
||||
<div class="flex shrink-0 gap-1 p-1.5">
|
||||
<button
|
||||
v-for="item in kinds"
|
||||
:key="item"
|
||||
type="button"
|
||||
class="flex-1 rounded-md px-2 py-1.5 text-xs"
|
||||
class="flex-1 cursor-pointer rounded-md px-2 py-1.5 text-xs"
|
||||
:class="
|
||||
item === kind
|
||||
? 'bg-primary/10 text-primary font-medium'
|
||||
@@ -249,16 +388,17 @@ onBeforeUnmount(() => {
|
||||
{{ catalogCiteLabel(item) }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="max-h-72 overflow-y-auto py-1">
|
||||
<!-- 固定高度,避免加载前后弹层跳动 -->
|
||||
<div class="cite-menu-list h-72 overflow-y-auto py-1">
|
||||
<div
|
||||
v-if="loadingList && items.length === 0"
|
||||
class="text-muted-foreground px-3 py-6 text-center text-xs"
|
||||
class="text-muted-foreground flex h-full items-center justify-center px-3 text-center text-xs"
|
||||
>
|
||||
搜索中…
|
||||
</div>
|
||||
<div
|
||||
v-else-if="items.length === 0"
|
||||
class="text-muted-foreground px-3 py-6 text-center text-xs"
|
||||
class="text-muted-foreground flex h-full items-center justify-center px-3 text-center text-xs"
|
||||
>
|
||||
这个分类下没有匹配
|
||||
</div>
|
||||
@@ -268,7 +408,7 @@ onBeforeUnmount(() => {
|
||||
:key="item.key"
|
||||
type="button"
|
||||
:data-cite-key="item.key"
|
||||
class="flex w-full flex-col px-3 py-1.5 text-left"
|
||||
class="flex w-full cursor-pointer flex-col px-3 py-1.5 text-left"
|
||||
:class="item.key === activeKey ? 'bg-primary/10' : 'hover:bg-muted'"
|
||||
@mouseenter="activeKey = item.key"
|
||||
@mousedown.prevent="pick(item)"
|
||||
@@ -284,7 +424,7 @@ onBeforeUnmount(() => {
|
||||
</template>
|
||||
</div>
|
||||
<div class="text-muted-foreground border-border border-t px-3 py-1.5 text-[11px]">
|
||||
↑↓ 选择 · Enter 引用 · Esc 关闭
|
||||
↑↓ 选择 · Enter 引用 · Esc 关闭 · ⌫ 删引用
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -292,9 +432,9 @@ onBeforeUnmount(() => {
|
||||
v-model="draft"
|
||||
class="agent-td-sender"
|
||||
:loading="loading"
|
||||
placeholder="输入问题,@ 引用店铺、商品或 SKU"
|
||||
:textarea-props="{ autosize: { minRows: 2, maxRows: 6 } }"
|
||||
@send="emit('send', $event)"
|
||||
placeholder="问点什么,或用 @ 引用店铺 / 商品 / SKU"
|
||||
:textarea-props="{ autosize: textareaAutosize }"
|
||||
@send="onChatSend"
|
||||
@stop="emit('stop')"
|
||||
>
|
||||
<template #input-prefix>
|
||||
@@ -308,7 +448,7 @@ onBeforeUnmount(() => {
|
||||
<span class="truncate">{{ cite.title }}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="opacity-60 hover:opacity-100"
|
||||
class="cursor-pointer opacity-60 hover:opacity-100"
|
||||
aria-label="移除引用"
|
||||
@mousedown.prevent
|
||||
@click="removeCite(cite.key)"
|
||||
@@ -319,13 +459,44 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</template>
|
||||
<template #footer-prefix>
|
||||
<button
|
||||
type="button"
|
||||
class="text-muted-foreground hover:text-primary rounded px-1 py-1 text-xs"
|
||||
@click="insertMention"
|
||||
>
|
||||
@ 引用
|
||||
</button>
|
||||
<div class="catalog-cite-footer flex min-w-0 flex-1 items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="text-muted-foreground hover:text-primary shrink-0 cursor-pointer rounded px-1 py-1 text-xs"
|
||||
@click="insertMention"
|
||||
>
|
||||
@ 引用
|
||||
</button>
|
||||
<slot name="footer-extra"></slot>
|
||||
</div>
|
||||
</template>
|
||||
<template #suffix>
|
||||
<div class="sender-suffix flex items-center gap-1">
|
||||
<Tooltip v-if="loading" title="停止生成">
|
||||
<button
|
||||
type="button"
|
||||
class="sender-send-btn sender-send-btn--stop"
|
||||
aria-label="停止生成"
|
||||
@mousedown.prevent
|
||||
@click="onStopClick"
|
||||
>
|
||||
<span class="sender-stop-square" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Tooltip v-else title="发送">
|
||||
<button
|
||||
type="button"
|
||||
class="sender-send-btn"
|
||||
:class="{ 'sender-send-btn--disabled': !canSend }"
|
||||
:disabled="!canSend"
|
||||
aria-label="发送"
|
||||
@mousedown.prevent
|
||||
@click="onSendClick"
|
||||
>
|
||||
<ArrowUpIcon class="size-4" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</template>
|
||||
</ChatSender>
|
||||
</div>
|
||||
@@ -335,14 +506,32 @@ onBeforeUnmount(() => {
|
||||
.agent-td-sender {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.catalog-cite-sender :deep(.t-chat-sender__textarea__wrapper) {
|
||||
align-items: flex-start;
|
||||
padding: 0;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.catalog-cite-sender :deep(.t-textarea) {
|
||||
flex: 1;
|
||||
width: auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.catalog-cite-sender :deep(.t-textarea__inner) {
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.catalog-cite-sender--expandable :deep(.t-textarea__inner) {
|
||||
/* 给右上角展开按钮留出点击空间,避免文字压住图标 */
|
||||
padding-right: 28px !important;
|
||||
}
|
||||
|
||||
.catalog-cite-sender :deep(.t-chat-sender__footer) {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.cite-inline {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
@@ -354,4 +543,62 @@ onBeforeUnmount(() => {
|
||||
margin-right: 8px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.sender-expand-corner {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
z-index: 5;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
border-radius: 999px;
|
||||
background: transparent;
|
||||
transition:
|
||||
background-color 0.15s,
|
||||
color 0.15s;
|
||||
}
|
||||
|
||||
.sender-send-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
border-radius: 999px;
|
||||
color: hsl(var(--primary-foreground, 0 0% 100%));
|
||||
background: hsl(var(--primary));
|
||||
transition:
|
||||
opacity 0.15s,
|
||||
transform 0.15s;
|
||||
}
|
||||
|
||||
.sender-send-btn:hover:not(:disabled) {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.sender-send-btn--disabled,
|
||||
.sender-send-btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
.sender-send-btn--stop {
|
||||
color: hsl(var(--foreground));
|
||||
background: hsl(var(--muted));
|
||||
}
|
||||
|
||||
.sender-stop-square {
|
||||
display: block;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 2px;
|
||||
background: currentColor;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { PlusOutlined } from '@ant-design/icons-vue';
|
||||
import { EllipsisText, Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import {
|
||||
BarChartOutlined,
|
||||
CalendarOutlined,
|
||||
FundOutlined,
|
||||
PlusOutlined,
|
||||
RiseOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { Button, Empty, Select, Spin, message } from 'ant-design-vue';
|
||||
import { Empty, Popover, Select, Spin, Tooltip, message } from 'ant-design-vue';
|
||||
import { ChatItem } from '@tdesign-vue-next/chat';
|
||||
import 'tdesign-vue-next/es/style/index.css';
|
||||
import '@tdesign-vue-next/chat/es/style/index.css';
|
||||
@@ -20,6 +28,7 @@ import {
|
||||
} from '#/api/agent';
|
||||
|
||||
import CatalogCiteSender from './catalog-cite-sender.vue';
|
||||
import SessionSearchModal from './session-search-modal.vue';
|
||||
import {
|
||||
composeMessageWithCites,
|
||||
stripTrailingMention,
|
||||
@@ -28,14 +37,41 @@ import {
|
||||
|
||||
defineOptions({ name: 'AgentChat' });
|
||||
|
||||
/** 新对话空态快捷提示:点击只填入输入框,不直接发送 */
|
||||
const AgentBrandIcon = createIconifyIcon('lucide:bot');
|
||||
const SearchIcon = createIconifyIcon('lucide:search');
|
||||
const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
|
||||
const PanelOpenIcon = createIconifyIcon('lucide:panel-left');
|
||||
const NewChatIcon = createIconifyIcon('lucide:square-pen');
|
||||
const RecentChatIcon = createIconifyIcon('lucide:message-square');
|
||||
|
||||
const SIDER_COLLAPSED_KEY = 'agent-chat-sider-collapsed';
|
||||
|
||||
/** 空态快捷 chips:短标签展示,点击填入完整提问 */
|
||||
const starterPrompts = [
|
||||
'近7天的销售额、单量、净利和费比分别是多少',
|
||||
'昨天的经营情况怎么样',
|
||||
'本周销售额和净利帮我汇总一下',
|
||||
'近30天单量和费比有什么变化',
|
||||
{
|
||||
label: '近7天经营概览',
|
||||
prompt: '近7天的销售额、单量、净利和费比分别是多少',
|
||||
icon: BarChartOutlined,
|
||||
},
|
||||
{
|
||||
label: '昨天经营情况',
|
||||
prompt: '昨天的经营情况怎么样',
|
||||
icon: CalendarOutlined,
|
||||
},
|
||||
{
|
||||
label: '本周销售与净利',
|
||||
prompt: '本周销售额和净利帮我汇总一下',
|
||||
icon: RiseOutlined,
|
||||
},
|
||||
{
|
||||
label: '近30天费比变化',
|
||||
prompt: '近30天单量和费比有什么变化',
|
||||
icon: FundOutlined,
|
||||
},
|
||||
];
|
||||
|
||||
type SessionGroup = { key: string; label: string; items: AgentVO.Session[] };
|
||||
|
||||
/** 消息气泡视图模型(走 Vue ChatItem,避免 ChatList→WebComponent 丢正文) */
|
||||
type BubbleView = {
|
||||
id: string;
|
||||
@@ -52,6 +88,14 @@ const sessions = ref<AgentVO.Session[]>([]);
|
||||
const activeThreadId = ref<string | null>(null);
|
||||
/** 点了「新对话」但还没发出第一条消息,此时不请求后端 */
|
||||
const composingNew = ref(false);
|
||||
/** 侧栏收起状态(localStorage 持久化) */
|
||||
const siderCollapsed = ref(
|
||||
typeof localStorage !== 'undefined' &&
|
||||
localStorage.getItem(SIDER_COLLAPSED_KEY) === '1',
|
||||
);
|
||||
/** 收起态:最近会话浮层 */
|
||||
const collapsedRecentOpen = ref(false);
|
||||
const sessionSearchModalRef = ref<{ open: () => void } | null>(null);
|
||||
const messages = ref<AgentVO.Message[]>([]);
|
||||
/** 当前流式助手正文(与 messages 末条同步) */
|
||||
const streamingText = ref('');
|
||||
@@ -110,7 +154,7 @@ const showMessageLoading = computed(
|
||||
() => loadingMessages.value && !sending.value && messages.value.length === 0,
|
||||
);
|
||||
|
||||
/** 新对话草稿,或还没有任何会话时,展示能力引导 */
|
||||
/** 新对话草稿,或还没有任何会话时,展示居中空态 */
|
||||
const showStarter = computed(
|
||||
() =>
|
||||
messages.value.length === 0 &&
|
||||
@@ -119,6 +163,86 @@ const showStarter = computed(
|
||||
(!loadingSessions.value && !activeThreadId.value)),
|
||||
);
|
||||
|
||||
const greeting = computed(() => {
|
||||
const h = dayjs().hour();
|
||||
if (h < 12) return '早上好,今天想看点什么?';
|
||||
if (h < 18) return '下午好,今天想看点什么?';
|
||||
return '晚上好,今天想看点什么?';
|
||||
});
|
||||
|
||||
function sessionTime(s: AgentVO.Session) {
|
||||
const raw = s.lastMessageAt || s.updatedAt;
|
||||
const d = raw ? dayjs(raw) : null;
|
||||
return d?.isValid() ? d : null;
|
||||
}
|
||||
|
||||
function setSiderCollapsed(next: boolean) {
|
||||
siderCollapsed.value = next;
|
||||
try {
|
||||
localStorage.setItem(SIDER_COLLAPSED_KEY, next ? '1' : '0');
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
if (!next) {
|
||||
collapsedRecentOpen.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 居中弹窗搜索会话(展开/收起侧栏共用入口) */
|
||||
function openSessionSearch() {
|
||||
sessionSearchModalRef.value?.open();
|
||||
}
|
||||
|
||||
function onCollapsedRecentOpenChange(open: boolean) {
|
||||
collapsedRecentOpen.value = open;
|
||||
}
|
||||
|
||||
/** 收起态浮层 / 搜索弹窗点选会话 */
|
||||
function pickSessionFromOverlay(threadId: string) {
|
||||
collapsedRecentOpen.value = false;
|
||||
onSessionClick(threadId);
|
||||
}
|
||||
|
||||
/** 收起态「最近」列表(按接口顺序,最多 20 条) */
|
||||
const recentSessions = computed(() => sessions.value.slice(0, 20));
|
||||
|
||||
/** 侧栏按「今天 / 昨天 / 近7天 / 更早」分组,对齐常见助手布局 */
|
||||
const sessionGroups = computed<SessionGroup[]>(() => {
|
||||
const buckets: Record<
|
||||
'today' | 'yesterday' | 'week' | 'earlier',
|
||||
AgentVO.Session[]
|
||||
> = {
|
||||
today: [],
|
||||
yesterday: [],
|
||||
week: [],
|
||||
earlier: [],
|
||||
};
|
||||
const startToday = dayjs().startOf('day');
|
||||
const startYesterday = startToday.subtract(1, 'day');
|
||||
const startWeek = startToday.subtract(6, 'day');
|
||||
for (const s of sessions.value) {
|
||||
const t = sessionTime(s);
|
||||
if (!t || !t.isBefore(startToday)) {
|
||||
buckets.today.push(s);
|
||||
} else if (!t.isBefore(startYesterday)) {
|
||||
buckets.yesterday.push(s);
|
||||
} else if (!t.isBefore(startWeek)) {
|
||||
buckets.week.push(s);
|
||||
} else {
|
||||
buckets.earlier.push(s);
|
||||
}
|
||||
}
|
||||
const labels: Array<[keyof typeof buckets, string]> = [
|
||||
['today', '今天'],
|
||||
['yesterday', '昨天'],
|
||||
['week', '近 7 天'],
|
||||
['earlier', '更早'],
|
||||
];
|
||||
return labels
|
||||
.map(([key, label]) => ({ key, label, items: buckets[key] }))
|
||||
.filter((g) => g.items.length > 0);
|
||||
});
|
||||
|
||||
const bubbleViews = computed<BubbleView[]>(() =>
|
||||
messages.value.map((m, idx) => {
|
||||
const isStreamingAssistant =
|
||||
@@ -469,182 +593,420 @@ void loadEnabledModels().then(() => refreshSessions());
|
||||
|
||||
<template>
|
||||
<Page auto-content-height content-class="!p-0">
|
||||
<div class="flex h-full min-h-0 w-full overflow-hidden">
|
||||
<div class="agent-shell flex h-full min-h-0 w-full overflow-hidden">
|
||||
<!-- 左轨:顶栏标题/搜索/收起;收起后为图标轨(展开/新建/搜索/最近) -->
|
||||
<aside
|
||||
class="flex w-64 shrink-0 flex-col border-r border-border bg-card"
|
||||
class="agent-sider flex shrink-0 flex-col border-r border-border transition-[width] duration-200"
|
||||
:class="siderCollapsed ? 'w-[56px]' : 'w-[260px]'"
|
||||
>
|
||||
<div class="border-b border-border p-3">
|
||||
<Button type="primary" block @click="beginNewChat">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
新对话
|
||||
</Button>
|
||||
</div>
|
||||
<div class="relative min-h-0 flex-1">
|
||||
<div
|
||||
v-if="loadingSessions"
|
||||
class="absolute inset-0 z-10 flex items-center justify-center bg-background/50"
|
||||
>
|
||||
<Spin size="small" />
|
||||
</div>
|
||||
<Empty
|
||||
v-if="!loadingSessions && sessions.length === 0 && !composingNew"
|
||||
class="mt-10 px-2"
|
||||
description="暂无会话"
|
||||
/>
|
||||
<div v-else class="h-full space-y-1 overflow-y-auto px-3 py-2">
|
||||
<button
|
||||
v-if="composingNew"
|
||||
type="button"
|
||||
class="bg-primary/10 text-primary mb-1 w-full rounded-lg px-3 py-2 text-left text-sm"
|
||||
>
|
||||
<div class="truncate font-medium">新对话</div>
|
||||
<div class="text-muted-foreground mt-0.5 truncate text-xs">
|
||||
尚未发送
|
||||
</div>
|
||||
</button>
|
||||
<button
|
||||
v-for="s in sessions"
|
||||
:key="s.threadId"
|
||||
type="button"
|
||||
class="w-full rounded-lg px-3 py-2 text-left text-sm transition-colors"
|
||||
:class="
|
||||
s.threadId === activeThreadId
|
||||
? 'bg-primary/10 text-primary'
|
||||
: 'hover:bg-muted text-foreground'
|
||||
"
|
||||
@click="onSessionClick(s.threadId)"
|
||||
>
|
||||
<div class="truncate font-medium">{{ s.title || '新对话' }}</div>
|
||||
<div
|
||||
v-if="s.updatedAt || s.lastMessageAt"
|
||||
class="text-muted-foreground mt-0.5 truncate text-xs"
|
||||
>
|
||||
{{ s.updatedAt || s.lastMessageAt }}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<section class="agent-chat-main flex min-h-0 min-w-0 flex-1 flex-col">
|
||||
<header
|
||||
class="flex h-12 shrink-0 items-center gap-3 border-b border-border px-4"
|
||||
<div
|
||||
v-if="!siderCollapsed"
|
||||
class="flex h-12 shrink-0 items-center gap-1 px-3"
|
||||
>
|
||||
<span class="min-w-0 flex-1 truncate font-medium">
|
||||
{{
|
||||
composingNew
|
||||
? '新对话'
|
||||
: activeSession?.title || '智能助手'
|
||||
}}
|
||||
</span>
|
||||
<Select
|
||||
:value="selectedModelKey"
|
||||
:options="modelOptions"
|
||||
:loading="patchingModel"
|
||||
:disabled="sending || enabledModels.length === 0"
|
||||
placeholder="选择模型"
|
||||
class="w-64 shrink-0"
|
||||
:allow-clear="false"
|
||||
@change="(v) => onModelChange(String(v ?? ''))"
|
||||
/>
|
||||
</header>
|
||||
|
||||
<div class="relative flex min-h-0 flex-1 flex-col">
|
||||
<div
|
||||
v-if="showMessageLoading"
|
||||
class="text-muted-foreground absolute inset-0 z-10 flex items-center justify-center bg-background/60 text-sm"
|
||||
>
|
||||
加载消息…
|
||||
<div class="min-w-0 flex-1 truncate text-sm font-semibold">
|
||||
智能助手
|
||||
</div>
|
||||
<Empty
|
||||
v-if="!showStarter && !showMessageLoading && messages.length === 0"
|
||||
class="absolute inset-0 flex items-center justify-center"
|
||||
description="开始提问吧(需先在「模型管理」配置 API)"
|
||||
/>
|
||||
<div
|
||||
ref="messagePaneRef"
|
||||
class="agent-td-chat t-chat t-chat--normal min-h-0 flex-1 overflow-y-auto py-4"
|
||||
>
|
||||
<div
|
||||
v-if="showStarter"
|
||||
class="mx-auto flex h-full max-w-xl flex-col justify-center px-2 py-6"
|
||||
<Tooltip title="搜索会话">
|
||||
<button
|
||||
type="button"
|
||||
class="hover:bg-muted text-muted-foreground hover:text-foreground flex size-9 items-center justify-center rounded-lg transition-colors"
|
||||
aria-label="搜索会话"
|
||||
@click="openSessionSearch"
|
||||
>
|
||||
<div class="text-base font-medium">智能助手可以帮你看经营数据</div>
|
||||
<p class="text-muted-foreground mt-2 text-sm leading-6">
|
||||
直接问销售额、单量、净利、费比。说「近7天」「昨天」「本周」「本月」即可,不必自己换算日期。查某家店或某个商品时,带上店铺名或商品名。
|
||||
</p>
|
||||
<ul
|
||||
class="text-muted-foreground mt-3 list-disc space-y-1 pl-5 text-sm leading-6"
|
||||
<SearchIcon class="size-5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Tooltip title="收起侧栏">
|
||||
<button
|
||||
type="button"
|
||||
class="hover:bg-muted text-muted-foreground hover:text-foreground flex size-9 items-center justify-center rounded-lg transition-colors"
|
||||
aria-label="收起侧栏"
|
||||
@click="setSiderCollapsed(true)"
|
||||
>
|
||||
<PanelCloseIcon class="size-5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="flex min-h-0 flex-1 flex-col items-center gap-1 px-1.5 pt-0 pb-3"
|
||||
>
|
||||
<Tooltip title="展开侧栏" placement="right">
|
||||
<button
|
||||
type="button"
|
||||
class="agent-sider-brand-btn hover:bg-muted group flex size-10 items-center justify-center rounded-lg transition-colors"
|
||||
aria-label="展开侧栏"
|
||||
@click="setSiderCollapsed(false)"
|
||||
>
|
||||
<AgentBrandIcon class="size-5 group-hover:hidden" />
|
||||
<PanelOpenIcon class="hidden size-5 group-hover:block" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Tooltip title="新对话" placement="right">
|
||||
<button
|
||||
type="button"
|
||||
class="hover:bg-muted text-muted-foreground hover:text-foreground flex size-10 items-center justify-center rounded-lg transition-colors"
|
||||
aria-label="新对话"
|
||||
@click="beginNewChat"
|
||||
>
|
||||
<NewChatIcon class="size-5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Tooltip title="搜索会话" placement="right">
|
||||
<button
|
||||
type="button"
|
||||
class="hover:bg-muted text-muted-foreground hover:text-foreground flex size-10 items-center justify-center rounded-lg transition-colors"
|
||||
aria-label="搜索会话"
|
||||
@click="openSessionSearch"
|
||||
>
|
||||
<SearchIcon class="size-5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
<Popover
|
||||
:open="collapsedRecentOpen"
|
||||
trigger="click"
|
||||
placement="rightTop"
|
||||
:overlay-style="{ padding: 0 }"
|
||||
@update:open="onCollapsedRecentOpenChange"
|
||||
>
|
||||
<template #content>
|
||||
<div class="agent-sider-pop flex w-64 flex-col p-2">
|
||||
<div class="text-muted-foreground px-1 pb-2 text-xs font-medium">
|
||||
最近聊天
|
||||
</div>
|
||||
<div class="max-h-72 overflow-y-auto">
|
||||
<Empty
|
||||
v-if="recentSessions.length === 0"
|
||||
class="py-6"
|
||||
description="暂无会话"
|
||||
:image="Empty.PRESENTED_IMAGE_SIMPLE"
|
||||
/>
|
||||
<button
|
||||
v-for="s in recentSessions"
|
||||
:key="s.threadId"
|
||||
type="button"
|
||||
class="agent-session-item mb-0.5 w-full cursor-pointer rounded-lg px-2.5 py-2 text-left text-sm transition-colors"
|
||||
:class="
|
||||
s.threadId === activeThreadId
|
||||
? 'agent-session-item--active'
|
||||
: ''
|
||||
"
|
||||
@click="pickSessionFromOverlay(s.threadId)"
|
||||
>
|
||||
<EllipsisText :tooltip-when-ellipsis="true" class="w-full">
|
||||
{{ s.title || '新对话' }}
|
||||
</EllipsisText>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<Tooltip
|
||||
:title="collapsedRecentOpen ? '' : '最近聊天'"
|
||||
placement="right"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="hover:bg-muted text-muted-foreground hover:text-foreground flex size-10 items-center justify-center rounded-lg transition-colors"
|
||||
:class="collapsedRecentOpen ? 'bg-muted text-foreground' : ''"
|
||||
aria-label="最近聊天"
|
||||
>
|
||||
<li>工作台概览:销售额、单量、净利、费比</li>
|
||||
<li>店铺 / 商品:销量、ROI、目标达成</li>
|
||||
</ul>
|
||||
<div class="mt-4 flex flex-col gap-2">
|
||||
<button
|
||||
v-for="item in starterPrompts"
|
||||
:key="item"
|
||||
type="button"
|
||||
class="hover:border-primary hover:bg-primary/5 rounded-lg border border-border bg-card px-3 py-2 text-left text-sm transition-colors"
|
||||
@click="applyStarterPrompt(item)"
|
||||
<RecentChatIcon class="size-5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
</Popover>
|
||||
</div>
|
||||
|
||||
<template v-if="!siderCollapsed">
|
||||
<div class="px-3 pb-2">
|
||||
<button
|
||||
type="button"
|
||||
class="hover:bg-muted flex h-9 w-full items-center gap-2 rounded-lg px-3 text-sm font-medium transition-colors"
|
||||
@click="beginNewChat"
|
||||
>
|
||||
<PlusOutlined />
|
||||
新对话
|
||||
</button>
|
||||
</div>
|
||||
<div class="relative min-h-0 flex-1">
|
||||
<div
|
||||
v-if="loadingSessions"
|
||||
class="absolute inset-0 z-10 flex items-center justify-center bg-background/50"
|
||||
>
|
||||
<Spin size="small" />
|
||||
</div>
|
||||
<Empty
|
||||
v-if="!loadingSessions && sessions.length === 0 && !composingNew"
|
||||
class="mt-12 px-3"
|
||||
description="暂无会话"
|
||||
/>
|
||||
<div v-else class="h-full overflow-y-auto px-2 pb-4">
|
||||
<button
|
||||
v-if="composingNew"
|
||||
type="button"
|
||||
class="bg-muted mb-3 w-full rounded-lg px-3 py-2 text-left text-sm font-medium"
|
||||
>
|
||||
新对话
|
||||
</button>
|
||||
<div
|
||||
v-for="group in sessionGroups"
|
||||
:key="group.key"
|
||||
class="mb-3"
|
||||
>
|
||||
<div
|
||||
class="text-muted-foreground px-3 pb-1 pt-2 text-xs font-medium"
|
||||
>
|
||||
{{ item }}
|
||||
{{ group.label }}
|
||||
</div>
|
||||
<button
|
||||
v-for="s in group.items"
|
||||
:key="s.threadId"
|
||||
type="button"
|
||||
class="agent-session-item mb-0.5 w-full cursor-pointer rounded-lg px-3 py-2 text-left text-sm transition-colors"
|
||||
:class="
|
||||
s.threadId === activeThreadId
|
||||
? 'agent-session-item--active'
|
||||
: ''
|
||||
"
|
||||
@click="onSessionClick(s.threadId)"
|
||||
>
|
||||
<EllipsisText :tooltip-when-ellipsis="true" class="w-full">
|
||||
{{ s.title || '新对话' }}
|
||||
</EllipsisText>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<ChatItem
|
||||
v-for="item in bubbleViews"
|
||||
:key="item.id"
|
||||
class="agent-td-item"
|
||||
:role="item.role"
|
||||
:name="item.name"
|
||||
:content="item.content"
|
||||
:text-loading="item.textLoading"
|
||||
variant="base"
|
||||
animation="gradient"
|
||||
/>
|
||||
<div
|
||||
v-if="toolStatusActive && toolStatusLabel"
|
||||
class="text-muted-foreground mx-auto flex max-w-3xl items-center gap-2 px-4 py-1 text-xs"
|
||||
>
|
||||
<span
|
||||
class="border-primary/40 inline-block size-3 animate-spin rounded-full border-2 border-t-transparent"
|
||||
/>
|
||||
<span>{{ toolStatusLabel }}…</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shrink-0 border-t border-border p-3">
|
||||
</template>
|
||||
</aside>
|
||||
|
||||
<!-- 主区:空态居中 / 对话时消息 + 底栏输入 -->
|
||||
<section class="agent-main relative flex min-h-0 min-w-0 flex-1 flex-col">
|
||||
<div
|
||||
v-if="showMessageLoading"
|
||||
class="text-muted-foreground absolute inset-0 z-10 flex items-center justify-center bg-background/60 text-sm"
|
||||
>
|
||||
加载消息…
|
||||
</div>
|
||||
|
||||
<!-- 空态:问候 + 居中输入 + chips -->
|
||||
<div
|
||||
v-if="showStarter"
|
||||
class="flex min-h-0 flex-1 flex-col items-center justify-center px-4 pb-16 pt-8"
|
||||
>
|
||||
<h1 class="mb-10 text-center text-3xl font-semibold tracking-tight">
|
||||
{{ greeting }}
|
||||
</h1>
|
||||
<div class="agent-composer w-full max-w-[720px]">
|
||||
<CatalogCiteSender
|
||||
v-model="draft"
|
||||
v-model:cites="citations"
|
||||
:loading="sending"
|
||||
@send="onSenderSend"
|
||||
@stop="onSenderStop"
|
||||
/>
|
||||
>
|
||||
<template #footer-extra>
|
||||
<Select
|
||||
:value="selectedModelKey"
|
||||
:options="modelOptions"
|
||||
:loading="patchingModel"
|
||||
:disabled="sending || enabledModels.length === 0"
|
||||
placeholder="模型"
|
||||
size="small"
|
||||
class="agent-model-select min-w-0 max-w-[200px] flex-1"
|
||||
:allow-clear="false"
|
||||
@change="(v) => onModelChange(String(v ?? ''))"
|
||||
/>
|
||||
</template>
|
||||
</CatalogCiteSender>
|
||||
<div class="mt-5 flex flex-wrap justify-center gap-2">
|
||||
<Tooltip
|
||||
v-for="item in starterPrompts"
|
||||
:key="item.label"
|
||||
:title="item.prompt"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="hover:bg-muted border-border text-foreground/80 hover:text-foreground inline-flex cursor-pointer items-center gap-2 rounded-full border bg-card px-3.5 py-1.5 text-sm transition-colors"
|
||||
@click="applyStarterPrompt(item.prompt)"
|
||||
>
|
||||
<component :is="item.icon" class="text-muted-foreground" />
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 对话态:可滚动消息 + 底部输入 -->
|
||||
<template v-else>
|
||||
<div
|
||||
ref="messagePaneRef"
|
||||
class="agent-td-chat t-chat t-chat--normal min-h-0 flex-1 overflow-y-auto px-4 pb-4 pt-6"
|
||||
>
|
||||
<Empty
|
||||
v-if="!showMessageLoading && messages.length === 0"
|
||||
class="mt-24"
|
||||
description="开始提问吧(需先在「模型管理」配置 API)"
|
||||
/>
|
||||
<div class="mx-auto max-w-[760px]">
|
||||
<ChatItem
|
||||
v-for="item in bubbleViews"
|
||||
:key="item.id"
|
||||
class="agent-td-item"
|
||||
:role="item.role"
|
||||
:name="item.name"
|
||||
:content="item.content"
|
||||
:text-loading="item.textLoading"
|
||||
variant="base"
|
||||
animation="gradient"
|
||||
/>
|
||||
<div
|
||||
v-if="toolStatusActive && toolStatusLabel"
|
||||
class="text-muted-foreground flex items-center gap-2 px-2 py-1 text-xs"
|
||||
>
|
||||
<span
|
||||
class="border-primary/40 inline-block size-3 animate-spin rounded-full border-2 border-t-transparent"
|
||||
/>
|
||||
<span>{{ toolStatusLabel }}…</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="agent-composer-dock shrink-0 px-4 pb-5 pt-2">
|
||||
<div class="agent-composer mx-auto max-w-[720px]">
|
||||
<CatalogCiteSender
|
||||
v-model="draft"
|
||||
v-model:cites="citations"
|
||||
:loading="sending"
|
||||
@send="onSenderSend"
|
||||
@stop="onSenderStop"
|
||||
>
|
||||
<template #footer-extra>
|
||||
<Select
|
||||
:value="selectedModelKey"
|
||||
:options="modelOptions"
|
||||
:loading="patchingModel"
|
||||
:disabled="sending || enabledModels.length === 0"
|
||||
placeholder="模型"
|
||||
size="small"
|
||||
class="agent-model-select min-w-0 max-w-[200px] flex-1"
|
||||
:allow-clear="false"
|
||||
@change="(v) => onModelChange(String(v ?? ''))"
|
||||
/>
|
||||
</template>
|
||||
</CatalogCiteSender>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
</div>
|
||||
<SessionSearchModal
|
||||
ref="sessionSearchModalRef"
|
||||
:sessions="sessions"
|
||||
:active-thread-id="activeThreadId"
|
||||
@pick="pickSessionFromOverlay"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.agent-td-chat {
|
||||
--td-bg-color-container: transparent;
|
||||
padding-inline: 28px;
|
||||
/* 浅色:侧栏略深于主区;深色沿用 background-deep */
|
||||
.agent-sider {
|
||||
background: hsl(var(--muted) / 0.45);
|
||||
}
|
||||
|
||||
html.dark .agent-sider,
|
||||
.dark .agent-sider {
|
||||
background: hsl(var(--background-deep, var(--background)));
|
||||
}
|
||||
|
||||
.agent-session-item:hover {
|
||||
background: hsl(var(--accent));
|
||||
}
|
||||
|
||||
.agent-session-item,
|
||||
.agent-session-item :deep(*) {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.agent-session-item--active {
|
||||
background: hsl(var(--background));
|
||||
font-weight: 500;
|
||||
box-shadow: 0 0 0 1px hsl(var(--border));
|
||||
}
|
||||
|
||||
html.dark .agent-session-item--active,
|
||||
.dark .agent-session-item--active {
|
||||
background: hsl(var(--muted));
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.agent-composer :deep(.t-chat-sender) {
|
||||
border-radius: 24px;
|
||||
box-shadow: 0 0 0 1px hsl(var(--border) / 0.8);
|
||||
}
|
||||
|
||||
.agent-composer :deep(.t-chat-sender__textarea__wrapper) {
|
||||
border-radius: 24px;
|
||||
padding: 0;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.agent-model-select :deep(.ant-select-selector) {
|
||||
border-radius: 999px !important;
|
||||
}
|
||||
|
||||
.agent-td-item {
|
||||
margin-bottom: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
/* 气泡按内容收缩,左右再留一截,避免贴边铺满 */
|
||||
|
||||
/* 气泡按内容收缩,避免贴边铺满 */
|
||||
.agent-td-item :deep(.t-chat__inner) {
|
||||
box-sizing: border-box;
|
||||
padding-inline: 4px;
|
||||
}
|
||||
|
||||
.agent-td-item :deep(.t-chat__content) {
|
||||
width: auto;
|
||||
max-width: min(720px, calc(100% - 32px));
|
||||
max-width: min(680px, calc(100% - 24px));
|
||||
}
|
||||
|
||||
.agent-td-item :deep(.t-chat__inner.user) {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.agent-td-item :deep(.t-chat__text__name) {
|
||||
opacity: 0.55;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 浅色:给气泡补边框与底色,避免与主背景糊在一起 */
|
||||
.agent-td-item :deep(.t-chat__text--variant--base .t-chat__detail),
|
||||
.agent-td-item :deep(.t-chat__detail) {
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 12px;
|
||||
background: hsl(var(--muted) / 0.65);
|
||||
padding-block: 10px;
|
||||
}
|
||||
|
||||
.agent-td-item :deep(.t-chat__inner.user .t-chat__text--variant--base .t-chat__detail),
|
||||
.agent-td-item :deep(.t-chat__inner.user .t-chat__detail) {
|
||||
background: hsl(var(--primary) / 0.1);
|
||||
border-color: hsl(var(--primary) / 0.22);
|
||||
}
|
||||
|
||||
html.dark .agent-td-item :deep(.t-chat__text--variant--base .t-chat__detail),
|
||||
html.dark .agent-td-item :deep(.t-chat__detail),
|
||||
.dark .agent-td-item :deep(.t-chat__text--variant--base .t-chat__detail),
|
||||
.dark .agent-td-item :deep(.t-chat__detail) {
|
||||
border-color: transparent;
|
||||
background: hsl(var(--muted) / 0.4);
|
||||
}
|
||||
|
||||
html.dark .agent-td-item :deep(.t-chat__inner.user .t-chat__text--variant--base .t-chat__detail),
|
||||
html.dark .agent-td-item :deep(.t-chat__inner.user .t-chat__detail),
|
||||
.dark .agent-td-item :deep(.t-chat__inner.user .t-chat__text--variant--base .t-chat__detail),
|
||||
.dark .agent-td-item :deep(.t-chat__inner.user .t-chat__detail) {
|
||||
background: hsl(var(--primary) / 0.22);
|
||||
border-color: transparent;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 会话搜索弹窗:居中打开,按标题过滤;点选后回传 threadId。
|
||||
*/
|
||||
import { computed, nextTick, ref } from 'vue';
|
||||
|
||||
import { EllipsisText, useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Empty, Input } from 'ant-design-vue';
|
||||
|
||||
import type { AgentVO } from '#/api/agent';
|
||||
|
||||
defineOptions({ name: 'AgentSessionSearchModal' });
|
||||
|
||||
const props = defineProps<{
|
||||
sessions: AgentVO.Session[];
|
||||
activeThreadId?: string | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
pick: [threadId: string];
|
||||
}>();
|
||||
|
||||
const query = ref('');
|
||||
const inputRef = ref<{ focus?: () => void } | null>(null);
|
||||
|
||||
const hits = computed(() => {
|
||||
const q = query.value.trim().toLowerCase();
|
||||
const list = props.sessions || [];
|
||||
if (!q) return list.slice(0, 30);
|
||||
return list
|
||||
.filter((s) => (s.title || '新对话').toLowerCase().includes(q))
|
||||
.slice(0, 30);
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
title: '搜索会话',
|
||||
class: 'w-[520px]',
|
||||
draggable: true,
|
||||
footer: false,
|
||||
showConfirmButton: false,
|
||||
showCancelButton: false,
|
||||
onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
query.value = '';
|
||||
return;
|
||||
}
|
||||
query.value = '';
|
||||
void nextTick(() => inputRef.value?.focus?.());
|
||||
},
|
||||
});
|
||||
|
||||
function open() {
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
function pick(threadId: string) {
|
||||
emit('pick', threadId);
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<div class="flex flex-col gap-3">
|
||||
<Input
|
||||
ref="inputRef"
|
||||
v-model:value="query"
|
||||
allow-clear
|
||||
placeholder="按会话标题搜索"
|
||||
size="large"
|
||||
/>
|
||||
<div class="max-h-[360px] min-h-[120px] overflow-y-auto">
|
||||
<Empty
|
||||
v-if="hits.length === 0"
|
||||
class="py-10"
|
||||
:description="query.trim() ? '无匹配会话' : '暂无会话'"
|
||||
:image="Empty.PRESENTED_IMAGE_SIMPLE"
|
||||
/>
|
||||
<button
|
||||
v-for="s in hits"
|
||||
:key="s.threadId"
|
||||
type="button"
|
||||
class="mb-0.5 w-full rounded-lg px-3 py-2.5 text-left text-sm transition-colors"
|
||||
:class="
|
||||
s.threadId === activeThreadId
|
||||
? 'bg-muted font-medium'
|
||||
: 'hover:bg-muted/70'
|
||||
"
|
||||
@click="pick(s.threadId)"
|
||||
>
|
||||
<EllipsisText :tooltip-when-ellipsis="true" class="w-full">
|
||||
{{ s.title || '新对话' }}
|
||||
</EllipsisText>
|
||||
<div
|
||||
v-if="s.updatedAt || s.lastMessageAt"
|
||||
class="text-muted-foreground mt-0.5 text-xs"
|
||||
>
|
||||
{{ s.updatedAt || s.lastMessageAt }}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
Reference in New Issue
Block a user