ChatHeader.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <!-- 顶部任务选择器 -->
  3. <div class="chat-header">
  4. <!-- 任务列表收起时显示导航按钮 -->
  5. <template v-if="panelCollapsed">
  6. <div :class="['nav-btn', { disabled: !canGoPrev }]" @click="emit('go-to-prev')">
  7. <div class="nav-icon prev-icon"></div>
  8. </div>
  9. <div :class="['nav-btn', { disabled: !canGoNext }]" @click="emit('go-to-next')">
  10. <div class="nav-icon next-icon"></div>
  11. </div>
  12. <div class="nav-btn" @click="emit('create-task')">
  13. <div class="nav-icon add-icon"></div>
  14. </div>
  15. </template>
  16. <!-- 会话标题区域(含编辑功能) -->
  17. <div v-if="currentTask?.sessionId" class="chat-header-title-wrapper">
  18. <template v-if="editingTitle">
  19. <input
  20. ref="titleInputRef"
  21. v-model="editTitleValue"
  22. class="title-edit-input"
  23. @keyup.enter="handleSaveTitle"
  24. @keyup.escape="cancelEditTitle"
  25. @blur="handleSaveTitle"
  26. />
  27. </template>
  28. <template v-else>
  29. <div class="title-edit-btn" @click="startEditTitle" title="编辑标题"></div>
  30. <span class="chat-header-title">{{ currentTask.name }}</span>
  31. </template>
  32. </div>
  33. <!-- 文件、链接与智能体聚合胶囊 -->
  34. <ResourceCapsule
  35. v-if="currentTask?.sessionId"
  36. :task-id="currentTask?.id"
  37. :files="capsuleFiles"
  38. :links="capsuleLinks"
  39. :agents="capsuleAgents"
  40. @file-preview="emit('file-preview', $event)"
  41. @agent-detail-click="emit('agent-detail-click', $event)"
  42. @locate-message="emit('locate-message', $event)"
  43. />
  44. <!-- 会话导出 -->
  45. <div v-if="currentTask?.sessionId" ref="exportWrapRef" class="export-wrapper">
  46. <div class="export-bg" title="导出会话" @click="toggleExportPopup">
  47. <div class="export-icon"></div>
  48. </div>
  49. <div v-if="showExportPopup" class="export-popup" @click.stop>
  50. <div class="export-item" @click="handleExport('md')">
  51. <div class="export-item-icon md-icon"></div>
  52. <span class="export-item-text">导出 Markdown (.md)</span>
  53. </div>
  54. <div class="export-item" @click="handleExport('word')">
  55. <div class="export-item-icon word-icon"></div>
  56. <span class="export-item-text">导出 Word (.docx)</span>
  57. </div>
  58. </div>
  59. </div>
  60. <!-- Word 报告下载按钮 -->
  61. <div v-if="currentWordUrl" class="upload-bg" @click="emit('download-word')">
  62. <div class="download-icon"></div>
  63. </div>
  64. </div>
  65. </template>
  66. <script setup lang="ts">
  67. import { ref, nextTick } from 'vue';
  68. import { onClickOutside } from '@vueuse/core';
  69. import ResourceCapsule from '/@/views/ventAI/manageAssistent/components/resource/ResourceCapsule.vue';
  70. import type { AttachedFile, CapsuleFileItem, CapsuleLinkItem, CapsuleAgentItem, Task } from '/@/views/ventAI/manageAssistent/types/index';
  71. interface Props {
  72. currentTask: Task | undefined;
  73. panelCollapsed: boolean;
  74. canGoPrev: boolean;
  75. canGoNext: boolean;
  76. currentWordUrl: string;
  77. capsuleFiles: CapsuleFileItem[];
  78. capsuleLinks: CapsuleLinkItem[];
  79. capsuleAgents: CapsuleAgentItem[];
  80. }
  81. const props = defineProps<Props>();
  82. const emit = defineEmits<{
  83. 'go-to-prev': [];
  84. 'go-to-next': [];
  85. 'create-task': [];
  86. // 保存标题时触发,参数为新标题(父组件负责 API 调用和状态更新)
  87. 'save-title': [newTitle: string];
  88. 'download-word': [];
  89. 'export-md': [];
  90. 'export-word': [];
  91. // 胶囊面板中点击上传附件,交给父组件打开右侧预览
  92. 'file-preview': [file: AttachedFile];
  93. // 胶囊面板中点击智能体条目,交给父组件打开右侧智能体详情
  94. 'agent-detail-click': [data: { messageIndex: number; agent: string; agentId?: string }];
  95. // 胶囊面板中点击"定位到消息",交给父组件滚动消息列表
  96. 'locate-message': [messageIndex: number];
  97. }>();
  98. // 导出气泡状态
  99. const exportWrapRef = ref<HTMLElement>();
  100. const showExportPopup = ref(false);
  101. const toggleExportPopup = () => {
  102. showExportPopup.value = !showExportPopup.value;
  103. };
  104. const handleExport = (type: 'md' | 'word') => {
  105. showExportPopup.value = false;
  106. if (type === 'md') emit('export-md');
  107. else emit('export-word');
  108. };
  109. onClickOutside(exportWrapRef, () => {
  110. showExportPopup.value = false;
  111. });
  112. // 标题编辑状态(UI 交互逻辑,内聚在子组件中)
  113. const editingTitle = ref(false);
  114. const editTitleValue = ref('');
  115. const titleInputRef = ref<HTMLInputElement | null>(null);
  116. const startEditTitle = () => {
  117. if (!props.currentTask?.sessionId) return;
  118. editTitleValue.value = props.currentTask.name;
  119. editingTitle.value = true;
  120. nextTick(() => {
  121. titleInputRef.value?.focus();
  122. titleInputRef.value?.select();
  123. });
  124. };
  125. const handleSaveTitle = () => {
  126. const newTitle = editTitleValue.value.trim();
  127. editingTitle.value = false;
  128. // 标题有变化时通知父组件保存
  129. if (props.currentTask?.sessionId && newTitle && newTitle !== props.currentTask.name) {
  130. emit('save-title', newTitle);
  131. }
  132. };
  133. const cancelEditTitle = () => {
  134. editingTitle.value = false;
  135. };
  136. </script>
  137. <style scoped lang="less">
  138. .chat-header {
  139. display: flex;
  140. padding: 6px 16px;
  141. flex-shrink: 0;
  142. align-items: center;
  143. background: rgba(2, 53, 100, 0.3);
  144. .chat-header-title {
  145. font-size: 16px;
  146. color: #e0e6ed;
  147. overflow: hidden;
  148. text-overflow: ellipsis;
  149. white-space: nowrap;
  150. margin-left: 10px;
  151. }
  152. .chat-header-title-wrapper {
  153. display: flex;
  154. align-items: center;
  155. flex: 1;
  156. min-width: 0;
  157. &:hover .title-edit-btn {
  158. opacity: 1;
  159. }
  160. .title-edit-btn {
  161. width: 28px;
  162. height: 28px;
  163. flex-shrink: 0;
  164. background-image: var(--img-chat-edit-icon);
  165. background-repeat: no-repeat;
  166. background-size: 16px 16px;
  167. background-position: center;
  168. cursor: pointer;
  169. opacity: 0;
  170. transition: opacity 0.2s;
  171. border-radius: 4px;
  172. margin-right: 4px;
  173. &:hover {
  174. background-color: rgba(10, 132, 255, 0.2);
  175. }
  176. }
  177. .chat-header-title {
  178. margin-left: 0;
  179. flex: 1;
  180. min-width: 0;
  181. }
  182. .title-edit-input {
  183. flex: 1;
  184. min-width: 0;
  185. height: 28px;
  186. padding: 0 8px;
  187. font-size: 14px;
  188. color: #e0e6ed;
  189. background: rgba(10, 132, 255, 0.1);
  190. border: 1px solid rgba(10, 132, 255, 0.5);
  191. border-radius: 4px;
  192. outline: none;
  193. &:focus {
  194. border-color: rgba(10, 132, 255, 0.8);
  195. }
  196. }
  197. }
  198. .nav-btn {
  199. width: 28px;
  200. height: 28px;
  201. display: flex;
  202. align-items: center;
  203. justify-content: center;
  204. cursor: pointer;
  205. border-radius: 4px;
  206. transition: background 0.2s;
  207. &:hover:not(.disabled) {
  208. background: rgba(10, 132, 255, 0.15);
  209. }
  210. &.disabled {
  211. opacity: 0.3;
  212. cursor: not-allowed;
  213. }
  214. .nav-icon {
  215. width: 16px;
  216. height: 16px;
  217. background-repeat: no-repeat;
  218. background-size: 100% 100%;
  219. }
  220. .prev-icon {
  221. background-image: var(--img-chat-prev-icon);
  222. }
  223. .next-icon {
  224. background-image: var(--img-chat-next-icon);
  225. }
  226. .add-icon {
  227. background-image: var(--img-chat-options-add-icon);
  228. }
  229. }
  230. .export-wrapper {
  231. position: relative;
  232. flex-shrink: 0;
  233. }
  234. .export-bg {
  235. cursor: pointer;
  236. width: 36px;
  237. height: 36px;
  238. margin-left: 8px;
  239. display: flex;
  240. align-items: center;
  241. justify-content: center;
  242. .export-icon {
  243. width: 18px;
  244. height: 18px;
  245. background-image: var(--img-chat-export-icon);
  246. background-repeat: no-repeat;
  247. background-size: 100% 100%;
  248. }
  249. }
  250. .export-popup {
  251. position: absolute;
  252. top: calc(100% + 6px);
  253. right: 0;
  254. background: #0a2a3f;
  255. border: 1px solid #1a4a6f;
  256. border-radius: 8px;
  257. min-width: 180px;
  258. z-index: 1000;
  259. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  260. padding: 4px;
  261. .export-item {
  262. display: flex;
  263. align-items: center;
  264. gap: 10px;
  265. padding: 9px 16px;
  266. cursor: pointer;
  267. transition: background 0.2s;
  268. border-radius: 6px;
  269. &:hover {
  270. background: rgba(10, 132, 255, 0.15);
  271. }
  272. .export-item-icon {
  273. width: 18px;
  274. height: 18px;
  275. background-repeat: no-repeat;
  276. background-size: 100% 100%;
  277. flex-shrink: 0;
  278. }
  279. .md-icon {
  280. background-image: var(--img-chat-file-md-icon);
  281. }
  282. .word-icon {
  283. background-image: var(--img-chat-file-word-icon);
  284. }
  285. .export-item-text {
  286. font-size: 13px;
  287. color: #e0e6ed;
  288. white-space: nowrap;
  289. }
  290. }
  291. }
  292. .upload-bg {
  293. cursor: pointer;
  294. width: 36px;
  295. height: 36px;
  296. background-image: var(--img-chat-close-bg);
  297. background-repeat: no-repeat;
  298. background-size: 100% 100%;
  299. display: flex;
  300. align-items: center;
  301. justify-content: center;
  302. margin-left: auto;
  303. position: relative;
  304. }
  305. .download-icon {
  306. width: 20px;
  307. height: 20px;
  308. background-image: var(--img-chat-download-icon);
  309. background-repeat: no-repeat;
  310. background-size: 100% 100%;
  311. }
  312. }
  313. </style>