Compare commits

..

2 Commits

Author SHA1 Message Date
wljjp ac0559f5bb 123 2024-05-10 10:44:33 +08:00
wljjp 437368a246 123 2024-05-10 10:44:03 +08:00
2 changed files with 130 additions and 68 deletions

View File

@ -137,8 +137,8 @@ const infoApi = {
return postPBRequest("/driver", params, 53202); return postPBRequest("/driver", params, 53202);
}, },
// //
addPz(params) { addPz(params, header) {
return postPBRequest("/driver", params, 54201, params.driver_name); return postPBRequest("/driver", params, 54201, header.driver_name);
}, },
// com // com
getCom() { getCom() {

View File

@ -1,70 +1,35 @@
<template> <template>
<el-drawer v-model="visible" :title= "pztype + '类型 配置管理'" direction="rtl" :before-close="closeDialog"> <el-drawer v-model="visible" :title= "pztype + '类型 配置管理'" direction="rtl" :before-close="closeDialog">
<el-form :model="form" label-width="120px" :rules="rules" ref="ruleFormRef" v-if="pztypecode === 2"> <!-- 1 -->
<el-form :model="form" label-width="120px" :rules="rules" ref="ruleFormRef" v-if="pztypecode === 1">
<el-form-item label="轮询时间" prop="polling_time"> <el-form-item label="轮询时间" prop="polling_time">
<el-input v-model="form.polling_time" clearable/><span></span> <el-input-number v-model="form.polling_time" :min="1" placeholder="(单位:秒)" clearable/><span></span>
</el-form-item> </el-form-item>
<el-form-item label="失败重试时间" prop="faile_retry_time"> <el-form-item label="失败重试时间" prop="faile_retry_time">
<el-input v-model="form.faile_retry_time" clearable/><span></span> <el-input-number v-model="form.faile_retry_time" :min="1" placeholder="(单位:秒)" clearable/><span></span>
</el-form-item> </el-form-item>
<el-form-item label="主机地址" prop="host"> <el-form-item label="主机地址" prop="host">
<el-input v-model="form.host" clearable/> <el-input v-model="form.host" clearable/>
</el-form-item> </el-form-item>
<el-form-item label="端口号" prop="port"> <el-form-item label="端口号" prop="port">
<el-input v-model="form.port" clearable /> <el-input-number v-model="form.port" :min="1" clearable />
</el-form-item> </el-form-item>
<!-- <el-form-item label="faile_retry_time">
<el-select v-model="form.region" placeholder="please select your zone">
<el-option label="Zone one" value="shanghai" />
<el-option label="Zone two" value="beijing" />
</el-select>
</el-form-item>
<el-form-item label="Activity time">
<el-col :span="11">
<el-date-picker v-model="form.date1" type="date" placeholder="Pick a date" style="width: 100%" />
</el-col>
<el-col :span="2" class="text-center">
<span class="text-gray-500">-</span>
</el-col>
<el-col :span="11">
<el-time-picker v-model="form.date2" placeholder="Pick a time" style="width: 100%" />
</el-col>
</el-form-item>
<el-form-item label="Instant delivery">
<el-switch v-model="form.delivery" />
</el-form-item>
<el-form-item label="Activity type">
<el-checkbox-group v-model="form.type">
<el-checkbox label="Online activities" name="type" />
<el-checkbox label="Promotion activities" name="type" />
<el-checkbox label="Offline activities" name="type" />
<el-checkbox label="Simple brand exposure" name="type" />
</el-checkbox-group>
</el-form-item>
<el-form-item label="Resources">
<el-radio-group v-model="form.resource">
<el-radio label="Sponsor" />
<el-radio label="Venue" />
</el-radio-group>
</el-form-item>
<el-form-item label="Activity form">
<el-input v-model="form.desc" type="textarea" />
</el-form-item> -->
<el-form-item> <el-form-item>
<el-button type="primary" @click="onSubmit"></el-button> <el-button type="primary" @click="onSubmit"></el-button>
<el-button @click="closeDialog"></el-button> <el-button @click="closeDialog"></el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-form :model="form1" label-width="120px" :rules="rules1" ref="ruleFormRef1" v-if="pztypecode === 1"> <!-- 2: 'modbus_rtu' -->
<el-form :model="form2" label-width="120px" :rules="rules2" ref="ruleFormRef2" v-if="pztypecode === 2">
<el-form-item label="轮询时间" prop="polling_time"> <el-form-item label="轮询时间" prop="polling_time">
<el-input v-model="form1.polling_time" clearable/><span></span> <el-input-number v-model="form2.polling_time" :min="1" placeholder="(单位:秒)" clearable/><span></span>
</el-form-item> </el-form-item>
<el-form-item label="失败重试时间" prop="faile_retry_time"> <el-form-item label="失败重试时间" prop="faile_retry_time">
<el-input v-model="form1.faile_retry_time" clearable/><span></span> <el-input-number v-model="form2.faile_retry_time" :min="1" placeholder="(单位:秒)" clearable/><span></span>
</el-form-item> </el-form-item>
<el-form-item label="COM" prop="driver_name"> <el-form-item label="COM" prop="driver_name">
<el-select v-model="form1.driver_name" clearable> <el-select v-model="form2.driver_name" clearable>
<el-option <el-option
v-for="item in comArr" v-for="item in comArr"
:label="item.name" :label="item.name"
:value="item.name" :value="item.name"
@ -73,7 +38,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="数据位" prop="dataBits" clearable> <el-form-item label="数据位" prop="dataBits" clearable>
<el-select v-model="form1.dataBits"> <el-select v-model="form2.dataBits">
<el-option <el-option
v-for="item in dataBitsArr" v-for="item in dataBitsArr"
:label="item.name" :label="item.name"
@ -84,7 +49,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="波特率" prop="baudRate" clearable> <el-form-item label="波特率" prop="baudRate" clearable>
<el-select v-model="form1.baudRate"> <el-select v-model="form2.baudRate">
<el-option <el-option
v-for="item in baudRateArr" v-for="item in baudRateArr"
:label="item.name" :label="item.name"
@ -95,7 +60,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="停止位" prop="stopBits" clearable> <el-form-item label="停止位" prop="stopBits" clearable>
<el-select v-model="form1.stopBits"> <el-select v-model="form2.stopBits">
<el-option <el-option
v-for="item in stopBitsArr" v-for="item in stopBitsArr"
:label="item.name" :label="item.name"
@ -106,7 +71,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="校验类型" prop="parity" clearable> <el-form-item label="校验类型" prop="parity" clearable>
<el-select v-model="form1.parity"> <el-select v-model="form2.parity">
<el-option <el-option
v-for="item in parityArr" v-for="item in parityArr"
:label="item.name" :label="item.name"
@ -116,6 +81,32 @@
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit"></el-button>
<el-button @click="closeDialog"></el-button>
</el-form-item>
</el-form>
<!-- 3: 'plc_s7' -->
<el-form :model="form3" label-width="120px" :rules="rules3" ref="ruleFormRef3" v-if="pztypecode === 3">
<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>
<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>
<el-form-item>
<el-button type="primary" @click="onSubmit"></el-button>
<el-button @click="closeDialog"></el-button>
</el-form-item>
</el-form> </el-form>
@ -125,7 +116,7 @@
import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue"; import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue";
import infoApi from "@/api/infoApi.js"; import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus"; import { ElMessage, ElMessageBox } from "element-plus";
export default {//2: 'modbus_rtu', 3: 'plc_s7' export default {
props: ["formData", "dialogVisible", "pztype", "pztypecode"], props: ["formData", "dialogVisible", "pztype", "pztypecode"],
emits: ["dialogClose", "dialogSuccess"], emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) { setup(props, ctx) {
@ -138,14 +129,23 @@ export default {//2: 'modbus_rtu', 3: 'plc_s7'
port: '', port: '',
id: 1, id: 1,
}, },
form1: { form2: {
polling_time: "", polling_time: "",
faile_retry_time: "", faile_retry_time: "",
driver_name: '', driver_name: '',
dataBits: '', dataBits: 5,
baudRate: '', baudRate: 2480,
stopBits: '', stopBits: 1,
parity: '' parity: 'N',
id: 1
},
form3: {
polling_time: "",
faile_retry_time: "",
host: '',
slot: '',
rack: 1,
id: 1
}, },
comArr: [],// com comArr: [],// com
baudRateArr: [{ baudRateArr: [{
@ -221,7 +221,7 @@ export default {//2: 'modbus_rtu', 3: 'plc_s7'
      }}, trigger: 'blur' }],       }}, trigger: 'blur' }],
port: [{ required: true, message: "请输入端口号", trigger: "blur" }] port: [{ required: true, message: "请输入端口号", trigger: "blur" }]
}, },
rules1: { rules2: {
polling_time: [{ required: true, message: "请输入轮询时间", trigger: "blur" }], polling_time: [{ required: true, message: "请输入轮询时间", trigger: "blur" }],
faile_retry_time: [{ required: true, message: "请输入失败重试时间", trigger: "blur" }], faile_retry_time: [{ required: true, message: "请输入失败重试时间", trigger: "blur" }],
driver_name: [{ required: true, message: "请选择COM口", trigger: "blur" }], driver_name: [{ required: true, message: "请选择COM口", trigger: "blur" }],
@ -230,21 +230,37 @@ export default {//2: 'modbus_rtu', 3: 'plc_s7'
stopBits: [{ required: true, message: "请选择停止位", trigger: "blur" }], stopBits: [{ required: true, message: "请选择停止位", trigger: "blur" }],
parity: [{ required: true, message: "请选择校验类型", trigger: "blur" }] parity: [{ required: true, message: "请选择校验类型", trigger: "blur" }]
}, },
rules3: {
polling_time: [{ required: true, message: "请输入轮询时间", trigger: "blur" }],
faile_retry_time: [{ required: true, message: "请输入失败重试时间", trigger: "blur" }],
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' }],
rack: [{ required: true, message: "请输入机架号", trigger: "blur" }],
slot: [{ required: true, message: "请输入插槽号", trigger: "blur" }]
},
}); });
const onSubmit = async () => { const onSubmit = async () => {
console.log(555, props.formData.name); console.log(555, props.formData.name);
await ruleFormRef.value.validate(async (valid) => { var header = {
driver_name: props.formData.name
}
if (props.pztypecode === 1) {
await ruleFormRef.value.validate(async (valid) => {
if (valid) { if (valid) {
const param = { var param = {
driver_name: props.formData.name,
polling_time:Number(state.form.polling_time), polling_time:Number(state.form.polling_time),
faile_retry_time: Number(state.form.faile_retry_time), faile_retry_time: Number(state.form.faile_retry_time),
host: state.form.host, host: state.form.host,
port: Number(state.form.port), port: Number(state.form.port),
id: Number(state.form.id) id: Number(state.form.id)
} }
console.log(777, param); const res = await infoApi.addPz(param, header);
const res = await infoApi.addPz(param);
if (res.code == 0) { if (res.code == 0) {
ElMessage.success(res.message || "请求成功"); ElMessage.success(res.message || "请求成功");
ctx.emit("dialogClose"); ctx.emit("dialogClose");
@ -255,6 +271,54 @@ export default {//2: 'modbus_rtu', 3: 'plc_s7'
console.log("error submit!"); console.log("error submit!");
} }
}); });
} else if (props.pztypecode === 2) {
await ruleFormRef2.value.validate(async (valid) => {
if (valid) {
var param = {
polling_time:Number(state.form2.polling_time),
faile_retry_time: Number(state.form2.faile_retry_time),
dataBits: Number(state.form2.dataBits),
baudRate: Number(state.form2.baudRate),
stopBits: Number(state.form2.stopBits),
driver_name: state.form2.driver_name,
parity: state.form2.parity,
id: Number(state.form2.id)
}
const res = await infoApi.addPz(param, header);
if (res.code == 0) {
ElMessage.success(res.message || "请求成功");
ctx.emit("dialogClose");
} else {
ElMessage.error(res.message);
}
} else {
console.log("error submit!");
}
});
} else if (props.pztypecode === 3) {
await ruleFormRef3.value.validate(async (valid) => {
if (valid) {
var param = {
polling_time:Number(state.form3.polling_time),
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) {
ElMessage.success(res.message || "请求成功");
ctx.emit("dialogClose");
} else {
ElMessage.error(res.message);
}
} else {
console.log("error submit!");
}
});
}
} }
const visible = computed(() => { const visible = computed(() => {
return props.dialogVisible; return props.dialogVisible;
@ -268,9 +332,7 @@ export default {//2: 'modbus_rtu', 3: 'plc_s7'
if (res.code == 0) { if (res.code == 0) {
state.comArr = res.data; state.comArr = res.data;
console.log(44, state.comArr); console.log(44, state.comArr);
nextTick(() => { state.form2.driver_name = state.comArr[0].name;
drawEchart();
});
} }
}; };
const closeDialog = () => { const closeDialog = () => {
@ -297,7 +359,7 @@ export default {//2: 'modbus_rtu', 3: 'plc_s7'
::v-deep .el-form-item__content { ::v-deep .el-form-item__content {
display: flex; display: flex;
flex-wrap: nowrap; flex-wrap: nowrap;
span { >span {
margin-left: 10px; margin-left: 10px;
} }
} }