{{item.sendUserInfo?.user.userName}}
-{{ item.sendUserInfo?.user.userName }}
+`; codeCopyDic.push({id: codeIndex,code:code}); - console.log(codeCopyDic.length); + // console.log(codeCopyDic.length); return html; // } catch (error) { diff --git a/Yi.Bbs.Vue3/src/components/MavonEdit.vue b/Yi.Bbs.Vue3/src/components/MavonEdit.vue index 819f3cd0..fee13136 100644 --- a/Yi.Bbs.Vue3/src/components/MavonEdit.vue +++ b/Yi.Bbs.Vue3/src/components/MavonEdit.vue @@ -118,14 +118,14 @@ const imgAdd = async (pos, $file) => { formdata.append('file', $file); const response = await upload(formdata) const url = `${import.meta.env.VITE_APP_BASEAPI}/file/${response.data[0].id}/true`; - console.log(url) + //console.log(url) md.value.$img2Url(pos, url); } //选择表情包 const onSelectEmoji=(emoji)=>{ - console.log(emoji.i,"emoji"); + //console.log(emoji.i,"emoji"); text.value+=emoji.i } diff --git a/Yi.Bbs.Vue3/src/hubs/chatHub.js b/Yi.Bbs.Vue3/src/hubs/chatHub.js index 2441973f..c2aaa819 100644 --- a/Yi.Bbs.Vue3/src/hubs/chatHub.js +++ b/Yi.Bbs.Vue3/src/hubs/chatHub.js @@ -13,17 +13,27 @@ const receiveMsg = (connection) => { }); //接受其他用户消息 connection.on("receiveMsg", (type, content) => { - chatStore.addMsg(content); + const letChatStore = useChatStore(); + //如果是ai消息,还要进行流式显示 + // alert(type) + if (type == 3) { + letChatStore.addOrUpdateMsg(content); + } + else { + letChatStore.addMsg(content); + } + + }); //用户状态-正在输入中,无 connection.on("userStatus", (type) => { }); }; -export function start(){ +export function start() { signalR.start(`chat`, receiveMsg); } -export function close(){ +export function close() { signalR.SR.stop(); } diff --git a/Yi.Bbs.Vue3/src/layout/AppHeader.vue b/Yi.Bbs.Vue3/src/layout/AppHeader.vue index a063c692..b9d9d06b 100644 --- a/Yi.Bbs.Vue3/src/layout/AppHeader.vue +++ b/Yi.Bbs.Vue3/src/layout/AppHeader.vue @@ -155,7 +155,7 @@ const fetchNoticeData = async () => { const handleSelect = (key, keyPath) => { - console.log(key, keyPath); + //console.log(key, keyPath); }; const logout = async () => { ElMessageBox.confirm(`确定登出系统吗?`, "警告", { diff --git a/Yi.Bbs.Vue3/src/stores/chat.js b/Yi.Bbs.Vue3/src/stores/chat.js index 803a3dbf..c7d88325 100644 --- a/Yi.Bbs.Vue3/src/stores/chat.js +++ b/Yi.Bbs.Vue3/src/stores/chat.js @@ -7,9 +7,23 @@ const chatStore = defineStore("chat", { getters: { allMsgContext: (state) => state.msgList.filter(x=>x.messageType=="All"), personalMsgContext: (state) => state.msgList.filter(x=>x.messageType=="Personal"), + aiMsgContext: (state) => state.msgList.filter(x=>x.messageType=="Ai") }, actions: { + addOrUpdateMsg(msg){ + var currentMsg= this.msgList.filter(x => x.id == msg.id)[0]; + //当前没有包含,如果有相同的上下文id,只需要改变content即可 + if(currentMsg==undefined) + { + this.addMsg(msg); + } + else + { + currentMsg.content+=msg.content; + } + + }, setMsgList(value) { this.msgList = value; }, diff --git a/Yi.Bbs.Vue3/src/utils/icon.js b/Yi.Bbs.Vue3/src/utils/icon.js index 3a1fcaff..4d8bd29c 100644 --- a/Yi.Bbs.Vue3/src/utils/icon.js +++ b/Yi.Bbs.Vue3/src/utils/icon.js @@ -2,10 +2,14 @@ export const getUrl = (fileId) => { if (fileId == null || fileId == undefined) { return "/acquiesce.png" } - else { - return getEnvUrl(fileId) + if (fileId.startsWith(`${import.meta.env.VITE_APP_BASEAPI}`)) { + return fileId; + } + + return getEnvUrl(fileId) + }; const getEnvUrl = (str) => { diff --git a/Yi.Bbs.Vue3/src/views/chathub/Index.vue b/Yi.Bbs.Vue3/src/views/chathub/Index.vue index 71db7d70..14dc07ab 100644 --- a/Yi.Bbs.Vue3/src/views/chathub/Index.vue +++ b/Yi.Bbs.Vue3/src/views/chathub/Index.vue @@ -3,7 +3,7 @@ import { onMounted, ref, computed, onUnmounted } from 'vue'; import { storeToRefs } from 'pinia' import useAuths from '@/hooks/useAuths.js'; import { getList as getChatUserList } from '@/apis/chatUserApi' -import { sendPersonalMessage, sendGroupMessage, getAccountList as getChatAccountMessageList } from '@/apis/chatMessageApi' +import { sendPersonalMessage, sendGroupMessage, getAccountList as getChatAccountMessageList, sendAiChat } from '@/apis/chatMessageApi' import useChatStore from "@/stores/chat"; import useUserStore from "@/stores/user"; const { isLogin } = useAuths(); @@ -19,17 +19,22 @@ const userStore = useUserStore(); //发送消息是否为空 const msgIsNullShow = ref(false) //当前选择用户 -const currentSelectUser = ref(null); +const currentSelectUser = ref('all'); //当前输入框的值 const currentInputValue = ref(""); //临时存储的输入框,根据用户id及组name、all组为key,data为value -const inputListDataStore = ref([{ key: "all", value: "" }]); +const inputListDataStore = ref([{ key: "all", value: "" }, { key: "ai", value: "" }]); +//AI聊天临时存储 +const sendAiChatContext = ref([]); //当前聊天框显示的消息 const currentMsgContext = computed(() => { if (selectIsAll()) { return chatStore.allMsgContext; } + else if (selectIsAi) { + return chatStore.aiMsgContext; + } else { return chatStore.personalMsgContext.filter(x => { //两个条件 @@ -40,11 +45,31 @@ const currentMsgContext = computed(() => { }); } }); +const getChatUrl=(url,position)=> +{ + if(position=="left" && selectIsAi()) + { + return "/openAi.png" + } + return getUrl(url); + +} //当前聊天框显示的名称 const currentHeaderName = computed(() => { - return currentSelectUser.value == null ? "官方学习交流群" : currentSelectUser.value.userName; + if (selectIsAll()) { + return "官方学习交流群"; + + } + else if + (selectIsAi()) { + return "Ai-ChatGpt(你的私人ai小助手)" + } + else { + currentSelectUser.value.userName; + } + }); const currentUserItem = computed(() => { return userList.value.filter(x => x.userId != useUserStore().id) @@ -76,8 +101,13 @@ onUnmounted(() => { /*-----方法-----*/ //当前选择的是否为全部 const selectIsAll = () => { - return currentSelectUser.value == null; + return currentSelectUser.value == 'all'; }; +//当前选择的是否为Ai +const selectIsAi = () => { + return currentSelectUser.value == 'ai'; +}; + //输入框的值被更改 const changeInputValue = (inputValue) => { @@ -85,7 +115,10 @@ const changeInputValue = (inputValue) => { let index = -1; let findKey = currentSelectUser.value?.userId if (selectIsAll()) { - findKey = 'all' + findKey = 'all'; + } + else if (selectIsAi()) { + findKey = 'ai'; } index = inputListDataStore.value.findIndex(obj => obj.key == findKey); inputListDataStore.value[index].value = currentInputValue.value; @@ -99,7 +132,12 @@ const getCurrentInputValue = () => { if (selectIsAll()) { return inputListDataStore.value.filter(x => x.key == "all")[0].value; - } else { + } + else if (selectIsAi()) { + return inputListDataStore.value.filter(x => x.key == "ai")[0].value; + } + + else { //如果不存在初始存储值 if (!inputListDataStore.value.some(x => x.key == currentSelectUser.value.userId)) { inputListDataStore.value.push({ key: currentSelectUser.value.userId, value: "" }); @@ -110,9 +148,12 @@ const getCurrentInputValue = () => { }; //点击用户列表, -const onclickUserItem = (userInfo, isAllItem) => { - if (isAllItem) { - currentSelectUser.value = null; +const onclickUserItem = (userInfo, itemType) => { + if (itemType == "all") { + currentSelectUser.value = 'all'; + } + else if (itemType == "ai") { + currentSelectUser.value = 'ai'; } else { currentSelectUser.value = userInfo; @@ -136,6 +177,17 @@ const onclickSendMsg = () => { if (selectIsAll()) { onclickSendGroupMsg("all", currentInputValue.value); + } + else if (selectIsAi()) { + //ai消息需要将上下文存储 + sendAiChatContext.value.push({ answererType: 'User', message: currentInputValue.value, number: sendAiChatContext.value.length }) + + //离线前端存储 + chatStore.addMsg({messageType:"Ai",content:currentInputValue.value,sendUserId:userStore.id,sendUserInfo:{user:{icon:userStore.icon}}}) + //发送ai消息 + sendAiChat(sendAiChatContext.value); + + } else { onclickSendPersonalMsg(currentSelectUser.value.userId, currentInputValue.value); @@ -184,10 +236,15 @@ const onclickSendGroupMsg = (groupName, msg) => { //获取当前最后一条信息 -const getLastMessage = ((receiveId, isAll) => { - if (isAll) { - return chatStore.allMsgContext[chatStore.allMsgContext.length - 1]?.content; - } else { +const getLastMessage = ((receiveId, itemType) => { + if (itemType == "all") { + return chatStore.allMsgContext[chatStore.allMsgContext.length - 1]?.content.substring(0, 15); + } + else if (itemType == "ai") { + return chatStore.aiMsgContext[chatStore.aiMsgContext.length - 1]?.content.substring(0, 15); + } + + else { const messageContext = chatStore.personalMsgContext.filter(x => { //两个条件 //接收用户者id为对面id(我发给他) @@ -195,7 +252,7 @@ const getLastMessage = ((receiveId, isAll) => { return (x.receiveId == receiveId && x.sendUserId == userStore.id) || (x.sendUserId == receiveId && x.receiveId == userStore.id); }); - return messageContext[messageContext.length - 1]?.content; + return messageContext[messageContext.length - 1]?.content.substring(0, 15); } }) @@ -203,16 +260,17 @@ const getLastMessage = ((receiveId, isAll) => {${language}复制代码${preCode}
当前版本:1.2.0
+当前版本:1.3.0
tip:官方学习交流群每次发送消息消耗 1 钱钱
tip:点击聊天窗口右上角“X”可退出
tip:多人同时在聊天室时,左侧可显示其他成员
+tip:即将接入OpenAi ChatGpt Ai聊天
官方学习交流群
-{{ getLastMessage(null, true) }}
+{{ getLastMessage(null, 'all') }}
+
+ Ai-ChatGpt
+{{ getLastMessage(null, 'ai') }}
{{ item.userName }}
-{{ getLastMessage(item.userId, false) }}
+{{ getLastMessage(item.userId, 'user') }}
{{item.sendUserInfo?.user.userName}}
-{{ item.sendUserInfo?.user.userName }}
+