From 17b583422095aff6bb91bd8ddff5faeb41c8edb2 Mon Sep 17 00:00:00 2001 From: wuyouming666 <2265557248@qq.com> Date: 星期六, 02 十二月 2023 09:06:24 +0800 Subject: [PATCH] 更新电气管理通讯逻辑 --- CanadaMes-ui/src/views/Electrical/ServoManualone.vue | 224 +++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 159 insertions(+), 65 deletions(-) diff --git a/CanadaMes-ui/src/views/Electrical/ServoManualone.vue b/CanadaMes-ui/src/views/Electrical/ServoManualone.vue index 37f5fea..1fb5565 100644 --- a/CanadaMes-ui/src/views/Electrical/ServoManualone.vue +++ b/CanadaMes-ui/src/views/Electrical/ServoManualone.vue @@ -27,6 +27,18 @@ }}</router-link> <router-link to="/Electrical/Positioning2" tag="el-button" type="text" active-class="blue-button">{{ $t('Positioning2') }}</router-link> + <router-link to="/Electrical/ManualonePosition" tag="el-button" type="text" active-class="blue-button">{{ + $t('ManualonePosition') + }}</router-link> + <router-link to="/Electrical/ManualonePosition2" tag="el-button" type="text" active-class="blue-button">{{ + $t('ManualonePosition2') + }}</router-link> + <router-link to="/Electrical/AutomaticParameterSetting" tag="el-button" type="text" active-class="blue-button">{{ + $t('AutomaticParameterSetting') + }}</router-link> + <router-link to="/Electrical/ManualJog" tag="el-button" type="text" active-class="blue-button">{{ + $t('ManualJog') + }}</router-link> </el-breadcrumb> <el-row :gutter="26"> @@ -44,8 +56,8 @@ </el-row> <div class="button-row" style="display: flex; justify-content: space-between;"> <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex"> - <el-button v-if="item.button" :name="item.button.name" v-model="item.button.value" :class="{'action-button': true, 'error-button': item.button.name === '鏁呴殰' && item.button.value === 1}" @click="updateButtonValue(dataGroup, itemIndex); submitDataToBackend(item.button.name);">{{ item.button.name }}</el-button> - + <el-button v-if="item.button && language === 'en-US' " :name="item.button.name" v-model="item.button.value" :class="{'action-button': true, 'error-button': item.button.name === 'Fault' && item.button.value === 1,'error-button2': item.button.name === 'NotZero' && item.button.value === 0}" @click="updateButtonValue(dataGroup, itemIndex); submitDataToBackend(item.button.name);">{{ item.button.name }}</el-button> + <el-button v-if="item.button && language === 'zh-CN' " :name="item.button.name" v-model="item.button.value" :class="{'action-button': true, 'error-button': item.button.name === '鏁呴殰' && item.button.value === 1,'error-button2': item.button.name === '鏈洖闆�' && item.button.value === 0}" @click="updateButtonValue(dataGroup, itemIndex); submitDataToBackend(item.button.name);">{{ item.button.name }}</el-button> </div> </div> </el-card> @@ -69,22 +81,27 @@ data() { return { jsonData: data , - +language:this.$i18n.locale, // 鍔犺浇鏁翠釜data.json鏂囦欢浣滀负jsonData } }, - created () { + + activated(){ + this.initWebSocket(); - // console.log('jsonData:', this.jsonData); - - }, - mounted() { - window.addEventListener('beforeunload', this.closeSocket); - }, - - beforeUnmount() { - window.removeEventListener('beforeunload', this.closeSocket); - }, + const language = this.$i18n.locale; + console.log(language); + if (language === 'en-US') { + this.replaceChineseWithEnglish(); + } + this.$forceUpdate(); + + + }, +// destroyed(){ +// this.close(); +// this.$router.go(0); +// }, methods: { closeSocket() { // 鍏抽棴 WebSocket 杩炴帴 @@ -104,19 +121,34 @@ // }); }, submitDataToBackend(currentButtonName) { - if (currentButtonName === 'A01鍗婅嚜鍔ㄥ惎鍔�') { + if (currentButtonName === 'A01鍗婅嚜鍔ㄥ惎鍔�' ||currentButtonName === 'A01 Semi-Auto Start') { const data = []; for (let i = 0; i < 1; i++) { - const inputData = this.jsonData[i].filter(item => item.type === '0').map(item => { + const inputData = this.jsonData[i].filter(item => item.type === '0' && item.read !== 9999).map(item => { return { value: item.value }; }); const values = inputData.map(item => item.value); data.push(values); + } + +data.push([], [], []); + +for (let i = 0; i < 1; i++) { + const inputData = this.jsonData[i].filter(item => item.type === '0' && item.read == 9999).map(item => { + return { value: item.value }; + }); + + const values = inputData.map(item => item.value); + + data.push(values); + +} +data.push([]); const jsonObject = { data }; @@ -127,11 +159,11 @@ } - if (currentButtonName === 'A02鍗婅嚜鍔ㄥ惎鍔�') { + if (currentButtonName === 'A02鍗婅嚜鍔ㄥ惎鍔�' ||currentButtonName === 'A02 Semi-Auto Start') { const data2 = []; for (let i = 1; i < 2; i++) { - const inputData = this.jsonData[i].filter(item => item.type === '0').map(item => { + const inputData = this.jsonData[i].filter(item => item.type === '0' && item.read !== 8888).map(item => { return { value: item.value }; }); @@ -141,6 +173,22 @@ } data2.unshift([]); + +data2.push([], [], []); + +for (let i = 1; i < 2; i++) { + const inputData = this.jsonData[i].filter(item => item.type === '0' && item.read == 8888).map(item => { + return { value: item.value }; + }); + + const values2 = inputData.map(item => item.value); + + data2.push(values2); + +} + + + const jsonObject = { data:data2 }; // 鎻愪氦鏁版嵁鍒板悗绔� @@ -150,10 +198,12 @@ } - if (currentButtonName === '澶嶄綅') { + if (currentButtonName === '澶嶄綅' || currentButtonName === 'Reset') { const data2 = []; const resetButtonValues = this.jsonData.map(item => { - const buttonItem = item.find(subItem => subItem.button && subItem.button.name === '澶嶄綅'); + const buttonItem = item.find(subItem => subItem.button && ['澶嶄綅', 'Reset'].includes(subItem.button.name)); + + return buttonItem ? buttonItem.button.value : null; }).filter(value => value !== null); @@ -170,13 +220,17 @@ const jsonString2 = JSON.stringify(jsonObject2); console.log('鎵�鏈塗ype涓�0鐨剉alue:', jsonString2); socket?.send(jsonString2); - window.location.reload(); + setTimeout(()=> + window.location.reload(),2000 + ) + } -if (currentButtonName === '鍥為浂') { +if (currentButtonName === '鍥為浂' || currentButtonName === 'Home') { const data3 = []; const resetButtonValues3 = this.jsonData.map(item => { - const buttonItem3 = item.find(subItem => subItem.button && subItem.button.name === '鍥為浂'); + const buttonItem3 = item.find(subItem => subItem.button && ['鍥為浂', 'Home'].includes(subItem.button.name)); + return buttonItem3 ? buttonItem3.button.value : null; }).filter(value => value !== null); @@ -193,13 +247,15 @@ const jsonString3 = JSON.stringify(jsonObject3); console.log('鍥為浂:', jsonString3); socket?.send(jsonString3); - window.location.reload(); + setTimeout(()=> + window.location.reload(),2000 + ) } - if (currentButtonName === 'A01鍗婅嚜鍔�') { + if (currentButtonName === 'A01鍗婅嚜鍔�' || currentButtonName === 'A01 Semi-Auto' ) { const elements = document.getElementsByClassName('special-class'); for (let i = 0; i < elements.length; i++) { if (elements[i].style.display === 'none') { @@ -207,8 +263,7 @@ } } } - - if (currentButtonName === 'A02鍗婅嚜鍔�') { + if (currentButtonName === 'A02鍗婅嚜鍔�' || currentButtonName === 'A02 Semi-Auto' ) { const elements = document.getElementsByClassName('special-class2'); for (let i = 0; i < elements.length; i++) { if (elements[i].style.display === 'none') { @@ -252,7 +307,8 @@ } let obj = JSON.parse(msg.data); - console.log(obj) + // console.log(obj) +const weihuiling=obj.weihuiling; const jsonData2 = this.jsonData; const handleMouseMove = throttle(function(event) { @@ -262,62 +318,68 @@ // 鎵ц鏇存柊閫昏緫 for (let i = 0; i < 6; i++) { jsonData2[i].forEach((item, index) => { - if (typeof item.value !== 'undefined' && typeof obj[`zuhe${i+1}`][0][index] !== 'undefined') { + if (typeof item.value !== 'undefined' && typeof obj[`zuhe${i+1}`][0][index] !== 'undefined'&& item.read !== '9999' && item.read !== '8888') { item.value = obj[`zuhe${i+1}`][0][index]; } }); } -// 閬嶅巻guzhang鏁扮粍 -for (let i = 0; i < obj.guzhang[0].length; i++) { - const guzhangValue = obj.guzhang[0][i]; - - // 鏌ユ壘jsonData2涓甫鏈�"button"鐨勫璞★紝骞朵笖name绛変簬"鏁呴殰" - for (let j = 0; j < jsonData2.length; j++) { - const section = jsonData2[j]; - - for (let k = 0; k < section.length; k++) { - const item = section[k]; - - if (item.button && item.button.name === "鏁呴殰") { - // 鏇存柊value灞炴�� - item.button.value = guzhangValue; - break; - } + + + +for (let i = 0; i < jsonData2.length; i++) { + let arr = jsonData2[i]; + for (let j = 0; j < arr.length; j++) { + let obj2 = arr[j]; + if (obj2.button && (obj2.button.name === "鏁呴殰" || obj2.button.name === "Fault")) { + obj2.button.value = obj.guzhang[0][i]; + // console.log(obj2.button.value) } - - } + + } -for (let i = 0; i < obj.weihuiling[0].length; i++) { - const weihuilingValue = obj.weihuiling[0][i]; - - // 鏌ユ壘jsonData2涓甫鏈�"button"鐨勫璞★紝骞朵笖name绛変簬"鏁呴殰" - for (let j = 0; j < jsonData2.length; j++) { - const section = jsonData2[j]; - - for (let k = 0; k < section.length; k++) { - const item = section[k]; - - if (item.button && item.button.name === "鏈洖闆�") { - // 鏇存柊value灞炴�� - item.button.value = weihuilingValue; - break; - } +for (let i = 3; i < jsonData2.length; i++) { + let arr2 = jsonData2[i]; + for (let j = 3; j < arr2.length; j++) { + let obj3 = arr2[j]; + if(obj3.button){ + if (obj3.button && (obj3.button.name === "鏈洖闆�" || obj3.button.name === "NotZero" )) { + obj3.button.value = weihuiling[0][i]; + // console.log(obj3.button.value) } - - + + } + } + + } +// console.log(jsonData2) +jsonData2.forEach((item) => { + item.forEach((subItem) => { + if (subItem.read === 9999) { + subItem.value = obj.jinpianid[0]; + } + }); +}); +jsonData2.forEach((item) => { + item.forEach((subItem) => { + if (subItem.read === 8888) { + subItem.value = obj.qupianid[0]; + } + }); +}); } -}, 500); +}, 50); document.addEventListener('mouseover', handleMouseMove); + }; @@ -332,6 +394,9 @@ socket.onerror = function () { console.log("websocket鍙戠敓浜嗛敊璇�"); }; + this.$router.afterEach(function(){ + socket.close(); + }) } }, @@ -339,7 +404,32 @@ socket?.send(JSON.stringify(this.messagepack)); + }, + replaceChineseWithEnglish() { + + + const nameMap= this.$t('ServoManualone') + this.jsonData = this.jsonData.map((item) => { + return item.map((obj) => { + if (obj.name) { + const newName = nameMap[obj.name] || obj.name; + return { ...obj, name: newName }; + } else if (obj.button && obj.button.name) { + const newName = nameMap[obj.button.name] || obj.button.name; + return { ...obj, button: { ...obj.button, name: newName } }; + } else if (obj.title && obj.title.name) { + const newName = nameMap[obj.title.name] || obj.title.name; + return { ...obj, title: { ...obj.title, name: newName } }; + } else { + return obj; } + }); +}); + + +// console.log(this.jsonData) + + }, } } @@ -366,5 +456,9 @@ background-color: red; } +.error-button2 { + background-color: red; +} + </style> \ No newline at end of file -- Gitblit v1.8.0