2021-06-08 16:03:49 +08:00
|
|
|
|
|
|
|
import { Condition } from '@/components/widget/bean/Condition'
|
2022-01-27 11:06:29 +08:00
|
|
|
import { ApplicationContext } from '@/utils/ApplicationContext'
|
|
|
|
|
2021-06-08 16:03:49 +08:00
|
|
|
/**
|
|
|
|
* 判断两个conditions数组是否相同
|
|
|
|
* @param {*} conditions1
|
|
|
|
* @param {*} conditions2
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
export const isChange = (conditions1, conditions2) => {
|
|
|
|
// 两个都null
|
|
|
|
if (!conditions1 && !conditions2) return false
|
|
|
|
if (!conditions1 || !conditions2) return true
|
|
|
|
// 数组长度不一样 肯定发生了改变
|
|
|
|
if (conditions1.length !== conditions2.length) return true
|
|
|
|
let arr1 = JSON.parse(JSON.stringify(conditions1))
|
|
|
|
let arr2 = JSON.parse(JSON.stringify(conditions2))
|
|
|
|
arr1 = arr1.sort((s1, s2) => s1.componentId > s2.componentId)
|
|
|
|
arr2 = arr2.sort((s1, s2) => s1.componentId > s2.componentId)
|
|
|
|
return JSON.stringify(arr1) !== JSON.stringify(arr2)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const valueValid = condition => {
|
|
|
|
return condition && condition.value && condition.value.length > 0 && condition.value[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
export const formatCondition = obj => {
|
2022-05-26 13:15:50 +08:00
|
|
|
const { component, value, operator, isTree } = obj
|
2022-05-26 17:35:53 +08:00
|
|
|
|
|
|
|
let fieldId = component.options.attrs.fieldId
|
2021-06-08 16:03:49 +08:00
|
|
|
const viewIds = component.options.attrs.viewIds
|
2022-05-26 17:35:53 +08:00
|
|
|
if (isTree && !component.options.attrs.multiple && value && value.length) {
|
|
|
|
// 单选树
|
|
|
|
const val = value[0]
|
|
|
|
if (val) {
|
|
|
|
const len = val.split(',').length
|
|
|
|
if (len) {
|
|
|
|
fieldId = fieldId.split(',').slice(0, len).join(',')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-26 13:15:50 +08:00
|
|
|
const condition = new Condition(component.id, fieldId, operator, value, viewIds, isTree)
|
2021-06-08 16:03:49 +08:00
|
|
|
return condition
|
|
|
|
}
|
2021-08-10 15:50:00 +08:00
|
|
|
|
|
|
|
export const formatLinkageCondition = obj => {
|
|
|
|
const { viewIds, fieldId, value, operator } = obj
|
|
|
|
const condition = new Condition(null, fieldId, operator, value, viewIds)
|
|
|
|
return condition
|
|
|
|
}
|
2022-01-27 11:06:29 +08:00
|
|
|
|
|
|
|
export const buildFilterMap = panelItems => {
|
|
|
|
const viewIdMatch = (viewIds, viewId) => !viewIds || viewIds.length === 0 || viewIds.includes(viewId)
|
|
|
|
const result = {}
|
|
|
|
panelItems.forEach(element => {
|
|
|
|
if (element.type === 'view') {
|
|
|
|
result[element.propValue.viewId] = []
|
|
|
|
}
|
2022-02-24 12:33:37 +08:00
|
|
|
if (element.type === 'de-tabs') {
|
|
|
|
element.options.tabList && element.options.tabList.forEach(tab => {
|
2022-02-28 11:05:10 +08:00
|
|
|
if (tab.content && tab.content.propValue && tab.content.propValue.viewId) {
|
2022-02-24 18:11:49 +08:00
|
|
|
result[tab.content.propValue.viewId] = []
|
|
|
|
}
|
2022-02-24 12:33:37 +08:00
|
|
|
})
|
|
|
|
}
|
2022-01-27 11:06:29 +08:00
|
|
|
})
|
|
|
|
panelItems.forEach(element => {
|
|
|
|
if (element.type !== 'custom') {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
const widget = ApplicationContext.getService(element.serviceName)
|
|
|
|
const param = widget.getParam(element)
|
|
|
|
const condition = formatCondition(param)
|
|
|
|
const vValid = valueValid(condition)
|
|
|
|
const filterComponentId = condition.componentId
|
|
|
|
Object.keys(result).forEach(viewId => {
|
|
|
|
const vidMatch = viewIdMatch(condition.viewIds, viewId)
|
|
|
|
const viewFilters = result[viewId]
|
|
|
|
let j = viewFilters.length
|
|
|
|
while (j--) {
|
|
|
|
const filter = viewFilters[j]
|
|
|
|
if (filter.componentId === filterComponentId) {
|
|
|
|
viewFilters.splice(j, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vidMatch && vValid && viewFilters.push(condition)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return result
|
|
|
|
}
|