From 765c2859b49051b6318f886b623b044db9ee4c91 Mon Sep 17 00:00:00 2001 From: zyh Date: Tue, 29 Nov 2022 10:26:46 +0800 Subject: [PATCH] =?UTF-8?q?NEZ-2431=20fix=EF=BC=9A=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E5=9C=B0=E5=9D=80=E6=A0=8F=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/mixin/routerPathParams.js | 89 ++++++++++++++++--- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/nezha-fronted/src/components/common/mixin/routerPathParams.js b/nezha-fronted/src/components/common/mixin/routerPathParams.js index d23f02be0..73a196c60 100644 --- a/nezha-fronted/src/components/common/mixin/routerPathParams.js +++ b/nezha-fronted/src/components/common/mixin/routerPathParams.js @@ -61,11 +61,11 @@ export default { params.bottomBox = false params.targetTab = this.$route.query.targetTab } + if (!params.targetTab) delete params.targetTab if (this.detailType === 'list' && this.$refs[detailType]) { - params.selectObj = JSON.stringify({ + const obj = { id: this.$refs[detailType].bottomBox.object.id, name: this.$refs[detailType].bottomBox.object.name, - configs: this.$refs[detailType].bottomBox.object.configs ? this.$refs[detailType].bottomBox.object.configs.map(item => { return { type: item.type, enable: item.enable } }) : '', childrenNum: this.$refs[detailType].bottomBox.object.childrenNum || '', clientState: this.$refs[detailType].bottomBox.object.clientState || '', protocol: this.$refs[detailType].bottomBox.object.protocol || '', @@ -74,13 +74,24 @@ export default { model: { tsgAppliance: this.$refs[detailType].bottomBox.object.model ? this.$refs[detailType].bottomBox.object.model.tsgAppliance : '' } - }) + } + if (this.$refs[detailType].bottomBox.object.configs) { + // 判断是JSON字符串还是对象 + if (typeof (this.$refs[detailType].bottomBox.object.configs) == 'string') { + obj.configs = JSON.parse(this.$refs[detailType].bottomBox.object.configs).map(item => { return { type: item.type, enable: item.enable } }) + } else { + obj.configs = this.$refs[detailType].bottomBox.object.configs.map(item => { return { type: item.type, enable: item.enable } }) + } + } + this.removeEmpty(obj) + if (JSON.stringify(obj) != '{}') { + params.selectObj = JSON.stringify(obj) + } } else if (this.$refs[detailType] && this.$refs[detailType].detailViewRightObj) { this.$nextTick(() => { - params.selectObj = JSON.stringify({ + const obj = { id: this.$refs[detailType].detailViewRightObj.id, name: this.$refs[detailType].detailViewRightObj.name, - configs: this.$refs[detailType].detailViewRightObj.configs ? this.$refs[detailType].detailViewRightObj.configs.map(item => { return { type: item.type, enable: item.enable } }) : '', childrenNum: this.$refs[detailType].detailViewRightObj.childrenNum || '', clientState: this.$refs[detailType].detailViewRightObj.clientState || '', protocol: this.$refs[detailType].detailViewRightObj.protocol || '', @@ -89,17 +100,28 @@ export default { model: { tsgAppliance: this.$refs[detailType].detailViewRightObj.model ? this.$refs[detailType].detailViewRightObj.model.tsgAppliance : '' } - }) + } + if (this.$refs[detailType].detailViewRightObj.configs) { + // 判断是JSON字符串还是对象 + if (typeof (this.$refs[detailType].detailViewRightObj.configs) == 'string') { + obj.configs = JSON.parse(this.$refs[detailType].detailViewRightObj.configs).map(item => { return { type: item.type, enable: item.enable } }) + } else { + obj.configs = this.$refs[detailType].detailViewRightObj.configs.map(item => { return { type: item.type, enable: item.enable } }) + } + } + this.removeEmpty(obj) + if (JSON.stringify(obj) != '{}') { + params.selectObj = JSON.stringify(obj) + } }) } this.$router.replace({ path: path, query: params }).catch(err => {}) } else if (from === 'nzDatalist' && this.bottomBox) { params.bottomBox = this.bottomBox.showSubList params.targetTab = this.bottomBox.targetTab - params.selectObj = JSON.stringify({ + const obj = { id: this.bottomBox.object.id, name: this.bottomBox.object.name, - configs: this.bottomBox.object.configs ? this.bottomBox.object.configs.map(item => { return { type: item.type, enable: item.enable } }) : '', childrenNum: this.bottomBox.object.childrenNum || '', clientState: this.bottomBox.object.clientState || '', protocol: this.bottomBox.object.protocol || '', @@ -108,14 +130,25 @@ export default { model: { tsgAppliance: this.bottomBox.object.model ? this.bottomBox.object.model.tsgAppliance : '' } - }) + } + if (this.bottomBox.object.configs) { + // 判断是JSON字符串还是对象 + if (typeof (this.bottomBox.object.configs) == 'string') { + obj.configs = JSON.parse(this.bottomBox.object.configs).map(item => { return { type: item.type, enable: item.enable } }) + } else { + obj.configs = this.bottomBox.object.configs.map(item => { return { type: item.type, enable: item.enable } }) + } + } + this.removeEmpty(obj) + if (JSON.stringify(obj) != '{}') { + params.selectObj = JSON.stringify(obj) + } this.$router.replace({ path: path, query: params }).catch(err => {}) } else if (from === 'nzDetailList' && this.detailViewRightObj) { params.targetTab = this.$route.query.targetTab - params.selectObj = JSON.stringify({ + const obj = { id: this.detailViewRightObj.id, name: this.detailViewRightObj.name, - configs: this.detailViewRightObj.configs ? this.detailViewRightObj.configs.map(item => { return { type: item.type, enable: item.enable } }) : '', childrenNum: this.detailViewRightObj.childrenNum || '', clientState: this.detailViewRightObj.clientState || '', protocol: this.detailViewRightObj.protocol || '', @@ -124,7 +157,19 @@ export default { model: { tsgAppliance: this.detailViewRightObj.model ? this.detailViewRightObj.model.tsgAppliance : '' } - }) + } + if (this.detailViewRightObj.configs) { + // 判断是JSON字符串还是对象 + if (typeof (this.detailViewRightObj.configs) == 'string') { + obj.configs = JSON.parse(this.detailViewRightObj.configs).map(item => { return { type: item.type, enable: item.enable } }) + } else { + obj.configs = this.detailViewRightObj.configs.map(item => { return { type: item.type, enable: item.enable } }) + } + } + this.removeEmpty(obj) + if (JSON.stringify(obj) != '{}') { + params.selectObj = JSON.stringify(obj) + } this.$router.replace({ path: path, query: params }).catch(err => {}) } else if (from === 'bottomBox' && this.targetTab) { params.targetTab = this.targetTab @@ -157,6 +202,26 @@ export default { setTimeout(() => { $temp.$refs[formName].validate() }, 100) + }, + // 清除空数据 + removeEmpty (obj) { + if (!obj) { + return + } + Object.keys(obj).forEach(key => { + // 属性为对象 + if (Object.prototype.toString.call(obj[key]) === '[object Object]' && (JSON.stringify(obj[key]) != '{}')) { + this.removeEmpty(obj[key]) + } + // 属性值为空 + if (!obj[key]) { + delete obj[key] + } + // 属性为空对象 + if ((Array.isArray(obj[key]) && !obj[key].length) || (JSON.stringify(obj[key]) == '{}')) { + delete obj[key] + } + }) } } }