🎉 增加多租户数据库隔离、动态数据源切换功能

dev
smallchill 5 years ago
parent 70756ef148
commit 38bf1fd32e
  1. 11
      src/api/system/tenant.js
  2. 68
      src/views/system/tenant.vue

@ -59,6 +59,17 @@ export const setting = (ids, form) => {
})
}
export const datasource = (tenantId, datasourceId) => {
return request({
url: '/api/blade-system/tenant/datasource',
method: 'post',
params: {
tenantId,
datasourceId
}
})
}
export const info = (domain) => {
return request({
url: '/api/blade-system/tenant/info',

@ -32,6 +32,12 @@
icon="el-icon-setting"
@click="handleSetting">授权配置
</el-button>
<el-button size="small"
plain
v-if="userInfo.role_name.includes('administrator')"
icon="el-icon-coin"
@click="handleDatasource">数据源配置
</el-button>
</template>
<template slot-scope="{row}"
slot="accountNumber">
@ -48,11 +54,17 @@
width="450px">
<avue-form :option="settingOption" v-model="settingForm" @submit="handleSubmit"/>
</el-dialog>
<el-dialog title="租户数据源配置"
append-to-body
:visible.sync="datasourceBox"
width="450px">
<avue-form :option="datasourceOption" v-model="datasourceForm" @submit="handleDatasourceSubmit"/>
</el-dialog>
</basic-container>
</template>
<script>
import {getList, getDetail, remove, update, add, setting} from "@/api/system/tenant";
import {getList, getDetail, remove, update, add, setting, datasource} from "@/api/system/tenant";
import {mapGetters} from "vuex";
export default {
@ -63,6 +75,7 @@
query: {},
loading: true,
box: false,
datasourceBox: false,
page: {
pageSize: 10,
currentPage: 1,
@ -186,6 +199,28 @@
span: 24,
},
]
},
datasourceForm: {},
datasourceOption: {
column: [
{
label: "数据源",
prop: "datasourceId",
search: true,
span: 24,
type: "select",
dicUrl: "/api/blade-develop/datasource/select",
props: {
label: "name",
value: "id"
},
rules: [{
required: true,
message: "请选择数据源",
trigger: "blur"
}]
},
]
}
};
},
@ -205,6 +240,9 @@
ids.push(ele.id);
});
return ids.join(",");
},
tenantId() {
return this.selectionList[0].tenantId;
}
},
methods: {
@ -322,6 +360,21 @@
}
this.box = true;
},
handleDatasource() {
if (this.selectionList.length === 0) {
this.$message.warning("请选择至少一条数据");
return;
}
if (this.selectionList.length !== 1) {
this.$message.warning("只能选择一条数据");
return;
}
getDetail(this.selectionList[0].id).then(res => {
const data = res.data.data;
this.datasourceForm.datasourceId = data.datasourceId;
});
this.datasourceBox = true;
},
handleSubmit(form, done, loading) {
setting(this.ids, form).then(() => {
this.onLoad(this.page);
@ -336,6 +389,19 @@
loading();
});
},
handleDatasourceSubmit(form, done, loading) {
datasource(this.tenantId, form.datasourceId).then(() => {
this.$message({
type: "success",
message: "配置成功!"
});
done();
this.datasourceBox = false;
}, error => {
window.console.log(error);
loading();
});
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},

Loading…
Cancel
Save