Browse Source

fix:打包时类型错误

master
qiutianhong 7 months ago
parent
commit
4d728be940
  1. 2
      frontend/components.d.ts
  2. 2
      frontend/src/components/chat/Chat.vue
  3. 10
      frontend/src/components/chat/ChatBox.vue
  4. 2
      frontend/src/components/chat/ChatMsgList.vue
  5. 191
      frontend/src/stores/chat.ts
  6. 4
      frontend/src/stores/db.ts
  7. 6
      frontend/src/stores/upgrade.ts
  8. 5
      frontend/src/system/index.ts

2
frontend/components.d.ts

@ -57,8 +57,6 @@ declare module 'vue' {
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem'] ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
ElCheckbox: typeof import('element-plus/es')['ElCheckbox'] ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
ElCol: typeof import('element-plus/es')['ElCol'] ElCol: typeof import('element-plus/es')['ElCol']
ElCollapse: typeof import('element-plus/es')['ElCollapse']
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
ElColorPicker: typeof import('element-plus/es')['ElColorPicker'] ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
ElContainer: typeof import('element-plus/es')['ElContainer'] ElContainer: typeof import('element-plus/es')['ElContainer']
ElDialog: typeof import('element-plus/es')['ElDialog'] ElDialog: typeof import('element-plus/es')['ElDialog']

2
frontend/src/components/chat/Chat.vue

@ -10,7 +10,7 @@
// el-transfer // el-transfer
const generateData = () => { const generateData = () => {
return store.allUserList.map((user) => ({ return store.allUserList.map((user: any) => ({
key: user.id, key: user.id,
label: user.nickname, label: user.nickname,
avatar: user.avatar, // avatar: user.avatar, //

10
frontend/src/components/chat/ChatBox.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { useChatStore } from "@/stores/chat"; import { useChatStore } from "@/stores/chat";
const store = useChatStore(); const store:any = useChatStore();
</script> </script>
<template> <template>
@ -11,11 +11,11 @@
<!--聊天顶部区--> <!--聊天顶部区-->
<el-header class="chat-header"> <el-header class="chat-header">
<div class="header-title"> <div class="header-title">
<span v-if="store.targetUserInfo.nickname">{{ <span v-if="store.targetUserInfo.displayName">{{
store.targetUserInfo.nickname store.targetUserInfo.displayName
}}</span> }}</span>
<span v-else-if="store.targetGroupInfo.name">{{ <span v-else-if="store.targetGroupInfo.displayName">{{
store.targetGroupInfo.name store.targetGroupInfo.displayName
}}</span> }}</span>
</div> </div>
</el-header> </el-header>

2
frontend/src/components/chat/ChatMsgList.vue

@ -19,7 +19,7 @@
<el-col :span="18" class="preview"> <el-col :span="18" class="preview">
<el-row class="preview-content"> <el-row class="preview-content">
<el-col :span="18" class="preview-left"> <el-col :span="18" class="preview-left">
<div class="previewName">{{ item.nickname || item.name }}</div> <div class="previewName">{{ item.displayName }}</div>
<div class="previewChat"> <div class="previewChat">
<span>{{ item.previewMessage }}</span> <span>{{ item.previewMessage }}</span>

191
frontend/src/stores/chat.ts

@ -1,5 +1,6 @@
import emojiList from "@/assets/emoji.json"; import emojiList from "@/assets/emoji.json";
import { fetchGet, fetchPost, getSystemConfig } from '@/system/config'; import { fetchGet, fetchPost, getSystemConfig } from '@/system/config';
import { notifyError } from "@/util/msg";
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { db } from "./db"; import { db } from "./db";
@ -11,12 +12,12 @@ export const useChatStore = defineStore('chatStore', () => {
interface ChatMessage { interface ChatMessage {
id?: any; id?: any;
type: any; // 消息类型,0表示文字消息,1表示图片消息,2表示文件消息 type: any; // 消息类型,0表示文字消息,1表示图片消息,2表示文件消息
time: any; // 消息发送时间 time?: Date | null;
message: any; // 消息内容 message: any; // 消息内容
userId: any; // 发送者id userId: any; // 发送者id
toUserId: any; // 接收者id toUserId?: any; // 接收者id
// receiver: any; // 消息接收者 to_groupid?: any;
// to_groupid: any; // 群组id messageType?: string; // 新增消息类型属性
userInfo: { // 发送者信息 userInfo: { // 发送者信息
} }
}; };
@ -59,11 +60,11 @@ export const useChatStore = defineStore('chatStore', () => {
// 聊天消息记录列表 // 聊天消息记录列表
const chatHistory: any = ref([]); const chatHistory: any = ref([]);
// 群组数据 // 群组l列表
const groupList: any = ref([ const groupList: any = ref([
]); ]);
const targetGroupInfo = ref({}) const targetGroupInfo: any = ref({})
const activeNames = ref([]); const activeNames = ref([]);
const userInfo: any = ref({}); const userInfo: any = ref({});
const showChooseFile = ref(false); const showChooseFile = ref(false);
@ -106,6 +107,7 @@ export const useChatStore = defineStore('chatStore', () => {
} }
userInfo.value = config.userInfo; userInfo.value = config.userInfo;
getUserList() getUserList()
getGroupList()
getDepartmentList() getDepartmentList()
initUserList() initUserList()
initChatList() initChatList()
@ -126,11 +128,12 @@ export const useChatStore = defineStore('chatStore', () => {
// 初始化用户列表 // 初始化用户列表
const initChatList = async () => { const initChatList = async () => {
const userchatList = await db.getAll('conversationList'); const userchatList = await db.getAll('conversationList');
console.log(userchatList)
// 获取群数据 // 获取群数据
const groupChatListawait = await db.getAll("groupChatList") // const groupChatListawait = await db.getAll("groupChatList")
// 合并两个数组 // 合并两个数组
chatList.value = [...userchatList, ...groupChatListawait]; chatList.value = [...userchatList, ...groupList.value];
}; };
const setCurrentNavId = (id: number) => { const setCurrentNavId = (id: number) => {
@ -138,26 +141,61 @@ export const useChatStore = defineStore('chatStore', () => {
}; };
const sendMessage = async () => { const sendMessage = async () => {
const chatSendUrl = config.userInfo.url + '/chat/send'; let messageHistory: ChatMessage;
// 封装成消息历史记录
console.log(chatSendUrl); // 判断是群聊发送还是单聊发送
const messageHistory: ChatMessage = { if (targetGroupInfo.value && Object.keys(targetGroupInfo.value).length) {
type: 'user', console.log('群聊发送');
time: null, // 群聊发送消息的逻辑
message: message.value, messageHistory = {
userId: userInfo.value.id, type: 'group',
toUserId: targetChatId.value, messageType: 'text', // 明确指定消息类型
userInfo: { time: null,
}, message: message.value,
}; userId: userInfo.value.id,
to_groupid: targetGroupInfo.value?.group_id, // 使用可选链操作符
userInfo: {
// 添加用户信息
},
};
} else if (targetUserInfo.value && Object.keys(targetUserInfo.value).length > 0) {
console.log('单聊发送');
// 单聊发送消息
// 封装成消息历史记录
messageHistory = {
type: 'user',
messageType: 'text', // 明确指定消息类型
time: null,
message: message.value,
userId: userInfo.value.id,
toUserId: targetChatId.value,
userInfo: {
// 添加用户信息
},
};
} else {
notifyError('请先选择聊天对象');
return;
}
console.log(messageHistory); if (!messageHistory) {
// 这是一个额外的检查,确保 messageHistory 已经被赋值
console.log('消息发送失败')
return;
}
// 创建没有 `id` 属性的副本 // 创建没有 `id` 属性的副本
const { id, ...messageHistoryWithoutId } = messageHistory; const { id, ...messageHistoryWithoutId } = messageHistory;
console.log(messageHistoryWithoutId); console.log(messageHistoryWithoutId);
// 消息发送请求
sendRequest(messageHistoryWithoutId)
}
const sendRequest = async (messageHistory: ChatMessage) => {
// 发送消息 // 发送消息
const res = await fetchPost(chatSendUrl, JSON.stringify(messageHistoryWithoutId)); const res = await fetchPost(config.userInfo.url + '/chat/send', JSON.stringify(messageHistory));
if (res.ok) { if (res.ok) {
// 本地存储一份聊天记录 // 本地存储一份聊天记录
await db.addOne('chatRecord', messageHistory); await db.addOne('chatRecord', messageHistory);
@ -166,7 +204,8 @@ export const useChatStore = defineStore('chatStore', () => {
chatHistory.value.push(messageHistory); chatHistory.value.push(messageHistory);
// 更新 chatList 和 conversationList // 更新 chatList 和 conversationList
// await changeChatListAndGetChatHistory(userInfo.value.userId); await changeChatListAndGetChatHistory(userInfo.value.userId);
// 清空输入框 // 清空输入框
clearMessage(); clearMessage();
@ -175,7 +214,7 @@ export const useChatStore = defineStore('chatStore', () => {
await setScrollToBottom(); await setScrollToBottom();
return; return;
} }
}; }
// 更新聊天和聊天记录 // 更新聊天和聊天记录
const changeChatListAndChatHistory = async (data: any) => { const changeChatListAndChatHistory = async (data: any) => {
@ -189,6 +228,7 @@ export const useChatStore = defineStore('chatStore', () => {
avatar: data.userInfo.avatar || "logo.png", // 如果没有头像使用默认图片 avatar: data.userInfo.avatar || "logo.png", // 如果没有头像使用默认图片
toUserId: data.toUserId, toUserId: data.toUserId,
messages: data.message, messages: data.message,
displayName: data.userInfo.nickname,
nickname: data.userInfo.nickname, nickname: data.userInfo.nickname,
time: data.time || Date.now(), time: data.time || Date.now(),
previewMessage: data.message, previewMessage: data.message,
@ -207,6 +247,7 @@ export const useChatStore = defineStore('chatStore', () => {
await db.update('conversationList', conversation[0].id, { await db.update('conversationList', conversation[0].id, {
avatar: data.userInfo.avatar || "logo.png", avatar: data.userInfo.avatar || "logo.png",
nickname: data.userInfo.nickname, nickname: data.userInfo.nickname,
displayName: data.userInfo.nickname,
previewMessage: data.message, previewMessage: data.message,
time: data.time || Date.now(), time: data.time || Date.now(),
previewTimeFormat: formatTime(Date.now()) previewTimeFormat: formatTime(Date.now())
@ -234,7 +275,7 @@ export const useChatStore = defineStore('chatStore', () => {
// 如果会话存在于 chatList,则获取聊天记录并更新 chatHistory // 如果会话存在于 chatList,则获取聊天记录并更新 chatHistory
if (chatIdSet.has(chatId)) { if (chatIdSet.has(chatId)) {
console.log("存在"); console.log("存在");
chatHistory.value = await getHistory(chatId, userInfo.value.id); chatHistory.value = await getHistory(chatId, userInfo.value.id, "user");
return; return;
} }
@ -252,6 +293,7 @@ export const useChatStore = defineStore('chatStore', () => {
chatId: user.id, chatId: user.id,
nickname: user.nickname, nickname: user.nickname,
avatar: user.avatar, avatar: user.avatar,
displayName: user.nickname,
previewTimeFormat: formatTime(Date.now()), previewTimeFormat: formatTime(Date.now()),
previewMessage: "", previewMessage: "",
}; };
@ -262,6 +304,7 @@ export const useChatStore = defineStore('chatStore', () => {
userId: user.id, userId: user.id,
type: "user", type: "user",
chatId: user.id, chatId: user.id,
displayName: user.nickname,
username: user.username, username: user.username,
nickname: user.nickname, nickname: user.nickname,
avatar: user.avatar, avatar: user.avatar,
@ -327,13 +370,13 @@ export const useChatStore = defineStore('chatStore', () => {
// 构建数据入库 // 构建数据入库
// 群数据 // 群数据
const group_id = groupData.data.group_id const group_id = groupData.data.group_id
const gourpData = { // const gourpData = {
name: departmentName.value, // name: departmentName.value,
avatar: "./logo.png", // avatar: "./logo.png",
groupId: group_id, // groupId: group_id,
creator: currUserId, // creator: currUserId,
createdAt: new Date() // createdAt: new Date()
} // }
// 群成员数据 // 群成员数据
const groupMembers = { const groupMembers = {
@ -341,8 +384,8 @@ export const useChatStore = defineStore('chatStore', () => {
groupId: group_id, groupId: group_id,
createdAt: new Date() createdAt: new Date()
} }
// 添加数据库 // // 添加数据库
db.addOne("group", gourpData) // db.addOne("group", gourpData)
db.addOne("groupMembers", groupMembers) db.addOne("groupMembers", groupMembers)
// 添加到会话列表中 // 添加到会话列表中
@ -353,11 +396,13 @@ export const useChatStore = defineStore('chatStore', () => {
messages: "", messages: "",
chatId: group_id, chatId: group_id,
type: "group", type: "group",
displayName: departmentName.value,
previewMessage: "", previewMessage: "",
previewTimeFormat: formatTime(Date.now()), previewTimeFormat: formatTime(Date.now()),
createdAt: new Date() createdAt: new Date()
} }
db.addOne("groupChatList", groupConversation) // todo 添加群聊会话记录
// db.addOne("groupChatList", groupConversation)
chatList.value.push(groupConversation) chatList.value.push(groupConversation)
// 关闭对话弹窗 // 关闭对话弹窗
setGroupChatInvitedDialogVisible(false) setGroupChatInvitedDialogVisible(false)
@ -420,6 +465,31 @@ export const useChatStore = defineStore('chatStore', () => {
// console.warn('scrollbarRef is not defined.'); // console.warn('scrollbarRef is not defined.');
// } // }
}; };
// 获取群列表信息
const getGroupList = async () => {
console.log('获取群列表')
const res = await fetchGet(userInfo.value.url + '/chat/group/list');
if (!res.ok) {
console.warn("Error fetching group list:", res);
return false;
}
const list = await res.json()
console.log(list.data.groups)
// 封装 list.data.groups
const formattedGroups = list.data.groups.map((group: any) => ({
group_id: group.id,
name: group.name,
avatar: group.avatar || '', // 使用默认头像
messages: "",
displayName: group.name,
chatId: group.id,
type: 'group',
previewMessage: "",
previewTimeFormat: formatTime(Date.now()),
createdAt: group.createdAt
}));
groupList.value = formattedGroups;
};
const handleUserData = async (data: any[]) => { const handleUserData = async (data: any[]) => {
@ -445,8 +515,6 @@ export const useChatStore = defineStore('chatStore', () => {
} }
}; };
const setUserList = async (data: any[]) => { const setUserList = async (data: any[]) => {
if (data.length < 1) { if (data.length < 1) {
return; return;
@ -502,7 +570,6 @@ export const useChatStore = defineStore('chatStore', () => {
// 刷新用户列表 // 刷新用户列表
await getUserList(); await getUserList();
}; };
const getUserList = async () => { const getUserList = async () => {
@ -585,6 +652,7 @@ export const useChatStore = defineStore('chatStore', () => {
const changeChatList = async (chatId: number, type: string) => { const changeChatList = async (chatId: number, type: string) => {
// 设置 targetUserId // 设置 targetUserId
// 根据type去判断 // 根据type去判断
// user会话,查发送和接收发方id // user会话,查发送和接收发方id
@ -597,6 +665,7 @@ export const useChatStore = defineStore('chatStore', () => {
// 设置目标用户的信息 // 设置目标用户的信息
await setTargetUserInfo(chatId); await setTargetUserInfo(chatId);
} else if (type === 'group') { } else if (type === 'group') {
console.log('group')
// 获取当前用户和目标用户的聊天记录 // 获取当前用户和目标用户的聊天记录
const history = await getHistory(userInfo.value.id, chatId, type) const history = await getHistory(userInfo.value.id, chatId, type)
chatHistory.value = history; chatHistory.value = history;
@ -623,19 +692,56 @@ export const useChatStore = defineStore('chatStore', () => {
// 设置目标用户的信息 // 设置目标用户的信息
const setTargetUserInfo = async (id: number) => { const setTargetUserInfo = async (id: number) => {
targetUserInfo.value = await db.getOne('workbenchusers', id); console.log(id)
const userInfoArray = await db.getByField('conversationList', "userId", id);
targetUserInfo.value = userInfoArray.length > 0 ? userInfoArray[0] : {};
targetGroupInfo.value = {}
}; };
// 设置目标群信息 // 设置目标群信息
const setTargetGrouprInfo = async (id: number) => { const setTargetGrouprInfo = async (id: number) => {
const info = await db.getByField('group', "groupId", id); const info = groupList.value.find((group: any) => group.group_id === id);
targetGroupInfo.value = info[0] targetGroupInfo.value = info || {};
targetUserInfo.value = {}
}; };
const handleContextMenu = async () => { const handleContextMenu = async () => {
contextMenu.value.visible = false; contextMenu.value.visible = false;
}; };
const groupChatMessage = async (data: any) => {
console.log(data)
// 创建消息记录
const messageRecord = {
userId: data.userId,
groupId: data.to_groupid,
messageType: data.messageType,
message: data.message,
time: data.time,
type: data.type,
createdAt: Date.now(),
userInfo: {
id: data.userId,
nickname: data.userInfo.nickname || "未知用户",
avatar: data.userInfo.avatar || "logo.png", // 使用默认头像。
email: data.userInfo.email,
phone: data.userInfo.phone,
remark: data.userInfo.remark,
role_id: data.userInfo.role_id,
}
};
console.log(messageRecord)
// 将消息记录添加到数据库
await db.addOne('groupChatRecord', messageRecord);
// // 更新 chatHistory
// chatHistory.value.push(messageRecord);
// // 更新 chatList 和 conversationList表
// changeChatListAndChatHistory(data);
};
const showContextMenu = (event: any, id: number) => { const showContextMenu = (event: any, id: number) => {
contextMenu.value.visible = true; contextMenu.value.visible = true;
@ -684,6 +790,7 @@ export const useChatStore = defineStore('chatStore', () => {
userChatMessage, userChatMessage,
initOnlineUserList, initOnlineUserList,
getDepartmentList, getDepartmentList,
getAllUser getAllUser,
groupChatMessage
}; };
}); });

4
frontend/src/stores/db.ts

@ -7,13 +7,13 @@ dbInit.version(1).stores({
// 用户列表 // 用户列表
workbenchusers: '++id,ip,userName,avatar,mobile,phone,nickName,isOnline,updatedAt,createdAt', workbenchusers: '++id,ip,userName,avatar,mobile,phone,nickName,isOnline,updatedAt,createdAt',
// 聊天记录 // 聊天记录
chatRecord: '++id,toUserId,messages,time,createdAt,userInfo', chatRecord: '++id,toUserId,messages,messageType,time,createdAt,userInfo',
// 会话列表 // 会话列表
conversationList: '++id,avatar,chatId,username,nickname,userId,toUserId,previewMessage,messages,time,createdAt', conversationList: '++id,avatar,chatId,username,nickname,userId,toUserId,previewMessage,messages,time,createdAt',
chatuser: '++id,ip,hostname,userName,avatar,mobile,nickName,isOnline,updatedAt,createdAt', chatuser: '++id,ip,hostname,userName,avatar,mobile,nickName,isOnline,updatedAt,createdAt',
// chatmsg: '++id,toUserId,targetIp,senderInfo,reciperInfo,previewMessage,content,type,status,isRead,isMe,readAt,createdAt', // chatmsg: '++id,toUserId,targetIp,senderInfo,reciperInfo,previewMessage,content,type,status,isRead,isMe,readAt,createdAt',
chatmessage: '++id,userId,toUserId,senderInfo,isMe,isRead,content,type,readAt,createdAt', chatmessage: '++id,userId,toUserId,senderInfo,isMe,isRead,content,type,readAt,createdAt',
groupChatRecord: '++id,userId,groupId,senderInfo,message,time,type,createdAt', groupChatRecord: '++id,userId,groupId,messageType,userInfo,message,time,type,createdAt',
// 群组表 // 群组表
group: '++id,avatar,name,groupId,creator,createdAt', group: '++id,avatar,name,groupId,creator,createdAt',
// 群成员表 // 群成员表

6
frontend/src/stores/upgrade.ts

@ -94,9 +94,12 @@ export const useUpgradeStore = defineStore('upgradeStore', () => {
chatChatStore.handleUserData(message.data) chatChatStore.handleUserData(message.data)
break; break;
case 'user': case 'user':
console.log(message.data)
chatChatStore.userChatMessage(message.data) chatChatStore.userChatMessage(message.data)
break break
case 'group':
console.log(message.data);
chatChatStore.groupChatMessage(message.data);
break;
default: default:
console.warn('Unknown message type:', message.type); console.warn('Unknown message type:', message.type);
} }
@ -144,6 +147,7 @@ export const useUpgradeStore = defineStore('upgradeStore', () => {
}); });
return list return list
} }
async function update() { async function update() {
const config = getSystemConfig(); const config = getSystemConfig();
const upUrl = `${config.apiUrl}/system/update?url=${updateUrl.value}` const upUrl = `${config.apiUrl}/system/update?url=${updateUrl.value}`

5
frontend/src/system/index.ts

@ -118,7 +118,6 @@ export class System {
// const messageStore = useMessageStore(); // const messageStore = useMessageStore();
// messageStore.systemMessage() // messageStore.systemMessage()
upgradeStore.onlineMessage(); upgradeStore.onlineMessage();
}, 3000); }, 3000);
} }
setTimeout(() => { setTimeout(() => {
@ -455,7 +454,7 @@ export class System {
filePwd: '' filePwd: ''
} }
//判断文件是否需要输入密码 //判断文件是否需要输入密码
if(fileStat.isPwd && path.indexOf('.exe') === -1) { if (fileStat.isPwd && path.indexOf('.exe') === -1) {
const temp = await Dialog.showInputBox() const temp = await Dialog.showInputBox()
if (temp.response !== 1) { if (temp.response !== 1) {
return return
@ -465,7 +464,7 @@ export class System {
} }
// 读取文件内容 // 读取文件内容
const fileContent = await this.fs.readFile(path, header); const fileContent = await this.fs.readFile(path, header);
if (!fileContent && fileStat.isPwd){ if (!fileContent && fileStat.isPwd) {
notifyError('密码错误') notifyError('密码错误')
return return
} }

Loading…
Cancel
Save