From 059083082a6d284821b70eb7bb6805763014c402 Mon Sep 17 00:00:00 2001 From: wujian <14790700720@163.com> Date: 星期六, 16 三月 2024 10:54:46 +0800 Subject: [PATCH] add PLC连接通信 add 扫码数据推送到前端 --- jcdm-ui/src/views/main/kb/engineCheck/index.vue | 92 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 89 insertions(+), 3 deletions(-) diff --git a/jcdm-ui/src/views/main/kb/engineCheck/index.vue b/jcdm-ui/src/views/main/kb/engineCheck/index.vue index a3b2be1..2e2ac99 100644 --- a/jcdm-ui/src/views/main/kb/engineCheck/index.vue +++ b/jcdm-ui/src/views/main/kb/engineCheck/index.vue @@ -44,7 +44,7 @@ <el-row :gutter="10" class="mb8" type="flex" justify="center" style="text-align: center"> <el-col :span="1.5"> - <el-button plain :disabled="buttondisabled" type="primary" style="width:400px;height:160px" v-hasPermi="['bs:formula:add']" @click="forceOnline"> + <el-button plain :disabled="buttondisabled" type="primary" style="width:400px;height:160px" v-hasPermi="['bs:formula:add']"> <span class="el-icon-thumb" style="font-size:40px;color:black"></span> <span style="font-size:45px;color:black"><strong>寮哄埗涓婄嚎</strong></span> </el-button> @@ -77,6 +77,41 @@ import { listOrderScheduling, getOrderScheduling, delOrderScheduling, addOrderScheduling, updateOrderScheduling } from "@/api/main/bs/orderScheduling/orderScheduling"; import { listPassingStationCollection, getPassingStationCollection, delPassingStationCollection, addPassingStationCollection, updatePassingStationCollection } from "@/api/main/da/passingStationCollection/passingStationCollection"; import {listLineInfo} from "@/api/main/bs/lineInfo/lineInfo"; +import WebSocketReconnect from "@/utils/WebsocketTool"; + +// let websocket = null +// //鍒ゆ柇褰撳墠娴忚鍣ㄦ槸鍚︽敮鎸乄ebSocket +// if ('WebSocket' in window) { +// //杩炴帴WebSocket鑺傜偣 +// websocket = new WebSocketReconnect('ws://127.0.0.1:8086/websocket/111122') +// } else { +// alert('娴忚鍣ㄤ笉鏀寔webSocket') +// } +// //鎺ユ敹鍒版秷鎭殑鍥炶皟鏂规硶 +// websocket.socket.onmessage = function (event) { +// let data = event.data +// console.log('鍚庣浼犻�掔殑鏁版嵁:' + data) +// if (data != null && data !== ''){ +// this.result = JSON.parse(data) +// console.log('this.result',this.result) +// // this.form.engineNo = this.result.server_message +// this.transEngineNo = this.result.server_message +// console.log('this.transEngineNo11111111111',this.transEngineNo) +// } +// +// } +// //鐩戝惉绐楀彛鍏抽棴浜嬩欢锛屽綋绐楀彛鍏抽棴鏃讹紝涓诲姩鍘诲叧闂瓀ebsocket杩炴帴锛岄槻姝㈣繛鎺ヨ繕娌℃柇寮�灏卞叧闂獥鍙o紝server绔細鎶涘紓甯搞�� +// window.onbeforeunload = function () { +// websocket.close() +// } +// //鍏抽棴杩炴帴 +// function closeWebSocket() { +// websocket.close() +// } +// //鍙戦�佹秷鎭� +// function send() { +// websocket.socket.send({ kk: 123 }) +// } export default { components: { }, @@ -84,11 +119,15 @@ props: [], data() { return { + websocket: null, + result: {}, + transEngineNo: '', options: [], total: 0, engineCheckList:[], showFlag:false, buttondisabled:true, + mess:'', // 鏌ヨ鍙傛暟 queryParams: { pageNum: 1, @@ -115,10 +154,57 @@ }; }, computed: {}, - watch: {}, + watch: { + // transEngineNo:{ + // handler(newVal,oldVal) { + // console.log('newVal',newVal) + // console.log('oldVal',oldVal) + // this.form.engineNo = newVal + // console.log('11111111111111') + // console.log('this.form.engineNo',this.form.engineNo) + // }, + // immediate:true + // } + }, created() {}, - mounted() {}, + mounted() { + this.initWebSocket() + }, methods: { + initWebSocket: function (){ + //鍒ゆ柇褰撳墠娴忚鍣ㄦ槸鍚︽敮鎸乄ebSocket + if ('WebSocket' in window) { + //杩炴帴WebSocket鑺傜偣 + this.websocket = new WebSocketReconnect('ws://127.0.0.1:8086/websocket/111122') + + //鎺ユ敹鍒版秷鎭殑鍥炶皟鏂规硶 + this.websocket.socket.onmessage = (event) => { + let data = event.data + console.log('鍚庣浼犻�掔殑鏁版嵁:' + data) + if (data != null && data !== ''){ + this.result = JSON.parse(data) + console.log('this.result',this.result) + this.form.engineNo = this.result.server_message + // this.transEngineNo = this.result.server_message + console.log('this.transEngineNo11111111111',this.transEngineNo) + } + } +//鐩戝惉绐楀彛鍏抽棴浜嬩欢锛屽綋绐楀彛鍏抽棴鏃讹紝涓诲姩鍘诲叧闂瓀ebsocket杩炴帴锛岄槻姝㈣繛鎺ヨ繕娌℃柇寮�灏卞叧闂獥鍙o紝server绔細鎶涘紓甯搞�� + window.onbeforeunload = function () { + this.websocket.close() + } +//鍏抽棴杩炴帴 + function closeWebSocket() { + this.websocket.close() + } +//鍙戦�佹秷鎭� + function send() { + this.websocket.socket.send({ kk: 123 }) + } + } else { + alert('娴忚鍣ㄤ笉鏀寔webSocket') + } + }, reset() { this.form = { engineNo:null, -- Gitblit v1.9.3