AIQuestions.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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. <!-- 原左侧折叠面板和右侧AI问答 -->
  24. <div class="content-wrapper">
  25. <div class="left-group2">
  26. <div class="title-box">
  27. <div class="box-icon" @click="goBack">
  28. <el-icon class="left-icon"><ArrowLeftBold /></el-icon>
  29. {{ personName }}
  30. </div>
  31. </div>
  32. <div class="selected-image">
  33. <img :src="selectedImage" alt="" />
  34. </div>
  35. </div>
  36. <!-- 右侧AI问答 -->
  37. <div class="number-people">
  38. <div class="content-box">
  39. <!-- AI对话框 -->
  40. <div class="chat-dialog">
  41. <!-- 对话消息列表 -->
  42. <div class="message-list" ref="messageListRef">
  43. <div v-for="(item, index) in messageList" :key="index">
  44. <!-- AI消息 -->
  45. <div class="ai-message" v-if="item.type !== 'user'">
  46. <MarkdownView class="left-text" :content="item.content" />
  47. <!-- {{item.content}} -->
  48. </div>
  49. <!-- 用户消息 -->
  50. <div class="user-message" v-if="item.type === 'user'">
  51. {{ item.content }}
  52. </div>
  53. </div>
  54. </div>
  55. <!-- 默认消息 -->
  56. <DefaultMessage
  57. v-if="showDefaultMessages"
  58. @select-message="handleDefaultMessageSelect"
  59. :category="route.query.category"
  60. :quest-tip="route.query.default"
  61. />
  62. <!-- 输入框和发送按钮 -->
  63. <div class="input-section">
  64. <input
  65. type="text"
  66. v-model="prompt"
  67. placeholder="问我任何问题..."
  68. @keyup.enter="handleSendByKeydown"
  69. />
  70. <!-- 添加语音输入按钮 -->
  71. <button
  72. @click="toggleSpeechInput"
  73. class="speech-btn"
  74. :class="{ 'recording': isRecording }"
  75. >
  76. <el-icon v-if="!isRecording"><Microphone /></el-icon>
  77. <el-icon v-else><Mute /></el-icon>
  78. <!-- 显示倒计时(仅录音时显示) -->
  79. <span v-if="isRecording" class="countdown-text">{{ countdown }}s</span>
  80. </button>
  81. <button @click="handleSendByButton">发送</button>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. </template>
  89. <script setup>
  90. import {ref, onMounted, computed, watch, nextTick} from "vue";
  91. import { CreateDialogue, sendChatMessageStream } from "@/api/questions.js";
  92. import { useRouter, useRoute } from "vue-router";
  93. import { saveRecord } from '@/api/personalized/index.js'
  94. // 导入全局状态
  95. import { globalState } from '@/utils/globalState.js'
  96. import MarkdownView from "@/components/MarkdownView/index.vue";
  97. import {
  98. Document,
  99. Menu as IconMenu,
  100. Location,
  101. Setting,
  102. ArrowLeftBold,
  103. MagicStick,
  104. ChatLineRound,
  105. Fold,
  106. Expand,
  107. Picture,
  108. Tickets,
  109. User,
  110. } from "@element-plus/icons-vue";
  111. import DefaultMessage from "@/components/DefaultMessage/index.vue";
  112. // 导入图片
  113. // import question from '@/assets/icon/question.png'
  114. // import painting from '@/assets/icon/painting.png'
  115. // import human from '@/assets/icon/human.png'
  116. // 语音图标
  117. import { Microphone, Mute } from "@element-plus/icons-vue";
  118. import LeftPanel from "@/components/LeftPanel.vue";
  119. const leftPanelRef = ref(null);
  120. // 语音输入响应式变量
  121. const isRecording = ref(false); // 录音状态
  122. const recognition = ref(null); // 语音识别实例
  123. const countdown = ref(0); // 倒计时剩余秒数
  124. const countdownTimer = ref(null); // 倒计时定时器
  125. // 默认消息控制
  126. const showDefaultMessages = ref(true);
  127. const handleDefaultMessageSelect = (message) => {
  128. prompt.value = message;
  129. handleSendByButton();
  130. showDefaultMessages.value = false;
  131. };
  132. // 添加抽屉显示状态
  133. const drawerVisible = ref(true);
  134. // 添加切换抽屉显示状态的函数
  135. const toggleDrawer = () => {
  136. drawerVisible.value = !drawerVisible.value;
  137. };
  138. // 处理菜单展开和关闭
  139. const handleOpen = () => {};
  140. const handleClose = () => {};
  141. // 返回上一页
  142. const goBack = () => {
  143. router.push("/ai-laboratory");
  144. };
  145. const router = useRouter();
  146. const route = useRoute();
  147. const personId = ref(route.query.id);
  148. const personName = ref(route.query.name);
  149. const personIntroduce = ref(route.query.message);
  150. const personImage = ref(route.query.image);
  151. // 渲染实验室携带的人物形象图片
  152. const selectedImage = ref("");
  153. onMounted(() => {
  154. const image = route.query.image;
  155. if (image) {
  156. selectedImage.value = image;
  157. }
  158. });
  159. // 聊天对话
  160. const activeConversationModelPath = ref(null); // 选中的对话编号
  161. const activeConversationId = ref(null); // 选中的对话编号
  162. const activeConversation = ref(null); // 选中的 Conversation
  163. const conversationInProgress = ref(false); // 对话是否正在进行中。目前只有【发送】消息时,会更新为 true,避免切换对话、删除对话等操作,导致 stream 中断
  164. // 消息列表
  165. const messageRef = ref();
  166. const activeMessageList = ref([]); // 选中对话的消息列表
  167. const activeMessageListLoading = ref(false); // activeMessageList 是否正在加载中
  168. const activeMessageListLoadingTimer = ref(); // activeMessageListLoading Timer 定时器。如果加载速度很快,就不进入加载中
  169. // 消息滚动
  170. const textSpeed = ref(50); // Typing speed in milliseconds
  171. const textRoleRunning = ref(false); // Typing speed in milliseconds
  172. // 发送消息输入框
  173. const isComposing = ref(false); // 判断用户是否在输入
  174. const conversationInAbortController = ref(); // 对话进行中 abort 控制器(控制 stream 对话)
  175. const inputTimeout = ref(); // 处理输入中回车的定时器
  176. const prompt = ref(''); // prompt
  177. const enableContext = ref(true); // 是否开启上下文
  178. // 接收 Stream 消息
  179. const receiveMessageFullText = ref("");
  180. const receiveMessageDisplayedText = ref("");
  181. const messageListRef = ref(null);
  182. // =========== 【聊天对话】相关 ===========
  183. /** 获取对话信息 */
  184. const getConversation = async (id) => {
  185. if (!id) {
  186. return;
  187. }
  188. const conversation = ref({});
  189. if (!conversation) {
  190. return;
  191. }
  192. conversation.systemMessage = personIntroduce.value;
  193. activeConversation.value = conversation;
  194. // activeConversationId.value = personId.value
  195. activeConversationModelPath.value = personImage.value;
  196. };
  197. // =========== 【语音录入】相关 ===========
  198. // 初始化语音识别
  199. const initSpeechRecognition = () => {
  200. const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
  201. if (!SpeechRecognition) {
  202. alert("当前浏览器不支持语音输入功能");
  203. return null;
  204. }
  205. const instance = new SpeechRecognition();
  206. instance.lang = 'zh-CN';
  207. instance.interimResults = false;
  208. instance.onresult = (event) => {
  209. if (event.results?.[0]?.[0]) {
  210. prompt.value += event.results[0][0].transcript;
  211. }
  212. };
  213. // 新增:识别器结束时清除定时器
  214. instance.onend = () => {
  215. clearInterval(countdownTimer.value);
  216. isRecording.value = false;
  217. countdown.value = 0;
  218. };
  219. instance.onerror = (event) => {
  220. console.error('语音识别错误:', event.error);
  221. clearInterval(countdownTimer.value); // 出错时清除定时器
  222. isRecording.value = false;
  223. alert('语音输入失败,请重试');
  224. countdown.value = 0;
  225. };
  226. return instance;
  227. };
  228. // 切换录音状态
  229. const toggleSpeechInput = () => {
  230. // 无论当前状态如何,先清除可能存在的旧定时器
  231. clearInterval(countdownTimer.value);
  232. countdownTimer.value = null;
  233. if (isRecording.value) {
  234. // 手动停止时重置状态
  235. countdown.value = 0;
  236. recognition.value?.stop();
  237. isRecording.value = false;
  238. } else {
  239. // 初始化倒计时前再次清除定时器(防止快速点击)
  240. clearInterval(countdownTimer.value);
  241. countdown.value = 10; // 重置为10秒
  242. recognition.value = initSpeechRecognition();
  243. if (!recognition.value) return;
  244. navigator.mediaDevices.getUserMedia({ audio: true })
  245. .then(() => {
  246. recognition.value.start();
  247. isRecording.value = true;
  248. // 启动新的倒计时定时器
  249. countdownTimer.value = setInterval(() => {
  250. countdown.value--;
  251. if (countdown.value <= 0) {
  252. clearInterval(countdownTimer.value); // 倒计时结束清除
  253. recognition.value.stop();
  254. isRecording.value = false;
  255. countdown.value = 0;
  256. }
  257. }, 1000);
  258. })
  259. .catch((err) => {
  260. console.error('麦克风权限获取失败:', err);
  261. alert('请允许麦克风权限以使用语音输入');
  262. // 出错时重置状态
  263. isRecording.value = false;
  264. countdown.value = 0;
  265. });
  266. }
  267. };
  268. // =========== 【聊天对话】相关 ===========
  269. /** 处理来自 keydown 的发送消息 */
  270. const handleSendByKeydown = async (event) => {
  271. // 判断用户是否在输入
  272. if (isComposing.value) {
  273. return;
  274. }
  275. // 进行中不允许发送
  276. if (conversationInProgress.value) {
  277. return;
  278. }
  279. const content = prompt.value?.trim();
  280. if (event.key === "Enter") {
  281. if (event.shiftKey) {
  282. // 插入换行
  283. prompt.value += "\r\n";
  284. event.preventDefault(); // 防止默认的换行行为
  285. } else {
  286. // 发送消息
  287. await doSendMessage(content);
  288. event.preventDefault(); // 防止默认的提交行为
  289. }
  290. }
  291. };
  292. /** 处理来自【发送】按钮的发送消息 */
  293. const handleSendByButton = () => {
  294. doSendMessage(prompt.value?.trim());
  295. };
  296. /** 处理 prompt 输入变化 */
  297. const handlePromptInput = (event) => {
  298. // 非输入法 输入设置为 true
  299. if (!isComposing.value) {
  300. // 回车 event data 是 null
  301. if (event.data == null) {
  302. return;
  303. }
  304. isComposing.value = true;
  305. }
  306. // 清理定时器
  307. if (inputTimeout.value) {
  308. clearTimeout(inputTimeout.value);
  309. }
  310. // 重置定时器
  311. inputTimeout.value = setTimeout(() => {
  312. isComposing.value = false;
  313. }, 400);
  314. };
  315. // TODO注:是不是可以通过 @keydown.enter、@keydown.shift.enter 来实现,回车发送、shift+回车换行;主要看看,是不是可以简化 isComposing 相关的逻辑
  316. const onCompositionstart = () => {
  317. isComposing.value = true;
  318. };
  319. const onCompositionend = () => {
  320. setTimeout(() => {
  321. isComposing.value = false;
  322. }, 200);
  323. };
  324. // 保存记录
  325. // 年级ID相关
  326. const gradeId = ref('')
  327. // 添加消息计数器变量
  328. const messageCount = ref(0)
  329. onMounted(() => {
  330. // 从全局状态初始化年级ID
  331. gradeId.value = globalState.initGradeId()
  332. });
  333. /** 真正执行【发送】消息操作 */
  334. const doSendMessage = async (content) => {
  335. // 校验
  336. if (content.length < 1) {
  337. console.error("发送失败,原因:内容为空!");
  338. return;
  339. }
  340. if (activeConversationId.value == null) {
  341. console.error("还没创建对话,不能发送!");
  342. return;
  343. }
  344. // 递增消息计数器
  345. messageCount.value++
  346. // 发送saveRecord请求 保存消息次数
  347. try{
  348. await saveRecord({
  349. brpNjId: gradeId.value,
  350. brpType: "aiCount",
  351. brpProgress: messageCount.value
  352. });
  353. }catch(error){
  354. console.error('保存记录失败:', error);
  355. }
  356. // 清空输入框
  357. prompt.value = "";
  358. // 执行发送
  359. await doSendMessageStream({
  360. conversationId: activeConversationId.value,
  361. content: content,
  362. });
  363. };
  364. import { useAudioPlayer } from '@/components/TTS/useAudioPlayer';
  365. const { playAudioChunk } = useAudioPlayer();
  366. /** 真正执行【发送】消息操作 */
  367. const doSendMessageStream = async (userMessage) => {
  368. // 创建 AbortController 实例,以便中止请求
  369. conversationInAbortController.value = new AbortController();
  370. // 标记对话进行中
  371. conversationInProgress.value = true;
  372. // 设置为空
  373. receiveMessageFullText.value = "";
  374. try {
  375. // 1.1 先添加两个假数据,等 stream 返回再替换
  376. activeMessageList.value.push({
  377. id: -1,
  378. conversationId: activeConversationId.value,
  379. type: "user",
  380. content: userMessage.content,
  381. createTime: new Date(),
  382. });
  383. activeMessageList.value.push({
  384. id: -2,
  385. conversationId: activeConversationId.value,
  386. type: "assistant",
  387. content: "思考中...",
  388. createTime: new Date(),
  389. });
  390. // 1.3 开始滚动
  391. textRoll();
  392. // 2. 发送 event stream
  393. let isFirstChunk = true; // 是否是第一个 chunk 消息段
  394. await sendChatMessageStream(
  395. userMessage.conversationId,
  396. userMessage.content,
  397. conversationInAbortController.value,
  398. enableContext.value,
  399. async (res) => {
  400. const { code, data, msg } = JSON.parse(res.data);
  401. if (code !== 0) {
  402. console.log(`对话异常! ${msg}`);
  403. return;
  404. }
  405. // 根据事件类型处理
  406. if (data.eventType === 'TEXT') {
  407. // 如果内容为空,就不处理。
  408. if (data.receive?.content === '') {
  409. return
  410. }
  411. // 处理文本消息
  412. receiveMessageFullText.value += data.receive.content;
  413. // 首次返回需要添加一个 message 到页面,后面的都是更新
  414. if (isFirstChunk) {
  415. isFirstChunk = false;
  416. // 弹出两个假数据
  417. activeMessageList.value.pop();
  418. activeMessageList.value.pop();
  419. // 更新返回的数据
  420. activeMessageList.value.push(data.send);
  421. activeMessageList.value.push(data.receive);
  422. }
  423. } else if (data.eventType === 'AUDIO') {
  424. // 处理音频消息
  425. await playAudioChunk(data.audioData);
  426. }
  427. },
  428. (error) => {
  429. console.log(`对话异常! ${error}`);
  430. stopStream();
  431. // 需要抛出异常,禁止重试
  432. throw error;
  433. },
  434. () => {
  435. stopStream();
  436. }
  437. );
  438. } catch {}
  439. };
  440. /** 停止 stream 流式调用 */
  441. const stopStream = async () => {
  442. // tip:如果 stream 进行中的 message,就需要调用 controller 结束
  443. if (conversationInAbortController.value) {
  444. conversationInAbortController.value.abort();
  445. }
  446. // 设置为 false
  447. conversationInProgress.value = false;
  448. };
  449. /**
  450. * 消息列表
  451. *
  452. * 和 {@link #getMessageList()} 的差异是,把 systemMessage 考虑进去
  453. */
  454. const messageList = computed(() => {
  455. if (activeMessageList.value.length > 0) {
  456. return activeMessageList.value;
  457. }
  458. // 没有消息时,如果有 systemMessage 则展示它
  459. if (activeConversation.value?.systemMessage) {
  460. let systemMessage = {
  461. id: 0,
  462. type: "system",
  463. content: activeConversation.value.systemMessage,
  464. };
  465. activeMessageList.value.push(systemMessage);
  466. return [systemMessage];
  467. }
  468. return [];
  469. });
  470. // ============== 【消息滚动】相关 =============
  471. /** 滚动到 message 底部 */
  472. const scrollToBottom = async (isIgnore = false) => {
  473. await nextTick();
  474. if (messageListRef.value) {
  475. messageListRef.value.scrollTop = messageListRef.value.scrollHeight;
  476. }
  477. };
  478. /** 自提滚动效果 */
  479. const textRoll = async () => {
  480. let index = 0;
  481. try {
  482. // 只能执行一次
  483. if (textRoleRunning.value) {
  484. return;
  485. }
  486. // 设置状态
  487. textRoleRunning.value = true;
  488. receiveMessageDisplayedText.value = "";
  489. const task = async () => {
  490. // 调整速度
  491. const diff =
  492. (receiveMessageFullText.value.length -
  493. receiveMessageDisplayedText.value.length) /
  494. 10;
  495. if (diff > 5) {
  496. textSpeed.value = 10;
  497. } else if (diff > 2) {
  498. textSpeed.value = 30;
  499. } else if (diff > 1.5) {
  500. textSpeed.value = 50;
  501. } else {
  502. textSpeed.value = 100;
  503. }
  504. // 对话结束,就按 30 的速度
  505. if (!conversationInProgress.value) {
  506. textSpeed.value = 10;
  507. }
  508. if (index < receiveMessageFullText.value.length) {
  509. receiveMessageDisplayedText.value += receiveMessageFullText.value[index];
  510. index++;
  511. // 更新 message
  512. const lastMessage =
  513. activeMessageList.value[activeMessageList.value.length - 1];
  514. lastMessage.content = receiveMessageDisplayedText.value;
  515. // 滚动到住下面
  516. await scrollToBottom();
  517. // 重新设置任务
  518. timer = setTimeout(task, textSpeed.value);
  519. } else {
  520. // 不是对话中可以结束
  521. if (!conversationInProgress.value) {
  522. textRoleRunning.value = false;
  523. clearTimeout(timer);
  524. } else {
  525. // 重新设置任务
  526. timer = setTimeout(task, textSpeed.value);
  527. }
  528. }
  529. };
  530. let timer = setTimeout(task, textSpeed.value);
  531. } catch {}
  532. };
  533. /** 初始化 **/
  534. onMounted(async () => {
  535. if (personId.value) {
  536. // 智能问答
  537. CreateDialogue({ roleId: personId.value })
  538. .then((res) => {
  539. console.log("创建会话:", res);
  540. activeConversationId.value = res.data;
  541. })
  542. .catch((error) => {
  543. console.error("请求出错:", error);
  544. });
  545. await getConversation(personId.value);
  546. }
  547. // 获取列表数据
  548. // activeMessageListLoading.value = true
  549. });
  550. </script>
  551. <style scoped lang="scss">
  552. @use "sass:math";
  553. // 定义rpx转换函数
  554. @function rpx($px) {
  555. @return math.div($px, 750) * 100vw;
  556. }
  557. /* 添加过渡样式 */
  558. .drawer-slide-enter-active,
  559. .drawer-slide-leave-active {
  560. transition: all 0.3s ease;
  561. }
  562. .drawer-slide-enter-from,
  563. .drawer-slide-leave-to {
  564. transform: translateX(-100%);
  565. opacity: 0;
  566. }
  567. .home-container {
  568. position: fixed;
  569. top: 0;
  570. left: 0;
  571. right: 0;
  572. bottom: 0;
  573. display: flex;
  574. flex-direction: row;
  575. gap: rpx(0);
  576. background: linear-gradient(to bottom, #e2ddfc, #f1effd);
  577. }
  578. .icon-expand {
  579. width: rpx(8);
  580. height: rpx(35);
  581. border-top-right-radius: rpx(5);
  582. border-bottom-right-radius: rpx(5);
  583. z-index: 9999;
  584. position: absolute;
  585. top: 50%;
  586. left: 18%;
  587. transform: translateY(-50%);
  588. background-color: #44449c;
  589. cursor: pointer; // 添加鼠标指针样式
  590. clip-path: polygon(0 0, 100% 15%, 100% 85%, 0 100%);
  591. display: flex;
  592. justify-content: center;
  593. align-items: center;
  594. transition: all 0.3s ease;
  595. }
  596. .icon-expand .vertical-lines {
  597. color: #8a78d0;
  598. font-size: rpx(10);
  599. }
  600. .menu-icon {
  601. width: rpx(11);
  602. height: rpx(11);
  603. margin-right: rpx(2);
  604. }
  605. .content-wrapper {
  606. display: flex;
  607. flex: 1;
  608. }
  609. .left-group {
  610. width: rpx(135);
  611. height: 100%;
  612. background: linear-gradient(to bottom, #001169, #8a78d0);
  613. }
  614. .mb-2 {
  615. color: black;
  616. margin-top: rpx(1);
  617. }
  618. .tac ::v-deep(.el-menu) {
  619. background-color: transparent;
  620. border: none;
  621. width: 100%;
  622. margin-top: rpx(55);
  623. margin-left: rpx(10);
  624. }
  625. .el-menu-item {
  626. width: rpx(115);
  627. height: rpx(25);
  628. margin-bottom: rpx(5);
  629. border-radius: rpx(6);
  630. color: white;
  631. font-size: rpx(8);
  632. }
  633. .el-menu-item .el-icon svg {
  634. font-size: rpx(15);
  635. color: white;
  636. }
  637. .el-menu ::v-deep(.el-menu-item:hover),
  638. .el-menu ::v-deep(.el-menu-item:focus),
  639. .el-menu ::v-deep(.el-menu-item:active) {
  640. background: linear-gradient(
  641. to bottom,
  642. #ffefb0,
  643. #ffcc00
  644. ); /* 设置悬停、聚焦、点击状态下的背景色 */
  645. box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
  646. color: black;
  647. font-size: rpx(8);
  648. }
  649. .el-menu .el-menu-item.is-active {
  650. background: linear-gradient(to bottom, #fee78a, #ffce1b);
  651. color: black;
  652. font-size: rpx(8);
  653. box-shadow: 0 4px 8px rgba(3, 3, 3, 0.3);
  654. }
  655. // 侧边栏
  656. .left-group2 {
  657. width: rpx(150);
  658. height: 100%;
  659. display: flex;
  660. background-color: #ece9fd;
  661. }
  662. .left-group2 img {
  663. width: rpx(120);
  664. // height: auto;
  665. }
  666. .selected-image {
  667. flex: 1;
  668. margin: auto;
  669. margin-left: rpx(-60);
  670. }
  671. .title-box {
  672. height: rpx(50);
  673. }
  674. .box-icon {
  675. width: 100%;
  676. height: 100%;
  677. flex: 1;
  678. display: flex; // 添加 flex 布局
  679. align-items: center; // 垂直居中
  680. color: black; // 设置图标颜色为白色
  681. padding-left: rpx(15);
  682. font-size: rpx(10); // 设置图标大小,可按需调整
  683. cursor: pointer; // 添加鼠标指针样式
  684. }
  685. .box-icon .left-icon {
  686. margin-left: rpx(10);
  687. margin-right: rpx(5); // 设置图标和文字之间的间距 ;
  688. }
  689. .number-people {
  690. flex: 1;
  691. height: 100%;
  692. display: flex;
  693. background-color: #ece9fd;
  694. }
  695. .content-box {
  696. flex: 1;
  697. margin-top: rpx(10);
  698. margin-bottom: rpx(10);
  699. margin-right: rpx(10);
  700. border-radius: rpx(15);
  701. background: rgba($color: #ffffff, $alpha: 0.5);
  702. }
  703. // 对话框
  704. .chat-dialog {
  705. display: flex;
  706. flex-direction: column;
  707. height: 100%;
  708. }
  709. .message-list {
  710. flex: 1;
  711. overflow-y: auto;
  712. padding: rpx(15);
  713. }
  714. /* 自定义滚动条样式 */
  715. .message-list::-webkit-scrollbar {
  716. width: rpx(2); /* 滚动条宽度 */
  717. }
  718. .message-list::-webkit-scrollbar-track {
  719. background: #f1effd; /* 滚动条轨道背景色 */
  720. border-radius: rpx(4);
  721. }
  722. .message-list::-webkit-scrollbar-thumb {
  723. background: #e2ddfc; /* 滚动条滑块颜色 */
  724. border-radius: rpx(4);
  725. }
  726. .message-list::-webkit-scrollbar-thumb:hover {
  727. background: #e2ddfc; /* 滚动条滑块 hover 状态颜色 */
  728. }
  729. .message-list .user-message {
  730. background-color: #ffffff;
  731. margin-left: auto; // 消息靠右显示
  732. margin-right: 0; // 重置右边距
  733. margin-bottom: rpx(10);
  734. max-width: rpx(400);
  735. font-size: rpx(8);
  736. width: fit-content; // 宽度随文字内容变化
  737. border-radius: rpx(5);
  738. padding: rpx(5);
  739. text-align: left; // 文字左对齐
  740. }
  741. .message-list .ai-message {
  742. background-color: #ffdd55;
  743. margin-left: 0; // 消息靠左显示
  744. margin-right: auto; // 重置右边距
  745. margin-bottom: rpx(10);
  746. width: fit-content;
  747. max-width: rpx(400);
  748. padding: rpx(5);
  749. font-size: rpx(8);
  750. border-radius: rpx(5);
  751. text-align: left; // 文字左对齐
  752. }
  753. .input-section {
  754. display: flex;
  755. padding: rpx(10);
  756. gap: rpx(10);
  757. .speech-btn {
  758. padding: rpx(5) rpx(10);
  759. background: #fff;
  760. border: 1px solid #ffce1b;
  761. border-radius: rpx(5);
  762. cursor: pointer;
  763. display: flex;
  764. align-items: center;
  765. &.recording {
  766. background: #ffeeba;
  767. border-color: #ffc107;
  768. .el-icon {
  769. color: #dc3545;
  770. }
  771. }
  772. .el-icon {
  773. font-size: rpx(8);
  774. color: #666;
  775. }
  776. }
  777. }
  778. .input-section input {
  779. flex: 1;
  780. padding: rpx(5);
  781. font-size: rpx(7);
  782. border: 1px solid #ccc;
  783. border-radius: rpx(5);
  784. }
  785. .input-section button {
  786. padding: rpx(5) rpx(15);
  787. background: linear-gradient(
  788. to bottom,
  789. #fee78a,
  790. #ffce1b
  791. ); /* 设置悬停、聚焦、点击状态下的背景色 */
  792. color: black;
  793. border: none;
  794. font-size: rpx(7);
  795. border-radius: rpx(5);
  796. cursor: pointer;
  797. box-shadow: 0 4px 8px rgba(202, 52, 52, 0.3);
  798. }
  799. </style>