From cec5cdc19a636ca50e12c853c29f95b44882f904 Mon Sep 17 00:00:00 2001 From: zhoumengru Date: Thu, 18 Sep 2025 16:58:35 +0800 Subject: [PATCH] =?UTF-8?q?```=20refactor(EditCom,=20device,=20station):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=92=8C=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 `EditCom.vue` 中,修改了 `workModeIdSelect` 监听器的条件判断,确保只有在旧值存在且新旧值不同时才清空 `policy_id`。 - 判断调用 `getRoleIdList` 方法。 - 在多个异步方法(如 `userConfirm`, `roleConfirm`, `stationConfirm`, `deviceConfirm`)中统一了成功与失败的消息提示,并移除了原有的错误日志打印。 - 场站管理对状态和策略id进行修改。 - 对 `station.vue` 进行了格式调整,改进了 `forEach` 循环内的逻辑处理。 ``` --- web/src/components/EditCom.vue | 41 ++++++++++++++++++++------------ web/src/views/system/device.vue | 1 - web/src/views/system/station.vue | 34 +++++++++++++++----------- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/web/src/components/EditCom.vue b/web/src/components/EditCom.vue index 4854cb4..470eddd 100644 --- a/web/src/components/EditCom.vue +++ b/web/src/components/EditCom.vue @@ -176,9 +176,9 @@ export default { computed: {}, watch: { workModeIdSelect: { - async handler(n,o) { - if(n !== o){ - this.detailInfos[0].ruleForm.policy_id='' + async handler(n, o) { + if (o && n !== o) { + this.detailInfos[0].ruleForm.policy_id = '' } switch (n) { case '1': @@ -235,6 +235,7 @@ export default { this.detailInfos = stationOptions this.formRules = stationFormRules this.workModeIdSelect = this.detailInfos[0].ruleForm['work_mode'] + console.log(stationOptions) break case 'device': @@ -264,7 +265,10 @@ export default { } }, mounted() { - this.getRoleIdList() + if(this.type == 'user'||this.type == 'role'){ + this.getRoleIdList() + + } }, unmounted() { console.log('modal') @@ -275,11 +279,9 @@ export default { try { const res = await getReq('/queryPolicyByType', { type }) if (res.errcode == 0) { - list = res.data - .map((item) => { - - return {label:item.name,value:item.policy_id } - }) + list = res.data.map((item) => { + return { label: item.name, value: item.policy_id } + }) } } catch (error) { console.log(error) @@ -386,14 +388,16 @@ export default { const res = await postReq(menuApi[this.action], paramsDate) if (res.errcode === 0) { + this.$message.success('操作成功') setTimeout(() => { this.handleback() }, 1000) } else { throw res } + } catch (error) { - console.log(error, 'userConfirm') + this.$message.error('操作失败') } }, async roleConfirm() { @@ -429,14 +433,16 @@ export default { const res = await postReq(menuApi[this.action], paramsDate) if (res.errcode === 0) { + this.$message.success('操作成功') setTimeout(() => { this.handleback() }, 1000) } else { throw res } + } catch (error) { - console.log(error, 'roleConfirm') + this.$message.error('操作失败') } }, // 定义筛选树形数据的函数 @@ -507,22 +513,27 @@ export default { edit: '/updateStation' } const paramsDate = { - ...this.form + ...this.form, + status:Number(this.form.status), + work_mode:this.workModeIdSelect } if (this.action == 'edit') { paramsDate.station_id = this.record.station_id } const res = await postReq(menuApi[this.action], paramsDate) + if (res.errcode === 0) { + this.$message.success('操作成功') setTimeout(() => { this.handleback() }, 1000) } else { throw res } + } catch (error) { - console.log(error, 'stationConfirm') + this.$message.error('操作失败') } }, async deviceConfirm() { @@ -544,7 +555,7 @@ export default { const res = await postReq(menuApi[this.action], paramsDate) if (res.errcode === 0) { - this.$message.success('添加成功') + this.$message.success('操作成功') setTimeout(() => { this.handleback() }, 1000) @@ -552,7 +563,7 @@ export default { throw res } } catch (error) { - this.$message.error('添加失败') + this.$message.error('操作失败') } }, async serviceApiConfirm() { diff --git a/web/src/views/system/device.vue b/web/src/views/system/device.vue index f0d8fb2..0f9709b 100644 --- a/web/src/views/system/device.vue +++ b/web/src/views/system/device.vue @@ -154,7 +154,6 @@ export default { this.getRuleFormInfo() } else if (type == 'edit' || type == 'read') { await this.getRuleFormInfo(record) - this.formModal = true this.formState = record } else if (type == 'del') { diff --git a/web/src/views/system/station.vue b/web/src/views/system/station.vue index f729f88..81816f7 100644 --- a/web/src/views/system/station.vue +++ b/web/src/views/system/station.vue @@ -18,7 +18,9 @@ {{}} - + { e.list.forEach((i) => { if (i.key == 'work_mode') { - switch (row[i.key]) { - case '1': - case '5': - e.ruleForm[i.key] =row[i.key] - e.ruleForm['policy_id'] = row ? row['policy_id'] : '' + if (row[i.key] == 1 || row[i.key] == 5) { stationOptions[0].list[stationOptions[0].list.length - 1].type = 'select' - break - default: - e.ruleForm[i.key] =row[i.key] + e.ruleForm[i.key] = row[i.key] + e.ruleForm['policy_id'] = row ? row['policy_id'] : '' + } else { + e.ruleForm[i.key] = row[i.key] stationOptions[0].list[stationOptions[0].list.length - 1].type = 'unshow' - - break } + } else if (i.key == 'status') { + e.ruleForm.status = row ? Boolean(Number(row.status)) : '' + } else { e.ruleForm[i.key] = row ? row[i.key] : '' } @@ -271,7 +277,7 @@ export default { .station { height: 100%; - padding: 0 20px; + padding: 0 20px; .content-table { height: calc(100% - 92px); }