app
This commit is contained in:
@@ -1,112 +1,119 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import {
|
||||
v4 as uuidv4
|
||||
} from "uuid";
|
||||
import IMSDK from "openim-uniapp-polyfill";
|
||||
|
||||
const state = {
|
||||
conversationList: [],
|
||||
currentConversation: {},
|
||||
unReadCount: 0,
|
||||
currentGroup: {},
|
||||
currentMemberInGroup: {},
|
||||
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,
|
||||
};
|
||||
},
|
||||
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", {});
|
||||
},
|
||||
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,
|
||||
};
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions,
|
||||
};
|
||||
@@ -1,75 +1,83 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { v4 as uuidv4} from "uuid";
|
||||
import IMSDK from "openim-uniapp-polyfill";
|
||||
import { businessGetUserInfo } from "@/api/login";
|
||||
import { filterEmptyValue } from "@/util/common";
|
||||
import { businessGetUserInfo} from "@/api/login";
|
||||
import { filterEmptyValue} from "@/util/common";
|
||||
|
||||
const state = {
|
||||
selfInfo: {},
|
||||
authData: {},
|
||||
isSyncing: false,
|
||||
reinstall: false,
|
||||
progress: 0,
|
||||
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;
|
||||
},
|
||||
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);
|
||||
}
|
||||
},
|
||||
async getSelfInfo({ commit }) {
|
||||
try {
|
||||
const {
|
||||
data
|
||||
} = await IMSDK.asyncApi(
|
||||
IMSDK.IMMethods.GetSelfUserInfo,
|
||||
uuidv4(),
|
||||
);
|
||||
const {users} = await businessGetUserInfo(data.userID);
|
||||
console.log(users);
|
||||
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,
|
||||
};
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions,
|
||||
};
|
||||
Reference in New Issue
Block a user