ww664853070
1 year ago
13 changed files with 965 additions and 8 deletions
@ -0,0 +1,98 @@ |
|||
'use strict'; |
|||
const moment = require('moment') |
|||
const fs = require('fs'); |
|||
|
|||
async function get(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
let roleList = await models.Role.findAndCountAll({ |
|||
where: { delete: true }, |
|||
order: [['id', 'desc']], |
|||
}); |
|||
ctx.status = 200 |
|||
ctx.body = roleList; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path:${ctx.path},error:${error}`) |
|||
ctx.status = 400; |
|||
ctx.body = { name: 'FindError', message: '查询角色数据失败' } |
|||
} |
|||
} |
|||
|
|||
async function add(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { name } = ctx.request.body |
|||
|
|||
const role = await models.Role.findOne({ |
|||
where: { name } |
|||
}) |
|||
|
|||
if (role && !role.delete) { |
|||
throw '当前角色已存在' |
|||
} |
|||
|
|||
let storageData = { name } |
|||
await models.Role.create(storageData) |
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function edit(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
// const { pepUserId, provinces, cities, businessLines } = ctx.request.body
|
|||
const { id, name } = ctx.request.body |
|||
|
|||
const role = await models.Role.findOne({ |
|||
where: { id } |
|||
}) |
|||
|
|||
if (!role) { |
|||
throw '当前角色不存在' |
|||
} |
|||
let storageData = { name } |
|||
await models.Role.update(storageData, { |
|||
where: { id } |
|||
}) |
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function del(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { id } = ctx.query |
|||
|
|||
await models.Role.update({ |
|||
delete: false}, |
|||
{where: {id } |
|||
}) |
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
module.exports = { |
|||
get, |
|||
add, |
|||
edit, |
|||
del, |
|||
} |
@ -0,0 +1,99 @@ |
|||
'use strict'; |
|||
const moment = require('moment') |
|||
const fs = require('fs'); |
|||
|
|||
async function get(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
let userRoleList = await models.UserRole.findAndCountAll({ |
|||
order: [['id', 'desc']] |
|||
}); |
|||
ctx.status = 200 |
|||
ctx.body = userRoleList; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path:${ctx.path},error:${error}`) |
|||
ctx.status = 400; |
|||
ctx.body = { name: 'FindError', message: '查询用户信息失败' } |
|||
} |
|||
} |
|||
|
|||
async function add(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { userId, roleId } = ctx.request.body |
|||
await models.UserRole.destroy({ |
|||
where: { roleId: roleId } |
|||
}) |
|||
|
|||
let storageData = userId.map(e => { |
|||
return { |
|||
roleId: roleId, |
|||
userId: e |
|||
} |
|||
}) |
|||
await models.UserRole.bulkCreate(storageData); |
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function edit(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
// const { pepUserId, provinces, cities, businessLines } = ctx.request.body
|
|||
const { id, name } = ctx.request.body |
|||
|
|||
const role = await models.Role.findOne({ |
|||
where: { id } |
|||
}) |
|||
|
|||
if (!role) { |
|||
throw '当前角色不存在' |
|||
} |
|||
let storageData = { name } |
|||
await models.Role.update(storageData, { |
|||
where: { id } |
|||
}) |
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function del(ctx) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
const { id } = ctx.request.body |
|||
|
|||
await models.SalesDistribution.update({ |
|||
delete: false |
|||
}, |
|||
{ |
|||
where: { id } |
|||
}) |
|||
ctx.status = 204; |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
module.exports = { |
|||
get, |
|||
add, |
|||
edit, |
|||
del, |
|||
} |
@ -0,0 +1,40 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const Role = sequelize.define("role", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true |
|||
}, |
|||
name: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
field: "name", |
|||
}, |
|||
delete: { |
|||
type: DataTypes.BOOLEAN, |
|||
allowNull: false, |
|||
defaultValue: true, |
|||
comment: null, |
|||
field: "delete", |
|||
}, |
|||
}, { |
|||
tableName: "role", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.Role = Role; |
|||
|
|||
return Role; |
|||
|
|||
}; |
@ -0,0 +1,38 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const UserRole = sequelize.define("user_role", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true |
|||
}, |
|||
roleId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
field: "role_id", |
|||
}, |
|||
userId: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: true, |
|||
comment: null, |
|||
field: "user_id", |
|||
}, |
|||
}, { |
|||
tableName: "user_role", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.UserRole = UserRole; |
|||
return UserRole; |
|||
}; |
@ -0,0 +1,19 @@ |
|||
'use strict'; |
|||
|
|||
const role = require('../../controllers/role'); |
|||
|
|||
module.exports = function (app, router, opts) { |
|||
|
|||
app.fs.api.logAttr['GET/role/list'] = { content: '查询角色列表', visible: true }; |
|||
router.get('/role/list', role.get); |
|||
|
|||
app.fs.api.logAttr['POST/role/add'] = { content: '添加角色', visible: true }; |
|||
router.post('/role/add', role.add); |
|||
|
|||
app.fs.api.logAttr['PUT/role/edit'] = { content: '编辑角色', visible: true }; |
|||
router.put('/role/edit', role.edit); |
|||
|
|||
app.fs.api.logAttr['DEL/role/del'] = { content: '删除角色', visible: true }; |
|||
router.del('/role/del', role.del); |
|||
|
|||
}; |
@ -0,0 +1,14 @@ |
|||
'use strict'; |
|||
|
|||
const userRole = require('../../controllers/userRole'); |
|||
|
|||
module.exports = function (app, router, opts) { |
|||
|
|||
app.fs.api.logAttr['GET/roleUser/list'] = { content: '角色用户列表', visible: true }; |
|||
router.get('/roleUser/list', userRole.get); |
|||
|
|||
app.fs.api.logAttr['POST/roleUser/add'] = { content: '角色添加用户成功', visible: true }; |
|||
router.post('/roleUser/add', userRole.add); |
|||
|
|||
|
|||
}; |
@ -0,0 +1,82 @@ |
|||
'use strict'; |
|||
|
|||
import { ApiTable, basicAction } from '$utils' |
|||
|
|||
export function getRoleList(query) {//查询
|
|||
return (dispatch) => basicAction({ |
|||
type: "get", |
|||
dispatch: dispatch, |
|||
actionType: "GET_ROLE_LIST", |
|||
query: query, |
|||
url: `${ApiTable.getRoleList}`, |
|||
msg: { option: "查询角色列表" }, |
|||
reducer: { name: "roleList", params: { noClear: true } }, |
|||
}); |
|||
} |
|||
export function addRole(data) { |
|||
return dispatch => basicAction({ |
|||
type: 'post', |
|||
dispatch: dispatch, |
|||
actionType: 'ADD_ROLE', |
|||
url: ApiTable.addRole, |
|||
data: data, |
|||
msg: { option: '添加角色' }, |
|||
}); |
|||
} |
|||
|
|||
export function editRole(data) {//更新
|
|||
let msg = '' |
|||
if (data) { |
|||
msg = data.msg |
|||
} |
|||
return (dispatch) => |
|||
basicAction({ |
|||
type: "put", |
|||
dispatch: dispatch, |
|||
data, |
|||
actionType: "PUT_ROLE", |
|||
url: `${ApiTable.editRole}`, |
|||
msg: { option: msg }, //更新
|
|||
reducer: {}, |
|||
}); |
|||
} |
|||
|
|||
export function delRole(data) {//删除
|
|||
let msg = '' |
|||
if (data) { |
|||
msg = data.msg |
|||
} |
|||
return (dispatch) => |
|||
basicAction({ |
|||
type: "del", |
|||
query: data, |
|||
dispatch: dispatch, |
|||
actionType: "DEL_ROLE", |
|||
url: `${ApiTable.delRole}`, |
|||
msg: { option: msg }, //删除
|
|||
reducer: {}, |
|||
}); |
|||
} |
|||
|
|||
export function getUserRoleList(query) {//查询
|
|||
return (dispatch) => basicAction({ |
|||
type: "get", |
|||
dispatch: dispatch, |
|||
actionType: "GET_USER_ROLE_LIST", |
|||
query: query, |
|||
url: `${ApiTable.getUserRoleList}`, |
|||
msg: { option: "查询角色用户列表" }, |
|||
reducer: { name: "userRoleList", params: { noClear: true } }, |
|||
}); |
|||
} |
|||
|
|||
export function addUserRole(data) { |
|||
return dispatch => basicAction({ |
|||
type: 'post', |
|||
dispatch: dispatch, |
|||
actionType: 'ADD_USER_ROLE', |
|||
url: ApiTable.addUserRole, |
|||
data: data, |
|||
msg: { option: '角色绑定用户' }, |
|||
}); |
|||
} |
@ -0,0 +1,79 @@ |
|||
import React, { useEffect, useState, useRef } from 'react'; |
|||
import { connect } from 'react-redux'; |
|||
import { Col, Row, Modal, Form } from '@douyinfe/semi-ui'; |
|||
import '../style.less' |
|||
|
|||
const EmployeeAuthModal = (props) => { |
|||
const form = useRef(); |
|||
const { dispatch, actions, handleCancel, eidtTit, visible, getRoleList, eidtRole } = props |
|||
|
|||
const handleOk = () => { |
|||
form.current.validate() |
|||
.then((values) => { |
|||
if (eidtRole == null) { |
|||
dispatch(actions.humanAffairs.addRole(values)).then(e => { |
|||
if (e.success) { |
|||
getRoleList() |
|||
handleCancel() |
|||
} |
|||
}) |
|||
} else { |
|||
values.id = eidtRole.id |
|||
dispatch(actions.humanAffairs.editRole(values)).then(e => { |
|||
if (e.success) { |
|||
getRoleList() |
|||
handleCancel() |
|||
} |
|||
}) |
|||
} |
|||
}) |
|||
.catch((errors) => { |
|||
console.log(errors); |
|||
}); |
|||
}; |
|||
let message = '该项为必填项'; |
|||
return ( |
|||
<> |
|||
<Modal |
|||
title={eidtTit} |
|||
visible={visible} |
|||
onOk={handleOk} |
|||
onCancel={handleCancel} |
|||
closeOnEsc={true} |
|||
maskClosable={false} |
|||
> |
|||
<Form |
|||
getFormApi={(formApi) => (form.current = formApi)} |
|||
labelPosition={'left'} |
|||
labelAlign={'right'} |
|||
labelCol={{ span: 6 }} |
|||
wrapperCol={{ span: 18 }} |
|||
> |
|||
<Row> |
|||
<Col span={24}> |
|||
<Form.Input |
|||
field='name' |
|||
label="角色名称" |
|||
initValue={eidtRole?.name || ""} |
|||
rules={[ |
|||
{ required: true, message }, |
|||
]} |
|||
/> |
|||
</Col> |
|||
</Row> |
|||
</Form> |
|||
</Modal> |
|||
</> |
|||
) |
|||
} |
|||
|
|||
function mapStateToProps(state) { |
|||
const { auth, global, roleList } = state; |
|||
return { |
|||
user: auth.user, |
|||
actions: global.actions, |
|||
roleList: roleList.data, |
|||
}; |
|||
} |
|||
|
|||
export default connect(mapStateToProps)(EmployeeAuthModal); |
@ -0,0 +1,114 @@ |
|||
import React, { useEffect, useState, useRef } from 'react'; |
|||
import { connect } from 'react-redux'; |
|||
import { Col, Row, Modal, Form } from '@douyinfe/semi-ui'; |
|||
import '../style.less' |
|||
|
|||
const employeeAuthUserModal = (props) => { |
|||
const form = useRef(); |
|||
const { dispatch, actions, handleCancelUser, visibleUser, getRoleList, roleList,userRoleList } = props |
|||
const [userValue, setUserValue] = useState([]); |
|||
|
|||
const handleOk = () => { |
|||
form.current.validate() |
|||
.then((values) => { |
|||
dispatch(actions.humanAffairs.addUserRole(values)).then(e => { |
|||
if (e.success) { |
|||
getRoleList() |
|||
handleCancelUser() |
|||
} |
|||
}) |
|||
}) |
|||
.catch((errors) => { |
|||
console.log(errors); |
|||
}); |
|||
}; |
|||
let message = '该项为必填项'; |
|||
let hrUser = JSON.parse(sessionStorage.getItem('hrUser')) |
|||
const seleRole = (value)=>{ |
|||
let userValue = [] |
|||
userRoleList&&userRoleList.rows&&userRoleList.rows.forEach(e=> { |
|||
if(e.roleId == value){ |
|||
userValue.push(e.userId) |
|||
} |
|||
}) |
|||
form.current.setValue('userId',userValue) |
|||
} |
|||
return ( |
|||
<> |
|||
<Modal |
|||
title='角色添加用户' |
|||
visible={visibleUser} |
|||
onOk={handleOk} |
|||
onCancel={handleCancelUser} |
|||
closeOnEsc={true} |
|||
maskClosable={false} |
|||
> |
|||
<Form |
|||
getFormApi={(formApi) => (form.current = formApi)} |
|||
labelPosition={'left'} |
|||
labelAlign={'right'} |
|||
labelCol={{ span: 6 }} |
|||
wrapperCol={{ span: 18 }} |
|||
> |
|||
<Row> |
|||
<Col span={24}> |
|||
{/* <Form.Input |
|||
field='name' |
|||
label="选择角色" |
|||
// initValue={eidtRole?.name || ""} |
|||
rules={[ |
|||
{ required: true, message }, |
|||
]} |
|||
/> */} |
|||
<Form.Select |
|||
field="roleId" |
|||
label='选择角色' |
|||
style={{ width: '100%' }} |
|||
onChange = {seleRole} |
|||
rules={[ |
|||
{ required: true, message }, |
|||
]}> |
|||
{ |
|||
roleList && roleList.rows.map(e => { |
|||
return ( |
|||
<Form.Select.Option value={e.id}>{e.name}</Form.Select.Option> |
|||
) |
|||
}) |
|||
} |
|||
</Form.Select> |
|||
<Form.Select |
|||
filter |
|||
multiple |
|||
autoClearSearchValue={false} |
|||
field="userId" |
|||
label='选择用户' |
|||
style={{ width: '100%' }} |
|||
rules={[ |
|||
{ required: true, message }, |
|||
]}> |
|||
{ |
|||
hrUser.userListArr.map(e => { |
|||
return ( |
|||
<Form.Select.Option value={e.id}>{e.name}</Form.Select.Option> |
|||
) |
|||
}) |
|||
} |
|||
</Form.Select> |
|||
</Col> |
|||
</Row> |
|||
</Form> |
|||
</Modal> |
|||
</> |
|||
) |
|||
} |
|||
|
|||
function mapStateToProps(state) { |
|||
const { auth, global, roleList } = state; |
|||
return { |
|||
user: auth.user, |
|||
actions: global.actions, |
|||
roleList: roleList.data, |
|||
}; |
|||
} |
|||
|
|||
export default connect(mapStateToProps)(employeeAuthUserModal); |
Loading…
Reference in new issue