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>
|
|
|
|
<el-icon name="back" class="back-button" @click.native="backToList" />
|
2021-06-22 11:54:53 +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-06-22 11:54: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="auto" label-position="right">
|
|
|
|
<el-form-item :label="$t('commons.name')" prop="name">
|
|
|
|
<el-input v-model="form.name" autocomplete="off" />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item :label="$t('commons.description')" prop="desc">
|
2021-04-29 15:38:03 +08:00
|
|
|
|
2021-06-22 11:54:53 +08:00
|
|
|
<el-input v-model="form.desc" autocomplete="off" type="textarea" />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item :label="$t('datasource.type')" prop="type">
|
2021-06-24 11:09:07 +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-06-22 11:54:53 +08:00
|
|
|
<el-form-item v-if="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.host')" prop="configuration.host">
|
2021-08-03 12:21:10 +08:00
|
|
|
<el-input v-model="form.configuration.host" autocomplete="off" />
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item v-if="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.data_base')" prop="configuration.dataBase">
|
2021-08-03 12:21:10 +08:00
|
|
|
<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
|
|
|
|
|
|
|
<el-form-item v-if="form.type=='oracle'" :label="$t('datasource.oracle_connection_type')" prop="configuration.connectionType">
|
|
|
|
<el-radio v-model="form.configuration.connectionType" label="sid">{{ $t('datasource.oracle_sid') }}</el-radio>
|
|
|
|
<el-radio v-model="form.configuration.connectionType" label="serviceName">{{ $t('datasource.oracle_service_name') }}</el-radio>
|
|
|
|
</el-form-item>
|
|
|
|
|
2021-06-22 11:54:53 +08:00
|
|
|
<el-form-item v-if="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.user_name')" prop="configuration.username">
|
2021-08-03 12:21:10 +08:00
|
|
|
<el-input v-model="form.configuration.username" autocomplete="off" />
|
2021-06-22 11:54:53 +08:00
|
|
|
</el-form-item>
|
|
|
|
<el-form-item v-if="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.password')" prop="configuration.password">
|
|
|
|
<el-input v-model="form.configuration.password" autocomplete="off" show-password />
|
|
|
|
</el-form-item>
|
|
|
|
<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" />
|
|
|
|
</el-form-item>
|
2021-07-05 12:17:16 +08:00
|
|
|
<el-form-item v-if="form.type=='oracle'">
|
|
|
|
<el-button icon="el-icon-plus" size="mini" @click="getSchema()">
|
|
|
|
{{ $t('datasource.get_schema') }}
|
|
|
|
</el-button>
|
|
|
|
</el-form-item>
|
|
|
|
|
2021-07-06 16:22:19 +08:00
|
|
|
<el-form-item v-if="form.type=='oracle'" :label="$t('datasource.schema')">
|
2021-08-03 12:21:10 +08:00
|
|
|
<el-select filterable v-model="form.configuration.schema" :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-06-22 11:54:53 +08:00
|
|
|
</el-form>
|
|
|
|
<div v-if="canEdit" slot="footer" class="dialog-footer">
|
2021-06-23 16:29:31 +08:00
|
|
|
<el-button v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)" @click="validaDatasource">{{ $t('commons.validate') }}</el-button>
|
|
|
|
<el-button v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)" type="primary" @click="save">{{ $t('commons.save') }}</el-button>
|
2021-06-22 11:54:53 +08:00
|
|
|
</div>
|
|
|
|
<div v-else slot="footer" class="dialog-footer">
|
2021-06-23 16:29:31 +08:00
|
|
|
<el-button v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)" @click="validaDatasource">{{ $t('commons.validate') }}</el-button>
|
|
|
|
<el-button v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)" type="primary" @click="changeEdit">{{ $t('commons.edit') }}</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-07-06 16:22:19 +08:00
|
|
|
import { addDs, editDs, getSchema, validateDs } from '@/api/system/datasource'
|
2021-08-03 12:21:10 +08:00
|
|
|
import { $confirm } from '@/utils/message'
|
|
|
|
|
2021-04-29 15:38:03 +08:00
|
|
|
export default {
|
2021-06-17 18:58:46 +08:00
|
|
|
name: 'DsForm',
|
2021-04-29 15:38:03 +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 {
|
|
|
|
form: { configuration: {}},
|
|
|
|
rule: {
|
|
|
|
name: [{ required: true, message: this.$t('datasource.input_name'), trigger: 'blur' },
|
2021-05-20 15:19:49 +08:00
|
|
|
{ min: 2, max: 25, message: this.$t('datasource.input_limit_2_25', [2, 25]), trigger: 'blur' }],
|
|
|
|
desc: [{ min: 0, max: 50, message: this.$t('datasource.input_limit_0_50'), trigger: 'blur' }],
|
2021-04-29 15:38:03 +08:00
|
|
|
type: [{ required: true, message: this.$t('datasource.please_choose_type'), trigger: 'change' }],
|
|
|
|
'configuration.dataBase': [{ required: true, message: this.$t('datasource.please_input_data_base'), trigger: 'blur' }],
|
2021-06-30 10:11:12 +08:00
|
|
|
'configuration.connectionType': [{ required: true, message: this.$t('datasource.please_select_oracle_type'), trigger: 'blur' }],
|
2021-04-29 15:38:03 +08:00
|
|
|
'configuration.username': [{ required: true, message: this.$t('datasource.please_input_user_name'), trigger: 'blur' }],
|
|
|
|
'configuration.password': [{ required: true, message: this.$t('datasource.please_input_password'), trigger: 'change' }],
|
|
|
|
'configuration.host': [{ required: true, message: this.$t('datasource.please_input_host'), trigger: 'change' }],
|
2021-07-08 09:54:08 +08:00
|
|
|
'configuration.port': [{ required: true, message: this.$t('datasource.please_input_port'), trigger: 'change' }]
|
2021-04-29 15:38:03 +08:00
|
|
|
},
|
2021-08-06 10:21:50 +08:00
|
|
|
allTypes: [{ name: 'mysql', label: 'MySQL', type: 'jdbc' },
|
|
|
|
{ name: 'oracle', label: 'Oracle', type: 'jdbc' },
|
|
|
|
{ name: 'sqlserver', label: 'SQLSERVER', type: 'jdbc' }],
|
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
|
|
|
|
this.form.configuration = {}
|
|
|
|
this.changeType()
|
|
|
|
console.log(this.form)
|
|
|
|
},
|
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-07-08 09:54:08 +08:00
|
|
|
if (!this.form.configuration.schema && this.form.type === 'oracle') {
|
2021-07-05 12:17:16 +08:00
|
|
|
this.$message.error(this.$t('datasource.please_choose_schema'))
|
|
|
|
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-08-03 12:21:10 +08:00
|
|
|
if(this.formType !== 'add' && this.originConfiguration !== form.configuration) {
|
|
|
|
$confirm(this.$t('datasource.edit_datasource_msg'), () => {
|
|
|
|
method(form).then(res => {
|
|
|
|
this.$success(this.$t('commons.save_success'))
|
|
|
|
this.refreshTree()
|
|
|
|
this.backToList()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}else {
|
|
|
|
method(form).then(res => {
|
|
|
|
this.$success(this.$t('commons.save_success'))
|
|
|
|
this.refreshTree()
|
|
|
|
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-07-08 09:54:08 +08:00
|
|
|
this.$success(this.$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') {
|
|
|
|
this.$message.error(this.$t('datasource.please_choose_schema'))
|
|
|
|
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)
|
|
|
|
validateDs(data).then(res => {
|
|
|
|
this.$success(this.$t('datasource.validate_success'))
|
|
|
|
})
|
|
|
|
} 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
backToList() {
|
2021-06-17 18:58:46 +08:00
|
|
|
this.$emit('switch-component', { })
|
|
|
|
// this.$router.push({ name: 'datasource' })
|
2021-06-17 19:34:46 +08:00
|
|
|
},
|
|
|
|
refreshTree() {
|
|
|
|
this.$emit('refresh-left-tree')
|
2021-04-29 15:38:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2021-06-17 18:58:46 +08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "~@/styles/mixin.scss";
|
|
|
|
@import "~@/styles/variables.scss";
|
|
|
|
|
|
|
|
.back-button {
|
|
|
|
cursor: pointer;
|
|
|
|
margin-right: 10px;
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
transform: scale(0.85);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|