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);
|
const hit = list.find((i) => i && i.value === tid);
|
||||||
if (hit?.label) return String(hit.label);
|
if (hit?.label) return String(hit.label);
|
||||||
// 不阻塞渲染:后台补齐团队名
|
// 不阻塞渲染:后台补齐团队名
|
||||||
void loadTeamName(tid);
|
void batchLoadTeamNames([tid]);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadTeamName(teamId) {
|
let teamNameBatchInflight = null; // Promise | null
|
||||||
const tid = String(teamId || '') || '';
|
async function batchLoadTeamNames(teamIds) {
|
||||||
if (!tid) return;
|
const ids = Array.isArray(teamIds) ? teamIds.map((v) => String(v || '').trim()).filter(Boolean) : [];
|
||||||
if (loadedTeamNameIds.has(tid)) return;
|
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();
|
const corpId = getCorpId();
|
||||||
if (!corpId) return;
|
if (!corpId) return;
|
||||||
|
unknown.forEach((tid) => loadedTeamNameIds.add(tid));
|
||||||
|
|
||||||
loadedTeamNameIds.add(tid);
|
teamNameBatchInflight = (async () => {
|
||||||
try {
|
// 现成接口:getTeamById 支持 teamIds 批量查询,返回 team 列表(含 teamId/name)
|
||||||
const res = await api('getTeamBaseInfo', { corpId, teamId: tid });
|
try {
|
||||||
if (res?.success) {
|
const res = await api('getTeamById', { corpId, teamIds: unknown }, false);
|
||||||
const data = res?.data && typeof res.data === 'object' ? res.data : {};
|
if (res?.success) {
|
||||||
const name = String(data?.name || data?.teamName || data?.team || '').trim();
|
const rows = Array.isArray(res?.data) ? res.data : Array.isArray(res?.data?.data) ? res.data.data : [];
|
||||||
if (name) teamNameMap.value = { ...(teamNameMap.value || {}), [tid]: name };
|
const patch = rows.reduce((acc, t) => {
|
||||||
return;
|
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 再试一次
|
// 兜底:逐个 getTeamData(并发不高,避免卡顿)
|
||||||
try {
|
const limit = 4;
|
||||||
const res = await api('getTeamData', { corpId, teamId: tid });
|
let idx = 0;
|
||||||
if (!res?.success) return;
|
const workers = Array.from({ length: Math.min(limit, unknown.length) }, async () => {
|
||||||
const data = res?.data && typeof res.data === 'object' ? res.data : {};
|
while (idx < unknown.length) {
|
||||||
const name = String(data?.name || data?.teamName || data?.team || '').trim();
|
const tid = unknown[idx++];
|
||||||
if (name) teamNameMap.value = { ...(teamNameMap.value || {}), [tid]: name };
|
try {
|
||||||
} catch {
|
const res = await api('getTeamData', { corpId, teamId: tid }, false);
|
||||||
// ignore
|
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) {
|
function executeTeamText(r) {
|
||||||
@ -508,6 +548,9 @@ async function getMore() {
|
|||||||
const teamIds = mapped.map((i) => i.executeTeamId).filter(Boolean);
|
const teamIds = mapped.map((i) => i.executeTeamId).filter(Boolean);
|
||||||
Array.from(new Set(teamIds)).forEach((tid) => loadTeamMembers(tid));
|
Array.from(new Set(teamIds)).forEach((tid) => loadTeamMembers(tid));
|
||||||
|
|
||||||
|
// 批量补齐团队名(与 userid 补齐策略一致:缓存 + 只补缺,不阻塞渲染)
|
||||||
|
void batchLoadTeamNames(teamIds);
|
||||||
|
|
||||||
// 补齐非团队成员执行人姓名(例如其他团队创建/操作)
|
// 补齐非团队成员执行人姓名(例如其他团队创建/操作)
|
||||||
const executorIds = mapped.map((i) => i.executorUserId).filter(Boolean);
|
const executorIds = mapped.map((i) => i.executorUserId).filter(Boolean);
|
||||||
void batchLoadCorpMembers(executorIds);
|
void batchLoadCorpMembers(executorIds);
|
||||||
|
|||||||
@ -10,6 +10,7 @@ const urlsConfig = {
|
|||||||
getCorpTags: 'getCorpTags',
|
getCorpTags: 'getCorpTags',
|
||||||
getTeamBaseInfo: 'getTeamBaseInfo',
|
getTeamBaseInfo: 'getTeamBaseInfo',
|
||||||
getTeamData: 'getTeamData',
|
getTeamData: 'getTeamData',
|
||||||
|
getTeamById: 'getTeamById',
|
||||||
getTeamBymember: 'getTeamBymember',
|
getTeamBymember: 'getTeamBymember',
|
||||||
getCurrentTemplate: 'getCurrentTemplate',
|
getCurrentTemplate: 'getCurrentTemplate',
|
||||||
getTemplateGroup: 'getTemplateGroup',
|
getTemplateGroup: 'getTemplateGroup',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user