增加多租户模块

This commit is contained in:
smallchill 2019-03-09 11:02:12 +08:00
parent 145f8ad072
commit f3d6f63f95
12 changed files with 564 additions and 194 deletions

View File

@ -46,10 +46,13 @@ export const getDept = (id) => {
}
})
}
export const getDeptTree = () => {
export const getDeptTree = (tenantCode) => {
return request({
url: '/api/blade-system/dept/tree',
method: 'get'
method: 'get',
params: {
tenantCode,
}
})
}

View File

@ -66,9 +66,12 @@ export const getRole = (roleIds) => {
})
}
export const getRoleTree = () => {
export const getRoleTree = (tenantCode) => {
return request({
url: '/api/blade-system/role/tree',
method: 'get'
method: 'get',
params: {
tenantCode,
}
})
}

38
src/api/system/tenant.js Normal file
View File

@ -0,0 +1,38 @@
import request from '@/router/axios';
export const getList = (current, size, params) => {
return request({
url: '/api/blade-system/tenant/list',
method: 'get',
params: {
...params,
current,
size,
}
})
}
export const remove = (ids) => {
return request({
url: '/api/blade-system/tenant/remove',
method: 'post',
params: {
ids,
}
})
}
export const add = (row) => {
return request({
url: '/api/blade-system/tenant/submit',
method: 'post',
data: row
})
}
export const update = (row) => {
return request({
url: '/api/blade-system/tenant/submit',
method: 'post',
data: row
})
}

View File

@ -1,10 +1,11 @@
import request from '@/router/axios';
import {baseUrl} from '@/config/env';
export const loginByUsername = (account, password, type) => request({
export const loginByUsername = (tenantCode, account, password, type) => request({
url: '/api/blade-auth/token',
method: 'post',
params: {
tenantCode,
account,
password,
type

View File

@ -66,6 +66,7 @@ export default {
login: {
title: 'Login ',
info: 'Enterprise Development Platform',
tenantCode: 'Please input tenantCode',
username: 'Please input username',
password: 'Please input a password',
wechat: 'Wechat',

View File

@ -66,6 +66,7 @@ export default {
login: {
title: '登录 ',
info: '企业级开发平台',
tenantCode: '请输入租户编号',
username: '请输入账号',
password: '请输入密码',
wechat: '微信',

View File

@ -5,6 +5,16 @@
ref="loginForm"
:model="loginForm"
label-width="0">
<el-form-item prop="tenantCode">
<el-input size="small"
@keyup.enter.native="handleLogin"
v-model="loginForm.tenantCode"
auto-complete="off"
:placeholder="$t('login.tenantCode')">
<i slot="prefix"
class="icon-quanxian"></i>
</el-input>
</el-form-item>
<el-form-item prop="username">
<el-input size="small"
@keyup.enter.native="handleLogin"
@ -45,11 +55,15 @@ export default {
data() {
return {
loginForm: {
tenantCode: "000000",
username: "admin",
password: "admin",
type: "account"
},
loginRules: {
tenantCode: [
{ required: true, message: "请输入租户编号", trigger: "blur" }
],
username: [
{ required: true, message: "请输入用户名", trigger: "blur" }
],

View File

@ -1,9 +1,9 @@
import {setToken, removeToken} from '@/util/auth'
import {setStore, getStore} from '@/util/store'
import {isURL, validatenull} from '@/util/validate'
import {deepClone} from '@/util/util'
import { setToken, removeToken } from '@/util/auth'
import { setStore, getStore } from '@/util/store'
import { isURL, validatenull } from '@/util/validate'
import { deepClone } from '@/util/util'
import webiste from '@/config/website'
import {loginByUsername, getUserInfo, getMenu, getTopMenu, logout, refeshToken, getButtons} from '@/api/user'
import { loginByUsername, getUserInfo, getMenu, getTopMenu, logout, refeshToken, getButtons } from '@/api/user'
function addPath(ele, first) {
@ -28,21 +28,20 @@ function addPath(ele, first) {
}
}
const user = {
state: {
userInfo: getStore({name: 'userInfo'}) || [],
permission: getStore({name: 'permission'}) || {},
userInfo: getStore({ name: 'userInfo' }) || [],
permission: getStore({ name: 'permission' }) || {},
roles: [],
menu: getStore({name: 'menu'}) || [],
menu: getStore({ name: 'menu' }) || [],
menuAll: [],
token: getStore({name: 'token'}) || '',
token: getStore({ name: 'token' }) || '',
},
actions: {
//根据用户名登录
LoginByUsername({commit}, userInfo) {
LoginByUsername({ commit }, userInfo) {
return new Promise((resolve) => {
loginByUsername(userInfo.username, userInfo.password, userInfo.type).then(res => {
loginByUsername(userInfo.tenantCode, userInfo.username, userInfo.password, userInfo.type).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data.accessToken);
commit('SET_USERIFNO', data);
@ -52,7 +51,7 @@ const user = {
})
})
},
GetButtons({commit}) {
GetButtons({ commit }) {
return new Promise((resolve) => {
getButtons().then(res => {
const data = res.data.data;
@ -62,7 +61,7 @@ const user = {
})
},
//根据手机号登录
LoginByPhone({commit}, userInfo) {
LoginByPhone({ commit }, userInfo) {
return new Promise((resolve) => {
loginByUsername(userInfo.phone, userInfo.code).then(res => {
const data = res.data.data;
@ -73,7 +72,7 @@ const user = {
})
})
},
GetUserInfo({commit}) {
GetUserInfo({ commit }) {
return new Promise((resolve, reject) => {
getUserInfo().then((res) => {
const data = res.data.data;
@ -85,7 +84,7 @@ const user = {
})
},
//刷新token
RefeshToken({state, commit}) {
RefeshToken({ state, commit }) {
return new Promise((resolve, reject) => {
refeshToken(state.refeshToken).then(res => {
const data = res.data.data;
@ -97,7 +96,7 @@ const user = {
})
},
// 登出
LogOut({commit}) {
LogOut({ commit }) {
return new Promise((resolve, reject) => {
logout().then(() => {
commit('SET_TOKEN', '')
@ -113,7 +112,7 @@ const user = {
})
},
//注销session
FedLogOut({commit}) {
FedLogOut({ commit }) {
return new Promise(resolve => {
commit('SET_TOKEN', '')
commit('SET_MENU', [])
@ -133,7 +132,7 @@ const user = {
})
},
//获取系统菜单
GetMenu({commit, dispatch}, parentId) {
GetMenu({ commit, dispatch }, parentId) {
return new Promise(resolve => {
getMenu(parentId).then((res) => {
const data = res.data.data
@ -152,15 +151,15 @@ const user = {
SET_TOKEN: (state, token) => {
setToken(token)
state.token = token;
setStore({name: 'token', content: state.token, type: 'session'})
setStore({ name: 'token', content: state.token, type: 'session' })
},
SET_USERIFNO: (state, userInfo) => {
state.userInfo = userInfo;
setStore({name: 'userInfo', content: state.userInfo})
setStore({ name: 'userInfo', content: state.userInfo })
},
SET_MENU: (state, menu) => {
state.menu = menu
setStore({name: 'menu', content: state.menu, type: 'session'})
setStore({ name: 'menu', content: state.menu, type: 'session' })
},
SET_MENU_ALL: (state, menuAll) => {
state.menuAll = menuAll;
@ -170,7 +169,6 @@ const user = {
},
SET_PERMISSION: (state, permission) => {
let result = [];
function getCode(list) {
list.forEach(ele => {
if (typeof (ele) === 'object') {
@ -185,13 +183,12 @@ const user = {
})
}
getCode(permission);
state.permission = {};
result.forEach(ele => {
state.permission[ele] = true;
});
setStore({name: 'permission', content: state.permission, type: 'session'})
setStore({ name: 'permission', content: state.permission, type: 'session' })
}
}

View File

@ -73,6 +73,18 @@
trigger: "blur"
}]
},
{
label: "租户编号",
prop: "tenantCode",
search: true,
addDisplay: false,
editDisplay: false,
rules: [{
required: true,
message: "请输入租户编号",
trigger: "blur"
}]
},
{
label: "部门全称",
prop: "fullName",

View File

@ -92,11 +92,14 @@ export default {
index: true,
selection: true,
viewBtn: true,
dialogWidth: 300,
dialogHeight: 400,
column: [
{
label: "角色名称",
prop: "roleName",
search: true,
span: 24,
rules: [
{
required: true,
@ -105,10 +108,42 @@ export default {
}
]
},
{
label: "租户编号",
prop: "tenantCode",
addDisplay: false,
editDisplay: false,
span: 24,
rules: [{
required: true,
message: "请输入租户编号",
trigger: "blur"
}]
},
{
label: "所属租户",
prop: "tenantCode",
type: "tree",
dicUrl: "/api/blade-system/tenant/select",
addDisplay: false,
editDisplay: false,
span: 24,
props: {
label: "tenantName",
value: "tenantCode"
},
search: true,
rules: [{
required: true,
message: "请输入所属租户",
trigger: "click"
}]
},
{
label: "角色别名",
prop: "roleAlias",
search: true,
span: 24,
rules: [
{
required: true,
@ -123,6 +158,7 @@ export default {
dicData: [],
type: "tree",
hide: true,
span: 24,
props: {
label: "title"
},
@ -138,6 +174,7 @@ export default {
label: "角色排序",
prop: "sort",
type: "number",
span: 24,
rules: [
{
required: true,

210
src/views/system/tenant.vue Normal file
View File

@ -0,0 +1,210 @@
<template>
<basic-container>
<avue-crud :option="option"
:data="data"
ref="crud"
v-model="form"
:page="page"
:permission="permissionList"
@row-del="rowDel"
@row-update="rowUpdate"
@row-save="rowSave"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@on-load="onLoad">
<template slot="menuLeft">
<el-button type="danger"
size="small"
icon="el-icon-delete"
v-if="permission.tenant_delete"
plain
@click="handleDelete">
</el-button>
</template>
<template slot-scope="{row}"
slot="roleId">
<el-tag>{{row.roleName}}</el-tag>
</template>
<template slot-scope="{row}"
slot="deptId">
<el-tag>{{row.deptName}}</el-tag>
</template>
</avue-crud>
</basic-container>
</template>
<script>
import {getList, remove, update, add} from "@/api/system/tenant";
import {mapGetters} from "vuex";
export default {
data() {
return {
form: {},
selectionList: [],
page: {
pageSize: 10,
currentPage: 1,
total: 0
},
option: {
tip: false,
border: true,
index: true,
selection: true,
viewBtn: true,
dialogWidth: 300,
dialogHeight: 400,
column: [
{
label: "租户编号",
prop: "tenantCode",
search: true,
addDisplay: false,
editDisplay: false,
span: 24,
rules: [{
required: true,
message: "请输入租户编号",
trigger: "blur"
}]
},
{
label: "租户名称",
prop: "tenantName",
search: true,
span: 24,
rules: [{
required: true,
message: "请输入参数名称",
trigger: "blur"
}]
},
{
label: "联系人",
prop: "linkman",
search: true,
span: 24,
rules: [{
required: true,
message: "请输入联系人",
trigger: "blur"
}]
},
{
label: "联系电话",
prop: "contactNumber",
span: 24,
},
{
label: "联系地址",
prop: "address",
span: 24,
minRows: 6,
type: "textarea",
}
]
},
data: []
};
},
computed: {
...mapGetters(["permission"]),
permissionList() {
return {
addBtn: this.vaildData(this.permission.tenant_add, false),
viewBtn: this.vaildData(this.permission.tenant_view, false),
delBtn: this.vaildData(this.permission.tenant_delete, false),
editBtn: this.vaildData(this.permission.tenant_edit, false)
};
},
ids() {
let ids = [];
this.selectionList.forEach(ele => {
ids.push(ele.id);
});
return ids.join(",");
}
},
methods: {
rowSave(row, loading) {
add(row).then(() => {
loading();
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!"
});
});
},
rowUpdate(row, index, loading) {
update(row).then(() => {
loading();
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!"
});
});
},
rowDel(row) {
this.$confirm("确定将选择数据删除?", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
return remove(row.id);
})
.then(() => {
this.onLoad(this.page);
this.$message({
type: "success",
message: "操作成功!"
});
});
},
searchReset() {
this.onLoad(this.page);
},
searchChange(params) {
this.onLoad(this.page, params);
},
selectionChange(list) {
this.selectionList = list;
},
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.warning("请选择至少一条数据");
return;
}
this.$confirm("确定将选择数据删除?", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
return remove(this.ids);
})
.then(() => {
this.$message({
type: "success",
message: "操作成功!"
});
this.$refs.crud.toggleSelection();
});
},
onLoad(page, params = {}) {
getList(page.currentPage, page.pageSize, params).then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
});
}
}
};
</script>
<style>
</style>

View File

@ -51,6 +51,8 @@
add,
resetPassword
} from "@/api/system/user";
import {getDeptTree} from "@/api/system/dept";
import {getRoleTree} from "@/api/system/role";
import {mapGetters} from "vuex";
export default {
@ -80,6 +82,10 @@
currentPage: 1,
total: 0
},
init: {
roleTree: [],
deptTree: [],
},
option: {
tip: false,
border: true,
@ -91,7 +97,6 @@
{
label: "登录账号",
prop: "account",
span: 24,
search: true,
rules: [{
required: true,
@ -99,6 +104,29 @@
trigger: "blur"
}]
},
{
label: "租户编号",
prop: "tenantCode",
addDisplay: false,
editDisplay: false,
viewDisplay: false,
},
{
label: "所属租户",
prop: "tenantCode",
type: "tree",
dicUrl: "/api/blade-system/tenant/select",
props: {
label: "tenantName",
value: "tenantCode"
},
search: true,
rules: [{
required: true,
message: "请输入所属租户",
trigger: "click"
}]
},
{
label: '密码',
prop: 'password',
@ -139,7 +167,7 @@
prop: "roleId",
multiple: true,
type: "tree",
dicUrl: "/api/blade-system/role/tree",
dicData: [],
props: {
label: "title"
},
@ -155,7 +183,7 @@
prop: "deptId",
type: "tree",
multiple: true,
dicUrl: "/api/blade-system/dept/tree",
dicData: [],
props: {
label: "title"
},
@ -174,6 +202,7 @@
{
label: "电子邮箱",
prop: "email",
hide: true,
overHidden: true
},
{
@ -201,11 +230,13 @@
type: "date",
prop: "birthday",
format: "yyyy-MM-dd hh:mm:ss",
valueFormat: "yyyy-MM-dd hh:mm:ss"
valueFormat: "yyyy-MM-dd hh:mm:ss",
hide: true
},
{
label: "账号状态",
prop: "statusName",
hide: true,
display: false
}
]
@ -213,6 +244,20 @@
data: []
};
},
watch: {
'form.tenantCode'() {
if (this.form.tenantCode !== '') {
getDeptTree(this.form.tenantCode).then(res => {
const index = this.$refs.crud.findColumnIndex("deptId");
this.option.column[index].dicData = res.data.data;
});
getRoleTree(this.form.tenantCode).then(res => {
const index = this.$refs.crud.findColumnIndex("roleId");
this.option.column[index].dicData = res.data.data;
});
}
}
},
computed: {
...mapGetters(["permission"]),
permissionList() {
@ -347,6 +392,14 @@
this.page.total = data.total;
this.data = data.records;
});
getDeptTree(this.form.tenantCode).then(res => {
const index = this.$refs.crud.findColumnIndex("deptId");
this.option.column[index].dicData = res.data.data;
});
getRoleTree(this.form.tenantCode).then(res => {
const index = this.$refs.crud.findColumnIndex("roleId");
this.option.column[index].dicData = res.data.data;
});
}
}
};