From dc1d9e1995c02bc638b9fd1980faed5438e90e5a Mon Sep 17 00:00:00 2001 From: wangqiujuan0808 <578331299@qq.com> Date: Wed, 8 May 2024 22:11:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/infoApi.js | 61 ++++++++--------- src/components/AddData.vue | 123 ++++++++++++++--------------------- src/components/AddMb.vue | 4 +- src/components/AddPoint.vue | 10 +-- src/components/ViewPoint.vue | 11 +++- src/utils/axios.js | 3 +- src/views/Model.vue | 2 +- src/views/Page.vue | 15 ++--- 8 files changed, 103 insertions(+), 126 deletions(-) diff --git a/src/api/infoApi.js b/src/api/infoApi.js index 5fb30f8..8e49d36 100644 --- a/src/api/infoApi.js +++ b/src/api/infoApi.js @@ -29,10 +29,6 @@ const infoApi = { // getFree(params) { // return getRequest('/com/free', params) // }, - // 获取支持的通讯驱动 - getTxSupport() { - return postPBRequest('/driver', null, 53001) - }, // // 获取所有串口列表api/com // getCom(params) { @@ -42,9 +38,7 @@ const infoApi = { // saveTx(params) { // return postJsonRequest("/tx", params); // }, - // editTx(params) { - // return putRequest("/tx", params); - // }, + // // 透传服务启停 // stopTc(params) { // return putRequest("/tc", params); @@ -55,11 +49,11 @@ const infoApi = { // }, // 模板列表 getMb(params) { - return postPBRequest('/template', params, 55000) + return postPBRequest('/template', params, 53000) }, // 新增模板 addMb(params) { - return postPBRequest('/template', params, 55100) + return postPBRequest('/template', params, 53100) }, // 更新模板 editMb(params) { @@ -67,24 +61,24 @@ const infoApi = { }, // 删除模板 delMb(params) { - return postPBRequest('/template', params, 55300) + return postPBRequest('/template', params, 53300) }, // 新增点位 addP(params) { - return postPBRequest('/template', params, 56100) + return postPBRequest('/template', params, 53110, params.template_name) }, // 获取模板支持类型 getTemplateType(params) { - return postPBRequest('/template', params, 55001) + return postPBRequest('/template', params, 53001) }, // 获取点位 getP(params) { - return postPBRequest('/template', params, 56000) + return postPBRequest('/template', params, 53010, params.template_name) }, // 删除点位 detP(params) { - return postPBRequest('/template', params, 56300) + return postPBRequest('/template', params, 53310, params.template_name) }, // // 获取设备列表 // getSet(params) { @@ -96,30 +90,39 @@ const infoApi = { // }, // 驱动列表查询 getTx(params) { - return postPBRequest('/driver', params, 53000) + return postPBRequest('/driver', params, 54000) }, - // 添加查询 + // 添加驱动 saveTx(params) { - return postPBRequest("/driver", params, 53100); + return postPBRequest("/driver", params, 54100); }, - // 查询支持的驱动列表 - getSupportTx(params) { - return postPBRequest("/driver", params, 53001); + // 更新驱动 + editTx(params) { + return postPBRequest("/driver", params, 54200); + }, + // 删除通讯 + delTx(params) { + return postPBRequest(`/driver`, params, 54300); + }, + + // 获取支持的通讯驱动 + getTxSupport() { + return postPBRequest('/driver', null, 54001) }, // 查询驱动配置项 getTxConfig(params) { return postPBRequest("/driver", params, 53002); - } + }, - // // 通讯服务启用,停用 - // changeStatus(params) { - // return postJsonRequest(`/tx/${params.url}/${params.name}`, params); - // }, + // 通讯服务启用,停用 + startStatus(params) { + return postPBRequest("/driver", params,53201); + }, + // 通讯服务停止 + stopStatus(params) { + return postPBRequest("/driver", params,53202); + } - // // 删除通讯 - // delTx(params) { - // return deleteRequest(`/tx`, params); - // }, // // 获取上报列表 // getSc(params) { // return getRequest('/sb/list', params) diff --git a/src/components/AddData.vue b/src/components/AddData.vue index df3f456..8cc559a 100644 --- a/src/components/AddData.vue +++ b/src/components/AddData.vue @@ -7,45 +7,40 @@ > - + - + - + - + -
+ -
+ @@ -180,6 +175,8 @@ export default { } }; const state = reactive({ + addForm: {}, + typeOptions: [], serialConfig: false, modbusTCPConfig: false, com_select: [], @@ -206,12 +203,12 @@ export default { stop_bits_select: [1, 2], timeout_select: [0, 100, 200, 500, 1000, 2000], rules: { - index: [ + name: [ { required: true, message: "请输入通讯名称", trigger: "blur" }, { required: true, validator: validName, trigger: "blur" }, ], description: [{ required: true, message: "请输入驱动描述", trigger: "blur" }], - drive: [{ required: true, message: "请选择通讯驱动", trigger: "blur" }], + type: [{ required: true, message: "请选择通讯驱动", trigger: "blur" }], // com: [{ required: true, message: "请选择COM口", trigger: "blur" }], // baudRate: [{ required: true, message: "请选择波特率", trigger: "blur" }], // parity: [{ required: true, message: "请选择校验位", trigger: "blur" }], @@ -227,69 +224,47 @@ export default { }); onMounted(async () => { - if (props.type === '1') { - if (props.formData.serial) { - state.serialConfig = true; - state.modbusTCPConfig = false; - // 获取com,比对赋值 - getCom(); - } else { - state.serialConfig = false; - if (props.formData.drive == "modbusTCP") { - state.modbusTCPConfig = true; - // 直接赋值 - state.configData1 = { - port: props.formData.host.split(":")[0], - host: props.formData.host.split(":")[1] - } - } - } - } + // if (props.type === '1') { + // if (props.formData.serial) { + // state.serialConfig = true; + // state.modbusTCPConfig = false; + // // 获取com,比对赋值 + // getCom(); + // } else { + // state.serialConfig = false; + // if (props.formData.drive == "modbusTCP") { + // state.modbusTCPConfig = true; + // // 直接赋值 + // state.configData1 = { + // port: props.formData.host.split(":")[0], + // host: props.formData.host.split(":")[1] + // } + // } + // } + // } + state.addForm = props.formData; + getTypeOptions(); }); + + const getTypeOptions = () => { + state.typeOptions = []; + for (let i in props.qudongOptions) { + let obj = { + key: Number(i), + name: props.qudongOptions[i] + } + state.typeOptions.push(obj); + console.log(33,state.typeOptions); + } + } const closeDialog = () => { ctx.emit("dialogClose"); }; const saveData = async () => { await ruleFormRef.value.validate(async (valid) => { if (valid) { - let req_configbuf; - if (props.type==='0') { // 新增 - if (props.formData.drive.serial) { - req_configbuf = state.configData - } else { - if (props.formData.drive.name == "modbusTCP") { - req_configbuf = state.configData1; - } - } - var obj = { - index: props.formData.index, - drive: props.formData.drive.name, - Description: props.formData.Description, - serial: props.formData.drive.serial, - config: req_configbuf, - }; - console.log('编辑数据3', obj); - } else { // 编辑 - console.log('编辑数据1', state.configData) - console.log('编辑数据2', state.configData1) - if (props.formData.serial) { - req_configbuf = state.configData - } else { - if (props.formData.drive == "modbusTCP") { - req_configbuf = state.configData1; - } - } - obj = { - name: props.formData.name, - drive: props.formData.drive, - description: props.formData.description, - serial: props.formData.serial, - config: req_configbuf, - }; - console.log('编辑数据3', obj); - } - const res = props.type === '0' ? await infoApi.saveTx(obj) : await infoApi.editTx(obj); + const res = props.type === '0' ? await infoApi.saveTx(state.addForm) : await infoApi.editTx(state.addForm); if (res.code == 0) { ElMessage.success(res.message || "请求成功"); ctx.emit("dialogSuccess"); diff --git a/src/components/AddMb.vue b/src/components/AddMb.vue index dcec09d..1c548ef 100644 --- a/src/components/AddMb.vue +++ b/src/components/AddMb.vue @@ -2,14 +2,14 @@ - + - + diff --git a/src/components/AddPoint.vue b/src/components/AddPoint.vue index e231ded..57519d1 100644 --- a/src/components/AddPoint.vue +++ b/src/components/AddPoint.vue @@ -147,13 +147,9 @@ export default { await ruleFormRef.value.validate(async (valid) => { if (valid) { const param = { - point_name: props.formData.name + '/' + state.addForm.name, - point: { - description: state.addForm.description, - address: Number(state.addForm.address), - type: state.addForm.type, - byte_order: state.addForm.byte_order - } + template_name: props.formData.name, + ...state.addForm, + address: Number(state.addForm.address) } const res = await infoApi.addP(param); if (res.code == 0) { diff --git a/src/components/ViewPoint.vue b/src/components/ViewPoint.vue index ca9f111..a075441 100644 --- a/src/components/ViewPoint.vue +++ b/src/components/ViewPoint.vue @@ -78,11 +78,15 @@ export default { const getPointList = async () => { const parm = { - name: props.formData.name + template_name: props.formData.name } const res = await infoApi.getP(parm); if (res.code == 0) { - state.propertiesData = res.data; + state.propertiesData = []; + const pointData = res.data; + for (let i in pointData) { + state.propertiesData.push(pointData[i]); + } } else { console.log(res); } @@ -99,7 +103,8 @@ export default { }) .then(async () => { let param = { - point_name: item.name + template_name: props.formData.name, + name: item.name } const res = await infoApi.detP(param); if (res.code == 0) { diff --git a/src/utils/axios.js b/src/utils/axios.js index a7d7583..5b5e86a 100644 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -56,13 +56,14 @@ axios.interceptors.response.use( } ); // post请求 -export function postPBRequest(url, params, actionNum) { +export function postPBRequest(url, params, actionNum,template_name) { return axios({ method: "post", url: url, data: params, headers: { "action": actionNum, + "template_name": template_name }, }); } \ No newline at end of file diff --git a/src/views/Model.vue b/src/views/Model.vue index 9490e4f..7697936 100644 --- a/src/views/Model.vue +++ b/src/views/Model.vue @@ -32,7 +32,7 @@
- {{ qudongOptions[scope.row.type]}} - + /> --> { state.formData = { name: '', - drive: '', + type: 1, description: '', - serial: false, - config: '', }; state.dialogVisible = true; state.type = '0'; @@ -229,9 +227,8 @@ export default { console.log(item.enable); const param = { name: item.name, - url: item.enable ? 'start': 'stop' } - const res = await infoApi.changeStatus(param); + const res = item.enable ? await infoApi.startStatus(param) : await infoApi.stopStatus(param); if (res.code == 0) { ElMessage.success(res.msg || "请求成功"); getTableData();