@@ -14,7 +14,7 @@ import DatasourceListSide from './DatasourceListSide.vue'
1414import DatasourceForm from ' ./DatasourceForm.vue'
1515import { datasourceApi } from ' @/api/datasource'
1616import Card from ' ./Card.vue'
17- import { dsTypeWithImg } from ' ./js/ds-type'
17+ import { dsTypeWithImgSort } from ' ./js/ds-type'
1818import { useI18n } from ' vue-i18n'
1919
2020interface Datasource {
@@ -34,20 +34,24 @@ const datasourceConfigvVisible = ref(false)
3434const editDatasource = ref (false )
3535const activeStep = ref (0 )
3636const activeName = ref (' ' )
37+ const activeType = ref (' ' )
3738const datasourceFormRef = ref ()
3839
3940const datasourceList = shallowRef ([] as Datasource [])
40- const defaultDatasourceList = shallowRef (dsTypeWithImg as (Datasource & { img: string })[])
41+ const defaultDatasourceList = shallowRef (dsTypeWithImgSort as (Datasource & { img: string })[])
4142
4243const currentDefaultDatasource = ref (' ' )
4344const datasourceListWithSearch = computed (() => {
44- if (! keywords .value ) return datasourceList .value
45- return datasourceList .value .filter ((ele ) =>
46- ele .name .toLowerCase ().includes (keywords .value .toLowerCase ())
45+ if (! keywords .value && ! currentDatasourceType .value ) return datasourceList .value
46+ return datasourceList .value .filter (
47+ (ele ) =>
48+ ele .name .toLowerCase ().includes (keywords .value .toLowerCase ()) &&
49+ (ele .type === currentDatasourceType .value || ! currentDatasourceType .value )
4750 )
4851})
4952const beforeClose = () => {
5053 datasourceConfigvVisible .value = false
54+ activeStep .value = 0
5155}
5256const defaultDatasourceListWithSearch = computed (() => {
5357 if (! defaultDatasourceKeywords .value ) return defaultDatasourceList .value
@@ -56,8 +60,16 @@ const defaultDatasourceListWithSearch = computed(() => {
5660 )
5761})
5862
63+ const currentDatasourceType = ref (' ' )
64+
5965const handleDefaultDatasourceChange = (item : any ) => {
60- currentDefaultDatasource .value = item .name
66+ if (currentDatasourceType .value === item .type ) {
67+ currentDefaultDatasource .value = ' '
68+ currentDatasourceType .value = ' '
69+ } else {
70+ currentDefaultDatasource .value = item .name
71+ currentDatasourceType .value = item .type
72+ }
6173}
6274
6375const formatKeywords = (item : string ) => {
@@ -92,6 +104,14 @@ const handleAddDatasource = () => {
92104 datasourceConfigvVisible .value = true
93105}
94106
107+ const refresh = () => {
108+ activeName .value = ' '
109+ activeStep .value = 0
110+ activeType .value = ' '
111+ datasourceConfigvVisible .value = false
112+ search ()
113+ }
114+
95115const deleteHandler = (item : any ) => {
96116 ElMessageBox .confirm (t (' datasource.data_source' , { msg: item .name }), {
97117 confirmButtonType: ' danger' ,
@@ -124,11 +144,12 @@ const deleteHandler = (item: any) => {
124144const clickDatasource = (ele : any ) => {
125145 activeStep .value = 1
126146 activeName .value = ele .name
147+ activeType .value = ele .type
127148}
128149
129150const clickDatasourceSide = (ele : any ) => {
130151 activeName .value = ele .name
131- activeStep .value = 1
152+ activeType .value = ele . type
132153}
133154
134155const search = () => {
@@ -138,28 +159,6 @@ const search = () => {
138159}
139160search ()
140161
141- const submit = (item : any ) => {
142- if (! item .id ) {
143- datasourceApi .add (item ).then (() => {
144- beforeClose ()
145- search ()
146- ElMessage ({
147- type: ' success' ,
148- message: ' Add completed' ,
149- })
150- })
151- return
152- }
153- datasourceApi .edit (item ).then (() => {
154- beforeClose ()
155- search ()
156- ElMessage ({
157- type: ' success' ,
158- message: ' Edit completed' ,
159- })
160- })
161- }
162-
163162const currentDataTable = ref ()
164163const dataTableDetail = (ele : any ) => {
165164 currentDataTable .value = ele
@@ -187,7 +186,7 @@ const dataTableDetail = (ele: any) => {
187186 <el-popover popper-class =" system-default_datasource" placement =" bottom" >
188187 <template #reference >
189188 <el-button secondary >
190- {{ $t('datasource.all_types') }}
189+ {{ currentDefaultDatasource || $t('datasource.all_types') }}
191190 <el-icon style =" margin-left : 8px " >
192191 <arrow _down ></arrow _down >
193192 </el-icon > </el-button
@@ -298,7 +297,8 @@ const dataTableDetail = (ele: any) => {
298297 ref =" datasourceFormRef"
299298 :active-step =" activeStep"
300299 :active-name =" activeName"
301- @submit =" submit"
300+ :active-type =" activeType"
301+ @refresh =" refresh"
302302 @change-active-step =" (val: number) => (activeStep = val)"
303303 ></DatasourceForm >
304304 </el-drawer >
@@ -324,6 +324,8 @@ const dataTableDetail = (ele: any) => {
324324 .card-content {
325325 display : flex ;
326326 flex-wrap : wrap ;
327+ max-height : calc (100% - 40px );
328+ overflow-y : auto ;
327329 }
328330}
329331 </style >
0 commit comments