Commit b71d9b4d by 胡悦

提交用户和角色接口逻辑

1 parent c224df34
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
<el-select <el-select
v-model="ruleForm[item.prop]" v-model="ruleForm[item.prop]"
:placeholder="item.placeholder || '请选择'" :placeholder="item.placeholder || '请选择'"
:filterable="item.filterable || false"
@change="selectChange" @change="selectChange"
> >
<el-option <el-option
...@@ -64,7 +65,7 @@ ...@@ -64,7 +65,7 @@
<el-radio <el-radio
v-for="(child,childIndex) in item.children" v-for="(child,childIndex) in item.children"
:key="childIndex" :key="childIndex"
:label="child" :label="childIndex"
>{{child}}</el-radio> >{{child}}</el-radio>
</el-radio-group> </el-radio-group>
<el-select <el-select
...@@ -83,11 +84,11 @@ ...@@ -83,11 +84,11 @@
</el-option> </el-option>
</el-select> </el-select>
</template> </template>
<template <template v-else-if="item.type == 'customize'">
v-else-if="item.type == 'customize'" <slot
name="form-slot" :scope="scope"
:name="item.slotName"
> >
<slot :scope="scope">
</slot> </slot>
</template> </template>
</template> </template>
...@@ -140,6 +141,8 @@ export default { ...@@ -140,6 +141,8 @@ export default {
default: '100px' default: '100px'
} }
}, },
mounted() {
},
methods: { methods: {
selectChange(val) { selectChange(val) {
// console.log(val ,'selectChange') // console.log(val ,'selectChange')
......
...@@ -20,12 +20,27 @@ const API = { ...@@ -20,12 +20,27 @@ const API = {
const USER_API = { const USER_API = {
USER_SEARCH: BASE_URL + '/usercenter/user/search', USER_SEARCH: BASE_URL + '/usercenter/user/search',
USER_SUPER: BASE_URL + '/usercenter/user/suitableSuperUsers', USER_SUPER: BASE_URL + '/usercenter/user/suitableSuperUsers',
USER_ADD: BASE_URL + '/usercenter/user/add' USER_ADD: BASE_URL + '/usercenter/user/add',
USER_EDIT: BASE_URL + '/usercenter/user/edit',
USER_INFO: BASE_URL + '/usercenter/user/info',
USER_DELETE: BASE_URL + '/usercenter/user/delete',
ROLE_SIMPLELIST: BASE_URL + '/usercenter/role/simplelist'
} }
const ROLE_API = { const ROLE_API = {
ROLE_SEARCH: { ROLE_SEARCH: BASE_URL + '/usercenter/role/search',
apiUrl: BASE_URL + '/usercenter/role/search' ROLE_INFO: BASE_URL + '/usercenter/role/info',
} TENANT_SIMPLELIST: BASE_URL + '/usercenter/tenant/simplelist',
ROLE_ADD: BASE_URL + '/usercenter/role/add',
ROLE_EDIT: BASE_URL + '/usercenter/role/edit',
ROLE_DELETE: BASE_URL + '/usercenter/role/delete'
}
const MENU_API = {
MENU_SEARCH: BASE_URL + '/usercenter/menu/search',
MENU_CHILDREN: BASE_URL + '/usercenter/menu/children',
MENU_ADD: BASE_URL + '/usercenter/menu/add',
MENU_EDIT: BASE_URL + '/usercenter/menu/edit',
MENU_DELETE: BASE_URL + '/usercenter/menu/delete',
MENU_INFO: BASE_URL + '/usercenter/menu/info'
} }
const ORGINIZA_API = { const ORGINIZA_API = {
ORGINIZA_SEARCH: BASE_URL + '/usercenter/organization/rootList', ORGINIZA_SEARCH: BASE_URL + '/usercenter/organization/rootList',
...@@ -48,4 +63,4 @@ const WORKLOG_API = { ...@@ -48,4 +63,4 @@ const WORKLOG_API = {
WORKLOG_SEARCH: BASE_URL + '/loggincenter/loggin/search', WORKLOG_SEARCH: BASE_URL + '/loggincenter/loggin/search',
WORKLOG_EXPORT: BASE_URL + '/loggincenter/loggin/export' WORKLOG_EXPORT: BASE_URL + '/loggincenter/loggin/export'
} }
export { API, USER_API, ROLE_API, ORGINIZA_API, DICT_API, WORKLOG_API } export { API, USER_API, ROLE_API, ORGINIZA_API, DICT_API, WORKLOG_API, MENU_API }
import { MENU_API } from '@/config/config'
import request from '@/services/request'
// 获取菜单列表
function getMenuList (params) {
const url = MENU_API.MENU_SEARCH
return request(params, url)
}
// 根据菜单根节点获取子节点
function getMenuChildren (params) {
const url = MENU_API.MENU_CHILDREN
return request(params, url)
}
// 添加菜单
function addMenu (params) {
const url = MENU_API.MENU_ADD
return request(params, url, 'post')
}
// 编辑菜单
function editMenu (params) {
const url = MENU_API.MENU_EDIT
return request(params, url, 'post')
}
// 删除菜单
function deleteMenu (params) {
const url = MENU_API.MENU_DELETE
return request(params, url)
}
// 获取菜单列表
function menuInfo (params) {
const url = MENU_API.MENU_INFO
return request(params, url)
}
export { getMenuList, getMenuChildren, addMenu, editMenu, menuInfo, deleteMenu }
import HTTP from '@/utils/http'
import { ROLE_API } from '@/config/config' import { ROLE_API } from '@/config/config'
import request from '@/services/request'
export default class RoleService extends HTTP { // 获取用户列表
function getRoleList (params) {
const url = ROLE_API.ROLE_SEARCH
return request(params, url)
}
// 获取用户详情
function roleInfo (params) {
const url = ROLE_API.ROLE_INFO
return request(params, url)
}
// 获取租户列表
function getTenantList (params) {
const url = ROLE_API.TENANT_SIMPLELIST
return request(params, url)
} }
// 获取用户列表
function addRole (params) {
const url = ROLE_API.ROLE_ADD
return request(params, url, 'post')
}
// 获取用户列表
function editRole (params) {
const url = ROLE_API.ROLE_EDIT
return request(params, url, 'post')
}
// 获取用户列表
function deleteRole (params) {
const url = ROLE_API.ROLE_DELETE
return request(params, url)
}
export { getRoleList, roleInfo, getTenantList, addRole, editRole, deleteRole }
import { USER_API} from '@/config/config' import { USER_API } from '@/config/config'
import request from '@/services/request' import request from '@/services/request'
// 获取用户列表 // 获取用户列表
...@@ -14,7 +14,26 @@ function getSuperUser (params) { ...@@ -14,7 +14,26 @@ function getSuperUser (params) {
// 新增用户 // 新增用户
function addUser (params) { function addUser (params) {
const url = USER_API.USER_ADD const url = USER_API.USER_ADD
return request(params, url, 'post')
}
// 编辑用户
function editUser (params) {
const url = USER_API.USER_EDIT
return request(params, url, 'post')
}
// 用户详情
function detailUser (params) {
const url = USER_API.USER_INFO
return request(params, url) return request(params, url)
} }
// 删除用户
export { getUserList, getSuperUser, addUser} function deleteUser (params) {
const url = USER_API.USER_DELETE
return request(params, url)
}
// 下拉角色列表
function roleList (params) {
const url = USER_API.ROLE_SIMPLELIST
return request(params, url)
}
export { getUserList, getSuperUser, addUser, editUser, detailUser, deleteUser, roleList }
const Constants = { const Constants = {
// 用户状态 // 用户状态
USER_STATUS: { USER_STATUS: {
'0': '正常, green', '1': '正常, green',
'-1': '停用, red' '2': '停用, red'
}, },
// 角色数据权限 // 角色数据权限
ROLE_AUTH: { ROLE_AUTH: {
...@@ -14,9 +14,20 @@ const Constants = { ...@@ -14,9 +14,20 @@ const Constants = {
}, },
// 租户可见度 // 租户可见度
ROLE_VISIBLE: { ROLE_VISIBLE: {
'0': '共享', 0: '共享',
'1': '仅系统管理员', 1: '仅系统管理员',
'2': '可见租户' 2: '可见租户'
},
// 菜单类型
MENU_TYPE: {
1: '目录',
2: '菜单',
3: '按钮'
},
// 菜单状态
MENU_STATUS: {
1: '正常, green',
2: '不显示, gray'
}, },
// 组织状态 // 组织状态
ORGINIZA_STATUS: { ORGINIZA_STATUS: {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
</div> </div>
<basic-table <basic-table
:tableParams="tableParams" :tableParams="tableParams"
:apiParame="apiParame" :getListApi="getListApi"
:searchForm="searchForm" :searchForm="searchForm"
:hasNum="false" :hasNum="false"
> >
...@@ -63,10 +63,32 @@ ...@@ -63,10 +63,32 @@
:labelWidth="'120px'" :labelWidth="'120px'"
ref='roleForm' ref='roleForm'
> >
<slot <div slot="visible-type">
name="form-slot" <el-radio-group
slot-scope="scope" @change="radioChange($event)"
v-model="roleForm.visibleType"
>
<el-radio
v-for="(child,childIndex) in $Constants.ROLE_VISIBLE"
:key="childIndex"
:label="childIndex"
>{{child}}</el-radio>
</el-radio-group>
<el-select
v-if="roleForm.visibleType == '2'"
v-model="roleForm.visibleTenant"
placeholder="请选择"
>
<el-option
v-for="i in tenantList"
:key="i.tenantId"
:label="i.departmentName"
:value="i.tenantId"
> >
</el-option>
</el-select>
</div>
<div slot="menu-list">
<el-tree <el-tree
:data="data" :data="data"
show-checkbox show-checkbox
...@@ -74,9 +96,11 @@ ...@@ -74,9 +96,11 @@
node-key="id" node-key="id"
ref="tree" ref="tree"
highlight-current highlight-current
@getCheckedKeys="getCheckedKeys"
@setCheckedNodes="setCheckedNodes"
> >
</el-tree> </el-tree>
</slot> </div>
</rule-form> </rule-form>
</slot> </slot>
</basic-dialog> </basic-dialog>
...@@ -85,13 +109,17 @@ ...@@ -85,13 +109,17 @@
</template> </template>
<script> <script>
import { import { getRoleList, roleInfo, getTenantList, addRole, editRole, deleteRole } from 'services/role';
ROLE_API
} from '@/config/config'
import RoleService from 'services/role';
export default { export default {
data() { data() {
var checkMenu = (rule, value, callBack) => {
if (value && value.length == 0) {
return callBack(new Error('请选择菜单列表'))
} else {
return callBack()
}
}
return { return {
searchForm: {}, searchForm: {},
roleFormList: [ roleFormList: [
...@@ -140,31 +168,30 @@ export default { ...@@ -140,31 +168,30 @@ export default {
] ]
} }
}, },
apiParame: ROLE_API.ROLE_SEARCH, getListApi: getRoleList,
// 弹窗数据 // 弹窗数据
roleDialogTitle: '新增角色', roleDialogTitle: '新增角色',
roleVisible: false, roleVisible: false,
roleForm: { roleForm: {
account: '胡悦', enableStatus: true,
departmentId: '', menuIdList: []
superiorId: '',
enableStatus: true
}, },
roleData: [ roleData: [
{ label: '角色名称:', prop: 'roleName', type: 'input' }, { label: '角色名称:', prop: 'roleName', type: 'input' },
{ label: '备注:', prop: 'remark', type: 'input' }, { label: '备注:', prop: 'remark', type: 'input' },
{ label: '状态:', prop: 'enableStatus', type: 'switch' }, { label: '状态:', prop: 'enableStatus', type: 'switch' },
{ label: '租户可见度:', prop: 'visibleType', type: 'radio', hasSelect: true, children: this.$Constants.ROLE_VISIBLE }, { label: '租户可见度:', prop: 'visibleType', type: 'customize', slotName: 'visible-type' },
// { label: '租户可见度:', prop: 'visibleType', type: 'radio', hasSelect: true, children: this.$Constants.ROLE_VISIBLE },
{ label: '数据权限:', prop: 'permissionType', type: 'radio', children: this.$Constants.ROLE_AUTH }, { label: '数据权限:', prop: 'permissionType', type: 'radio', children: this.$Constants.ROLE_AUTH },
// [{ id: 1, label: '本人' }, { id: 2, label: '本人及下属' }, { id: 3, label: '本部门' }, { id: 4, label: '本部门&下属' }, { id: 5, label: '全部' }] // [{ id: 1, label: '本人' }, { id: 2, label: '本人及下属' }, { id: 3, label: '本部门' }, { id: 4, label: '本部门&下属' }, { id: 5, label: '全部' }]
{ label: '菜单权限:', prop: 'menuIdList', type: 'customize' } { label: '菜单权限:', prop: 'menuIdList', type: 'customize', slotName: 'menu-list' }
], ],
roleRules: { roleRules: {
roleName: [{ required: true, message: '请输入角色名称', trigger: blur }], roleName: [{ required: true, message: '请输入角色名称', trigger: 'blur' }],
enableStatus: [{ required: true }], enableStatus: [{ required: true }],
visibleType: [{ required: true, message: '请选择租户可见度' }], visibleType: [{ required: true, message: '请选择租户可见度' }],
permissionType: [{ required: true, message: '请选择数据权限' }], permissionType: [{ required: true, message: '请选择数据权限' }],
menuIdList: [{ required: true, message: '请选择菜单列表' }] menuIdList: [{ required: true, validator: checkMenu, trigger: 'blur' }]
}, },
data: [{ data: [{
id: 1, id: 1,
...@@ -200,9 +227,13 @@ export default { ...@@ -200,9 +227,13 @@ export default {
id: 8, id: 8,
label: '二级 3-2' label: '二级 3-2'
}] }]
}] }],
tenantList: []
} }
}, },
mounted() {
this.getTenantList()
},
methods: { methods: {
// 重置搜索条件 // 重置搜索条件
refresh() { refresh() {
...@@ -210,10 +241,17 @@ export default { ...@@ -210,10 +241,17 @@ export default {
}, },
// 确定 // 确定
handleConfirm() { handleConfirm() {
console.log(this.$refs.roleForm) this.getCheckedKeys()
console.log(this.roleForm)
this.$refs.roleForm.$children[0].validate((valid) => { this.$refs.roleForm.$children[0].validate((valid) => {
if (valid) { if (valid) {
let params = JSON.parse(JSON.stringify(this.roleForm))
params.enableStatus = this.roleForm.enableStatus ? 1 : 2
let api = addRole
if (params.id) api = editRole
api(params).then(res => {
this.handleClose() this.handleClose()
})
} else { } else {
console.log('error') console.log('error')
} }
...@@ -232,6 +270,11 @@ export default { ...@@ -232,6 +270,11 @@ export default {
switch (pType) { switch (pType) {
case 'create': case 'create':
this.roleDialogTitle = '新增角色' this.roleDialogTitle = '新增角色'
this.roleForm = {
enableStatus: true,
menuIdList: []
}
this.setCheckedNodes()
this.handleClose() this.handleClose()
break break
case 'edit': case 'edit':
...@@ -245,7 +288,12 @@ export default { ...@@ -245,7 +288,12 @@ export default {
}, },
// 编辑触发事件 // 编辑触发事件
editEvent(row) { editEvent(row) {
this.handleClose() roleInfo({ id: row.id }).then(res => {
this.roleForm = JSON.parse(JSON.stringify(res.data))
this.roleForm.enableStatus = res.data.enableStatus == 1 ? true : false
this.handleClose(res.data)
})
}, },
// 删除触发事件 // 删除触发事件
deleteEvent(id) { deleteEvent(id) {
...@@ -256,13 +304,32 @@ export default { ...@@ -256,13 +304,32 @@ export default {
tipTitle: '提示', tipTitle: '提示',
type: 'error', type: 'error',
callBack: () => { callBack: () => {
deleteRole({ id: id }).then(res => {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '删除成功!' message: '删除成功!'
}) })
})
} }
} }
this.$Common.confirmDialog(tipData) this.$Common.confirmDialog(tipData)
},
// 获取选中菜单数组
getCheckedKeys() {
this.roleForm.menuIdList = this.$refs.tree.getCheckedKeys()
console.log(this.$refs.tree.getCheckedKeys())
},
setCheckedNodes() {
this.$refs.tree.setCheckedNodes([])
},
// 获取租户列表
getTenantList() {
getTenantList().then(res => {
this.tenantList = res.data
})
},
radioChange(e) {
console.log(e)
} }
} }
} }
......
...@@ -56,7 +56,8 @@ ...@@ -56,7 +56,8 @@
<span <span
class="dot" class="dot"
:class="scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[1] : ''" :class="scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[1] : ''"
></span><span class="statusText">{{ scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[0] : '--'}}</span> ></span>
<span class="statusText">{{ scope.scope.enableStatus ? USERSTATUS[scope.scope.enableStatus].split(',')[0] : '--'}}</span>
</span> </span>
<span <span
slot="table-button" slot="table-button"
...@@ -119,7 +120,7 @@ ...@@ -119,7 +120,7 @@
<script> <script>
// import UserService from 'services/user'; // import UserService from 'services/user';
import { getUserList, getSuperUser, addUser } from 'services/user'; import { getUserList, getSuperUser, addUser, editUser, detailUser, deleteUser, roleList } from 'services/user';
import OrginizaService from 'services/orginizaManage'; import OrginizaService from 'services/orginizaManage';
const orginizaService = new OrginizaService(); const orginizaService = new OrginizaService();
export default { export default {
...@@ -207,18 +208,19 @@ export default { ...@@ -207,18 +208,19 @@ export default {
superiorName: '', superiorName: '',
enableStatus: true enableStatus: true
}, },
roleList: [],
userData: [ userData: [
{ label: '登录名称:', prop: 'account', type: 'input' }, { label: '登录名称:', prop: 'account', type: 'input' },
{ label: '部门名称:', prop: 'departmentName', type: 'input', readonly: true, clickFunc: this.selectDepart }, { label: '部门名称:', prop: 'departmentName', type: 'input', readonly: true, clickFunc: this.selectDepart },
{ label: '直接上级:', prop: 'superiorName', type: 'input', readonly: true, clickFunc: this.selectSuperior }, { label: '直接上级:', prop: 'superiorName', type: 'input', readonly: true, clickFunc: this.selectSuperior },
{ label: '用户名称:', prop: 'username', type: 'input' }, { label: '用户名称:', prop: 'username', type: 'input' },
{ label: '密码:', prop: 'password', type: 'input', inputText: 'password' }, { label: '密码:', prop: 'password', type: 'input', inputText: 'password' },
{ label: '角色:', prop: 'roleId', type: 'select', options: [] }, { label: '角色:', prop: 'roleId', type: 'select', options: [], key: 'roleName', value: 'roleId', filterable: true },
{ label: '邮箱:', prop: 'email', type: 'input' }, { label: '邮箱:', prop: 'email', type: 'input' },
{ label: '手机:', prop: 'phoneNumber', type: 'input' }, { label: '手机:', prop: 'phoneNumber', type: 'input' },
{ label: '性别:', prop: 'gender', type: 'select', options: [] }, { label: '性别:', prop: 'gender', type: 'select', options: [{ label: '男', value: 0 }, { label: '女', value: 1 }] },
{ label: '状态:', prop: 'enableStatus', type: 'switch' }, { label: '状态:', prop: 'enableStatus', type: 'switch' },
{ label: '岗位:', prop: 'position', type: 'select', options: [] } { label: '岗位:', prop: 'position', type: 'select', options: [{ label: '12121', value: 0 }, { label: 'fasdfas', value: 1 }] }
], ],
userRules: { userRules: {
account: [{ required: true, message: '请输入登录名称', trigger: blur }], account: [{ required: true, message: '请输入登录名称', trigger: blur }],
...@@ -305,6 +307,7 @@ export default { ...@@ -305,6 +307,7 @@ export default {
}, },
mounted() { mounted() {
this.getTreeOrg() this.getTreeOrg()
this.getRoleList()
}, },
methods: { methods: {
// 重置搜索条件 // 重置搜索条件
...@@ -313,10 +316,16 @@ export default { ...@@ -313,10 +316,16 @@ export default {
}, },
// 确定,新增用户、编辑用户 // 确定,新增用户、编辑用户
handleConfirm() { handleConfirm() {
console.log(this.$refs.userForm) console.log(this.userForm)
this.$refs.userForm.$children[0].validate((valid) => { this.$refs.userForm.$children[0].validate((valid) => {
if (valid) { if (valid) {
let params = JSON.parse(JSON.stringify(this.userForm))
params.enableStatus = this.userForm.enableStatus ? 1 : 2
let api = addUser
if (params.id) api = editUser
api(params).then(res => {
this.handleClose() this.handleClose()
})
} else { } else {
console.log('error') console.log('error')
} }
...@@ -328,6 +337,7 @@ export default { ...@@ -328,6 +337,7 @@ export default {
this.$refs.userForm.$children[0].resetFields() this.$refs.userForm.$children[0].resetFields()
} }
this.userVisible = !this.userVisible this.userVisible = !this.userVisible
console.log(this.userForm)
}, },
// 组织架构节点 // 组织架构节点
handleNodeClick(data) { handleNodeClick(data) {
...@@ -347,6 +357,11 @@ export default { ...@@ -347,6 +357,11 @@ export default {
switch (pType) { switch (pType) {
case 'create': case 'create':
this.userDialogTitle = '新增用户' this.userDialogTitle = '新增用户'
this.userForm = {
departmentName: '',
superiorName: '',
enableStatus: true
}
this.handleClose() this.handleClose()
break break
case 'edit': case 'edit':
...@@ -361,9 +376,13 @@ export default { ...@@ -361,9 +376,13 @@ export default {
// 编辑触发事件 // 编辑触发事件
editEvent(row) { editEvent(row) {
console.log(row) console.log(row)
detailUser({ id: row.id }).then(res => {
this.userDialogTitle = '编辑用户' this.userDialogTitle = '编辑用户'
this.userForm = row this.userForm = JSON.parse(JSON.stringify(res.data))
this.handleClose(row) this.userForm.enableStatus = res.data.enableStatus == 1 ? true : false
this.handleClose(res.data)
})
}, },
// 删除触发事件 // 删除触发事件
deleteEvent(id) { deleteEvent(id) {
...@@ -374,10 +393,12 @@ export default { ...@@ -374,10 +393,12 @@ export default {
tipTitle: '提示', tipTitle: '提示',
type: 'error', type: 'error',
callBack: () => { callBack: () => {
deleteUser({ id: id }).then(res => {
this.$message({ this.$message({
type: 'success', type: 'success',
message: '删除成功!' message: '删除成功!'
}) })
})
} }
} }
this.$Common.confirmDialog(tipData) this.$Common.confirmDialog(tipData)
...@@ -435,6 +456,14 @@ export default { ...@@ -435,6 +456,14 @@ export default {
console.log(res) console.log(res)
this.data = res.data.list this.data = res.data.list
}) })
},
// 角色下拉列表
getRoleList() {
roleList().then(res => {
this.roleList = res.data
this.userData[5].options = res.data
console.log(this.roleList)
})
} }
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!