ykt-wxapp/store/team.js
2026-02-02 14:12:46 +08:00

51 lines
1.6 KiB
JavaScript

import { computed, ref } from "vue";
import { defineStore, storeToRefs } from "pinia";
import api from '@/utils/api';
import { toast } from '@/utils/widget';
import useAccountStore from "./account";
export default defineStore("teamStore", () => {
const { account, doctorInfo } = storeToRefs(useAccountStore());
const teams = ref([]);
const chargeTeams = computed(() => {
const userid = doctorInfo.value?.userid;
return teams.value.filter(team => {
const memberLeaderList = Array.isArray(team.memberLeaderList) ? team.memberLeaderList : [];
return memberLeaderList.includes(userid);
});
})
async function getTeam(teamId) {
if (!teamId || !account.value?.corpId) return;
const res = await api('getTeamData', { teamId, corpId: account.value.corpId });
if (res && res.data) {
return res.data;
} else {
toast(res?.message || '获取团队信息失败')
}
}
async function getTeams() {
const corpId = account.value?.corpId;
const mateId = doctorInfo.value?.userid;
if (!corpId || !mateId) return;
const res = await api('getJoinedTeams', { corpId, mateId });
teams.value = res && Array.isArray(res.data) ? res.data : [];
}
// 获取团队成员头像映射
async function getTeamMemberAvatars(teamId) {
if (!teamId || !account.value?.corpId) return {};
const res = await api('getTeamMemberAvatars', {
teamId,
corpId: account.value.corpId
});
if (res && res.success && res.data) {
return res.data; // 返回 { userId: avatar } 的映射对象
}
return {};
}
return { teams, chargeTeams, getTeam, getTeams, getTeamMemberAvatars }
})