重构: AiChat 样式同步到子组件 scoped + 复用抽取(God 拆分遗漏修复)

根因:AiChat God 拆分(抽 ConversationSidebar/ChatInput/MessageList)时样式没移子组件,
留 AiChat <style scoped>。Vue scoped 不匹配子组件内部元素(子元素无父 data-v)→
对话列表/输入框样式丢失 → 布局塌陷(主导航被覆盖点击无反应 + 样式乱)。

修复(纯样式移动,不改选择器/属性/值):
- AiChat <style scoped> 886→151 行(瘦身 83%)
- 侧栏 .ai-conv-* 47 选择器 → ConversationSidebar <style scoped>(新建)
- 输入框 .ai-input-*/.ai-skill-*/.ai-mention-*/.ai-send-btn 40 → ChatInput <style scoped>(新建)
- 复用 .ai-btn-icon* 6 处 → components.css(全局,TopBar+ConversationSidebar 共用)
- 容器 .ai-panel/.ai-chat-area/.ai-queue-*/.ai-toast* 32 → AiChat 保留 scoped
- 清理 TopBar 重复块(AiChat 漏删死代码,零视觉变更)+ 删 TEMP DEBUG 参考线

自验: vite build ✓ + vue-tsc EXIT 0 + AiChat scoped CLEAN(0 子组件类)
This commit is contained in:
lxy
2026-06-20 00:28:14 +08:00
parent 5c395f4825
commit 4f8f1cf794
4 changed files with 596 additions and 742 deletions
+234
View File
@@ -656,3 +656,237 @@ defineExpose({
sendExamplePrompt,
})
</script>
<!-- ═══ ChatInput scoped 样式(第二批抽离遗漏修复: 从 AiChat.vue <style scoped> 迁移,
零视觉变更。原 AiChat scoped 不渗透子组件根,输入框/技能联想/发送按钮元素失配 → 本组件自持。
CSS 变量(--df-*)由根级 global.css 提供,共享同一份。.ai-input-area 容器留父级 AiChat scoped。) ═══ -->
<style scoped>
.ai-input-wrap {
position: relative;
display: flex;
/* F-260614-05 Phase 2b: flex-wrap 让全宽的图片预览行强制 textarea+按钮换行到下一行 */
flex-wrap: wrap;
align-items: center;
gap: 6px;
background: var(--df-bg-card);
border: 0.5px solid var(--df-border);
border-radius: var(--df-radius-lg);
padding: 6px 8px;
transition: border-color 0.15s;
}
/* F-260614-05 Phase 2b: 待发送图片预览行(粘贴/拖拽加入,发送前可移除) */
.ai-img-preview-row {
display: flex;
flex-wrap: wrap;
gap: 6px;
width: 100%; /* 全宽强制后续 textarea+按钮换行 */
padding-bottom: 4px;
border-bottom: 0.5px solid var(--df-border);
}
.ai-img-preview {
position: relative;
width: 56px;
height: 56px;
border-radius: var(--df-radius);
overflow: hidden;
border: 0.5px solid var(--df-border);
background: var(--df-bg);
}
.ai-img-preview-thumb {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.ai-img-preview-x {
position: absolute;
top: 2px;
right: 2px;
width: 16px;
height: 16px;
display: flex;
align-items: center;
justify-content: center;
border: none;
border-radius: 50%;
background: color-mix(in srgb, var(--df-bg) 80%, transparent);
color: var(--df-text-dim);
font-size: 14px;
line-height: 1;
cursor: pointer;
padding: 0;
transition: background 0.15s, color 0.15s;
}
.ai-img-preview-x:hover {
background: var(--df-danger);
color: #fff;
}
.ai-input-wrap:focus-within {
border-color: color-mix(in srgb, var(--df-accent) 40%, transparent);
}
/* ── 技能 chip / 联想浮层 ── */
.ai-skill-chip {
display: flex;
align-items: center;
gap: 6px;
margin-bottom: 6px;
padding: 3px 8px;
background: color-mix(in srgb, var(--df-accent) 16%, transparent);
border: 0.5px solid color-mix(in srgb, var(--df-accent) 40%, transparent);
border-radius: var(--df-radius);
font-size: 12px;
}
.ai-skill-chip-name { color: var(--df-accent); font-weight: 600; flex-shrink: 0; }
.ai-skill-chip-desc { color: var(--df-text-dim); flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 参数格式提示(技能自带 argument_hint 数据,不进 i18n) */
.ai-skill-chip-main { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; flex-wrap: wrap; }
.ai-skill-chip-hint {
color: var(--df-text-dim);
font-family: var(--df-font-mono, ui-monospace, monospace);
font-size: 11px;
background: color-mix(in srgb, var(--df-text-dim) 14%, transparent);
padding: 1px 5px;
border-radius: 3px;
}
.ai-skill-chip-x { background: none; border: none; color: var(--df-text-dim); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; flex-shrink: 0; }
.ai-skill-chip-x:hover { color: var(--df-text); }
.ai-skill-popover {
position: absolute;
bottom: calc(100% + 4px);
left: 0;
right: 0;
max-height: 240px;
overflow-y: auto;
background: var(--df-bg-card);
border: 0.5px solid var(--df-border);
border-radius: var(--df-radius);
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
z-index: 20;
}
.ai-skill-item {
display: flex;
flex-direction: column;
gap: 2px;
padding: 6px 10px;
cursor: pointer;
font-size: 12px;
}
.ai-skill-item-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ai-skill-item--active,
.ai-skill-item:hover {
background: color-mix(in srgb, var(--df-accent) 14%, transparent);
}
.ai-skill-item-name { color: var(--df-accent); font-weight: 600; min-width: 90px; }
.ai-skill-item-desc { color: var(--df-text-dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-skill-item-src { color: var(--df-text-dim); opacity: 0.6; font-size: 10px; text-transform: uppercase; }
/* 浮层内参数格式提示(等宽 dim 小字,仅在 skill.argument_hint 有值时显) */
.ai-skill-item-hint {
color: var(--df-text-dim);
font-family: var(--df-font-mono, ui-monospace, monospace);
font-size: 11px;
opacity: 0.85;
word-break: break-all;
}
.ai-skill-empty { padding: 8px 12px; color: var(--df-text-dim); opacity: 0.7; font-size: 12px; }
/* ── UX-10 §1.4: @ 实体引用浮层(复用 .ai-skill-popover 容器,仅新增组标题/类型标签) ── */
.ai-mention-popover { /* 同 .ai-skill-popover 定位,这里仅为语义占位,样式继承 */ }
.ai-mention-group {
padding: 4px 10px 2px;
font-size: 10px;
font-weight: 600;
color: var(--df-text-dim);
text-transform: uppercase;
letter-spacing: 0.5px;
user-select: none;
}
.ai-mention-item-name { color: var(--df-text); font-weight: 500; flex-shrink: 0; }
.ai-mention-item-desc {
color: var(--df-text-dim);
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 类型标签小色块(项目/任务区分) */
.ai-mention-item-type {
flex-shrink: 0;
padding: 1px 5px;
border-radius: var(--df-radius-sm);
font-size: 9px;
font-weight: 600;
letter-spacing: 0.3px;
background: var(--df-bg-hover);
color: var(--df-text-dim);
}
.ai-mention-item-type--project {
background: color-mix(in srgb, var(--df-accent) 16%, transparent);
color: var(--df-accent);
}
.ai-mention-item-type--task {
background: color-mix(in srgb, var(--df-success) 16%, transparent);
color: var(--df-success);
}
.ai-input {
flex: 1;
background: transparent;
border: none;
outline: none;
color: var(--df-text);
font-size: 13px;
font-family: var(--df-font-sans);
line-height: 1.5;
resize: vertical;
min-height: 20px;
height: 20px;
max-height: 200px;
overflow-y: auto;
}
.ai-input::placeholder {
color: var(--df-text-dim);
}
.ai-send-btn {
display: flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
border: none;
border-radius: var(--df-radius);
background: var(--df-bg-raised);
color: var(--df-text-dim);
cursor: pointer;
transition: all 0.15s;
flex-shrink: 0;
}
.ai-send-btn--active {
background: var(--df-accent);
color: #fff;
}
.ai-send-btn--active:hover {
background: var(--df-accent-hover);
}
.ai-send-btn:disabled {
opacity: 0.4;
cursor: not-allowed;
}
.ai-send-btn--stop {
background: #e5484d;
color: #fff;
}
.ai-send-btn--stop:hover {
background: #d63a3f;
}
.ai-input-hint {
font-size: 10px;
color: var(--df-text-dim);
text-align: right;
margin-top: 4px;
opacity: 0.6;
}
</style>
+308
View File
@@ -463,3 +463,311 @@ defineExpose({
focusSearch,
})
</script>
<!-- ═══ ConversationSidebar scoped 样式(第一批抽离遗漏修复: 从 AiChat.vue <style scoped> 迁移,
零视觉变更。原 AiChat scoped 不渗透子组件根,导致侧栏元素失配 → 本组件自持样式。
CSS 变量(--df-*)由根级 global.css 提供,共享同一份。.ai-btn-icon 共享按钮抽 components.css 全局。) ═══ -->
<style scoped>
/* ═══ 对话侧边栏 ═══ */
/* 宽度由 CSS 变量驱动(UX-2025-16 拖拽)::style 绑 --sidebar-width,不直接绑 width,
这样 sidebar-slide 过渡的 width:0(enter-from/leave-to)能正常覆盖,折叠/展开动画不破 */
.ai-conv-sidebar {
position: relative;
width: var(--sidebar-width, 200px);
min-width: var(--sidebar-width, 200px);
border-right: 0.5px solid var(--df-border);
display: flex;
flex-direction: column;
height: 100%;
background: var(--df-bg);
}
/* UX-2025-16:右边缘 2px 拖拽条。hover/active 显高亮;拖拽中 body.ai-sidebar-resizing 全局锁 cursor 防抖 */
.ai-sidebar-resize-handle {
position: absolute;
top: 0;
right: -1px; /* 跨过 0.5px border-right,确保命中区不被 border 遮挡 */
width: 4px; /* 命中区 4px(视觉 2px 由 background 控制),易抓取 */
height: 100%;
cursor: col-resize;
z-index: 5;
background: transparent;
transition: background 0.15s var(--df-ease);
}
.ai-sidebar-resize-handle:hover {
background: var(--df-accent, #4f8cff);
opacity: 0.5;
}
/* 拖拽中全局锁 cursor + 禁选中文本(挂在 body 上,跨元素生效) */
body.ai-sidebar-resizing,
body.ai-sidebar-resizing * {
cursor: col-resize !important;
user-select: none !important;
}
.ai-conv-sidebar-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 10px;
border-bottom: 0.5px solid var(--df-border);
}
.ai-conv-sidebar-title {
font-size: 12px;
font-weight: 500;
color: var(--df-text);
}
/* UX-06 §3.1: 对话搜索框(紧贴 header 下,样式跟随周围输入控件) */
.ai-conv-search {
position: relative;
display: flex;
align-items: center;
padding: 6px 10px;
border-bottom: 0.5px solid var(--df-border);
}
.ai-conv-search-icon {
flex: none;
color: var(--df-text-dim);
margin-right: 6px;
}
.ai-conv-search-input {
flex: 1;
min-width: 0;
border: none;
outline: none;
background: transparent;
font-size: 12px;
color: var(--df-text);
}
.ai-conv-search-input::placeholder {
color: var(--df-text-dim);
}
.ai-conv-search-kbd {
flex: none;
font-family: inherit;
font-size: 10px;
color: var(--df-text-dim);
border: 0.5px solid var(--df-border);
border-radius: 3px;
padding: 0 4px;
user-select: none;
}
.ai-conv-list {
flex: 1;
overflow-y: auto;
padding: 4px;
}
.ai-conv-group-title {
padding: 8px 8px 3px;
font-size: 10px;
font-weight: 600;
color: var(--df-text-dim);
user-select: none;
}
.ai-conv-group-title--fold {
cursor: pointer;
display: flex;
align-items: center;
gap: 3px;
}
.ai-conv-group-title--fold:hover {
color: var(--df-text);
}
.ai-conv-group-arrow {
display: inline-block;
transition: transform 0.15s;
font-size: 9px;
}
.ai-conv-group-arrow.is-folded {
transform: rotate(0deg);
}
.ai-conv-group-arrow:not(.is-folded) {
transform: rotate(90deg);
}
.ai-conv-group-count {
margin-left: 2px;
font-weight: 400;
opacity: 0.7;
}
.ai-conv-group-empty {
padding: 2px 8px 4px 20px;
font-size: 10px;
color: var(--df-text-dim);
font-style: italic;
}
.ai-conv-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 8px;
border-radius: var(--df-radius);
cursor: pointer;
transition: background 0.15s;
gap: 4px;
}
.ai-conv-item:hover {
background: var(--df-sidebar-hover);
}
.ai-conv-item--active {
background: var(--df-sidebar-active);
}
.ai-conv-item--archived .ai-conv-item-title {
opacity: 0.6;
}
.ai-conv-item-main {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 2px;
}
.ai-conv-item-title {
font-size: 11px;
color: var(--df-text);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 3px;
min-width: 0;
}
/* UX-2025-20 §7.4: AI 生成标题淡入(0.3s opacity + transform 过渡) */
.ai-conv-item-title--flash {
animation: ai-title-flash 0.3s var(--df-ease);
}
.ai-conv-item-title-badge {
flex-shrink: 0;
color: var(--df-success);
}
@keyframes ai-title-flash {
from { opacity: 0; transform: translateX(-3px); }
to { opacity: 1; transform: translateX(0); }
}
.ai-conv-item-edit {
font-size: 11px;
color: var(--df-text);
width: 100%;
height: 18px;
padding: 0 4px;
border: 1px solid var(--df-primary, #4f8cff);
border-radius: var(--df-radius-sm);
background: var(--df-bg, #fff);
outline: none;
box-sizing: border-box;
}
.ai-conv-item-time {
font-size: 9px;
color: var(--df-text-dim);
}
/* F-09: 多会话并发生成指示器(会话项标题行内脉冲点,多会话可同时显示) */
.ai-conv-gen-dot {
display: inline-block;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--df-primary, #4f8cff);
flex-shrink: 0;
animation: ai-conv-gen-pulse 1.4s ease-in-out infinite;
}
@keyframes ai-conv-gen-pulse {
0%, 100% { opacity: 0.35; transform: scale(0.85); }
50% { opacity: 1; transform: scale(1.15); }
}
.ai-conv-item-actions {
display: none;
align-items: center;
gap: 2px;
flex-shrink: 0;
}
.ai-conv-item:hover .ai-conv-item-actions {
display: flex;
}
.ai-conv-item-act {
display: flex;
align-items: center;
justify-content: center;
width: 18px;
height: 18px;
border: none;
border-radius: var(--df-radius-sm);
background: transparent;
color: var(--df-text-dim);
cursor: pointer;
flex-shrink: 0;
}
.ai-conv-item-act:hover {
background: var(--df-sidebar-hover);
color: var(--df-text);
}
.ai-conv-item-act:last-child:hover {
background: var(--df-danger-bg);
color: var(--df-danger);
}
/* UX-17: 置顶按钮高亮态(已置顶时常驻强调色,不依赖 hover) */
.ai-conv-item-act--pinned {
color: var(--df-accent, var(--df-text));
}
/* CR-22-1: 已置顶对话视觉强调(左边线,不依赖 hover 图钉一眼识别)。
原方案「图钉常驻」与 hover 浮出 actions 矛盾(父 display:none 压制子),
改用 :has 给已置顶 item 左 accent 边线,hover 浮出操作不变。 */
.ai-conv-item:has(.ai-conv-item-act--pinned) {
box-shadow: inset 2px 0 0 var(--df-accent, var(--df-text));
}
/* ── UX-18: 对话导出按钮 + 格式菜单 ──
导出按钮位于归档与删除之间(非 last-child,保持删除按钮 :last-child 红色态不被破坏)。
菜单绝对定位浮于 item 下方右侧,窄侧栏优先避免溢出。 */
.ai-conv-item-export {
position: relative;
display: flex;
align-items: center;
flex-shrink: 0;
}
.ai-conv-export-menu {
position: absolute;
top: 100%;
right: 0;
margin-top: 2px;
z-index: 20;
min-width: 84px;
padding: 2px;
display: flex;
flex-direction: column;
gap: 1px;
background: var(--df-bg, #fff);
border: 1px solid var(--df-border, #e2e2e2);
border-radius: var(--df-radius-sm);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}
.ai-conv-export-opt {
border: none;
background: transparent;
text-align: left;
padding: 4px 8px;
font-size: 11px;
color: var(--df-text);
cursor: pointer;
border-radius: var(--df-radius-sm);
white-space: nowrap;
}
.ai-conv-export-opt:hover {
background: var(--df-sidebar-hover);
}
.ai-conv-empty {
padding: 16px 8px;
text-align: center;
font-size: 11px;
color: var(--df-text-dim);
}
/* 侧边栏滑入动画 */
.sidebar-slide-enter-active { transition: width 0.2s var(--df-ease), opacity 0.15s; }
.sidebar-slide-leave-active { transition: width 0.15s var(--df-ease), opacity 0.1s; }
.sidebar-slide-enter-from, .sidebar-slide-leave-to {
width: 0;
min-width: 0;
opacity: 0;
overflow: hidden;
}
</style>