Commit 4b14ba05 by zhanghouying

实现上传SQL脚本来更新数据功能

parent 1ff0492d
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: 300px" /><el-button :loading="loading" type="info" @click="testConnectDatabase">测试</el-button> <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,7 +49,7 @@ ...@@ -37,7 +49,7 @@
</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="数据库名称" width="180" /> <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="用户名" width="100" /> <el-table-column prop="userName" label="用户名" width="100" />
...@@ -76,12 +88,17 @@ ...@@ -76,12 +88,17 @@
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 { 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: [
...@@ -125,6 +142,17 @@ export default { ...@@ -125,6 +142,17 @@ export default {
}) })
} }
}) })
},
execute() {
if (!this.selectIndex) {
this.$message.error('请先选择数据库')
} else {
this.$refs.execute.dialog = true
}
},
handleCurrentChange(row) {
this.currentRow = row
this.selectIndex = !row ? null : row.id
} }
} }
} }
......
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