11<template >
22 <div class =" m-editor-data-source-field-select" >
3- <template v-if =" checkStrictly " >
3+ <template v-if =" dataSourceId " >
4+ <TMagicCascader
5+ :model-value =" selectFieldsId"
6+ clearable
7+ filterable
8+ :size =" size"
9+ :disabled =" disabled"
10+ :options =" fieldsOptions"
11+ :props =" {
12+ checkStrictly,
13+ }"
14+ @change =" fieldChangeHandler"
15+ ></TMagicCascader >
16+ </template >
17+
18+ <template v-else-if =" checkStrictly " >
419 <TMagicSelect
520 :model-value =" selectDataSourceId"
621 clearable
@@ -92,6 +107,8 @@ const props = defineProps<{
92107 dataSourceFieldType? : DataSourceFieldType [];
93108 /** 是否可以编辑数据源,disable表示的是是否可以选择数据源 */
94109 notEditable? : boolean | FilterFunction ;
110+ /** 指定数据源ID,限定只能选择该数据源的字段 */
111+ dataSourceId? : string ;
95112}>();
96113
97114const emit = defineEmits <{
@@ -106,7 +123,12 @@ const { dataSourceService, uiService } = useServices();
106123const mForm = inject <FormState | undefined >(' mForm' );
107124const eventBus = inject <EventBus >(' eventBus' );
108125
109- const dataSources = computed (() => dataSourceService .get (' dataSources' ) || []);
126+ const allDataSources = computed (() => dataSourceService .get (' dataSources' ) || []);
127+
128+ const dataSources = computed (() => {
129+ if (! props .dataSourceId ) return allDataSources .value ;
130+ return allDataSources .value .filter ((ds ) => ds .id === props .dataSourceId );
131+ });
110132
111133const valueIsKey = computed (() => props .value === ' key' );
112134const notEditable = computed (() => filterFunction (mForm , props .notEditable , props ));
@@ -125,7 +147,13 @@ const selectFieldsId = ref<string[]>([]);
125147watch (
126148 modelValue ,
127149 (value ) => {
128- if (Array .isArray (value )) {
150+ if (props .dataSourceId ) {
151+ const dsIdValue = valueIsKey .value
152+ ? props .dataSourceId
153+ : ` ${DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX }${props .dataSourceId } ` ;
154+ selectDataSourceId .value = dsIdValue ;
155+ selectFieldsId .value = Array .isArray (value ) ? value : [];
156+ } else if (Array .isArray (value ) && value .length ) {
129157 const [dsId, ... fields] = value ;
130158 selectDataSourceId .value = dsId ;
131159 selectFieldsId .value = fields ;
@@ -140,7 +168,7 @@ watch(
140168);
141169
142170const fieldsOptions = computed (() => {
143- const ds = dataSources .value .find ((ds ) => ds .id === removeDataSourceFieldPrefix (selectDataSourceId .value ));
171+ const ds = allDataSources .value .find ((ds ) => ds .id === removeDataSourceFieldPrefix (selectDataSourceId .value ));
144172
145173 if (! ds ) return [];
146174
@@ -163,8 +191,13 @@ const dsChangeHandler = (v: string) => {
163191};
164192
165193const fieldChangeHandler = (v : string [] = []) => {
166- modelValue .value = [selectDataSourceId .value , ... v ];
167- emit (' change' , modelValue .value );
194+ if (props .dataSourceId ) {
195+ modelValue .value = v ;
196+ emit (' change' , v );
197+ } else {
198+ modelValue .value = [selectDataSourceId .value , ... v ];
199+ emit (' change' , modelValue .value );
200+ }
168201};
169202
170203const onChangeHandler = (v : string [] = []) => {
0 commit comments