Initial commit

This commit is contained in:
2025-07-04 16:18:58 +08:00
commit 2cf13f673d
770 changed files with 73394 additions and 0 deletions

22
store/getters.js Normal file
View File

@@ -0,0 +1,22 @@
export default {
storeConversationList: (state) => state.conversation.conversationList,
storeCurrentConversation: (state) => state.conversation.currentConversation,
storeUnReadCount: (state) => state.conversation.unReadCount,
storeCurrentGroup: (state) => state.conversation.currentGroup,
storeCurrentMemberInGroup: (state) => state.conversation.currentMemberInGroup,
storeFriendList: (state) => state.contact.friendList,
storeBlackList: (state) => state.contact.blackList,
storeGroupList: (state) => state.contact.groupList,
storeRecvFriendApplications: (state) => state.contact.recvFriendApplications,
storeSentFriendApplications: (state) => state.contact.sentFriendApplications,
storeRecvGroupApplications: (state) => state.contact.recvGroupApplications,
storeSentGroupApplications: (state) => state.contact.sentGroupApplications,
storeHistoryMessageList: (state) => state.message.historyMessageList,
storeHasMoreMessage: (state) => state.message.hasMoreMessage,
storeSelfInfo: (state) => state.user.selfInfo,
storeCurrentUserID: (state) => state.user.selfInfo.userID,
storeIsSyncing: (state) => state.user.isSyncing,
storeReinstall: (state) => state.user.reinstall,
storeProgress: (state) => state.user.progress,
storeAuthData: (state) => state.user.authData,
};

21
store/index.js Normal file
View File

@@ -0,0 +1,21 @@
import Vue from "vue";
import Vuex from "vuex";
import user from "./modules/user";
import contact from "./modules/contact";
import conversation from "./modules/conversation";
import message from "./modules/message";
import getters from "./getters";
Vue.use(Vuex);
const store = new Vuex.Store({
modules: {
user,
contact,
conversation,
message,
},
getters,
});
export default store;

320
store/modules/contact.js Normal file
View File

@@ -0,0 +1,320 @@
import { v4 as uuidv4 } from "uuid";
import IMSDK from "openim-uniapp-polyfill";
const state = {
friendList: [],
blackList: [],
groupList: [],
recvFriendApplications: [],
sentFriendApplications: [],
recvGroupApplications: [],
sentGroupApplications: [],
unHandleFriendApplicationNum: 0,
unHandleGroupApplicationNum: 0,
};
const mutations = {
SET_FRIEND_LIST(state, list) {
state.friendList = [...list];
},
SET_BLACK_LIST(state, list) {
state.blackList = [...list];
},
SET_GROUP_LIST(state, list) {
state.groupList = [...list];
},
SET_RECV_FRIEND_APPLICATIONS(state, list) {
state.recvFriendApplications = [...list];
},
SET_SENT_FRIEND_APPLICATIONS(state, list) {
state.sentFriendApplications = [...list];
},
SET_RECV_GROUP_APPLICATIONS(state, list) {
state.recvGroupApplications = [...list];
},
SET_SENT_GROUP_APPLICATIONS(state, list) {
state.sentGroupApplications = [...list];
},
};
const actions = {
async getFriendList({ commit }) {
let offset = 0;
let friendInfoList = [];
let initialFetch = true;
while (true) {
try {
const count = initialFetch ? 10000 : 1000;
const { data } = await IMSDK.asyncApi("getFriendListPage", uuidv4(), {
offset,
count,
});
friendInfoList = [
...friendInfoList,
...data,
];
offset += count;
if (data.length < count) break;
initialFetch = false;
} catch (error) {
console.error("getFriendListPage error");
}
}
commit("SET_FRIEND_LIST", friendInfoList);
},
async getGrouplist({ commit }) {
let offset = 0;
let groupList = [];
while (true) {
try {
const { data } = await IMSDK.asyncApi(
"getJoinedGroupListPage",
uuidv4(),
{
offset,
count: 1000,
}
);
groupList = [...groupList, ...data];
offset += 1000;
if (data.length < 1000) break;
} catch (error) {
console.error("getGrouplist error");
}
}
commit("SET_GROUP_LIST", groupList);
},
getBlacklist({ commit }) {
IMSDK.asyncApi(IMSDK.IMMethods.GetBlackList, uuidv4()).then(({ data }) => {
commit("SET_BLACK_LIST", data);
});
},
getRecvFriendApplications({ commit }) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetFriendApplicationListAsRecipient,
uuidv4(),
).then(({ data }) => {
commit("SET_RECV_FRIEND_APPLICATIONS", data);
});
},
getSentFriendApplications({ commit }) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetFriendApplicationListAsApplicant,
uuidv4(),
).then(({ data }) => {
commit("SET_SENT_FRIEND_APPLICATIONS", data);
});
},
getRecvGroupApplications({ commit }) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetGroupApplicationListAsRecipient,
uuidv4(),
).then(({ data }) => {
commit("SET_RECV_GROUP_APPLICATIONS", data);
});
},
getSentGroupApplications({ commit }) {
IMSDK.asyncApi(
IMSDK.IMMethods.GetGroupApplicationListAsApplicant,
uuidv4(),
).then(({ data }) => {
commit("SET_SENT_GROUP_APPLICATIONS", data);
});
},
pushNewFriend({ commit, state }, friendInfo) {
const tmpList = [...state.friendList];
const idx = tmpList.findIndex((item) => item.userID === friendInfo.userID);
if (idx === -1) {
commit("SET_FRIEND_LIST", [...tmpList, friendInfo]);
}
},
updateFriendInfo({ commit, state }, { friendInfo, isRemove = false }) {
const tmpList = [...state.friendList];
const idx = tmpList.findIndex((item) => item.userID === friendInfo.userID);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...friendInfo,
};
}
commit("SET_FRIEND_LIST", tmpList);
}
},
pushNewBlack({ commit, state }, blackInfo) {
const tmpList = [...state.blackList];
const idx = tmpList.findIndex((item) => item.userID === blackInfo.userID);
if (idx === -1) {
commit("SET_BLACK_LIST", [...tmpList, blackInfo]);
}
},
updateBlackInfo({ commit, state }, { blackInfo, isRemove = false }) {
const tmpList = [...state.blackList];
const idx = tmpList.findIndex((item) => item.userID === blackInfo.userID);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...blackInfo,
};
}
commit("SET_BLACK_LIST", tmpList);
}
},
pushNewGroup({ commit, state }, groupInfo) {
const tmpList = [...state.groupList];
const idx = tmpList.findIndex((item) => item.groupID === groupInfo.groupID);
if (idx === -1) {
commit("SET_GROUP_LIST", [...tmpList, groupInfo]);
}
},
updateGroupInfo(
{ commit, state, rootState },
{ groupInfo, isRemove = false },
) {
const tmpList = [...state.groupList];
const idx = tmpList.findIndex((item) => item.groupID === groupInfo.groupID);
if (rootState.conversation.currentGroup.groupID === groupInfo.groupID) {
commit("conversation/SET_CURRENT_GROUP", groupInfo, { root: true });
}
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...groupInfo,
};
}
commit("SET_GROUP_LIST", tmpList);
}
},
pushNewRecvFriendApplition({ commit, state }, application) {
const tmpList = [...state.recvFriendApplications];
const idx = tmpList.findIndex(
(item) => item.fromUserID === application.fromUserID,
);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_RECV_FRIEND_APPLICATIONS", [...tmpList, application]);
},
updateRecvFriendApplition(
{ commit, state, rootState },
{ application, isRemove = false },
) {
const tmpList = [...state.recvFriendApplications];
const idx = tmpList.findIndex(
(item) => item.fromUserID === application.fromUserID,
);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_RECV_FRIEND_APPLICATIONS", tmpList);
}
},
pushNewSentFriendApplition({ commit, state }, application) {
const tmpList = [...state.sentFriendApplications];
const idx = tmpList.findIndex(
(item) => item.toUserID === application.toUserID,
);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_SENT_FRIEND_APPLICATIONS", [...tmpList, application]);
},
updateSentFriendApplition(
{ commit, state, rootState },
{ application, isRemove = false },
) {
const tmpList = [...state.sentFriendApplications];
const idx = tmpList.findIndex(
(item) => item.toUserID === application.toUserID,
);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_SENT_FRIEND_APPLICATIONS", tmpList);
}
},
pushNewRecvGroupApplition({ commit, state }, application) {
const tmpList = [...state.recvGroupApplications];
const idx = tmpList.findIndex((item) => item.userID === application.userID);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_RECV_GROUP_APPLICATIONS", [...tmpList, application]);
},
updateRecvGroupApplition(
{ commit, state, rootState },
{ application, isRemove = false },
) {
const tmpList = [...state.recvGroupApplications];
const idx = tmpList.findIndex((item) => item.userID === application.userID);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_RECV_GROUP_APPLICATIONS", tmpList);
}
},
pushNewSentGroupApplition({ commit, state }, application) {
const tmpList = [...state.sentGroupApplications];
const idx = tmpList.findIndex(
(item) => item.groupID === application.groupID,
);
if (idx !== -1) {
tmpList.splice(idx, 1);
}
commit("SET_SENT_GROUP_APPLICATIONS", [...tmpList, application]);
},
updateSentGroupApplition(
{ commit, state, rootState },
{ application, isRemove = false },
) {
const tmpList = [...state.sentGroupApplications];
const idx = tmpList.findIndex(
(item) => item.groupID === application.groupID,
);
if (idx !== -1) {
if (isRemove) {
tmpList.splice(idx, 1);
} else {
tmpList[idx] = {
...application,
};
}
commit("SET_SENT_GROUP_APPLICATIONS", tmpList);
}
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};

View File

@@ -0,0 +1,112 @@
import { v4 as uuidv4 } from "uuid";
import IMSDK from "openim-uniapp-polyfill";
const state = {
conversationList: [],
currentConversation: {},
unReadCount: 0,
currentGroup: {},
currentMemberInGroup: {},
};
const mutations = {
SET_CONVERSATION_LIST(state, list) {
state.conversationList = [...list];
},
SET_CURRENT_CONVERSATION(state, conversation) {
state.currentConversation = {
...conversation,
};
},
SET_UNREAD_COUNT(state, count) {
if (count) {
uni.setTabBarBadge({
index: 0,
text: count < 99 ? count + "" : "99+",
});
} else {
uni.removeTabBarBadge({
index: 0,
});
}
state.unReadCount = count;
},
SET_CURRENT_GROUP(state, group) {
state.currentGroup = {
...group,
};
},
SET_CURRENT_MEMBER_IN_GROUP(state, member) {
state.currentMemberInGroup = {
...member,
};
},
};
const actions = {
async getConversationList({ state, commit }, isFirstPage = true) {
try {
const { data } = await IMSDK.asyncApi(
IMSDK.IMMethods.GetConversationListSplit,
uuidv4(),
{
offset: isFirstPage ? 0 : state.conversationList.length,
count: 500,
},
);
commit("SET_CONVERSATION_LIST", [
...(isFirstPage ? [] : state.conversationList),
...data,
]);
return [...data];
} catch (e) {
console.log(e);
commit("SET_CONVERSATION_LIST", []);
return [];
}
},
getCurrentGroup({ commit }, groupID) {
IMSDK.asyncApi(IMSDK.IMMethods.GetSpecifiedGroupsInfo, uuidv4(), [
groupID,
]).then(({ data }) => {
commit("SET_CURRENT_GROUP", data[0] ?? {});
});
},
getCurrentMemberInGroup({ commit, rootState }, groupID) {
IMSDK.asyncApi(IMSDK.IMMethods.GetSpecifiedGroupMembersInfo, uuidv4(), {
groupID,
userIDList: [rootState.user.selfInfo.userID],
}).then(({ data }) => {
commit("SET_CURRENT_MEMBER_IN_GROUP", data[0] ?? {});
});
},
getUnReadCount({ commit }) {
IMSDK.asyncApi(IMSDK.IMMethods.GetTotalUnreadMsgCount, uuidv4()).then(
(res) => {
console.log(res);
commit("SET_UNREAD_COUNT", res.data);
},
);
},
updateCurrentMemberInGroup({ commit, state }, memberInfo) {
console.log(memberInfo);
if (
memberInfo.groupID === state.currentMemberInGroup.groupID &&
memberInfo.userID === state.currentMemberInGroup.userID
) {
commit("SET_CURRENT_MEMBER_IN_GROUP", memberInfo);
}
},
resetConversationState({ commit }) {
commit("SET_CURRENT_MEMBER_IN_GROUP", {});
commit("SET_CURRENT_GROUP", {});
commit("SET_CURRENT_CONVERSATION", {});
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};

87
store/modules/message.js Normal file
View File

@@ -0,0 +1,87 @@
import IMSDK, { MessageStatus, MessageType } from "openim-uniapp-polyfill";
import { v4 as uuidv4 } from "uuid";
import { UpdateMessageTypes } from "@/constant";
const state = {
historyMessageList: [],
hasMoreMessage: true,
};
const mutations = {
SET_HISTORY_MESSAGE_LIST(state, list) {
state.historyMessageList = [...list];
},
SET_HAS_MORE_MESSAGE(state, hasMore) {
state.hasMoreMessage = hasMore;
},
};
const actions = {
async getHistoryMesageList({ commit, state }, params) {
let emptyFlag = true;
try {
console.log("getHistoryMesageList:::");
console.log(params);
const { data } = await IMSDK.asyncApi(
IMSDK.IMMethods.GetAdvancedHistoryMessageList,
uuidv4(),
params,
);
console.log(data);
const isFistPage = !params.startClientMsgID
const messages = data.messageList ?? [];
emptyFlag = messages.length === 0;
commit("SET_HISTORY_MESSAGE_LIST", [
...messages,
...(isFistPage ? [] : state.historyMessageList),
]);
commit("SET_HAS_MORE_MESSAGE", !data.isEnd && messages.length === 20);
} catch (e) {
commit("SET_HISTORY_MESSAGE_LIST", []);
}
return {
emptyFlag,
};
},
pushNewMessage({ commit, state }, message) {
commit("SET_HISTORY_MESSAGE_LIST", [...state.historyMessageList, message]);
},
updateOneMessage(
{ commit, state },
{
message,
type = UpdateMessageTypes.Overall,
keyWords = [],
isSuccess = false,
},
) {
const tmpList = state.historyMessageList;
const idx = tmpList.findIndex(
(msg) => msg.clientMsgID === message.clientMsgID,
);
if (idx !== -1) {
if (type === UpdateMessageTypes.Overall) {
tmpList[idx] = {
...message,
};
} else if (type === UpdateMessageTypes.KeyWords) {
const updateFields = Array.isArray(keyWords) ? keyWords : [keyWords];
updateFields.forEach(
(field) => (tmpList[idx][field.key] = field.value),
);
}
commit("SET_HISTORY_MESSAGE_LIST", tmpList);
}
},
resetMessageState({ commit }) {
commit("SET_HISTORY_MESSAGE_LIST", []);
commit("SET_HAS_MORE_MESSAGE", true);
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};

75
store/modules/user.js Normal file
View File

@@ -0,0 +1,75 @@
import { v4 as uuidv4 } from "uuid";
import IMSDK from "openim-uniapp-polyfill";
import { businessGetUserInfo } from "@/api/login";
import { filterEmptyValue } from "@/util/common";
const state = {
selfInfo: {},
authData: {},
isSyncing: false,
reinstall: false,
progress: 0,
};
const mutations = {
SET_SELF_INFO(state, info) {
state.selfInfo = {
...info,
};
},
SET_AUTH_DATA(state, data) {
state.authData = {
...data,
};
},
SET_IS_SYNCING(state, data) {
state.isSyncing = data;
},
SET_REINSTALL(state, data) {
state.reinstall = data;
},
SET_PROGRESS(state, data) {
state.progress = data;
},
};
const actions = {
async getSelfInfo({ commit }) {
try {
const { data } = await IMSDK.asyncApi(
IMSDK.IMMethods.GetSelfUserInfo,
uuidv4(),
);
const { users } = await businessGetUserInfo(data.userID);
const businessData = users[0] ?? {};
filterEmptyValue(businessData);
commit("SET_SELF_INFO", {
...data,
...businessData,
});
} catch (e) {
console.log(e);
uni.$u.toast("获取个人信息失败");
}
},
async updateBusinessInfo({ commit, state }) {
try {
const { users } = await businessGetUserInfo(state.selfInfo.userID);
const businessData = users[0] ?? {};
filterEmptyValue(businessData);
commit("SET_SELF_INFO", {
...state.selfInfo,
...businessData,
});
} catch (e) {
console.log(e);
}
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};