1
0
mirror of synced 2026-04-03 06:28:35 +08:00

feat(editor, core): 支持直接绑定整个数据源对象

This commit is contained in:
roymondchen
2023-06-28 16:39:47 +08:00
parent 649720079a
commit 74c9deaa29
11 changed files with 185 additions and 30 deletions

View File

@@ -0,0 +1,75 @@
<template>
<MSelect
:model="model"
:name="name"
:size="size"
:prop="prop"
:disabled="disabled"
:config="selectConfig"
:last-values="lastValues"
@change="changeHandler"
></MSelect>
</template>
<script setup lang="ts">
import { computed, inject } from 'vue';
import { FieldSize } from '@tmagic/design';
import { MSelect, SelectConfig } from '@tmagic/form';
import { Services } from '../type';
defineOptions({
name: 'MEditorDataSourceSelect',
});
const emit = defineEmits(['change']);
const props = withDefaults(
defineProps<{
config: {
type: 'data-source-select';
name: string;
text: string;
placeholder: string;
dataSourceType?: string;
};
model: Record<string, any>;
name: string;
prop: string;
disabled: boolean;
lastValues?: Record<string, any>;
size?: FieldSize;
}>(),
{
disabled: false,
},
);
const { dataSourceService } = inject<Services>('services') || {};
const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
const selectConfig = computed<SelectConfig>(() => {
const { type, dataSourceType, ...config } = props.config;
return {
...config,
type: 'select',
valueKey: 'dataSourceId',
options: dataSources.value
.filter((ds) => !dataSourceType || ds.type === dataSourceType)
.map((ds) => ({
value: {
isBindDataSource: true,
dataSourceType: ds.type,
dataSourceId: ds.id,
},
text: ds.title || ds.id,
})),
};
});
const changeHandler = (value: any) => {
emit('change', value);
};
</script>