fix:修复teamid显示问题

This commit is contained in:
Jafeng 2026-02-09 16:33:42 +08:00
parent 69a0c83311
commit eead7920dc
2 changed files with 70 additions and 26 deletions

View File

@ -221,40 +221,80 @@ function resolveTeamName(teamId) {
const hit = list.find((i) => i && i.value === tid);
if (hit?.label) return String(hit.label);
//
void loadTeamName(tid);
void batchLoadTeamNames([tid]);
return '';
}
async function loadTeamName(teamId) {
const tid = String(teamId || '') || '';
if (!tid) return;
if (loadedTeamNameIds.has(tid)) return;
let teamNameBatchInflight = null; // Promise | null
async function batchLoadTeamNames(teamIds) {
const ids = Array.isArray(teamIds) ? teamIds.map((v) => String(v || '').trim()).filter(Boolean) : [];
if (!ids.length) return;
const uniq = Array.from(new Set(ids));
const unknown = uniq.filter((tid) => {
if (loadedTeamNameIds.has(tid)) return false;
const cached = teamNameMap.value?.[tid];
if (cached) return false;
const list = teamList.value || [];
const hit = list.find((i) => i && i.value === tid);
return !hit?.label;
});
if (!unknown.length) return;
if (teamNameBatchInflight) return teamNameBatchInflight;
const corpId = getCorpId();
if (!corpId) return;
unknown.forEach((tid) => loadedTeamNameIds.add(tid));
loadedTeamNameIds.add(tid);
try {
const res = await api('getTeamBaseInfo', { corpId, teamId: tid });
if (res?.success) {
const data = res?.data && typeof res.data === 'object' ? res.data : {};
const name = String(data?.name || data?.teamName || data?.team || '').trim();
if (name) teamNameMap.value = { ...(teamNameMap.value || {}), [tid]: name };
return;
teamNameBatchInflight = (async () => {
// getTeamById teamIds team teamId/name
try {
const res = await api('getTeamById', { corpId, teamIds: unknown }, false);
if (res?.success) {
const rows = Array.isArray(res?.data) ? res.data : Array.isArray(res?.data?.data) ? res.data.data : [];
const patch = rows.reduce((acc, t) => {
const id = String(t?.teamId || t?.id || t?._id || '').trim();
if (!id) return acc;
const name = String(t?.name || t?.teamName || t?.team || '').trim();
if (!name) return acc;
//
const existing = teamNameMap.value?.[id];
if (existing) return acc;
acc[id] = name;
return acc;
}, {});
if (Object.keys(patch).length) teamNameMap.value = { ...(teamNameMap.value || {}), ...patch };
return;
}
} catch {
// ignore
}
} catch {
// ignore
}
// getTeamData
try {
const res = await api('getTeamData', { corpId, teamId: tid });
if (!res?.success) return;
const data = res?.data && typeof res.data === 'object' ? res.data : {};
const name = String(data?.name || data?.teamName || data?.team || '').trim();
if (name) teamNameMap.value = { ...(teamNameMap.value || {}), [tid]: name };
} catch {
// ignore
}
// getTeamData
const limit = 4;
let idx = 0;
const workers = Array.from({ length: Math.min(limit, unknown.length) }, async () => {
while (idx < unknown.length) {
const tid = unknown[idx++];
try {
const res = await api('getTeamData', { corpId, teamId: tid }, false);
if (!res?.success) continue;
const data = res?.data && typeof res.data === 'object' ? res.data : {};
const name = String(data?.name || data?.teamName || data?.team || '').trim();
if (!name) continue;
if (!teamNameMap.value?.[tid]) teamNameMap.value = { ...(teamNameMap.value || {}), [tid]: name };
} catch {
// ignore
}
}
});
await Promise.allSettled(workers);
})().finally(() => {
teamNameBatchInflight = null;
});
return teamNameBatchInflight;
}
function executeTeamText(r) {
@ -508,6 +548,9 @@ async function getMore() {
const teamIds = mapped.map((i) => i.executeTeamId).filter(Boolean);
Array.from(new Set(teamIds)).forEach((tid) => loadTeamMembers(tid));
// userid +
void batchLoadTeamNames(teamIds);
// /
const executorIds = mapped.map((i) => i.executorUserId).filter(Boolean);
void batchLoadCorpMembers(executorIds);

View File

@ -10,6 +10,7 @@ const urlsConfig = {
getCorpTags: 'getCorpTags',
getTeamBaseInfo: 'getTeamBaseInfo',
getTeamData: 'getTeamData',
getTeamById: 'getTeamById',
getTeamBymember: 'getTeamBymember',
getCurrentTemplate: 'getCurrentTemplate',
getTemplateGroup: 'getTemplateGroup',