Commit ccd2611c by chenwq1

refactor: 优化加载子标签逻辑

- 更新 `loadSubTabsForBigModule` 函数,新增 `force` 参数以控制缓存策略。
- 调整多个调用点,确保在特定情况下强制重新加载子标签。
- 移除不再使用的 `markActiveSubTabCompletedLocally` 函数,简化代码结构。
1 parent 8cdbc8eb
Pipeline #106 for ccd2611c failed in 0 seconds
...@@ -309,15 +309,16 @@ async function initializeInspection() { ...@@ -309,15 +309,16 @@ async function initializeInspection() {
/** /**
* @param bigModuleKey 大项 id * @param bigModuleKey 大项 id
* @param syncSelection 为 false 时只拉取/填充 subTabs,不改当前 activeSubKey(用于后台匹配节点) * @param syncSelection 为 false 时只拉取/填充 subTabs,不改当前 activeSubKey(用于后台匹配节点)
* @param force 为 true 时忽略已有 subTabs 缓存,重新请求 `getInspectionChildren`
*/ */
async function loadSubTabsForBigModule(bigModuleKey: number | string, syncSelection = true) { async function loadSubTabsForBigModule(bigModuleKey: number | string, syncSelection = true, force = false) {
if (bigModuleKey === SCORE_BIG_KEY) return; if (bigModuleKey === SCORE_BIG_KEY) return;
try { try {
const targetBigModule = bigModules.value.find((module) => module.key === bigModuleKey); const targetBigModule = bigModules.value.find((module) => module.key === bigModuleKey);
if (!targetBigModule) return; if (!targetBigModule) return;
if (targetBigModule.subTabs.length > 0) { if (!force && targetBigModule.subTabs.length > 0) {
if (syncSelection) { if (syncSelection) {
activeSubKey.value = targetBigModule.subTabs[0]!.key; activeSubKey.value = targetBigModule.subTabs[0]!.key;
} }
...@@ -392,13 +393,13 @@ async function switchToUncompletedInspectionNode(nodeId: number | string): Promi ...@@ -392,13 +393,13 @@ async function switchToUncompletedInspectionNode(nodeId: number | string): Promi
); );
if (rootHit) { if (rootHit) {
activeBigKey.value = rootHit.key; activeBigKey.value = rootHit.key;
await loadSubTabsForBigModule(rootHit.key); await loadSubTabsForBigModule(rootHit.key, true, true);
activeSubKey.value = rootHit.subTabs[0]?.key ?? ""; activeSubKey.value = rootHit.subTabs[0]?.key ?? "";
return true; return true;
} }
for (const m of mains) { for (const m of mains) {
await loadSubTabsForBigModule(m.key, false); await loadSubTabsForBigModule(m.key, false, true);
const sub = m.subTabs.find( const sub = m.subTabs.find(
(s) => String(s.key) === idStr || String(s.nodeId ?? "") === idStr, (s) => String(s.key) === idStr || String(s.nodeId ?? "") === idStr,
); );
...@@ -447,7 +448,7 @@ function advanceInspectionStep() { ...@@ -447,7 +448,7 @@ function advanceInspectionStep() {
if (activeMainIndex < mains.length - 1) { if (activeMainIndex < mains.length - 1) {
const nextMain = mains[activeMainIndex + 1]!; const nextMain = mains[activeMainIndex + 1]!;
activeBigKey.value = nextMain.key; activeBigKey.value = nextMain.key;
loadSubTabsForBigModule(nextMain.key).then(() => { loadSubTabsForBigModule(nextMain.key, true, true).then(() => {
activeSubKey.value = nextMain.subTabs[0]?.key ?? ""; activeSubKey.value = nextMain.subTabs[0]?.key ?? "";
}); });
} else { } else {
...@@ -482,16 +483,6 @@ async function saveCurrentLeafInspectionRecord(nextFlag: boolean): Promise<boole ...@@ -482,16 +483,6 @@ async function saveCurrentLeafInspectionRecord(nextFlag: boolean): Promise<boole
return true; return true;
} }
/** 下一步保存成功后同步当前二级 Tab 完成态,避免进度条与 Tab 勾选依赖再次拉模板 */
function markActiveSubTabCompletedLocally() {
if (activeBigKey.value === SCORE_BIG_KEY) return;
const mod = bigModules.value.find((m) => m.key === activeBigKey.value);
const sub = mod?.subTabs.find((s) => s.key === activeSubKey.value);
if (sub) {
sub.completedFlag = 1;
}
}
/** 切换大项 / 二级项前静默落库当前叶子数据 */ /** 切换大项 / 二级项前静默落库当前叶子数据 */
async function persistCurrentSubTabSilently() { async function persistCurrentSubTabSilently() {
if (activeBigKey.value === SCORE_BIG_KEY) return; if (activeBigKey.value === SCORE_BIG_KEY) return;
...@@ -509,13 +500,17 @@ async function onSelectBigModule(selectedBigModule: BigModule) { ...@@ -509,13 +500,17 @@ async function onSelectBigModule(selectedBigModule: BigModule) {
activeBigKey.value = selectedBigModule.key; activeBigKey.value = selectedBigModule.key;
activeSubKey.value = ""; activeSubKey.value = "";
if (selectedBigModule.key !== SCORE_BIG_KEY) { if (selectedBigModule.key !== SCORE_BIG_KEY) {
loadSubTabsForBigModule(selectedBigModule.key); await loadSubTabsForBigModule(selectedBigModule.key, true, true);
} }
} }
async function onSelectSubTab(subTabKey: number | string) { async function onSelectSubTab(subTabKey: number | string) {
if (subTabKey === activeSubKey.value) return; if (subTabKey === activeSubKey.value) return;
await persistCurrentSubTabSilently(); await persistCurrentSubTabSilently();
const bigKey = activeBigKey.value;
if (bigKey !== SCORE_BIG_KEY) {
await loadSubTabsForBigModule(bigKey, false, true);
}
activeSubKey.value = subTabKey; activeSubKey.value = subTabKey;
} }
...@@ -534,7 +529,9 @@ async function onNext() { ...@@ -534,7 +529,9 @@ async function onNext() {
showToast("未获取到表单数据"); showToast("未获取到表单数据");
return; return;
} }
markActiveSubTabCompletedLocally(); if (activeBigKey.value !== SCORE_BIG_KEY) {
await loadSubTabsForBigModule(activeBigKey.value, false, true);
}
advanceInspectionStep(); advanceInspectionStep();
} catch (error) { } catch (error) {
if (!isRequestFailureAlreadyHandled(error)) { if (!isRequestFailureAlreadyHandled(error)) {
...@@ -560,7 +557,7 @@ async function onPrev() { ...@@ -560,7 +557,7 @@ async function onPrev() {
const lastMain = mains[mains.length - 1]; const lastMain = mains[mains.length - 1];
if (lastMain) { if (lastMain) {
activeBigKey.value = lastMain.key; activeBigKey.value = lastMain.key;
await loadSubTabsForBigModule(lastMain.key); await loadSubTabsForBigModule(lastMain.key, true, true);
activeSubKey.value = lastMain.subTabs[lastMain.subTabs.length - 1]?.key ?? ""; activeSubKey.value = lastMain.subTabs[lastMain.subTabs.length - 1]?.key ?? "";
} }
return; return;
...@@ -572,14 +569,16 @@ async function onPrev() { ...@@ -572,14 +569,16 @@ async function onPrev() {
const activeSubIndex = subTabsOfActive.findIndex((subTab) => subTab.key === activeSubKey.value); const activeSubIndex = subTabsOfActive.findIndex((subTab) => subTab.key === activeSubKey.value);
if (activeSubIndex > 0) { if (activeSubIndex > 0) {
activeSubKey.value = subTabsOfActive[activeSubIndex - 1]!.key; const prevSubKey = subTabsOfActive[activeSubIndex - 1]!.key;
await loadSubTabsForBigModule(activeBigKey.value, false, true);
activeSubKey.value = prevSubKey;
} else { } else {
const mains = mainInspectionBigModules.value; const mains = mainInspectionBigModules.value;
const activeMainIndex = mains.findIndex((module) => module.key === activeBigKey.value); const activeMainIndex = mains.findIndex((module) => module.key === activeBigKey.value);
if (activeMainIndex > 0) { if (activeMainIndex > 0) {
const previousMain = mains[activeMainIndex - 1]!; const previousMain = mains[activeMainIndex - 1]!;
activeBigKey.value = previousMain.key; activeBigKey.value = previousMain.key;
await loadSubTabsForBigModule(previousMain.key); await loadSubTabsForBigModule(previousMain.key, true, true);
activeSubKey.value = activeSubKey.value =
previousMain.subTabs[previousMain.subTabs.length - 1]?.key ?? ""; previousMain.subTabs[previousMain.subTabs.length - 1]?.key ?? "";
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!