Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions packages/plugins/datasource/src/DataSourceForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ import { camelize, capitalize } from '@vue/shared'
import { ButtonGroup, PluginSetting, SvgButton } from '@opentiny/tiny-engine-common'
import DataSourceType from './DataSourceType.vue'
import DataSourceName, { getDataSourceName } from './DataSourceName.vue'
import { getServiceForm } from './DataSourceRemoteForm.vue'
import DataSourceSettings from './DataSourceSettings.vue'
import { close as closeRemoteResult, open as openRemoteResult } from './DataSourceSettingRemoteResult.vue'
import { getRecordGrid } from './DataSourceSettingRecordList.vue'
import {
requestUpdateDataSource,
requestAddDataSource,
Expand Down Expand Up @@ -203,12 +205,20 @@ export default {
})
}

const save = () => {
getDataSourceName().validate((valid) => {
if (valid) {
close()
closeRemoteResult()
const activeTabChange = (name) => {
emit('activeTab', name)
}

const save = async () => {
try {
// await validate() 如果验证不通过会抛出异常,而不是返回 false
await getServiceForm().validate()
} catch (error) {
activeTabChange('remote')
return
}
getDataSourceName().validate(async (valid) => {
if (valid) {
const columns = state.dataSource.data.columns.map(({ name, title, type, format, field }) => {
return {
name,
Expand All @@ -219,6 +229,14 @@ export default {
}
})

try {
// await validate() 如果验证不通过会抛出异常,而不是返回 false
await getRecordGrid().fullValidate()
} catch (error) {
activeTabChange('record')
return
}

settingRef.value.saveRecord().then((record) => {
const editRequestData = {
name: state.dataSource.name,
Expand Down Expand Up @@ -254,6 +272,7 @@ export default {
emit('save')
dataSourceState.dataSourceColumn = {}
dataSourceState.dataSourceColumnCopies = {}
dataSourceState.remoteConfig = {}
})
} else {
requestAddDataSource({
Expand All @@ -270,12 +289,15 @@ export default {
emit('save')
dataSourceState.dataSourceColumn = {}
dataSourceState.dataSourceColumnCopies = {}
dataSourceState.remoteConfig = {}
})
.catch((error) => {
message({ message: `数据源保存失败:${error?.message || ''}`, status: 'error' })
})
}
})
close()
closeRemoteResult()
}
})
}
Expand All @@ -298,10 +320,6 @@ export default {
emit('renderRemoteData', remoteData)
}

const activeTabChange = (name) => {
emit('activeTab', name)
}

watch(
() => state.dataSource.data?.type,
(value) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/datasource/src/DataSourceList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { onMounted, reactive, ref } from 'vue'
import { useResource, getMetaApi, META_SERVICE } from '@opentiny/tiny-engine-meta-register'
import { fetchDataSourceList, fetchDataSourceDetail } from './js/http'
import { SvgButton } from '@opentiny/tiny-engine-common'
import { getServiceForm } from './DataSourceRemoteForm.vue'

const dataSourceList = ref([])
const activeIndex = ref(-1)
Expand Down Expand Up @@ -74,6 +75,7 @@ export default {
data: { ...item.data, type: 'remote' }
}
emit('edit', editData)
getServiceForm()?.clearValidate()
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ import { fetchDataSourceDetail } from './js/http'
import { downloadFn, handleImportedData, overrideOrMergeData, getDataAfterPage } from './js/datasource'
import DataSourceRecordUpload from './DataSourceRecordUpload.vue'

const grid = ref(null)

export const getRecordGrid = () => {
return grid.value
}
Comment thread
xuanlid marked this conversation as resolved.

export default {
components: {
TinyGrid: Grid,
Expand All @@ -90,7 +96,6 @@ export default {
},
emits: ['edit'],
setup(props, { emit }) {
const grid = ref(null)
const { confirm } = useModal()
const { PLUGIN_NAME, getPluginByLayout } = useLayout()
const align = computed(() => getPluginByLayout(PLUGIN_NAME.Collections))
Expand Down
6 changes: 6 additions & 0 deletions packages/plugins/datasource/src/DataSourceSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
:data="state.currentData"
ref="recordRef"
@refresh="refresh()"
@edit="changeTab()"
></data-source-setting-record-list>
</tiny-tab-item>
</tiny-tabs>
Expand Down Expand Up @@ -93,6 +94,10 @@ export default {
closeGlobalDataHandler()
}

const changeTab = () => {
state.activeTabName = 'field'
}

const tabClick = (e) => {
state.activeTabName = e.name
emit('activeTab', e.name)
Expand Down Expand Up @@ -144,6 +149,7 @@ export default {
tabClick,
renderRemoteData,
refresh,
changeTab,
saveRecord
}
}
Expand Down