index.vue 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. <template>
  2. <el-container class="ai-layout">
  3. <!-- 左侧:会话列表 -->
  4. <el-aside width="260px" class="conversation-container">
  5. <div>
  6. <!-- 左顶部:新建对话 -->
  7. <el-button class="w-1/1 btn-new-conversation" type="primary" @click="createConversation">
  8. <Icon icon="ep:plus" class="mr-5px" />
  9. 新建对话
  10. </el-button>
  11. <!-- 左顶部:搜索对话 -->
  12. <el-input
  13. v-model="searchName"
  14. size="large"
  15. class="mt-10px search-input"
  16. placeholder="搜索历史记录"
  17. @keyup="searchConversation"
  18. >
  19. <template #prefix>
  20. <Icon icon="ep:search" />
  21. </template>
  22. </el-input>
  23. <!-- 左中间:对话列表 -->
  24. <div class="conversation-list">
  25. <!-- TODO @芋艿,置顶、聊天记录、一星期钱、30天前,前端对数据重新做一下分组,或者后端接口改一下 -->
  26. <div>
  27. <el-text class="mx-1" size="small" tag="b">置顶</el-text>
  28. </div>
  29. <el-row v-for="conversation in conversationList" :key="conversation.id">
  30. <div
  31. :class="conversation.id === conversationId ? 'conversation active' : 'conversation'"
  32. @click="changeConversation(conversation.id)"
  33. >
  34. <div class="title-wrapper">
  35. <img class="avatar" :src="conversation.roleAvatar" />
  36. <span class="title">{{ conversation.title }}</span>
  37. </div>
  38. <div class="button-wrapper">
  39. <el-icon title="编辑" @click="updateConversationTitle(conversation)">
  40. <Icon icon="ep:edit" />
  41. </el-icon>
  42. <el-icon title="删除会话" @click="deleteConversationTitle(conversation)">
  43. <Icon icon="ep:delete" />
  44. </el-icon>
  45. </div>
  46. </div>
  47. </el-row>
  48. </div>
  49. </div>
  50. <!-- 左底部:工具栏 -->
  51. <div class="tool-box">
  52. <div>
  53. <Icon icon="ep:user" />
  54. <el-text size="small">角色仓库</el-text>
  55. </div>
  56. <div>
  57. <Icon icon="ep:delete" />
  58. <el-text size="small">清空未置顶对话</el-text>
  59. </div>
  60. </div>
  61. </el-aside>
  62. <!-- 右侧:会话详情 -->
  63. <el-container class="detail-container">
  64. <!-- 右顶部 TODO 芋艿:右对齐 -->
  65. <el-header class="header">
  66. <div class="title">
  67. {{ useConversation?.title }}
  68. </div>
  69. <div>
  70. <!-- TODO @fan:样式改下;这里我已经改成点击后,弹出了 -->
  71. <el-dropdown style="margin-right: 12px" @command="openChatConversationUpdateForm">
  72. <el-button type="primary">
  73. <span v-html="useModal?.name"></span>
  74. <Icon icon="ep:setting" style="margin-left: 10px" />
  75. </el-button>
  76. <template #dropdown>
  77. <el-dropdown-menu v-for="(item, index) in modalList" :key="index">
  78. <el-dropdown-item :command="item">{{ item.name }}</el-dropdown-item>
  79. </el-dropdown-menu>
  80. </template>
  81. </el-dropdown>
  82. <el-button>
  83. <Icon icon="ep:user" />
  84. </el-button>
  85. <el-button>
  86. <Icon icon="ep:download" />
  87. </el-button>
  88. <el-button>
  89. <Icon icon="ep:arrow-up" />
  90. </el-button>
  91. </div>
  92. </el-header>
  93. <!-- main -->
  94. <el-main class="main-container">
  95. <div class="message-container" ref="messageContainer">
  96. <div class="chat-list" v-for="(item, index) in list" :key="index">
  97. <!-- 靠左 message -->
  98. <div class="left-message message-item" v-if="item.type === 'system'">
  99. <div class="avatar">
  100. <el-avatar
  101. src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
  102. />
  103. </div>
  104. <div class="message">
  105. <div>
  106. <el-text class="time">{{ formatDate(item.createTime) }}</el-text>
  107. </div>
  108. <div class="left-text-container" ref="markdownViewRef">
  109. <div class="left-text markdown-view" v-html="item.content"></div>
  110. <!-- <mdPreview :content="item.content" :delay="false" />-->
  111. </div>
  112. <div class="left-btns">
  113. <div class="btn-cus" @click="noCopy(item.content)">
  114. <img class="btn-image" src="../../../assets/ai/copy.svg" />
  115. <el-text class="btn-cus-text">复制</el-text>
  116. </div>
  117. <div class="btn-cus" style="margin-left: 20px" @click="onDelete(item.id)">
  118. <img class="btn-image" src="@/assets/ai/delete.svg" style="height: 17px" />
  119. <el-text class="btn-cus-text">删除</el-text>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. <!-- 靠右 message -->
  125. <div class="right-message message-item" v-if="item.type === 'user'">
  126. <div class="avatar">
  127. <el-avatar
  128. src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
  129. />
  130. </div>
  131. <div class="message">
  132. <div>
  133. <el-text class="time">{{ formatDate(item.createTime) }}</el-text>
  134. </div>
  135. <div class="right-text-container">
  136. <div class="right-text">{{ item.content }}</div>
  137. </div>
  138. <div class="right-btns">
  139. <div class="btn-cus" @click="noCopy(item.content)">
  140. <img class="btn-image" src="@/assets/ai/copy.svg" />
  141. <el-text class="btn-cus-text">复制</el-text>
  142. </div>
  143. <div class="btn-cus" style="margin-left: 20px" @click="onDelete(item.id)">
  144. <img class="btn-image" src="@/assets/ai/delete.svg" style="height: 17px" />
  145. <el-text class="btn-cus-text">删除</el-text>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. </div>
  152. </el-main>
  153. <el-footer class="footer-container">
  154. <form @submit.prevent="onSend" class="prompt-from">
  155. <textarea
  156. class="prompt-input"
  157. v-model="prompt"
  158. @keyup.enter="onSend"
  159. @input="onPromptInput"
  160. @compositionstart="onCompositionstart"
  161. @compositionend="onCompositionend"
  162. placeholder="问我任何问题...(Shift+Enter 换行,按下 Enter 发送)"
  163. ></textarea>
  164. <div class="prompt-btns">
  165. <el-switch />
  166. <el-button
  167. type="primary"
  168. size="default"
  169. @click="onSend()"
  170. :loading="conversationInProgress"
  171. v-if="conversationInProgress == false"
  172. >
  173. {{ conversationInProgress ? '进行中' : '发送' }}
  174. </el-button>
  175. <el-button
  176. type="danger"
  177. size="default"
  178. @click="stopStream()"
  179. v-if="conversationInProgress == true"
  180. >
  181. 停止
  182. </el-button>
  183. </div>
  184. </form>
  185. </el-footer>
  186. </el-container>
  187. </el-container>
  188. <ChatConversationUpdateForm ref="chatConversationUpdateFormRef" />
  189. </template>
  190. <script setup lang="ts">
  191. import { ChatMessageApi, ChatMessageSendVO, ChatMessageVO } from '@/api/ai/chat/message'
  192. import {
  193. ChatConversationApi,
  194. ChatConversationUpdateVO,
  195. ChatConversationVO
  196. } from '@/api/ai/chat/conversation'
  197. import ChatConversationUpdateForm from './components/ChatConversationUpdateForm.vue'
  198. import { ChatModelApi, ChatModelVO } from '@/api/ai/model/chatModel'
  199. import { formatDate } from '@/utils/formatTime'
  200. import { useClipboard } from '@vueuse/core'
  201. // 转换 markdown
  202. import { marked } from 'marked'
  203. // 代码高亮 https://highlightjs.org/
  204. import 'highlight.js/styles/vs2015.min.css'
  205. import hljs from 'highlight.js'
  206. const { t } = useI18n() // 国际化
  207. const message = useMessage() // 消息弹窗
  208. // 自定义渲染器
  209. const renderer = {
  210. code(code, language, c) {
  211. const highlightHtml = hljs.highlight(code, { language: language, ignoreIllegals: true }).value
  212. const copyHtml = `<div id="copy" data-copy='${code}' style="position: absolute; right: 10px; top: 5px; color: #fff;cursor: pointer;">复制</div>`
  213. return `<pre>${copyHtml}<code class="hljs">${highlightHtml}</code></pre>`
  214. }
  215. }
  216. marked.use({
  217. renderer: renderer
  218. })
  219. const conversationList = ref([] as ChatConversationVO[])
  220. // 初始化 copy 到粘贴板
  221. const { copy } = useClipboard()
  222. const searchName = ref('') // 查询的内容
  223. const inputTimeout = ref<any>() // 处理输入中回车的定时器
  224. const conversationId = ref(0) // 选中的对话编号
  225. const conversationInProgress = ref<Boolean>() // 对话进行中
  226. conversationInProgress.value = false
  227. const conversationInAbortController = ref<any>() // 对话进行中 abort 控制器(控制 stream 对话)
  228. const prompt = ref<string>() // prompt
  229. // 判断 消息列表 滚动的位置(用于判断是否需要滚动到消息最下方)
  230. const messageContainer: any = ref(null)
  231. const isScrolling = ref(false) //用于判断用户是否在滚动
  232. const isComposing = ref(false) // 判断用户是否在输入
  233. /** chat message 列表 */
  234. // defineOptions({ name: 'chatMessageList' })
  235. const list = ref<ChatMessageVO[]>([]) // 列表的数据
  236. const useModal = ref<ChatModelVO>() // 使用的modal
  237. const useConversation = ref<ChatConversationVO>() // 使用的 Conversation
  238. const modalList = ref<ChatModelVO[]>([]) // 列表的数据
  239. /** 新建对话 */
  240. const createConversation = async () => {
  241. // 新建对话
  242. const conversationId = await ChatConversationApi.createChatConversationMy(
  243. {} as unknown as ChatConversationVO
  244. )
  245. changeConversation(conversationId)
  246. // 刷新对话列表
  247. await getChatConversationList()
  248. }
  249. const changeConversation = (id: number) => {
  250. conversationId.value = id
  251. // TODO 芋艿:待实现
  252. }
  253. /** 更新聊天会话的标题 */
  254. const updateConversationTitle = async (conversation: ChatConversationVO) => {
  255. // 二次确认
  256. const { value } = await ElMessageBox.prompt('修改标题', {
  257. inputPattern: /^[\s\S]*.*\S[\s\S]*$/, // 判断非空,且非空格
  258. inputErrorMessage: '标题不能为空',
  259. inputValue: conversation.title
  260. })
  261. // 发起修改
  262. await ChatConversationApi.updateChatConversationMy({
  263. id: conversation.id,
  264. title: value
  265. } as ChatConversationVO)
  266. message.success('重命名成功')
  267. // 刷新列表
  268. await getChatConversationList()
  269. }
  270. /** 删除聊天会话 */
  271. const deleteConversationTitle = async (conversation: ChatConversationVO) => {
  272. console.log(conversation)
  273. // TODO 芋艿:待实现
  274. }
  275. const searchConversation = () => {
  276. // TODO 芋艿:待实现
  277. }
  278. /** send */
  279. const onSend = async () => {
  280. // 判断用户是否在输入
  281. if (isComposing.value) {
  282. return
  283. }
  284. // 进行中不允许发送
  285. if (conversationInProgress.value) {
  286. return
  287. }
  288. const content = prompt.value?.trim()
  289. if (content?.length < 2) {
  290. ElMessage({
  291. message: '请输入内容!',
  292. type: 'error'
  293. })
  294. return
  295. }
  296. // 清空输入框
  297. prompt.value = ''
  298. const requestParams = {
  299. conversationId: conversationId.value,
  300. content: content
  301. } as unknown as ChatMessageSendVO
  302. // 添加 message
  303. const userMessage = (await ChatMessageApi.add(requestParams)) as unknown as ChatMessageVO
  304. list.value.push(userMessage)
  305. // 滚动到住下面
  306. scrollToBottom()
  307. // stream
  308. await doSendStream(userMessage)
  309. //
  310. }
  311. const doSendStream = async (userMessage: ChatMessageVO) => {
  312. // 创建AbortController实例,以便中止请求
  313. conversationInAbortController.value = new AbortController()
  314. // 标记对话进行中
  315. conversationInProgress.value = true
  316. try {
  317. // 发送 event stream
  318. let isFirstMessage = true
  319. let content = ''
  320. ChatMessageApi.sendStream(
  321. userMessage.id,
  322. conversationInAbortController.value,
  323. (message) => {
  324. console.log('message', message)
  325. const data = JSON.parse(message.data) as unknown as ChatMessageVO
  326. // 如果没有内容结束链接
  327. if (data.content === '') {
  328. // 标记对话结束
  329. conversationInProgress.value = false
  330. // 结束 stream 对话
  331. conversationInAbortController.value.abort()
  332. }
  333. // 首次返回需要添加一个 message 到页面,后面的都是更新
  334. if (isFirstMessage) {
  335. isFirstMessage = false
  336. list.value.push(data)
  337. } else {
  338. content = content + data.content
  339. const lastMessage = list.value[list.value.length - 1]
  340. lastMessage.content = marked(content) as unknown as string
  341. list.value[list.value - 1] = lastMessage
  342. }
  343. // 滚动到最下面
  344. scrollToBottom()
  345. },
  346. (error) => {
  347. console.log('error', error)
  348. // 标记对话结束
  349. conversationInProgress.value = false
  350. // 结束 stream 对话
  351. conversationInAbortController.value.abort()
  352. },
  353. () => {
  354. console.log('close')
  355. // 标记对话结束
  356. conversationInProgress.value = false
  357. // 结束 stream 对话
  358. conversationInAbortController.value.abort()
  359. }
  360. )
  361. } finally {
  362. }
  363. }
  364. /** 查询列表 */
  365. const messageList = async () => {
  366. try {
  367. // 获取列表数据
  368. const res = await ChatMessageApi.messageList(conversationId.value)
  369. // 处理 markdown
  370. // marked(this.markdownText)
  371. res.map((item) => {
  372. // item.content = marked(item.content)
  373. if (item.type !== 'user') {
  374. item.content = marked(item.content)
  375. }
  376. })
  377. list.value = res
  378. // 滚动到最下面
  379. scrollToBottom()
  380. } finally {
  381. }
  382. }
  383. function scrollToBottom() {
  384. nextTick(() => {
  385. //注意要使用nexttick以免获取不到dom
  386. console.log('isScrolling.value', isScrolling.value)
  387. if (!isScrolling.value) {
  388. messageContainer.value.scrollTop =
  389. messageContainer.value.scrollHeight - messageContainer.value.offsetHeight
  390. }
  391. })
  392. }
  393. function handleScroll() {
  394. const scrollContainer = messageContainer.value
  395. const scrollTop = scrollContainer.scrollTop
  396. const scrollHeight = scrollContainer.scrollHeight
  397. const offsetHeight = scrollContainer.offsetHeight
  398. if (scrollTop + offsetHeight < scrollHeight) {
  399. // 用户开始滚动并在最底部之上,取消保持在最底部的效果
  400. isScrolling.value = true
  401. } else {
  402. // 用户停止滚动并滚动到最底部,开启保持到最底部的效果
  403. isScrolling.value = false
  404. }
  405. }
  406. function noCopy(content) {
  407. copy(content)
  408. ElMessage({
  409. message: '复制成功!',
  410. type: 'success'
  411. })
  412. }
  413. const onDelete = async (id) => {
  414. // 删除 message
  415. await ChatMessageApi.delete(id)
  416. ElMessage({
  417. message: '删除成功!',
  418. type: 'success'
  419. })
  420. // tip:如果 stream 进行中的 message,就需要调用 controller 结束
  421. stopStream()
  422. // 重新获取 message 列表
  423. await messageList()
  424. }
  425. const stopStream = async () => {
  426. // tip:如果 stream 进行中的 message,就需要调用 controller 结束
  427. if (conversationInAbortController.value) {
  428. conversationInAbortController.value.abort()
  429. }
  430. // 设置为 false
  431. conversationInProgress.value = false
  432. }
  433. /** 修改聊天会话 */
  434. const chatConversationUpdateFormRef = ref()
  435. const openChatConversationUpdateForm = async (command) => {
  436. // const update = {
  437. // id: conversationId.value,
  438. // modelId: command.id
  439. // } as unknown as ChatConversationUpdateVO
  440. // // 切换 modal
  441. // useModal.value = command
  442. // // 更新
  443. // await ChatConversationApi.updateChatConversationMy(update)
  444. chatConversationUpdateFormRef.value.open(conversationId.value)
  445. }
  446. const getModalList = async () => {
  447. // 获取模型 as unknown as ChatModelVO
  448. modalList.value = (await ChatModelApi.getChatModelSimpleList(0)) as unknown as ChatModelVO[]
  449. }
  450. // 输入
  451. const onCompositionstart = () => {
  452. console.log('onCompositionstart。。。.')
  453. isComposing.value = true
  454. }
  455. const onCompositionend = () => {
  456. // console.log('输入结束...')
  457. setTimeout(() => {
  458. console.log('输入结束...')
  459. isComposing.value = false
  460. }, 200)
  461. }
  462. const onPromptInput = (event) => {
  463. // 非输入法 输入设置为 true
  464. if (!isComposing.value) {
  465. // 回车 event data 是 null
  466. if (event.data == null) {
  467. return
  468. }
  469. console.log('setTimeout 输入开始...')
  470. isComposing.value = true
  471. }
  472. // 清理定时器
  473. if (inputTimeout.value) {
  474. clearTimeout(inputTimeout.value)
  475. }
  476. // 重置定时器
  477. inputTimeout.value = setTimeout(() => {
  478. console.log('setTimeout 输入结束...')
  479. isComposing.value = false
  480. }, 400)
  481. }
  482. const getConversation = async (conversationId: string) => {
  483. // 获取对话信息
  484. useConversation.value = await ChatConversationApi.getChatConversationMy(conversationId)
  485. console.log('useConversation.value', useConversation.value)
  486. // 选中 modal
  487. if (useConversation.value) {
  488. modalList.value.forEach((item) => {
  489. if (useConversation.value?.modelId === item.id) {
  490. useModal.value = item
  491. }
  492. })
  493. }
  494. }
  495. /** 获得聊天会话列表 */
  496. const getChatConversationList = async () => {
  497. conversationList.value = await ChatConversationApi.getChatConversationMyList()
  498. // 默认选中第一条
  499. if (conversationList.value.length === 0) {
  500. conversationId.value = 0
  501. // TODO 芋艿:清空对话
  502. } else {
  503. if (conversationId.value === 0) {
  504. conversationId.value = conversationList.value[0].id
  505. changeConversation(conversationList.value[0].id)
  506. }
  507. }
  508. }
  509. /** 初始化 **/
  510. onMounted(async () => {
  511. // 获得聊天会话列表
  512. await getChatConversationList()
  513. // 获取模型
  514. getModalList()
  515. // 获取对话信息
  516. getConversation(conversationId.value)
  517. // 获取列表数据
  518. messageList()
  519. // scrollToBottom();
  520. // await nextTick
  521. // 监听滚动事件,判断用户滚动状态
  522. messageContainer.value.addEventListener('scroll', handleScroll)
  523. // 添加 copy 监听
  524. messageContainer.value.addEventListener('click', (e: any) => {
  525. console.log(e)
  526. if (e.target.id === 'copy') {
  527. copy(e.target?.dataset?.copy)
  528. ElMessage({
  529. message: '复制成功!',
  530. type: 'success'
  531. })
  532. }
  533. })
  534. })
  535. </script>
  536. <style lang="scss" scoped>
  537. .ai-layout {
  538. // TODO @范 这里height不能 100% 先这样临时处理
  539. position: absolute;
  540. flex: 1;
  541. top: 0;
  542. left: 0;
  543. height: 100%;
  544. width: 100%;
  545. //padding: 15px 15px;
  546. }
  547. .conversation-container {
  548. position: relative;
  549. display: flex;
  550. flex-direction: column;
  551. justify-content: space-between;
  552. padding: 0 10px;
  553. padding-top: 10px;
  554. .btn-new-conversation {
  555. padding: 18px 0;
  556. }
  557. .search-input {
  558. margin-top: 20px;
  559. }
  560. .conversation-list {
  561. margin-top: 20px;
  562. .conversation {
  563. display: flex;
  564. flex-direction: row;
  565. justify-content: space-between;
  566. flex: 1;
  567. padding: 0 5px;
  568. margin-top: 10px;
  569. cursor: pointer;
  570. border-radius: 5px;
  571. align-items: center;
  572. line-height: 30px;
  573. &.active {
  574. background-color: #e6e6e6;
  575. .button {
  576. display: inline-block;
  577. }
  578. }
  579. .title-wrapper {
  580. display: flex;
  581. flex-direction: row;
  582. align-items: center;
  583. }
  584. .title {
  585. padding: 5px 10px;
  586. max-width: 220px;
  587. font-size: 14px;
  588. overflow: hidden;
  589. white-space: nowrap;
  590. text-overflow: ellipsis;
  591. }
  592. .avatar {
  593. width: 28px;
  594. height: 28px;
  595. display: flex;
  596. flex-direction: row;
  597. justify-items: center;
  598. }
  599. // 对话编辑、删除
  600. .button-wrapper {
  601. right: 2px;
  602. display: flex;
  603. flex-direction: row;
  604. justify-items: center;
  605. color: #606266;
  606. .el-icon {
  607. margin-right: 5px;
  608. }
  609. }
  610. }
  611. }
  612. // 角色仓库、清空未设置对话
  613. .tool-box {
  614. line-height: 35px;
  615. display: flex;
  616. justify-content: space-between;
  617. align-items: center;
  618. color: var(--el-text-color);
  619. > div {
  620. display: flex;
  621. align-items: center;
  622. color: #606266;
  623. padding: 0;
  624. margin: 0;
  625. > span {
  626. margin-left: 5px;
  627. }
  628. }
  629. }
  630. }
  631. // 头部
  632. .detail-container {
  633. background: #ffffff;
  634. .header {
  635. display: flex;
  636. flex-direction: row;
  637. align-items: center;
  638. justify-content: space-between;
  639. background: #fbfbfb;
  640. box-shadow: 0 0 0 0 #dcdfe6;
  641. .title {
  642. font-size: 18px;
  643. font-weight: bold;
  644. }
  645. }
  646. }
  647. // main 容器
  648. .main-container {
  649. margin: 0;
  650. padding: 0;
  651. position: relative;
  652. }
  653. .message-container {
  654. position: absolute;
  655. top: 0;
  656. bottom: 0;
  657. left: 0;
  658. right: 0;
  659. //width: 100%;
  660. //height: 100%;
  661. overflow-y: scroll;
  662. padding: 0 15px;
  663. }
  664. // 中间
  665. .chat-list {
  666. display: flex;
  667. flex-direction: column;
  668. overflow-y: hidden;
  669. .message-item {
  670. margin-top: 50px;
  671. }
  672. .left-message {
  673. display: flex;
  674. flex-direction: row;
  675. }
  676. .right-message {
  677. display: flex;
  678. flex-direction: row-reverse;
  679. justify-content: flex-start;
  680. }
  681. .avatar {
  682. //height: 170px;
  683. //width: 170px;
  684. }
  685. .message {
  686. display: flex;
  687. flex-direction: column;
  688. text-align: left;
  689. margin: 0 15px;
  690. .time {
  691. text-align: left;
  692. line-height: 30px;
  693. }
  694. .left-text-container {
  695. display: flex;
  696. flex-direction: column;
  697. overflow-wrap: break-word;
  698. background-color: rgba(228, 228, 228, 0.8);
  699. box-shadow: 0 0 0 1px rgba(228, 228, 228, 0.8);
  700. border-radius: 10px;
  701. padding: 10px 10px 5px 10px;
  702. .left-text {
  703. color: #393939;
  704. font-size: 0.95rem;
  705. }
  706. }
  707. .right-text-container {
  708. display: flex;
  709. flex-direction: row-reverse;
  710. .right-text {
  711. font-size: 0.95rem;
  712. color: #fff;
  713. display: inline;
  714. background-color: #267fff;
  715. color: #fff;
  716. box-shadow: 0 0 0 1px #267fff;
  717. border-radius: 10px;
  718. padding: 10px;
  719. width: auto;
  720. overflow-wrap: break-word;
  721. }
  722. }
  723. .left-btns,
  724. .right-btns {
  725. display: flex;
  726. flex-direction: row;
  727. margin-top: 8px;
  728. }
  729. }
  730. // 复制、删除按钮
  731. .btn-cus {
  732. display: flex;
  733. background-color: transparent;
  734. align-items: center;
  735. .btn-image {
  736. height: 20px;
  737. margin-right: 5px;
  738. }
  739. .btn-cus-text {
  740. color: #757575;
  741. }
  742. }
  743. .btn-cus:hover {
  744. cursor: pointer;
  745. }
  746. .btn-cus:focus {
  747. background-color: #8c939d;
  748. }
  749. }
  750. // 底部
  751. .footer-container {
  752. display: flex;
  753. flex-direction: column;
  754. height: auto;
  755. margin: 0;
  756. padding: 0;
  757. .prompt-from {
  758. display: flex;
  759. flex-direction: column;
  760. height: auto;
  761. border: 1px solid #e3e3e3;
  762. border-radius: 10px;
  763. margin: 20px 20px;
  764. padding: 9px 10px;
  765. }
  766. .prompt-input {
  767. height: 80px;
  768. //box-shadow: none;
  769. border: none;
  770. box-sizing: border-box;
  771. resize: none;
  772. padding: 0px 2px;
  773. //padding: 5px 5px;
  774. overflow: hidden;
  775. }
  776. .prompt-input:focus {
  777. outline: none;
  778. }
  779. .prompt-btns {
  780. display: flex;
  781. justify-content: space-between;
  782. padding-bottom: 0px;
  783. padding-top: 5px;
  784. }
  785. }
  786. </style>
  787. <style lang="scss">
  788. .markdown-view {
  789. font-family: PingFang SC;
  790. font-size: 0.95rem;
  791. font-weight: 400;
  792. line-height: 1.6rem;
  793. letter-spacing: 0em;
  794. text-align: left;
  795. color: #3b3e55;
  796. max-width: 100%;
  797. pre {
  798. position: relative;
  799. }
  800. pre code.hljs {
  801. width: auto;
  802. }
  803. code.hljs {
  804. border-radius: 6px;
  805. padding-top: 20px;
  806. width: auto;
  807. @media screen and (min-width: 1536px) {
  808. width: 960px;
  809. }
  810. @media screen and (max-width: 1536px) and (min-width: 1024px) {
  811. width: calc(100vw - 400px - 64px - 32px * 2);
  812. }
  813. @media screen and (max-width: 1024px) and (min-width: 768px) {
  814. width: calc(100vw - 32px * 2);
  815. }
  816. @media screen and (max-width: 768px) {
  817. width: calc(100vw - 16px * 2);
  818. }
  819. }
  820. p,
  821. code.hljs {
  822. margin-bottom: 16px;
  823. }
  824. p {
  825. //margin-bottom: 1rem !important;
  826. margin: 0;
  827. margin-bottom: 3px;
  828. }
  829. /* 标题通用格式 */
  830. h1,
  831. h2,
  832. h3,
  833. h4,
  834. h5,
  835. h6 {
  836. color: var(--color-G900);
  837. margin: 24px 0 8px;
  838. font-weight: 600;
  839. }
  840. h1 {
  841. font-size: 22px;
  842. line-height: 32px;
  843. }
  844. h2 {
  845. font-size: 20px;
  846. line-height: 30px;
  847. }
  848. h3 {
  849. font-size: 18px;
  850. line-height: 28px;
  851. }
  852. h4 {
  853. font-size: 16px;
  854. line-height: 26px;
  855. }
  856. h5 {
  857. font-size: 16px;
  858. line-height: 24px;
  859. }
  860. h6 {
  861. font-size: 16px;
  862. line-height: 24px;
  863. }
  864. /* 列表(有序,无序) */
  865. ul,
  866. ol {
  867. margin: 0 0 8px 0;
  868. padding: 0;
  869. font-size: 16px;
  870. line-height: 24px;
  871. color: #3b3e55; // var(--color-CG600);
  872. }
  873. li {
  874. margin: 4px 0 0 20px;
  875. margin-bottom: 1rem;
  876. }
  877. ol > li {
  878. list-style-type: decimal;
  879. margin-bottom: 1rem;
  880. // 表达式,修复有序列表序号展示不全的问题
  881. // &:nth-child(n + 10) {
  882. // margin-left: 30px;
  883. // }
  884. // &:nth-child(n + 100) {
  885. // margin-left: 30px;
  886. // }
  887. }
  888. ul > li {
  889. list-style-type: disc;
  890. font-size: 16px;
  891. line-height: 24px;
  892. margin-right: 11px;
  893. margin-bottom: 1rem;
  894. color: #3b3e55; // var(--color-G900);
  895. }
  896. ol ul,
  897. ol ul > li,
  898. ul ul,
  899. ul ul li {
  900. // list-style: circle;
  901. font-size: 16px;
  902. list-style: none;
  903. margin-left: 6px;
  904. margin-bottom: 1rem;
  905. }
  906. ul ul ul,
  907. ul ul ul li,
  908. ol ol,
  909. ol ol > li,
  910. ol ul ul,
  911. ol ul ul > li,
  912. ul ol,
  913. ul ol > li {
  914. list-style: square;
  915. }
  916. }
  917. </style>