mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-29 22:16:36 +08:00
feat(editor): 数据源选择器支持选择数据源id
This commit is contained in:
parent
c80ea829ac
commit
cdba8aeaf2
@ -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,19 +45,24 @@ 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
|
||||||
isBindDataSource: true,
|
? ds.id
|
||||||
dataSourceType: ds.type,
|
: {
|
||||||
dataSourceId: ds.id,
|
isBindDataSource: true,
|
||||||
},
|
dataSourceType: ds.type,
|
||||||
|
dataSourceId: ds.id,
|
||||||
|
},
|
||||||
text: ds.title || ds.id,
|
text: ds.title || ds.id,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user