diff --git a/nezha-fronted/src/components/chart/panelChart.vue b/nezha-fronted/src/components/chart/panelChart.vue index c3eafd1ac..2dae84488 100644 --- a/nezha-fronted/src/components/chart/panelChart.vue +++ b/nezha-fronted/src/components/chart/panelChart.vue @@ -546,12 +546,23 @@ export default { }, variablesReplace (expression) { let str = expression + let confirmReg = '' + let confirmRegItem = '' this.variablesArr.forEach(item => { - const reg = new RegExp('\\$' + item.name, 'g') // 后续需要考虑 item,name 使用特殊字符的问题 - if (reg.test(expression)) { - str = str.replace(reg, item.checked.map(label => label.replace(/\"/g, '\\"').replace(/\'/g, "\\'")).join('|')) + const reg = '$' + item.name // 后续需要考虑 item,name 使用特殊字符的问题 + const index = expression.indexOf(reg) + if (index !== -1) { + if (reg.length > confirmReg.length) { + confirmReg = reg + confirmRegItem = item + } } }) + if (confirmReg) { + const index = expression.indexOf(confirmReg) + const replaceStr = confirmRegItem.checked.map(label => label.replace(/\"/g, '\\"').replace(/\'/g, "\\'")).join('|') + str = str.substring(0, index) + replaceStr + str.substring(index + confirmReg.length) + } return str }, getHexagonFigureData () { diff --git a/nezha-fronted/src/components/common/panel/panelVariables.vue b/nezha-fronted/src/components/common/panel/panelVariables.vue index 427225b50..d123399ae 100644 --- a/nezha-fronted/src/components/common/panel/panelVariables.vue +++ b/nezha-fronted/src/components/common/panel/panelVariables.vue @@ -368,16 +368,19 @@ export default { }) item.checked = item.checkAll ? allValue : [] item.isIndeterminate = false - this.$store.dispatch('dispatchVariablesArr', [...this.labelArr]) + if (!item.multi) { + this.close() + this.$store.dispatch('dispatchVariablesArr', [...this.labelArr]) + } }, checkedChange (item, value) { const checkedCount = value.length item.checkAll = checkedCount === this.labelValue[item.name].length item.isIndeterminate = checkedCount > 0 && checkedCount < this.labelValue[item.name].length - this.$store.dispatch('dispatchVariablesArr', [...this.labelArr]) }, selectLabelValue (item, value) { item.checked = [value.value] + this.close() this.$store.dispatch('dispatchVariablesArr', [...this.labelArr]) }, triggerVisible (item) { @@ -387,6 +390,9 @@ export default { }, close () { this.labelArr.forEach((item) => { + if (item.visible && item.multi) { + this.$store.dispatch('dispatchVariablesArr', [...this.labelArr]) + } item.visible = false }) }