main
wangqiujuan0808 2024-05-09 17:00:05 +08:00
parent e66c6f116d
commit 581846d228
10 changed files with 46 additions and 289 deletions

14
package-lock.json generated
View File

@ -14,7 +14,7 @@
"axios": "^0.21.1",
"echarts": "^5.4.2",
"element-plus": "^2.3.4",
"js-base64": "^3.7.5",
"js-base64": "^3.7.7",
"js-md5": "^0.7.3",
"moment": "^2.29.4",
"protobufjs": "^7.2.4",
@ -3928,9 +3928,9 @@
}
},
"node_modules/js-base64": {
"version": "3.7.5",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.5.tgz",
"integrity": "sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA=="
"version": "3.7.7",
"resolved": "https://registry.npmmirror.com/js-base64/-/js-base64-3.7.7.tgz",
"integrity": "sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw=="
},
"node_modules/js-md5": {
"version": "0.7.3",
@ -9882,9 +9882,9 @@
}
},
"js-base64": {
"version": "3.7.5",
"resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.5.tgz",
"integrity": "sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA=="
"version": "3.7.7",
"resolved": "https://registry.npmmirror.com/js-base64/-/js-base64-3.7.7.tgz",
"integrity": "sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw=="
},
"js-md5": {
"version": "0.7.3",

View File

@ -16,7 +16,7 @@
"axios": "^0.21.1",
"echarts": "^5.4.2",
"element-plus": "^2.3.4",
"js-base64": "^3.7.5",
"js-base64": "^3.7.7",
"js-md5": "^0.7.3",
"moment": "^2.29.4",
"protobufjs": "^7.2.4",

View File

@ -36,7 +36,7 @@ export default {
addForm: {},
rules: {
name: [
{ required: true, message: "请输入模板名称", trigger: "blur" }
{ required: true, message: "请输入模板名称", trigger: "blur" },
],
description: [
{ required: true, message: "请输入模板描述", trigger: "blur" }

View File

@ -5,7 +5,7 @@
<el-input v-model="addForm.name" placeholder="请输入点位名称" clearable :disabled="type !== 'I'" />
</el-form-item>
<el-form-item label="点位地址:" prop="address">
<el-input v-model="addForm.address" placeholder="请输入点位地址" clearable type="number" />
<el-input v-model="addForm.address" placeholder="请输入点位地址0-19999或30000-49999" clearable type="number" />
</el-form-item>
<el-form-item label="点位类型:" prop="type">
<el-select v-model="addForm.type" size="mini" placeholder="请选择点位类型">
@ -48,6 +48,14 @@ export default {
props: ["formData", "dialogVisible", "pointData", "type"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const checkAddress = (rule, value, callback) => {
let num = Number(value);
if (value && (num >= 0 && num <= 19999) || (num >= 30000 && num <= 49999)) {
callback();
} else {
callback(new Error("点位地址0-1999930000-49999"));
}
};
const ruleFormRef = ref(null);
const state = reactive({
addForm: {
@ -141,7 +149,10 @@ export default {
],
rules: {
name: [{ required: true, message: "请输入点位名称", trigger: "blur" }],
address: [{ required: true, message: "请输入点位地址", trigger: "blur" }],
address: [
{ required: true, message: "请输入点位地址", trigger: "blur" },
{ required: true, validator: checkAddress, trigger: "blur" }
],
type: [{ required: true, message: "请选择点位类型", trigger: "blur" }],
byte_order: [{ required: true, message: "请选择字节顺序", trigger: "blur" }],
multiplier: [{ required: true, message: "请输入缩放系数", trigger: "blur" }],
@ -174,7 +185,7 @@ export default {
address: Number(state.addForm.address),
multiplier: Number(state.addForm.multiplier)
}
const res = props.type === 'I' ? await infoApi.addP(param): await infoApi.editP(param);
const res = props.type === 'I' ? await infoApi.addP(param) : await infoApi.editP(param);
if (res.code == 0) {
ElMessage.success(res.message || "请求成功");
ctx.emit("dialogSuccess");

View File

@ -1,262 +0,0 @@
<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,11 +1,11 @@
<template>
<el-dialog v-model="visible" title="设备管理" width="60%" :before-close="closeDialog">
<el-dialog v-model="visible" title="设备管理" width="40%" :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 :disabled="type!=='I'"/>
</el-form-item>
<el-form-item label="设备id:" prop="id">
<el-input v-model="addForm.id" placeholder="请输入设备id" clearable type="number" />
<el-input v-model="addForm.id" placeholder="请输入设备id:1-255" clearable type="number" />
</el-form-item>
<el-form-item label="模板名称:" prop="template_name">
<el-select v-model="addForm.template_name" size="mini" placeholder="请选择模板名称">
@ -34,6 +34,14 @@ export default {
props: ["formData", "dialogVisible", "setData", "type"],
emits: ["dialogClose", "dialogSuccess"],
setup(props, ctx) {
const checkSetId = (rule, value, callback) => {
let num = Number(value);
if (value && (num >= 1 && num <= 255)) {
callback();
} else {
callback(new Error("设备ID1-255"));
}
};
const ruleFormRef = ref(null);
const state = reactive({
addForm: {
@ -42,7 +50,10 @@ export default {
rules: {
name: [{ required: true, message: "请输入设备名称", trigger: "blur" }],
template_name: [{ required: true, message: "请选择模板名称", trigger: "blur" }],
id: [{ required: true, message: "请输入设备ID", trigger: "blur" }],
id: [
{ required: true, message: "请输入设备ID", trigger: "blur" },
{ required: true, validator: checkSetId, trigger: "blur" }
],
},
});
const visible = computed(() => {
@ -73,10 +84,9 @@ export default {
state.modelArr.push(obj);
console.log(33,state.modelArr);
}
console.log(state.modelArr);
state.addForm.template_name = state.modelArr[0].name;
} else {
ElMessage.error(res.message || "请求失败");
ElMessage.error(res.data || res.messgae);
}
};
const closeDialog = () => {
@ -99,7 +109,7 @@ export default {
ElMessage.success(res.message || "请求成功");
ctx.emit("dialogSuccess");
} else {
ElMessage.error(res.message);
ElMessage.error(res.data || res.message);
}
} else {
console.log("error submit!");

View File

@ -16,7 +16,7 @@
<el-button type="primary" @click="exportData"> </el-button>
</div>
</div>
<el-table :data="propertiesData" height="740" style="width: 100%" border stripe
<el-table :data="propertiesData" height="640" style="width: 100%" border stripe
:header-cell-style="{ background: '#F6F7FC' }">
<el-table-column type="index" label="序号" width="80" align="center" />
<el-table-column prop="name" label="点位名称" align="center" show-overflow-tooltip>
@ -126,7 +126,7 @@ export default {
state.propertiesData.push(pointData[i]);
}
} else {
console.log(res);
ElMessage.error(res.data || res.message);
}
};
const closeDialog = () => {

View File

@ -16,7 +16,7 @@
<el-button type="primary" @click="exportData"> </el-button>
</div>
</div>
<el-table :data="propertiesData" height="230" style="width: 100%" border stripe
<el-table :data="propertiesData" height="640" style="width: 100%" border stripe
:header-cell-style="{ background: '#F6F7FC' }">
<el-table-column prop="name" label="设备名称" align="center" show-overflow-tooltip>
</el-table-column>

View File

@ -6,12 +6,10 @@ import router from "@/router/index";
import {
localSet,
localGet,
localRemove
localRemove,
} from "./index";
import config from "~/config";
import {
response
} from '../proto/data/pd';
import {Base64} from 'js-base64';
axios.defaults.baseURL = config[
import.meta.env.MODE].baseUrl;
@ -57,7 +55,7 @@ axios.interceptors.response.use(
);
// post
export function postPBRequest(url, params, actionNum,name) {
const title = url === '/driver' ? {'driver_name': name }: {'template_name': name}
const title = url === '/driver' ? {'driver_name': Base64.encode(name) }: {'template_name': Base64.encode(name)}
return axios({
method: "post",
url: url,

View File

@ -37,4 +37,4 @@ export const pathMap = {
report: '上报管理',
transparent: '透传管理',
rules: '规则引擎'
}
}