dataControl/src/components/PzSet.vue

425 lines
14 KiB
Vue
Raw Normal View History

2024-05-08 23:16:25 +08:00
<template>
2024-08-13 20:34:31 +08:00
<el-drawer v-model="visible" direction="rtl" :before-close="closeDialog" title="驱动配置">
2024-06-26 15:51:33 +08:00
<fieldset class="box2">
<legend class="box-ht">驱动名称</legend>
<el-form label-width="130px">
<el-form-item>
2024-08-13 20:34:31 +08:00
{{ form.driver_name }}
2024-06-26 15:51:33 +08:00
</el-form-item>
</el-form>
</fieldset>
2024-08-13 20:34:31 +08:00
<!-- 2 modbus_tcp -->
<el-form size="large" :model="form" label-width="120px" :rules="rules" ref="ruleFormRef" v-if="pztypecode === 2">
2024-06-26 15:51:33 +08:00
<fieldset class="box2">
<legend class="box-ht">通用配置</legend>
<el-form-item label="轮询时间" prop="polling_time">
2024-10-22 14:51:07 +08:00
<el-input-number v-model="form.polling_time" :min="1" placeholder="(单位:毫秒)" clearable /><span>毫秒</span>
2024-06-26 15:51:33 +08:00
</el-form-item>
<el-form-item label="失败重试时间" prop="faile_retry_time">
<el-input-number v-model="form.faile_retry_time" :min="1" placeholder="(单位:秒)" clearable /><span></span>
</el-form-item>
</fieldset>
<fieldset class="box2">
<legend class="box-ht">专属配置</legend>
<el-form-item label="主机地址" prop="host">
<el-input v-model="form.host" clearable />
</el-form-item>
<el-form-item label="端口号" prop="port">
<el-input-number v-model="form.port" :min="1" clearable />
</el-form-item>
2024-08-13 20:34:31 +08:00
<el-form-item label="大小端模式" prop="little_endian">
<el-select v-model="form.little_endian">
<el-option v-for="item in endianArr" :label="item.name" :value="item.value" :key="item.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="字节顺序" prop="wordswap">
<el-select v-model="form.wordswap">
<el-option v-for="item in wordswapArr" :label="item.name" :value="item.value" :key="item.value"></el-option>
</el-select>
</el-form-item>
2024-06-26 15:51:33 +08:00
</fieldset>
2024-05-08 23:16:25 +08:00
</el-form>
2024-08-13 20:34:31 +08:00
<!-- 1: 'modbus_rtu' -->
<el-form size="large" :model="form2" label-width="120px" :rules="rules2" ref="ruleFormRef2" v-if="pztypecode === 1">
2024-06-26 15:51:33 +08:00
<fieldset class="box2">
<legend class="box-ht">通用配置</legend>
<el-form-item label="轮询时间" prop="polling_time">
2024-10-23 00:09:00 +08:00
<el-input-number v-model="form2.polling_time" :min="1" placeholder="(单位:毫秒)" clearable /><span>毫秒</span>
2024-06-26 15:51:33 +08:00
</el-form-item>
<el-form-item label="失败重试时间" prop="faile_retry_time">
<el-input-number v-model="form2.faile_retry_time" :min="1" placeholder="(单位:秒)" clearable /><span></span>
</el-form-item>
</fieldset>
<fieldset class="box2">
<legend class="box-ht">专属配置</legend>
<el-form-item label="COM" prop="com_name">
<el-select v-model="form2.com_name" clearable>
<el-option v-for="item in comArr" :label="item.name" :value="item.name" :key="item.name"></el-option>
</el-select>
</el-form-item>
<el-form-item label="数据位" prop="dataBits" clearable>
<el-select v-model="form2.dataBits">
<el-option v-for="item in dataBitsArr" :label="item.name" :value="item.value" :key="item.value"
clearable></el-option>
</el-select>
</el-form-item>
<el-form-item label="波特率" prop="baudRate" clearable>
<el-select v-model="form2.baudRate">
<el-option v-for="item in baudRateArr" :label="item.name" :value="item.value" :key="item.value"
clearable></el-option>
</el-select>
</el-form-item>
<el-form-item label="停止位" prop="stopBits" clearable>
<el-select v-model="form2.stopBits">
<el-option v-for="item in stopBitsArr" :label="item.name" :value="item.value" :key="item.value"
clearable></el-option>
</el-select>
</el-form-item>
<el-form-item label="校验类型" prop="parity" clearable>
<el-select v-model="form2.parity">
<el-option v-for="item in parityArr" :label="item.name" :value="item.value" :key="item.value"
clearable></el-option>
</el-select>
</el-form-item>
</fieldset>
</el-form>
2024-05-10 10:44:03 +08:00
<!-- 3: 'plc_s7' -->
2024-06-25 15:33:15 +08:00
<!-- <el-form :model="form3" label-width="120px" :rules="rules3" ref="ruleFormRef3" v-if="pztypecode === 3">
2024-06-26 15:51:33 +08:00
<fieldset class="box2">
<legend class="box-ht">通用配置</legend>
<el-form-item label="轮询时间" prop="polling_time">
<el-input-number v-model="form3.polling_time" :min="1" placeholder="(单位:秒)" clearable/><span></span>
</el-form-item>
<el-form-item label="失败重试时间" prop="faile_retry_time">
<el-input-number v-model="form3.faile_retry_time" :min="1" placeholder="(单位:秒)" clearable/><span></span>
</el-form-item>
</fieldset>
<fieldset class="box2">
<legend class="box-ht">专属配置</legend>
<el-form-item label="主机地址" prop="host">
<el-input v-model="form3.host" clearable/>
</el-form-item>
<el-form-item label="机架号" prop="rack">
<el-input-number v-model="form3.rack" :min="1" :max="20" clearable />
</el-form-item>
<el-form-item label="插槽号" prop="slot">
<el-input-number v-model="form3.slot" :min="1" :max="20" clearable />
</el-form-item>
</fieldset>
2024-06-25 15:33:15 +08:00
</el-form> -->
2024-06-26 15:51:33 +08:00
<div class="btns">
2024-06-26 21:37:56 +08:00
<el-button type="primary" size="large" @click="onSubmit"></el-button>
2024-06-26 15:51:33 +08:00
</div>
2024-05-09 18:03:28 +08:00
2024-05-08 23:16:25 +08:00
</el-drawer>
</template>
<script>
import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue";
import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
2024-05-10 10:44:03 +08:00
export default {
2024-05-09 15:45:37 +08:00
props: ["formData", "dialogVisible", "pztype", "pztypecode"],
2024-05-08 23:16:25 +08:00
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const ruleFormRef = ref(null);
2024-06-26 15:51:33 +08:00
const ruleFormRef2 = ref(null);
2024-06-25 15:33:15 +08:00
const ruleFormRef3 = ref(null);
2024-05-08 23:16:25 +08:00
const state = reactive({
form: {
2024-08-13 20:34:31 +08:00
driver_name: '',
2024-05-09 15:45:37 +08:00
polling_time: "",
faile_retry_time: "",
host: '',
port: '',
id: 1,
2024-08-13 20:34:31 +08:00
little_endian: false,
wordswap: false
2024-05-09 15:45:37 +08:00
},
2024-05-10 10:44:03 +08:00
form2: {
2024-06-26 15:51:33 +08:00
polling_time: "",
2024-05-09 18:03:28 +08:00
faile_retry_time: "",
2024-06-25 15:33:15 +08:00
com_name: '',
2024-05-10 10:44:03 +08:00
dataBits: 5,
2024-06-25 15:33:15 +08:00
baudRate: 2400,
2024-05-10 10:44:03 +08:00
stopBits: 1,
parity: 'N',
2024-06-25 15:33:15 +08:00
id: 1,
2024-05-10 10:44:03 +08:00
},
form3: {
polling_time: "",
faile_retry_time: "",
host: '',
slot: '',
rack: 1,
id: 1
2024-05-09 18:03:28 +08:00
},
2024-08-13 20:34:31 +08:00
endianArr: [
{
name: '大端模式',
value: false
},
{
name: '小端模式',
value: true
}
],
wordswapArr: [
{
name: '正常',
value: false
},
{
name: '交换',
value: true
}
],
2024-05-09 18:03:28 +08:00
comArr: [],// com
baudRateArr: [{
2024-06-25 15:33:15 +08:00
name: 2400,
value: 2400
2024-06-26 15:51:33 +08:00
}, {
2024-06-25 15:33:15 +08:00
name: 4800,
2024-06-26 15:51:33 +08:00
value: 4800
2024-05-09 18:03:28 +08:00
},
{
2024-06-26 15:51:33 +08:00
name: 9600,
2024-05-09 18:03:28 +08:00
value: 9600
},
{
2024-06-26 15:51:33 +08:00
name: 19200,
2024-05-09 18:03:28 +08:00
value: 19200
},
{
2024-06-26 15:51:33 +08:00
name: 38400,
2024-05-09 18:03:28 +08:00
value: 38400
},
{
2024-06-26 15:51:33 +08:00
name: 76800,
2024-05-09 18:03:28 +08:00
value: 76800
},
{
2024-06-26 15:51:33 +08:00
name: 115200,
2024-05-09 18:03:28 +08:00
value: 115200
}],
2024-06-26 15:51:33 +08:00
dataBitsArr: [{
2024-05-09 18:03:28 +08:00
name: 5,
value: 5
2024-06-26 15:51:33 +08:00
}, {
2024-05-09 18:03:28 +08:00
name: 6,
2024-06-26 15:51:33 +08:00
value: 6
2024-05-09 18:03:28 +08:00
},
{
2024-06-26 15:51:33 +08:00
name: 7,
2024-05-09 18:03:28 +08:00
value: 7
},
{
2024-06-26 15:51:33 +08:00
name: 8,
2024-05-09 18:03:28 +08:00
value: 8
}],
stopBitsArr: [{
name: 1,
value: 1
2024-06-26 15:51:33 +08:00
}, {
2024-05-09 18:03:28 +08:00
name: 2,
2024-06-26 15:51:33 +08:00
value: 2
2024-05-09 18:03:28 +08:00
}],
parityArr: [{
name: "N",
value: "N"
2024-06-26 15:51:33 +08:00
}, {
2024-05-09 18:03:28 +08:00
name: "E",
value: "E",
2024-06-26 15:51:33 +08:00
}, {
2024-05-09 18:03:28 +08:00
name: "O",
value: "O",
}],
2024-05-09 15:45:37 +08:00
rules: {
polling_time: [{ required: true, message: "请输入轮询时间", trigger: "blur" }],
faile_retry_time: [{ required: true, message: "请输入失败重试时间", trigger: "blur" }],
2024-06-26 15:51:33 +08:00
host: [{
required: true, validator: (rule, value, callback) => {
// 只能输入英文字母
var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
if (value && reg.test(value)) {
callback();
} else {
callback(new Error("请输入正确的ip地址"));
}
}, trigger: 'blur'
}],
2024-08-13 20:34:31 +08:00
port: [{ required: true, message: "请输入端口号", trigger: "blur" }],
little_endian: [{ required: true, message: "请选择大小端模式", trigger: "blur" }],
wordswap: [{ required: true, message: "请选择字节顺序", trigger: "blur" }]
2024-05-09 15:45:37 +08:00
},
2024-05-10 10:44:03 +08:00
rules2: {
2024-05-09 18:03:28 +08:00
polling_time: [{ required: true, message: "请输入轮询时间", trigger: "blur" }],
faile_retry_time: [{ required: true, message: "请输入失败重试时间", trigger: "blur" }],
2024-06-25 15:33:15 +08:00
com_name: [{ required: true, message: "请选择COM口", trigger: "blur" }],
2024-05-09 18:03:28 +08:00
dataBits: [{ required: true, message: "请选择数据位", trigger: "blur" }],
baudRate: [{ required: true, message: "请选择波特率", trigger: "blur" }],
stopBits: [{ required: true, message: "请选择停止位", trigger: "blur" }],
parity: [{ required: true, message: "请选择校验类型", trigger: "blur" }]
},
2024-05-10 10:44:03 +08:00
rules3: {
polling_time: [{ required: true, message: "请输入轮询时间", trigger: "blur" }],
faile_retry_time: [{ required: true, message: "请输入失败重试时间", trigger: "blur" }],
2024-06-26 15:51:33 +08:00
host: [{
required: true, validator: (rule, value, callback) => {
// 只能输入英文字母
var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
if (value && reg.test(value)) {
callback();
} else {
callback(new Error("请输入正确的ip地址"));
}
}, trigger: 'blur'
}],
2024-05-10 10:44:03 +08:00
rack: [{ required: true, message: "请输入机架号", trigger: "blur" }],
slot: [{ required: true, message: "请输入插槽号", trigger: "blur" }]
},
2024-05-08 23:16:25 +08:00
});
2024-05-09 15:45:37 +08:00
const onSubmit = async () => {
2024-05-10 10:44:03 +08:00
var header = {
2024-08-13 20:34:31 +08:00
driver_name: props.formData.driver_name
2024-05-10 10:44:03 +08:00
}
2024-10-23 00:09:00 +08:00
if (props.pztypecode === 2) { //modbus_tcp
2024-05-10 10:44:03 +08:00
await ruleFormRef.value.validate(async (valid) => {
2024-06-26 15:51:33 +08:00
if (valid) {
var param = {
2024-08-13 20:34:31 +08:00
...state.form,
2024-06-26 15:51:33 +08:00
polling_time: Number(state.form.polling_time),
faile_retry_time: Number(state.form.faile_retry_time),
port: Number(state.form.port),
id: Number(state.form.id)
}
const res = await infoApi.addPz(param, header);
if (res.code == 0) {
2024-10-23 00:09:00 +08:00
ElMessage.success(res.data || "请求成功");
2024-06-26 15:51:33 +08:00
ctx.emit("dialogClose");
} else {
2024-10-23 00:09:00 +08:00
ElMessage.error(res.data);
2024-06-26 15:51:33 +08:00
}
2024-05-09 15:45:37 +08:00
} else {
}
2024-06-26 15:51:33 +08:00
});
2024-10-23 00:09:00 +08:00
} else if (props.pztypecode === 1) { // modbus_rtu
2024-05-10 10:44:03 +08:00
await ruleFormRef2.value.validate(async (valid) => {
if (valid) {
2024-06-26 15:51:33 +08:00
var param = {
name: props.formData.name,
polling_time: Number(state.form2.polling_time),
faile_retry_time: Number(state.form2.faile_retry_time),
com: {
name: state.form2.com_name,
dataBits: Number(state.form2.dataBits),
baudRate: Number(state.form2.baudRate),
stopBits: Number(state.form2.stopBits),
parity: state.form2.parity
}
}
2024-05-10 10:44:03 +08:00
const res = await infoApi.addPz(param, header);
if (res.code == 0) {
2024-10-23 00:09:00 +08:00
ElMessage.success(res.data || "请求成功");
2024-05-10 10:44:03 +08:00
ctx.emit("dialogClose");
} else {
2024-10-23 00:09:00 +08:00
ElMessage.error(res.data);
2024-05-10 10:44:03 +08:00
}
} else {
}
});
} else if (props.pztypecode === 3) {
await ruleFormRef3.value.validate(async (valid) => {
if (valid) {
var param = {
2024-06-26 15:51:33 +08:00
polling_time: Number(state.form3.polling_time),
2024-05-10 10:44:03 +08:00
faile_retry_time: Number(state.form3.faile_retry_time),
host: state.form3.host,
rack: Number(state.form3.rack),
slot: Number(state.form3.slot),
id: Number(state.form3.id)
}
const res = await infoApi.addPz(param, header);
if (res.code == 0) {
2024-10-23 00:09:00 +08:00
ElMessage.success(res.data || "请求成功");
2024-05-10 10:44:03 +08:00
ctx.emit("dialogClose");
} else {
2024-10-23 00:09:00 +08:00
ElMessage.error(res.data);
2024-05-10 10:44:03 +08:00
}
} else {
}
});
}
2024-06-26 15:51:33 +08:00
2024-05-08 23:16:25 +08:00
}
const visible = computed(() => {
return props.dialogVisible;
});
onMounted(() => {
2024-08-13 20:34:31 +08:00
getD();
2024-10-23 00:09:00 +08:00
getCom();
2024-05-08 23:16:25 +08:00
});
2024-08-13 20:34:31 +08:00
const getD = async () => {
const parm = {
driver_name: props.formData.driver_name
}
const res = await infoApi.getD(parm);
if (res.code == 0) {
2024-10-23 00:09:00 +08:00
if (props.pztypecode === 2) {
state.form = res.data;
}
if (props.pztypecode === 1) {
state.form2 = res.data;
state.form2.com_name = res.data.com.name;
state.form2.dataBits = Number(res.data.com.dataBits);
state.form2.baudRate = Number(res.data.com.baudRate);
state.form2.stopBits = Number(res.data.com.stopBits);
state.form2.parity = res.data.com.parity;
}
2024-08-13 20:34:31 +08:00
}
};
2024-05-09 18:03:28 +08:00
const getCom = async () => {
2024-06-25 15:33:15 +08:00
const parm = {
2024-06-26 15:51:33 +08:00
name: props.formData.name
2024-06-25 15:33:15 +08:00
}
const res = await infoApi.getCom(parm);
2024-05-09 18:03:28 +08:00
if (res.code == 0) {
2024-06-26 15:51:33 +08:00
state.comArr = res.data.sort((a, b) => {
2024-06-25 16:40:20 +08:00
return (a.name > b.name ? 1 : -1)
});
2024-05-09 18:03:28 +08:00
}
};
2024-05-08 23:16:25 +08:00
const closeDialog = () => {
ctx.emit("dialogClose");
};
const importData = () => { };
const exportData = () => { };
return {
...toRefs(state),
visible,
closeDialog,
importData,
2024-06-26 15:51:33 +08:00
exportData,
2024-05-09 15:45:37 +08:00
onSubmit,
2024-05-09 18:03:28 +08:00
ruleFormRef,
2024-06-25 15:33:15 +08:00
ruleFormRef2,
ruleFormRef3,
2024-05-09 18:03:28 +08:00
getCom
2024-05-08 23:16:25 +08:00
};
},
};
</script>
2024-05-09 15:45:37 +08:00
<style lang="scss" scoped>
::v-deep .el-form-item__content {
display: flex;
flex-wrap: nowrap;
2024-06-26 15:51:33 +08:00
2024-05-10 10:44:03 +08:00
>span {
2024-05-09 15:45:37 +08:00
margin-left: 10px;
}
}
</style>