增加多租户模块

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',
@ -98,4 +99,4 @@ export default {
closeOthers: 'Close Others',
closeAll: 'Close All'
}
}
}

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,199 +1,196 @@
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) {
const menu = webiste.menu;
const propsConfig = menu.props;
const propsDefault = {
label: propsConfig.label || 'name',
path: propsConfig.path || 'path',
icon: propsConfig.icon || 'icon',
children: propsConfig.children || 'children'
}
const icon = ele[propsDefault.icon];
ele[propsDefault.icon] = validatenull(icon) ? menu.iconDefault : icon;
const isChild = ele[propsDefault.children] && ele[propsDefault.children].length !== 0;
if (!isChild) ele[propsDefault.children] = [];
if (!isChild && first && !isURL(ele[propsDefault.path])) {
ele[propsDefault.path] = ele[propsDefault.path] + '/index'
} else {
ele[propsDefault.children].forEach(child => {
addPath(child);
})
}
const menu = webiste.menu;
const propsConfig = menu.props;
const propsDefault = {
label: propsConfig.label || 'name',
path: propsConfig.path || 'path',
icon: propsConfig.icon || 'icon',
children: propsConfig.children || 'children'
}
const icon = ele[propsDefault.icon];
ele[propsDefault.icon] = validatenull(icon) ? menu.iconDefault : icon;
const isChild = ele[propsDefault.children] && ele[propsDefault.children].length !== 0;
if (!isChild) ele[propsDefault.children] = [];
if (!isChild && first && !isURL(ele[propsDefault.path])) {
ele[propsDefault.path] = ele[propsDefault.path] + '/index'
} else {
ele[propsDefault.children].forEach(child => {
addPath(child);
})
}
}
const user = {
state: {
userInfo: getStore({name: 'userInfo'}) || [],
permission: getStore({name: 'permission'}) || {},
roles: [],
menu: getStore({name: 'menu'}) || [],
menuAll: [],
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();
})
})
state: {
userInfo: getStore({ name: 'userInfo' }) || [],
permission: getStore({ name: 'permission' }) || {},
roles: [],
menu: getStore({ name: 'menu' }) || [],
menuAll: [],
token: getStore({ name: 'token' }) || '',
},
GetButtons({commit}) {
return new Promise((resolve) => {
getButtons().then(res => {
const data = res.data.data;
commit('SET_PERMISSION', data);
resolve();
})
})
actions: {
//根据用户名登录
LoginByUsername({ commit }, userInfo) {
return new Promise((resolve) => {
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);
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)
})
})
},
},
//根据手机号登录
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: {
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 = [];
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);
}
}
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;
});
setStore({name: 'permission', content: state.permission, type: 'session'})
getCode(permission);
state.permission = {};
result.forEach(ele => {
state.permission[ele] = true;
});
setStore({ name: 'permission', content: state.permission, type: 'session' })
}
}
}
}
export default user

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;
});
}
}
};