Skip to content

Commit

Permalink
fix: 字段映射,没字段可选 --bug=137404685
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasikeai committed Jan 22, 2025
1 parent 29ddb2c commit c77ee52
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
}
interface Expose {
getFields: () => IFormData
getTableFields: () => Array<DatabaseTableFieldModel>
}
interface Props {
editData: StrategyModel
Expand Down Expand Up @@ -523,6 +524,9 @@
}
return params;
},
getTableFields() {
return tableFields.value;
},
});
</script>
<style scoped lang="postcss">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@

import type ControlModel from '@model/control/control';
import CommonDataModel from '@model/strategy/common-data';
import DatabaseTableFieldModel from '@model/strategy/database-table-field';
import StrategyModel from '@model/strategy/strategy';

import useRecordPage from '@hooks/use-record-page';
Expand Down Expand Up @@ -596,6 +597,15 @@
}
// 获取审计参数(自定义规则审计、引入模型审计)
const fields = comRef.value.getFields();
// 如果select为空数组,传全部
if (fields.configs.select.length === 0) {
const tableFields: Array<DatabaseTableFieldModel> = comRef.value.getTableFields();
fields.configs.select = tableFields.map(item => ({
...item,
aggregate: null,
display_name: `${item.display_name}_${item.aggregate}`,
}));
}
// 非联表不需要link_table参数
if (fields.configs.config_type !== 'LinkTable' && fields.configs.data_source) {
fields.configs.data_source.link_table = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@
case 'event_basic_field_configs':
// 根据select填充event_basic_field_configs参数
if (tableData.value[key].length && props.select.length) {
// 把不匹配的项清空
tableData.value.event_basic_field_configs = tableData.value.event_basic_field_configs.map((item) => {
if (item.map_config) {
const value = item.map_config.source_field || item.map_config.target_value;
if (!props.select.some(selectItem => selectItem.display_name === value)) {
// eslint-disable-next-line no-param-reassign
item.map_config = {
source_field: undefined,
target_value: undefined,
};
}
}
return item;
});
props.select.forEach((item) => {
if (fieldMap[item.raw_name]) {
const field = tableData.value[key].find(fieldItem => fieldItem.field_name === fieldMap[item.raw_name]);
Expand All @@ -167,17 +181,7 @@
case 'event_data_field_configs':
if (!props.select.length) return;
// 根据select更新event_data_field_configs
// 如果没有event_data_field_configs,根据select生成
if (!tableData.value[key].length) {
tableData.value.event_data_field_configs = props.select.map(item => createField(item));
} else {
// eslint-disable-next-line max-len
const newSelect = props.select.filter(item => !tableData.value.event_data_field_configs.some(field => field.field_name === item.raw_name));
// 第一步添加新的select
newSelect.forEach((item) => {
tableData.value.event_data_field_configs.push(createField(item));
});
}
tableData.value.event_data_field_configs = props.select.map(item => createField(item));
}
};

Expand Down

0 comments on commit c77ee52

Please sign in to comment.