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
57 changes: 53 additions & 4 deletions packages/business/src/views/connections/DatabaseForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@

<script>
import { action } from '@formily/reactive'
import { cloneDeep } from 'lodash'

import i18n from '@tap/i18n'
import { clusterApi, connectionsApi, databaseTypesApi, pdkApi, externalStorageApi, proxyApi } from '@tap/api'
import { VIcon, GitBook } from '@tap/component'
import { SchemaToForm } from '@tap/form'
import { checkConnectionName, isEmpty } from '@tap/shared'
import { checkConnectionName, isEmpty, submitForm } from '@tap/shared'
import Test from './Test'
import { getConnectionIcon } from './util'
import DatabaseTypeDialog from './DatabaseTypeDialog'
Expand Down Expand Up @@ -764,10 +765,12 @@ export default {
}
}
if (id) {
this.getPdkData(id)
await this.getPdkData(id)
delete result.properties.START.properties.__TAPDATA.properties.name
}

this.setConnectionConfig()

this.schemaScope = {
isEdit: !!id,
useAsyncDataSource: (service, fieldName = 'dataSource', ...serviceParams) => {
Expand Down Expand Up @@ -898,13 +901,33 @@ export default {
} catch (e) {
return []
}
},
goToAuthorized: async params => {
const routeQuery = cloneDeep(this.$route.query)
const routeParams = this.$route.params
delete routeQuery['connectionConfig']
let routeUrl = this.$router.resolve({
name: routeParams?.id ? 'connectionsEdit' : 'connectionCreate',
query: routeQuery,
params: routeParams
})

const { __TAPDATA, ...__TAPDATA_CONFIG } = this.$refs.schemaToForm?.getFormValues?.() || {}
const data = Object.assign({}, params, {
url: location.origin + location.pathname + routeUrl.href,
connectionConfig: {
__TAPDATA,
__TAPDATA_CONFIG
}
})
submitForm(params?.target, data)
}
}
this.schemaData = result
this.loadingFrom = false
},
getPdkData(id) {
connectionsApi.getNoSchema(id).then(data => {
async getPdkData(id) {
await connectionsApi.getNoSchema(id).then(data => {
this.model = data
let {
name,
Expand Down Expand Up @@ -947,6 +970,32 @@ export default {
pdkApi.doc(pdkHash).then(res => {
this.doc = res?.data
})
},
async setConnectionConfig() {
const { connectionConfig, pdkHash } = this.$route.query || {}
if (connectionConfig) {
const params = {
pdkHash,
connectionConfig: JSON.parse(connectionConfig),
command: 'OAuth',
type: 'connection'
}
const res = await proxyApi.command(params)
const { __TAPDATA, __TAPDATA_CONFIG = {}, ...trace } = res || JSON.parse(connectionConfig) || {}
Object.assign(
this.model,
__TAPDATA,
{
config: __TAPDATA_CONFIG
},
trace
)
this.schemaFormInstance.setValues({
__TAPDATA,
...__TAPDATA_CONFIG,
...trace
})
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions packages/shared/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ export function openUrl(url, target = '_blank', name = '') {
window.URL.revokeObjectURL(url)
}

export function submitForm(url, obj = {}, method = 'post') {
const form = document.createElement('form')
form.action = url
form.method = method
for (let key in obj) {
const dom = document.createElement('input')
dom.setAttribute('type', 'hidden')
dom.setAttribute('name', key)
dom.value = typeof obj[key] === 'object' ? JSON.stringify(obj[key]) : obj[key]
form.appendChild(dom)
}
document.body.appendChild(form)
form.submit()
form.parentNode.removeChild(form)
}

// 下载Blob
export function downloadBlob(res, name = '') {
if (!res) {
Expand Down