ソースを参照

封装开门、关门、灯带的方法。
还料入库、还料离开、领料离开,直接前端调用相关的方法。

yangzhijie 5 ヶ月 前
コミット
8dae2f47b4

+ 3 - 11
src/gate/ControlGate.vue

@@ -145,7 +145,7 @@ import { ref, onMounted } from 'vue';
 import { useRouter } from 'vue-router';
 import { showNotify } from 'vant';
 import { controlGate, controlGateByBigInv, getGateStatus } from '../api/gate.js';
-import { LIGHT_NORMAL, LIGHT_OPEN, LIGHT_CLOSE, LIGHT_ALARM, LIGHT_RESTART } from '../gate/Light.js';
+import { gateController } from '../hardware/GateOperate.js';
 // 图片资源
 import bgImg from '../assets/images/bj.png';
 // import { plugin } from 'postcss';
@@ -174,16 +174,8 @@ const handleControl = async (command, actionName, isBigInv) => {
         // } else {
         //     res = await controlGate(command);
         // }
-        plugin.gateConfig.controlGate(command);
-        if(command == 'OPEN' || command == 'SHOTOPEN'){
-            plugin.gateConfig.controlLight(JSON.stringify(LIGHT_OPEN));
-        }else if(command == 'CLOSE'){
-            plugin.gateConfig.controlLight(JSON.stringify(LIGHT_CLOSE));
-        }else if(command == 'REBOOT'){
-            plugin.gateConfig.controlLight(JSON.stringify(LIGHT_RESTART));
-        }else if(command == 'ALARM'){
-            plugin.gateConfig.controlLight(JSON.stringify(LIGHT_ALARM));
-        }
+        gateController(command);
+        
         showNotify({ type: 'success', message: `${actionName}操作成功`, duration: 2000 });
         // if (res.errorCode === 0) {
         //     showNotify({ type: 'success', message: `${actionName}操作成功`, duration: 2000 });

+ 0 - 54
src/gate/Light.js

@@ -1,54 +0,0 @@
-
-const LIGHT_NORMAL = {
-    'lightEffect': 'BREATH',
-    'breathParams': {
-        'color': 6399885,
-        'speed': 3,
-        'lightOffInterval': 1000,
-    },
-};
-
-const LIGHT_OPEN = {
-    'lightEffect': 'FLOW',
-    'flowParams': {
-        'color': 16777215,
-        'repeat': false,
-        'flowInterval': 1,
-    },
-};
-
-const LIGHT_CLOSE = {
-    'lightEffect': 'FLOW_RESERVE',
-    'flowParams': {
-        'color': 16777215,
-        'repeat': false,
-        'flowInterval': 1,
-    },
-};
-
-const LIGHT_ALARM = {
-    'lightEffect': 'FLASH',
-    'flashParameters': {
-        'color': 16711680,
-        'lightOnInterval': 1000,
-        'lightOffInterval': 1000,
-    },
-};
-
-
-const LIGHT_RESTART = {
-    'lightEffect': 'FLASH',
-    'flashParameters': {
-        'color': 0xFFFFFF,
-        'lightOnInterval': 1000,
-        'lightOffInterval': 1000,
-    },
-};
-
-export {
-    LIGHT_NORMAL,
-    LIGHT_OPEN,
-    LIGHT_CLOSE,
-    LIGHT_ALARM,
-    LIGHT_RESTART,
-};

+ 46 - 0
src/hardware/GateOperate.js

@@ -0,0 +1,46 @@
+// 导入灯光控制常量
+import { LIGHT_NORMAL, LIGHT_OPEN, LIGHT_CLOSE, LIGHT_ALARM, LIGHT_RESTART } from '../hardware/Light.js';
+
+/**
+ * 执行闸机控制的主要函数
+ * @param {string} command - 控制命令,支持 'OPEN', 'SHOTOPEN', 'CLOSE', 'REBOOT', 'ALARM'
+ * @returns {Promise<void>} 异步操作结果
+ */
+const gateController = command => {
+    try {
+        // 验证输入参数
+        if (!command || typeof command !== 'string') {
+            console.error('Invalid command: command must be a non-empty string');
+            return;
+        }
+
+        // 执行闸机控制操作
+        plugin.gateConfig.controlGate(command);
+
+        // 根据命令类型控制对应的灯光状态
+        if (command === 'OPEN' || command === 'SHOTOPEN') {
+            // 开门命令:控制灯光显示开门状态(绿灯常亮)
+            plugin.gateConfig.controlLight(LIGHT_OPEN);
+        } else if (command === 'CLOSE') {
+            // 关门命令:控制灯光显示关门状态(红灯常亮)
+            plugin.gateConfig.controlLight(LIGHT_CLOSE);
+        } else if (command === 'REBOOT') {
+            // 重启命令:控制灯光显示重启状态(黄灯闪烁)
+            plugin.gateConfig.controlLight(LIGHT_RESTART);
+        } else if (command === 'ALARM') {
+            // 报警命令:控制灯光显示报警状态(红灯闪烁)
+            plugin.gateConfig.controlLight(LIGHT_ALARM);
+        } else {
+            // 未知命令处理
+            console.warn(`Unknown gate control command: ${command}`);
+            // 可以设置默认灯光状态或执行其他默认操作
+            plugin.gateConfig.controlLight(LIGHT_NORMAL);
+        }
+    } catch (error) {
+        // 错误处理:记录错误信息并防止程序崩溃
+        console.error('Error controlling gate:', error);
+    }
+};
+
+// 导出函数供其他模块使用
+export { gateController };

+ 82 - 0
src/hardware/Light.js

@@ -0,0 +1,82 @@
+
+// 闸机灯光控制配置常量
+// 用于定义不同状态下的灯光效果和参数
+
+/**
+ * 正常状态灯光配置
+ * 用于闸机待机或正常通行状态
+ * 效果:呼吸灯 - 绿色缓慢呼吸效果
+ */
+const LIGHT_NORMAL = {
+    'lightEffect': 'BREATH',  // 呼吸灯效果
+    'breathParams': {
+        'color': 0x0066FF,      // 呼吸灯颜色 (蓝色: #0066FF)
+        'speed': 3,             // 呼吸速度 (数值越大呼吸越快)
+        'lightOffInterval': 1000, // 呼吸间隔时间 (毫秒)
+    },
+};
+
+/**
+ * 开门状态灯光配置
+ * 用于闸机开门允许通行状态
+ * 效果:流动灯 - 白色单向流动效果
+ */
+const LIGHT_OPEN = {
+    'lightEffect': 'FLOW',     // 流动灯效果
+    'flowParams': {
+        'color': 0xFFFFFF,      // 流动灯颜色 (白色: #FFFFFF)
+        'repeat': false,        // 是否重复播放 (false: 单次播放)
+        'flowInterval': 1,      // 流动间隔 (数值越小流动越快)
+    },
+};
+
+/**
+ * 关门状态灯光配置
+ * 用于闸机关闭禁止通行状态
+ * 效果:反向流动灯 - 白色反向流动效果
+ */
+const LIGHT_CLOSE = {
+    'lightEffect': 'FLOW_RESERVE', // 反向流动灯效果
+    'flowParams': {
+        'color': 0xFFFFFF,      // 流动灯颜色 (白色: #FFFFFF)
+        'repeat': false,        // 是否重复播放 (false: 单次播放)
+        'flowInterval': 1,      // 流动间隔 (数值越小流动越快)
+    },
+};
+
+/**
+ * 报警状态灯光配置
+ * 用于闸机异常或报警状态
+ * 效果:闪烁灯 - 红色闪烁警示效果
+ */
+const LIGHT_ALARM = {
+    'lightEffect': 'FLASH',    // 闪烁灯效果
+    'flashParameters': {
+        'color': 0xFF0000,      // 闪烁灯颜色 (红色: #FF0000)
+        'lightOnInterval': 1000, // 亮灯持续时间 (毫秒)
+        'lightOffInterval': 1000, // 灭灯持续时间 (毫秒)
+    },
+};
+
+/**
+ * 重启状态灯光配置
+ * 用于闸机系统重启状态
+ * 效果:闪烁灯 - 白色闪烁提示效果
+ */
+const LIGHT_RESTART = {
+    'lightEffect': 'FLASH',    // 闪烁灯效果
+    'flashParameters': {
+        'color': 0xFFFFFF,      // 闪烁灯颜色 (白色: #FFFFFF)
+        'lightOnInterval': 1000, // 亮灯持续时间 (毫秒)
+        'lightOffInterval': 1000, // 灭灯持续时间 (毫秒)
+    },
+};
+
+// 导出所有灯光配置常量
+export {
+    LIGHT_NORMAL,    // 正常状态 - 蓝色呼吸灯
+    LIGHT_OPEN,      // 开门状态 - 白色流动灯
+    LIGHT_CLOSE,     // 关门状态 - 白色反向流动灯
+    LIGHT_ALARM,     // 报警状态 - 红色闪烁灯
+    LIGHT_RESTART,   // 重启状态 - 白色闪烁灯
+};

+ 6 - 0
src/stock-in/InConfirm.vue

@@ -106,6 +106,7 @@ import { showNotify } from 'vant';
 import { ref,reactive, onMounted, computed, onUnmounted } from 'vue';
 import { cfStockIn, createStockIn } from '../api/stockIn.js';
 import { areArraysEqual } from '../common/utils.js';
+import { gateController } from '../hardware/GateOperate.js';
 
 // 图片资源
 import bgImg from '../assets/images/bj.png';
@@ -233,7 +234,12 @@ const generateCFStockIn = async params => {
         const res = await createStockIn(params);
 
         if (res.errorCode === 0) {
+
+            // 调用开门操作
+            gateController('SHOTOPEN');
+            
             showNotify({ type: 'success', message: '入库申请已完成,还料任务已创建!' });
+            // 跳转回主页
             router.push('/home');
         } else {
             showNotify({ type: 'danger', message: res.errorMessage });

+ 3 - 0
src/stock-in/ReturnedLeave.vue

@@ -106,6 +106,7 @@ import { showNotify } from 'vant';
 import { ref, onMounted, computed, onUnmounted } from 'vue';
 import { queryCFStockInByUser, backfillCFStockInTime, cfStockInLeave } from '../api/stockIn.js';
 import { areArraysEqual } from '../common/utils.js';
+import { gateController } from '../hardware/GateOperate.js';
 
 // 图片资源
 import bgImg from '../assets/images/bj.png';
@@ -255,6 +256,8 @@ const generateCFStockIn = async params => {
         const res = await backfillCFStockInTime(params);
 
         if (res.errorCode === 0) {
+            // 调用开门操作
+            gateController('SHOTOPEN');
             showNotify({ type: 'success', message: '还料离开已完成!' });
             router.push('/home');
         } else {

+ 2 - 0
src/stock-out/OutboundConfirm.vue

@@ -118,6 +118,7 @@ import { ref, computed, onMounted, onUnmounted } from 'vue';
 import { showNotify } from 'vant';
 import { cfStockOut, createStockOut, cfStockOutLeave,leaveCFWarehouse } from '../api/stockOut.js';
 import { areArraysEqual } from '../common/utils.js';
+import { gateController } from '../hardware/GateOperate.js';
 
 // 图片资源
 import bgImg from '../assets/images/bj.png';
@@ -227,6 +228,7 @@ const handleLeave = async () => {
         const res = await cfStockOutLeave(params);
 
         if (res.errorCode === 0) {
+            gateController('SHOTOPEN');
             showNotify({ type: 'success', message: '领料离开成功' });
             router.push('/home');
         } else {

+ 3 - 3
webpack.dev.js

@@ -43,17 +43,17 @@ module.exports = WebpackMerge.merge(baseConfig, {
         // },
         proxy: {
             '/api': {
-                target: 'http://192.168.1.112:10026/',
+                target: 'http://192.168.50.11:10026/',
                 ws: false,
                 changeOrigin: true,
             },
             '/authApi': {
-                target: 'http://192.168.1.112:10026/',
+                target: 'http://192.168.50.11:10026/',
                 ws: false,
                 changeOrigin: true,
             },
             '/android-device-sdk': {
-                target: 'http://192.168.1.112:10026/',
+                target: 'http://192.168.50.11:10026/',
                 ws: false,
                 changeOrigin: true,
             },