update 角色管理
This commit is contained in:
169
web-react/src/pages/system/role/data.jsx
Normal file
169
web-react/src/pages/system/role/data.jsx
Normal file
@@ -0,0 +1,169 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Select, Spin, TreeSelect } from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { api } from 'common/api'
|
||||
import getDicData from 'util/dic'
|
||||
|
||||
const { SHOW_PARENT } = TreeSelect
|
||||
|
||||
const initialValues = {}
|
||||
|
||||
export default class data extends Component {
|
||||
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
dataScopeType: [],
|
||||
orgTreeData: [],
|
||||
arerTreeData: [],
|
||||
orgCheckedKeys: [],
|
||||
|
||||
isDefine: false
|
||||
}
|
||||
|
||||
// 表单实例
|
||||
form = React.createRef()
|
||||
|
||||
// 初始化数据
|
||||
record = {}
|
||||
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.props.created && this.props.created(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
|
||||
this.record = cloneDeep(params.record)
|
||||
//#region 从后端转换成前段所需格式
|
||||
const { dataScopeType } = await getDicData('data_scope_type')
|
||||
const orgTreeData = await this.onLoadOrgTreeData()
|
||||
const arerTreeData = await this.onLoadAreaTreeData()
|
||||
const orgCheckedKeys = await this.onLoadRoleOwn(this.record.id)
|
||||
this.setState({
|
||||
dataScopeType,
|
||||
orgTreeData,
|
||||
arerTreeData,
|
||||
orgCheckedKeys
|
||||
})
|
||||
//#endregion
|
||||
this.form.current.setFieldsValue({
|
||||
dataScopeType: this.record.dataScopeType.toString()
|
||||
})
|
||||
|
||||
this.onChange(this.record.dataScopeType)
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
|
||||
const valid = await form.validateFields()
|
||||
if (valid) {
|
||||
const postData = form.getFieldsValue()
|
||||
if (this.record) {
|
||||
postData.id = this.record.id
|
||||
}
|
||||
//#region 从前段转换后端所需格式
|
||||
//#endregion
|
||||
return postData
|
||||
}
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
async onLoadOrgTreeData() {
|
||||
const { data } = await api.getOrgTree()
|
||||
return data
|
||||
}
|
||||
|
||||
async onLoadAreaTreeData() {
|
||||
const { data } = await api.getAreaTree()
|
||||
return data
|
||||
}
|
||||
|
||||
async onLoadRoleOwn(id) {
|
||||
const { data } = await api.sysRoleOwnData({ id })
|
||||
return data
|
||||
}
|
||||
|
||||
onChange(value) {
|
||||
if (value == 5) {
|
||||
this.setState({
|
||||
isDefine: true
|
||||
})
|
||||
} else {
|
||||
this.setState({
|
||||
isDefine: false
|
||||
})
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
initialValues={initialValues}
|
||||
ref={this.form}
|
||||
className="yo-form"
|
||||
>
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<div className="yo-form-group">
|
||||
<Form.Item label="授权范围" name="dataScopeType">
|
||||
<Select placeholder="请选择授权范围" onChange={(value) => this.onChange(value)}>
|
||||
{
|
||||
this.state.dataScopeType.map(item => {
|
||||
return (
|
||||
<Select.Option
|
||||
key={item.code}
|
||||
value={item.code}
|
||||
>{item.value}</Select.Option>
|
||||
)
|
||||
})
|
||||
}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
{
|
||||
this.state.isDefine &&
|
||||
<>
|
||||
<Form.Item label="选择机构" name="grantOrgIdList">
|
||||
<TreeSelect
|
||||
showCheckedStrategy={SHOW_PARENT}
|
||||
treeData={this.state.orgTreeData}
|
||||
placeholder="请选择机构"
|
||||
treeCheckable
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="选择区域" name="grantAreaCodeList" help="缺少获取已保存的列表,react版本节点名无法设置">
|
||||
<TreeSelect
|
||||
showCheckedStrategy={SHOW_PARENT}
|
||||
treeData={this.state.arerTreeData}
|
||||
placeholder="请选择所属区域"
|
||||
treeCheckable
|
||||
/>
|
||||
</Form.Item>
|
||||
</>
|
||||
}
|
||||
</div>
|
||||
</Spin>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
104
web-react/src/pages/system/role/form.jsx
Normal file
104
web-react/src/pages/system/role/form.jsx
Normal file
@@ -0,0 +1,104 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Input, InputNumber, Spin } from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import { cloneDeep } from 'lodash'
|
||||
|
||||
const initialValues = {
|
||||
sort: 100
|
||||
}
|
||||
|
||||
export default class form extends Component {
|
||||
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
}
|
||||
|
||||
// 表单实例
|
||||
form = React.createRef()
|
||||
|
||||
// 初始化数据
|
||||
record = {}
|
||||
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.props.created && this.props.created(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
|
||||
this.record = cloneDeep(params.record)
|
||||
//#region 从后端转换成前段所需格式
|
||||
//#endregion
|
||||
this.form.current.setFieldsValue(this.record)
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
|
||||
const valid = await form.validateFields()
|
||||
if (valid) {
|
||||
const postData = form.getFieldsValue()
|
||||
if (this.record) {
|
||||
postData.id = this.record.id
|
||||
}
|
||||
//#region 从前段转换后端所需格式
|
||||
//#endregion
|
||||
return postData
|
||||
}
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
initialValues={initialValues}
|
||||
ref={this.form}
|
||||
className="yo-form"
|
||||
>
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<div className="yo-form-group">
|
||||
<Form.Item label="角色名" name="name" rules={[{ required: true, message: '请输入应用名称', trigger: 'blur' }]}>
|
||||
<Input autoComplete="off" placeholder="请输入角色名" />
|
||||
</Form.Item>
|
||||
<Form.Item label="唯一编码" name="code" rules={[{ required: true, message: '请输入唯一编码', trigger: 'blur' }]}>
|
||||
<Input autoComplete="off" placeholder="请输入唯一编码" />
|
||||
</Form.Item>
|
||||
<Form.Item label="排序" name="sort">
|
||||
<InputNumber
|
||||
max={1000}
|
||||
min={0}
|
||||
className="w-100-p"
|
||||
autoComplete="off"
|
||||
placeholder="请输入排序"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input.TextArea rows={4} autoComplete="off" placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Spin>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
250
web-react/src/pages/system/role/index.jsx
Normal file
250
web-react/src/pages/system/role/index.jsx
Normal file
@@ -0,0 +1,250 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Dropdown, Form, Input, Menu, message as Message, Popconfirm } from 'antd'
|
||||
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import auth from 'components/authorized/handler'
|
||||
import { isEqual } from 'lodash'
|
||||
import FormBody from './form'
|
||||
import MenuForm from './menu'
|
||||
import DataForm from './data'
|
||||
|
||||
// 配置页面所需接口函数
|
||||
const apiAction = {
|
||||
page: api.getRolePage,
|
||||
add: api.sysRoleAdd,
|
||||
edit: api.sysRoleEdit,
|
||||
delete: api.sysRoleDelete,
|
||||
|
||||
grantMenu: api.sysRoleGrantMenu,
|
||||
grantData: api.sysRoleGrantData
|
||||
}
|
||||
|
||||
// 用于弹窗标题
|
||||
const name = '角色'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
// 表格实例
|
||||
table = React.createRef()
|
||||
|
||||
// 新增窗口实例
|
||||
addForm = React.createRef()
|
||||
// 编辑窗口实例
|
||||
editForm = React.createRef()
|
||||
|
||||
menuForm = React.createRef()
|
||||
dataForm = React.createRef()
|
||||
|
||||
columns = [
|
||||
{
|
||||
title: '角色名',
|
||||
dataIndex: 'name',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '唯一编码',
|
||||
dataIndex: 'code',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sort',
|
||||
sorter: true,
|
||||
}
|
||||
]
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
const flag = auth({ sysRole: [['edit'], ['delete']] })
|
||||
|
||||
if (flag) {
|
||||
this.columns.push({
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (<QueryTableActions>
|
||||
<Auth auth="sysRole:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysRole:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
<Auth auth={{ sysRole: [['grantMenu'], ['grantData']] }}>
|
||||
<Dropdown
|
||||
placement="bottomRight"
|
||||
overlay={
|
||||
<Menu>
|
||||
<Auth auth="sysRole:grantMenu">
|
||||
<Menu.Item>
|
||||
<a onClick={() => this.onOpen(this.menuForm, record)}>授权菜单</a>
|
||||
</Menu.Item>
|
||||
</Auth>
|
||||
<Auth auth="sysRole:grantData">
|
||||
<Menu.Item>
|
||||
<a onClick={() => this.onOpen(this.dataForm, record)}>授权数据</a>
|
||||
</Menu.Item>
|
||||
</Auth>
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
<a className="ant-dropdown-link">
|
||||
授权
|
||||
<AntIcon type="down" />
|
||||
</a>
|
||||
</Dropdown>
|
||||
</Auth>
|
||||
</QueryTableActions>)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
const { data } = await apiAction.page({
|
||||
...params,
|
||||
...query,
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
modal.current.open({
|
||||
record
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
try {
|
||||
await action
|
||||
Message.success(successMessage)
|
||||
this.table.current.onReloadData()
|
||||
} catch {
|
||||
this.table.current.onLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container mode="fluid">
|
||||
<br />
|
||||
<Card bordered={false}>
|
||||
<QueryTable
|
||||
ref={this.table}
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
query={
|
||||
<Auth auth="sysRole:page">
|
||||
<Form.Item label="角色名称" name="name">
|
||||
<Input autoComplete="off" placeholder="请输入角色名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="唯一编号" name="code">
|
||||
<Input autoComplete="off" placeholder="请输入唯一编号" />
|
||||
</Form.Item>
|
||||
</Auth>
|
||||
}
|
||||
operator={
|
||||
<Auth auth="sysRole:add">
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>新增{name}</Button>
|
||||
</Auth>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<ModalForm
|
||||
title={`新增${name}`}
|
||||
action={apiAction.add}
|
||||
ref={this.addForm}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title={`编辑${name}`}
|
||||
action={apiAction.edit}
|
||||
ref={this.editForm}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title="授权菜单"
|
||||
action={apiAction.grantMenu}
|
||||
ref={this.menuForm}
|
||||
width={1200}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<MenuForm />
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title="数据授权"
|
||||
action={apiAction.grantData}
|
||||
ref={this.dataForm}
|
||||
onSuccess={() => this.table.current.onReloadData()}
|
||||
>
|
||||
<DataForm />
|
||||
</ModalForm>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
89
web-react/src/pages/system/role/menu.jsx
Normal file
89
web-react/src/pages/system/role/menu.jsx
Normal file
@@ -0,0 +1,89 @@
|
||||
import React, { Component } from 'react'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { AntIcon, AuthorityView } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import { Empty, Spin } from 'antd'
|
||||
|
||||
export default class form extends Component {
|
||||
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
defaultSelectedKeys: []
|
||||
}
|
||||
|
||||
selectedKeys = []
|
||||
|
||||
view = React.createRef()
|
||||
|
||||
// 初始化数据
|
||||
record = {}
|
||||
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.props.created && this.props.created(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
|
||||
this.record = cloneDeep(params.record)
|
||||
//#region 从后端转换成前段所需格式
|
||||
const { data } = await api.sysRoleOwnMenu({ id: this.record.id })
|
||||
this.setState({
|
||||
defaultSelectedKeys: data
|
||||
})
|
||||
this.view.current.onLoadData()
|
||||
//#endregion
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const postData = {}
|
||||
if (this.record) {
|
||||
postData.id = this.record.id
|
||||
}
|
||||
//#region 从前段转换后端所需格式
|
||||
postData.grantMenuIdList = this.selectedKeys
|
||||
//#endregion
|
||||
return postData
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
async loadData() {
|
||||
const { data } = await api.SysMenuTreeForGrant()
|
||||
return data
|
||||
}
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<AuthorityView
|
||||
autoLoad={false}
|
||||
loadData={this.loadData}
|
||||
defaultSelectedKeys={this.state.defaultSelectedKeys}
|
||||
onSelect={(s1, s2, s3) => this.selectedKeys = s3}
|
||||
ref={this.view}
|
||||
/>
|
||||
{ this.state.loading && <Empty className="pt-lg pb-lg" />}
|
||||
</Spin>
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user