index.vue 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529
  1. <script setup lang="ts">
  2. import { computed, isReactive, nextTick, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
  3. import { Local } from '/@/utils/storage'
  4. import common from '/@/api/common/index'
  5. import {
  6. ArrowDown,
  7. ChatDotRound,
  8. Check,
  9. Close,
  10. CopyDocument,
  11. Delete,
  12. Download,
  13. Edit,
  14. Loading,
  15. MoreFilled,
  16. Plus,
  17. Promotion,
  18. Search,
  19. Setting,
  20. Setting as EleSetting,
  21. Star,
  22. StarFilled,
  23. User,
  24. VideoPause,
  25. Document,
  26. Picture,
  27. VideoPlay,
  28. Headset,
  29. Files,
  30. } from '@element-plus/icons-vue'
  31. import { MarkdownPlugin } from '/@/components/markdown/type/markdown'
  32. import EChartsPlugin from '/@/components/markdown/plugins/echarts'
  33. import ToolsLoadingPlugin from '/@/components/markdown/plugins/tools-loading'
  34. import TablePlugin from '/@/components/markdown/plugins/table'
  35. import Markdown from '/@/components/markdown/Markdown.vue'
  36. import assist from '/@/api/assist'
  37. import { ChatResponse, LmConfigInfo, LmSession, Message, Prompt } from '/@/api/assist/type'
  38. import { useLoading } from '/@/utils/loading-util'
  39. import { useRouter } from 'vue-router'
  40. import { ElMessage, ElMessageBox } from 'element-plus'
  41. import StructDataPlugin from '/@/components/markdown/plugins/struct-data'
  42. import { useFileDialog } from '@vueuse/core'
  43. import download from 'downloadjs'
  44. const plugins: Array<MarkdownPlugin<any>> = [EChartsPlugin(), ToolsLoadingPlugin(), TablePlugin(), StructDataPlugin()]
  45. //聊天管理接口
  46. // 消息列表
  47. const messages = ref<Message[]>([])
  48. const messagesContainer = ref<HTMLElement>()
  49. // 输入框内容
  50. const inputMessage = ref('')
  51. const {
  52. open,
  53. reset,
  54. files: attachments,
  55. } = useFileDialog({
  56. multiple: true,
  57. })
  58. // 附件管理:使用本地列表以支持单个移除
  59. const selectedFiles = ref<File[]>([])
  60. watch(
  61. attachments,
  62. (newFiles) => {
  63. if (newFiles === null || newFiles.length === 0) return
  64. selectedFiles.value = [...selectedFiles.value, ...newFiles]
  65. reset()
  66. },
  67. { immediate: true }
  68. )
  69. const removeAttachment = (index: number) => {
  70. if (index < 0 || index >= selectedFiles.value.length) return
  71. selectedFiles.value.splice(index, 1)
  72. }
  73. // // 选中的工具和模型
  74. // const selectedTool = ref([])
  75. // // 工具选择
  76. // const toolOptions = ref([
  77. // {
  78. // value: 'code',
  79. // label: '代码工具',
  80. // children: [
  81. // {
  82. // value: 'codebase-retrieval',
  83. // label: '代码库检索',
  84. // },
  85. // {
  86. // value: 'str-replace-editor',
  87. // label: '代码编辑器',
  88. // },
  89. // {
  90. // value: 'save-file',
  91. // label: '文件保存',
  92. // },
  93. // ],
  94. // },
  95. // {
  96. // value: 'web',
  97. // label: '网络工具',
  98. // children: [
  99. // {
  100. // value: 'web-search',
  101. // label: '网络搜索',
  102. // },
  103. // {
  104. // value: 'web-fetch',
  105. // label: '网页获取',
  106. // },
  107. // ],
  108. // },
  109. // {
  110. // value: 'system',
  111. // label: '系统工具',
  112. // children: [
  113. // {
  114. // value: 'execute-command',
  115. // label: '命令执行',
  116. // },
  117. // {
  118. // value: 'launch-process',
  119. // label: '进程启动',
  120. // },
  121. // ],
  122. // },
  123. // ])
  124. // 模型选择
  125. const modelOptions = ref<LmConfigInfo[]>([])
  126. const modelLabel = computed(() => {
  127. if (!loadingModels.value && selectedModel.value === undefined) {
  128. return '未配置模型'
  129. }
  130. const select = modelOptions.value.filter((i) => i.id === selectedModel.value)
  131. if (select.length === 0) {
  132. return '加载中'
  133. }
  134. return select[0].modelName
  135. })
  136. const { loading: loadingModels, doLoading: loadModel } = useLoading(async () => {
  137. const data: { list: LmConfigInfo[]; total: number } = await assist.model.getList({ modelType: 'chat' }).catch(() => {
  138. return {
  139. list: [],
  140. }
  141. })
  142. modelOptions.value = data.list ?? []
  143. selectedModel.value = modelOptions.value[0]?.id ?? undefined
  144. })
  145. // 词嵌入模型选择
  146. const embeddingModelOptions = ref<LmConfigInfo[]>([])
  147. const selectedEmbeddingModel = ref<number | undefined>(undefined)
  148. const embeddingModelLabel = computed(() => {
  149. if (!loadingEmbeddingModels.value && selectedEmbeddingModel.value === undefined) {
  150. return '未配置词嵌入'
  151. }
  152. const select = embeddingModelOptions.value.filter((i) => i.id === selectedEmbeddingModel.value)
  153. if (select.length === 0) {
  154. return '加载中'
  155. }
  156. return select[0].modelName
  157. })
  158. onMounted(loadModel)
  159. const { loading: loadingEmbeddingModels, doLoading: loadEmbeddingModel } = useLoading(async () => {
  160. const data: { list: LmConfigInfo[]; total: number } = await assist.model.getList({ modelType: 'embedding' }).catch(() => {
  161. return {
  162. list: [],
  163. }
  164. })
  165. embeddingModelOptions.value = data.list ?? []
  166. if (embeddingModelOptions.value.length !== 0) {
  167. embeddingModelOptions.value.unshift({
  168. id: -1,
  169. modelName: '不启用词嵌入',
  170. status: true,
  171. })
  172. }
  173. selectedEmbeddingModel.value = embeddingModelOptions.value[0]?.id ?? undefined
  174. })
  175. onMounted(loadEmbeddingModel)
  176. // 提示词列表相关状态
  177. const customPrompt = ref('')
  178. const promptList = ref<Prompt[]>([])
  179. const displayPromptList = computed(() => {
  180. //有提示词展示自定义提示词
  181. let r = [...promptList.value]
  182. if (customPrompt.value.trim() !== '') {
  183. r.splice(1, 0, {
  184. id: -2,
  185. title: `自定义提示词 (${customPrompt.value.length}) 字`,
  186. prompt: customPrompt.value,
  187. })
  188. }
  189. return r
  190. })
  191. const selectPromptId = ref<number | undefined>(undefined)
  192. watch(selectPromptId, (newVal) => {
  193. const placeholder = displayPromptList.value.find((i) => i.id === newVal)?.placeholder
  194. if (placeholder === undefined) {
  195. return
  196. }
  197. messages.value.push({
  198. id: messages.value.length,
  199. render_content: placeholder,
  200. timestamp: Date.now(),
  201. role: 'assistant',
  202. content: placeholder
  203. })
  204. // inputMessage.value = displayPromptList.value.find((i) => i.id === newVal)?.placeholder ?? ''
  205. })
  206. const promptLabel = computed(() => {
  207. if (!loadingPromptList.value && selectPromptId.value === undefined) {
  208. return '未配置提示词'
  209. }
  210. const select = displayPromptList.value.filter((i) => i.id === selectPromptId.value)
  211. if (select.length === 0) {
  212. return '加载中'
  213. }
  214. return select[0].title
  215. })
  216. const { loading: loadingPromptList, doLoading: loadPromptList } = useLoading(async () => {
  217. const data: { list: Prompt[]; total: number } = await assist.chat.prompt.list({ pageSize: 10, pageNum: 1, keyWord: '' }).catch(() => {
  218. return {
  219. list: [],
  220. total: 0,
  221. }
  222. })
  223. promptList.value = data.list ?? []
  224. if (promptList.value.length !== 0) {
  225. promptList.value.unshift({
  226. id: -1,
  227. title: '不启用提示词',
  228. prompt: '',
  229. })
  230. }
  231. selectPromptId.value = promptList.value[0]?.id ?? undefined
  232. })
  233. onMounted(loadPromptList)
  234. const selectedModel = ref<number | undefined>(undefined)
  235. // 提示词管理对话框可见性
  236. const promptDialogVisible = ref(false)
  237. const chatInstance = ref<(() => void) | undefined>(undefined)
  238. onUnmounted(() => chatInstance.value?.())
  239. // 是否正在对话
  240. const isConversationActive = computed(() => chatInstance.value !== undefined || loadingUpload.value)
  241. const { loading: loadingClearMessage, doLoading: clearMessage } = useLoading(async () => {
  242. stopConversation()
  243. if (messages.value.length !== 0 && activeConversationId.value !== undefined) {
  244. const res = await assist.session.message
  245. .save({
  246. sessionId: activeConversationId.value,
  247. messages: [],
  248. })
  249. .then(() => true)
  250. .catch(() => false)
  251. if (!res) {
  252. return
  253. }
  254. }
  255. messages.value = []
  256. })
  257. const {loading:loadingUpload,doLoading: doUpload} = useLoading(async ()=> {
  258. return selectedFiles.value.length === 0 ? undefined : (await common.upload.multi(selectedFiles.value)) as Message['files']
  259. })
  260. // 发送消息
  261. const sendMessage = async () => {
  262. if (!inputMessage.value.trim()) return
  263. if (activeConversationId.value === undefined) {
  264. //未选中任何会话则创建新会话
  265. await createConversationAndSetItActive()
  266. }
  267. await nextTick()
  268. messages.value.push({
  269. id: messages.value.length,
  270. role: 'user',
  271. render_content: inputMessage.value,
  272. content: inputMessage.value,
  273. timestamp: Date.now(),
  274. files: await doUpload(),
  275. })
  276. selectedFiles.value = []
  277. const rtn = reactive<Message>({
  278. id: messages.value.length,
  279. role: 'assistant',
  280. render_content: '',
  281. content: '',
  282. timestamp: Date.now(),
  283. tool_calls: [],
  284. })
  285. inputMessage.value = ''
  286. scrollToBottom()
  287. chatInternal(rtn)
  288. messages.value.push(rtn)
  289. }
  290. const replaceMessage = async (index: number) => {
  291. // 获取当前用户消息
  292. const userMessage = messages.value[index]
  293. if (!userMessage || userMessage.role !== 'user') {
  294. return
  295. }
  296. // 查找对应的AI回复消息(通常是下一条消息)
  297. let aiMessageIndex = -1
  298. for (let i = index + 1; i < messages.value.length; i++) {
  299. if (messages.value[i].role === 'assistant') {
  300. aiMessageIndex = i
  301. break
  302. }
  303. }
  304. let rtn: Message
  305. if (aiMessageIndex !== -1) {
  306. // 找到了AI回复消息
  307. const aiMessage = messages.value[aiMessageIndex]
  308. if (aiMessage?.like === true) {
  309. const confirm = await ElMessageBox({
  310. title: '提示',
  311. message: '替换消息会导致收藏内容被修改,是否继续?',
  312. type: 'warning',
  313. confirmButtonText: '确认',
  314. cancelButtonText: '取消',
  315. })
  316. if (!confirm) {
  317. return
  318. }
  319. }
  320. if (isReactive(aiMessage)) {
  321. // 如果是reactive对象,清空内容
  322. aiMessage.render_content = ''
  323. aiMessage.content = ''
  324. aiMessage.tool_calls = []
  325. rtn = aiMessage
  326. } else {
  327. // 如果不是reactive对象,创建新的reactive对象替换
  328. rtn = reactive<Message>({
  329. id: aiMessage.id,
  330. role: 'assistant',
  331. render_content: '',
  332. content: '',
  333. timestamp: aiMessage.timestamp,
  334. tool_calls: [],
  335. })
  336. messages.value[aiMessageIndex] = rtn
  337. }
  338. } else {
  339. // 没有找到AI回复消息,创建新的
  340. rtn = reactive<Message>({
  341. id: messages.value.length,
  342. role: 'assistant',
  343. render_content: '',
  344. content: '',
  345. timestamp: Date.now(),
  346. tool_calls: [],
  347. })
  348. messages.value.push(rtn)
  349. }
  350. // 重新发起对话
  351. chatInternal(rtn, messages.value.slice(0, aiMessageIndex))
  352. }
  353. const chatInternal = (rtn: Message, context: Message[] = messages.value) => {
  354. let r = [...context]
  355. if (selectPromptId.value != undefined && selectPromptId.value != -1) {
  356. const prompt = displayPromptList.value.find((i) => i.id === selectPromptId.value)?.prompt ?? ''
  357. //insert element on top
  358. r.unshift({
  359. id: messages.value.length,
  360. role: 'system',
  361. render_content: prompt,
  362. content: prompt,
  363. timestamp: Date.now(),
  364. })
  365. }
  366. chatInstance.value = assist.chat.sse({
  367. chatRequest: {
  368. session_id: activeConversationId.value!,
  369. message: r,
  370. modelClassId: selectedModel.value,
  371. modelEmbeddingId: (selectedEmbeddingModel.value ?? -1) > 0 ? selectedEmbeddingModel.value : undefined,
  372. },
  373. onReceive: (resp: ChatResponse) => {
  374. switch (resp.type) {
  375. case 'structdata':
  376. rtn.render_content += `
  377. \`\`\`structdata
  378. ${resp.uuid}
  379. \`\`\`
  380. `
  381. break
  382. case 'message':
  383. rtn.render_content += resp.message
  384. rtn.content += resp.message
  385. break
  386. case 'toolres': {
  387. if (showToolCalls.value) {
  388. rtn.render_content += `
  389. \`\`\`tools-loading
  390. resp
  391. ${resp.response.name}
  392. ${resp.response.data.replace('\n', '')}
  393. \`\`\`
  394. `
  395. } else {
  396. if (rtn.render_content.at(-1) !== '\n') {
  397. rtn.render_content += '\n\n'
  398. }
  399. }
  400. //防止重试时底部有聊天记录无脑插入到底部出现后端无法识别的问题
  401. messages.value.splice(messages.value.indexOf(rtn) + 1, 0, {
  402. id: messages.value.length,
  403. tool_call_id: resp.response.id,
  404. role: 'tool',
  405. render_content: '',
  406. name: resp.response.name,
  407. content: resp.response.data,
  408. timestamp: Date.now(),
  409. tool_calls: [],
  410. })
  411. break
  412. }
  413. case 'toolcall': {
  414. if (showToolCalls.value) {
  415. rtn.render_content += `
  416. \`\`\`tools-loading
  417. request
  418. ${resp.request.name}
  419. ${resp.request.data.replace('\n', '')}
  420. \`\`\`
  421. `
  422. }
  423. rtn.tool_calls?.push({
  424. id: resp.request.id,
  425. type: 'function',
  426. function: {
  427. name: resp.request.name,
  428. arguments: resp.request.data,
  429. },
  430. })
  431. break
  432. }
  433. case 'error':
  434. rtn.render_content += `
  435. > ### 系统报错
  436. >
  437. >
  438. > ${resp.error.split('\n').join('\n> ')}
  439. `
  440. //过滤ai消息下的所有tool防止报错,鬼知道后端怎么想的
  441. messages.value = messages.value.slice(0, messages.value.indexOf(rtn) + 1)
  442. break
  443. }
  444. },
  445. onComplete: async (e) => {
  446. if (e !== undefined) {
  447. rtn.content += `
  448. `
  449. }
  450. rtn.render_content += '\n'
  451. const save_status = await assist.session.message
  452. .save({
  453. sessionId: activeConversationId.value!,
  454. messages: messages.value,
  455. })
  456. .then(() => true)
  457. .catch(() => false)
  458. if (!save_status) {
  459. ElMessage.warning('消息保存失败,切换对话会导致消息记录丢失')
  460. }
  461. chatInstance.value = undefined
  462. },
  463. })
  464. }
  465. // 终止对话
  466. const stopConversation = () => {
  467. chatInstance.value?.()
  468. chatInstance.value = undefined
  469. }
  470. // 滚动到底部
  471. const scrollToBottom = () => {
  472. nextTick(() => {
  473. if (messagesContainer.value) {
  474. messagesContainer.value.scrollTop = messagesContainer.value.scrollHeight
  475. }
  476. })
  477. }
  478. // 会话管理模块
  479. // 所有会话
  480. const conversations = ref<LmSession[]>([])
  481. const displayConversations = computed(() => {
  482. return [{ session_id: -1, title: '收藏夹' }, ...conversations.value]
  483. })
  484. const { loading: loadConversations, doLoading: doLoadConversations } = useLoading(async () => {
  485. const data: { list: LmSession[]; total: number } = await assist.session
  486. .list({
  487. pageNum: 1,
  488. pageSize: 30,
  489. })
  490. .catch(() => {
  491. return {
  492. list: [],
  493. total: 0,
  494. }
  495. })
  496. conversations.value = data.list ?? []
  497. })
  498. onMounted(doLoadConversations)
  499. // 当前活跃会话
  500. const activeConversationId = ref<number | undefined>(undefined)
  501. // watch(activeConversationId, async (newVal) => {
  502. // if (newVal === undefined) {
  503. // return
  504. // }
  505. // await doLoadingMessage(newVal)
  506. // })
  507. const bookmarkOptions = ref({
  508. pageSize: 30,
  509. pageNum: 1,
  510. keyWord: '',
  511. })
  512. // 收藏消息总数
  513. const bookmarkTotal = ref(0)
  514. const { loading: loadingMessage, doLoading: doLoadingMessage } = useLoading(async (id: number) => {
  515. //如果id是-1,拉取收藏的记录
  516. if (id === -1) {
  517. const data: {
  518. messages: Message[]
  519. total: number
  520. } = await assist.session.message.bookmark_list(bookmarkOptions.value).catch(() => {
  521. return {
  522. list: [],
  523. total: 0,
  524. }
  525. })
  526. messages.value = data.messages ?? []
  527. bookmarkTotal.value = data.total ?? 0
  528. return
  529. }
  530. const data: {
  531. messages: Message[]
  532. total: number
  533. } = await assist.session.message.list({ sessionId: id }).catch(() => {
  534. return {
  535. list: [],
  536. total: 0,
  537. }
  538. })
  539. messages.value = data.messages ?? []
  540. })
  541. // 选择会话
  542. const selectConversation = async (id: number) => {
  543. if (activeConversationId.value === id) {
  544. return
  545. }
  546. activeConversationId.value = id
  547. await doLoadingMessage(id)
  548. }
  549. // 删除会话
  550. const currentDeletingConversation = ref(-1)
  551. const { loading: loadingDeleteConversation, doLoading: deleteConversation } = useLoading(async (id: number) => {
  552. currentDeletingConversation.value = id
  553. const res = await assist.session
  554. .del([id])
  555. .then(() => true)
  556. .catch(() => false)
  557. .finally(() => (currentDeletingConversation.value = -1))
  558. if (!res) {
  559. return
  560. }
  561. ElMessage.success('删除成功')
  562. activeConversationId.value = undefined
  563. messages.value = []
  564. conversations.value = conversations.value.filter((item) => item.session_id !== id)
  565. // await nextTick()
  566. // await doLoadConversations()
  567. })
  568. const multiDeleteConversationModel = ref({
  569. visible: false,
  570. selectedConversations: [] as number[],
  571. })
  572. const multiDeleteConversationClear = () => {
  573. multiDeleteConversationModel.value.selectedConversations = []
  574. multiDeleteConversationModel.value.visible = false
  575. }
  576. // 多选删除会话
  577. const startMultidelete = async () => {
  578. if (multiDeleteConversationModel.value.selectedConversations.length === 0) {
  579. ElMessage.warning('请选择要删除的会话')
  580. return
  581. }
  582. const confirm = await ElMessageBox.confirm(
  583. `确定要删除选中的 ${multiDeleteConversationModel.value.selectedConversations.length} 个会话吗?此操作不可恢复!`,
  584. '警告',
  585. {
  586. confirmButtonText: '确定',
  587. cancelButtonText: '取消',
  588. type: 'error',
  589. }
  590. )
  591. if (confirm !== 'confirm') {
  592. return
  593. }
  594. const res = await assist.session
  595. .del(multiDeleteConversationModel.value.selectedConversations)
  596. .then(() => true)
  597. .catch(() => false)
  598. if (!res) {
  599. return
  600. }
  601. ElMessage.success('删除成功')
  602. await nextTick()
  603. await doLoadConversations()
  604. }
  605. // 创建新对话
  606. const { loading: creatingConversation, doLoading: createConversationAndSetItActive } = useLoading(async () => {
  607. // 调用API创建新对话,默认标题为"新对话"
  608. const { id } = await assist.session.add('新对话')
  609. // 刷新对话列表
  610. await doLoadConversations()
  611. await nextTick()
  612. activeConversationId.value = id
  613. messages.value = []
  614. })
  615. // 编辑会话状态管理
  616. const editingConversationId = ref<number | undefined>(undefined)
  617. const editingTitle = ref('')
  618. // 编辑会话摘要
  619. const editSummary = (id: number) => {
  620. const conversation = conversations.value.find((conv) => conv.session_id === id)
  621. if (conversation) {
  622. // 设置当前编辑的会话ID
  623. editingConversationId.value = id
  624. editingTitle.value = conversation.title
  625. // 下一帧聚焦到输入框
  626. nextTick(() => {
  627. const editInput = document.querySelector('.edit-input .el-input__inner') as HTMLInputElement
  628. if (editInput) {
  629. editInput.focus()
  630. editInput.select()
  631. }
  632. })
  633. }
  634. }
  635. // 确认编辑
  636. const { doLoading: confirmEdit, loading: loadingConfirmEdit } = useLoading(async (id: number) => {
  637. const conversation = conversations.value.find((conv) => conv.session_id === id)
  638. if (conversation && editingTitle.value.trim()) {
  639. const edit = await assist.session
  640. .edit(id, editingTitle.value.trim())
  641. .then(() => true)
  642. .catch(() => false)
  643. if (!edit) {
  644. return
  645. }
  646. conversation.title = editingTitle.value.trim()
  647. // 清除编辑状态
  648. editingConversationId.value = undefined
  649. editingTitle.value = ''
  650. }
  651. })
  652. // 取消编辑
  653. const cancelEdit = () => {
  654. // 清除编辑状态
  655. editingConversationId.value = undefined
  656. editingTitle.value = ''
  657. }
  658. onMounted(() => {
  659. scrollToBottom()
  660. })
  661. //杂项
  662. const getUserInfos = ref<{
  663. avatar: string
  664. userName: string
  665. }>(Local.get('userInfo') || {})
  666. const canSendMessage = computed(() => {
  667. return !inputMessage.value.trim() || loadingModels.value || loadingEmbeddingModels.value || loadingPromptList.value || loadConversations.value || loadingMessage.value || loadingUpload.value
  668. })
  669. const router = useRouter()
  670. const redirectToModelManager = () => router.push('model')
  671. // 设置面板相关状态
  672. const showSettingsPanel = ref(false)
  673. const showToolCalls = ref(false)
  674. // 收藏消息功能
  675. const favoriteMessageIdx = ref(-1)
  676. const { loading: loadingFavoriteMessage, doLoading: toggleFavorite } = useLoading(async (messageIndex: number) => {
  677. favoriteMessageIdx.value = messageIndex
  678. const data = messages.value[messageIndex]
  679. //@ts-ignore
  680. const active = activeConversationId.value === -1 ? data['session_id'] : activeConversationId.value ?? undefined
  681. if (active === undefined) {
  682. return
  683. }
  684. const success = assist.session.message
  685. .bookmark(active, data.id, !(data.like ?? false))
  686. .then(() => true)
  687. .catch(() => false)
  688. .finally(() => (favoriteMessageIdx.value = -1))
  689. if (!success) {
  690. return
  691. }
  692. messages.value[messageIndex] = {
  693. ...data,
  694. like: !(data.like ?? false),
  695. }
  696. })
  697. // 收藏面板功能
  698. // 搜索功能
  699. const handleBookmarkSearch = async () => {
  700. bookmarkOptions.value.pageNum = 1
  701. await doLoadingMessage(-1)
  702. }
  703. // 分页变化
  704. const handleBookmarkPageChange = async (page: number) => {
  705. bookmarkOptions.value.pageNum = page
  706. await doLoadingMessage(-1)
  707. }
  708. // 每页数目变化
  709. const handleBookmarkPageSizeChange = async (pageSize: number) => {
  710. bookmarkOptions.value.pageSize = pageSize
  711. bookmarkOptions.value.pageNum = 1 // 重置到第一页
  712. await doLoadingMessage(-1)
  713. }
  714. // 重置功能
  715. const handleBookmarkReset = async () => {
  716. bookmarkOptions.value.keyWord = ''
  717. bookmarkOptions.value.pageNum = 1
  718. await doLoadingMessage(-1)
  719. }
  720. // 每页数目选项
  721. const pageSizeOptions = [3, 10, 20, 30, 50, 100]
  722. // 最大页数限制
  723. const maxPages = 100
  724. const exportToMarkDown = (message: Message) => {
  725. // 创建CSV内容
  726. const csvContent = message.render_content
  727. download(csvContent, `export_${new Date().getTime()}.md`)
  728. }
  729. // 导出对话历史
  730. const exportId = ref<number>(-1)
  731. const { loading: exportConversationLoading, doLoading: exportConversation } = useLoading(async (id: number) => {
  732. exportId.value = id
  733. const result: {
  734. messages: Message[]
  735. total: number
  736. } = await assist.session.message.list({ sessionId: id }).catch(() => {
  737. return {
  738. list: [],
  739. total: 0,
  740. }
  741. })
  742. let md = ''
  743. for (const resultElement of result.messages) {
  744. switch (resultElement.role) {
  745. case 'user': {
  746. md += '\n\n>' + resultElement.render_content + '\n\n'
  747. continue
  748. }
  749. case 'assistant': {
  750. md += '\n\n' + resultElement.render_content + '\n\n'
  751. continue
  752. }
  753. }
  754. }
  755. exportToMarkDown({
  756. id: 0,
  757. role: 'assistant',
  758. render_content: md,
  759. content: md,
  760. timestamp: Date.now(),
  761. })
  762. exportId.value = -1
  763. })
  764. const isBlank = (str: string) => {
  765. return str == null || str.trim().length === 0
  766. }
  767. // 打开文件
  768. const openFile = (fullPath: string) => {
  769. window.open(fullPath, '_blank')
  770. }
  771. // 格式化文件大小
  772. const formatFileSize = (bytes: number): string => {
  773. if (bytes === 0) return '0 B'
  774. const k = 1024
  775. const sizes = ['B', 'KB', 'MB', 'GB', 'TB']
  776. const i = Math.floor(Math.log(bytes) / Math.log(k))
  777. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
  778. }
  779. </script>
  780. <template>
  781. <el-container class="chat-container">
  782. <!-- 左侧会话列表 -->
  783. <el-aside width="300px" class="chat-sidebar">
  784. <div class="sidebar-header">
  785. <h3>对话历史</h3>
  786. <el-dropdown v-model="showSettingsPanel" trigger="click" placement="bottom-end">
  787. <el-button round :icon="EleSetting" size="small">
  788. <el-icon class="el-icon--right">
  789. <ArrowDown />
  790. </el-icon>
  791. </el-button>
  792. <template #dropdown>
  793. <el-dropdown-menu v-if="!multiDeleteConversationModel.visible">
  794. <el-dropdown-item class="settings-item">
  795. <div class="settings-row">
  796. <span class="settings-label">新对话自动记录工具调用</span>
  797. <el-switch v-model="showToolCalls" size="small" />
  798. </div>
  799. </el-dropdown-item>
  800. <el-dropdown-item @click="redirectToModelManager">
  801. <span class="settings-label">模型管理</span>
  802. </el-dropdown-item>
  803. <el-dropdown-item @click="promptDialogVisible = true">
  804. <span class="settings-label">提示词管理</span>
  805. </el-dropdown-item>
  806. <el-dropdown-item @click="multiDeleteConversationModel.visible = true">
  807. <span class="settings-label">对话管理</span>
  808. </el-dropdown-item>
  809. </el-dropdown-menu>
  810. <el-dropdown-menu v-else>
  811. <el-dropdown-item @click="multiDeleteConversationClear">
  812. <el-icon>
  813. <Close />
  814. </el-icon>
  815. <span>取消选择</span>
  816. </el-dropdown-item>
  817. <el-dropdown-item @click="startMultidelete">
  818. <el-icon>
  819. <Delete />
  820. </el-icon>
  821. <span>删除选中</span>
  822. </el-dropdown-item>
  823. </el-dropdown-menu>
  824. </template>
  825. </el-dropdown>
  826. </div>
  827. <el-scrollbar class="conversation-list" v-loading="loadConversations">
  828. <div
  829. v-for="conv in displayConversations"
  830. :key="conv.session_id"
  831. @click="(editingConversationId !== conv.session_id && !multiDeleteConversationModel.visible) ? selectConversation(conv.session_id) : () => {}"
  832. :class="['conversation-item', { active: activeConversationId === conv.session_id, editing: editingConversationId === conv.session_id }]"
  833. >
  834. <!-- 非编辑状态 -->
  835. <div v-if="editingConversationId !== conv.session_id" class="conversation-content">
  836. <el-checkbox
  837. v-if="multiDeleteConversationModel.visible && conv.session_id !== -1 && conv.session_id !== activeConversationId"
  838. :model-value="multiDeleteConversationModel.selectedConversations.includes(conv.session_id)"
  839. @change="(enable: boolean) => enable ? multiDeleteConversationModel.selectedConversations.push(conv.session_id) : multiDeleteConversationModel.selectedConversations = multiDeleteConversationModel.selectedConversations.filter((id: number) => id !== conv.session_id)"
  840. :disabled="isConversationActive && activeConversationId === conv.session_id"
  841. @click.stop
  842. />
  843. <span class="conversation-title">{{ conv.title }}</span>
  844. </div>
  845. <!-- 编辑状态 -->
  846. <div v-else class="conversation-edit-content">
  847. <el-input
  848. v-model="editingTitle"
  849. size="small"
  850. @keydown.enter="confirmEdit(conv.session_id)"
  851. @keydown.esc="cancelEdit"
  852. class="edit-input"
  853. />
  854. </div>
  855. <!-- 操作按钮 -->
  856. <div class="conversation-actions" v-if="conv.session_id !== -1 && !multiDeleteConversationModel.visible">
  857. <!-- 非编辑状态的三点菜单 -->
  858. <template v-if="editingConversationId !== conv.session_id">
  859. <el-dropdown trigger="click" placement="bottom-end" @click.stop>
  860. <el-button type="primary" size="small" :icon="MoreFilled" class="action-btn more-btn" title="更多操作" plain circle @click.stop />
  861. <template #dropdown>
  862. <el-dropdown-menu>
  863. <el-dropdown-item @click="exportConversation(conv.session_id)">
  864. <el-button v-if="conv.session_id === exportId && exportConversationLoading" size="small" loading circle plain />
  865. <el-icon v-else>
  866. <Download />
  867. </el-icon>
  868. <span>导出</span>
  869. </el-dropdown-item>
  870. <el-dropdown-item @click="editSummary(conv.session_id)">
  871. <el-icon>
  872. <Edit />
  873. </el-icon>
  874. <span>编辑</span>
  875. </el-dropdown-item>
  876. <el-dropdown-item
  877. @click="deleteConversation(conv.session_id)"
  878. :disabled="isConversationActive || (loadingDeleteConversation && currentDeletingConversation == conv.session_id)"
  879. >
  880. <el-icon>
  881. <Delete />
  882. </el-icon>
  883. <span>删除</span>
  884. </el-dropdown-item>
  885. </el-dropdown-menu>
  886. </template>
  887. </el-dropdown>
  888. </template>
  889. <!-- 编辑状态的按钮 -->
  890. <template v-else>
  891. <el-button
  892. type="success"
  893. size="small"
  894. :icon="Check"
  895. :loading="loadingConfirmEdit"
  896. @click.stop="confirmEdit(conv.session_id)"
  897. class="action-btn confirm-btn"
  898. title="确认修改"
  899. plain
  900. circle
  901. />
  902. <el-button
  903. type="info"
  904. size="small"
  905. @click.stop="cancelEdit(conv.session_id)"
  906. class="action-btn cancel-btn"
  907. title="取消编辑"
  908. plain
  909. circle
  910. >
  911. <el-icon>
  912. <Close />
  913. </el-icon>
  914. </el-button>
  915. </template>
  916. </div>
  917. </div>
  918. </el-scrollbar>
  919. <el-button
  920. type="primary"
  921. size="large"
  922. class="create-conversation-btn"
  923. @click="createConversationAndSetItActive"
  924. :loading="creatingConversation"
  925. :disabled="isConversationActive"
  926. >创建对话
  927. </el-button>
  928. </el-aside>
  929. <!-- 右侧聊天区域 -->
  930. <el-main class="chat-main">
  931. <!-- 消息展示区域 -->
  932. <div class="messages-container" ref="messagesContainer" v-loading="loadingMessage">
  933. <div v-if="messages.length !== 0">
  934. <div v-for="(message, idx) in messages" :key="message.id" :class="['message-wrapper', message.role]">
  935. <!-- AI消息 -->
  936. <div v-if="message.role === 'assistant'" class="ai-message-container">
  937. <el-avatar class="message-avatar" :icon="ChatDotRound" />
  938. <div class="ai-message-content">
  939. <div class="message-bubble ai-bubble">
  940. <Markdown v-if="!isBlank(message.render_content)" :content="message.render_content" :plugins="plugins" class="markdown-content" />
  941. <div v-else class="loading-container">
  942. <div class="loading-dots">
  943. <span class="dot"></span>
  944. <span class="dot"></span>
  945. <span class="dot"></span>
  946. </div>
  947. <span class="loading-text">AI正在思考中...</span>
  948. </div>
  949. </div>
  950. <div class="ai-message-actions">
  951. <el-button
  952. :loading="favoriteMessageIdx === idx && loadingFavoriteMessage"
  953. @click="toggleFavorite(idx)"
  954. class="favorite-btn"
  955. :class="{ favorited: message.like ?? false }"
  956. :disabled="isConversationActive"
  957. :icon="message.like ?? false ? StarFilled : Star"
  958. plain
  959. circle
  960. />
  961. <el-button
  962. :loading="favoriteMessageIdx === idx && loadingFavoriteMessage"
  963. @click="exportToMarkDown(message)"
  964. class="favorite-btn"
  965. :disabled="isConversationActive"
  966. :icon="Download"
  967. plain
  968. circle
  969. />
  970. </div>
  971. </div>
  972. </div>
  973. <!-- 用户消息 -->
  974. <div v-if="message.role === 'user'" class="user-message-container">
  975. <div class="user-message-content">
  976. <div class="message-bubble user-bubble">
  977. {{ message.render_content }}
  978. <div v-if="message.files !== undefined && message.files.length > 0" class="message-files">
  979. <div
  980. v-for="file in message.files"
  981. :key="file.path"
  982. class="file-item"
  983. @click="openFile(file.full_path)"
  984. :title="`点击打开: ${file.name}`"
  985. >
  986. <el-icon class="file-icon">
  987. <Document v-if="file.type.includes('text') || file.type.includes('document')" />
  988. <Picture v-else-if="file.type.includes('image')" />
  989. <VideoPlay v-else-if="file.type.includes('video')" />
  990. <Headset v-else-if="file.type.includes('audio')" />
  991. <Files v-else />
  992. </el-icon>
  993. <span class="file-name">{{ file.name }}</span>
  994. <span class="file-size">{{ formatFileSize(file.size) }}</span>
  995. </div>
  996. </div>
  997. </div>
  998. <div class="user-message-actions">
  999. <el-button
  1000. type="primary"
  1001. size="small"
  1002. @click="replaceMessage(messages.indexOf(message))"
  1003. class="retry-btn"
  1004. plain
  1005. :disabled="isConversationActive"
  1006. >
  1007. 重试
  1008. </el-button>
  1009. </div>
  1010. </div>
  1011. <el-avatar class="message-avatar" :src="getUserInfos.avatar" :icon="User" />
  1012. </div>
  1013. </div>
  1014. </div>
  1015. <!-- 空状态页面 -->
  1016. <div v-else class="empty-content">
  1017. <!-- 收藏页面空状态 -->
  1018. <div v-if="activeConversationId === -1" class="bookmark-empty">
  1019. <div class="empty-icon">
  1020. <el-icon :size="80" color="#f59e0b">
  1021. <StarFilled />
  1022. </el-icon>
  1023. </div>
  1024. <div class="empty-text">
  1025. <h2 class="empty-title">暂无收藏消息</h2>
  1026. <p class="empty-description">您还没有收藏任何对话消息</p>
  1027. </div>
  1028. <div class="empty-tips">
  1029. <div class="tip-item">
  1030. <el-icon color="#409eff">
  1031. <InfoFilled />
  1032. </el-icon>
  1033. <span>在对话中点击 ⭐ 按钮即可收藏消息</span>
  1034. </div>
  1035. <div class="tip-item">
  1036. <el-icon color="#67c23a">
  1037. <Search />
  1038. </el-icon>
  1039. <span>收藏的消息支持关键词搜索</span>
  1040. </div>
  1041. <div class="tip-item">
  1042. <el-icon color="#e6a23c">
  1043. <Collection />
  1044. </el-icon>
  1045. <span>收藏消息会保存在云端,永不丢失</span>
  1046. </div>
  1047. </div>
  1048. </div>
  1049. <!-- 普通对话空状态 -->
  1050. <div v-else class="chat-empty">
  1051. <div class="empty-icon">
  1052. <el-icon :size="80" color="#d1d5db">
  1053. <ChatDotRound />
  1054. </el-icon>
  1055. </div>
  1056. <div class="empty-text">
  1057. <h2 class="empty-title">开始新的对话</h2>
  1058. </div>
  1059. <div class="example-questions">
  1060. <h4>试试这些问题:</h4>
  1061. <div class="question-tags">
  1062. <el-tag class="question-tag" @click="inputMessage = '帮我查看设备运行状态和告警信息'" type="info">
  1063. 帮我查看设备运行状态和告警信息
  1064. </el-tag>
  1065. <el-tag class="question-tag" @click="inputMessage = '分析用户权限配置和角色分配情况'" type="success">
  1066. 分析用户权限配置和角色分配情况
  1067. </el-tag>
  1068. <el-tag class="question-tag" @click="inputMessage = '检查系统性能和在线用户统计'" type="warning"> 检查系统性能和在线用户统计 </el-tag>
  1069. </div>
  1070. </div>
  1071. </div>
  1072. </div>
  1073. <div class="messages-spacer"></div>
  1074. </div>
  1075. <!-- 附件栏(内嵌到输入框上方) -->
  1076. <div class="input-container" v-if="activeConversationId !== -1">
  1077. <!-- 大输入框容器 -->
  1078. <div class="large-input-container">
  1079. <!-- 附件栏:紧贴输入框上方,位于容器内部 -->
  1080. <div class="attachments-inline">
  1081. <el-scrollbar>
  1082. <div class="attachments-inline-scroll">
  1083. <div
  1084. v-for="(file, fIdx) in selectedFiles"
  1085. :key="file.name + '_' + file.size + '_' + (file as any).lastModified"
  1086. class="attachment-card"
  1087. title=""
  1088. >
  1089. <button class="control-btn attachment-item" :title="`${file.name}`">
  1090. <el-icon :size="10"><CopyDocument /></el-icon>
  1091. <span class="attachment-name">{{ file.name }}</span>
  1092. </button>
  1093. <button class="remove-attachment-icon" @click="removeAttachment(fIdx)">
  1094. <el-icon><Close /></el-icon>
  1095. </button>
  1096. </div>
  1097. <!-- 无附件时的提示信息 -->
  1098. <div v-if="selectedFiles.length === 0" class="attachment-hint">
  1099. <span>点击右侧+上传文件</span>
  1100. </div>
  1101. </div>
  1102. </el-scrollbar>
  1103. <button class="control-btn add-attachment-btn" @click="open">
  1104. <el-icon :size="10"><Plus /></el-icon>
  1105. </button>
  1106. </div>
  1107. <!-- 输入框 -->
  1108. <textarea
  1109. v-model="inputMessage"
  1110. class="large-textarea"
  1111. placeholder="请输入您的问题..."
  1112. @keydown.enter.ctrl="sendMessage"
  1113. @keydown.enter.meta="sendMessage"
  1114. :disabled="isConversationActive"
  1115. rows="3"
  1116. ></textarea>
  1117. <!-- 内嵌按钮区域 -->
  1118. <div class="embedded-controls">
  1119. <!-- 左下角按钮组 -->
  1120. <div class="left-controls">
  1121. <!-- 模型选择按钮 -->
  1122. <el-dropdown trigger="click" placement="top-start" :disabled="loadingModels || modelLabel == '未配置模型'">
  1123. <button class="control-btn model-btn">
  1124. <el-icon>
  1125. <Setting v-if="!loadingModels" />
  1126. <Loading v-else class="spin" />
  1127. </el-icon>
  1128. <span>{{ modelLabel }}</span>
  1129. </button>
  1130. <template #dropdown>
  1131. <el-dropdown-menu>
  1132. <el-dropdown-item
  1133. v-for="item in modelOptions"
  1134. :key="item.id"
  1135. @click="selectedModel = item.id"
  1136. :class="{ 'is-selected': selectedModel === item.id }"
  1137. >
  1138. {{ item.modelName }}
  1139. </el-dropdown-item>
  1140. </el-dropdown-menu>
  1141. </template>
  1142. </el-dropdown>
  1143. <!-- 词嵌入模型选择按钮 -->
  1144. <el-dropdown trigger="click" placement="top-start" :disabled="loadingModels || embeddingModelLabel == '未配置词嵌入'">
  1145. <button class="control-btn embedding-model-btn">
  1146. <el-icon>
  1147. <CopyDocument v-if="!loadingEmbeddingModels" />
  1148. <Loading v-else class="spin" />
  1149. </el-icon>
  1150. <span>{{ embeddingModelLabel }}</span>
  1151. </button>
  1152. <template #dropdown>
  1153. <el-dropdown-menu>
  1154. <el-dropdown-item
  1155. v-for="item in embeddingModelOptions"
  1156. :key="item.id"
  1157. @click="selectedEmbeddingModel = item.id"
  1158. :class="{ 'is-selected': selectedEmbeddingModel === item.id }"
  1159. >
  1160. {{ item.modelName }}
  1161. </el-dropdown-item>
  1162. </el-dropdown-menu>
  1163. </template>
  1164. </el-dropdown>
  1165. <!-- 词嵌入模型选择按钮 -->
  1166. <el-dropdown trigger="click" placement="top-start" :disabled="loadingModels || promptLabel == '未配置提示词'">
  1167. <button class="control-btn embedding-model-btn">
  1168. <el-icon>
  1169. <CopyDocument v-if="!loadingPromptList" />
  1170. <Loading v-else class="spin" />
  1171. </el-icon>
  1172. <span>{{ promptLabel }}</span>
  1173. </button>
  1174. <template #dropdown>
  1175. <el-dropdown-menu>
  1176. <el-dropdown-item
  1177. v-for="item in displayPromptList"
  1178. :key="item.id"
  1179. @click="selectPromptId = item.id"
  1180. :class="{ 'is-selected': selectPromptId === item.id }"
  1181. >
  1182. {{ item.title }}
  1183. </el-dropdown-item>
  1184. </el-dropdown-menu>
  1185. </template>
  1186. </el-dropdown>
  1187. </div>
  1188. <!-- 右下角按钮组 -->
  1189. <div class="right-controls">
  1190. <!-- 清空按钮 -->
  1191. <button v-show="messages.length !== 0" class="control-btn clear-btn" @click="clearMessage" :disabled="loadingClearMessage">
  1192. <el-icon v-if="loadingClearMessage"><Loading /></el-icon>
  1193. <el-icon v-else><Delete /></el-icon>
  1194. </button>
  1195. <!-- 发送按钮 -->
  1196. <button v-if="!isConversationActive" class="control-btn send-btn" @click="sendMessage" :disabled="canSendMessage">
  1197. <el-icon><Promotion /></el-icon>
  1198. </button>
  1199. <button v-else class="control-btn stop-btn" @click="stopConversation">
  1200. <el-icon><VideoPause /></el-icon>
  1201. </button>
  1202. </div>
  1203. </div>
  1204. </div>
  1205. </div>
  1206. <!-- 收藏面板底部栏 -->
  1207. <div class="input-container bookmark-footer" v-else>
  1208. <div class="bookmark-controls">
  1209. <!-- 搜索框 -->
  1210. <div class="bookmark-search">
  1211. <el-input
  1212. v-model="bookmarkOptions.keyWord"
  1213. placeholder="搜索收藏的消息..."
  1214. :prefix-icon="Search"
  1215. clearable
  1216. @keydown.enter="handleBookmarkSearch"
  1217. @clear="handleBookmarkReset"
  1218. style="width: 300px"
  1219. />
  1220. <el-button type="primary" :icon="Search" @click="handleBookmarkSearch" :loading="loadingMessage"> 搜索 </el-button>
  1221. </div>
  1222. <!-- 分页和重置 -->
  1223. <div class="bookmark-pagination">
  1224. <el-button @click="handleBookmarkReset" :loading="loadingMessage"> 重置</el-button>
  1225. <el-pagination
  1226. v-model:current-page="bookmarkOptions.pageNum"
  1227. v-model:page-size="bookmarkOptions.pageSize"
  1228. :total="bookmarkTotal"
  1229. :page-sizes="pageSizeOptions"
  1230. :pager-count="7"
  1231. :max-page="maxPages"
  1232. layout="total, sizes, prev, pager, next, jumper"
  1233. @current-change="handleBookmarkPageChange"
  1234. @size-change="handleBookmarkPageSizeChange"
  1235. :disabled="loadingMessage"
  1236. small
  1237. />
  1238. </div>
  1239. </div>
  1240. </div>
  1241. </el-main>
  1242. <!-- 提示词管理对话框 -->
  1243. <el-dialog v-model="promptDialogVisible" title="提示词管理" width="60%" append-to-body>
  1244. <div class="prompt-dialog-content">
  1245. <div class="prompt-input-section">
  1246. <h4>自定义提示词</h4>
  1247. <el-input
  1248. v-model="customPrompt"
  1249. type="textarea"
  1250. :autosize="{ minRows: 12, maxRows: 24 }"
  1251. placeholder="在此编写你的提示词...(将用于本次会话的系统提示)"
  1252. />
  1253. </div>
  1254. </div>
  1255. <template #footer>
  1256. <div class="dialog-footer">
  1257. <el-button @click="promptDialogVisible = false">取 消</el-button>
  1258. <el-button type="primary" @click="promptDialogVisible = false">确 认</el-button>
  1259. </div>
  1260. </template>
  1261. </el-dialog>
  1262. </el-container>
  1263. </template>
  1264. <style scoped lang="scss">
  1265. :deep(.el-icon) {
  1266. margin-right: 0 !important;
  1267. }
  1268. .chat-container {
  1269. height: 100%;
  1270. background: var(--el-bg-color-page);
  1271. }
  1272. .create-conversation-btn {
  1273. margin: 16px;
  1274. }
  1275. /* 左侧边栏样式 */
  1276. .chat-sidebar {
  1277. background: var(--el-bg-color);
  1278. border-right: 1px solid var(--el-border-color-light);
  1279. display: flex;
  1280. flex-direction: column;
  1281. }
  1282. .sidebar-header {
  1283. padding: 20px;
  1284. border-bottom: 1px solid var(--el-border-color-light);
  1285. display: flex;
  1286. justify-content: space-between;
  1287. align-items: center;
  1288. h3 {
  1289. margin: 0;
  1290. color: var(--el-text-color-primary);
  1291. font-size: 16px;
  1292. font-weight: 600;
  1293. }
  1294. }
  1295. /* 设置面板样式 */
  1296. :deep(.el-dropdown-menu) {
  1297. .settings-item {
  1298. padding: 0;
  1299. &:hover {
  1300. background: none;
  1301. }
  1302. }
  1303. .settings-row {
  1304. display: flex;
  1305. align-items: center;
  1306. justify-content: space-between;
  1307. padding: 8px 16px;
  1308. min-width: 160px;
  1309. &:hover {
  1310. background: var(--el-fill-color-light);
  1311. }
  1312. }
  1313. .settings-label {
  1314. font-size: 14px;
  1315. color: var(--el-text-color-primary);
  1316. flex: 1;
  1317. }
  1318. }
  1319. .conversation-list {
  1320. flex: 1;
  1321. padding: 10px;
  1322. }
  1323. .conversation-item {
  1324. display: flex;
  1325. align-items: center;
  1326. justify-content: space-between;
  1327. padding: 12px 16px;
  1328. margin-bottom: 8px;
  1329. border-radius: 8px;
  1330. transition: all 0.2s;
  1331. color: var(--el-text-color-regular);
  1332. border: 1px solid transparent;
  1333. position: relative;
  1334. cursor: pointer;
  1335. &:hover {
  1336. background: var(--el-fill-color-light);
  1337. color: var(--el-text-color-primary);
  1338. .conversation-actions {
  1339. opacity: 1;
  1340. }
  1341. }
  1342. &.active {
  1343. background: var(--el-color-primary-light-9);
  1344. color: var(--el-color-primary);
  1345. border-color: var(--el-color-primary-light-7);
  1346. .conversation-actions {
  1347. opacity: 1;
  1348. }
  1349. }
  1350. &.editing {
  1351. background: var(--el-color-warning-light-9);
  1352. border-color: var(--el-color-warning-light-7);
  1353. .conversation-actions {
  1354. opacity: 1;
  1355. }
  1356. }
  1357. }
  1358. .conversation-content {
  1359. flex: 1;
  1360. min-width: 0;
  1361. cursor: pointer;
  1362. display: flex;
  1363. align-items: center;
  1364. .el-checkbox {
  1365. margin-right: 8px;
  1366. }
  1367. }
  1368. .conversation-edit-content {
  1369. flex: 1;
  1370. min-width: 0;
  1371. }
  1372. .edit-input {
  1373. width: 100%;
  1374. :deep(.el-input__inner) {
  1375. font-size: 14px;
  1376. padding: 4px 8px;
  1377. height: 28px;
  1378. line-height: 20px;
  1379. }
  1380. }
  1381. .conversation-title {
  1382. display: block;
  1383. overflow: hidden;
  1384. text-overflow: ellipsis;
  1385. white-space: nowrap;
  1386. }
  1387. .conversation-actions {
  1388. display: flex;
  1389. align-items: center;
  1390. gap: 4px;
  1391. opacity: 0;
  1392. transition: opacity 0.2s;
  1393. flex-shrink: 0;
  1394. }
  1395. .action-btn {
  1396. width: 28px !important;
  1397. height: 28px !important;
  1398. padding: 0 !important;
  1399. margin: 0 2px;
  1400. }
  1401. .more-btn {
  1402. &:hover {
  1403. background: var(--el-color-primary-light-9) !important;
  1404. border-color: var(--el-color-primary-light-7) !important;
  1405. }
  1406. }
  1407. /* 对话历史三点菜单样式 */
  1408. .conversation-actions {
  1409. :deep(.el-dropdown-menu) {
  1410. .el-dropdown-menu__item {
  1411. display: flex;
  1412. align-items: center;
  1413. gap: 8px;
  1414. padding: 8px 16px;
  1415. .el-icon {
  1416. font-size: 14px;
  1417. color: var(--el-text-color-regular);
  1418. }
  1419. span {
  1420. font-size: 14px;
  1421. color: var(--el-text-color-primary);
  1422. }
  1423. &:hover {
  1424. background: var(--el-fill-color-light);
  1425. .el-icon {
  1426. color: var(--el-color-primary);
  1427. }
  1428. }
  1429. &.is-disabled {
  1430. .el-icon,
  1431. span {
  1432. color: var(--el-text-color-disabled);
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. /* 右侧聊天区域样式 */
  1439. .chat-main {
  1440. display: flex;
  1441. flex-direction: column;
  1442. padding: 0;
  1443. background: var(--el-bg-color-page);
  1444. position: relative;
  1445. }
  1446. .messages-container {
  1447. flex: 1;
  1448. padding: 20px;
  1449. overflow-y: auto;
  1450. }
  1451. .messages-spacer {
  1452. height: 203px;
  1453. }
  1454. .message-wrapper {
  1455. margin-bottom: 20px;
  1456. &:last-child {
  1457. margin-bottom: 0;
  1458. }
  1459. }
  1460. /* AI消息样式 */
  1461. .ai-message-container {
  1462. display: flex;
  1463. align-items: flex-start;
  1464. gap: 12px;
  1465. }
  1466. .ai-message-content {
  1467. display: flex;
  1468. flex-direction: column;
  1469. align-items: flex-start;
  1470. gap: 8px;
  1471. width: 70%;
  1472. }
  1473. .ai-message-actions {
  1474. display: flex;
  1475. justify-content: flex-start;
  1476. transition: opacity 0.2s ease;
  1477. }
  1478. .favorite-btn {
  1479. width: 16px !important;
  1480. height: 16px !important;
  1481. padding: 0 !important;
  1482. border: none !important;
  1483. background: transparent !important;
  1484. color: var(--el-text-color-regular);
  1485. transition: all 0.2s ease;
  1486. &:hover {
  1487. background: var(--el-fill-color-light) !important;
  1488. }
  1489. &.favorited {
  1490. color: #ff4757;
  1491. }
  1492. .el-icon {
  1493. font-size: 16px;
  1494. }
  1495. }
  1496. .ai-bubble {
  1497. background: var(--el-fill-color-light);
  1498. color: var(--el-text-color-primary);
  1499. position: relative;
  1500. max-width: 100%;
  1501. border: 1px solid var(--el-border-color-lighter);
  1502. &::before {
  1503. content: '';
  1504. position: absolute;
  1505. left: -8px;
  1506. top: 12px;
  1507. width: 0;
  1508. height: 0;
  1509. border-right: 8px solid var(--el-fill-color-light);
  1510. border-top: 8px solid transparent;
  1511. border-bottom: 8px solid transparent;
  1512. }
  1513. }
  1514. /* 用户消息样式 */
  1515. .user-message-container {
  1516. display: flex;
  1517. align-items: flex-start;
  1518. gap: 12px;
  1519. justify-content: flex-end;
  1520. }
  1521. .user-message-content {
  1522. display: flex;
  1523. flex-direction: column;
  1524. align-items: flex-end;
  1525. gap: 8px;
  1526. width: 70%;
  1527. }
  1528. .user-message-actions {
  1529. display: flex;
  1530. justify-content: flex-end;
  1531. opacity: 0;
  1532. transition: opacity 0.2s ease;
  1533. }
  1534. .user-message-container:hover .user-message-actions {
  1535. opacity: 1;
  1536. }
  1537. .retry-btn {
  1538. font-size: 12px;
  1539. padding: 4px 12px;
  1540. height: 24px;
  1541. border-radius: 12px;
  1542. }
  1543. .user-bubble {
  1544. background: var(--el-color-primary);
  1545. color: white;
  1546. position: relative;
  1547. max-width: 100%;
  1548. &::after {
  1549. content: '';
  1550. position: absolute;
  1551. right: -8px;
  1552. top: 12px;
  1553. width: 0;
  1554. height: 0;
  1555. border-left: 8px solid var(--el-color-primary);
  1556. border-top: 8px solid transparent;
  1557. border-bottom: 8px solid transparent;
  1558. }
  1559. }
  1560. /* 消息气泡通用样式 */
  1561. .message-bubble {
  1562. padding: 12px 16px;
  1563. border-radius: 12px;
  1564. line-height: 1.5;
  1565. word-wrap: break-word;
  1566. box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  1567. }
  1568. /* 消息文件样式 */
  1569. .message-files {
  1570. margin-top: 8px;
  1571. display: flex;
  1572. flex-direction: row;
  1573. gap: 6px;
  1574. flex-wrap: wrap;
  1575. overflow: visible;
  1576. }
  1577. .file-item {
  1578. display: flex;
  1579. align-items: center;
  1580. gap: 4px;
  1581. padding: 4px 6px;
  1582. background: rgba(255, 255, 255, 0.1);
  1583. border-radius: 4px;
  1584. cursor: pointer;
  1585. transition: all 0.2s ease;
  1586. font-size: 11px;
  1587. flex-shrink: 0;
  1588. min-width: 0;
  1589. &:hover {
  1590. background: rgba(255, 255, 255, 0.2);
  1591. }
  1592. .file-icon {
  1593. flex-shrink: 0;
  1594. font-size: 12px;
  1595. color: rgba(255, 255, 255, 0.8);
  1596. }
  1597. .file-name {
  1598. max-width: 80px;
  1599. overflow: hidden;
  1600. text-overflow: ellipsis;
  1601. white-space: nowrap;
  1602. color: rgba(255, 255, 255, 0.9);
  1603. }
  1604. .file-size {
  1605. flex-shrink: 0;
  1606. color: rgba(255, 255, 255, 0.6);
  1607. font-size: 10px;
  1608. }
  1609. }
  1610. .message-avatar {
  1611. flex-shrink: 0;
  1612. margin-top: 2px;
  1613. }
  1614. /* 加载动画样式 */
  1615. .loading-container {
  1616. display: flex;
  1617. align-items: center;
  1618. gap: 12px;
  1619. padding: 8px 0;
  1620. color: var(--el-text-color-secondary);
  1621. }
  1622. .loading-dots {
  1623. display: flex;
  1624. gap: 4px;
  1625. }
  1626. .dot {
  1627. width: 6px;
  1628. height: 6px;
  1629. border-radius: 50%;
  1630. background-color: var(--el-color-primary);
  1631. animation: loading-bounce 1.4s ease-in-out infinite both;
  1632. }
  1633. .dot:nth-child(1) {
  1634. animation-delay: -0.32s;
  1635. }
  1636. .dot:nth-child(2) {
  1637. animation-delay: -0.16s;
  1638. }
  1639. .dot:nth-child(3) {
  1640. animation-delay: 0s;
  1641. }
  1642. @keyframes loading-bounce {
  1643. 0%,
  1644. 80%,
  1645. 100% {
  1646. transform: scale(0.8);
  1647. opacity: 0.5;
  1648. }
  1649. 40% {
  1650. transform: scale(1);
  1651. opacity: 1;
  1652. }
  1653. }
  1654. .loading-text {
  1655. font-size: 14px;
  1656. font-weight: 500;
  1657. }
  1658. .tools-button {
  1659. margin-bottom: 10px;
  1660. color: var(--el-text-color-regular);
  1661. }
  1662. .message-input {
  1663. margin-bottom: 12px;
  1664. :deep(.el-textarea__inner) {
  1665. border-radius: 8px;
  1666. resize: none;
  1667. }
  1668. }
  1669. .input-actions {
  1670. display: flex;
  1671. justify-content: flex-end;
  1672. gap: 12px;
  1673. }
  1674. /* Markdown 内容样式优化 - 接入Element Plus颜色系统 */
  1675. :deep(.markdown-content) {
  1676. /* 标题样式 */
  1677. h1,
  1678. h2,
  1679. h3,
  1680. h4,
  1681. h5,
  1682. h6 {
  1683. margin-top: 24px;
  1684. margin-bottom: 16px;
  1685. font-weight: 600;
  1686. line-height: 1.25;
  1687. color: var(--el-text-color-primary);
  1688. }
  1689. h1 {
  1690. font-size: 2em;
  1691. border-bottom: 1px solid var(--el-border-color-light);
  1692. padding-bottom: 8px;
  1693. }
  1694. h2 {
  1695. font-size: 1.5em;
  1696. border-bottom: 1px solid var(--el-border-color-lighter);
  1697. padding-bottom: 6px;
  1698. }
  1699. h3 {
  1700. font-size: 1.25em;
  1701. }
  1702. /* 段落样式 */
  1703. p {
  1704. margin-bottom: 16px;
  1705. line-height: 1.6;
  1706. color: var(--el-text-color-regular);
  1707. }
  1708. /* 代码块样式 */
  1709. pre {
  1710. background-color: var(--el-fill-color-light);
  1711. border: 1px solid var(--el-border-color-light);
  1712. border-radius: 6px;
  1713. padding: 16px;
  1714. overflow: auto;
  1715. margin: 16px 0;
  1716. color: var(--el-text-color-primary);
  1717. }
  1718. /* 行内代码样式 */
  1719. code {
  1720. background-color: var(--el-fill-color-light);
  1721. color: var(--el-color-danger);
  1722. padding: 2px 4px;
  1723. border-radius: 3px;
  1724. font-size: 85%;
  1725. border: 1px solid var(--el-border-color-lighter);
  1726. }
  1727. /* 引用块样式 */
  1728. blockquote {
  1729. border-left: 4px solid var(--el-color-primary);
  1730. padding-left: 16px;
  1731. margin: 16px 0;
  1732. color: var(--el-text-color-secondary);
  1733. background-color: var(--el-fill-color-extra-light);
  1734. padding: 12px 16px;
  1735. border-radius: 4px;
  1736. }
  1737. /* 列表样式 */
  1738. ul,
  1739. ol {
  1740. margin: 16px 0;
  1741. padding-left: 32px;
  1742. color: var(--el-text-color-regular);
  1743. }
  1744. li {
  1745. margin: 4px 0;
  1746. line-height: 1.6;
  1747. }
  1748. /* 表格样式 */
  1749. table {
  1750. border-collapse: collapse;
  1751. margin: 16px 0;
  1752. width: 100%;
  1753. border: 1px solid var(--el-border-color-light);
  1754. }
  1755. th,
  1756. td {
  1757. border: 1px solid var(--el-border-color-light);
  1758. padding: 8px 12px;
  1759. text-align: left;
  1760. }
  1761. th {
  1762. background-color: var(--el-fill-color-light);
  1763. font-weight: 600;
  1764. color: var(--el-text-color-primary);
  1765. }
  1766. td {
  1767. color: var(--el-text-color-regular);
  1768. }
  1769. /* 分割线样式 */
  1770. hr {
  1771. border: none;
  1772. border-top: 1px solid var(--el-border-color-light);
  1773. margin: 24px 0;
  1774. }
  1775. /* 链接样式 */
  1776. a {
  1777. color: var(--el-color-primary);
  1778. text-decoration: none;
  1779. &:hover {
  1780. color: var(--el-color-primary-light-3);
  1781. text-decoration: underline;
  1782. }
  1783. }
  1784. /* 强调文本样式 */
  1785. strong {
  1786. font-weight: 600;
  1787. color: var(--el-text-color-primary);
  1788. }
  1789. em {
  1790. font-style: italic;
  1791. color: var(--el-text-color-regular);
  1792. }
  1793. }
  1794. /* 新的输入容器样式 */
  1795. .input-container {
  1796. position: absolute;
  1797. width: 90%;
  1798. left: 50%;
  1799. bottom: 25px;
  1800. transform: translate(-50%, 0);
  1801. background: var(--el-bg-color);
  1802. border: 1px solid var(--el-border-color-light);
  1803. border-radius: 8px;
  1804. padding: 0;
  1805. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  1806. }
  1807. /* 附件栏(内嵌)样式 */
  1808. .attachments-inline {
  1809. width: 100%;
  1810. padding: 4px;
  1811. display: flex;
  1812. align-items: center;
  1813. gap: 8px;
  1814. background: var(--el-fill-color-extra-light);
  1815. border-radius: 8px 8px 0 0;
  1816. border-bottom: 1px solid var(--el-border-color-lighter);
  1817. }
  1818. .attachments-inline-scroll {
  1819. flex: 1;
  1820. //overflow-x: auto;
  1821. display: flex;
  1822. align-items: center;
  1823. gap: 8px;
  1824. background: var(--el-fill-color-extra-light);
  1825. padding: 6px;
  1826. }
  1827. .attachment-card {
  1828. position: relative;
  1829. display: inline-flex;
  1830. align-items: center;
  1831. gap: 0;
  1832. }
  1833. .attachment-item {
  1834. /* 对齐下方控制按钮的尺寸与风格 */
  1835. max-width: 260px;
  1836. white-space: nowrap;
  1837. overflow: hidden;
  1838. text-overflow: ellipsis;
  1839. font-size: 10px !important;
  1840. padding: 4px 8px!important;
  1841. }
  1842. .attachment-name {
  1843. max-width: 200px;
  1844. white-space: nowrap;
  1845. overflow: hidden;
  1846. text-overflow: ellipsis;
  1847. }
  1848. .add-attachment-btn {
  1849. flex-shrink: 0;
  1850. font-size: 10px !important;
  1851. margin: 5px;
  1852. }
  1853. .attachment-hint {
  1854. display: flex;
  1855. align-items: center;
  1856. justify-content: center;
  1857. padding: 4px;
  1858. color: var(--el-text-color-placeholder);
  1859. font-size: 12px;
  1860. opacity: 0.8;
  1861. height: 21.5px;
  1862. line-height: 1;
  1863. }
  1864. .remove-attachment-icon {
  1865. position: absolute;
  1866. top: -5px;
  1867. right: -5px;
  1868. width: 15px;
  1869. height: 15px;
  1870. border-radius: 50%;
  1871. border: 1px solid var(--el-border-color-light);
  1872. background: var(--el-bg-color);
  1873. display: flex;
  1874. align-items: center;
  1875. justify-content: center;
  1876. cursor: pointer;
  1877. color: var(--el-text-color-regular);
  1878. padding: 0;
  1879. }
  1880. .large-input-container {
  1881. position: relative;
  1882. width: 100%;
  1883. }
  1884. .large-textarea {
  1885. width: 100%;
  1886. min-height: 120px;
  1887. padding: 16px 16px 60px 16px;
  1888. border: none;
  1889. outline: none;
  1890. resize: none;
  1891. font-size: 14px;
  1892. line-height: 1.5;
  1893. background: transparent;
  1894. color: var(--el-text-color-primary);
  1895. border-radius: 8px;
  1896. font-family: inherit;
  1897. }
  1898. .large-textarea::placeholder {
  1899. color: var(--el-text-color-placeholder);
  1900. }
  1901. .large-textarea:disabled {
  1902. color: var(--el-text-color-disabled);
  1903. cursor: not-allowed;
  1904. }
  1905. .embedded-controls {
  1906. position: absolute;
  1907. bottom: 0;
  1908. left: 0;
  1909. right: 0;
  1910. display: flex;
  1911. justify-content: space-between;
  1912. align-items: center;
  1913. padding: 12px 16px;
  1914. border-top: 1px solid var(--el-border-color-lighter);
  1915. background: var(--el-fill-color-extra-light);
  1916. border-radius: 0 0 8px 8px;
  1917. }
  1918. .left-controls,
  1919. .right-controls {
  1920. display: flex;
  1921. align-items: center;
  1922. gap: 8px;
  1923. }
  1924. .control-btn {
  1925. display: flex;
  1926. align-items: center;
  1927. gap: 6px;
  1928. padding: 6px 12px;
  1929. border: 1px solid var(--el-border-color-light);
  1930. border-radius: 6px;
  1931. background: var(--el-bg-color);
  1932. color: var(--el-text-color-regular);
  1933. font-size: 12px;
  1934. cursor: pointer;
  1935. transition: all 0.2s ease;
  1936. white-space: nowrap;
  1937. }
  1938. .control-btn:hover:not(:disabled) {
  1939. background: var(--el-fill-color-light);
  1940. border-color: var(--el-color-primary-light-7);
  1941. color: var(--el-color-primary);
  1942. }
  1943. .control-btn:disabled {
  1944. opacity: 0.5;
  1945. cursor: not-allowed;
  1946. }
  1947. .control-btn .el-icon {
  1948. font-size: 14px;
  1949. }
  1950. /* 特定按钮样式 */
  1951. .send-btn {
  1952. background: var(--el-color-primary);
  1953. color: white;
  1954. border-color: var(--el-color-primary);
  1955. }
  1956. .send-btn:hover:not(:disabled) {
  1957. background: var(--el-color-primary-light-3);
  1958. border-color: var(--el-color-primary-light-3);
  1959. }
  1960. .stop-btn {
  1961. background: var(--el-color-danger);
  1962. color: white;
  1963. border-color: var(--el-color-danger);
  1964. }
  1965. .stop-btn:hover:not(:disabled) {
  1966. background: var(--el-color-danger-light-3);
  1967. border-color: var(--el-color-danger-light-3);
  1968. }
  1969. .clear-btn:hover:not(:disabled) {
  1970. background: var(--el-color-warning-light-9);
  1971. border-color: var(--el-color-warning-light-7);
  1972. color: var(--el-color-warning);
  1973. }
  1974. /* 下拉菜单样式 */
  1975. :deep(.el-dropdown-menu) {
  1976. .el-dropdown-menu__item.is-selected {
  1977. background: var(--el-color-primary-light-9);
  1978. color: var(--el-color-primary);
  1979. }
  1980. }
  1981. /* 对话框样式 */
  1982. .dialog-footer {
  1983. text-align: right;
  1984. }
  1985. /* 提示词对话框样式 */
  1986. .prompt-dialog-content {
  1987. display: flex;
  1988. flex-direction: column;
  1989. gap: 24px;
  1990. max-height: 600px;
  1991. }
  1992. .prompt-input-section {
  1993. h4 {
  1994. margin: 0 0 12px 0;
  1995. color: var(--el-text-color-primary);
  1996. font-size: 14px;
  1997. font-weight: 600;
  1998. }
  1999. }
  2000. .prompt-list-section {
  2001. border-top: 1px solid var(--el-border-color-lighter);
  2002. padding-top: 20px;
  2003. h4 {
  2004. margin: 0 0 16px 0;
  2005. color: var(--el-text-color-primary);
  2006. font-size: 14px;
  2007. font-weight: 600;
  2008. }
  2009. }
  2010. .prompt-list-header {
  2011. display: flex;
  2012. justify-content: space-between;
  2013. align-items: center;
  2014. margin-bottom: 16px;
  2015. .prompt-search {
  2016. display: flex;
  2017. align-items: center;
  2018. gap: 8px;
  2019. }
  2020. }
  2021. .prompt-list-container {
  2022. min-height: 200px;
  2023. max-height: 300px;
  2024. overflow-y: auto;
  2025. border: 1px solid var(--el-border-color-light);
  2026. border-radius: 6px;
  2027. background: var(--el-fill-color-extra-light);
  2028. }
  2029. .prompt-list-empty {
  2030. display: flex;
  2031. align-items: center;
  2032. justify-content: center;
  2033. height: 200px;
  2034. }
  2035. .prompt-list {
  2036. padding: 8px;
  2037. }
  2038. .prompt-item {
  2039. padding: 12px;
  2040. margin-bottom: 8px;
  2041. border: 1px solid var(--el-border-color-lighter);
  2042. border-radius: 6px;
  2043. background: var(--el-bg-color);
  2044. cursor: pointer;
  2045. transition: all 0.2s ease;
  2046. &:hover {
  2047. border-color: var(--el-color-primary-light-7);
  2048. background: var(--el-color-primary-light-9);
  2049. transform: translateY(-1px);
  2050. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  2051. }
  2052. &:last-child {
  2053. margin-bottom: 0;
  2054. }
  2055. }
  2056. .prompt-item-header {
  2057. display: flex;
  2058. justify-content: space-between;
  2059. align-items: center;
  2060. margin-bottom: 8px;
  2061. }
  2062. .prompt-title {
  2063. font-weight: 600;
  2064. color: var(--el-text-color-primary);
  2065. font-size: 14px;
  2066. }
  2067. .prompt-preview {
  2068. color: var(--el-text-color-regular);
  2069. font-size: 12px;
  2070. line-height: 1.4;
  2071. word-break: break-all;
  2072. }
  2073. .prompt-pagination {
  2074. margin-top: 16px;
  2075. display: flex;
  2076. justify-content: center;
  2077. }
  2078. /* 响应式调整 */
  2079. /* 空状态页面样式 */
  2080. .empty-content {
  2081. text-align: center;
  2082. max-width: 600px;
  2083. width: 100%;
  2084. position: absolute;
  2085. left: 50%;
  2086. top: 50%;
  2087. transform: translate(-50%, -50%);
  2088. }
  2089. .empty-icon {
  2090. margin-bottom: 24px;
  2091. opacity: 0.6;
  2092. }
  2093. .empty-text {
  2094. margin-bottom: 40px;
  2095. }
  2096. .empty-title {
  2097. font-size: 28px;
  2098. font-weight: 600;
  2099. color: var(--el-text-color-primary);
  2100. margin: 0 0 12px 0;
  2101. }
  2102. .empty-description {
  2103. font-size: 16px;
  2104. color: var(--el-text-color-regular);
  2105. margin: 0;
  2106. line-height: 1.5;
  2107. }
  2108. .quick-start {
  2109. display: flex;
  2110. justify-content: center;
  2111. gap: 40px;
  2112. margin-bottom: 40px;
  2113. flex-wrap: wrap;
  2114. }
  2115. .quick-start-item {
  2116. display: flex;
  2117. align-items: center;
  2118. gap: 12px;
  2119. color: var(--el-text-color-regular);
  2120. }
  2121. .step-number {
  2122. display: flex;
  2123. align-items: center;
  2124. justify-content: center;
  2125. width: 24px;
  2126. height: 24px;
  2127. background: var(--el-color-primary);
  2128. color: white;
  2129. border-radius: 50%;
  2130. font-size: 12px;
  2131. font-weight: 600;
  2132. flex-shrink: 0;
  2133. }
  2134. .step-text {
  2135. font-size: 14px;
  2136. font-weight: 500;
  2137. }
  2138. .example-questions {
  2139. h4 {
  2140. font-size: 16px;
  2141. font-weight: 600;
  2142. color: var(--el-text-color-primary);
  2143. margin: 0 0 16px 0;
  2144. }
  2145. }
  2146. .question-tags {
  2147. display: flex;
  2148. flex-wrap: wrap;
  2149. gap: 12px;
  2150. justify-content: center;
  2151. }
  2152. .question-tag {
  2153. cursor: pointer;
  2154. transition: all 0.2s ease;
  2155. font-size: 13px;
  2156. padding: 8px 16px;
  2157. border-radius: 20px;
  2158. &:hover {
  2159. transform: translateY(-1px);
  2160. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  2161. }
  2162. }
  2163. /* 收藏面板底部栏样式 */
  2164. .bookmark-footer {
  2165. border-radius: 8px;
  2166. padding: 16px;
  2167. .bookmark-controls {
  2168. display: flex;
  2169. justify-content: space-between;
  2170. align-items: center;
  2171. gap: 16px;
  2172. width: 100%;
  2173. }
  2174. .bookmark-search {
  2175. display: flex;
  2176. align-items: center;
  2177. gap: 12px;
  2178. }
  2179. .bookmark-pagination {
  2180. display: flex;
  2181. align-items: center;
  2182. gap: 16px;
  2183. flex-wrap: wrap;
  2184. }
  2185. }
  2186. /* 响应式调整 */
  2187. @media (max-width: 768px) {
  2188. .bookmark-footer {
  2189. .bookmark-controls {
  2190. flex-direction: column;
  2191. gap: 12px;
  2192. }
  2193. .bookmark-search {
  2194. width: 100%;
  2195. justify-content: center;
  2196. .el-input {
  2197. width: 100% !important;
  2198. max-width: 300px;
  2199. }
  2200. }
  2201. .bookmark-pagination {
  2202. width: 100%;
  2203. justify-content: center;
  2204. flex-direction: column;
  2205. gap: 8px;
  2206. .el-pagination {
  2207. justify-content: center;
  2208. }
  2209. }
  2210. }
  2211. }
  2212. // 无限旋转动画
  2213. @keyframes spin {
  2214. to {
  2215. transform: rotate(360deg);
  2216. }
  2217. }
  2218. // 基础旋转类
  2219. .spin {
  2220. display: inline-block;
  2221. animation: spin 1s linear infinite;
  2222. transform-origin: center center;
  2223. // 变体:慢速
  2224. &-slow {
  2225. animation-duration: 3s;
  2226. }
  2227. // 变体:快速
  2228. &-fast {
  2229. animation-duration: 0.6s;
  2230. }
  2231. // 变体:反向
  2232. &-rev {
  2233. animation-direction: reverse;
  2234. }
  2235. // 变体:悬停暂停
  2236. &-pause:hover {
  2237. animation-play-state: paused;
  2238. }
  2239. }
  2240. </style>