|
@@ -0,0 +1,382 @@
|
|
|
+<template>
|
|
|
+ <div class="page page-ds">
|
|
|
+ <div class="my-top">
|
|
|
+ <el-form inline size="default">
|
|
|
+ <el-form-item label="数据类型">
|
|
|
+ <el-select size="default" v-model="type" style="width: 120px" @change="changeType">
|
|
|
+ <el-option :value="-1" label="全部类型"></el-option>
|
|
|
+ <el-option :value="0" label="mysql"></el-option>
|
|
|
+ <el-option :value="1" label="oracle"></el-option>
|
|
|
+ <el-option :value="2" label="sqlserver"></el-option>
|
|
|
+ <el-option :value="3" label="postgresql"></el-option>
|
|
|
+ <el-option :value="4" label="clickhouse"></el-option>
|
|
|
+ <el-option :value="5" label="kingbase"></el-option>
|
|
|
+ <el-option :value="6" label="dameng"></el-option>
|
|
|
+ <el-option :value="9" label="sybase"></el-option>
|
|
|
+ <el-option :value="10" label="mongodb"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="数据库名称">
|
|
|
+ <el-input size="default" v-model="name" clearable placeholder="输入数据库名称"
|
|
|
+ style="width: 160px"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <el-button size="default" @click="getData" :loading="loading">查询</el-button>
|
|
|
+ <el-button size="default" @click="onReset" :loading="loading">重置</el-button>
|
|
|
+ <div style="flex: 1"></div>
|
|
|
+ <el-button size="default" type="primary" @click="onDsAdd">
|
|
|
+ <el-icon>
|
|
|
+ <Plus/>
|
|
|
+ </el-icon>
|
|
|
+ 新增数据源
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ <div style="height: calc(100% - 95px);overflow-y: auto">
|
|
|
+ <el-table :data="list" height="100%" size="default" v-loading="loading">
|
|
|
+ <el-table-column label="数据库名" prop="dsDb"></el-table-column>
|
|
|
+ <el-table-column label="数据库类型">
|
|
|
+ <template v-slot="{ row }">{{ typeMap[row.dsType] }}</template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="IP地址" prop="dsIp"></el-table-column>
|
|
|
+ <el-table-column label="端口" prop="dsPort"></el-table-column>
|
|
|
+ <el-table-column label="连接用户" prop="dsUser"></el-table-column>
|
|
|
+ <el-table-column label="描述" prop="remark">
|
|
|
+ <template v-slot="{ row }">
|
|
|
+ <div :title="row.remark">{{ row.remark || '-' }}</div>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" width="170px">
|
|
|
+ <template v-slot="{ row }">
|
|
|
+ <el-button type="text" @click="onDsEdit(row)">编辑</el-button>
|
|
|
+ <span class="btn-split">|</span>
|
|
|
+ <el-button type="text" @click="onGoDetail(row)">查看</el-button>
|
|
|
+ <span class="btn-split">|</span>
|
|
|
+ <el-button type="text" @click="onDsDel(row)">删除</el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+ <el-pagination
|
|
|
+ :current-page.sync="page.current" :page-size="page.size" :page-sizes="[10, 20, 30, 40]" :total="page.total"
|
|
|
+ background class="my-page" layout="total, sizes, prev, pager, next, jumper" @size-change="sizeChange"
|
|
|
+ @current-change="currentChange" style="padding-bottom: 0;"
|
|
|
+ ></el-pagination>
|
|
|
+ <el-dialog
|
|
|
+ v-model="showEdit" append-to-body :title="`${editType === 'add' ? '新增' : '编辑'}数据源`" width="600px"
|
|
|
+ >
|
|
|
+ <el-form ref="form" :model="dsForm" :rules="rules" label-width="115px" size="default">
|
|
|
+ <el-form-item label="数据源类型">
|
|
|
+ <el-select v-model="dsForm.dsType" @change="changeType">
|
|
|
+ <el-option :value="0" label="mysql"></el-option>
|
|
|
+ <el-option :value="1" label="oracle"></el-option>
|
|
|
+ <el-option :value="2" label="sqlserver"></el-option>
|
|
|
+ <el-option :value="3" label="postgresql"></el-option>
|
|
|
+ <el-option :value="4" label="clickhouse"></el-option>
|
|
|
+ <el-option :value="5" label="kingbase"></el-option>
|
|
|
+ <el-option :value="6" label="dameng"></el-option>
|
|
|
+ <el-option :value="9" label="sybase"></el-option>
|
|
|
+ <el-option :value="10" label="mongodb"></el-option>
|
|
|
+ </el-select>
|
|
|
+ <el-tooltip
|
|
|
+ class="item" effect="dark" placement="right"
|
|
|
+ content="某些版本的oracle数据库,用户名需要大写才可查询,请自行检查"
|
|
|
+ >
|
|
|
+ <el-button style="margin-left: 10px; color: #999" type="text">
|
|
|
+ <el-icon>
|
|
|
+ <QuestionFilled/>
|
|
|
+ </el-icon>
|
|
|
+ </el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ </el-form-item>
|
|
|
+ <template v-if="[1,2,3,5,6,8,9,10].includes(dsForm.dsType)">
|
|
|
+ <el-form-item label="模式(schema)" prop="dbSchema">
|
|
|
+ <el-input v-model="dsForm.dbSchema" clearable :style="{width:dsForm.dsType===10?'405px':'100%'}"></el-input>
|
|
|
+ <el-tooltip
|
|
|
+ v-if="dsForm.dsType===10" class="item" effect="dark" placement="right"
|
|
|
+ content="使用authSource属性值(指定应验证所提供档案的数据库)"
|
|
|
+ >
|
|
|
+ <el-button type="text" style="margin-left: 10px; color: #999">
|
|
|
+ <el-icon>
|
|
|
+ <QuestionFilled/>
|
|
|
+ </el-icon>
|
|
|
+ </el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ <el-form-item label="数据库名" prop="dsDb">
|
|
|
+ <el-input placeholder="请输入数据库名" v-model="dsForm.dsDb" clearable maxlength="100" show-word-limit
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="连接名" prop="dsName">
|
|
|
+ <el-input placeholder="请输入连接名" v-model="dsForm.dsName" clearable maxlength="100" show-word-limit
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="IP地址" prop="dsIp">
|
|
|
+ <el-input placeholder="请输入IP地址" v-model="dsForm.dsIp" clearable maxlength="100" show-word-limit
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="端口" prop="dsPort">
|
|
|
+ <el-input
|
|
|
+ placeholder="请输入端口" v-model="dsForm.dsPort" clearable maxlength="5" show-word-limit type="number"
|
|
|
+ :min="1"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="连接用户" prop="dsUser" maxlength="100" show-word-limit>
|
|
|
+ <el-input
|
|
|
+ placeholder="请输入连接用户" v-model="dsForm.dsUser" autocomplete="new-password" clearable
|
|
|
+ maxlength="100" show-word-limit
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="dsPassword">
|
|
|
+ <template #label>
|
|
|
+ <span v-if="editType==='add'" style="color: #F56C6C;margin-right: 4px;">*</span>
|
|
|
+ 连接密码
|
|
|
+ </template>
|
|
|
+ <el-input
|
|
|
+ :placeholder="editType==='add'?'请输入连接密码':'******'" v-model="dsForm.dsPassword" clearable
|
|
|
+ autocomplete="new-password" :show-password="editType === 'add'" maxlength="100" show-word-limit
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="描述">
|
|
|
+ <el-input
|
|
|
+ placeholder="请输入描述" v-model="dsForm.remark" :rows="3" type="textarea" clearable
|
|
|
+ maxlength="100" show-word-limit
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div style="margin-top: 30px; display: flex; justify-content: flex-end">
|
|
|
+ <el-button @click="showEdit = false">取消</el-button>
|
|
|
+ <el-button type="primary" @click="onDsEditConfirm" :loading="loadingEdit"> 确定</el-button>
|
|
|
+ <el-button type="primary" @click="onDsTest" :loading="loadingEdit">测试连接</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import {
|
|
|
+ dsList,
|
|
|
+ dsSave,
|
|
|
+ dsTest,
|
|
|
+ dsDel,
|
|
|
+ dsUpdate,
|
|
|
+} from '@/api/ds';
|
|
|
+import {Plus, QuestionFilled} from "@element-plus/icons-vue";
|
|
|
+import {ElMessage, ElMessageBox} from "element-plus";
|
|
|
+let editType = 'add'
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ page: {size: 20, current: 1, total: 0},
|
|
|
+ name: '',
|
|
|
+ type: -1,
|
|
|
+ list: [],
|
|
|
+ showEdit: false,
|
|
|
+ dsForm: {dbSchema: '',},
|
|
|
+ editType: 'add',
|
|
|
+ typeMap: {
|
|
|
+ 0: 'mysql',
|
|
|
+ 1: 'oracle',
|
|
|
+ 2: 'sqlserver',
|
|
|
+ 3: 'postgresql',
|
|
|
+ 4: 'clickhouse',
|
|
|
+ 5: 'kingbase',
|
|
|
+ 6: 'dameng',
|
|
|
+ 9: 'sybase',
|
|
|
+ 10: 'mongodb',
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ dsDb: [
|
|
|
+ {required: true, message: '请输入数据库名', trigger: 'blur'},
|
|
|
+ {
|
|
|
+ validator(rule, value, callback) {
|
|
|
+ if (value.trim() || !value) {
|
|
|
+ callback()
|
|
|
+ } else {
|
|
|
+ callback(new Error('请输入有效内容'));
|
|
|
+ }
|
|
|
+ }, trigger: 'change'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ dsName: [
|
|
|
+ {
|
|
|
+ validator(rule, value, callback) {
|
|
|
+ if (value.trim() || !value) {
|
|
|
+ callback()
|
|
|
+ } else {
|
|
|
+ callback(new Error('请输入有效内容'));
|
|
|
+ }
|
|
|
+ }, trigger: 'change'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ dsIp: [
|
|
|
+ {required: true, message: '请输入IP地址', trigger: 'blur'},
|
|
|
+ {
|
|
|
+ validator(rule, value, callback) {
|
|
|
+ if (/^[0123456789.]+$/g.test(value)) {
|
|
|
+ callback()
|
|
|
+ } else {
|
|
|
+ if ((value + '').length) {
|
|
|
+ callback(new Error('只能输入数字和点'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, trigger: 'change'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ dbSchema: [{required: true, message: '请输入模式(schema)', trigger: 'blur'}],
|
|
|
+ dsPort: [{required: true, message: '请输入端口号', trigger: 'blur'}],
|
|
|
+ dsUser: [{required: true, message: '请输入连接用户', trigger: 'blur'}],
|
|
|
+ dsPassword: [
|
|
|
+ {
|
|
|
+ validator(rule, value, callback) {
|
|
|
+ if (editType === 'add') {
|
|
|
+ if (!value) {
|
|
|
+ callback(new Error('请输入连接密码'));
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ }, trigger: 'blur'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ loading: false,
|
|
|
+ loadingEdit: false,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getData();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getChildren(arr, nodes) {
|
|
|
+ if (!nodes) return;
|
|
|
+ arr.push(...nodes);
|
|
|
+ nodes.forEach(item => {
|
|
|
+ this.getChildren(arr, item.children);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onDsTest() {
|
|
|
+ this.$refs.form.validate(valid => {
|
|
|
+ if (!valid) return
|
|
|
+ let data = {...this.dsForm};
|
|
|
+ if (data.driverClassName) delete data.driverClassName;
|
|
|
+ if (data.url) delete data.url;
|
|
|
+ this.loadingEdit = true
|
|
|
+ dsTest(data).then(res => {
|
|
|
+ if (res.code == 200) {
|
|
|
+ ElMessage({message: '连接成功', type: 'success'});
|
|
|
+ } else {
|
|
|
+ ElMessage.error('连接错误');
|
|
|
+ }
|
|
|
+ }).finally(() => this.loadingEdit = false);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onDsDel(ds) {
|
|
|
+ ElMessageBox.confirm('确定删除此数据源?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning',
|
|
|
+ }).then(() => {
|
|
|
+ dsDel({ids: ds.id}).then(res => {
|
|
|
+ ElMessage({type: 'success', message: '已删除'});
|
|
|
+ this.getData();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 确认编辑数据源
|
|
|
+ onDsEditConfirm() {
|
|
|
+ this.$refs.form.validate(valid => {
|
|
|
+ if (!valid) return;
|
|
|
+ let data = {...this.dsForm};
|
|
|
+ this.loadingEdit = true
|
|
|
+ if (this.editType == 'add') {
|
|
|
+ dsSave(data).then(res => {
|
|
|
+ ElMessage({type: 'success', message: '已提交'});
|
|
|
+ this.showEdit = false;
|
|
|
+ this.getData();
|
|
|
+ }).finally(() => this.loadingEdit = false);
|
|
|
+ } else if (this.editType == 'edit') {
|
|
|
+ dsUpdate(data).then(res => {
|
|
|
+ ElMessage({type: 'success', message: '已提交'});
|
|
|
+ this.showEdit = false;
|
|
|
+ this.getData();
|
|
|
+ }).finally(() => this.loadingEdit = false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onGoDetail(ds) {
|
|
|
+ this.$router.push({path: '/system/ds/detail', query: {id: ds.id, type: ds.dsType}});
|
|
|
+ },
|
|
|
+ // 编辑数据源
|
|
|
+ onDsEdit(ds) {
|
|
|
+ this.editType = 'edit';
|
|
|
+ editType = 'edit'
|
|
|
+ this.dsForm = {...ds};
|
|
|
+ this.showEdit = true;
|
|
|
+ },
|
|
|
+ // 添加数据源
|
|
|
+ onDsAdd() {
|
|
|
+ this.editType = 'add';
|
|
|
+ editType = 'add';
|
|
|
+ this.dsForm = {
|
|
|
+ dsDb: '', // 数据库名
|
|
|
+ dsName: '', // 数据库连接名
|
|
|
+ dbSchema: 'public', // 数据库schema
|
|
|
+ dsIp: '', // ip地址
|
|
|
+ dsPort: '', // 端口
|
|
|
+ dsUser: '', // 连接用户名
|
|
|
+ dsPassword: '', // 连接密码
|
|
|
+ dsType: 0, // 数据源类型 0-mysql 1-oracle 2-sqlserver 3-postgresql 4-clickhouse 5-kingbase 6-dameng
|
|
|
+ remark: '', // 描述
|
|
|
+ whetherPublic: 1 // 公共数据源
|
|
|
+ };
|
|
|
+ this.showEdit = true;
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.form.clearValidate();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ changeType(e) {
|
|
|
+ if (e === 1) {
|
|
|
+ this.dsForm.dbSchema = '';
|
|
|
+ } else if (e === 2) {
|
|
|
+ this.dsForm.dbSchema = 'dbo';
|
|
|
+ } else if (e === 10) {
|
|
|
+ this.dsForm.dbSchema = 'admin';
|
|
|
+ } else {
|
|
|
+ this.dsForm.dbSchema = 'public';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getData() {
|
|
|
+ let {current, size} = this.page;
|
|
|
+ let data = {current, size};
|
|
|
+ if (this.name) data.dsName = this.name;
|
|
|
+ if (this.type !== -1) data.dsType = this.type;
|
|
|
+ this.loading = true
|
|
|
+ dsList(data).then(res => {
|
|
|
+ let {total, records} = res.data;
|
|
|
+ this.page.total = total;
|
|
|
+ this.list = records;
|
|
|
+ }).finally(() => {
|
|
|
+ this.loading = false
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onReset() {
|
|
|
+ this.type = -1;
|
|
|
+ this.name = '';
|
|
|
+ this.page.current = 1;
|
|
|
+ this.getData();
|
|
|
+ },
|
|
|
+ sizeChange(size) {
|
|
|
+ this.page.size = size;
|
|
|
+ this.getData();
|
|
|
+ },
|
|
|
+ currentChange(val) {
|
|
|
+ this.page.current = val;
|
|
|
+ this.getData();
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style lang="scss">
|
|
|
+</style>
|