feat(editor): 数据源选择器支持选择数据源id

This commit is contained in:
roymondchen 2023-11-21 11:32:59 +08:00
parent c80ea829ac
commit cdba8aeaf2

View File

@ -29,9 +29,10 @@ const props = withDefaults(
FieldProps<{ FieldProps<{
type: 'data-source-select'; type: 'data-source-select';
name: string; name: string;
text: string; text?: string;
placeholder: string; placeholder?: string;
dataSourceType?: string; dataSourceType?: string;
value?: 'id' | 'value';
}> }>
>(), >(),
{ {
@ -44,15 +45,20 @@ const { dataSourceService } = inject<Services>('services') || {};
const dataSources = computed(() => dataSourceService?.get('dataSources') || []); const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
const selectConfig = computed<SelectConfig>(() => { const selectConfig = computed<SelectConfig>(() => {
const { type, dataSourceType, ...config } = props.config; const { type, dataSourceType, value, ...config } = props.config;
const valueIsId = props.config.value === 'id';
return { return {
...config, ...config,
type: 'select', type: 'select',
valueKey: 'dataSourceId', valueKey: 'dataSourceId',
options: dataSources.value options: dataSources.value
.filter((ds) => !dataSourceType || ds.type === dataSourceType) .filter((ds) => !props.config.dataSourceType || ds.type === props.config.dataSourceType)
.map((ds) => ({ .map((ds) => ({
value: { value: valueIsId
? ds.id
: {
isBindDataSource: true, isBindDataSource: true,
dataSourceType: ds.type, dataSourceType: ds.type,
dataSourceId: ds.id, dataSourceId: ds.id,