合并 2.4opt
This commit is contained in:
17
src/api/mnt/connect.js
Normal file
17
src/api/mnt/connect.js
Normal file
@@ -0,0 +1,17 @@
|
||||
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) {
|
||||
})
|
||||
}
|
||||
|
||||
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) {
|
||||
})
|
||||
}
|
||||
|
||||
export function testConnect(data) {
|
||||
return request({
|
||||
url: 'api/serverDeploy/testConnect',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export default { add, edit, del }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const getters = {
|
||||
deployUploadApi: state => state.api.deployUploadApi,
|
||||
databaseUploadApi: state => state.api.databaseUploadApi,
|
||||
size: state => state.app.size,
|
||||
sidebar: state => state.app.sidebar,
|
||||
device: state => state.app.device,
|
||||
|
||||
@@ -3,6 +3,8 @@ const api = {
|
||||
state: {
|
||||
// 部署包上传
|
||||
deployUploadApi: baseUrl + '/api/deploy/upload',
|
||||
// SQL脚本上传
|
||||
databaseUploadApi: baseUrl + '/api/database/upload',
|
||||
// 实时控制台
|
||||
socketApi: baseUrl + '/websocket?token=kl',
|
||||
// 图片上传
|
||||
|
||||
86
src/views/mnt/database/execute.vue
Normal file
86
src/views/mnt/database/execute.vue
Normal file
@@ -0,0 +1,86 @@
|
||||
<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 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,8 @@
|
||||
|
||||
<script>
|
||||
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'
|
||||
export default {
|
||||
mixins: [crud],
|
||||
@@ -141,7 +142,7 @@ export default {
|
||||
this.$refs['form'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.loading = true
|
||||
testConnect(this.form).then((res) => {
|
||||
testServerConnect(this.form).then((res) => {
|
||||
this.loading = false
|
||||
this.$notify({
|
||||
title: res ? '连接成功' : '连接失败',
|
||||
|
||||
Reference in New Issue
Block a user