NEZ-2431 fix:取消浏览器地址栏无用参数

This commit is contained in:
zyh
2022-11-29 10:26:46 +08:00
parent 78cac8c1ad
commit 765c2859b4

View File

@@ -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]
}
})
}
}
}