1
1
<template >
2
2
<div class =" m-editor-data-source-field-select" >
3
- <TMagicSelect
4
- :model-value =" selectDataSourceId"
5
- clearable
6
- filterable
7
- :size =" size"
8
- :disabled =" disabled"
9
- @change =" dsChangeHandler"
10
- >
11
- <component
12
- v-for =" option in dataSourcesOptions"
13
- class =" tmagic-design-option"
14
- :key =" option.value"
15
- :is =" optionComponent?.component || 'el-option'"
16
- v-bind ="
17
- optionComponent?.props({
18
- label: option.text,
19
- value: option.value,
20
- disabled: option.disabled,
21
- }) || {
22
- label: option.text,
23
- value: option.value,
24
- disabled: option.disabled,
25
- }
26
- "
3
+ <template v-if =" checkStrictly " >
4
+ <TMagicSelect
5
+ :model-value =" selectDataSourceId"
6
+ clearable
7
+ filterable
8
+ :size =" size"
9
+ :disabled =" disabled"
10
+ @change =" dsChangeHandler"
27
11
>
28
- </component >
29
- </TMagicSelect >
12
+ <component
13
+ v-for =" option in dataSourcesOptions"
14
+ class =" tmagic-design-option"
15
+ :key =" option.value"
16
+ :is =" optionComponent?.component || 'el-option'"
17
+ v-bind ="
18
+ optionComponent?.props({
19
+ label: option.text,
20
+ value: option.value,
21
+ disabled: option.disabled,
22
+ }) || {
23
+ label: option.text,
24
+ value: option.value,
25
+ disabled: option.disabled,
26
+ }
27
+ "
28
+ >
29
+ </component >
30
+ </TMagicSelect >
31
+
32
+ <TMagicCascader
33
+ :model-value =" selectFieldsId"
34
+ clearable
35
+ filterable
36
+ :size =" size"
37
+ :disabled =" disabled"
38
+ :options =" fieldsOptions"
39
+ :props =" {
40
+ checkStrictly,
41
+ }"
42
+ @change =" fieldChangeHandler"
43
+ ></TMagicCascader >
44
+ </template >
30
45
31
46
<TMagicCascader
32
- :model-value = " selectFieldsId "
47
+ v-else
33
48
clearable
34
49
filterable
35
- :size = " size "
50
+ :model-value = " modelValue "
36
51
:disabled =" disabled"
37
- :options =" fieldsOptions"
52
+ :size =" size"
53
+ :options =" cascaderOptions"
38
54
:props =" {
39
55
checkStrictly,
40
56
}"
41
- @change =" fieldChangeHandler "
57
+ @change =" onChangeHandler "
42
58
></TMagicCascader >
43
59
44
60
<TMagicButton
@@ -132,6 +148,16 @@ const fieldsOptions = computed(() => {
132
148
return getCascaderOptionsFromFields (ds .fields , props .dataSourceFieldType );
133
149
});
134
150
151
+ const cascaderOptions = computed (() => {
152
+ const options =
153
+ dataSources .value ?.map ((ds ) => ({
154
+ label: ds .title || ds .id ,
155
+ value: valueIsKey .value ? ds .id : ` ${DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX }${ds .id } ` ,
156
+ children: getCascaderOptionsFromFields (ds .fields , props .dataSourceFieldType ),
157
+ })) || [];
158
+ return options .filter ((option ) => option .children .length );
159
+ });
160
+
135
161
const dsChangeHandler = (v : string ) => {
136
162
modelValue .value = [v ];
137
163
emit (' change' , modelValue .value );
@@ -142,6 +168,11 @@ const fieldChangeHandler = (v: string[] = []) => {
142
168
emit (' change' , modelValue .value );
143
169
};
144
170
171
+ const onChangeHandler = (v : string [] = []) => {
172
+ modelValue .value = v ;
173
+ emit (' change' , v );
174
+ };
175
+
145
176
const hasDataSourceSidePanel = computed (() =>
146
177
(services ?.uiService .get (' sideBarItems' ) || []).find ((item ) => item .$key === SideItemKey .DATA_SOURCE ),
147
178
);
0 commit comments