| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595 |
- <!-- eslint-disable vue/multi-word-component-names -->
- <!-- eslint-disable vue/no-v-html -->
- <template>
- <transition name="fade">
- <div v-if="visible" class="dialog-overlay">
- <!-- 左侧折叠区域 -->
- <div class="left-side" :class="{ collapsed: isFold }" id="leftSide">
- <div
- class="addBtn"
- :style="{
- backgroundImage: `url(${isFold ? '/src/assets/images/vent/home/add.svg' : ''})`,
- backgroundColor: isFold ? '' : '#2cb6ff',
- width: isFold ? '20px' : 'auto',
- }"
- @click="addNew"
- >
- <span
- class="btn-text-bg"
- :style="{
- backgroundImage: `url(${!isFold ? '/src/assets/images/vent/home/addB.svg' : ''})`,
- }"
- ></span>
- <span v-if="!isFold" class="btn-text">添加新对话</span>
- </div>
- <div class="divider0"></div>
- <div
- v-if="isFold"
- class="historyBtn"
- :style="{ backgroundImage: `url(${isFold ? '/src/assets/images/vent/home/history.svg' : '/src/assets/images/vent/home/history.svg'})` }"
- @click="addNew"
- ></div>
- <div v-else class="historyBtn1">
- <span
- class="btn-text-bg"
- :style="{
- backgroundImage: `url(${!isFold ? '/src/assets/images/vent/home/history.svg' : ''})`,
- }"
- ></span>
- <span v-if="!isFold" class="btn-text">历史对话</span>
- <a-list style="width: 110px" :split="false" :data-source="store.sessionHistory" :scroll="200" class="custom-list">
- <template #renderItem="{ item }">
- <a-list-item
- :style="{
- padding: '8px 10px 0 8px',
- color: '#5e7081',
- fontSize: '10px',
- position: 'relative', // 新增定位
- }"
- @click="sessionsHistory(item.id)"
- >
- <!-- 新增flex布局容器 -->
- <div style="display: flex; justify-content: space-between; width: 100%">
- <div v-if="editingId !== item.id" class="text-container">
- <span :class="{ 'color-white': item.id === store.currentSessionID }" class="edit-text">{{ item.title || '新会话' }}</span>
- <edit-outlined class="edit-icon" @click="startEditing(item)" />
- </div>
- <!-- 输入框 -->
- <a-input
- size="small"
- v-else
- v-model:value="editText"
- v-focus
- @blur="handleSave(item)"
- @keyup.enter="handleSave(item)"
- class="edit-input"
- />
- </div>
- </a-list-item>
- </template>
- </a-list>
- </div>
- <div
- class="foldBtn"
- :style="{ backgroundImage: `url(${isFold ? '/src/assets/images/vent/home/Fold.svg' : '/src/assets/images/vent/home/unfold.svg'})` }"
- @click="fold"
- ></div>
- </div>
- <!-- 右侧对话框 -->
- <div class="right-side">
- <div class="input-content">
- <!-- 对话区域 -->
- <div ref="dialogRef" class="dialog-area">
- <div v-for="message in store.getMessageHistory" :key="message.id" :class="['message-item', message.type]">
- <!-- 用户提问样式 -->
- <div v-if="message.type === 'user'" class="ask-message">
- <span>{{ message.content }}</span>
- </div>
- <!-- 系统回答样式 -->
- <div v-else class="system-message">
- <div class="answerIcon"></div>
- <div class="answer-message">
- <div v-if="message.contentR1" class="thinking-text" v-html="formatMessage(message.contentR1)"> </div>
- <div class="answer-text" v-html="formatMessage(message.content)"> </div>
- </div>
- </div>
- </div>
- </div>
- <!-- 文本输入区域 -->
- <div v-if="store.streaming" class="thinking-area">
- <span style="color: #fff">思考中···</span>
- <a-spin :spinning="store.streaming" />
- </div>
- <div class="input-area">
- <textarea v-model="inputText" placeholder="请输入你的问题"> </textarea>
- <!-- 底部操作栏 -->
- <div class="action-bar">
- <!-- 左侧深度思考按钮 -->
- <div class="think-btn" :class="{ active: store.deepseekR1Enable }" @click="toggleThinking"> <span>深度思考</span> </div>
- <!-- 右侧操作按钮 -->
- <div class="right-actions">
- <label class="upload-btn">
- <div class="send-file"></div>
- <span class="divider"> | </span>
- <div class="send-img"></div>
- <div class="send-btn" @click="handleSend"></div>
- </label>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </transition>
- </template>
- <script lang="ts" setup>
- import { ref, onMounted } from 'vue';
- import { EditOutlined } from '@ant-design/icons-vue';
- import { useAIChat } from '/@/store/modules/AIChat';
- // 响应式变量声明
- const store = useAIChat(); //获取用户信息
- const dialogRef = ref<HTMLElement | null>(null);
- const isFold = ref(false); // 是否折叠
- const inputText = ref(''); // 输入框内容
- const hasCreated = ref(false); // 标志位,防止重复调用create接口
- const editingId = ref<number | null>(null);
- const editText = ref('');
- const props = defineProps({
- visible: {
- type: Boolean,
- required: true,
- },
- });
- const vFocus = {
- mounted: (el: HTMLElement) => el.querySelector('input')?.focus(),
- };
- const openMenu = () => {
- if (props.visible) {
- hasCreated.value = true;
- }
- };
- const fold = () => {
- isFold.value = !isFold.value;
- if (!isFold.value) {
- store.getSessionHistory();
- }
- };
- const addNew = () => {
- store.createSession();
- };
- //编辑标题
- const startEditing = (item) => {
- editingId.value = item.id;
- editText.value = item.title || '';
- };
- // 保存修改
- const handleSave = (item) => {
- store.changeSessionTitle(editText.value, item.id).then(() => {
- editingId.value = null;
- store.getSessionHistory();
- });
- };
- //启用深度思考
- const toggleThinking = () => {
- store.deepseekR1Enable = !store.deepseekR1Enable;
- };
- //获取消息列表
- async function handleSend() {
- store
- .sendQuestion(inputText.value, () => {
- if (dialogRef.value) {
- dialogRef.value.scrollTop = dialogRef.value.scrollHeight;
- }
- })
- .then(() => {
- inputText.value = '';
- });
- }
- //获取具体会话记录
- function sessionsHistory(id: string) {
- store.getSessionHistoryByID(id);
- }
- //格式化消息
- function formatMessage(text: string) {
- let formatted = text
- // 处理换行
- .replace(/\n\n/g, '<br>')
- .replace(/\n###/g, '<br> ')
- .replace(/###/g, '')
- .replace(/---/g, '')
- // 处理粗体
- .replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
- // 处理斜体
- .replace(/\*(.*?)\*/g, '<em>$1</em>')
- // 处理行内代码
- .replace(/`([^`]+)`/g, '<code>$1</code>');
- return formatted;
- }
- // 初始化按钮定位
- onMounted(() => {
- store.getSessionHistory();
- openMenu();
- });
- </script>
- <style lang="less" scoped>
- @keyframes menuShow {
- 0% {
- width: 0;
- height: 0;
- }
- 100% {
- width: 480px;
- height: 100vh;
- }
- }
- .custom-list {
- height: 360px;
- overflow-y: auto;
- }
- /* 穿透组件作用域 */
- ::v-deep .custom-list {
- scrollbar-width: thin;
- scrollbar-color: #1890ff #f0f0f0;
- &::-webkit-scrollbar {
- width: 4px;
- height: 6px;
- }
- &::-webkit-scrollbar-thumb {
- background: #1890ff;
- border-radius: 4px;
- }
- &::-webkit-scrollbar-track {
- background: #f0f0f0;
- border-radius: 4px;
- }
- }
- ::v-deep .zxm-list-items {
- color: #1890ff;
- }
- ::v-deep .zxm-list-item:hover {
- text-decoration: underline;
- color: #1890ff !important;
- }
- .text-container {
- display: flex;
- align-items: center;
- width: 100%;
- overflow: hidden;
- }
- .text-ellipsis {
- flex: 1;
- }
- .edit-text {
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- min-width: 0;
- }
- .edit-icon {
- flex-shrink: 0;
- cursor: pointer;
- margin-left: auto;
- }
- .edit-input {
- font-size: 10px;
- }
- .trigger-button {
- position: fixed;
- bottom: 10px;
- right: 10px;
- z-index: 1000000;
- .icon {
- width: 60px;
- height: 60px;
- position: relative;
- background-image: url('/@/assets/images/vent/home/wakeBtn.png');
- background-position: center;
- background-size: 100% 100%;
- }
- }
- .dialog-overlay {
- display: flex;
- background-color: #09172c;
- }
- /* 遮罩层淡入淡出 */
- .fade-enter-active,
- .fade-leave-active {
- transition: opacity 0.3s;
- }
- .fade-enter-from,
- .fade-leave-to {
- opacity: 0;
- }
- /* 弹窗缩放动画 */
- .scale-enter-active,
- .scale-leave-active {
- transition: all 0.3s ease;
- }
- .scale-enter-from {
- transform: scale(0.5) translate(-50%, -50%);
- opacity: 0;
- }
- .scale-leave-to {
- transform: scale(1.2) translate(-50%, -50%);
- opacity: 0;
- }
- .left-side {
- background: #0c2842;
- transition: width 0.5s ease; /* 平滑过渡动画 */
- width: 120px; /* 展开时宽度 */
- position: relative; /* 用于按钮定位 */
- }
- .left-side.collapsed {
- width: 40px; /* 折叠时宽度 */
- }
- .addBtn {
- height: 30px;
- position: absolute;
- background-size: 100% 100%;
- background-position: center;
- padding: 2px;
- right: 10px;
- top: 10px;
- left: 10px;
- align-items: center;
- border-radius: 3px;
- cursor: pointer;
- }
- .btn-text-bg {
- width: 14px;
- height: 14px;
- position: absolute;
- background-size: 100% 100%;
- right: 10px;
- top: 9px;
- left: 10px;
- bottom: 10px;
- }
- .btn-text {
- margin-left: 3px;
- font-size: 12px;
- color: #fff;
- white-space: nowrap;
- margin-left: 30px;
- line-height: 26px;
- }
- .historyBtn {
- width: 20px;
- height: 20px;
- position: absolute;
- background-size: 100% 100%;
- background-position: center;
- padding: 2px;
- right: 10px;
- top: 100px;
- }
- .historyBtn1 {
- width: 20px;
- height: 20px;
- position: absolute;
- background-size: 100% 100%;
- background-position: center;
- left: 3px;
- top: 80px;
- }
- .divider0 {
- border-bottom: 1px solid #1074c1;
- width: auto;
- margin: 0 10px;
- height: 13%;
- display: block;
- background: transparent;
- }
- .foldBtn {
- width: 20px;
- height: 20px;
- position: absolute;
- background-size: 100% 100%;
- background-position: center;
- padding: 2px;
- right: 10px;
- bottom: 10px;
- cursor: pointer;
- }
- .right-side {
- flex: 1; /* 占据剩余空间 */
- background: #09172c;
- }
- .input-content {
- display: flex;
- flex-direction: column;
- justify-content: flex-end; /* 内容底部对齐 */
- height: 100%;
- padding: 20px; /* 统一内边距 */
- }
- .ask-message {
- align-self: flex-end;
- float: right;
- max-width: 70%;
- padding: 10px;
- margin: 10px;
- border-radius: 5px;
- color: #fff;
- background: #0c2842;
- align-self: flex-end; /* 右侧对齐:ml-citation{ref="2" data="citationList"} */
- }
- .answer {
- display: flex;
- flex-direction: row;
- }
- .answerIcon {
- flex-shrink: 0;
- margin-top: 10px;
- width: 35px;
- height: 35px;
- background-image: url('/@/assets/images/vent/home/answerIcon.svg');
- background-size: 100% 100%;
- }
- .answer-message {
- float: left;
- padding: 10px;
- margin: 10px;
- border-radius: 5px;
- background: #0c2842;
- }
- .thinking-text {
- color: gray;
- font-size: 12px;
- }
- .answer-text {
- color: #fff;
- }
- /** 系统返回信息**/
- .system-message {
- display: flex;
- flex-direction: row;
- align-self: flex-start;
- width: 100%;
- padding: 12px;
- display: flex;
- }
- .answerIcon {
- margin-top: 10px;
- width: 35px;
- height: 35px;
- background-image: url('/@/assets/images/vent/home/answerIcon.svg');
- background-size: 100% 100%;
- }
- .think-area {
- color: #7979799f;
- }
- .answer-area {
- color: #fff;
- }
- .dialog-area {
- flex: 1; /* 占据剩余空间 */
- gap: 50px; /* 消息块间隔统一控制 */
- overflow-y: auto; /* 垂直滚动条 */
- margin-bottom: 10px;
- }
- .loading-wrapper,
- .content-wrapper {
- min-height: 40px;
- }
- .message-item.user {
- margin-bottom: 50px;
- }
- .input-area {
- background-color: #043256 !important;
- display: flex;
- flex-direction: column;
- gap: 10px;
- }
- textarea {
- background-color: #043256 !important;
- width: 100%;
- height: 40px;
- border: none;
- resize: none;
- outline: none;
- overflow: hidden;
- padding: 10px; /* 统一内边距 */
- color: #fff;
- }
- .action-bar {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 8px 16px;
- }
- .think-btn {
- border: 1px solid #ccc;
- width: 120px;
- height: 20px;
- line-height: 20px;
- text-align: center;
- border-radius: 50px;
- cursor: pointer;
- background: white;
- transition: background 0.3s;
- }
- .think-btn.active {
- background: #1890ff;
- color: white;
- border-color: #1890ff;
- }
- .right-actions {
- display: flex;
- align-items: center;
- gap: 8px;
- }
- .upload-btn {
- display: flex;
- align-items: center;
- gap: 8px;
- }
- .upload-btn {
- float: right;
- display: flex;
- cursor: pointer;
- padding: 6px 12px;
- }
- .divider {
- color: #ccc;
- font-weight: 300;
- margin: 0 10px;
- }
- .send-file {
- width: 20px;
- height: 20px;
- background-image: url('/@/assets/images/vent/home/sendFile.svg');
- background-size: 100% 100%;
- border-radius: 4px;
- cursor: pointer;
- }
- .send-img {
- width: 20px;
- height: 20px;
- background-image: url('/@/assets/images/vent/home/sendImg.svg');
- background-size: 100% 100%;
- border-radius: 4px;
- cursor: pointer;
- }
- .send-btn {
- width: 20px;
- height: 20px;
- margin-left: 10px;
- margin-right: 10px;
- background-color: #1074c1;
- background-image: url('/@/assets/images/vent/home/send.svg');
- background-position: center;
- background-size: 100% 100%;
- border-radius: 2px;
- cursor: pointer;
- }
- </style>
|