ChatHeader.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. <div v-if="currentTask?.sessionId" ref="exportWrapRef" class="export-wrapper">
  35. <div class="export-bg" title="导出会话" @click="toggleExportPopup">
  36. <div class="export-icon"></div>
  37. </div>
  38. <div v-if="showExportPopup" class="export-popup" @click.stop>
  39. <div class="export-item" @click="handleExport('md')">
  40. <div class="export-item-icon md-icon"></div>
  41. <span class="export-item-text">导出 Markdown (.md)</span>
  42. </div>
  43. <div class="export-item" @click="handleExport('word')">
  44. <div class="export-item-icon word-icon"></div>
  45. <span class="export-item-text">导出 Word (.docx)</span>
  46. </div>
  47. </div>
  48. </div>
  49. <!-- Word 报告下载按钮 -->
  50. <div v-if="currentWordUrl" class="upload-bg" @click="emit('download-word')">
  51. <div class="download-icon"></div>
  52. </div>
  53. </div>
  54. </template>
  55. <script setup lang="ts">
  56. import { ref, nextTick } from 'vue';
  57. import { onClickOutside } from '@vueuse/core';
  58. import type { Task } from './types';
  59. interface Props {
  60. currentTask: Task | undefined;
  61. panelCollapsed: boolean;
  62. canGoPrev: boolean;
  63. canGoNext: boolean;
  64. currentWordUrl: string;
  65. }
  66. const props = defineProps<Props>();
  67. const emit = defineEmits<{
  68. 'go-to-prev': [];
  69. 'go-to-next': [];
  70. 'create-task': [];
  71. // 保存标题时触发,参数为新标题(父组件负责 API 调用和状态更新)
  72. 'save-title': [newTitle: string];
  73. 'download-word': [];
  74. 'export-md': [];
  75. 'export-word': [];
  76. }>();
  77. // 导出气泡状态
  78. const exportWrapRef = ref<HTMLElement>();
  79. const showExportPopup = ref(false);
  80. const toggleExportPopup = () => {
  81. showExportPopup.value = !showExportPopup.value;
  82. };
  83. const handleExport = (type: 'md' | 'word') => {
  84. showExportPopup.value = false;
  85. if (type === 'md') emit('export-md');
  86. else emit('export-word');
  87. };
  88. onClickOutside(exportWrapRef, () => {
  89. showExportPopup.value = false;
  90. });
  91. // 标题编辑状态(UI 交互逻辑,内聚在子组件中)
  92. const editingTitle = ref(false);
  93. const editTitleValue = ref('');
  94. const titleInputRef = ref<HTMLInputElement | null>(null);
  95. const startEditTitle = () => {
  96. if (!props.currentTask?.sessionId) return;
  97. editTitleValue.value = props.currentTask.name;
  98. editingTitle.value = true;
  99. nextTick(() => {
  100. titleInputRef.value?.focus();
  101. titleInputRef.value?.select();
  102. });
  103. };
  104. const handleSaveTitle = () => {
  105. const newTitle = editTitleValue.value.trim();
  106. editingTitle.value = false;
  107. // 标题有变化时通知父组件保存
  108. if (props.currentTask?.sessionId && newTitle && newTitle !== props.currentTask.name) {
  109. emit('save-title', newTitle);
  110. }
  111. };
  112. const cancelEditTitle = () => {
  113. editingTitle.value = false;
  114. };
  115. </script>
  116. <style scoped lang="less">
  117. .chat-header {
  118. display: flex;
  119. padding: 12px 20px;
  120. flex-shrink: 0;
  121. align-items: center;
  122. background: rgba(2, 53, 100, 0.3);
  123. .chat-header-title {
  124. font-size: 16px;
  125. color: #e0e6ed;
  126. overflow: hidden;
  127. text-overflow: ellipsis;
  128. white-space: nowrap;
  129. margin-left: 10px;
  130. }
  131. .chat-header-title-wrapper {
  132. display: flex;
  133. align-items: center;
  134. flex: 1;
  135. min-width: 0;
  136. &:hover .title-edit-btn {
  137. opacity: 1;
  138. }
  139. .title-edit-btn {
  140. width: 28px;
  141. height: 28px;
  142. flex-shrink: 0;
  143. background-image: var(--img-chat-edit-icon);
  144. background-repeat: no-repeat;
  145. background-size: 16px 16px;
  146. background-position: center;
  147. cursor: pointer;
  148. opacity: 0;
  149. transition: opacity 0.2s;
  150. border-radius: 4px;
  151. margin-right: 4px;
  152. &:hover {
  153. background-color: rgba(10, 132, 255, 0.2);
  154. }
  155. }
  156. .chat-header-title {
  157. margin-left: 0;
  158. flex: 1;
  159. min-width: 0;
  160. }
  161. .title-edit-input {
  162. flex: 1;
  163. min-width: 0;
  164. height: 28px;
  165. padding: 0 8px;
  166. font-size: 14px;
  167. color: #e0e6ed;
  168. background: rgba(10, 132, 255, 0.1);
  169. border: 1px solid rgba(10, 132, 255, 0.5);
  170. border-radius: 4px;
  171. outline: none;
  172. &:focus {
  173. border-color: rgba(10, 132, 255, 0.8);
  174. }
  175. }
  176. }
  177. .nav-btn {
  178. width: 28px;
  179. height: 28px;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. cursor: pointer;
  184. border-radius: 4px;
  185. transition: background 0.2s;
  186. &:hover:not(.disabled) {
  187. background: rgba(10, 132, 255, 0.15);
  188. }
  189. &.disabled {
  190. opacity: 0.3;
  191. cursor: not-allowed;
  192. }
  193. .nav-icon {
  194. width: 16px;
  195. height: 16px;
  196. background-repeat: no-repeat;
  197. background-size: 100% 100%;
  198. }
  199. .prev-icon {
  200. background-image: var(--img-chat-prev-icon);
  201. }
  202. .next-icon {
  203. background-image: var(--img-chat-next-icon);
  204. }
  205. .add-icon {
  206. background-image: var(--img-chat-options-add-icon);
  207. }
  208. }
  209. .export-wrapper {
  210. position: relative;
  211. flex-shrink: 0;
  212. }
  213. .export-bg {
  214. cursor: pointer;
  215. width: 36px;
  216. height: 36px;
  217. margin-left: 8px;
  218. display: flex;
  219. align-items: center;
  220. justify-content: center;
  221. .export-icon {
  222. width: 18px;
  223. height: 18px;
  224. background-image: var(--img-chat-export-icon);
  225. background-repeat: no-repeat;
  226. background-size: 100% 100%;
  227. }
  228. }
  229. .export-popup {
  230. position: absolute;
  231. top: calc(100% + 6px);
  232. right: 0;
  233. background: #0a2a3f;
  234. border: 1px solid #1a4a6f;
  235. border-radius: 8px;
  236. min-width: 180px;
  237. z-index: 1000;
  238. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  239. padding: 4px;
  240. .export-item {
  241. display: flex;
  242. align-items: center;
  243. gap: 10px;
  244. padding: 9px 16px;
  245. cursor: pointer;
  246. transition: background 0.2s;
  247. border-radius: 6px;
  248. &:hover {
  249. background: rgba(10, 132, 255, 0.15);
  250. }
  251. .export-item-icon {
  252. width: 18px;
  253. height: 18px;
  254. background-repeat: no-repeat;
  255. background-size: 100% 100%;
  256. flex-shrink: 0;
  257. }
  258. .md-icon {
  259. background-image: var(--img-chat-file-md-icon);
  260. }
  261. .word-icon {
  262. background-image: var(--img-chat-file-word-icon);
  263. }
  264. .export-item-text {
  265. font-size: 13px;
  266. color: #e0e6ed;
  267. white-space: nowrap;
  268. }
  269. }
  270. }
  271. .upload-bg {
  272. cursor: pointer;
  273. width: 36px;
  274. height: 36px;
  275. background-image: var(--img-chat-close-bg);
  276. background-repeat: no-repeat;
  277. background-size: 100% 100%;
  278. display: flex;
  279. align-items: center;
  280. justify-content: center;
  281. margin-left: auto;
  282. position: relative;
  283. }
  284. .download-icon {
  285. width: 20px;
  286. height: 20px;
  287. background-image: var(--img-chat-download-icon);
  288. background-repeat: no-repeat;
  289. background-size: 100% 100%;
  290. }
  291. }
  292. </style>