main
wangqiujuan0808 2024-05-07 17:31:52 +08:00
parent 88bcff5741
commit 972993be58
5 changed files with 77 additions and 79 deletions

View File

@ -55,29 +55,33 @@ const infoApi = {
// },
//
getMb(params) {
return postPBRequest('/template', params, 54000)
return postPBRequest('/template', params, 55000)
},
//
addMb(params) {
return postPBRequest('/template', params, 54100)
return postPBRequest('/template', params, 55100)
},
//
//
editMb(params) {
return postPBRequest('/template', params, 54200)
return postPBRequest('/template', params, 55200)
},
//
delMb(params) {
return postPBRequest('/template', params, 54300)
return postPBRequest('/template', params, 55300)
},
//
addP(params) {
return postPBRequest('/tx/mb', params)
return postPBRequest('/template', params, 56100)
},
//
getTemplateType(params) {
return postPBRequest('/template', params, 55001)
},
// //
// getP(params) {
// return postJsonRequest('/tx/mb/info', params)
// },
//
getP(params) {
return postPBRequest('/template', params, 56000)
},
// //
// getSet(params) {
// return postJsonRequest('/tx/info', params)

View File

@ -9,7 +9,7 @@
</el-form-item>
<el-form-item label="模板类型:" prop="type">
<el-select v-model="addForm.type" clearable placeholder="请选择模板类型" @change="driveChange" :disabled="type!=='I'">
<el-select v-model="addForm.type" clearable placeholder="请选择模板类型" @change="driveChange" :disabled="type !== 'I'">
<el-option v-for="(item, index) of typeOptions" :key="index" :label="item.name" :value="item.key" />
</el-select>
</el-form-item>
@ -28,7 +28,7 @@ import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
// import { mb_list, mb_info, response} from '../proto/data/pd'
export default {
props: ["formData", "dialogVisible", "type"],
props: ["formData", "dialogVisible", "type", "templateData"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const ruleFormRef = ref(null);
@ -45,17 +45,10 @@ export default {
{ required: true, message: "请选择类型", trigger: "blur" }
],
},
typeOptions: [
{
key: 1,
name: 'MODBUS'
},
{
key: 2,
name: 'PLC'
}
]
typeOptions: []
});
const visible = computed(() => {
return props.dialogVisible;
});
@ -64,8 +57,22 @@ export default {
});
onMounted(() => {
state.addForm = props.formData;
getTypeOptions();
});
const getTypeOptions = () => {
console.log(11,props.templateData)
state.typeOptions = [];
for (let i in props.templateData) {
let obj = {
key: Number(i),
name: props.templateData[i]
}
state.typeOptions.push(obj);
console.log(33,state.typeOptions);
}
}
const closeDialog = () => {
ctx.emit("dialogClose");
};

View File

@ -3,17 +3,17 @@
<el-card class="top-title">
<span>模板名称{{ addForm.name }}</span>
<span>模板描述{{ addForm.description }}</span>
<span>模板类型{{ addForm.type == 1 ? 'MODBUS' : 'PLC' }}</span>
<span>模板类型{{ templateData[1] }}</span>
</el-card>
<div class="btns">
<div>
<el-button type="primary" @click="saveP"> </el-button>
<el-button @click="closeDialog"></el-button>
</div>
<div>
<!-- <div>
<el-button type="primary" @click="importData"> </el-button>
<el-button type="primary" @click="exportData"> </el-button>
</div>
</div> -->
</div>
<div>
<el-table :data="propertiesData" height="230" style="width: 100%" border stripe
@ -28,18 +28,18 @@
<el-input v-model="scope.row.address" clearable />
</template>
</el-table-column>
<el-table-column prop="datatype" label="点位类型" align="center" show-overflow-tooltip>
<el-table-column prop="type" label="点位类型" align="center" show-overflow-tooltip>
<template #default="scope">
<el-select v-model="scope.row.datatype" size="mini">
<el-select v-model="scope.row.type" size="mini">
<el-option v-for="item in datatypeArr" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</template>
</el-table-column>
<el-table-column prop="byteorder" label="字节顺序" align="center" show-overflow-tooltip>
<el-table-column prop="byte_order" label="字节顺序" align="center" show-overflow-tooltip>
<template #default="scope">
<el-select v-model="scope.row.byteorder" size="mini">
<el-option v-for="item in byteorderArr" :key="item.value" :label="item.label" :value="item.value" />
<el-select v-model="scope.row.byte_order" size="mini">
<el-option v-for="item in byte_orderArr" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</template>
</el-table-column>
@ -78,7 +78,7 @@ import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
// import { m_point, m_properties, mb_info, response} from '../proto/data/pd'
export default {
props: ["formData", "dialogVisible"],
props: ["formData", "dialogVisible","templateData"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const state = reactive({
@ -106,7 +106,7 @@ export default {
label: 'float64',
value: 'float64'
}],
byteorderArr: [{
byte_orderArr: [{
label: 'null',
value: 'null'
}, {
@ -135,27 +135,23 @@ export default {
onMounted(() => {
state.addForm = props.formData;
console.log(123, props.formData)
//
getPointList();
});
const getPointList = async () => {
const parm = mb_info.encode({
const parm = {
name: state.addForm.name
}).finish();
//
const parm_data = parm.slice(0, parm.length);
const res = await infoApi.getP(parm_data);
const ret = response.decode(new Uint8Array(res));
if (ret.code == 0) {
const propArr = mb_info.decode(ret.data).points;
}
const res = await infoApi.getP(parm);
if (res.code == 0) {
const propArr = res.data || [];
state.propertiesData = [];
propArr.forEach(v => {
state.propertiesData.push({
name: v.name,
address: v.properties[0].value,
datatype: v.properties[1].value,
byteorder: v.properties[2].value,
type: v.properties[1].value,
byte_order: v.properties[2].value,
multplier: v.properties[3].value,
unit: v.properties[4].value,
description: v.properties[5].value,
@ -177,38 +173,16 @@ export default {
if (state.propertiesData.length < 1) {
return ElMessage.error("请添加一条点位");
}
const newArr = [];
state.propertiesData.forEach(item => {
newArr.push(m_point.create({
name: item.name,
properties: [
m_properties.create({
name: 'address', value: item.address
}),
m_properties.create({
name: 'datatype', value: item.datatype
}),
m_properties.create({
name: 'byteorder', value: item.byteorder
}),
m_properties.create({
name: 'multplier', value: item.multplier
}),
m_properties.create({
name: 'unit', value: item.unit
}),
m_properties.create({
name: 'description', value: item.description
})
]
}))
})
console.log(123, newArr)
// const newArr = [];
// state.propertiesData.forEach(item => {
// })
// console.log(123, newArr)
const param = {
name: state.addForm.name,
type: state.addForm.type,
description: state.addForm.description,
points: newArr
points: state.propertiesData
}
const res = await infoApi.addP(param);
if (res.code == 0) {
@ -224,8 +198,8 @@ export default {
let newRow = {
name: '',
address: '',
datatype: 'bool',
byteorder: 'null',
type: 'bool',
byte_order: 'null',
multplier: '',
unit: '',
description: ''

View File

@ -35,7 +35,7 @@ axios.interceptors.response.use(
}
const ret = res.data;
// token
if (ret.code === 2003) {
if (ret.code === 3004) {
localRemove("token");
ElMessage.closeAll();
ElMessage.error(ret.message || "Token异常,请重新登录");

View File

@ -10,7 +10,7 @@
<el-table-column prop="name" label="模板名称" width="240" align="center" show-overflow-tooltip />
<el-table-column prop="type" label="模板类型" width="240" align="center" show-overflow-tooltip>
<template #default="scope">
<span>{{ scope.row.type === 1 ? 'MODBUS' : 'PLC' }}</span>
<span>{{ templateData[scope.row.type]}}</span>
</template>
</el-table-column>
<el-table-column prop="description" label="模板描述" width="600" align="center" show-overflow-tooltip />
@ -29,10 +29,10 @@
</el-table-column>
</el-table>
</div>
<AddMb :type="type" :formData="formData" :dialogVisible="dialogVisible" v-if="dialogVisible"
<AddMb :type="type" :formData="formData" :dialogVisible="dialogVisible" v-if="dialogVisible"
@dialogClose="dialogClose" @dialogSuccess="dialogSuccess">
</AddMb>
<AddPoint :formData="formData1" :dialogVisible="dialogVisible1" v-if="dialogVisible1" @dialogClose="dialogClose"
<AddPoint :formData="formData1" :templateData="templateData" :dialogVisible="dialogVisible1" v-if="dialogVisible1" @dialogClose="dialogClose"
@dialogSuccess="dialogSuccess">
</AddPoint>
</el-card>
@ -59,15 +59,28 @@ export default {
formData: {
name: '',
description: '',
type: 'modbus'
type: '1'
},
formData1: {},
type: 'I'
type: 'I',
templateData: {}
});
onMounted(() => {
getTemplateType();
getTableData();
});
const getTemplateType = async () => {
const res = await infoApi.getTemplateType();
if (res.code == 0) {
//
state.templateData = res.data;
} else {
console.log(res);
}
}
const getTableData = async () => {
const res = await infoApi.getMb();
if (res.code == 0) {