index.vue 25 KB

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