Commit 6154a8a3c4f94fd8ead478822983c85b1eed3707
1 parent
c67b791d
左侧扫码
Showing
2 changed files
with
140 additions
and
8 deletions
src/mes/common/commonOperationBarComponent/index.js
| ... | ... | @@ -908,6 +908,7 @@ const useCommonOperationBarComponentEvent = props => { |
| 908 | 908 | }; |
| 909 | 909 | |
| 910 | 910 | const CommonOperationBarComponent = basProps => { |
| 911 | + const [value, setValue] = useState(""); | |
| 911 | 912 | if (basProps.belongsToForm && basProps.costomFormOperationBar) |
| 912 | 913 | return basProps.costomFormOperationBar; |
| 913 | 914 | |
| ... | ... | @@ -1005,6 +1006,7 @@ const CommonOperationBarComponent = basProps => { |
| 1005 | 1006 | const { app, form, sModelsId, searchValue } = props; |
| 1006 | 1007 | |
| 1007 | 1008 | let showTypeProps = {}; |
| 1009 | + // let leftShowTypeProps = {} | |
| 1008 | 1010 | if (commonUtils.isNotEmptyObject(searchField)) { |
| 1009 | 1011 | if (sModelsId === "12710101117203990977610") { |
| 1010 | 1012 | const { gdsconfigformslave } = config; |
| ... | ... | @@ -1050,9 +1052,12 @@ const CommonOperationBarComponent = basProps => { |
| 1050 | 1052 | } |
| 1051 | 1053 | |
| 1052 | 1054 | let searchProductProps = {}; |
| 1055 | + | |
| 1053 | 1056 | const searchProductConfig = gdsconfigformslave.filter( |
| 1054 | 1057 | item => item.sName === "sSearchProductName" |
| 1055 | 1058 | ); |
| 1059 | + const letfSearchField = btnLeftConfig.find(x => x.sControlName.includes('ScanLoadMaterial') && x.sButtonParam) | |
| 1060 | + | |
| 1056 | 1061 | if (commonUtils.isNotEmptyArr(searchProductConfig)) { |
| 1057 | 1062 | searchProductConfig[0].placeholder = searchProductConfig[0].showName; |
| 1058 | 1063 | searchProductProps = { |
| ... | ... | @@ -1194,7 +1199,7 @@ const CommonOperationBarComponent = basProps => { |
| 1194 | 1199 | } |
| 1195 | 1200 | |
| 1196 | 1201 | const btnSearch = commonFunc.showLocalMessage(props, 'BtnSearch', '查询'); |
| 1197 | - const letfSearchField = btnLeftConfig.find(x => x.sControlName.includes('ScanLoadMaterial') && x.sButtonParam) | |
| 1202 | + | |
| 1198 | 1203 | let leftShowTypeProps = { |
| 1199 | 1204 | app, |
| 1200 | 1205 | record: {}, |
| ... | ... | @@ -1203,7 +1208,7 @@ const CommonOperationBarComponent = basProps => { |
| 1203 | 1208 | form, |
| 1204 | 1209 | formId: sModelsId, |
| 1205 | 1210 | getFloatNum: props.getFloatNum, |
| 1206 | - onChange: props.onSearchValueChange, | |
| 1211 | + | |
| 1207 | 1212 | showConfig: { |
| 1208 | 1213 | ...letfSearchField, |
| 1209 | 1214 | placeholder: '请输入' |
| ... | ... | @@ -1221,9 +1226,116 @@ const CommonOperationBarComponent = basProps => { |
| 1221 | 1226 | getDateFormat: props.getDateFormat, |
| 1222 | 1227 | bNoMesBlue: true, |
| 1223 | 1228 | record: props.slaveData?.[0], |
| 1224 | - onDropDownBlur: props.onDropDownBlur | |
| 1229 | + onDropDownBlur: props.onDropDownBlur, | |
| 1225 | 1230 | } |
| 1226 | 1231 | const isShow = props.sModelType?.includes('/indexPage/commonList') && props.sModelsId?.includes("172117190122117670007462620") |
| 1232 | + const scanEventTime = useRef(-1); | |
| 1233 | + const userInfo = commonUtils.getAppData("userinfo") | |
| 1234 | + // 执行扫码枪指令 | |
| 1235 | + const handleScanCodeInstructs = (value, bCostom) => { | |
| 1236 | + scanEventTime.current = -1; | |
| 1237 | + // this.handleBtnClick() | |
| 1238 | + props.onProcedureCall({ | |
| 1239 | + btnConfig: letfSearchField, | |
| 1240 | + sValue: { | |
| 1241 | + sproName: value, | |
| 1242 | + inMap: userInfo?.sMachineGuid | |
| 1243 | + }, | |
| 1244 | + onSuccess: () => { | |
| 1245 | + props.onRefresh && props.onRefresh(); | |
| 1246 | + // setValue('') | |
| 1247 | + }, | |
| 1248 | + onConfirm: () => { }, | |
| 1249 | + onError: () => { } | |
| 1250 | + }); | |
| 1251 | + }; | |
| 1252 | + // 判断是否扫码枪输入 | |
| 1253 | + const isScannerInput = event => { | |
| 1254 | + const thresholdMs = 50; // 扫码枪输入间隔时间阈值(毫秒) | |
| 1255 | + const lastInputTime = event.timeStamp; | |
| 1256 | + | |
| 1257 | + if (!event.repeat) { | |
| 1258 | + if (!("lastInputTime" in window)) { | |
| 1259 | + window.lastInputTime = lastInputTime; | |
| 1260 | + scanEventTime.current = 0; | |
| 1261 | + return false; | |
| 1262 | + } | |
| 1263 | + | |
| 1264 | + const timeDiff = lastInputTime - window.lastInputTime; | |
| 1265 | + window.lastInputTime = lastInputTime; | |
| 1266 | + | |
| 1267 | + if (timeDiff <= thresholdMs) { | |
| 1268 | + scanEventTime.current += 1; | |
| 1269 | + return true; | |
| 1270 | + } | |
| 1271 | + } | |
| 1272 | + | |
| 1273 | + scanEventTime.current = 0; | |
| 1274 | + return false; | |
| 1275 | + }; | |
| 1276 | + const timer = useRef(null); | |
| 1277 | + // const timerNew = useRef(null); | |
| 1278 | + useEffect( | |
| 1279 | + () => { | |
| 1280 | + if (value === "") return; | |
| 1281 | + | |
| 1282 | + // 10s后清空数据 | |
| 1283 | + clearTimeout(timer.current); | |
| 1284 | + timer.current = setTimeout(() => { | |
| 1285 | + setValue(""); | |
| 1286 | + }, 10000); | |
| 1287 | + }, | |
| 1288 | + [value] | |
| 1289 | + ); | |
| 1290 | + | |
| 1291 | + const scannedData = useRef(""); | |
| 1292 | + const scannedDataTimer = useRef(null); | |
| 1293 | + | |
| 1294 | + useEffect(() => { | |
| 1295 | + const keypressEvent = event => { | |
| 1296 | + if ( | |
| 1297 | + ["textarea", "input"].includes( | |
| 1298 | + document.activeElement.tagName.toLowerCase() | |
| 1299 | + ) | |
| 1300 | + ) | |
| 1301 | + return; | |
| 1302 | + | |
| 1303 | + if (document.activeElement.tagName.toLowerCase() === "button") { | |
| 1304 | + document.querySelectorAll("button").forEach(btn => { | |
| 1305 | + btn.blur(); | |
| 1306 | + }); | |
| 1307 | + } | |
| 1308 | + | |
| 1309 | + // 获取按键的字符值 | |
| 1310 | + const keyValue = event.key; | |
| 1311 | + | |
| 1312 | + // 检查是否为可打印字符 | |
| 1313 | + if (keyValue.length === 1) { | |
| 1314 | + // 添加到已扫描的数据字符串 | |
| 1315 | + scannedData.current += keyValue; | |
| 1316 | + } else if (event.key === "Enter") { | |
| 1317 | + // 如果扫码枪以回车键结束,则处理已扫描的数据 | |
| 1318 | + setValue(scannedData.current); | |
| 1319 | + handleScanCodeInstructs(scannedData.current, false); | |
| 1320 | + | |
| 1321 | + // 清空已扫描的数据 | |
| 1322 | + scannedData.current = ""; | |
| 1323 | + } | |
| 1324 | + | |
| 1325 | + clearTimeout(scannedDataTimer.current); | |
| 1326 | + scannedDataTimer.current = setTimeout(() => { | |
| 1327 | + scannedData.current = ""; | |
| 1328 | + }, 200); | |
| 1329 | + }; | |
| 1330 | + | |
| 1331 | + // 监听 keypress 事件 | |
| 1332 | + document.body.addEventListener("keypress", keypressEvent); | |
| 1333 | + | |
| 1334 | + return () => { | |
| 1335 | + // 在组件卸载时移除事件监听 | |
| 1336 | + document.body.removeEventListener("keypress", keypressEvent); | |
| 1337 | + }; | |
| 1338 | + }, []); | |
| 1227 | 1339 | return ( |
| 1228 | 1340 | <div className={styles.commonOperationBar}> |
| 1229 | 1341 | <div className="leftBar"> |
| ... | ... | @@ -1268,10 +1380,30 @@ const CommonOperationBarComponent = basProps => { |
| 1268 | 1380 | ); |
| 1269 | 1381 | } else if (isShow) { |
| 1270 | 1382 | return <div className="changeClassName"> |
| 1271 | - <ShowType {...leftShowTypeProps} /> | |
| 1272 | - {/* <Button type="primary" size="large" onClick={handleBtnSearch}> | |
| 1273 | - {btnSearch} | |
| 1274 | - </Button> */} | |
| 1383 | + <Input | |
| 1384 | + placeholder="请输入" | |
| 1385 | + value={value} | |
| 1386 | + onChange={event => { | |
| 1387 | + if (value && scanEventTime.current === -1) { | |
| 1388 | + setValue(event.target.value[event.target.value.length - 1]); | |
| 1389 | + isScannerInput(event); | |
| 1390 | + } else { | |
| 1391 | + isScannerInput(event); | |
| 1392 | + setValue(event.target.value); | |
| 1393 | + } | |
| 1394 | + }} | |
| 1395 | + onPressEnter={() => { | |
| 1396 | + handleScanCodeInstructs(value, scanEventTime.current < 5); | |
| 1397 | + }} | |
| 1398 | + suffix={ | |
| 1399 | + <ScanOutlined | |
| 1400 | + style={{ | |
| 1401 | + fontSize: 30, | |
| 1402 | + color: "rgba(0,0,0,0.3)" | |
| 1403 | + }} | |
| 1404 | + /> | |
| 1405 | + } | |
| 1406 | + /> | |
| 1275 | 1407 | </div> |
| 1276 | 1408 | } |
| 1277 | 1409 | return ( | ... | ... |
src/mes/indexMes/index.js
| ... | ... | @@ -684,7 +684,7 @@ const SiderComponent = () => { |
| 684 | 684 | } |
| 685 | 685 | ]; |
| 686 | 686 | let menuLists = [] |
| 687 | - managementData.forEach(item=>{ | |
| 687 | + managementData && managementData?.forEach(item=>{ | |
| 688 | 688 | const i = menuList.findIndex(x=>x.title === item.sMenuName) |
| 689 | 689 | if (i !== -1){ |
| 690 | 690 | menuLists.push(menuList[i]) | ... | ... |