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/AutomaticParameterSetting.vue | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 41 insertions(+), 10 deletions(-) diff --git a/CanadaMes-ui/src/views/Electrical/AutomaticParameterSetting.vue b/CanadaMes-ui/src/views/Electrical/AutomaticParameterSetting.vue index 64b71e0..8f34e82 100644 --- a/CanadaMes-ui/src/views/Electrical/AutomaticParameterSetting.vue +++ b/CanadaMes-ui/src/views/Electrical/AutomaticParameterSetting.vue @@ -47,10 +47,10 @@ <el-row :gutter="20"> <el-col :span="12" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex"> - <el-card class="json-block" style="width:485px;"> + <el-card class="json-block" style="width:585px;"> <div v-for="(item, itemIndex) in dataGroup" :key="itemIndex" class="item-container"> <div class="item-row" v-if="item.type === '0'"> - <span class="name" v-if="item.type === '0'" style="width:150px;">{{ item.name }}</span> + <span class="name" v-if="item.type === '0'" style="width:300px;">{{ item.name }}</span> <el-input style="width:250px;" v-if="item.type === '0'" v-model="item.value" class="input-box" @keyup.enter.native="submitDataToBackend"></el-input> </div> @@ -76,12 +76,23 @@ jsonData: data // 鍔犺浇鏁翠釜data.json鏂囦欢浣滀负jsonData } }, - created () { + activated () { + this.initWebSocket(); - // console.log('jsonData:', this.jsonData); + const language = this.$i18n.locale; + console.log(language); + if (language === 'en-US') { + this.replaceChineseWithEnglish(); + } + this.$forceUpdate(); + }, methods: { + closeSocket () { + // 鍏抽棴 WebSocket 杩炴帴 + socket.close(); + }, updateButtonValue (dataGroup, itemIndex) { this.$set(dataGroup[itemIndex].button, 'value', 1); // 鐐瑰嚮鎸夐挳鍚庡皢鍊兼敼涓�1 }, @@ -146,7 +157,7 @@ let obj = JSON.parse(msg.data); const jsonData2 = this.jsonData; -console.log(obj); + console.log(obj); const handleMouseMove = throttle(function (event) { const inputBox = document.querySelectorAll('.el-card__body'); @@ -205,20 +216,40 @@ socket.onerror = function () { console.log("websocket鍙戠敓浜嗛敊璇�"); }; + this.$router.afterEach(function () { + socket.close(); + }) } }, - replaceChineseWithEnglish () { - const translation = this.$t('AutomaticParameterSetting'); - this.jsonData = this.jsonData.map(item => { return { name: translation[item.name] || item.name, value: item.value }; }); - // console.log(translation); - }, send () { socket?.send(JSON.stringify(this.messagepack)); }, + replaceChineseWithEnglish () { + + + const nameMap = this.$t('AutomaticParameterSettinglang') + 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 { + return obj; + } + }); + }); + + + console.log(this.jsonData) + + } } } -- Gitblit v1.8.0