fix:修复teamid显示问题
This commit is contained in:
parent
69a0c83311
commit
eead7920dc
@ -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);
|
||||
|
||||
@ -10,6 +10,7 @@ const urlsConfig = {
|
||||
getCorpTags: 'getCorpTags',
|
||||
getTeamBaseInfo: 'getTeamBaseInfo',
|
||||
getTeamData: 'getTeamData',
|
||||
getTeamById: 'getTeamById',
|
||||
getTeamBymember: 'getTeamBymember',
|
||||
getCurrentTemplate: 'getCurrentTemplate',
|
||||
getTemplateGroup: 'getTemplateGroup',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user