数据源模板化

Raod 3 years ago
parent c49e2608f8
commit d36a721f5b

@ -41,14 +41,7 @@
</el-dialog>
</template>
<script>
import {
pageList,
addDataSource,
editDataSource,
deleteDataSource,
} from '@/api/report'
import { testConnection, reportDataSourceDetail, reportDataSourceAdd, reportDataSourceDeleteBatch, reportDataSourceUpdate, } from '@/api/reportDataSource'
import { testConnection, reportDataSourceDetail, reportDataSourceAdd, reportDataSourceUpdate } from '@/api/reportDataSource'
import { getDictList } from '@/api/dict-data' //
import Dictionary from '@/components/Dictionary/index'
export default {

@ -1,340 +1,200 @@
<!--
* @Author: lide1202@hotmail.com
* @Date: 2021-3-13 11:04:24
* @Last Modified by: lide1202@hotmail.com
* @Last Modified time: 2021-3-13 11:04:24
!-->
<template>
<div class="app-container">
<el-form ref="form" :model="params" :rules="rules" label-width="120px" v-permission="'datasourceManage:query'">
<!-- 搜索 -->
<el-row :gutter="10">
<el-col :xs="24" :sm="20" :md="12" :lg="6" :xl="4">
<el-form-item label="数据源名称">
<el-input v-model.trim="params.sourceName" size="mini" clearable placeholder="数据源名称" class="filter-item" @keyup.enter.native="crud.toQuery" />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="20" :md="12" :lg="6" :xl="4">
<el-form-item label="数据源编码">
<el-input v-model.trim="params.sourceCode" size="mini" clearable placeholder="数据源Code" class="filter-item" @keyup.enter.native="crud.toQuery" />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="20" :md="12" :lg="6" :xl="4" class="query">
<el-form-item label="数据源类型" size="mini">
<Dictionary v-model="params.sourceType" :updata-dict="params.sourceType" :dict-key="'SOURCE_TYPE'" />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="20" :md="4" :lg="4" :xl="4" class="query">
<el-button type="primary" size="mini" @click="search('form')"></el-button>
<el-button type="danger" size="mini" @click="reset('form')"></el-button>
</el-col>
</el-row>
</el-form>
<el-button type="primary" icon="el-icon-plus" size="mini" @click="showAddLogModel()" v-permission="'datasourceManage:insert'"></el-button>
<anji-crud ref="listPage" :option="crudOption">
<template v-slot:buttonLeftOnTable>
<el-button type="primary" icon="el-icon-plus" @click="operateDatasource('add')" v-permission="'datasourceManage:insert'"></el-button>
</template>
<!--表格渲染-->
<el-table v-loading="listLoading" border :data="list" class="mt10" element-loading-text="Loading" style="width: 100%">
<el-table-column align="center" label="序号" type="index" min-width="60px" />
<el-table-column prop="sourceType" label="数据源类型" min-width="140px" />
<el-table-column prop="sourceNameCode" label="数据源名称[编码]" min-width="250px" />
<el-table-column prop="sourceDesc" label="数据源描述" min-width="250px" />
<el-table-column prop="createBy" label="创建人" min-width="100px" />
<el-table-column prop="createTime" label="创建时间" min-width="150px" />
<el-table-column prop="updateBy" label="修改人" min-width="100px" />
<el-table-column prop="updateTime" label="修改时间" min-width="150px" />
<el-table-column label="操作" align="center" min-width="120px">
<template slot-scope="scope">
<el-button type="text" @click="showAddLogModel(scope.row)" v-permission="'datasourceManage:update'"></el-button>
<!-- <el-popconfirm :title="'确定删除' + scope.row.sourceNameCode + '吗?'"
@onConfirm="delData(scope.row)"> -->
<el-button slot="reference" @click="delData(scope.row)" type="text" v-permission="'datasourceManage:delete'"></el-button>
<!-- </el-popconfirm> -->
<template slot="rowButton" slot-scope="props">
<el-button type="text" @click="operateDatasource('edit',props)" v-permission="'datasourceManage:update'"></el-button>
</template>
<!--自定义的卡片插槽将在编辑详情页面出现在底部新卡片-->
<!--这里可以将自定义的弹出框代码放入到page中
-->
<template v-slot:pageSection>
<EditDataSource :dataSource="dataSource" :visib="dialogVisibleSetDataSource" @handleClose="dialogVisibleSetDataSource = false" @refreshList="refreshList" />
</template>
</el-table-column>
</el-table>
<div class="block">
<el-pagination :total="totalCount" :page-sizes="[10, 20, 50, 100]" :page-size="params.pageSize" :current-page="params.pageNumber" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
</div>
<!--表单组件-->
<el-dialog title="项目基础配置" width="50%" :close-on-click-modal="false" center :visible.sync="basicDialog" @close="closeDialog">
<el-form ref="userForm" :model="dialogForm" :rules="rules" size="small" label-width="100px">
<el-row :gutter="10">
<el-col :xs="24" :sm="20" :md="6" :lg="6" :xl="6">
<el-form-item label="数据源类型" prop="sourceType">
<el-select v-model.trim="dialogForm.sourceType" placeholder="请选择" clearable @change="selectChange">
<el-option v-for="item in dictionaryOptions" :key="item.id" :label="item.text" :value="item.id" />
</el-select>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="20" :md="7" :lg="7" :xl="7">
<el-form-item label="数据源编码" prop="sourceCode">
<el-input :disabled="updataDisabled" v-model.trim="dialogForm.sourceCode" />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="20" :md="7" :lg="7" :xl="7">
<el-form-item label="数据源名称" prop="sourceName">
<el-input v-model.trim="dialogForm.sourceName" />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="20" :md="20" :lg="20" :xl="20">
<el-form-item label="数据源描述">
<el-input v-model.trim="dialogForm.sourceDesc" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="10">
<el-col v-for="(data, index) in dataLink" :key="index" :xs="24" :sm="20" :md="20" :lg="20" :xl="20">
<el-form-item :label="data.labelValue">
<el-input v-model.trim="data.value" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="closeDialog"></el-button>
<el-button type="warning" @click="test"></el-button>
<el-button type="primary" @click="UserConfirm('userForm')"></el-button>
</div>
</el-dialog>
</div>
</anji-crud>
</template>
<script>
import {
pageList,
testConnection,
addDataSource,
editDataSource,
deleteDataSource,
} from '@/api/report'
import { getDictList } from '@/api/dict-data' //
import Dictionary from '@/components/Dictionary/index'
import { reportDataSourceList, reportDataSourceAdd, reportDataSourceDeleteBatch, reportDataSourceUpdate, reportDataSourceDetail } from '@/api/reportDataSource'
import EditDataSource from '@/views/report/datasource/components/EditDataSource'
export default {
name: 'Support',
components: { Dictionary },
name: 'ReportDataSource',
components: {
EditDataSource: EditDataSource
},
data() {
return {
dictionaryOptions: [], //
selectedList: [],
clickType: '',
formData: {},
list: null,
totalCount: 0,
totalPage: 0,
listLoading: true,
//
dialogFormVisible: false,
basicDialog: false,
params: {
sourceName: '',
sourceCode: '',
sourceType: '',
pageNumber: 1,
pageSize: 10,
order: 'DESC',
sort: 'update_time',
},
dialogForm: {
sourceName: '',
sourceCode: '',
sourceType: '',
sourceDesc: '',
sourceConfig: '',
dialogVisibleSetDataSource : false,
dataSource : {},
crudOption: {
// 使
title: '数据源',
//
labelWidth: '120px',
//
queryFormFields: [
{
inputType: 'input',
label: '数据源编码',
field: 'sourceCode'
},
{
inputType: 'input',
label: '数据源名称',
field: 'sourceName'
},
{
inputType: 'anji-select', //form input|input-number|anji-select(urldictCode)|anji-tree()|date|datetime|datetimerange
anjiSelectOption: {
dictCode: 'SOURCE_TYPE',
},
label: '数据源类型',
field: 'sourceType'
},
dataLink: [],
rules: {
sourceType: [
{ required: true, message: '数据集名称必选', trigger: 'change' },
],
sourceCode: [
{ required: true, message: '数据集编码必填', trigger: 'blur' },
//
buttons: {
query: {
api: reportDataSourceList,
permission: 'datasourceManage:query',
sort: 'update_time',
order: 'DESC'
},
queryByPrimarykey: {
api: reportDataSourceDetail,
permission: 'datasourceManage:detail'
},
add: {
api: reportDataSourceAdd,
permission: 'datasourceManage:insert',
isShow:false
},
delete: {
api: reportDataSourceDeleteBatch,
permission: 'datasourceManage:delete'
},
edit: {
api: reportDataSourceUpdate,
permission: 'datasourceManage:update',
isShow:false
},
},
//
columns: [
{
label: '',
field: 'id',
primaryKey: true, // ,
tableHide: true, //
editHide: true, //
},
{
label: '数据源编码',//
placeholder: '',
field: 'sourceCode',
editField: 'sourceCode',
inputType: 'input',
rules: [
{ min: 1, max: 100, message: '不超过100个字符', trigger: 'blur' }
],
sourceName: [
{ required: true, message: '数据源名称必选', trigger: 'blur' },
disabled: false,
},
{
label: '数据源名称',//
placeholder: '',
field: 'sourceName',
editField: 'sourceName',
inputType: 'input',
rules: [
{ min: 1, max: 100, message: '不超过100个字符', trigger: 'blur' }
],
disabled: false,
},
{
label: '数据源描述',//
placeholder: '',
field: 'sourceDesc',
editField: 'sourceDesc',
inputType: 'input',
rules: [
{ min: 1, max: 255, message: '不超过255个字符', trigger: 'blur' }
],
disabled: false,
},
{
label: '数据源类型',// DIC_NAME=SOURCE_TYPE; mysqloracesqlserverelasticsearchjavaBeanitem-extend
placeholder: '',
field: 'sourceType',
fieldTableRowRenderer: (row) => {
return this.getDictLabelByCode('SOURCE_TYPE', row['sourceType'])
},
editField: 'sourceType',
inputType: 'input',
rules: [
{ min: 1, max: 50, message: '不超过50个字符', trigger: 'blur' }
],
disabled: false,
},
{
label: '数据源连接配置json',//json{ jdbcUrl:'', username:'', password:'' } ES{ hostList:'ip1:9300,ip2:9300,ip3:9300', clusterName:'elasticsearch_cluster' } { apiUrl:'http://ip:port/url', method:'' } javaBean{ beanNamw:'xxx' }
placeholder: '',
field: 'sourceConfig',
editField: 'sourceConfig',
tableHide: true,
inputType: 'input',
rules: [
{ min: 1, max: 2048, message: '不超过2048个字符', trigger: 'blur' }
],
disabled: false,
},
{
label: '状态',//0-- 1-- DIC_NAME=ENABLE_FLAG
placeholder: '',
field: 'enableFlag',
fieldTableRowRenderer: (row) => {
return this.getDictLabelByCode('ENABLE_FLAG', row['enableFlag'])
},
colorStyle: {
0: 'table-danger', //keyeditField'': 'danger','': 'primary','绿': 'success','': 'warning','': 'info',''''
1: 'table-success',
},
editField: 'enableFlag',
inputType: 'input',
rules: [
],
disabled: false,
},
{
label: '删除标记',//0-- 1-- DIC_NAME=DELETE_FLAG
placeholder: '',
field: 'deleteFlag',
editField: 'deleteFlag',
tableHide: true,
inputType: 'input',
rules: [
],
disabled: false,
},
value: '',
updataDisabled: false,
testReplyCode: null,
}
},
watch: {},
// beforeCreatethis
beforeCreate: function () {},
mounted() {},
created() {
this.getSystem()
this.queryByPage()
},
methods: {
//
search() {
this.params.pageNumber = 1
this.queryByPage()
},
//
reset(formName) {
// this.$refs[formName].resetFields()
this.params.sourceName = ''
this.params.sourceCode = ''
this.params.pageNumber = 1
this.params.sourceType = ''
this.queryByPage()
},
async queryByPage() {
const res = await pageList(this.params)
if (res.code != '200') return
this.listLoading = true
this.list = res.data.records
this.list.forEach((value) => {
value['sourceNameCode'] =
value.sourceName + '[' + value.sourceCode + ']'
})
this.totalCount = res.data.total
this.totalPage = res.data.pages
this.listLoading = false
},
handleSizeChange(val) {
this.params.pageSize = val
this.queryByPage()
},
handleCurrentChange(val) {
this.params.pageNumber = val
this.queryByPage()
},
//
closeDialog(bool) {
// bool && this.search('form') //
// this.$refs['userForm'].resetFields()
this.basicDialog = false
],
},
//
showAddLogModel(val) {
this.basicDialog = true
if (val == undefined) {
this.updataDisabled = false
this.getSystem()
this.dialogForm = {
sourceName: '',
sourceCode: '',
sourceType: '',
sourceDesc: '',
sourceConfig: '',
}
} else {
this.updataDisabled = true
this.dialogForm = val
const newSourceType = this.dialogForm
let newDataLink = []
this.dictionaryOptions.map((item) => {
if (item.id == newSourceType.sourceType) {
newDataLink = JSON.parse(item.extend)
var sourceConfigJson = JSON.parse(newSourceType.sourceConfig)
for (var i = 0; i < newDataLink.length; i++) {
newDataLink[i].value = sourceConfigJson[newDataLink[i].label]
}
}
})
this.dataLink = newDataLink
}
},
//
async getSystem() {
const { code, data } = await getDictList('SOURCE_TYPE')
if (code != '200') return
this.dictionaryOptions = data
this.dialogForm.sourceType = this.dictionaryOptions[0].text
this.dataLink = JSON.parse(this.dictionaryOptions[0].extend)
},
selectChange(val) {
this.dataLink = []
const extendJSON = this.dictionaryOptions.find(function (obj) {
return obj.id == val
})
this.dataLink = JSON.parse(extendJSON.extend)
},
//
test() {
const newList = {}
this.dataLink.forEach((item) => {
newList[item.label] = item.value
})
this.dialogForm.sourceConfig = JSON.stringify(newList)
testConnection(this.dialogForm).then((data) => {
if (data.code == '200') {
this.testReplyCode = data.code
this.$message({
message: '测试成功!',
type: 'success',
})
} else {
this.testReplyCode = null
created() { },
methods: {
operateDatasource(type, prop) {
this.dialogVisibleSetDataSource = true
if (prop) {
this.dataSource = prop.msg;
}else {
this.dataSource = {}
}
})
},
async delData(val) {
this.$confirm('确定删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(async () => {
this.$emit('deletelayer')
this.visible = false
const { code, data } = await deleteDataSource(val)
if (code != '200') return
this.queryByPage()
this.$message({
type: 'success',
message: '删除成功!',
})
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消删除',
})
})
},
//
async UserConfirm(formName) {
const newList = {}
this.dataLink.forEach((item) => {
newList[item.label] = item.value
})
this.dialogForm.sourceConfig = JSON.stringify(newList)
this.$refs[formName].validate(async (valid, obj) => {
if (valid) {
if (this.testReplyCode != '200') {
this.$message.error('测试结果为成功后方可保存!')
return
refreshList(){
this.$refs.listPage.handleQueryForm('query')
}
if (this.dialogForm.id == undefined) {
const { code } = await addDataSource(this.dialogForm)
if (code != '200') return
this.queryByPage()
} else {
const { code } = await editDataSource(this.dialogForm)
if (code != '200') return
this.queryByPage()
}
this.closeDialog(false)
} else {
return
}
})
},
},
}
</script>
<style lang="scss" scoped>
.title {
width: 100%;
display: inline-block;
text-align: left;
}
.query {
margin-top: 5px;
}
</style>

Loading…
Cancel
Save