瓶中沙 2024-05-08 23:26:08 +08:00
commit 9959342a91
6 changed files with 579 additions and 281 deletions

View File

@ -80,14 +80,6 @@ const infoApi = {
detP(params) {
return postPBRequest('/template', params, 53310, params.template_name)
},
// //
// getSet(params) {
// return postJsonRequest('/tx/info', params)
// },
// //
// addSet(params) {
// return putRequest('/tx/device', params)
// },
//
getTx(params) {
return postPBRequest('/driver', params, 54000)
@ -109,19 +101,33 @@ const infoApi = {
getTxSupport() {
return postPBRequest('/driver', null, 54001)
},
//
//
getTxConfig(params) {
return postPBRequest("/driver", params, 53002);
getTxTemplate(params) {
return postPBRequest("/driver", params, 54011, params.driver_name);
},
//
addSet(params) {
return postPBRequest('/driver', params, 54110, params.driver_name)
},
// ,
startStatus(params) {
return postPBRequest("/driver", params,53201);
},
//
stopStatus(params) {
return postPBRequest("/driver", params,53202);
}
//
getSet(params) {
return postPBRequest('/driver', params, 54010, params.driver_name)
},
//
delSet(params) {
return postPBRequest('/driver', params, 54310, params.driver_name)
},
// ,
startStatus(params) {
return postPBRequest("/driver", params, 53201);
},
//
stopStatus(params) {
return postPBRequest("/driver", params, 53202);
}
// //
// getSc(params) {

View File

@ -0,0 +1,262 @@
<template>
<el-dialog
v-model="visible"
title="设备管理"
width="60%"
:before-close="closeDialog"
>
<el-card class="top-title">
<span>通讯名称{{ addForm.name }}</span>
<span>通讯描述{{ addForm.description }}</span>
<span>通讯主机{{ addForm.host }}</span>
</el-card>
<div class="btns">
<div>
<el-button type="primary" @click="saveSet"> </el-button>
<el-button @click="closeDialog"></el-button>
</div>
<div>
<el-button type="primary" @click="scanData"> </el-button>
</div>
</div>
<div>
<el-table
:data="propertiesData"
height="230"
style="width: 100%"
border
stripe
:header-cell-style="{ background: '#F6F7FC' }"
>
<el-table-column
prop="name"
label="设备名称"
align="center"
show-overflow-tooltip
>
<template #default="scope">
<el-input
v-model="scope.row.name"
clearable
/>
</template>
</el-table-column>
<el-table-column
prop="ID"
label="设备id"
align="center"
show-overflow-tooltip
>
<template #default="scope">
<el-input
v-model="scope.row.ID"
clearable
/>
</template>
</el-table-column>
<el-table-column
prop="template"
label="数据模板"
align="center"
show-overflow-tooltip
>
<template #default="scope">
<el-select v-model="scope.row.template" clearable placeholder="请选择模板" size="mini">
<el-option
v-for="item in modelArr"
:key="item.name"
:label="item.name"
:value="item.name"
/>
</el-select>
</template>
</el-table-column>
<el-table-column
prop="description"
label="设备描述"
align="center"
show-overflow-tooltip
>
<template #default="scope">
<el-input
v-model="scope.row.description"
clearable
/>
</template>
</el-table-column>
<el-table-column label="操作" align="center" show-overflow-tooltip>
<template #default="scope">
<el-button type="danger" @click="delData(scope.$index)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex-center" @click="addRow">
+新增一行
</div>
</div>
</el-dialog>
</template>
<script>
import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue";
import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
// import { mb_list, tx_info, response, m_device, m_properties, tx_add_device} from '../proto/data/pd'
export default {
props: ["formData", "dialogVisible"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const state = reactive({
addForm: {},
propertiesData: [],
modelArr: []
});
const visible = computed(() => {
return props.dialogVisible;
});
onMounted(() => {
state.addForm = props.formData;
console.log(123, props.formData)
//
getMbData();
//
getSetList();
});
const getMbData = async () => {
const res = await infoApi.getMb();
const ret = response.decode(new Uint8Array(res));
if (ret.code == 0) {
//
state.modelArr = mb_list.decode(ret.data).mb;
console.log(mb_list.decode(ret.data).mb);
} else {
console.log(res);
}
};
const getSetList = async() => {
const parm = tx_info.encode({
name: state.addForm.name
}).finish();
//
const parm_data = parm.slice(0, parm.length);
const res = await infoApi.getSet(parm_data);
const ret = response.decode(new Uint8Array(res));
if (ret.code == 0) {
console.log(99, tx_info.decode(ret.data).device);
const propArr = tx_info.decode(ret.data).device;
state.propertiesData = [];
propArr.forEach(v => {
state.propertiesData.push({
name: v.name,
ID: v.properties[0].value,
template: v.properties[1].value,
description: v.properties[2].value,
})
})
} else {
console.log(res);
}
};
const closeDialog = () => {
ctx.emit("dialogClose");
};
const scanData = () => {};
const saveSet = async () => {
if (state.propertiesData.length < 1) {
return ElMessage.error("请至少添加一条数据");
}
const newArr = [];
state.propertiesData.forEach(item => {
newArr.push({
name: item.name,
properties: [
{
name: 'ID', value: item.ID
},{
name: 'template', value: item.template
},{
name: 'description', value: item.description
}]
})
})
const req_databuf = tx_add_device.encode({
name: state.addForm.name,
device: newArr
}).finish();
//
const req_data = req_databuf.slice(0, req_databuf.length);
const res = await infoApi.addSet(req_data);
const ret = response.decode(new Uint8Array(res));
if (ret.code == 0) {
console.log(new TextDecoder().decode(ret.data));
ElMessage.success(new TextDecoder().decode(ret.data) || "请求成功");
//
getSetList();
}
};
const addRow = () => {
let newRow = {
name: '',
address: '',
datatype: 'bool',
byteorder: 'null',
multplier: '',
unit: '',
description: ''
};
state.propertiesData.push(newRow);
}
const delData = (index) => {
state.propertiesData.splice(index, 1);
}
return {
...toRefs(state),
visible,
closeDialog,
scanData,
addRow,
saveSet,
delData,
getMbData
};
},
};
</script>
<style lang="scss" scoped>
.top-title {
width: 100%;
::v-deep .el-card__body {
width: 100%;
display: flex;
justify-content: space-between;
font-weight: 800;
font-size: 16px;
}
}
.btns {
padding: 15px 0;
width: 100%;
display: flex;
justify-content: space-between;
}
.flex-center {
display: flex;
justify-content: center;
padding: 10px 0;
cursor: pointer;
}
</style>

View File

@ -1,262 +1,150 @@
<template>
<el-dialog
v-model="visible"
title="设备管理"
width="60%"
:before-close="closeDialog"
>
<el-card class="top-title">
<span>通讯名称{{ addForm.name }}</span>
<span>通讯描述{{ addForm.description }}</span>
<span>通讯主机{{ addForm.host }}</span>
</el-card>
<div class="btns">
<div>
<el-button type="primary" @click="saveSet"> </el-button>
<el-button @click="closeDialog"></el-button>
</div>
<div>
<el-button type="primary" @click="scanData"> </el-button>
</div>
</div>
<div>
<el-table
:data="propertiesData"
height="230"
style="width: 100%"
border
stripe
:header-cell-style="{ background: '#F6F7FC' }"
>
<el-table-column
prop="name"
label="设备名称"
align="center"
show-overflow-tooltip
>
<template #default="scope">
<el-input
v-model="scope.row.name"
clearable
/>
</template>
</el-table-column>
<el-table-column
prop="ID"
label="设备id"
align="center"
show-overflow-tooltip
>
<template #default="scope">
<el-input
v-model="scope.row.ID"
clearable
/>
</template>
</el-table-column>
<el-table-column
prop="template"
label="数据模板"
align="center"
show-overflow-tooltip
>
<template #default="scope">
<el-select v-model="scope.row.template" clearable placeholder="请选择模板" size="mini">
<el-option
v-for="item in modelArr"
:key="item.name"
:label="item.name"
:value="item.name"
/>
</el-select>
</template>
</el-table-column>
<el-table-column
prop="description"
label="设备描述"
align="center"
show-overflow-tooltip
>
<template #default="scope">
<el-input
v-model="scope.row.description"
clearable
/>
</template>
</el-table-column>
<el-table-column label="操作" align="center" show-overflow-tooltip>
<template #default="scope">
<el-button type="danger" @click="delData(scope.$index)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex-center" @click="addRow">
+新增一行
</div>
</div>
</el-dialog>
<el-dialog v-model="visible" title="设备管理" width="60%" :before-close="closeDialog">
<el-form :model="addForm" label-width="100px" :rules="rules" ref="ruleFormRef">
<el-form-item label="设备名称:" prop="name">
<el-input v-model="addForm.name" placeholder="请输入点位名称" clearable />
</el-form-item>
<el-form-item label="设备id:" prop="id">
<el-input v-model="addForm.id" placeholder="请输入设备id" clearable type="number" />
</el-form-item>
<el-form-item label="模板名称:" prop="template_name">
<el-select v-model="addForm.template_name" size="mini" placeholder="请选择模板名称">
<el-option v-for="item in modelArr" :key="item.name" :label="item.name"
:value="item.name" />
</el-select>
</el-form-item>
<el-form-item label="设备描述:" prop="description">
<el-input v-model="addForm.description" placeholder="请输入点位描述" clearable />
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="closeDialog"></el-button>
<el-button type="primary" @click="saveSet"> </el-button>
</span>
</template>
</el-dialog>
</template>
<script>
import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue";
import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
// import { mb_list, tx_info, response, m_device, m_properties, tx_add_device} from '../proto/data/pd'
export default {
props: ["formData", "dialogVisible"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const state = reactive({
addForm: {},
propertiesData: [],
modelArr: []
});
const visible = computed(() => {
return props.dialogVisible;
});
props: ["formData", "dialogVisible"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const ruleFormRef = ref(null);
const state = reactive({
addForm: {
name: '',
template_name: '',
id: 1,
description: ''
},
modelArr: [],
rules: {
name: [{ required: true, message: "请输入设备名称", trigger: "blur" }],
template_name: [{ required: true, message: "请选择模板名称", trigger: "blur" }],
id: [{ required: true, message: "请输入设备ID", trigger: "blur" }],
},
});
const visible = computed(() => {
return props.dialogVisible;
});
onMounted(() => {
state.addForm = props.formData;
console.log(123, props.formData)
//
getMbData();
//
getSetList();
});
const getMbData = async () => {
const res = await infoApi.getMb();
const ret = response.decode(new Uint8Array(res));
if (ret.code == 0) {
//
state.modelArr = mb_list.decode(ret.data).mb;
console.log(mb_list.decode(ret.data).mb);
onMounted(() => {
console.log(123, props.formData)
//
getTxTemplate();
});
const getTxTemplate = async () => {
const param = {
driver_name: props.formData.name
}
const res = await infoApi.getTxTemplate(param);
if (res.code == 0) {
//
state.modelArr = [];
const data = res.data;
for (let i in data) {
let obj = {
key: Number(i),
name: data[i]
}
state.modelArr.push(obj);
console.log(33,state.modelArr);
}
console.log(state.modelArr);
state.addForm.template_name = state.modelArr[0].name;
} else {
console.log(res);
ElMessage.error(res.message || "请求失败");
}
};
const getSetList = async() => {
const parm = tx_info.encode({
name: state.addForm.name
}).finish();
//
const parm_data = parm.slice(0, parm.length);
const res = await infoApi.getSet(parm_data);
const ret = response.decode(new Uint8Array(res));
if (ret.code == 0) {
console.log(99, tx_info.decode(ret.data).device);
const propArr = tx_info.decode(ret.data).device;
state.propertiesData = [];
propArr.forEach(v => {
state.propertiesData.push({
name: v.name,
ID: v.properties[0].value,
template: v.properties[1].value,
description: v.properties[2].value,
})
})
} else {
console.log(res);
}
};
const closeDialog = () => {
ctx.emit("dialogClose");
};
const closeDialog = () => {
ctx.emit("dialogClose");
};
const scanData = () => {};
const scanData = () => { };
const saveSet = async () => {
if (state.propertiesData.length < 1) {
return ElMessage.error("请至少添加一条数据");
}
const newArr = [];
state.propertiesData.forEach(item => {
newArr.push({
name: item.name,
properties: [
{
name: 'ID', value: item.ID
},{
name: 'template', value: item.template
},{
name: 'description', value: item.description
}]
})
})
const req_databuf = tx_add_device.encode({
name: state.addForm.name,
device: newArr
}).finish();
//
const req_data = req_databuf.slice(0, req_databuf.length);
const res = await infoApi.addSet(req_data);
const ret = response.decode(new Uint8Array(res));
if (ret.code == 0) {
console.log(new TextDecoder().decode(ret.data));
ElMessage.success(new TextDecoder().decode(ret.data) || "请求成功");
//
getSetList();
}
};
const addRow = () => {
let newRow = {
name: '',
address: '',
datatype: 'bool',
byteorder: 'null',
multplier: '',
unit: '',
description: ''
};
state.propertiesData.push(newRow);
}
const delData = (index) => {
state.propertiesData.splice(index, 1);
}
return {
...toRefs(state),
visible,
closeDialog,
scanData,
addRow,
saveSet,
delData,
getMbData
};
},
const saveSet = async () => {
console.log(ruleFormRef.value);
await ruleFormRef.value.validate(async (valid) => {
if (valid) {
const param = {
driver_name: props.formData.name,
...state.addForm,
id: Number(state.addForm.id)
}
const res = await infoApi.addSet(param);
if (res.code == 0) {
ElMessage.success(res.message || "请求成功");
ctx.emit("dialogClose");
} else {
ElMessage.error(res.message);
}
} else {
console.log("error submit!");
}
});
};
return {
...toRefs(state),
visible,
closeDialog,
saveSet,
ruleFormRef
};
},
};
</script>
<style lang="scss" scoped>
.top-title {
width: 100%;
::v-deep .el-card__body {
width: 100%;
display: flex;
justify-content: space-between;
font-weight: 800;
font-size: 16px;
}
}
.btns {
padding: 15px 0;
width: 100%;
display: flex;
justify-content: space-between;
width: 100%;
::v-deep .el-card__body {
width: 100%;
display: flex;
justify-content: space-between;
font-weight: 800;
font-size: 16px;
}
}
.btns {
padding: 15px 0;
width: 100%;
display: flex;
justify-content: space-between;
}
.flex-center {
display: flex;
justify-content: center;
padding: 10px 0;
cursor: pointer;
display: flex;
justify-content: center;
padding: 10px 0;
cursor: pointer;
}
</style>

120
src/components/ViewSet.vue Normal file
View File

@ -0,0 +1,120 @@
<template>
<el-dialog v-model="visible" title="设备管理" width="60%" :before-close="closeDialog">
<el-table :data="propertiesData" height="230" style="width: 100%" border stripe
:header-cell-style="{ background: '#F6F7FC' }">
<el-table-column prop="name" label="设备名称" align="center" show-overflow-tooltip>
</el-table-column>
<el-table-column prop="id" label="设备ID" align="center" show-overflow-tooltip>
</el-table-column>
<el-table-column prop="template_name" label="设备的可用模板名称" align="center" show-overflow-tooltip>
</el-table-column>
<el-table-column prop="description" label="设备描述" align="center" show-overflow-tooltip>
</el-table-column>
<el-table-column label="操作" align="center" show-overflow-tooltip>
<template #default="scope">
<el-button type="danger" @click="delData(scope.row)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-dialog>
</template>
<script>
import { onMounted, reactive, ref, toRefs, computed, nextTick } from "vue";
import infoApi from "@/api/infoApi.js";
import { ElMessage, ElMessageBox } from "element-plus";
export default {
props: ["formData", "dialogVisible"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const state = reactive({
propertiesData: [],
});
const visible = computed(() => {
return props.dialogVisible;
});
onMounted(() => {
getSet();
});
const getSet = async () => {
const parm = {
driver_name: props.formData.name
}
const res = await infoApi.getSet(parm);
if (res.code == 0) {
state.propertiesData = res.data;
} else {
console.log(res);
}
};
const closeDialog = () => {
ctx.emit("dialogClose");
};
const delData = (item) => {
ElMessageBox.confirm("确定删除该数据?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(async () => {
let param = {
driver_name: props.formData.name,
name: item.name
}
const res = await infoApi.delSet(param);
if (res.code == 0) {
ElMessage.success(res.message || "删除成功");
getSet();
} else {
ElMessage.error(res.message | "删除失败");
}
})
.catch(() => {
ElMessage.info("已取消删除");
});
}
return {
...toRefs(state),
visible,
closeDialog,
delData
};
},
};
</script>
<style lang="scss" scoped>
.top-title {
width: 100%;
::v-deep .el-card__body {
width: 100%;
display: flex;
justify-content: space-between;
font-weight: 800;
font-size: 16px;
}
}
.btns {
padding: 15px 0;
width: 100%;
display: flex;
justify-content: space-between;
}
.flex-center {
display: flex;
justify-content: center;
padding: 10px 0;
cursor: pointer;
}
</style>

View File

@ -56,14 +56,15 @@ axios.interceptors.response.use(
}
);
// post
export function postPBRequest(url, params, actionNum,template_name) {
export function postPBRequest(url, params, actionNum,name) {
const title = url === '/driver' ? {'driver_name': name }: {'template_name': name}
return axios({
method: "post",
url: url,
data: params,
headers: {
"action": actionNum,
"template_name": template_name
...title
},
});
}

View File

@ -93,7 +93,10 @@
删除
</el-button>
<el-button type="info" @click="manageData(scope.row)">
设备
新增设备
</el-button>
<el-button type="info" @click="viewData(scope.row)">
设备查询
</el-button>
</template>
</el-table-column>
@ -112,17 +115,20 @@
:formData="formData"
:dialogVisible="dialogVisible1"
v-if="dialogVisible1"
@dialogClose="dialogClose1"
@dialogSuccess="dialogSuccess1"
@dialogClose="dialogClose"
@dialogSuccess="dialogSuccess"
>
</AddSet>
<PzSet
:dialogVisible="dialogVisible2"
v-if="dialogVisible2"
@dialogClose="dialogClose2"
@dialogSuccess="dialogSuccess2"
:dialogVisible="dialogVisible3"
v-if="dialogVisible3"
@dialogClose="dialogClose3"
@dialogSuccess="dialogSuccess3"
>
</PzSet>
<ViewSet :formData="formData" :dialogVisible="dialogVisible2" v-if="dialogVisible2" @dialogClose="dialogClose"
@dialogSuccess="dialogSuccess">
</ViewSet>
</el-card>
</template>
@ -133,12 +139,14 @@ import { ElMessage, ElMessageBox } from "element-plus";
import AddData from "@/components/AddData.vue";
import AddSet from "@/components/AddSet.vue";
import PzSet from "@/components/PzSet.vue";
import ViewSet from "@/components/ViewSet.vue";
export default {
name: "page",
components: {
AddData,
AddSet,
PzSet
PzSet,
ViewSet
},
setup() {
const state = reactive({
@ -147,8 +155,9 @@ export default {
formData: {},
dialogVisible: false,
dialogVisible1: false,
dialogVisible2: false,//
type: '0', // 0 1
dialogVisible2: false,
dialogVisible3: false,
type: '0' // 0 1
});
onMounted(() => {
@ -176,6 +185,8 @@ export default {
};
const dialogClose = () => {
state.dialogVisible = false;
state.dialogVisible1 = false;
state.dialogVisible2 = false;
};
const dialogSuccess = () => {
@ -186,18 +197,22 @@ export default {
const dialogClose1 = () => {
state.dialogVisible1 = false;
};
const dialogClose2 = () => {
state.dialogVisible2 = false;
const dialogClose3 = () => {
state.dialogVisible3 = false;
};
const dialogSuccess3 = () => {
state.dialogVisible3 = false;
getTableData();
};
const dialogSuccess1 = () => {
state.dialogVisible1 = false;
getTableData();
};
const dialogSuccess2 = () => {
state.dialogVisible2 = false;
getTableData();
};
const addData = () => {
state.formData = {
name: '',
@ -243,6 +258,11 @@ export default {
state.dialogVisible1 = true;
};
const viewData = (item) => {
state.dialogVisible2 = true;
state.formData = JSON.parse(JSON.stringify(item));
}
const changeStatus = async (item) => {
console.log(item.enable);
const param = {
@ -258,7 +278,7 @@ export default {
};
const openPz = (item) => {
state.dialogVisible2 = true;
state.dialogVisible3 = true;
}
return {
@ -272,9 +292,10 @@ export default {
changeStatus,
dialogClose1,
dialogSuccess1,
dialogClose2,
dialogSuccess2,
openPz
dialogClose3,
dialogSuccess3,
openPz,
viewData
};
},
};