Browse Source

fix reload will back to list page in match page

master
CANCERYS\kw093 1 day ago
parent
commit
267acfb863
2 changed files with 45 additions and 39 deletions
  1. +3
    -38
      src/components/Jodetail/JobPickExecutionsecondscan.tsx
  2. +42
    -1
      src/components/ProductionProcess/ProductionProcessPage.tsx

+ 3
- 38
src/components/Jodetail/JobPickExecutionsecondscan.tsx View File

@@ -549,52 +549,17 @@ const JobPickExecution: React.FC<Props> = ({ filterArgs, onBack }) => {


useEffect(() => {
unassignExecutedRef.current = false;
const executeUnassign = () => {
if (unassignExecutedRef.current || !currentPickOrderId || !currentUserId) {
return;
}
unassignExecutedRef.current = true;
console.log("🔄 Executing unassign:", currentPickOrderId);
handleUnassignSync(currentPickOrderId);
};
const handleVisibilityChange = () => {
if (document.visibilityState === 'hidden') {
// 页面隐藏时(可能是刷新或登出),执行 unassign
executeUnassign();
}
};
const handleBeforeUnload = () => {
// beforeunload 中无法执行异步操作,使用同步版本
if (currentPickOrderId && currentUserId) {
console.log("🚪 Page unloading, attempting to unassign pick order:", currentPickOrderId);
executeUnassign();
}
};
document.addEventListener('visibilitychange', handleVisibilityChange);
window.addEventListener('beforeunload', handleBeforeUnload);

return () => {
document.removeEventListener('visibilitychange', handleVisibilityChange);
window.removeEventListener('beforeunload', handleBeforeUnload);
// 组件卸载时执行 unassign(但只在未执行过的情况下)
if (!unassignExecutedRef.current && currentPickOrderId && currentUserId) {
executeUnassign();
}
// Cleanup QR scanner
if (isManualScanning) {
console.log("🧹 Second scan component unmounting, stopping QR scanner...");
stopScan();
resetScan();
}

};
}, [currentPickOrderId, currentUserId, isManualScanning, handleUnassignSync, stopScan, resetScan]);
}, [isManualScanning, stopScan, resetScan]);

// 添加:处理返回按钮
const handleBack = useCallback(async () => {


+ 42
- 1
src/components/ProductionProcess/ProductionProcessPage.tsx View File

@@ -25,6 +25,7 @@ type PrinterCombo = {
interface ProductionProcessPageProps {
printerCombo: PrinterCombo[];
}
const STORAGE_KEY = 'productionProcess_selectedMatchingStock';

const ProductionProcessPage: React.FC<ProductionProcessPageProps> = ({ printerCombo }) => {
const [selectedProcessId, setSelectedProcessId] = useState<number | null>(null);
@@ -35,11 +36,51 @@ const ProductionProcessPage: React.FC<ProductionProcessPageProps> = ({ printerCo
const { data: session } = useSession() as { data: SessionWithTokens | null };
const currentUserId = session?.id ? parseInt(session.id) : undefined;

// 从 sessionStorage 恢复状态(仅在客户端)
useEffect(() => {
if (typeof window !== 'undefined') {
try {
const saved = sessionStorage.getItem(STORAGE_KEY);
if (saved) {
const parsed = JSON.parse(saved);
// 验证数据有效性
if (parsed && typeof parsed.jobOrderId === 'number' && typeof parsed.productProcessId === 'number') {
setSelectedMatchingStock(parsed);
console.log("📦 Restored selectedMatchingStock from sessionStorage:", parsed);
}
}
} catch (error) {
console.error("Error restoring selectedMatchingStock:", error);
sessionStorage.removeItem(STORAGE_KEY);
}
}
}, []);

// 保存状态到 sessionStorage
useEffect(() => {
if (typeof window !== 'undefined') {
if (selectedMatchingStock) {
sessionStorage.setItem(STORAGE_KEY, JSON.stringify(selectedMatchingStock));
console.log("💾 Saved selectedMatchingStock to sessionStorage:", selectedMatchingStock);
} else {
sessionStorage.removeItem(STORAGE_KEY);
}
}
}, [selectedMatchingStock]);

// 处理返回列表时清除存储
const handleBackFromSecondScan = useCallback(() => {
setSelectedMatchingStock(null);
if (typeof window !== 'undefined') {
sessionStorage.removeItem(STORAGE_KEY);
}
}, []);

if (selectedMatchingStock) {
return (
<JobPickExecutionsecondscan
filterArgs={{ jobOrderId: selectedMatchingStock.jobOrderId }}
onBack={() => setSelectedMatchingStock(null)}
onBack={handleBackFromSecondScan}
/>
);
}


Loading…
Cancel
Save