From b8c59be4ffa49a152fe9b981fea3430f1c98c72c Mon Sep 17 00:00:00 2001 From: dataeaseShu Date: Wed, 10 Apr 2024 16:21:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=9F=A5=E8=AF=A2=E7=BB=84=E4=BB=B6):=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=96=87=E6=9C=AC=E6=90=9C=E7=B4=A2=20#7715?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v-query/QueryConditionConfiguration.vue | 217 +++++++++++++++++- .../custom-component/v-query/StyleInject.vue | 4 + .../custom-component/v-query/TextSearch.vue | 163 +++++++++++++ core/core-frontend/src/hooks/web/useFilter.ts | 89 ++++++- 4 files changed, 464 insertions(+), 9 deletions(-) create mode 100644 core/core-frontend/src/custom-component/v-query/TextSearch.vue diff --git a/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue b/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue index 03cdbf268f..ed30f6b11a 100644 --- a/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue +++ b/core/core-frontend/src/custom-component/v-query/QueryConditionConfiguration.vue @@ -171,6 +171,7 @@ const handleCheckAllChange = (val: boolean) => { isIndeterminate.value = false } const handleCheckedFieldsChange = (value: string[]) => { + if (curComponent.value.displayType === '8') return handleDialogClick() const checkedCount = value.length checkAll.value = checkedCount === fields.value.length @@ -369,6 +370,31 @@ const isInRange = (ele, startWindowTime, timeStamp) => { } } +const validateConditionType = ({ + defaultConditionValueF, + defaultConditionValueS, + conditionType +}) => { + if (conditionType === 0) { + return defaultConditionValueF === '' + } else { + return defaultConditionValueF === '' || defaultConditionValueS === '' + } +} + +const setParams = ele => { + const { + defaultConditionValueOperatorF, + defaultConditionValueF, + defaultConditionValueOperatorS, + defaultConditionValueS + } = ele + ele.conditionValueOperatorF = defaultConditionValueOperatorF + ele.conditionValueF = defaultConditionValueF + ele.conditionValueOperatorS = defaultConditionValueOperatorS + ele.conditionValueS = defaultConditionValueS +} + const validate = () => { return conditions.value.some(ele => { if (ele.auto) return false @@ -378,6 +404,15 @@ const validate = () => { } if (ele.required) { + if (ele.displayType === '8') { + setParams(ele) + const result = validateConditionType(ele) + if (result) { + ElMessage.error('查询条件为必填项,默认值不能为空') + } + return result + } + if (!ele.defaultValueCheck) { ElMessage.error('查询条件为必填项,默认值不能为空') return true @@ -392,6 +427,11 @@ const validate = () => { } } + if (ele.displayType === '8') { + setParams(ele) + return false + } + if (+ele.displayType === 7) { if (!ele.defaultValueCheck) return false if (ele.timeType === 'fixed') { @@ -633,6 +673,15 @@ const parameterCompletion = () => { timeType: 'fixed', required: false, parametersStart: null, + conditionType: 0, + conditionValueOperatorF: 'eq', + conditionValueF: '', + conditionValueOperatorS: 'like', + conditionValueS: '', + defaultConditionValueOperatorF: 'eq', + defaultConditionValueF: '', + defaultConditionValueOperatorS: 'like', + defaultConditionValueS: '', parametersEnd: null, relativeToCurrent: 'custom', timeNum: 0, @@ -645,6 +694,7 @@ const parameterCompletion = () => { arbitraryTimeRange: new Date(), setTimeRange: false, showEmpty: false, + conditionType: 0, timeRange: { intervalType: 'none', dynamicWindow: false, @@ -715,7 +765,7 @@ const showError = computed(() => { if (!checkedFields.length || !arr.length) { return true } - if ([1, 7].includes(+displayType)) { + if ([1, 7, 8].includes(+displayType)) { return false } return (optionValueSource === 1 && !field.id) || (optionValueSource === 2 && !valueSource.length) @@ -723,6 +773,17 @@ const showError = computed(() => { const handleDialogClick = () => { visiblePopover.value = false } + +const operators = [ + { + label: '精准匹配', + value: 'eq' + }, + { + label: '模糊匹配', + value: 'like' + } +] const relativeToCurrentList = computed(() => { let list = [] if (!curComponent.value) return list @@ -1154,10 +1215,15 @@ defineExpose({ v-model="curComponent.displayType" > + -
+
选项值来源
@@ -1362,7 +1431,69 @@ defineExpose({
-
+
+
条件类型
+
+
+ + 单条件 + 与条件 + 或条件 + +
+
+
+
+
设置默认值
+
+
+ + + + + +
+
+
+ {{ + curComponent.conditionType === 1 ? '与' : '或' + }} + + + + + +
+
+
+
+
选项类型
-
+
-
+
@@ -1694,6 +1825,11 @@ defineExpose({ + diff --git a/core/core-frontend/src/hooks/web/useFilter.ts b/core/core-frontend/src/hooks/web/useFilter.ts index 7d56a2a891..8d1e6a693b 100644 --- a/core/core-frontend/src/hooks/web/useFilter.ts +++ b/core/core-frontend/src/hooks/web/useFilter.ts @@ -106,6 +106,56 @@ export const useFilter = (curComponentId: string, firstLoad = false) => { } } +const getResult = ( + conditionType, + defaultConditionValueF, + defaultConditionValueS, + conditionValueF, + conditionValueS, + firstLoad +) => { + const valueF = firstLoad ? defaultConditionValueF : conditionValueF + const valueS = firstLoad ? defaultConditionValueS : conditionValueS + if (conditionType === 0) { + return valueF === '' ? [] : valueF + } + return [valueF || '', valueS || ''].filter(ele => ele !== '') +} + +const getOperator = ( + displayType, + multiple, + conditionType, + defaultConditionValueOperatorF, + defaultConditionValueF, + defaultConditionValueOperatorS, + defaultConditionValueS, + conditionValueOperatorF, + conditionValueF, + conditionValueOperatorS, + conditionValueS, + firstLoad +) => { + const valueF = firstLoad ? defaultConditionValueF : conditionValueF + const valueS = firstLoad ? defaultConditionValueS : conditionValueS + const operatorF = firstLoad ? defaultConditionValueOperatorF : conditionValueOperatorF + const operatorS = firstLoad ? defaultConditionValueOperatorS : conditionValueOperatorS + if (displayType === '8') { + if (conditionType === 0) { + return defaultConditionValueOperatorF + } + const operatorArr = [valueF === '' ? '' : operatorF, valueS === '' ? '' : operatorS].filter( + ele => ele !== '' + ) + if (operatorArr.length === 2) { + return operatorArr.join(`-${conditionType === 1 ? 'and' : 'or'}-`) + } + return valueF === '' ? operatorS : operatorF + } + + return [1, 7].includes(+displayType) ? 'between' : multiple ? 'in' : 'eq' +} + export const searchQuery = (queryComponentList, filter, curComponentId, firstLoad) => { queryComponentList.forEach(ele => { if (!!ele.propValue?.length) { @@ -122,6 +172,15 @@ export const searchQuery = (queryComponentList, filter, curComponentId, firstLoa timeGranularityMultiple, parametersStart, parametersEnd, + conditionType = 0, + defaultConditionValueOperatorF = 'eq', + defaultConditionValueF = '', + defaultConditionValueOperatorS = 'like', + defaultConditionValueS = '', + conditionValueOperatorF = 'eq', + conditionValueF = '', + conditionValueOperatorS = 'like', + conditionValueS = '', defaultValueCheck, timeType = 'fixed', defaultValue, @@ -173,6 +232,15 @@ export const searchQuery = (queryComponentList, filter, curComponentId, firstLoa item.defaultValue = [startTime, endTime] item.selectValue = [startTime, endTime] } + } else if (displayType === '8') { + selectValue = getResult( + conditionType, + defaultConditionValueF, + defaultConditionValueS, + conditionValueF, + conditionValueS, + firstLoad + ) } else { selectValue = getValueByDefaultValueCheckOrFirstLoad( defaultValueCheck, @@ -184,19 +252,34 @@ export const searchQuery = (queryComponentList, filter, curComponentId, firstLoa } if ( !!selectValue?.length || + displayType === '8' || Object.prototype.toString.call(selectValue) === '[object Date]' ) { - const values = forMatterValue( + const result = forMatterValue( +displayType, selectValue, timeGranularity, timeGranularityMultiple ) + const operator = getOperator( + displayType, + multiple, + conditionType, + defaultConditionValueOperatorF, + defaultConditionValueF, + defaultConditionValueOperatorS, + defaultConditionValueS, + conditionValueOperatorF, + conditionValueF, + conditionValueOperatorS, + conditionValueS, + firstLoad + ) filter.push({ componentId: ele.id, fieldId: item.checkedFieldsMap[curComponentId], - operator: [1, 7].includes(+displayType) ? 'between' : multiple ? 'in' : 'eq', - value: values, + operator, + value: result, parameters: parametersCheck ? +displayType === 7 ? [