Commit a4a0ad78 by Elune

Merge branch '2.4opt' of gitee.com:elunez/eladmin-web into 2.4opt

parents 561255c4 4b14ba05
import request from '@/utils/request'
export function testDbConnect(data) {
return request({
url: 'api/database/testConnect',
method: 'post',
data
})
}
export function testServerConnect(data) {
return request({
url: 'api/serverDeploy/testConnect',
method: 'post',
data
})
}
...@@ -23,4 +23,12 @@ export function edit(data) { ...@@ -23,4 +23,12 @@ export function edit(data) {
}) })
} }
export default { add, edit, del } export function testDbConnection(data) {
return request({
url: 'api/database/testConnect',
method: 'post',
data
})
}
export default { add, edit, del, testDbConnection }
...@@ -23,12 +23,4 @@ export function edit(data) { ...@@ -23,12 +23,4 @@ export function edit(data) {
}) })
} }
export function testConnect(data) {
return request({
url: 'api/serverDeploy/testConnect',
method: 'post',
data
})
}
export default { add, edit, del } export default { add, edit, del }
const getters = { const getters = {
deployUploadApi: state => state.api.deployUploadApi, deployUploadApi: state => state.api.deployUploadApi,
databaseUploadApi: state => state.api.databaseUploadApi,
size: state => state.app.size, size: state => state.app.size,
sidebar: state => state.app.sidebar, sidebar: state => state.app.sidebar,
device: state => state.app.device, device: state => state.app.device,
......
...@@ -3,6 +3,8 @@ const api = { ...@@ -3,6 +3,8 @@ const api = {
state: { state: {
// 部署包上传 // 部署包上传
deployUploadApi: baseUrl + '/api/deploy/upload', deployUploadApi: baseUrl + '/api/deploy/upload',
// SQL脚本上传
databaseUploadApi: baseUrl + '/api/database/upload',
// 实时控制台 // 实时控制台
socketApi: baseUrl + '/websocket?token=kl', socketApi: baseUrl + '/websocket?token=kl',
// 图片上传 // 图片上传
......
<template>
<el-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialog" title="执行脚本" width="400px">
<el-form ref="form" :rules="rules" size="small">
<el-upload
:action="databaseUploadApi"
:data="databaseInfo"
:headers="headers"
:on-success="handleSuccess"
:on-error="handleError"
class="upload-demo"
drag
>
<i class="el-icon-upload" />
<div class="el-upload__text">
将文件拖到此处,或
<em>点击上传</em>
</div>
<div slot="tip" class="el-upload__tip">上传后,系统会自动执行SQL脚本</div>
</el-upload>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="cancel">关闭</el-button>
</div>
</el-dialog>
</template>
<script>
import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth'
export default {
props: {
databaseInfo: {
type: Object,
default() {
return {}
}
}
},
data() {
return {
loading: false,
dialog: false,
headers: {
Authorization: 'Bearer ' + getToken()
},
rules: {}
}
},
computed: {
...mapGetters(['databaseUploadApi'])
},
mounted() {
},
methods: {
cancel() {
this.dialog = false
},
handleSuccess(response, file, fileList) {
if (response === 'success') {
this.$notify({
title: '执行成功',
type: 'success',
duration: 2500
})
} else {
this.$notify({
title: response,
type: 'error',
duration: 0
})
}
},
handleError(e, file, fileList) {
const msg = JSON.parse(e.message)
this.$notify({
title: msg.message,
type: 'error',
duration: 0
})
}
}
}
</script>
<style scoped>
</style>
...@@ -13,16 +13,28 @@ ...@@ -13,16 +13,28 @@
type="primary" type="primary"
icon="el-icon-plus" icon="el-icon-plus"
@click="showAddFormDialog" @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> </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-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 ref="form" :model="form" :rules="rules" size="small" label-width="100px">
<el-form-item label="数据库名称" prop="name"> <el-form-item label="数据库名称" prop="name">
<el-input v-model="form.name" style="width: 370px" /> <el-input v-model="form.name" style="width: 370px" />
</el-form-item> </el-form-item>
<el-form-item label="连接地址" prop="jdbcUrl"> <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>
<el-form-item label="用户名" prop="userName"> <el-form-item label="用户名" prop="userName">
<el-input v-model="form.userName" style="width: 370px" /> <el-input v-model="form.userName" style="width: 370px" />
...@@ -37,10 +49,10 @@ ...@@ -37,10 +49,10 @@
</div> </div>
</el-dialog> </el-dialog>
<!--表格渲染--> <!--表格渲染-->
<el-table v-loading="loading" :data="data" size="small" style="width: 100%"> <el-table v-loading="loading" :data="data" highlight-current-row stripe size="small" style="width: 100%" @current-change="handleCurrentChange">
<el-table-column prop="name" label="数据库名称" /> <el-table-column prop="name" label="数据库名称" width="180" />
<el-table-column prop="jdbcUrl" label="连接地址" /> <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"> <el-table-column v-if="checkPermission(['admin','database:edit','database:del'])" label="操作" width="150px" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button v-permission="['admin','database:edit']" size="mini" type="primary" icon="el-icon-edit" @click="showEditFormDialog(scope.row)" /> <el-button v-permission="['admin','database:edit']" size="mini" type="primary" icon="el-icon-edit" @click="showEditFormDialog(scope.row)" />
...@@ -74,13 +86,19 @@ ...@@ -74,13 +86,19 @@
<script> <script>
import crud from '@/mixins/crud' 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 { export default {
components: { eForm },
mixins: [crud], mixins: [crud],
data() { data() {
return { return {
title: '数据库', title: '数据库',
crudMethod: { ...crudDataBase }, crudMethod: { ...crudDatabase },
currentRow: {},
selectIndex: '',
databaseInfo: '',
form: { id: null, name: null, jdbcUrl: null, userName: null, pwd: null }, form: { id: null, name: null, jdbcUrl: null, userName: null, pwd: null },
rules: { rules: {
name: [ name: [
...@@ -107,6 +125,34 @@ export default { ...@@ -107,6 +125,34 @@ export default {
beforeInit() { beforeInit() {
this.url = 'api/database' this.url = 'api/database'
return true 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
} }
} }
} }
......
...@@ -96,7 +96,8 @@ ...@@ -96,7 +96,8 @@
<script> <script>
import crud from '@/mixins/crud' import crud from '@/mixins/crud'
import { crudServer, testConnect } from '@/api/mnt/serverDeploy' import crudServer from '@/api/mnt/serverDeploy'
import { testServerConnect } from '@/api/mnt/connect'
import { validateIP } from '@/utils/validate' import { validateIP } from '@/utils/validate'
export default { export default {
mixins: [crud], mixins: [crud],
...@@ -141,7 +142,7 @@ export default { ...@@ -141,7 +142,7 @@ export default {
this.$refs['form'].validate((valid) => { this.$refs['form'].validate((valid) => {
if (valid) { if (valid) {
this.loading = true this.loading = true
testConnect(this.form).then((res) => { testServerConnect(this.form).then((res) => {
this.loading = false this.loading = false
this.$notify({ this.$notify({
title: res ? '连接成功' : '连接失败', title: res ? '连接成功' : '连接失败',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment