fix(仪表板): 带过滤器的模版过滤器无法切换数据集

This commit is contained in:
fit2cloud-chenyw 2023-05-23 16:38:25 +08:00
parent 32cbe7f1fa
commit ad26aeea2c

View File

@ -447,12 +447,13 @@ export default {
this.currentElement = JSON.parse(JSON.stringify(this.element))
this.myAttrs = this.currentElement.options.attrs
this.treeNode(this.groupForm)
this.loadViews()
if (this.myAttrs && this.myAttrs.dragItems) {
this.enableSureButton()
}
this.initWithField()
this.loadViews()
this.ProhibitMultiple()
},
mounted() {
@ -462,7 +463,29 @@ export default {
bus.$off('valid-values-change', this.validateFilterValue)
},
methods: {
checkSuperior(list) {
let fieldValid = false
const fieldId = this.myAttrs?.fieldId
if (fieldId && list?.length) {
const stack = [...list]
while (stack.length) {
const item = stack.pop()
if (item.id === fieldId) {
fieldValid = true
break
}
if (item.children?.length) {
item.children.forEach(kid => stack.push(kid))
}
}
}
if (!fieldValid) {
this.myAttrs.fieldId = null
this.myAttrs.dragItems = []
this.myAttrs.fieldsParent = null
}
return fieldValid
},
treeNode(cache) {
const modelInfo = localStorage.getItem('dataset-tree')
const userCache = (modelInfo && cache)
@ -471,6 +494,7 @@ export default {
const results = this.buildTree(this.tData)
this.defaultData = JSON.parse(JSON.stringify(results))
this.treeData = JSON.parse(JSON.stringify(results))
return
}
queryAuthModel({ modelType: 'dataset' }, !userCache).then(res => {
localStorage.setItem('dataset-tree', JSON.stringify(res.data))
@ -488,8 +512,8 @@ export default {
if (this.myAttrs.fieldsParent) {
this.fieldsParent = this.myAttrs.fieldsParent
this.$nextTick(() => {
this.activeName === 'dataset' && this.showFieldData(this.fieldsParent)
this.activeName !== 'dataset' && this.comShowFieldData(this.fieldsParent)
this.activeName === 'dataset' && this.showFieldData(this.fieldsParent, true)
this.activeName !== 'dataset' && this.comShowFieldData(this.fieldsParent, true)
})
}
}
@ -692,7 +716,7 @@ export default {
},
removeTail(bread) {
if (!bread.id) {
if (!bread?.id) {
this.dataSetBreads = this.dataSetBreads.slice(0, 1)
this.dataSetBreads[this.dataSetBreads.length - 1]['link'] = false
return
@ -718,7 +742,7 @@ export default {
this.expandedArray = []
this.keyWord = ''
this.isTreeSearch = false
if (bread.id) {
if (bread?.id) {
const node = this.getNode(bread.id, this.treeData)
if (node) {
this.tempTreeData = node.children
@ -736,15 +760,17 @@ export default {
this.comRemoveTail()
},
loadField(tableId) {
fieldListWithPermission(tableId).then(res => {
let data = res.data
if (this.widget && this.widget.filterFieldMethod) {
data = this.widget.filterFieldMethod(data)
}
this.originFieldData = data
this.fieldData = JSON.parse(JSON.stringify(data))
})
async loadField(tableId, init) {
const res = await fieldListWithPermission(tableId)
let data = res.data || []
if (init && !this.checkSuperior(data)) {
this.backToLink()
}
if (this.widget && this.widget.filterFieldMethod) {
data = this.widget.filterFieldMethod(data)
}
this.originFieldData = data
this.fieldData = JSON.parse(JSON.stringify(data))
},
loadDatasetParams(tableId) {
var type = 'TEXT'
@ -758,22 +784,24 @@ export default {
this.datasetParams = res.data || []
})
},
comLoadField(tableId) {
fieldListWithPermission(tableId).then(res => {
let data = res.data
if (this.widget && this.widget.filterFieldMethod) {
data = this.widget.filterFieldMethod(data)
}
this.originComFieldData = data
this.comFieldData = JSON.parse(JSON.stringify(data))
})
async comLoadField(tableId, init) {
const res = await fieldListWithPermission(tableId)
let data = res.data || []
if (init && !this.checkSuperior(data)) {
this.comBackLink()
}
if (this.widget && this.widget.filterFieldMethod) {
data = this.widget.filterFieldMethod(data)
}
this.originComFieldData = data
this.comFieldData = JSON.parse(JSON.stringify(data))
},
showFieldData(row) {
showFieldData(row, init) {
this.keyWord = ''
this.showDomType = 'field'
this.addQueue(row)
this.fieldsParent = row
this.loadField(row.id)
this.loadField(row.id, init)
this.loadDatasetParams(row.id)
},
showNextGroup(row) {
@ -782,13 +810,13 @@ export default {
this.showDomType = 'tree'
this.addQueue(row)
},
comShowFieldData(row) {
comShowFieldData(row, init) {
this.viewKeyWord = ''
this.comShowDomType = 'field'
this.comSetTailLink(row)
this.comAddTail(row)
this.fieldsParent = row
this.comLoadField(row.tableId)
this.comLoadField(row.tableId, init)
},
onMove(e, originalEvent) {
this.showTips = false