diff --git a/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx b/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx index 6864342..556e6a8 100644 --- a/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx +++ b/src/components/FinishedGoodSearch/GoodPickExecutiondetail.tsx @@ -1584,36 +1584,7 @@ const handleSubmitPickQtyWithQty = useCallback(async (lot: any, submitQty: numbe {/* DO Header */} - {fgPickOrdersLoading ? ( - - - - ) : ( - fgPickOrders.length > 0 && ( - - - {/* 基本信息 */} - - - {t("Shop Name")}: {fgPickOrders[0].shopName || '-'} - - - {t("Store ID")}: {fgPickOrders[0].storeId || '-'} - - - {t("Ticket No.")}: {fgPickOrders[0].ticketNo || '-'} - - - {t("Departure Time")}: {fgPickOrders[0].DepartureTime || '-'} - - - - - - - - ) - )} + diff --git a/src/components/ProductionProcess/OperatorScanner.tsx b/src/components/ProductionProcess/OperatorScanner.tsx index 9628736..80696fb 100644 --- a/src/components/ProductionProcess/OperatorScanner.tsx +++ b/src/components/ProductionProcess/OperatorScanner.tsx @@ -13,6 +13,9 @@ import { import CloseIcon from "@mui/icons-material/Close"; import { isOperatorExist } from "@/app/api/jo/actions"; import { OperatorQrCode } from "./types"; +// ✅ 新增:导入 user API +import { fetchUserDetails } from "@/app/api/user/actions"; +import { fetchNameList } from "@/app/api/user/actions"; interface OperatorScannerProps { operators: Operator[]; @@ -27,19 +30,20 @@ const OperatorScanner: React.FC = ({ operators, onOperatorsChange, error, - isActive=false, + isActive = false, onActivate, onDeactivate, }) => { const [scanningMode, setScanningMode] = useState(false); const [scanError, setScanError] = useState(null); const operatorScanRef = useRef(null); + useEffect(() => { if (!isActive && scanningMode) { - stopScanning(); } }, [isActive]); + const startScanning = (): void => { setScanningMode(true); setScanError(null); @@ -67,6 +71,54 @@ const OperatorScanner: React.FC = ({ console.log("Raw input:", usernameInput); try { + // ✅ 检查是否是测试快捷格式 {2fitest} + const testMatch = usernameInput.match(/\{2fitest(\d+)\??}?/i); + if (testMatch && testMatch[1]) { + const userId = parseInt(testMatch[1]); + console.log(`🧪 Test mode: Fetching user with ID ${userId} from API`); + + try { + // ✅ 方案 1:使用 fetchNameList 获取所有用户,然后找到对应 ID + const nameList = await fetchNameList(); + const matchedUser = nameList.find(user => user.id === userId); + + if (matchedUser) { + // ✅ 将 NameList 转换为 Operator 格式 + const operator: Operator = { + id: matchedUser.id, + name: matchedUser.name, + username: `user${matchedUser.id}`, // 生成一个 username + }; + + const isAlreadyAdded = operators.some( + (op) => op.id === operator.id, + ); + + if (!isAlreadyAdded) { + onOperatorsChange([...operators, operator]); + } + + target.value = ""; + setScanError(null); + console.log(`✅ Added operator from API:`, operator); + return; + } else { + setScanError( + `User with ID ${userId} not found. Please check the ID and try again.` + ); + target.value = ""; + return; + } + } catch (apiError) { + console.error("Error fetching user by ID:", apiError); + setScanError( + "Failed to fetch user data. Please try again." + ); + target.value = ""; + return; + } + } + let username: string; // ✅ 尝试解析 JSON @@ -163,7 +215,6 @@ const OperatorScanner: React.FC = ({ variant="outlined" size="small" sx={{ bgcolor: "white" }} - onInput={handleOperatorScan} />