fix(查询组件): 级联查询设置后,相关查询字段的默认值不生效了 #17655

This commit is contained in:
dataeaseShu
2025-12-22 14:30:00 +08:00
committed by dataeaseShu
parent d0bb1d0206
commit 4a6961543c
3 changed files with 72 additions and 72 deletions

View File

@@ -300,11 +300,17 @@ watch(
}
)
const list = ref([])
let oldList = []
let isResetData = false
watch(
() => props.element.propValue,
() => {
list.value = [...props.element.propValue]
if (isResetData) {
isResetData = false
return
}
oldList = cloneDeep(props.element.propValue)
},
{
immediate: true
@@ -670,43 +676,50 @@ const delQueryConfig = index => {
}
const resetData = () => {
;(list.value || []).reduce((pre, next) => {
next.conditionValueF = next.defaultConditionValueF
next.conditionValueOperatorF = next.defaultConditionValueOperatorF
next.conditionValueS = next.defaultConditionValueS
next.conditionValueOperatorS = next.defaultConditionValueOperatorS
isResetData = true
element.value.propValue = []
nextTick(() => {
element.value.propValue = cloneDeep(oldList)
;(element.value.propValue || []).reduce((pre, next) => {
next.conditionValueF = next.defaultConditionValueF
next.conditionValueOperatorF = next.defaultConditionValueOperatorF
next.conditionValueS = next.defaultConditionValueS
next.conditionValueOperatorS = next.defaultConditionValueOperatorS
if (next.displayType === '22') {
next.numValueEnd = next.defaultNumValueEnd
next.numValueStart = next.defaultNumValueStart
}
if (next.displayType === '22') {
next.numValueEnd = next.defaultNumValueEnd
next.numValueStart = next.defaultNumValueStart
}
if (!next.defaultValueCheck) {
next.defaultValue = next.multiple || +next.displayType === 7 ? [] : undefined
}
next.selectValue = Array.isArray(next.defaultValue) ? [...next.defaultValue] : next.defaultValue
if (next.optionValueSource === 1 && next.defaultMapValue?.length) {
next.mapValue = Array.isArray(next.defaultMapValue)
? [...next.defaultMapValue]
: next.defaultMapValue
}
if (!next.defaultValueCheck) {
next.defaultValue = next.multiple || +next.displayType === 7 ? [] : undefined
}
next.selectValue = Array.isArray(next.defaultValue)
? [...next.defaultValue]
: next.defaultValue
if (next.optionValueSource === 1 && next.defaultMapValue?.length) {
next.mapValue = Array.isArray(next.defaultMapValue)
? [...next.defaultMapValue]
: next.defaultMapValue
}
;(props.element.cascade || []).forEach(ele => {
ele.forEach(item => {
const comId = item.datasetId.split('--')[1]
if (next.id === comId) {
item.currentSelectValue = Array.isArray(next.selectValue)
? next.selectValue
: [next.selectValue].filter(itx => ![null, undefined].includes(itx))
useEmitt().emitter.emit(`${item.datasetId.split('--')[1]}-select`)
}
;(props.element.cascade || []).forEach(ele => {
ele.forEach(item => {
const comId = item.datasetId.split('--')[1]
if (next.id === comId) {
item.currentSelectValue = Array.isArray(next.selectValue)
? next.selectValue
: [next.selectValue].filter(itx => ![null, undefined].includes(itx))
useEmitt().emitter.emit(`${item.datasetId.split('--')[1]}-select`)
}
})
})
})
const keyList = getKeyList(next)
pre = [...new Set([...keyList, ...pre])]
return pre
}, [])
!componentWithSure.value && queryData()
const keyList = getKeyList(next)
pre = [...new Set([...keyList, ...pre])]
return pre
}, [])
!componentWithSure.value && queryData()
})
}
const clearData = () => {

View File

@@ -344,6 +344,8 @@ const handleFieldIdChange = (val: EnumValue) => {
const valArr = options.value.map(ele => ele.value)
let change = false
if (
config.value.multiple &&
Array.isArray(selectValue.value) &&
@@ -354,12 +356,24 @@ const handleFieldIdChange = (val: EnumValue) => {
selectValue.value = selectValue.value.filter(ele => valArr.includes(ele))
options.value = options.value.filter(ele => !delArr.includes(ele.value))
config.value.defaultValue = selectValue.value
change = true
}
if (!config.value.multiple && selectValue.value && !valArr.includes(selectValue.value)) {
options.value = options.value.filter(ele => selectValue.value !== ele.value)
selectValue.value = undefined
config.value.defaultValue = selectValue.value
change = true
}
if (change) {
config.value.mapValue = setDefaultMapValue(
Array.isArray(selectValue.value) ? [...selectValue.value] : [selectValue.value]
)
config.value.defaultMapValue = setDefaultMapValue(
Array.isArray(selectValue.value) ? [...selectValue.value] : [selectValue.value]
)
setCascadeValueBack(config.value.mapValue)
}
})
.finally(() => {
@@ -675,8 +689,6 @@ const single = ref()
const getOptionFromCascade = () => {
if (config.value.optionValueSource !== 1 || ![0, 2, 5].includes(+config.value.displayType)) return
config.value.selectValue = config.value.multiple ? [] : undefined
selectValue.value = config.value.multiple ? [] : undefined
isFromRemote.value = true
debounceOptions(1)
}

View File

@@ -6,8 +6,8 @@ import {
isTransparent,
parseJson,
resetRgbOpacity,
safeDecimalMean,
safeDecimalSum
safeDecimalSum,
safeDecimalMean
} from '../..//util'
import {
DEFAULT_BASIC_STYLE,
@@ -50,13 +50,17 @@ import {
filter,
find,
intersection,
isNumber,
keys,
map,
maxBy,
meanBy,
merge,
minBy,
repeat
repeat,
sumBy,
size,
sum,
isNumber
} from 'lodash-es'
import { createVNode, render } from 'vue'
import TableTooltip from '@/views/chart/components/editor/common/TableTooltip.vue'
@@ -2194,7 +2198,7 @@ export class CustomDataCell extends TableDataCell {
* @protected
*/
protected drawTextShape() {
if (this.meta.isMergedCell) {
if(this.meta.isMergedCell) {
return
}
if (this.meta.autoWrap) {
@@ -2238,8 +2242,7 @@ const drawTextShape = (cell, isHeader) => {
// 单元格文本
const { formattedValue } = cell.getFormattedFieldValue()
// 获取文本样式
const textStyle = cloneDeep(cell.getTextStyle())
textStyle.textAlign = undefined
const textStyle = cell.getTextStyle()
// 宽度能放几个字符,就放几个,放不下就换行
let wrapText = getWrapText(
formattedValue ? formattedValue?.toString() : emptyPlaceholder,
@@ -2295,8 +2298,7 @@ const drawTextShape = (cell, isHeader) => {
cell.actualTextWidth = cell.spreadsheet.measureTextWidth(wrapText, textStyle)
// 获取文本位置并渲染文本
const { y } = cell.getTextAndIconPosition()?.text || cell.getTextPosition()
const x = getTextStartX(cell, textStyle)
const { x, y } = cell.getTextAndIconPosition()?.text || cell.getTextPosition()
// 绘制文本
cell.textShape = renderText(cell, [cell.textShape], x, y, wrapText, textStyle, {
fontSize: extraStyleFontSize
@@ -2306,33 +2308,6 @@ const drawTextShape = (cell, isHeader) => {
cell.textShapes.push(cell.textShape)
}
/**
* 计算文本起始X位置
* @param cell
* @param textStyle
*/
function getTextStartX(cell, textStyle) {
// 获取单元格区域
const area = cell.getCellArea()
// 计算文本宽度,只计算第一行宽度
const textWidth = cell.spreadsheet.measureTextWidthRoughly(
cell.actualText.split('\n')[0],
textStyle
)
const padding = cell.theme.colCell?.cell?.padding ?? { left: 0, right: 0 }
const align = cell.getTextStyle()?.textAlign ?? 'left'
switch (align) {
case 'left':
return area.x + (padding.left || 0)
case 'center':
return area.x + (area.width - textWidth) / 2
case 'right':
return area.x + area.width - textWidth - (padding.right || 0)
default:
return area.x + (padding.left || 0)
}
}
/**
* 计算表头高度
* @param info 单元格信息