合并 2.4opt

This commit is contained in:
Elune
2019-12-10 19:40:45 +08:00
8 changed files with 171 additions and 18 deletions

View File

@@ -13,16 +13,28 @@
type="primary"
icon="el-icon-plus"
@click="showAddFormDialog"
>新增</el-button>
>新增
</el-button>
<el-button
v-permission="['admin','database:add']"
class="filter-item"
size="mini"
type="warning"
icon="el-icon-upload"
@click="execute"
>执行脚本
</el-button>
</div>
<!--表单组件-->
<eForm ref="execute" :database-info="currentRow" />
<el-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialog" :title="getFormTitle()" width="530px">
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">
<el-form-item label="数据库名称" prop="name">
<el-input v-model="form.name" style="width: 370px" />
</el-form-item>
<el-form-item label="连接地址" prop="jdbcUrl">
<el-input v-model="form.jdbcUrl" style="width: 370px" />
<el-input v-model="form.jdbcUrl" style="width: 300px" />
<el-button :loading="loading" type="info" @click="testConnectDatabase">测试</el-button>
</el-form-item>
<el-form-item label="用户名" prop="userName">
<el-input v-model="form.userName" style="width: 370px" />
@@ -37,10 +49,10 @@
</div>
</el-dialog>
<!--表格渲染-->
<el-table v-loading="loading" :data="data" style="width: 100%">
<el-table-column prop="name" label="数据库名称" />
<el-table v-loading="loading" :data="data" highlight-current-row stripe style="width: 100%" @current-change="handleCurrentChange">
<el-table-column prop="name" label="数据库名称" width="180" />
<el-table-column prop="jdbcUrl" label="连接地址" />
<el-table-column prop="userName" label="用户名" />
<el-table-column prop="userName" label="用户名" width="100" />
<el-table-column v-if="checkPermission(['admin','database:edit','database:del'])" label="操作" width="150px" align="center">
<template slot-scope="scope">
<el-button v-permission="['admin','database:edit']" size="mini" type="primary" icon="el-icon-edit" @click="showEditFormDialog(scope.row)" />
@@ -74,13 +86,19 @@
<script>
import crud from '@/mixins/crud'
import crudDataBase from '@/api//mnt/database'
import crudDatabase from '@/api/mnt/database'
import { testDbConnect } from '@/api/mnt/connect'
import eForm from './execute'
export default {
components: { eForm },
mixins: [crud],
data() {
return {
title: '数据库',
crudMethod: { ...crudDataBase },
crudMethod: { ...crudDatabase },
currentRow: {},
selectIndex: '',
databaseInfo: '',
form: { id: null, name: null, jdbcUrl: null, userName: null, pwd: null },
rules: {
name: [
@@ -107,6 +125,34 @@ export default {
beforeInit() {
this.url = 'api/database'
return true
},
testConnectDatabase() {
this.$refs['form'].validate((valid) => {
if (valid) {
this.loading = true
testDbConnect(this.form).then((res) => {
this.loading = false
this.$notify({
title: res ? '连接成功' : '连接失败',
type: res ? 'success' : 'error',
duration: 2500
})
}).catch(() => {
this.loading = false
})
}
})
},
execute() {
if (!this.selectIndex) {
this.$message.error('请先选择数据库')
} else {
this.$refs.execute.dialog = true
}
},
handleCurrentChange(row) {
this.currentRow = row
this.selectIndex = !row ? null : row.id
}
}
}