Files
im/store/modules/user.js
T

77 lines
1.5 KiB
JavaScript
Raw Normal View History

2025-11-27 03:55:38 +08:00
import { v4 as uuidv4} from "uuid";
2025-11-07 09:56:20 +08:00
import IMSDK from "openim-uniapp-polyfill";
2025-11-27 03:55:38 +08:00
import { businessGetUserInfo} from "@/api/login";
import { filterEmptyValue} from "@/util/common";
2025-11-07 09:56:20 +08:00
const state = {
2025-11-21 01:20:28 +08:00
selfInfo: {},
authData: {},
isSyncing: false,
reinstall: false,
progress: 0,
2025-11-23 01:01:52 +08:00
token: ""
2025-11-07 09:56:20 +08:00
};
const mutations = {
2025-11-23 01:01:52 +08:00
SET_TOKEN(state, info) {
state.token = info;
},
2025-11-21 01:20:28 +08:00
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;
},
2025-11-07 09:56:20 +08:00
};
const actions = {
2025-11-27 03:55:38 +08:00
async getSelfInfo({ commit }) {
2025-11-21 01:20:28 +08:00
try {
2025-11-25 05:36:02 +08:00
const result = await IMSDK.asyncApi(IMSDK.IMMethods.GetSelfUserInfo,uuidv4(),);
const res = await businessGetUserInfo(result.data.userID);
2025-11-23 07:58:47 +08:00
const businessData = res.data[0] ?? {};
2025-11-21 01:20:28 +08:00
filterEmptyValue(businessData);
commit("SET_SELF_INFO", {
2025-11-25 05:36:02 +08:00
...result.data,
2025-11-21 01:20:28 +08:00
...businessData,
});
} catch (e) {
console.log(e);
uni.$u.toast("获取个人信息失败");
}
},
2025-11-27 03:55:38 +08:00
async updateBusinessInfo({ commit, state }) {
2025-11-21 01:20:28 +08:00
try {
2025-11-23 07:58:47 +08:00
const res = await businessGetUserInfo(state.selfInfo.userID);
const businessData = res.data[0] ?? {};
2025-11-21 01:20:28 +08:00
filterEmptyValue(businessData);
commit("SET_SELF_INFO", {
...state.selfInfo,
...businessData,
});
} catch (e) {
console.log(e);
}
},
2025-11-07 09:56:20 +08:00
};
export default {
2025-11-21 01:20:28 +08:00
namespaced: true,
state,
mutations,
actions,
};