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() {
/**
* @param bigModuleKey 大项 id
* @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;
try {
const targetBigModule = bigModules.value.find((module) => module.key === bigModuleKey);
if (!targetBigModule) return;
if (targetBigModule.subTabs.length > 0) {
if (!force && targetBigModule.subTabs.length > 0) {
if (syncSelection) {
activeSubKey.value = targetBigModule.subTabs[0]!.key;
}
......@@ -392,13 +393,13 @@ async function switchToUncompletedInspectionNode(nodeId: number | string): Promi
);
if (rootHit) {
activeBigKey.value = rootHit.key;
await loadSubTabsForBigModule(rootHit.key);
await loadSubTabsForBigModule(rootHit.key, true, true);
activeSubKey.value = rootHit.subTabs[0]?.key ?? "";
return true;
}
for (const m of mains) {
await loadSubTabsForBigModule(m.key, false);
await loadSubTabsForBigModule(m.key, false, true);
const sub = m.subTabs.find(
(s) => String(s.key) === idStr || String(s.nodeId ?? "") === idStr,
);
......@@ -447,7 +448,7 @@ function advanceInspectionStep() {
if (activeMainIndex < mains.length - 1) {
const nextMain = mains[activeMainIndex + 1]!;
activeBigKey.value = nextMain.key;
loadSubTabsForBigModule(nextMain.key).then(() => {
loadSubTabsForBigModule(nextMain.key, true, true).then(() => {
activeSubKey.value = nextMain.subTabs[0]?.key ?? "";
});
} else {
......@@ -482,16 +483,6 @@ async function saveCurrentLeafInspectionRecord(nextFlag: boolean): Promise<boole
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() {
if (activeBigKey.value === SCORE_BIG_KEY) return;
......@@ -509,13 +500,17 @@ async function onSelectBigModule(selectedBigModule: BigModule) {
activeBigKey.value = selectedBigModule.key;
activeSubKey.value = "";
if (selectedBigModule.key !== SCORE_BIG_KEY) {
loadSubTabsForBigModule(selectedBigModule.key);
await loadSubTabsForBigModule(selectedBigModule.key, true, true);
}
}
async function onSelectSubTab(subTabKey: number | string) {
if (subTabKey === activeSubKey.value) return;
await persistCurrentSubTabSilently();
const bigKey = activeBigKey.value;
if (bigKey !== SCORE_BIG_KEY) {
await loadSubTabsForBigModule(bigKey, false, true);
}
activeSubKey.value = subTabKey;
}
......@@ -534,7 +529,9 @@ async function onNext() {
showToast("未获取到表单数据");
return;
}
markActiveSubTabCompletedLocally();
if (activeBigKey.value !== SCORE_BIG_KEY) {
await loadSubTabsForBigModule(activeBigKey.value, false, true);
}
advanceInspectionStep();
} catch (error) {
if (!isRequestFailureAlreadyHandled(error)) {
......@@ -560,7 +557,7 @@ async function onPrev() {
const lastMain = mains[mains.length - 1];
if (lastMain) {
activeBigKey.value = lastMain.key;
await loadSubTabsForBigModule(lastMain.key);
await loadSubTabsForBigModule(lastMain.key, true, true);
activeSubKey.value = lastMain.subTabs[lastMain.subTabs.length - 1]?.key ?? "";
}
return;
......@@ -572,14 +569,16 @@ async function onPrev() {
const activeSubIndex = subTabsOfActive.findIndex((subTab) => subTab.key === activeSubKey.value);
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 {
const mains = mainInspectionBigModules.value;
const activeMainIndex = mains.findIndex((module) => module.key === activeBigKey.value);
if (activeMainIndex > 0) {
const previousMain = mains[activeMainIndex - 1]!;
activeBigKey.value = previousMain.key;
await loadSubTabsForBigModule(previousMain.key);
await loadSubTabsForBigModule(previousMain.key, true, true);
activeSubKey.value =
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!