dataease/frontend/src/views/system/datasource/index.vue

276 lines
10 KiB
Vue
Raw Normal View History

2021-03-03 15:06:52 +08:00
<template>
2021-03-15 12:12:14 +08:00
<layout-content v-loading="$store.getters.loadingMap[$store.getters.currentPath]">
<complex-table
:data="data"
:columns="columns"
2021-03-15 12:12:14 +08:00
:search-config="searchConfig"
:pagination-config="paginationConfig"
@select="select"
@search="search"
>
<template #toolbar>
2021-05-06 14:43:57 +08:00
<!-- <fu-table-button v-permission="['datasource:add']" icon="el-icon-circle-plus-outline" :label="$t('datasource.create')" @click="create" /> -->
<el-button v-permission="['datasource:add']" icon="el-icon-circle-plus-outline" @click="create">{{ $t('datasource.create') }}</el-button>
2021-03-03 15:06:52 +08:00
</template>
2021-03-15 12:12:14 +08:00
<!-- <el-table-column type="selection" fix /> -->
<el-table-column prop="name" :label="$t('commons.name')" />
<el-table-column prop="desc" :label="$t('commons.description')" />
<el-table-column prop="type" :label="$t('datasource.type')" />
<fu-table-operations :buttons="buttons" :label="$t('commons.operating')" fix />
</complex-table>
2021-03-03 15:06:52 +08:00
<!-- add datasource form -->
<el-dialog
:close-on-click-modal="false"
2021-03-15 12:12:14 +08:00
:title="formType=='add' ? $t('datasource.create') : $t('datasource.modify')"
:visible.sync="dialogVisible"
2021-03-03 15:06:52 +08:00
width="30%"
:destroy-on-close="true"
@closed="closeFunc"
>
<el-form ref="createDatasource" :model="form" label-position="right" label-width="100px" size="small">
<el-form-item
:label="$t('commons.name')"
prop="name"
:rules="[{required: true, message: this.$t('datasource.input_name'), trigger: 'blur'},
{min: 2, max: 25, message: this.$t('commons.input_limit', [2, 25]), trigger: 'blur'}]"
>
<el-input v-model="form.name" autocomplete="off" />
</el-form-item>
<el-form-item
:label="$t('commons.description')"
prop="desc"
:rules="[{required: true, message: this.$t('datasource.input_desc'), trigger: 'blur'},
{min: 2, max: 50, message: this.$t('commons.input_limit', [2, 50]), trigger: 'blur'}]"
>
<el-input v-model="form.desc" autocomplete="off" type="textarea" />
</el-form-item>
<el-form-item :label="$t('datasource.type')" prop="type" :rules="{required: true, message: $t('datasource.please_choose_type'), trigger: 'change'}">
<el-select v-model="form.type" :placeholder="$t('datasource.please_choose_type')" class="select-width" @change="changeType()">
<el-option
v-for="item in allTypes"
:key="item.name"
:label="item.name"
:value="item.name"
/>
</el-select>
</el-form-item>
<el-form-item v-show="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.data_base')" prop="configuration.dataBase" :rules="{required: true, message: $t('datasource.please_input_data_base'), trigger: 'blur'}">
<el-input v-model="form.configuration.dataBase" autocomplete="off" />
</el-form-item>
2021-03-18 17:59:52 +08:00
<el-form-item v-show="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.user_name')" prop="configuration.username" :rules="{required: true, message: $t('datasource.please_input_user_name'), trigger: 'blur'}">
2021-03-03 15:06:52 +08:00
<el-input v-model="form.configuration.username" autocomplete="off" />
</el-form-item>
<el-form-item v-show="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.password')" prop="configuration.password" :rules="{required: true, message: $t('datasource.please_input_password'), trigger: 'change'}">
<el-input v-model="form.configuration.password" autocomplete="off" />
</el-form-item>
<el-form-item v-show="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.host')" prop="configuration.host" :rules="{required: true, message: $t('datasource.please_input_host'), trigger: 'change'}">
<el-input v-model="form.configuration.host" autocomplete="off" />
</el-form-item>
<el-form-item v-show="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.port')" prop="configuration.port" :rules="{required: true, message: $t('datasource.please_input_port'), trigger: 'change'}">
<el-input v-model="form.configuration.port" autocomplete="off" />
</el-form-item>
</el-form>
2021-03-15 12:12:14 +08:00
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="dialogVisible = false">{{ $t('commons.cancel') }}</el-button>
2021-03-18 17:59:52 +08:00
<el-button type="primary" @click="validaDatasource('createDatasource')">{{ $t('commons.validate') }}</el-button>
<el-button type="primary" @click="saveDatasource('createDatasource')">{{ $t('commons.confirm') }}</el-button>
2021-03-15 12:12:14 +08:00
</div>
2021-03-03 15:06:52 +08:00
</el-dialog>
2021-03-15 12:12:14 +08:00
</layout-content>
2021-03-03 15:06:52 +08:00
</template>
<script>
2021-03-15 12:12:14 +08:00
import LayoutContent from '@/components/business/LayoutContent'
import ComplexTable from '@/components/business/complex-table'
import { checkPermission } from '@/utils/permission'
import { formatCondition } from '@/utils/index'
2021-03-03 15:06:52 +08:00
import { dsGrid, addDs, editDs, delDs, validateDs } from '@/api/system/datasource'
export default {
name: 'DEDatasource',
components: {
2021-03-15 12:12:14 +08:00
LayoutContent,
ComplexTable
2021-03-03 15:06:52 +08:00
},
data() {
return {
2021-03-15 12:12:14 +08:00
formType: 'add',
dialogVisible: false,
data: [],
2021-03-03 15:06:52 +08:00
form: { configuration: {}},
allTypes: [{ name: 'mysql', type: 'jdbc' }, { name: 'sqlServer', type: 'jdbc' }],
rule: {
name: [
{ required: true, message: this.$t('organization.input_name'), trigger: 'blur' },
{ min: 2, max: 25, message: this.$t('commons.input_limit', [2, 25]), trigger: 'blur' }
],
desc: [
{ required: true, message: this.$t('organization.input_name'), trigger: 'blur' },
{ max: 50, message: this.$t('commons.input_limit', [0, 50]), trigger: 'blur' }
]
2021-03-15 12:12:14 +08:00
},
header: '',
columns: [],
buttons: [
{
label: this.$t('commons.edit'), icon: 'el-icon-edit', click: this.edit,
show: checkPermission(['datasource:edit'])
}, {
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this._handleDelete,
2021-03-15 12:12:14 +08:00
show: checkPermission(['datasource:del'])
}
],
searchConfig: {
useQuickSearch: true,
2021-05-17 14:19:46 +08:00
quickPlaceholder: this.$t('commons.search_by_name'),
2021-03-15 12:12:14 +08:00
combine: false,
components: [
2021-05-17 14:19:46 +08:00
{ field: 'name', label: this.$t('commons.name'), component: 'FuComplexInput' },
2021-03-15 12:12:14 +08:00
{
field: 'type',
2021-05-17 14:19:46 +08:00
label: this.$t('datasource.type'),
2021-03-15 12:12:14 +08:00
component: 'FuComplexSelect',
options: [{ label: 'mysql', value: 'mysql' }, { label: 'sqlServer', value: 'sqlServer' }],
multiple: false
}
// { field: 'deptId', label: '组织', component: conditionTable }
]
},
paginationConfig: {
currentPage: 1,
pageSize: 10,
total: 0
2021-03-03 15:06:52 +08:00
}
}
},
mounted() {
2021-03-15 12:12:14 +08:00
this.search()
2021-03-03 15:06:52 +08:00
},
methods: {
2021-03-15 12:12:14 +08:00
select(selection) {
console.log(selection)
2021-03-03 15:06:52 +08:00
},
// create() {
// this.formType = 'add'
// this.dialogVisible = true
// },
2021-03-15 12:12:14 +08:00
create() {
2021-05-19 10:30:51 +08:00
this.$router.push({ name: 'datasource-form' })
2021-03-03 15:06:52 +08:00
},
2021-03-15 12:12:14 +08:00
// edit(row) {
// this.formType = 'modify'
// this.dialogVisible = true
// this.form = Object.assign({}, row)
// this.form.configuration = JSON.parse(this.form.configuration)
// },
2021-03-03 15:06:52 +08:00
edit(row) {
2021-05-19 10:30:51 +08:00
this.$router.push({ name: 'datasource-form', params: row })
2021-03-03 15:06:52 +08:00
},
2021-03-15 12:12:14 +08:00
2021-03-03 15:06:52 +08:00
_handleDelete(datasource) {
this.$confirm(this.$t('datasource.delete_confirm'), '', {
confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
delDs(datasource.id).then(res => {
this.$success(this.$t('commons.delete_success'))
2021-03-15 12:12:14 +08:00
this.search()
2021-03-03 15:06:52 +08:00
})
}).catch(() => {
this.$message({
type: 'info',
message: this.$t('commons.delete_cancelled')
})
})
},
2021-03-15 12:12:14 +08:00
saveDatasource(createDatasourceForm) {
2021-03-03 15:06:52 +08:00
this.$refs[createDatasourceForm].validate(valid => {
if (valid) {
2021-03-15 12:12:14 +08:00
const method = this.formType === 'add' ? addDs : editDs
2021-03-03 15:06:52 +08:00
this.form.configuration = JSON.stringify(this.form.configuration)
2021-03-15 12:12:14 +08:00
method(this.form).then(res => {
2021-03-03 15:06:52 +08:00
this.$success(this.$t('commons.save_success'))
2021-03-15 12:12:14 +08:00
this.search()
this.dialogVisible = false
})
2021-03-03 15:06:52 +08:00
} else {
return false
}
})
},
validaDatasource(datasourceForm) {
this.$refs[datasourceForm].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++) {
2021-03-03 17:38:41 +08:00
if (this.allTypes[i].name === this.form.type) {
2021-03-03 15:06:52 +08:00
this.form.configuration.dataSourceType = this.allTypes[i].type
}
}
},
2021-03-15 12:12:14 +08:00
quick_condition(condition) {
const result = {}
if (condition && condition.quick) {
for (const [key, value] of Object.entries(condition)) {
if (`${key}` === 'quick') {
const v_new = Object.assign({}, value)
v_new['field'] = 'name'
result['name'] = v_new
} else {
result[`${key}`] = value
}
}
return result
}
return Object.assign({}, condition)
},
search(condition) {
const temp_param = this.quick_condition(condition)
const temp = formatCondition(temp_param)
const param = temp || {}
const { currentPage, pageSize } = this.paginationConfig
dsGrid(currentPage, pageSize, param).then(response => {
this.data = response.data.listObject
this.paginationConfig.total = response.data.itemCount
2021-03-03 15:06:52 +08:00
})
},
2021-03-15 12:12:14 +08:00
2021-03-03 15:06:52 +08:00
closeFunc() {
2021-03-15 12:12:14 +08:00
this.formType = 'add'
// this.search()
2021-03-03 15:06:52 +08:00
this.form = { configuration: {}}
2021-03-15 12:12:14 +08:00
this.dialogVisible = false
2021-03-03 15:06:52 +08:00
}
2021-03-15 12:12:14 +08:00
2021-03-03 15:06:52 +08:00
}
}
</script>
<style scoped>
</style>