增加多租户模块

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({ return request({
url: '/api/blade-system/dept/tree', 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({ return request({
url: '/api/blade-system/role/tree', 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 request from '@/router/axios';
import {baseUrl} from '@/config/env'; 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', url: '/api/blade-auth/token',
method: 'post', method: 'post',
params: { params: {
tenantCode,
account, account,
password, password,
type type

View File

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

View File

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

View File

@ -5,6 +5,16 @@
ref="loginForm" ref="loginForm"
:model="loginForm" :model="loginForm"
label-width="0"> 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-form-item prop="username">
<el-input size="small" <el-input size="small"
@keyup.enter.native="handleLogin" @keyup.enter.native="handleLogin"
@ -45,11 +55,15 @@ export default {
data() { data() {
return { return {
loginForm: { loginForm: {
tenantCode: "000000",
username: "admin", username: "admin",
password: "admin", password: "admin",
type: "account" type: "account"
}, },
loginRules: { loginRules: {
tenantCode: [
{ required: true, message: "请输入租户编号", trigger: "blur" }
],
username: [ username: [
{ required: true, message: "请输入用户名", trigger: "blur" } { required: true, message: "请输入用户名", trigger: "blur" }
], ],

View File

@ -1,199 +1,196 @@
import {setToken, removeToken} from '@/util/auth' import { setToken, removeToken } from '@/util/auth'
import {setStore, getStore} from '@/util/store' import { setStore, getStore } from '@/util/store'
import {isURL, validatenull} from '@/util/validate' import { isURL, validatenull } from '@/util/validate'
import {deepClone} from '@/util/util' import { deepClone } from '@/util/util'
import webiste from '@/config/website' 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) { function addPath(ele, first) {
const menu = webiste.menu; const menu = webiste.menu;
const propsConfig = menu.props; const propsConfig = menu.props;
const propsDefault = { const propsDefault = {
label: propsConfig.label || 'name', label: propsConfig.label || 'name',
path: propsConfig.path || 'path', path: propsConfig.path || 'path',
icon: propsConfig.icon || 'icon', icon: propsConfig.icon || 'icon',
children: propsConfig.children || 'children' children: propsConfig.children || 'children'
} }
const icon = ele[propsDefault.icon]; const icon = ele[propsDefault.icon];
ele[propsDefault.icon] = validatenull(icon) ? menu.iconDefault : icon; ele[propsDefault.icon] = validatenull(icon) ? menu.iconDefault : icon;
const isChild = ele[propsDefault.children] && ele[propsDefault.children].length !== 0; const isChild = ele[propsDefault.children] && ele[propsDefault.children].length !== 0;
if (!isChild) ele[propsDefault.children] = []; if (!isChild) ele[propsDefault.children] = [];
if (!isChild && first && !isURL(ele[propsDefault.path])) { if (!isChild && first && !isURL(ele[propsDefault.path])) {
ele[propsDefault.path] = ele[propsDefault.path] + '/index' ele[propsDefault.path] = ele[propsDefault.path] + '/index'
} else { } else {
ele[propsDefault.children].forEach(child => { ele[propsDefault.children].forEach(child => {
addPath(child); addPath(child);
}) })
} }
} }
const user = { const user = {
state: { state: {
userInfo: getStore({name: 'userInfo'}) || [], userInfo: getStore({ name: 'userInfo' }) || [],
permission: getStore({name: 'permission'}) || {}, permission: getStore({ name: 'permission' }) || {},
roles: [], roles: [],
menu: getStore({name: 'menu'}) || [], menu: getStore({ name: 'menu' }) || [],
menuAll: [], menuAll: [],
token: getStore({name: 'token'}) || '', token: getStore({ name: 'token' }) || '',
},
actions: {
//根据用户名登录
LoginByUsername({commit}, userInfo) {
return new Promise((resolve) => {
loginByUsername(userInfo.username, userInfo.password, userInfo.type).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data.accessToken);
commit('SET_USERIFNO', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
resolve();
})
})
}, },
GetButtons({commit}) { actions: {
return new Promise((resolve) => { //根据用户名登录
getButtons().then(res => { LoginByUsername({ commit }, userInfo) {
const data = res.data.data; return new Promise((resolve) => {
commit('SET_PERMISSION', data); loginByUsername(userInfo.tenantCode, userInfo.username, userInfo.password, userInfo.type).then(res => {
resolve(); const data = res.data.data;
}) commit('SET_TOKEN', data.accessToken);
}) commit('SET_USERIFNO', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
resolve();
})
})
},
GetButtons({ commit }) {
return new Promise((resolve) => {
getButtons().then(res => {
const data = res.data.data;
commit('SET_PERMISSION', data);
resolve();
})
})
},
//根据手机号登录
LoginByPhone({ commit }, userInfo) {
return new Promise((resolve) => {
loginByUsername(userInfo.phone, userInfo.code).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
resolve();
})
})
},
GetUserInfo({ commit }) {
return new Promise((resolve, reject) => {
getUserInfo().then((res) => {
const data = res.data.data;
commit('SET_ROLES', data.roles);
resolve(data);
}).catch(err => {
reject(err);
})
})
},
//刷新token
RefeshToken({ state, commit }) {
return new Promise((resolve, reject) => {
refeshToken(state.refeshToken).then(res => {
const data = res.data.data;
commit('SET_TOKEN', data);
resolve(data);
}).catch(error => {
reject(error)
})
})
},
// 登出
LogOut({ commit }) {
return new Promise((resolve, reject) => {
logout().then(() => {
commit('SET_TOKEN', '')
commit('SET_MENU', [])
commit('SET_ROLES', [])
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
removeToken()
resolve()
}).catch(error => {
reject(error)
})
})
},
//注销session
FedLogOut({ commit }) {
return new Promise(resolve => {
commit('SET_TOKEN', '')
commit('SET_MENU', [])
commit('SET_ROLES', [])
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
removeToken()
resolve()
})
},
GetTopMenu() {
return new Promise(resolve => {
getTopMenu().then((res) => {
const data = res.data.data || []
resolve(data)
})
})
},
//获取系统菜单
GetMenu({ commit, dispatch }, parentId) {
return new Promise(resolve => {
getMenu(parentId).then((res) => {
const data = res.data.data
let menu = deepClone(data);
menu.forEach(ele => {
addPath(ele, true);
})
commit('SET_MENU', menu)
dispatch('GetButtons');
resolve(menu)
})
})
},
}, },
//根据手机号登录 mutations: {
LoginByPhone({commit}, userInfo) { SET_TOKEN: (state, token) => {
return new Promise((resolve) => { setToken(token)
loginByUsername(userInfo.phone, userInfo.code).then(res => { state.token = token;
const data = res.data.data; setStore({ name: 'token', content: state.token, type: 'session' })
commit('SET_TOKEN', data); },
commit('DEL_ALL_TAG'); SET_USERIFNO: (state, userInfo) => {
commit('CLEAR_LOCK'); state.userInfo = userInfo;
resolve(); setStore({ name: 'userInfo', content: state.userInfo })
}) },
}) SET_MENU: (state, menu) => {
}, state.menu = menu
GetUserInfo({commit}) { setStore({ name: 'menu', content: state.menu, type: 'session' })
return new Promise((resolve, reject) => { },
getUserInfo().then((res) => { SET_MENU_ALL: (state, menuAll) => {
const data = res.data.data; state.menuAll = menuAll;
commit('SET_ROLES', data.roles); },
resolve(data); SET_ROLES: (state, roles) => {
}).catch(err => { state.roles = roles;
reject(err); },
}) SET_PERMISSION: (state, permission) => {
}) let result = [];
}, function getCode(list) {
//刷新token list.forEach(ele => {
RefeshToken({state, commit}) { if (typeof (ele) === 'object') {
return new Promise((resolve, reject) => { const chiildren = ele.children;
refeshToken(state.refeshToken).then(res => { const code = ele.code;
const data = res.data.data; if (chiildren) {
commit('SET_TOKEN', data); getCode(chiildren)
resolve(data); } else {
}).catch(error => { result.push(code);
reject(error) }
}) }
})
},
// 登出
LogOut({commit}) {
return new Promise((resolve, reject) => {
logout().then(() => {
commit('SET_TOKEN', '')
commit('SET_MENU', [])
commit('SET_ROLES', [])
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
removeToken()
resolve()
}).catch(error => {
reject(error)
})
})
},
//注销session
FedLogOut({commit}) {
return new Promise(resolve => {
commit('SET_TOKEN', '')
commit('SET_MENU', [])
commit('SET_ROLES', [])
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
removeToken()
resolve()
})
},
GetTopMenu() {
return new Promise(resolve => {
getTopMenu().then((res) => {
const data = res.data.data || []
resolve(data)
})
})
},
//获取系统菜单
GetMenu({commit, dispatch}, parentId) {
return new Promise(resolve => {
getMenu(parentId).then((res) => {
const data = res.data.data
let menu = deepClone(data);
menu.forEach(ele => {
addPath(ele, true);
})
commit('SET_MENU', menu)
dispatch('GetButtons');
resolve(menu)
})
})
},
},
mutations: {
SET_TOKEN: (state, token) => {
setToken(token)
state.token = token;
setStore({name: 'token', content: state.token, type: 'session'})
},
SET_USERIFNO: (state, userInfo) => {
state.userInfo = userInfo;
setStore({name: 'userInfo', content: state.userInfo})
},
SET_MENU: (state, menu) => {
state.menu = menu
setStore({name: 'menu', content: state.menu, type: 'session'})
},
SET_MENU_ALL: (state, menuAll) => {
state.menuAll = menuAll;
},
SET_ROLES: (state, roles) => {
state.roles = roles;
},
SET_PERMISSION: (state, permission) => {
let result = [];
function getCode(list) { })
list.forEach(ele => {
if (typeof (ele) === 'object') {
const chiildren = ele.children;
const code = ele.code;
if (chiildren) {
getCode(chiildren)
} else {
result.push(code);
} }
} getCode(permission);
state.permission = {};
}) result.forEach(ele => {
} state.permission[ele] = true;
});
getCode(permission); setStore({ name: 'permission', content: state.permission, type: 'session' })
state.permission = {}; }
result.forEach(ele => {
state.permission[ele] = true;
});
setStore({name: 'permission', content: state.permission, type: 'session'})
} }
}
} }
export default user export default user

View File

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

View File

@ -92,11 +92,14 @@ export default {
index: true, index: true,
selection: true, selection: true,
viewBtn: true, viewBtn: true,
dialogWidth: 300,
dialogHeight: 400,
column: [ column: [
{ {
label: "角色名称", label: "角色名称",
prop: "roleName", prop: "roleName",
search: true, search: true,
span: 24,
rules: [ rules: [
{ {
required: true, 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: "角色别名", label: "角色别名",
prop: "roleAlias", prop: "roleAlias",
search: true, search: true,
span: 24,
rules: [ rules: [
{ {
required: true, required: true,
@ -123,6 +158,7 @@ export default {
dicData: [], dicData: [],
type: "tree", type: "tree",
hide: true, hide: true,
span: 24,
props: { props: {
label: "title" label: "title"
}, },
@ -138,6 +174,7 @@ export default {
label: "角色排序", label: "角色排序",
prop: "sort", prop: "sort",
type: "number", type: "number",
span: 24,
rules: [ rules: [
{ {
required: true, 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, add,
resetPassword resetPassword
} from "@/api/system/user"; } from "@/api/system/user";
import {getDeptTree} from "@/api/system/dept";
import {getRoleTree} from "@/api/system/role";
import {mapGetters} from "vuex"; import {mapGetters} from "vuex";
export default { export default {
@ -80,6 +82,10 @@
currentPage: 1, currentPage: 1,
total: 0 total: 0
}, },
init: {
roleTree: [],
deptTree: [],
},
option: { option: {
tip: false, tip: false,
border: true, border: true,
@ -91,7 +97,6 @@
{ {
label: "登录账号", label: "登录账号",
prop: "account", prop: "account",
span: 24,
search: true, search: true,
rules: [{ rules: [{
required: true, required: true,
@ -99,6 +104,29 @@
trigger: "blur" 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: '密码', label: '密码',
prop: 'password', prop: 'password',
@ -139,7 +167,7 @@
prop: "roleId", prop: "roleId",
multiple: true, multiple: true,
type: "tree", type: "tree",
dicUrl: "/api/blade-system/role/tree", dicData: [],
props: { props: {
label: "title" label: "title"
}, },
@ -155,7 +183,7 @@
prop: "deptId", prop: "deptId",
type: "tree", type: "tree",
multiple: true, multiple: true,
dicUrl: "/api/blade-system/dept/tree", dicData: [],
props: { props: {
label: "title" label: "title"
}, },
@ -174,6 +202,7 @@
{ {
label: "电子邮箱", label: "电子邮箱",
prop: "email", prop: "email",
hide: true,
overHidden: true overHidden: true
}, },
{ {
@ -201,11 +230,13 @@
type: "date", type: "date",
prop: "birthday", prop: "birthday",
format: "yyyy-MM-dd hh:mm:ss", format: "yyyy-MM-dd hh:mm:ss",
valueFormat: "yyyy-MM-dd hh:mm:ss" valueFormat: "yyyy-MM-dd hh:mm:ss",
hide: true
}, },
{ {
label: "账号状态", label: "账号状态",
prop: "statusName", prop: "statusName",
hide: true,
display: false display: false
} }
] ]
@ -213,6 +244,20 @@
data: [] 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: { computed: {
...mapGetters(["permission"]), ...mapGetters(["permission"]),
permissionList() { permissionList() {
@ -347,6 +392,14 @@
this.page.total = data.total; this.page.total = data.total;
this.data = data.records; 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;
});
} }
} }
}; };