index.vue 25 KB

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