2021-04-29 15:38:03 +08:00
|
|
|
<template>
|
2021-06-17 18:58:46 +08:00
|
|
|
<layout-content :header="formType=='add' ? $t('datasource.create') : $t('datasource.modify')">
|
|
|
|
<template v-slot:header>
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-icon name="back" class="back-button" @click.native="backToList" />
|
2021-11-24 18:49:41 +08:00
|
|
|
{{
|
|
|
|
params && params.id && params.showModel && params.showModel === 'show' && !canEdit ? $t('datasource.show_info') : formType == 'add' ? $t('datasource.create') : $t('datasource.modify')
|
|
|
|
}}
|
2021-06-17 18:58:46 +08:00
|
|
|
</template>
|
2021-06-22 11:54:53 +08:00
|
|
|
<div>
|
2021-04-29 15:38:03 +08:00
|
|
|
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-form
|
|
|
|
ref="dsForm"
|
|
|
|
:model="form"
|
|
|
|
:rules="rule"
|
|
|
|
size="small"
|
|
|
|
:disabled="params && params.id && params.showModel && params.showModel === 'show' && !canEdit "
|
|
|
|
label-width="180px"
|
|
|
|
label-position="right"
|
|
|
|
>
|
2021-06-22 11:54:53 +08:00
|
|
|
<el-form-item :label="$t('commons.name')" prop="name">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-input v-model="form.name" autocomplete="off" />
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item :label="$t('commons.description')" prop="desc">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-input v-model="form.desc" autocomplete="off" />
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item :label="$t('datasource.type')" prop="type">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-select
|
|
|
|
v-model="form.type"
|
|
|
|
:placeholder="$t('datasource.please_choose_type')"
|
|
|
|
class="select-width"
|
|
|
|
:disabled="formType=='modify' || (formType==='add' && params && !!params.type)"
|
|
|
|
@change="changeType()"
|
|
|
|
>
|
2021-06-22 11:54:53 +08:00
|
|
|
<el-option
|
|
|
|
v-for="item in allTypes"
|
|
|
|
:key="item.name"
|
|
|
|
:label="item.label"
|
|
|
|
:value="item.name"
|
|
|
|
/>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
2021-04-29 15:38:03 +08:00
|
|
|
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-form-item
|
|
|
|
v-if="form.configuration.dataSourceType=='jdbc'"
|
|
|
|
:label="$t('datasource.host')"
|
|
|
|
prop="configuration.host"
|
|
|
|
>
|
|
|
|
<el-input v-model="form.configuration.host" autocomplete="off" />
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form-item>
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-form-item
|
|
|
|
v-if="form.configuration.dataSourceType=='es'"
|
|
|
|
:label="$t('datasource.datasource_url')"
|
|
|
|
prop="configuration.url"
|
|
|
|
>
|
|
|
|
<el-input
|
|
|
|
v-model="form.configuration.url"
|
|
|
|
:placeholder="$t('datasource.please_input_datasource_url')"
|
|
|
|
autocomplete="off"
|
|
|
|
/>
|
2021-09-08 15:49:25 +08:00
|
|
|
</el-form-item>
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-form-item
|
|
|
|
v-if="form.configuration.dataSourceType=='jdbc'"
|
|
|
|
:label="$t('datasource.data_base')"
|
|
|
|
prop="configuration.dataBase"
|
|
|
|
>
|
|
|
|
<el-input v-model="form.configuration.dataBase" autocomplete="off" />
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form-item>
|
2021-06-30 10:11:12 +08:00
|
|
|
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-form-item
|
|
|
|
v-if="form.type=='oracle'"
|
|
|
|
:label="$t('datasource.oracle_connection_type')"
|
|
|
|
prop="configuration.connectionType"
|
|
|
|
>
|
2021-06-30 10:11:12 +08:00
|
|
|
<el-radio v-model="form.configuration.connectionType" label="sid">{{ $t('datasource.oracle_sid') }}</el-radio>
|
2021-11-24 18:49:41 +08:00
|
|
|
<el-radio v-model="form.configuration.connectionType" label="serviceName">
|
|
|
|
{{ $t('datasource.oracle_service_name') }}
|
|
|
|
</el-radio>
|
2021-06-30 10:11:12 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
2021-11-10 18:42:44 +08:00
|
|
|
<el-form-item v-if="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.user_name')">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-input v-model="form.configuration.username" autocomplete="off" />
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form-item>
|
2021-11-10 18:42:44 +08:00
|
|
|
<el-form-item v-if="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.password')">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-input v-model="form.configuration.password" autocomplete="off" show-password />
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form-item>
|
2021-11-24 18:49:41 +08:00
|
|
|
<el-form-item v-if="form.configuration.dataSourceType=='es'" :label="$t('datasource.user_name')">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-input v-model="form.configuration.esUsername" autocomplete="off" />
|
2021-09-29 16:55:55 +08:00
|
|
|
</el-form-item>
|
2021-11-24 18:49:41 +08:00
|
|
|
<el-form-item v-if="form.configuration.dataSourceType=='es'" :label="$t('datasource.password')">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-input v-model="form.configuration.esPassword" autocomplete="off" show-password />
|
2021-09-29 16:55:55 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-form-item
|
|
|
|
v-if="form.configuration.dataSourceType=='jdbc' && form.type!=='oracle'"
|
|
|
|
:label="$t('datasource.extra_params')"
|
|
|
|
>
|
|
|
|
<el-input v-model="form.configuration.extraParams" autocomplete="off" />
|
2021-09-29 18:26:47 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-form-item
|
|
|
|
v-if="form.configuration.dataSourceType=='jdbc'"
|
|
|
|
:label="$t('datasource.port')"
|
|
|
|
prop="configuration.port"
|
|
|
|
>
|
|
|
|
<el-input v-model="form.configuration.port" autocomplete="off" type="number" min="0" />
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form-item>
|
2021-11-01 17:33:31 +08:00
|
|
|
<el-form-item v-if="form.type=='oracle' || form.type=='sqlServer' || form.type=='pg' || form.type=='redshift'">
|
2021-07-05 12:17:16 +08:00
|
|
|
<el-button icon="el-icon-plus" size="mini" @click="getSchema()">
|
|
|
|
{{ $t('datasource.get_schema') }}
|
|
|
|
</el-button>
|
|
|
|
</el-form-item>
|
|
|
|
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-form-item
|
|
|
|
v-if="form.type=='oracle' || form.type=='sqlServer' || form.type=='pg' || form.type=='redshift'"
|
|
|
|
:label="$t('datasource.schema')"
|
|
|
|
>
|
|
|
|
<el-select
|
|
|
|
v-model="form.configuration.schema"
|
|
|
|
filterable
|
|
|
|
:placeholder="$t('datasource.please_choose_schema')"
|
|
|
|
class="select-width"
|
|
|
|
>
|
2021-07-05 12:17:16 +08:00
|
|
|
<el-option
|
|
|
|
v-for="item in schemas"
|
|
|
|
:key="item"
|
|
|
|
:label="item"
|
|
|
|
:value="item"
|
|
|
|
/>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
2021-09-08 15:49:25 +08:00
|
|
|
<el-collapse v-if="form.configuration.dataSourceType=='jdbc'">
|
2021-08-16 18:05:46 +08:00
|
|
|
<el-collapse-item :title="$t('datasource.priority')" name="1">
|
2021-09-08 15:49:25 +08:00
|
|
|
<el-form-item :label="$t('datasource.initial_pool_size')" prop="configuration.initialPoolSize">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-input
|
|
|
|
v-model="form.configuration.initialPoolSize"
|
|
|
|
autocomplete="off"
|
|
|
|
type="number"
|
|
|
|
min="0"
|
|
|
|
size="small"
|
|
|
|
/>
|
2021-08-16 18:05:46 +08:00
|
|
|
</el-form-item>
|
2021-09-08 15:49:25 +08:00
|
|
|
<el-form-item :label="$t('datasource.min_pool_size')" prop="configuration.minPoolSize">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-input v-model="form.configuration.minPoolSize" autocomplete="off" type="number" min="0" />
|
2021-08-16 18:05:46 +08:00
|
|
|
</el-form-item>
|
2021-09-08 15:49:25 +08:00
|
|
|
<el-form-item :label="$t('datasource.max_pool_size')" prop="configuration.maxPoolSize">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-input v-model="form.configuration.maxPoolSize" autocomplete="off" type="number" min="0" />
|
2021-08-16 18:05:46 +08:00
|
|
|
</el-form-item>
|
2021-07-05 12:17:16 +08:00
|
|
|
|
2021-08-16 18:05:46 +08:00
|
|
|
</el-collapse-item>
|
|
|
|
</el-collapse>
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form>
|
|
|
|
<div v-if="canEdit" slot="footer" class="dialog-footer">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-button
|
|
|
|
v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)"
|
|
|
|
@click="validaDatasource"
|
|
|
|
>{{ $t('commons.validate') }}
|
2021-11-24 18:49:41 +08:00
|
|
|
</el-button>
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-button
|
|
|
|
v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)"
|
|
|
|
type="primary"
|
|
|
|
@click="save"
|
|
|
|
>{{ $t('commons.save') }}
|
2021-11-24 18:49:41 +08:00
|
|
|
</el-button>
|
2021-06-22 11:54:53 +08:00
|
|
|
</div>
|
|
|
|
<div v-else slot="footer" class="dialog-footer">
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-button
|
|
|
|
v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)"
|
|
|
|
@click="validaDatasource"
|
|
|
|
>{{ $t('commons.validate') }}
|
2021-11-24 18:49:41 +08:00
|
|
|
</el-button>
|
2021-12-01 18:04:53 +08:00
|
|
|
<el-button
|
|
|
|
v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)"
|
|
|
|
type="primary"
|
|
|
|
@click="changeEdit"
|
|
|
|
>{{ $t('commons.edit') }}
|
2021-11-24 18:49:41 +08:00
|
|
|
</el-button>
|
2021-06-22 11:54:53 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-29 15:38:03 +08:00
|
|
|
</layout-content>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import LayoutContent from '@/components/business/LayoutContent'
|
2021-12-01 18:04:53 +08:00
|
|
|
import { addDs, editDs, getSchema, validateDs, validateDsById } from '@/api/system/datasource'
|
|
|
|
import { $confirm } from '@/utils/message'
|
2021-12-01 11:56:05 +08:00
|
|
|
import i18n from '@/lang/index'
|
2021-08-03 12:21:10 +08:00
|
|
|
|
2021-04-29 15:38:03 +08:00
|
|
|
export default {
|
2021-06-17 18:58:46 +08:00
|
|
|
name: 'DsForm',
|
2021-12-01 18:04:53 +08:00
|
|
|
components: { LayoutContent },
|
2021-06-17 18:58:46 +08:00
|
|
|
props: {
|
|
|
|
params: {
|
|
|
|
type: Object,
|
|
|
|
default: null
|
|
|
|
}
|
|
|
|
},
|
2021-04-29 15:38:03 +08:00
|
|
|
data() {
|
|
|
|
return {
|
2021-08-16 18:27:20 +08:00
|
|
|
form: {
|
|
|
|
configuration: {
|
2021-08-16 18:05:46 +08:00
|
|
|
initialPoolSize: 5,
|
2021-10-11 12:19:19 +08:00
|
|
|
extraParams: '',
|
2021-08-16 18:05:46 +08:00
|
|
|
minPoolSize: 5,
|
|
|
|
maxPoolSize: 50,
|
|
|
|
maxIdleTime: 30,
|
|
|
|
acquireIncrement: 5,
|
|
|
|
idleConnectionTestPeriod: 5,
|
|
|
|
connectTimeout: 5
|
2021-08-16 18:27:20 +08:00
|
|
|
}
|
|
|
|
},
|
2021-04-29 15:38:03 +08:00
|
|
|
rule: {
|
2021-12-01 18:04:53 +08:00
|
|
|
name: [{ required: true, message: i18n.t('datasource.input_name'), trigger: 'blur' },
|
|
|
|
{ min: 2, max: 25, message: i18n.t('datasource.input_limit_2_25', [2, 25]), trigger: 'blur' }],
|
|
|
|
desc: [{ min: 0, max: 50, message: i18n.t('datasource.input_limit_0_50'), trigger: 'blur' }],
|
|
|
|
type: [{ required: true, message: i18n.t('datasource.please_choose_type'), trigger: 'change' }],
|
2021-11-24 18:49:41 +08:00
|
|
|
'configuration.dataBase': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_input_data_base'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'blur'
|
|
|
|
}],
|
|
|
|
'configuration.connectionType': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_select_oracle_type'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'blur'
|
|
|
|
}],
|
|
|
|
'configuration.username': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_input_user_name'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'blur'
|
|
|
|
}],
|
|
|
|
'configuration.password': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_input_password'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'change'
|
|
|
|
}],
|
2021-12-01 18:04:53 +08:00
|
|
|
'configuration.host': [{ required: true, message: i18n.t('datasource.please_input_host'), trigger: 'change' }],
|
|
|
|
'configuration.url': [{ required: true, message: i18n.t('datasource.please_input_url'), trigger: 'change' }],
|
|
|
|
'configuration.port': [{ required: true, message: i18n.t('datasource.please_input_port'), trigger: 'change' }],
|
2021-11-24 18:49:41 +08:00
|
|
|
'configuration.initialPoolSize': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_input_initial_pool_size'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'change'
|
|
|
|
}],
|
|
|
|
'configuration.minPoolSize': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_input_min_pool_size'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'change'
|
|
|
|
}],
|
|
|
|
'configuration.maxPoolSize': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_input_max_pool_size'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'change'
|
|
|
|
}],
|
|
|
|
'configuration.maxIdleTime': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_input_max_idle_time'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'change'
|
|
|
|
}],
|
|
|
|
'configuration.acquireIncrement': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_input_acquire_increment'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'change'
|
|
|
|
}],
|
|
|
|
'configuration.connectTimeout': [{
|
|
|
|
required: true,
|
2021-12-01 11:56:05 +08:00
|
|
|
message: i18n.t('datasource.please_input_connect_timeout'),
|
2021-11-24 18:49:41 +08:00
|
|
|
trigger: 'change'
|
|
|
|
}]
|
2021-04-29 15:38:03 +08:00
|
|
|
},
|
2021-09-15 18:20:31 +08:00
|
|
|
allTypes: [
|
2021-11-24 18:49:41 +08:00
|
|
|
{
|
|
|
|
name: 'mysql',
|
|
|
|
label: 'MySQL',
|
|
|
|
type: 'jdbc',
|
|
|
|
extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
|
|
|
|
},
|
2021-12-01 18:04:53 +08:00
|
|
|
{ name: 'hive', label: 'Apache Hive', type: 'jdbc', extraParams: '' },
|
|
|
|
{ name: 'oracle', label: 'Oracle', type: 'jdbc' },
|
|
|
|
{ name: 'sqlServer', label: 'SQL Server', type: 'jdbc', extraParams: '' },
|
|
|
|
{ name: 'pg', label: 'PostgreSQL', type: 'jdbc', extraParams: '' },
|
|
|
|
{ name: 'es', label: 'Elasticsearch', type: 'es' },
|
2021-11-24 18:49:41 +08:00
|
|
|
{
|
|
|
|
name: 'mariadb',
|
|
|
|
label: 'MariaDB',
|
|
|
|
type: 'jdbc',
|
|
|
|
extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'ds_doris',
|
|
|
|
label: 'Doris',
|
|
|
|
type: 'jdbc',
|
|
|
|
extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'
|
|
|
|
},
|
2021-12-01 18:04:53 +08:00
|
|
|
{ name: 'ck', label: 'ClickHouse', type: 'jdbc', extraParams: '' },
|
|
|
|
{ name: 'redshift', label: 'AWS Redshift', type: 'jdbc' },
|
|
|
|
{ name: 'mongo', label: 'MongoDB', type: 'jdbc', extraParams: '' }
|
2021-11-24 18:49:41 +08:00
|
|
|
],
|
2021-07-05 12:17:16 +08:00
|
|
|
schemas: [],
|
2021-08-03 12:21:10 +08:00
|
|
|
canEdit: false,
|
|
|
|
originConfiguration: {}
|
2021-04-29 15:38:03 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
2021-06-17 18:58:46 +08:00
|
|
|
if (this.params && this.params.id) {
|
|
|
|
const row = this.params
|
2021-04-29 15:38:03 +08:00
|
|
|
this.edit(row)
|
|
|
|
} else {
|
|
|
|
this.create()
|
2021-06-24 11:09:07 +08:00
|
|
|
if (this.params && this.params.type) {
|
|
|
|
this.setType()
|
|
|
|
}
|
2021-04-29 15:38:03 +08:00
|
|
|
}
|
|
|
|
},
|
2021-06-17 18:58:46 +08:00
|
|
|
mounted() {
|
|
|
|
},
|
2021-04-29 15:38:03 +08:00
|
|
|
methods: {
|
2021-06-24 11:09:07 +08:00
|
|
|
setType() {
|
|
|
|
this.form.type = this.params.type
|
2021-08-16 18:05:46 +08:00
|
|
|
this.form.configuration = {
|
|
|
|
initialPoolSize: 5,
|
2021-10-11 12:19:19 +08:00
|
|
|
extraParams: '',
|
2021-08-16 18:05:46 +08:00
|
|
|
minPoolSize: 5,
|
|
|
|
maxPoolSize: 50,
|
|
|
|
maxIdleTime: 30,
|
|
|
|
acquireIncrement: 5,
|
|
|
|
idleConnectionTestPeriod: 5,
|
|
|
|
connectTimeout: 5
|
|
|
|
}
|
2021-06-24 11:09:07 +08:00
|
|
|
this.changeType()
|
|
|
|
},
|
2021-06-22 11:54:53 +08:00
|
|
|
changeEdit() {
|
|
|
|
this.canEdit = true
|
|
|
|
this.formType = 'modify'
|
|
|
|
},
|
2021-04-29 15:38:03 +08:00
|
|
|
create() {
|
|
|
|
this.formType = 'add'
|
2021-06-22 11:54:53 +08:00
|
|
|
this.canEdit = true
|
2021-04-29 15:38:03 +08:00
|
|
|
},
|
|
|
|
edit(row) {
|
|
|
|
this.formType = 'modify'
|
|
|
|
this.form = Object.assign({}, row)
|
2021-08-03 12:21:10 +08:00
|
|
|
this.originConfiguration = this.form.configuration
|
2021-04-29 15:38:03 +08:00
|
|
|
this.form.configuration = JSON.parse(this.form.configuration)
|
|
|
|
},
|
|
|
|
reset() {
|
|
|
|
this.$refs.dsForm.resetFields()
|
|
|
|
},
|
|
|
|
save() {
|
2021-08-16 18:05:46 +08:00
|
|
|
if (!this.form.configuration.schema && (this.form.type === 'oracle' || this.form.type === 'sqlServer')) {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$message.error(i18n.t('datasource.please_choose_schema'))
|
2021-07-05 12:17:16 +08:00
|
|
|
return
|
|
|
|
}
|
2021-10-11 15:06:18 +08:00
|
|
|
if (this.form.configuration.dataSourceType === 'jdbc' && this.form.configuration.port <= 0) {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$message.error(i18n.t('datasource.port_no_less_then_0'))
|
2021-10-11 15:06:18 +08:00
|
|
|
return
|
|
|
|
}
|
2021-10-14 17:50:14 +08:00
|
|
|
if (this.form.configuration.initialPoolSize < 0 || this.form.configuration.minPoolSize < 0 || this.form.configuration.maxPoolSize < 0) {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$message.error(i18n.t('datasource.no_less_then_0'))
|
2021-08-16 18:05:46 +08:00
|
|
|
return
|
|
|
|
}
|
2021-04-29 15:38:03 +08:00
|
|
|
this.$refs.dsForm.validate(valid => {
|
|
|
|
if (valid) {
|
|
|
|
const method = this.formType === 'add' ? addDs : editDs
|
2021-05-28 12:40:19 +08:00
|
|
|
const form = JSON.parse(JSON.stringify(this.form))
|
|
|
|
form.configuration = JSON.stringify(form.configuration)
|
2021-09-03 14:40:47 +08:00
|
|
|
if (this.formType !== 'add' && this.originConfiguration !== form.configuration) {
|
2021-12-01 11:56:05 +08:00
|
|
|
$confirm(i18n.t('datasource.edit_datasource_msg'), () => {
|
2021-08-03 12:21:10 +08:00
|
|
|
method(form).then(res => {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$success(i18n.t('commons.save_success'))
|
2021-11-02 15:42:52 +08:00
|
|
|
this.refreshType(form)
|
2021-08-03 12:21:10 +08:00
|
|
|
this.backToList()
|
|
|
|
})
|
|
|
|
})
|
2021-09-03 14:40:47 +08:00
|
|
|
} else {
|
2021-08-03 12:21:10 +08:00
|
|
|
method(form).then(res => {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$success(i18n.t('commons.save_success'))
|
2021-11-02 15:42:52 +08:00
|
|
|
this.refreshType(form)
|
2021-08-03 12:21:10 +08:00
|
|
|
this.backToList()
|
|
|
|
})
|
|
|
|
}
|
2021-04-29 15:38:03 +08:00
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2021-07-06 16:22:19 +08:00
|
|
|
getSchema() {
|
2021-07-05 12:17:16 +08:00
|
|
|
this.$refs.dsForm.validate(valid => {
|
|
|
|
if (valid) {
|
|
|
|
const data = JSON.parse(JSON.stringify(this.form))
|
|
|
|
data.configuration = JSON.stringify(data.configuration)
|
|
|
|
getSchema(data).then(res => {
|
|
|
|
this.schemas = res.data
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$success(i18n.t('commons.success'))
|
2021-07-05 12:17:16 +08:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2021-04-29 15:38:03 +08:00
|
|
|
validaDatasource() {
|
2021-07-08 09:54:08 +08:00
|
|
|
if (!this.form.configuration.schema && this.form.type === 'oracle') {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$message.error(i18n.t('datasource.please_choose_schema'))
|
2021-07-08 09:54:08 +08:00
|
|
|
return
|
|
|
|
}
|
2021-10-11 17:09:29 +08:00
|
|
|
if (this.form.configuration.dataSourceType === 'jdbc' && this.form.configuration.port <= 0) {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$message.error(i18n.t('datasource.port_no_less_then_0'))
|
2021-10-11 17:09:29 +08:00
|
|
|
return
|
|
|
|
}
|
2021-04-29 15:38:03 +08:00
|
|
|
this.$refs.dsForm.validate(valid => {
|
|
|
|
if (valid) {
|
|
|
|
const data = JSON.parse(JSON.stringify(this.form))
|
|
|
|
data.configuration = JSON.stringify(data.configuration)
|
2021-09-03 14:40:47 +08:00
|
|
|
if (data.showModel === 'show' && !this.canEdit) {
|
2021-08-23 16:27:05 +08:00
|
|
|
validateDsById(data.id).then(res => {
|
2021-09-03 14:40:47 +08:00
|
|
|
if (res.success) {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$success(i18n.t('datasource.validate_success'))
|
2021-09-03 14:40:47 +08:00
|
|
|
} else {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$error(res.message)
|
2021-08-23 16:27:05 +08:00
|
|
|
}
|
2021-11-03 10:36:35 +08:00
|
|
|
this.refreshType(data)
|
2021-08-23 16:27:05 +08:00
|
|
|
}).catch(res => {
|
|
|
|
this.$error(res.message)
|
|
|
|
})
|
2021-09-03 14:40:47 +08:00
|
|
|
} else {
|
2021-08-23 16:27:05 +08:00
|
|
|
validateDs(data).then(res => {
|
2021-09-03 14:40:47 +08:00
|
|
|
if (res.success) {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$success(i18n.t('datasource.validate_success'))
|
2021-09-03 14:40:47 +08:00
|
|
|
} else {
|
2021-12-01 11:56:05 +08:00
|
|
|
this.$error(res.message)
|
2021-08-23 16:27:05 +08:00
|
|
|
}
|
|
|
|
}).catch(res => {
|
|
|
|
this.$error(res.message)
|
|
|
|
})
|
|
|
|
}
|
2021-04-29 15:38:03 +08:00
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
changeType() {
|
|
|
|
for (let i = 0; i < this.allTypes.length; i++) {
|
|
|
|
if (this.allTypes[i].name === this.form.type) {
|
|
|
|
this.form.configuration.dataSourceType = this.allTypes[i].type
|
2021-09-29 18:26:47 +08:00
|
|
|
this.form.configuration.extraParams = this.allTypes[i].extraParams
|
2021-04-29 15:38:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
backToList() {
|
2021-11-24 18:49:41 +08:00
|
|
|
this.$emit('switch-component', {})
|
2021-06-17 19:34:46 +08:00
|
|
|
},
|
2021-11-02 15:42:52 +08:00
|
|
|
refreshType(form) {
|
|
|
|
this.$emit('refresh-type', form)
|
2021-04-29 15:38:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2021-06-17 18:58:46 +08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
|
|
|
.back-button {
|
|
|
|
cursor: pointer;
|
|
|
|
margin-right: 10px;
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
transform: scale(0.85);
|
|
|
|
}
|
|
|
|
}
|
2021-08-16 18:05:46 +08:00
|
|
|
|
|
|
|
.el-input {
|
|
|
|
width: 300px;
|
|
|
|
}
|
2021-11-24 18:49:41 +08:00
|
|
|
|
2021-08-16 18:05:46 +08:00
|
|
|
.el-select {
|
|
|
|
width: 300px;
|
|
|
|
}
|
2021-06-17 18:58:46 +08:00
|
|
|
</style>
|