diff --git a/io.sc.platform.core.frontend/src/platform/components/query-builder/WQueryBuilder.vue b/io.sc.platform.core.frontend/src/platform/components/query-builder/WQueryBuilder.vue index 04cbd8fe..9391b828 100644 --- a/io.sc.platform.core.frontend/src/platform/components/query-builder/WQueryBuilder.vue +++ b/io.sc.platform.core.frontend/src/platform/components/query-builder/WQueryBuilder.vue @@ -365,6 +365,8 @@ watch( if (Tools.isEmpty(newVal)) { modelValueObject['operator'] = criteriaMode.and.name; modelValueObject['criteria'] = [{ fieldName: '', operator: criteriaOperator.equals.name, value: undefined }]; + } else if (newVal !== oldVal && Tools.isEmpty(modelValueObject['criteria'][0]['fieldName'])) { + sqlToCriteria(modelValue.value); } } if (newVal !== oldVal) { @@ -379,6 +381,19 @@ const getSqlValue = () => { const getCriteriaValue = () => { return props.mode === 'criteria' ? modelValue.value : toRaw(modelValueObject); }; +const sqlToCriteria = (sql) => { + const sqlPrefix = 'select * from t where '; + const criteria = CriteriaUtil.sqlToCriteria(sqlPrefix + sql); + // 转换后的 criteria 值还需根据使用的组件进一步进行处理 + criteria['criteria'].forEach((item) => { + const field = getUseField(item['fieldName']); + if ((field['type'] === 'w-select' || field['type'] === 'w-checkbox-group') && !Array.isArray(item['value'])) { + item['value'] = [item['value']]; + } + }); + modelValueObject['operator'] = criteria['operator']; + modelValueObject['criteria'] = criteria['criteria']; +}; onBeforeMount(() => { if (Tools.isEmpty(modelValue.value)) { @@ -397,10 +412,7 @@ onBeforeMount(() => { modelValueObject['operator'] = modelValue.value['operator']; modelValueObject['criteria'] = modelValue.value['criteria']; } else { - const sqlPrefix = 'select * from t where '; - const criteria = CriteriaUtil.sqlToCriteria(sqlPrefix + modelValue.value); - modelValueObject['operator'] = criteria['operator']; - modelValueObject['criteria'] = criteria['criteria']; + sqlToCriteria(modelValue.value); } } });