<template>
|
<div class="app">
|
<el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb">
|
<router-link to="/Electrical/alarm" tag="el-button" type="text" active-class="blue-button">{{ $t('Alarm')
|
}}</router-link>
|
<router-link to="/Electrical/Sign" tag="el-button" type="text" active-class="blue-button">{{ $t('Sign')
|
}}</router-link>
|
<router-link to="/Electrical/AlbaniaServo" tag="el-button" type="text" active-class="blue-button">{{
|
$t('Parameter')
|
}}</router-link>
|
</el-breadcrumb>
|
<!-- <el-breadcrumb separator-class="el-icon-arrow-right" class="el-breadcrumb">
|
<router-link to="/Electrical/Parameter2" tag="el-button" type="text" active-class="blue-button">
|
{{ $t('Automatic State') }}</router-link>
|
|
<router-link to="/Electrical/ManualonePosition" tag="el-button" type="text" active-class="blue-button">{{
|
$t('ManualonePosition')
|
}}</router-link>
|
|
<router-link v-if="hasPermission" to="/Electrical/Servomanualone" tag="el-button" type="text"
|
active-class="blue-button">
|
{{ $t('Servomanualone') }}
|
</router-link>
|
|
|
<router-link v-if="hasPermission" to="/Electrical/Positioning1" tag="el-button" type="text"
|
active-class="blue-button">{{
|
$t('Address parameter settings')
|
}}</router-link>
|
|
<router-link v-if="hasPermission" to="/Electrical/AutomaticParameterSetting" tag="el-button" type="text"
|
active-class="blue-button">{{
|
$t('Speed parameter settings')
|
}}</router-link>
|
|
<router-link v-if="hasPermission" to="/Electrical/InteractionState" tag="el-button" type="text"
|
active-class="blue-button">{{ $t("InteractionState") }}</router-link>
|
|
</el-breadcrumb> -->
|
|
<el-row :gutter="10">
|
<el-col :span="12" v-for="(dataGroup, groupIndex) in jsonData" :key="groupIndex">
|
<el-card class="json-block" style="width:670px;margin-bottom: 10px;">
|
<div v-for="(item, itemIndex) in dataGroup" :key="itemIndex" class="item-container">
|
<div class="item-row">
|
<span class="name" style="width:300px;">{{ item.CNname }}</span>
|
|
<el-input style="width:300px;"
|
v-if="item.state != 0 && item.type === '0' && groupIndex === 0 && (itemIndex === 2)"
|
@focus="handleInput(groupIndex, itemIndex)" v-model="item.value" class="input-box"
|
:oninput="`value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,2})?).*$/g, '$1');if(value<` + item.min + `){value=` + item.value + `}else if(value>` + item.max + `){value=` + item.value + `}`"></el-input>
|
|
<el-input style="width:300px;" v-else-if="item.state != 0 && item.type === '0' && groupIndex === 0"
|
@focus="handleInput(groupIndex, itemIndex)" v-model="item.value"
|
@keyup.enter.native="WriteWord(dataGroup, itemIndex, 0)" @blur="WriteWord(dataGroup, itemIndex, 1)"
|
class="input-box"
|
:oninput="`value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,2})?).*$/g, '$1');if(value<` + item.min + `){value=` + item.value + `}else if(value>` + item.max + `){value=` + item.value + `}`"></el-input>
|
|
<!-- <el-input style="width: 300px;" v-else-if="(item.state !== 0) && (item.type === '0') && (itemIndex === 2)"
|
v-model="item.value" readonly class="input-box"></el-input> -->
|
|
<el-input style="width:300px;" v-else-if="item.state != 0 && item.type === '0' && groupIndex === 1"
|
@focus="handleInput(groupIndex, itemIndex)" v-model="item.value"
|
@keyup.enter.native="WriteWord(dataGroup, itemIndex, 0)" @blur="WriteWord(dataGroup, itemIndex, 1)"
|
class="input-box"
|
:oninput="`value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,2})?).*$/g, '$1');if(value<` + item.min + `){value=` + item.value + `}else if(value>` + item.max + `){value=` + item.value + `}`"></el-input>
|
<el-input style="width:300px;" v-else-if="item.state != 0 && item.type === '0' && groupIndex === 2"
|
@focus="handleInput(groupIndex, itemIndex)" v-model="item.value"
|
@keyup.enter.native="WriteWord(dataGroup, itemIndex, 0)" @blur="WriteWord(dataGroup, itemIndex, 1)"
|
class="input-box"
|
:oninput="`value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,2})?).*$/g, '$1');if(value<` + item.min + `){value=` + item.value + `}else if(value>` + item.max + `){value=` + item.value + `}`"></el-input>
|
<el-input style="width:300px;" v-else-if="item.state != 0 && item.type === '0' && groupIndex === 3"
|
@focus="handleInput(groupIndex, itemIndex)" v-model="item.value"
|
@keyup.enter.native="WriteWord(dataGroup, itemIndex, 0)" @blur="WriteWord(dataGroup, itemIndex, 1)"
|
class="input-box"
|
:oninput="`value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,2})?).*$/g, '$1');if(value<` + item.min + `){value=` + item.value + `}else if(value>` + item.max + `){value=` + item.value + `}`"></el-input>
|
<el-input style="width:300px;" v-else-if="item.state != 0 && item.type === '0'" v-model="item.value"
|
@focus="handleInput(groupIndex, itemIndex)" class="input-box"
|
@keyup.enter.native="WriteWord(dataGroup, itemIndex, 0)" @blur="WriteWord(dataGroup, itemIndex, 1)"
|
:oninput="`value=value.replace(/^\\D*(\\d*(?:\\.\\d{0,2})?).*$/g, '$1');if(value<` + item.min + `){value=` + item.value + `}else if(value>` + item.max + `){value=` + item.value + `}`"></el-input>
|
<span class="name" style="width:30px;">{{ item.unit }}</span>
|
</div>
|
</div>
|
<div class="button-row" style="display: flex; justify-content: center;flex-wrap: wrap;">
|
<div v-for="(item, itemIndex) in dataGroup" :key="itemIndex">
|
<el-button v-if="item.button && language === 'en-US' && item.state != 0" :name="item.button.CNname"
|
v-model="item.button.value"
|
:class="{ 'action-button': true, 'error-button': item.button.CNname === 'Fault' && item.button.value === 1, 'error-button2': item.button.CNname === 'NotZero' && item.button.value === 0, 'error-button3': item.button.CNname === 'Zero' && item.button.value === 1, 'greenbutton': item.button.CNname !== 'NotZero' && item.button.CNname !== 'Fault' && item.button.value === 1 }"
|
@click="updateButtonValue(dataGroup, itemIndex);">{{
|
item.button.CNname }}</el-button>
|
<el-button v-if="item.button && language === 'zh-CN' && item.state != 0" :name="item.button.CNname"
|
v-model="item.button.value"
|
:class="{ 'action-button': true, 'error-button': item.button.CNname === '故障' && item.button.value === 1, 'error-button2': item.button.CNname === '未回零' && item.button.value === 0, 'error-button3': item.button.CNname === '已回零' && item.button.value === 1, 'greenbutton': item.button.CNname !== '未回零' && item.button.CNname !== '故障' && item.button.value === 1 }"
|
@click="updateButtonValue(dataGroup, itemIndex);">{{
|
item.button.CNname }}</el-button>
|
</div>
|
</div>
|
</el-card>
|
</el-col>
|
</el-row>
|
<!-- <div class="container">
|
|
<component :is="embeddedComponent"></component>
|
<component :is="embeddedComponent2"></component>
|
</div> -->
|
|
<!-- <el-button @click="submitDataToBackend">提交数据到后端</el-button> -->
|
</div>
|
|
</template>
|
|
|
<script>
|
import LanguageMixin from '../../lang/LanguageMixin'
|
import data from '../../configuration/AlbaniaServo'
|
|
// import ManualonePosition2 from './ManualonePosition2.vue';
|
// import ManualJog from './ManualJog.vue';
|
import {
|
SelectPermissionByUserName, currentUsername, WriteWord, WriteBit
|
} from "../../api/home";
|
// import { createWebSocket } from '../../api/websocket.js';
|
let socket;
|
export default {
|
name: "AlbaniaServo",
|
mixins: [LanguageMixin],
|
data() {
|
return {
|
jsonData: data,
|
language: this.$i18n.locale,
|
// embeddedComponent: ManualonePosition2,
|
// embeddedComponent2: ManualJog,
|
hasPermission: false // 默认没有权限
|
|
// 加载整个data.json文件作为jsonData
|
}
|
},
|
activated() {
|
this.initWebSocket();
|
// const language = this.$i18n.locale;
|
//console.log(language);
|
// if (language === 'en-US') {
|
// this.replaceChineseWithEnglish();
|
// }
|
this.$forceUpdate();
|
currentUsername().then(res => {
|
SelectPermissionByUserName(res.data).then(res => {
|
res.data.permission.forEach(item => {
|
if (item.permissionId == "36" && item.state == 1) {
|
this.hasPermission = true;
|
}
|
|
});
|
});
|
|
});
|
|
},
|
methods: {
|
handleInput(groupIndex, itemIndex) {
|
this.jsonData[groupIndex][itemIndex].value2 = 1;
|
|
},
|
closeSocket() {
|
// 关闭 WebSocket 连接
|
socket.close();
|
},
|
updateButtonValue(dataGroup, itemIndex) {
|
// 将当前按钮的值设为1
|
if (dataGroup[itemIndex].button.value === 0) {
|
// 如果当前按钮的值是 0,将其设为 1
|
this.$set(dataGroup[itemIndex].button, 'value', 1);
|
} else {
|
// 否则将其设为 0
|
this.$set(dataGroup[itemIndex].button, 'value', 0);
|
}
|
WriteBit(dataGroup[itemIndex].button.address, dataGroup[itemIndex].button.value).then(res => {
|
if (res.data.message == 200) {
|
this.$message.success(this.$t('Operation successful'));
|
}
|
});
|
|
},
|
WriteWord(dataGroup, itemIndex, index) {
|
if (isNaN(dataGroup[itemIndex].value)) {
|
this.$message.success(this.$t('Operation Please enter number'));
|
} else {
|
WriteWord(dataGroup[itemIndex].address, dataGroup[itemIndex].value).then(res => {
|
if (res.data.message == 200) {
|
this.$message.success(this.$t('Operation successful'));
|
}
|
});
|
}
|
if (index == 1) {
|
this.$set(dataGroup[itemIndex], 'value2', 0);
|
}
|
|
},
|
|
|
initWebSocket() {
|
let viewname = "AlbaniaServo";
|
|
if (typeof WebSocket === "undefined") {
|
console.log("您的浏览器不支持WebSocket");
|
} else {
|
let socketUrl = "ws://" + this.$t('ip') + ":8888" + "/springboot-vue3/api/talk/" + viewname;
|
if (socket != null) {
|
socket.close();
|
socket = null;
|
}
|
|
// 开启一个websocket服务
|
socket = new WebSocket(socketUrl);
|
|
// 打开事件
|
socket.onopen = function () {
|
console.log("websocket已打开");
|
};
|
|
// 收到消息
|
// let isMouseInInputBox = false; // 标记鼠标是否在输入框内
|
|
// const inputBox = document.querySelectorAll('.input-box');
|
// inputBox.forEach(box => {
|
// box.addEventListener('mouseenter', () => {
|
// isMouseInInputBox = true;
|
// });
|
// box.addEventListener('mouseleave', () => {
|
// isMouseInInputBox = false;
|
// });
|
// });
|
socket.onmessage = (msg) => {
|
if (!msg.data) {
|
return; // 如果收到空数据,则直接返回,不执行后续逻辑
|
}
|
|
// 添加判断条件:如果光标在输入框内,则不执行后续逻辑
|
// if (document.activeElement.tagName.toLowerCase() === 'input') {
|
// return;
|
// }
|
// console.log(this.jsonData);
|
let obj = JSON.parse(msg.data);
|
// const weihuiling = obj.weihuiling;
|
|
this.jsonData.forEach((item, index) => {
|
item.forEach((item2, index2) => {
|
|
if (item2.button !== undefined) {
|
switch (index) {
|
case 0:
|
item2.button.value = obj.listpositionparam[0][index2];
|
break;
|
case 1:
|
item2.button.value = obj.listA01param[0][index2];
|
break;
|
case 2:
|
item2.button.value = obj.listA02param[0][index2];
|
break;
|
case 3:
|
item2.button.value = obj.listB01param[0][index2];
|
break;
|
case 4:
|
item2.button.value = obj.listC01param[0][index2];
|
break;
|
case 5:
|
item2.button.value = obj.listC02param[0][index2];
|
break;
|
case 6:
|
item2.button.value = obj.listHollowparam[0][index2];
|
break;
|
default:
|
break;
|
}
|
|
} else {
|
if (item2.value2 !== 1) {
|
switch (index) {
|
case 0:
|
item2.value = obj.listpositionparam[0][index2];
|
break;
|
case 1:
|
item2.value = obj.listA01param[0][index2];
|
break;
|
case 2:
|
item2.value = obj.listA02param[0][index2];
|
break;
|
case 3:
|
item2.value = obj.listB01param[0][index2];
|
break;
|
case 4:
|
item2.value = obj.listC01param[0][index2];
|
break;
|
case 5:
|
item2.value = obj.listC02param[0][index2];
|
break;
|
case 6:
|
item2.value = obj.listHollowparam[0][index2];
|
break;
|
default:
|
break;
|
}
|
}
|
|
}
|
|
});
|
});
|
|
// if (obj.zuhe1) {
|
// console.log(obj);
|
|
// // 执行更新逻辑
|
// for (let i = 0; i < 4; i++) {
|
// jsonData2[i].forEach((item, index) => {
|
// if (typeof item.value !== 'undefined' && typeof obj[`zuhe${i + 1}`][0][index] !== 'undefined') {
|
// item.value = obj[`zuhe${i + 1}`][0][index];
|
// }
|
// });
|
// }
|
// }
|
|
};
|
|
|
|
|
// 关闭事件
|
socket.onclose = function () {
|
console.log("websocket已关闭");
|
};
|
|
// 发生错误事件
|
socket.onerror = function () {
|
console.log("websocket发生了错误");
|
};
|
this.$router.afterEach(function () {
|
socket.close();
|
})
|
|
}
|
},
|
send() {
|
|
|
socket?.send(JSON.stringify(this.messagepack));
|
}
|
|
}
|
}
|
</script>
|
|
<style scoped>
|
.item-row {
|
display: flex;
|
align-items: center;
|
margin-bottom: 2px;
|
/* 调整每个项目之间的间距 */
|
}
|
|
.action-button {
|
margin-right: 10px;
|
background: #66b1ff;
|
color: #FFF;
|
}
|
|
.blue-button {
|
background-color: skyblue;
|
}
|
|
.el-card ::v-deep .el-card__body {
|
padding: 13px;
|
}
|
|
.error-button {
|
background-color: red;
|
}
|
|
.error-button2 {
|
background-color: red;
|
}
|
|
.greenbutton {
|
|
background-color: green;
|
}
|
|
.error-button3 {
|
background-color: green;
|
|
}
|
</style>
|