-
+
{{ result.ioType === 'in' ? '入库' : '出库' }}
@@ -52,32 +38,22 @@
{{ formatItemType(result.itemType) }}
-
+
-
+
{{ result.quantity }}
-
- {{ result.unit }}
-
-
+
-
+
确认执行
-
+
重置
@@ -91,6 +67,24 @@ import ProductInfo from '@/components/KLPService/Renderer/ProductInfo';
import RawMaterialInfo from '@/components/KLPService/Renderer/RawMaterialInfo';
import { addStockIoDetail } from '@/api/wms/stockIoDetail';
+// 通用防抖高阶函数(可放在工具类中全局复用)
+function debounce(fn, delay = 300) {
+ let debounceTimer = null; // 闭包保存定时器,避免重复创建
+
+ // 返回被包装后的函数(支持传递参数给业务函数)
+ return function (...args) {
+ // 1. 清除上一次未执行的定时器(核心:避免短时间内重复触发)
+ if (debounceTimer) {
+ clearTimeout(debounceTimer);
+ }
+
+ // 2. 延迟执行业务函数,this 绑定到调用者(适配 Vue 组件上下文)
+ debounceTimer = setTimeout(() => {
+ fn.apply(this, args); // 传递参数+保持this指向(Vue组件实例)
+ }, delay);
+ };
+}
+
export default {
data() {
return {
@@ -104,17 +98,25 @@ export default {
ProductInfo,
RawMaterialInfo,
},
+ created() {
+ // 包装“输入解析+提交”的业务函数,生成带防抖的版本
+ this.debouncedHandleInput = debounce(
+ this.actualParseAndSubmit, // 实际的业务逻辑函数
+ 500 // 防抖延迟时间
+ );
+ },
computed: {
result() {
try {
- return JSON.parse(this.text);
+ const text = JSON.parse(this.text)
+ return text;
} catch (error) {
return {};
}
},
// 验证数据是否有效
isValid() {
- const requiredFields = ['ioType', 'itemType', 'itemId', 'quantity', 'unit'];
+ const requiredFields = ['ioType', 'itemType', 'itemId', 'quantity'];
// 检查是否包含所有必要字段
const hasAllFields = requiredFields.every(field => this.result.hasOwnProperty(field));
// 检查出入库类型是否有效
@@ -123,51 +125,66 @@ export default {
const isItemTypeValid = ['product', 'semi', 'raw_material'].includes(this.result.itemType);
// 检查数量是否为有效数字
const isQuantityValid = !isNaN(Number(this.result.quantity)) && Number(this.result.quantity) > 0;
-
+
return hasAllFields && isIoTypeValid && isItemTypeValid && isQuantityValid;
}
},
methods: {
- handleChange(value) {
- if (!value) {
- this.inputHint = '请输入二维码内容,系统将自动解析';
+ handleInput(value) {
+ const trimmedValue = value.trim();
+
+ // 空值场景:立即反馈,不触发防抖逻辑
+ if (!trimmedValue) {
+ this.inputHint = "请输入二维码内容,系统将自动解析";
return;
}
-
- this.isLoading = true;
-
- // 模拟解析延迟,提升用户体验
- setTimeout(() => {
- try {
- const parsed = JSON.parse(value);
- if (this.isValid) {
- this.inputHint = '数据解析成功,可以提交操作';
- this.$message.success({
- message: '数据解析成功',
- duration: 1500
- });
- // 解析成功后禁用输入框
- this.handleSubmit();
- // this.$refs.textarea.disabled = true;
- console.log(this.$refs.textarea.disabled, '禁用输入框');
- } else {
- this.inputHint = '解析的数据格式不完整,请检查二维码是否正确';
- this.$message.warning({
- message: '数据格式不完整',
- duration: 2000
- });
- }
- } catch (error) {
- this.inputHint = '无法解析数据,请确保输入的是有效的二维码内容';
- this.$message.error({
- message: '解析失败,请检查输入内容',
- duration: 2000
- });
- } finally {
- this.isLoading = false;
- }
- }, 500);
+
+ // 基础校验不通过:立即反馈,不触发防抖逻辑
+ if (!this.isValid) {
+ this.inputHint = "输入内容不符合基础格式要求,请检查";
+ return;
+ }
+
+ // 触发防抖后的业务逻辑(此时已自动防抖)
+ this.debouncedHandleInput(trimmedValue);
},
+
+ // 5. 实际的“JSON解析+提交”业务逻辑(纯业务,无防抖代码)
+ actualParseAndSubmit(validValue) {
+ this.isLoading = true;
+ try {
+ // 1. 解析JSON
+ const parsedData = JSON.parse(validValue);
+
+
+ // if (!this.isValid) {
+ // this.inputHint = "解析的数据格式不完整,请检查二维码是否正确";
+ // this.$message.warning({
+ // message: "数据格式不完整",
+ // duration: 2000,
+ // });
+ // return;
+ // }
+ // 3. 解析成功:反馈+提交
+ this.inputHint = "数据解析成功,可以提交操作";
+ this.$message.success({
+ message: "数据解析成功",
+ duration: 1500,
+ });
+ this.handleSubmit(parsedData); // 调用提交接口
+ } catch (error) {
+ // 6. 解析失败:错误处理
+ this.inputHint = "无法解析数据,请确保输入的是有效的二维码内容";
+ this.$message.error({
+ message: "解析失败,请检查输入内容",
+ duration: 2000,
+ });
+ } finally {
+ // 7. 无论成功/失败,结束加载状态
+ this.isLoading = false;
+ }
+ },
+
handleBlur() {
// 自动重新聚焦,方便连续扫描
this.$nextTick(() => {
@@ -176,9 +193,9 @@ export default {
},
handleSubmit() {
if (!this.isValid) return;
-
+
this.isSubmitting = true;
-
+
addStockIoDetail(this.result)
.then(res => {
this.$message.success({
@@ -337,6 +354,7 @@ export default {
opacity: 0;
transform: translateY(10px);
}
+
to {
opacity: 1;
transform: translateY(0);
diff --git a/klp-ui/src/views/wms/stockIo/panels/detail.vue b/klp-ui/src/views/wms/stockIo/panels/detail.vue
index 246f00c3..3efd6e1a 100644
--- a/klp-ui/src/views/wms/stockIo/panels/detail.vue
+++ b/klp-ui/src/views/wms/stockIo/panels/detail.vue
@@ -208,9 +208,9 @@
-
+
@@ -290,9 +290,9 @@ export default {
quantity: [
{ required: true, message: "数量不能为空", trigger: "blur" }
],
- unit: [
- { required: true, message: "单位不能为空", trigger: "blur" }
- ]
+ // unit: [
+ // { required: true, message: "单位不能为空", trigger: "blur" }
+ // ]
},
ids: [],
single: true,
@@ -467,7 +467,7 @@ export default {
itemType: undefined,
itemId: undefined,
quantity: undefined,
- unit: undefined,
+ // unit: undefined,
batchNo: 'auto',
remark: undefined
};
@@ -594,12 +594,12 @@ export default {
if (type === 'relocation') return 'info';
return 'default';
},
- onItemChange(e) {
- if (e && e.unit) {
- this.form.unit = e.unit;
- this.unitDisabled = true;
- }
- }
+ // onItemChange(e) {
+ // if (e && e.unit) {
+ // this.form.unit = e.unit;
+ // this.unitDisabled = true;
+ // }
+ // }
}
}
diff --git a/scaner/pom.xml b/scaner/pom.xml
index 3c052700..da3d1e31 100644
--- a/scaner/pom.xml
+++ b/scaner/pom.xml
@@ -56,12 +56,23 @@
+
+
+ net.java.dev.jna
+ jna
+ 5.17.0
+
+
+ net.java.dev.jna
+ jna-platform
+ 5.17.0
+
-
- com.klp
- mv-code-reader-ctrl-wrapper
- 1.0.0
-
+
+
+
+
+
org.json
json
@@ -89,4 +100,4 @@
-
\ No newline at end of file
+
diff --git a/scaner/src/main/java/org/example/Main.java b/scaner/src/main/java/org/example/Main.java
index 6c034408..9e0a9364 100644
--- a/scaner/src/main/java/org/example/Main.java
+++ b/scaner/src/main/java/org/example/Main.java
@@ -12,7 +12,6 @@ import org.json.JSONException;
import org.json.JSONObject;
public class Main {
- static HttpRequestUtil http = null;
private static String userIdentity;
// 存储扫码枪输入的字符
private static final BlockingQueue inputQueue = new ArrayBlockingQueue<>(4096);
@@ -24,7 +23,7 @@ public class Main {
public static void main(String[] args) throws InterruptedException {
System.out.print(" ***************程序开始****************** \r\n");
- lockEnglishInputMethod();
+ SCTool.lockEnglishInputMethod();
// 使用BufferedReader获取用户身份,避免关闭System.in
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
@@ -45,9 +44,6 @@ public class Main {
startRawInputListener();
startScanDataProcessor();
- // 初始化HTTP请求工具
- http = new HttpRequestUtil();
- System.out.println("HTTP请求工具创建完成");
System.out.println("提示:1. 使用扫码枪扫描JSON数据;2. 输入 'exit' 并回车退出程序\n");
// 主线程阻塞(直到isExit被标记为true)
@@ -121,9 +117,9 @@ public class Main {
}
// 校验JSON格式
- if (isValidJson(scanInput)) {
+ if (SCTool.isValidJson(scanInput)) {
System.out.println("JSON格式校验通过,开始处理...");
- sendDataToServer(scanInput);
+ SCTool.sendDataToServer(scanInput, userIdentity);
} else {
System.out.println("错误:输入不是有效JSON格式\n");
}
@@ -144,98 +140,4 @@ public class Main {
processorThread.setDaemon(true);
processorThread.start();
}
-
- /**
- * 校验字符串是否为有效JSON
- */
- private static boolean isValidJson(String input) {
- try {
- new JSONObject(input);
- return true;
- } catch (JSONException e) {
- System.out.println("JSON解析失败原因: " + e.getMessage());
- return false;
- }
- }
-
- /**
- * 锁定英文输入法(Windows系统专用)
- */
- private static void lockEnglishInputMethod() {
- try {
- String powerShellCmd = "powershell -Command \"$im = Get-WinUserLanguageList | Where-Object LanguageTag -eq 'en-US'; " +
- "if ($im) { Set-WinUserLanguageList -LanguageList $im -Force; Write-Host 'Success' }\"";
-
- Process process = Runtime.getRuntime().exec(powerShellCmd);
- process.waitFor();
-
- if (process.exitValue() == 0) {
- System.out.println("英文输入法已锁定(en-US)");
- } else {
- System.out.println("PowerShell切换输入法失败,尝试备选方案(Ctrl+空格)");
- sendKeyStroke(0x11, 0x20);
- }
- } catch (Exception e) {
- System.out.println("设置英文输入法异常: " + e.getMessage());
- e.printStackTrace();
- }
- }
-
- /**
- * 发送键盘组合键(用于输入法切换备选方案)
- */
- private static void sendKeyStroke(int modifier, int key) {
- try {
- Robot robot = new Robot();
- robot.keyPress(modifier);
- robot.keyPress(key);
- robot.keyRelease(key);
- robot.keyRelease(modifier);
- System.out.println("已尝试Ctrl+空格切换输入法");
- } catch (AWTException e) {
- System.out.println("发送键盘事件失败: " + e.getMessage());
- }
- }
-
- /**
- * 处理JSON数据并发送POST请求
- */
- private static void sendDataToServer(String jsonInput) {
- try {
- JSONObject json = new JSONObject(jsonInput);
- json.put("createBy", userIdentity);
- String finalJson = json.toString(2);
-
- System.out.println("最终发送的JSON数据: ");
- System.out.println(finalJson + "\n");
-
- // 取消注释以下代码以启用HTTP请求
- String response = HttpRequestUtil.postJson(
- "http://140.143.206.120:8080/wms/stockIoDetail",
- finalJson
- );
-
- if (response == null || response.isEmpty()) {
- System.out.println("服务器无响应,请检查接口连接\n");
- } else {
- System.out.println("服务器返回结果: ");
- String formattedResponse = isJson(response) ? new JSONObject(response).toString(2) : response;
- System.out.println(formattedResponse + "\n");
- }
-
- } catch (JSONException e) {
- System.out.println("JSON处理异常: " + e.getMessage() + "\n");
- } catch (Exception e) {
- System.out.println("发送请求异常: " + e.getMessage() + "\n");
- }
- }
-
- /**
- * 判断字符串是否为JSON格式
- */
- private static boolean isJson(String str) {
- if (str == null || str.isEmpty()) return false;
- str = str.trim();
- return (str.startsWith("{") && str.endsWith("}")) || (str.startsWith("[") && str.endsWith("]"));
- }
}
diff --git a/scaner/src/main/java/org/example/SCTool.java b/scaner/src/main/java/org/example/SCTool.java
new file mode 100644
index 00000000..b03adc10
--- /dev/null
+++ b/scaner/src/main/java/org/example/SCTool.java
@@ -0,0 +1,102 @@
+package org.example;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.awt.*;
+
+public class SCTool {
+ /**
+ * 判断字符串是否为JSON格式
+ */
+ public static boolean isJson(String str) {
+ if (str == null || str.isEmpty()) return false;
+ str = str.trim();
+ return (str.startsWith("{") && str.endsWith("}")) || (str.startsWith("[") && str.endsWith("]"));
+ }
+
+ /**
+ * 校验字符串是否为有效JSON
+ */
+ public static boolean isValidJson(String input) {
+ try {
+ new JSONObject(input);
+ return true;
+ } catch (JSONException e) {
+ System.out.println("JSON解析失败原因: " + e.getMessage());
+ return false;
+ }
+ }
+
+ /**
+ * 锁定英文输入法(Windows系统专用)
+ */
+ public static void lockEnglishInputMethod() {
+ try {
+ String powerShellCmd = "powershell -Command \"$im = Get-WinUserLanguageList | Where-Object LanguageTag -eq 'en-US'; " +
+ "if ($im) { Set-WinUserLanguageList -LanguageList $im -Force; Write-Host 'Success' }\"";
+
+ Process process = Runtime.getRuntime().exec(powerShellCmd);
+ process.waitFor();
+
+ if (process.exitValue() == 0) {
+ System.out.println("英文输入法已锁定(en-US)");
+ } else {
+ System.out.println("PowerShell切换输入法失败,尝试备选方案(Ctrl+空格)");
+ sendKeyStroke(0x11, 0x20);
+ }
+ } catch (Exception e) {
+ System.out.println("设置英文输入法异常: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 发送键盘组合键(用于输入法切换备选方案)
+ */
+ public static void sendKeyStroke(int modifier, int key) {
+ try {
+ Robot robot = new Robot();
+ robot.keyPress(modifier);
+ robot.keyPress(key);
+ robot.keyRelease(key);
+ robot.keyRelease(modifier);
+ System.out.println("已尝试Ctrl+空格切换输入法");
+ } catch (AWTException e) {
+ System.out.println("发送键盘事件失败: " + e.getMessage());
+ }
+ }
+
+ /**
+ * 处理JSON数据并发送POST请求
+ */
+ public static void sendDataToServer(String jsonInput, String userIdentity) {
+ try {
+ JSONObject json = new JSONObject(jsonInput);
+ json.put("createBy", userIdentity);
+ String finalJson = json.toString(2);
+
+ System.out.println("最终发送的JSON数据: ");
+ System.out.println(finalJson + "\n");
+
+ // 取消注释以下代码以启用HTTP请求
+ String response = HttpRequestUtil.postJson(
+ "http://140.143.206.120:8080/wms/stockIoDetail",
+ finalJson
+ );
+
+ if (response == null || response.isEmpty()) {
+ System.out.println("服务器无响应,请检查接口连接\n");
+ } else {
+ System.out.println("服务器返回结果: ");
+ String formattedResponse = SCTool.isJson(response) ? new JSONObject(response).toString(2) : response;
+ System.out.println(formattedResponse + "\n");
+ }
+
+ } catch (JSONException e) {
+ System.out.println("JSON处理异常: " + e.getMessage() + "\n");
+ } catch (Exception e) {
+ System.out.println("发送请求异常: " + e.getMessage() + "\n");
+ }
+ }
+}