AIImageToImage.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. <template>
  2. <!-- 图生图 -->
  3. <div class="home-container">
  4. <!-- 展开收起侧边栏 -->
  5. <div
  6. class="icon-expand"
  7. :style="{
  8. backgroundColor: drawerVisible ? '#44449c' : '#7F70C840',
  9. left: drawerVisible ? '18%' : '0'
  10. }"
  11. @click="toggleDrawer"
  12. >
  13. <span
  14. class="vertical-lines"
  15. :style="{
  16. color: drawerVisible ? '#8a78d0' : 'white'
  17. }"
  18. >||</span
  19. >
  20. </div>
  21. <!-- 左侧折叠面板 -->
  22. <LeftPanel ref="leftPanelRef" v-if="drawerVisible"/>
  23. <div class="left-group2">
  24. <div class="title-box">
  25. <div class="box-icon" @click="goBack">
  26. <el-icon class="left-icon"><ArrowLeftBold /></el-icon>
  27. 图生图
  28. </div>
  29. </div>
  30. <div class="img-box">
  31. <p>
  32. <img
  33. style=" width: fit-content; height: 180px; margin: 10px;"
  34. src="@/assets/images/color.png"
  35. class="avatar user"
  36. />
  37. </p>
  38. <p>期待你的画作喔~</p>
  39. </div>
  40. </div>
  41. <!-- 右侧AI问答 -->
  42. <div class="number-people">
  43. <div class="content-box">
  44. <!-- AI对话框 -->
  45. <div class="chat-dialog">
  46. <!-- 对话消息列表 -->
  47. <div class="message-list">
  48. <div v-if="imageAllList.length > 0">
  49. <div v-for="(item, index) in imageAllList" :key="index">
  50. <!-- 用户消息 -->
  51. <div class="user-message" v-if="item.type === 'user'">
  52. {{ item.content }}
  53. <div class="user-image-list" v-if="item.imageUrl">
  54. <el-image
  55. style="width: fit-content; height: 180px; margin: 10px;"
  56. :src="item.imageUrl"
  57. :preview-src-list="[item.imageUrl]"
  58. fit="cover"
  59. show-progress
  60. >
  61. <template
  62. #toolbar="{ actions, prev, next, reset, activeIndex, setActiveItem }"
  63. >
  64. <el-icon @click="prev"><Back /></el-icon>
  65. <el-icon @click="next"><Right /></el-icon>
  66. <el-icon @click="setActiveItem(item.imageList.length - 1)">
  67. <DArrowRight />
  68. </el-icon>
  69. <el-icon @click="actions('zoomOut')"><ZoomOut /></el-icon>
  70. <el-icon @click="actions('zoomIn', { enableTransition: false, zoomRate: 2 })"><ZoomIn /></el-icon>
  71. <el-icon @click="actions('clockwise', { rotateDeg: 180, enableTransition: false })"><RefreshRight /></el-icon>
  72. <el-icon @click="actions('anticlockwise')"><RefreshLeft /></el-icon>
  73. <el-icon @click="reset"><Refresh /></el-icon>
  74. <el-icon @click="download(activeIndex)"><Download /></el-icon>
  75. </template>
  76. </el-image>
  77. </div>
  78. </div>
  79. <!-- AI生成图片对话框 -->
  80. <div class="ai-message" v-if="item.type !== 'user'">
  81. {{ item.content }}
  82. <span v-if="item.loading" class="loading-dots">
  83. <span class="dot"></span>
  84. <span class="dot"></span>
  85. <span class="dot"></span>
  86. </span>
  87. <div class="image-list" v-if="item.imageList">
  88. <el-image
  89. v-for="(image, index) in item.imageList"
  90. :key="index"
  91. style=" width: fit-content; height: 220px; margin: 10px;"
  92. :src="image"
  93. :preview-src-list="item.imageList"
  94. fit="cover"
  95. show-progress
  96. >
  97. <template
  98. #toolbar="{ actions, reset, activeIndex}"
  99. >
  100. <el-icon @click="actions('zoomOut')"><ZoomOut /></el-icon>
  101. <el-icon
  102. @click="actions('zoomIn', { enableTransition: false, zoomRate: 2 })">
  103. <ZoomIn />
  104. </el-icon>
  105. <el-icon
  106. @click="actions('clockwise', { rotateDeg: 180, enableTransition: false })">
  107. <RefreshRight />
  108. </el-icon>
  109. <el-icon @click="actions('anticlockwise')"><RefreshLeft /></el-icon>
  110. <el-icon @click="reset"><Refresh /></el-icon>
  111. <el-icon @click="download(activeIndex)"><Download /></el-icon>
  112. </template>
  113. </el-image>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. <!-- 输入框和发送按钮 -->
  120. <div class="input-section">
  121. <input
  122. type="text"
  123. v-model="inputMessage"
  124. placeholder="描述任何画面..."
  125. @keyup.enter="sendMessage"
  126. style="flex: 1; margin-right: 8px;"
  127. />
  128. <!-- 参考图 -->
  129. <ImageUpload v-model="uploadedImage" ref="imageUploadRef"/>
  130. <!-- 语音输入按钮 -->
  131. <button
  132. @click="toggleSpeechInput"
  133. class="speech-btn"
  134. :class="{ 'recording': isRecording }"
  135. >
  136. <el-icon v-if="!isRecording"><Microphone /></el-icon>
  137. <el-icon v-else><Mute /></el-icon>
  138. <!-- 显示倒计时(仅录音时显示) -->
  139. <span v-if="isRecording" class="countdown-text">{{ countdown }}s</span>
  140. </button>
  141. <!-- 终止按钮 -->
  142. <div
  143. v-if="conversationInProgress"
  144. @click="stopStream"
  145. class="stop-btn"
  146. title="终止问答"
  147. >
  148. <img :src="stopicon" alt="停止" />
  149. </div>
  150. <button v-if="!conversationInProgress"
  151. @click="sendMessage">发送</button>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </template>
  158. <script setup>
  159. import { ref, onMounted,onUnmounted} from 'vue'
  160. import {AiImageStatusEnum, CreatePainting, PaintingGetMys} from '@/api/questions.js'
  161. import { useRouter, useRoute } from 'vue-router'
  162. import {
  163. Document,
  164. Menu as IconMenu,
  165. Location,
  166. Setting,
  167. ArrowLeftBold,
  168. Fold,
  169. Expand,
  170. ChatLineRound,
  171. Picture,
  172. MagicStick,
  173. Tickets,
  174. User
  175. } from '@element-plus/icons-vue'
  176. import { saveRecord } from '@/api/personalized/index.js'
  177. // 导入全局状态
  178. import { globalState } from '@/utils/globalState.js'
  179. // 语音图标
  180. import { Microphone, Mute } from "@element-plus/icons-vue";
  181. // 终止按钮
  182. import stopicon from "@/assets/icon/stopicon.png";
  183. // 消息组件
  184. import {Message} from "@/utils/message/Message.js";
  185. // 图生图
  186. import ImageUpload from '@/components/ImageUpload/index.vue';
  187. // 导入getModelIdByType接口
  188. import { getModelIdByType } from '@/api/teachers.js'
  189. import { ModelTypeEnum } from '@/api/teachers.js'
  190. // 存储上传的图片
  191. const uploadedImage = ref('');
  192. const imageUploadRef = ref(null);
  193. // 语音输入响应式变量
  194. const isRecording = ref(false); // 录音状态
  195. const recognition = ref(null); // 语音识别实例
  196. const countdown = ref(0); // 倒计时剩余秒数
  197. const countdownTimer = ref(null); // 倒计时定
  198. // 对话状态变量
  199. const conversationInProgress = ref(false); // 对话是否正在进行中
  200. const conversationInAbortController = ref(); // 对话进行中 abort 控制器
  201. // 返回上一页
  202. const goBack = () => {
  203. router.push('/ai-laboratory')
  204. }
  205. const router = useRouter()
  206. const route = useRoute()
  207. // 导入图片
  208. import question from '@/assets/icon/question.png'
  209. import painting from '@/assets/icon/painting.png'
  210. import human from '@/assets/icon/human.png'
  211. import LeftPanel from '@/components/LeftPanel.vue'
  212. const leftPanelRef = ref(null)
  213. // tts 语音
  214. import { useAudioPlayer } from '@/api/tts/useAudioPlayer';
  215. const { playAudioChunk } = useAudioPlayer();
  216. // 添加抽屉显示状态
  217. const drawerVisible = ref(true)
  218. // 添加切换抽屉显示状态的函数
  219. const toggleDrawer = () => {
  220. drawerVisible.value = !drawerVisible.value
  221. }
  222. // 年级ID相关
  223. const gradeId = ref('')
  224. // 添加消息计数器变量
  225. const messageCount = ref(0)
  226. // modelId响应式变量
  227. const modelId = ref(0)
  228. // 保存记录
  229. onMounted(async () => {
  230. // 从全局状态初始化年级ID
  231. gradeId.value = globalState.initGradeId()
  232. try{
  233. const res = await saveRecord({
  234. brpNjId: gradeId.value,
  235. brpType: "aiCount",
  236. brpProgress: 1
  237. });
  238. // 获取modelId
  239. const modelRes = await getModelIdByType({ type: ModelTypeEnum.IMAGE_TO_IMAGE, platform: "DouBao" })
  240. modelId.value = modelRes.data
  241. }catch(error){
  242. console.error('保存记录失败:', error);
  243. }
  244. });
  245. // 消息列表和输入内容的响应式变量
  246. const messages = ref([])
  247. const inputMessage = ref('')
  248. // 初始化语音识别
  249. const initSpeechRecognition = () => {
  250. const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
  251. if (!SpeechRecognition) {
  252. alert("当前浏览器不支持语音输入功能");
  253. return null;
  254. }
  255. const instance = new SpeechRecognition();
  256. instance.lang = 'zh-CN';
  257. instance.interimResults = false;
  258. instance.onresult = (event) => {
  259. if (event.results?.[0]?.[0]) {
  260. inputMessage.value += event.results[0][0].transcript;
  261. }
  262. };
  263. // 识别器结束时清除定时器
  264. instance.onend = () => {
  265. clearInterval(countdownTimer.value);
  266. isRecording.value = false;
  267. countdown.value = 0;
  268. };
  269. instance.onerror = (event) => {
  270. console.error('语音识别错误:', event.error);
  271. clearInterval(countdownTimer.value); // 出错时清除定时器
  272. isRecording.value = false;
  273. Message().error('语音输入失败,请重试!', true)
  274. countdown.value = 0;
  275. };
  276. return instance;
  277. };
  278. // 切换录音状态
  279. const toggleSpeechInput = () => {
  280. // 清除可能存在的旧定时器
  281. clearInterval(countdownTimer.value);
  282. countdownTimer.value = null;
  283. if (isRecording.value) {
  284. // 手动停止时重置状态
  285. countdown.value = 0;
  286. recognition.value?.stop();
  287. isRecording.value = false;
  288. } else {
  289. // 初始化倒计时前再次清除定时器(防止快速点击)
  290. clearInterval(countdownTimer.value);
  291. countdown.value = 10; // 重置为10秒
  292. recognition.value = initSpeechRecognition();
  293. if (!recognition.value) return;
  294. navigator.mediaDevices.getUserMedia({ audio: true })
  295. .then(() => {
  296. recognition.value.start();
  297. isRecording.value = true;
  298. // 启动新的倒计时定时器
  299. countdownTimer.value = setInterval(() => {
  300. countdown.value--;
  301. if (countdown.value <= 0) {
  302. clearInterval(countdownTimer.value); // 倒计时结束清除
  303. recognition.value.stop();
  304. isRecording.value = false;
  305. countdown.value = 0;
  306. }
  307. }, 1000);
  308. })
  309. .catch((err) => {
  310. console.error("麦克风权限获取失败:", err);
  311. alert("请允许麦克风权限以使用语音输入");
  312. // 出错时重置状态
  313. isRecording.value = false;
  314. countdown.value = 0;
  315. });
  316. }
  317. };
  318. // 停止操作函数
  319. const stopStream = async () => {
  320. // tip:如果 stream 进行中的 message,就需要调用 controller 结束
  321. if (conversationInAbortController.value) {
  322. conversationInAbortController.value.abort();
  323. }
  324. // 设置为 false
  325. conversationInProgress.value = false;
  326. };
  327. // 发送消息函数,图片数据
  328. const sendMessage = async() => {
  329. if (uploadedImage.value) {
  330. // 创建 AbortController 实例,以便中止请求
  331. conversationInAbortController.value = new AbortController();
  332. // 标记对话进行中
  333. conversationInProgress.value = true;
  334. // 先保存内容 再置空输入框
  335. let content = inputMessage.value;
  336. inputMessage.value = '';
  337. // 创建用户消息对象,包含可能的图片
  338. const userMessage = {
  339. type: 'user',
  340. content: content,
  341. };
  342. // 如果有上传的图片,添加到用户消息中
  343. if (uploadedImage.value) {
  344. userMessage.imageUrl = uploadedImage.value;
  345. // 清空上传的图片
  346. // uploadedImage.value = '';
  347. }
  348. imageAllList.value.push(userMessage);
  349. imageAllList.value.push({
  350. type: 'ai',
  351. content: "正在为您生成图片,请稍等",
  352. loading: true
  353. })
  354. // 递增消息计数器
  355. messageCount.value++
  356. // 发送saveRecord请求 保存消息次数
  357. try{
  358. await saveRecord({
  359. brpNjId: gradeId.value,
  360. brpType: "aiCount",
  361. brpProgress: messageCount.value
  362. });
  363. console.log('保存记录成功,消息次数:', messageCount.value);
  364. }catch(error){
  365. console.error('保存记录失败:', error);
  366. conversationInProgress.value = false;
  367. }
  368. try {
  369. CreatePainting({
  370. "modelId": modelId.value,
  371. "prompt":content,
  372. "width":1024,
  373. "height":1024,
  374. "promptImage":uploadedImage.value
  375. }).then(res=>{
  376. console.log("生成图片",res)
  377. //目前写死调用已生成的图片,全部通了后再改
  378. inProgressImageMap.value[res.data] = {id:res.data,status:AiImageStatusEnum.IN_PROGRESS}
  379. // inProgressImageMap.value[260] = {id:260,status:AiImageStatusEnum.IN_PROGRESS}
  380. }).finally(() => {
  381. // 图片生成请求完成后更新状态
  382. conversationInProgress.value = false;
  383. });
  384. } catch (error) {
  385. console.error('生成图片失败:', error);
  386. conversationInProgress.value = false;
  387. }
  388. } else {
  389. // 如果没有上传图片,显示提示信息
  390. Message().error('请先上传图片!', true);
  391. }
  392. // 调用子组件的方法清除预览图
  393. imageUploadRef.value?.clearPreview();
  394. };
  395. // 生成图片
  396. import { ElIcon } from 'element-plus'
  397. import {
  398. Back,
  399. DArrowRight,
  400. Download,
  401. Refresh,
  402. RefreshLeft,
  403. RefreshRight,
  404. Right,
  405. ZoomIn,
  406. ZoomOut,
  407. } from '@element-plus/icons-vue'
  408. const imageAllList = ref([]) // 对话的消息列表
  409. const imageList = ref([]) // image 列表
  410. // 图片轮询相关的参数(正在生成中的)
  411. const inProgressImageMap = ref({}) // 监听的 image 映射,一般是生成中(需要轮询),key 为 image 编号,value 为 image
  412. const inProgressTimer = ref() // 生成中的 image 定时器,轮询生成进展
  413. /** 轮询生成中的 image 列表 */
  414. const refreshWatchImages = async () => {
  415. const imageIds = Object.keys(inProgressImageMap.value).map(Number)
  416. if (imageIds.length === 0) {
  417. return
  418. }
  419. const list = await PaintingGetMys(imageIds)
  420. const newWatchImages = {}
  421. list.data.forEach((image) => {
  422. if (image.status === AiImageStatusEnum.IN_PROGRESS) {
  423. newWatchImages[image.id] = image
  424. } else {
  425. imageAllList.value.pop();
  426. console.log('AI生成的图片地址:', image.picUrl);
  427. imageAllList.value.push({
  428. type: 'ai',
  429. content: "已为您生成图片:",
  430. imageList: [image.picUrl],
  431. })
  432. }
  433. })
  434. inProgressImageMap.value = newWatchImages
  435. if (newWatchImages.size === 0) {
  436. inProgressTimerFun()
  437. }
  438. }
  439. /** 组件挂在的时候 */
  440. onMounted(async () => {
  441. refreshWatchImagesFun()
  442. })
  443. /** 组件取消挂在的时候 */
  444. onUnmounted(async () => {
  445. inProgressTimerFun()
  446. })
  447. // 自动刷新 image 列表
  448. const refreshWatchImagesFun = () => {
  449. inProgressTimer.value = setInterval(async () => {
  450. await refreshWatchImages()
  451. }, 1000 * 3)
  452. }
  453. // 停止刷新image列表
  454. const inProgressTimerFun = () => {
  455. if (inProgressTimer.value) {
  456. clearInterval(inProgressTimer.value)
  457. }
  458. }
  459. </script>
  460. <style scoped lang="scss">
  461. @use 'sass:math';
  462. // 定义rpx转换函数
  463. @function rpx($px) {
  464. @return math.div($px, 750) * 100vw;
  465. }
  466. // 用户图片列表样式
  467. .user-image-list {
  468. display: flex;
  469. flex-wrap: wrap;
  470. margin-top: rpx(5);
  471. }
  472. /* 添加过渡样式 */
  473. .drawer-slide-enter-active,
  474. .drawer-slide-leave-active {
  475. transition: all 0.3s ease;
  476. }
  477. .drawer-slide-enter-from,
  478. .drawer-slide-leave-to {
  479. transform: translateX(-100%);
  480. opacity: 0;
  481. }
  482. :deep(.el-image-viewer__wrapper) {
  483. z-index: 10000 !important;
  484. }
  485. .icon-expand {
  486. width: rpx(8);
  487. height: rpx(35);
  488. border-top-right-radius: rpx(5);
  489. border-bottom-right-radius: rpx(5);
  490. z-index: 9999;
  491. position: absolute;
  492. top: 50%;
  493. left: 18%;
  494. transform: translateY(-50%);
  495. background-color: #44449c;
  496. cursor: pointer; // 添加鼠标指针样式
  497. clip-path: polygon(0 0, 100% 15%, 100% 85%, 0 100%);
  498. display: flex;
  499. justify-content: center;
  500. align-items: center;
  501. transition: all 0.3s ease;
  502. }
  503. .icon-expand .vertical-lines {
  504. color: #8a78d0;
  505. font-size: rpx(10);
  506. }
  507. .menu-icon {
  508. width:rpx(11);
  509. height: rpx(11);
  510. margin-right: rpx(2);
  511. }
  512. // 侧边栏
  513. .left-group1 {
  514. width: rpx(135);
  515. height: 100%;
  516. background: linear-gradient(to bottom, #001169, #8a78d0);
  517. }
  518. .home-container {
  519. position: fixed;
  520. top: 0;
  521. left: 0;
  522. right: 0;
  523. bottom: 0;
  524. display: flex;
  525. flex-direction: row;
  526. gap: rpx(0);
  527. background: linear-gradient(
  528. to bottom,
  529. #e2ddfc,
  530. #f1effd
  531. ); /* 设置悬停、聚焦、点击状态下的背景色 */
  532. }
  533. // 侧边栏
  534. .left-group {
  535. width: rpx(135);
  536. height: 100%;
  537. background: linear-gradient(to bottom, #001169, #8a78d0);
  538. }
  539. .mb-2 {
  540. color: black;
  541. margin-top: rpx(1);
  542. }
  543. .tac ::v-deep(.el-menu) {
  544. background-color: transparent;
  545. border: none;
  546. width: 100%;
  547. margin-top: rpx(55);
  548. margin-left: rpx(10);
  549. }
  550. .el-menu-item {
  551. width: rpx(115);
  552. height: rpx(25);
  553. margin-bottom: rpx(5);
  554. border-radius: rpx(6);
  555. color: white;
  556. font-size: rpx(8);
  557. }
  558. .el-menu-item .el-icon svg {
  559. font-size: rpx(15);
  560. color: white;
  561. }
  562. .el-menu ::v-deep(.el-menu-item:hover),
  563. .el-menu ::v-deep(.el-menu-item:focus),
  564. .el-menu ::v-deep(.el-menu-item:active) {
  565. background: linear-gradient(
  566. to bottom,
  567. #ffefb0,
  568. #ffcc00
  569. ); /* 设置悬停、聚焦、点击状态下的背景色 */
  570. box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
  571. color: black;
  572. font-size: rpx(8);
  573. }
  574. .el-menu-vertical-demo .el-menu-item.is-active {
  575. /* 可根据需求修改选中样式 */
  576. background: linear-gradient(
  577. to bottom,
  578. #ffefb0,
  579. #ffcc00
  580. ); /* 设置悬停、聚焦、点击状态下的背景色 */
  581. box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
  582. color: black;
  583. font-size: rpx(8);
  584. }
  585. // 侧边栏
  586. .left-group2 {
  587. width: rpx(150);
  588. height: 100%;
  589. background-color: #ece9fd;
  590. }
  591. .left-group2 img {
  592. width: rpx(110);
  593. height: auto;
  594. margin-top: rpx(30);
  595. }
  596. .title-box {
  597. height: rpx(50);
  598. }
  599. .box-icon {
  600. width: 100%;
  601. height: 100%;
  602. flex: 1;
  603. display: flex; // 添加 flex 布局
  604. align-items: center; // 垂直居中
  605. color: black; // 设置图标颜色为白色
  606. padding-left: rpx(15);
  607. font-size: rpx(10); // 设置图标大小,可按需调整
  608. cursor: pointer; // 添加鼠标指针样式
  609. }
  610. .box-icon .left-icon {
  611. margin-left: rpx(10);
  612. margin-right: rpx(5); // 设置图标和文字之间的间距 ;
  613. }
  614. .number-people {
  615. flex: 1;
  616. height: 100%;
  617. display: flex;
  618. background-color: #ece9fd;
  619. }
  620. .content-box {
  621. flex: 1;
  622. margin-top: rpx(10);
  623. margin-bottom: rpx(10);
  624. margin-right: rpx(10);
  625. border-radius: rpx(15);
  626. background: rgba($color: #ffffff, $alpha: 0.5);
  627. overflow-y: auto;
  628. }
  629. //左侧展览区图标
  630. .img-box {
  631. margin-top: rpx(50);
  632. color: #a39dce;
  633. }
  634. // 对话框
  635. .chat-dialog {
  636. display: flex;
  637. flex-direction: column;
  638. height: 100%;
  639. }
  640. .message-list {
  641. flex: 1;
  642. overflow-y: auto;
  643. padding: rpx(15);
  644. }
  645. /* 自定义滚动条样式 */
  646. .message-list::-webkit-scrollbar {
  647. width: rpx(2); /* 滚动条宽度 */
  648. }
  649. .message-list::-webkit-scrollbar-track {
  650. background: #f1effd; /* 滚动条轨道背景色 */
  651. border-radius: rpx(4);
  652. }
  653. .message-list::-webkit-scrollbar-thumb {
  654. background: #e2ddfc; /* 滚动条滑块颜色 */
  655. border-radius: rpx(4);
  656. }
  657. .message-list::-webkit-scrollbar-thumb:hover {
  658. background: #e2ddfc; /* 滚动条滑块 hover 状态颜色 */
  659. }
  660. .message-list .user-message {
  661. background-color: #ffffff;
  662. margin-left: auto; // 消息靠右显示
  663. margin-right: 0; // 重置右边距
  664. max-width: rpx(400);
  665. font-size: rpx(8);
  666. width: fit-content; // 宽度随文字内容变化
  667. border-radius: rpx(5);
  668. padding: rpx(5);
  669. text-align: left; // 文字左对齐
  670. }
  671. .message-list .ai-message {
  672. background-color: #ffdd55;
  673. margin-left: 0; // 消息靠左显示
  674. margin-right: auto; // 重置右边距
  675. margin-bottom: rpx(10);
  676. width: fit-content;
  677. max-width: rpx(400);
  678. padding: rpx(5);
  679. font-size: rpx(8);
  680. border-radius: rpx(5);
  681. text-align: left; // 文字左对齐
  682. }
  683. // 加载动画效果
  684. .loading-dots {
  685. display: inline-block;
  686. margin-left: rpx(5);
  687. }
  688. .loading-dots .dot {
  689. display: inline-block;
  690. width: rpx(3);
  691. height: rpx(3);
  692. border-radius: 50%;
  693. background-color: #333;
  694. margin: 0 rpx(1);
  695. animation: loading-dot 1.4s infinite ease-in-out both;
  696. }
  697. .loading-dots .dot:nth-child(1) {
  698. animation-delay: -0.32s;
  699. }
  700. .loading-dots .dot:nth-child(2) {
  701. animation-delay: -0.16s;
  702. }
  703. @keyframes loading-dot {
  704. 0%, 80%, 100% {
  705. transform: scale(0);
  706. }
  707. 40% {
  708. transform: scale(1);
  709. }
  710. }
  711. .image-list {
  712. display: flex;
  713. flex-wrap: wrap;
  714. }
  715. .content-demo {
  716. background-color: #f4f2fa;
  717. border-radius: 15px;
  718. padding: 30px 10px;
  719. }
  720. .input-section {
  721. display: flex;
  722. padding: rpx(10);
  723. gap: rpx(5);
  724. .speech-btn {
  725. padding: rpx(5) rpx(10);
  726. background: #fff;
  727. border: 1px solid #ffce1b;
  728. border-radius: rpx(5);
  729. cursor: pointer;
  730. display: flex;
  731. align-items: center;
  732. &.recording {
  733. background: #ffeeba;
  734. border-color: #ffc107;
  735. .el-icon {
  736. color: #dc3545;
  737. }
  738. }
  739. .el-icon {
  740. font-size: rpx(8);
  741. color: #666;
  742. }
  743. }
  744. // 终止按钮样式
  745. .stop-btn {
  746. cursor: pointer;
  747. display: flex;
  748. align-items: center;
  749. img {
  750. width: rpx(20);
  751. height: rpx(20);
  752. }
  753. }
  754. }
  755. .input-section input {
  756. flex: 1;
  757. padding: rpx(5);
  758. font-size: rpx(7);
  759. border: 1px solid #ccc;
  760. border-radius: rpx(5);
  761. }
  762. .input-section button {
  763. padding: rpx(5) rpx(15);
  764. background: linear-gradient(
  765. to bottom,
  766. #fee78a,
  767. #ffce1b
  768. ); /* 设置悬停、聚焦、点击状态下的背景色 */
  769. color: black;
  770. border: none;
  771. font-size: rpx(7);
  772. border-radius: rpx(5);
  773. cursor: pointer;
  774. box-shadow: 0 0px 2px rgba(0, 0, 0, 0.3);
  775. }
  776. .image-upload-section {
  777. padding: rpx(10);
  778. display: flex;
  779. justify-content: center;
  780. align-items: center;
  781. }
  782. </style>