Merge branch 'master' of http://118.178.224.202:3000/ewide/ewide_core
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Input, InputNumber, Spin } from 'antd'
|
||||
import { AntIcon, IconSelector } from 'components'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { AntIcon, ColorSelector, IconSelector } from 'components'
|
||||
import { api } from 'common/api'
|
||||
|
||||
const initialValues = {
|
||||
sort: 100
|
||||
sort: 100,
|
||||
}
|
||||
|
||||
export default class form extends Component {
|
||||
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
@@ -33,17 +32,18 @@ export default class form extends Component {
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
|
||||
this.record = cloneDeep(params.record)
|
||||
//#region 从后端转换成前段所需格式
|
||||
if (params.id) {
|
||||
this.record = (await api.sysAppDetail({ id: params.id })).data
|
||||
}
|
||||
//#endregion
|
||||
this.form.current.setFieldsValue(this.record)
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
loading: false,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export default class form extends Component {
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
@@ -73,17 +73,21 @@ export default class form extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
initialValues={initialValues}
|
||||
ref={this.form}
|
||||
className="yo-form"
|
||||
>
|
||||
<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: '请输入应用名称' }]}>
|
||||
<Form.Item
|
||||
label="应用名称"
|
||||
name="name"
|
||||
rules={[{ required: true, message: '请输入应用名称' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入应用名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="唯一编码" name="code" rules={[{ required: true, message: '请输入唯一编码' }]}>
|
||||
<Form.Item
|
||||
label="唯一编码"
|
||||
name="code"
|
||||
rules={[{ required: true, message: '请输入唯一编码' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入唯一编码" />
|
||||
</Form.Item>
|
||||
<Form.Item label="图标" name="icon">
|
||||
@@ -94,15 +98,17 @@ export default class form extends Component {
|
||||
<AntIcon
|
||||
type="setting"
|
||||
onClick={() =>
|
||||
this
|
||||
.iconSelector
|
||||
.current
|
||||
.open(this.form.current.getFieldValue('icon'))
|
||||
this.iconSelector.current.open(
|
||||
this.form.current.getFieldValue('icon')
|
||||
)
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="颜色" name="color">
|
||||
<ColorSelector placeholder="请选择颜色" />
|
||||
</Form.Item>
|
||||
<Form.Item label="排序" name="sort">
|
||||
<InputNumber
|
||||
max={1000}
|
||||
@@ -113,9 +119,14 @@ export default class form extends Component {
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Spin>
|
||||
<IconSelector ref={this.iconSelector} onSelect={(icon) => this.form.current.setFieldsValue({
|
||||
icon
|
||||
})} />
|
||||
<IconSelector
|
||||
ref={this.iconSelector}
|
||||
onSelect={icon =>
|
||||
this.form.current.setFieldsValue({
|
||||
icon,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -38,6 +38,33 @@ export default class index extends Component {
|
||||
|
||||
// 表格字段
|
||||
columns = [
|
||||
{
|
||||
title: '图标',
|
||||
dataIndex: 'icon',
|
||||
width: 32,
|
||||
render: (text, record) => (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
width: '32px',
|
||||
height: '32px',
|
||||
borderRadius: '100%',
|
||||
backgroundColor: record.color,
|
||||
margin: '0 auto',
|
||||
}}
|
||||
>
|
||||
<AntIcon
|
||||
type={text}
|
||||
style={{
|
||||
fontSize: '20px',
|
||||
color: '#fff',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '应用名称',
|
||||
dataIndex: 'name',
|
||||
@@ -87,6 +114,7 @@ export default class index extends Component {
|
||||
dataIndex: 'sort',
|
||||
width: 100,
|
||||
sorter: true,
|
||||
defaultSortOrder: 'ascend',
|
||||
},
|
||||
]
|
||||
|
||||
@@ -107,7 +135,7 @@ export default class index extends Component {
|
||||
render: (text, record) => (
|
||||
<QueryTableActions>
|
||||
<Auth auth="sysApp:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
<a onClick={() => this.onOpen(this.editForm, record.id)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysApp:delete">
|
||||
<Popconfirm
|
||||
@@ -191,11 +219,11 @@ export default class index extends Component {
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
* @param {*} id
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
onOpen(modal, id) {
|
||||
modal.current.open({
|
||||
record,
|
||||
id,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ export default class index extends Component {
|
||||
title: '区域类型',
|
||||
dataIndex: 'levelType',
|
||||
sorter: true,
|
||||
width: 50,
|
||||
width: 100,
|
||||
render: text => <>{this.bindCodeValue(text, 'areacode_type')}</>,
|
||||
},
|
||||
{
|
||||
@@ -60,14 +60,15 @@ export default class index extends Component {
|
||||
{
|
||||
title: '区域编号',
|
||||
dataIndex: 'code',
|
||||
width: 80,
|
||||
width: 100,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '行政编号',
|
||||
dataIndex: 'adCode',
|
||||
width: 80,
|
||||
width: 100,
|
||||
sorter: true,
|
||||
defaultSortOrder: 'ascend',
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Form, Input, message as Message, Popconfirm } from 'antd'
|
||||
import { Button, Card, Form, Input, message as Message, Popconfirm, Tooltip } from 'antd'
|
||||
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import auth from 'components/authorized/handler'
|
||||
@@ -41,28 +41,41 @@ export default class index extends Component {
|
||||
{
|
||||
title: '参数名称',
|
||||
dataIndex: 'name',
|
||||
width: 200,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '唯一编码',
|
||||
dataIndex: 'code',
|
||||
width: 200,
|
||||
sorter: true,
|
||||
ellipsis: {
|
||||
showTitle: false,
|
||||
},
|
||||
render: text => <Tooltip title={text}>{text}</Tooltip>,
|
||||
},
|
||||
{
|
||||
title: '参数值',
|
||||
dataIndex: 'value',
|
||||
width: 200,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '所属分类',
|
||||
dataIndex: 'groupCode',
|
||||
width: 140,
|
||||
sorter: true,
|
||||
render: text => this.bindCodeValue(text, 'consts_type'),
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
width: 400,
|
||||
sorter: true,
|
||||
ellipsis: {
|
||||
showTitle: false,
|
||||
},
|
||||
render: text => <Tooltip title={text}>{text}</Tooltip>,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -213,6 +226,7 @@ export default class index extends Component {
|
||||
autoLoad={false}
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
scroll={{ x: 1140 }}
|
||||
query={
|
||||
<Auth auth={{ [authName]: 'page' }}>
|
||||
<Form.Item label="参数名称" name="name">
|
||||
|
||||
@@ -14,20 +14,19 @@ const apiAction = {
|
||||
add: api.sysDictDataAdd,
|
||||
edit: api.sysDictDataEdit,
|
||||
delete: api.sysDictDataDelete,
|
||||
deleteBatch: api.sysDictDataDeleteBatch
|
||||
deleteBatch: api.sysDictDataDeleteBatch,
|
||||
}
|
||||
|
||||
// 用于弹窗标题
|
||||
const name = '字典值'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
state = {
|
||||
codes: {
|
||||
commonStatus: []
|
||||
commonStatus: [],
|
||||
},
|
||||
|
||||
selectedRowKeys: []
|
||||
selectedRowKeys: [],
|
||||
}
|
||||
|
||||
// 表格实例
|
||||
@@ -45,7 +44,7 @@ export default class index extends Component {
|
||||
dataIndex: 'value',
|
||||
sorter: true,
|
||||
width: 200,
|
||||
render: (text, record, index) =>
|
||||
render: (text, record, index) => (
|
||||
<Form.Item
|
||||
name={[index, 'value']}
|
||||
rules={[{ required: true, message: '请输入文本' }]}
|
||||
@@ -53,13 +52,14 @@ export default class index extends Component {
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入文本" />
|
||||
</Form.Item>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '字典值',
|
||||
dataIndex: 'code',
|
||||
sorter: true,
|
||||
width: 200,
|
||||
render: (text, record, index) =>
|
||||
render: (text, record, index) => (
|
||||
<Form.Item
|
||||
name={[index, 'code']}
|
||||
rules={[{ required: true, message: '请输入文本' }]}
|
||||
@@ -67,18 +67,19 @@ export default class index extends Component {
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入字典值" />
|
||||
</Form.Item>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '扩展值',
|
||||
dataIndex: 'extCode',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
render: (text, record, index) =>
|
||||
render: (text, record, index) => (
|
||||
<>
|
||||
<Form.Item name={[index, 'extCode']} className="hidden">
|
||||
<Input type="hidden" />
|
||||
</Form.Item>
|
||||
{auth('sysDictData:edit') ?
|
||||
{auth('sysDictData:edit') ? (
|
||||
<a
|
||||
onClick={() => this.onOpen(this.jsonForm, record)}
|
||||
style={{
|
||||
@@ -87,50 +88,58 @@ export default class index extends Component {
|
||||
transform: 'scaleY(.85)',
|
||||
color: 'transparent',
|
||||
backgroundImage: 'linear-gradient(135deg, #007bff, #52c41a)',
|
||||
WebkitBackgroundClip: 'text'
|
||||
WebkitBackgroundClip: 'text',
|
||||
}}
|
||||
>JSON</a>
|
||||
:
|
||||
>
|
||||
JSON
|
||||
</a>
|
||||
) : (
|
||||
<>{text}</>
|
||||
}
|
||||
)}
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sort',
|
||||
sorter: true,
|
||||
width: 100,
|
||||
render: (text, record, index) => <Form.Item name={[index, 'sort']} className="mb-none">
|
||||
<InputNumber
|
||||
max={1000}
|
||||
min={0}
|
||||
step={1}
|
||||
className="w-100-p"
|
||||
autoComplete="off"
|
||||
placeholder="排序"
|
||||
/>
|
||||
</Form.Item>
|
||||
render: (text, record, index) => (
|
||||
<Form.Item name={[index, 'sort']} className="mb-none">
|
||||
<InputNumber
|
||||
max={1000}
|
||||
min={0}
|
||||
step={1}
|
||||
className="w-100-p"
|
||||
autoComplete="off"
|
||||
placeholder="排序"
|
||||
/>
|
||||
</Form.Item>
|
||||
),
|
||||
defaultSortOrder: 'ascend',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
sorter: true,
|
||||
render: (text, record, index) => <Form.Item name={[index, 'remark']} className="mb-none">
|
||||
<Input autoComplete="off" placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
render: (text, record, index) => (
|
||||
<Form.Item name={[index, 'remark']} className="mb-none">
|
||||
<Input autoComplete="off" placeholder="请输入备注" />
|
||||
</Form.Item>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
sorter: true,
|
||||
width: 80,
|
||||
render: text => this.bindCodeValue(text, 'common_status')
|
||||
}
|
||||
render: text => this.bindCodeValue(text, 'common_status'),
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -142,27 +151,28 @@ export default class index extends Component {
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record, index) => (<QueryTableActions>
|
||||
{
|
||||
record.id !== -1 ?
|
||||
render: (text, record, index) => (
|
||||
<QueryTableActions>
|
||||
{record.id !== -1 ? (
|
||||
<Auth auth="sysDictData:edit">
|
||||
<a onClick={() => this.onEdit(index)}>保存编辑</a>
|
||||
</Auth>
|
||||
:
|
||||
) : (
|
||||
<Auth auth="sysDictData:add">
|
||||
<a onClick={() => this.onAdd(index)}>保存新增</a>
|
||||
</Auth>
|
||||
}
|
||||
<Auth auth="sysDictData:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>)
|
||||
)}
|
||||
<Auth auth="sysDictData:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -171,9 +181,9 @@ export default class index extends Component {
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
@@ -186,26 +196,28 @@ export default class index extends Component {
|
||||
componentDidMount() {
|
||||
this.table.current.onLoading()
|
||||
getDictData('common_status').then(res => {
|
||||
this.setState({
|
||||
codes: res
|
||||
}, () => {
|
||||
this.table.current.onLoadData()
|
||||
})
|
||||
this.setState(
|
||||
{
|
||||
codes: res,
|
||||
},
|
||||
() => {
|
||||
this.table.current.onLoadData()
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
|
||||
query = {
|
||||
...query,
|
||||
typeId: this.props.type.id
|
||||
typeId: this.props.type.id,
|
||||
}
|
||||
|
||||
const { data } = await apiAction.page({
|
||||
@@ -225,15 +237,15 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
bindCodeValue(code, name) {
|
||||
name = toCamelCase(name)
|
||||
const codes = this.state.codes[name]
|
||||
if (codes) {
|
||||
const c = codes.find((p) => p.code == code)
|
||||
const c = codes.find(p => p.code == code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
@@ -243,20 +255,20 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
modal.current.open({
|
||||
record
|
||||
record,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage, reload = true) {
|
||||
const table = this.table.current
|
||||
@@ -276,13 +288,10 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(record), '删除成功')
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
@@ -295,12 +304,12 @@ export default class index extends Component {
|
||||
typeId: this.props.type.id,
|
||||
sort: 100,
|
||||
status: 0,
|
||||
remark: null
|
||||
remark: null,
|
||||
}
|
||||
const index = this.table.current.onAddRow(record)
|
||||
if (index !== false) {
|
||||
this.form.current.setFieldsValue({
|
||||
[index]: record
|
||||
[index]: record,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -318,10 +327,7 @@ export default class index extends Component {
|
||||
const record = form.getFieldsValue([index])[index]
|
||||
// 为了正常显示checkbox,默认给id赋予了-1,在这里删除id以表示新增
|
||||
record.id = undefined
|
||||
this.onAction(
|
||||
apiAction.add(record),
|
||||
'新增成功'
|
||||
)
|
||||
this.onAction(apiAction.add(record), '新增成功')
|
||||
}
|
||||
|
||||
async onEdit(index) {
|
||||
@@ -335,21 +341,14 @@ export default class index extends Component {
|
||||
}
|
||||
}
|
||||
const record = form.getFieldsValue([index])[index]
|
||||
this.onAction(
|
||||
apiAction.edit(record),
|
||||
'编辑成功',
|
||||
false
|
||||
)
|
||||
this.onAction(apiAction.edit(record), '编辑成功', false)
|
||||
}
|
||||
|
||||
async onDeleteBatch() {
|
||||
await this.onAction(
|
||||
apiAction.deleteBatch(this.state.selectedRowKeys),
|
||||
'删除成功'
|
||||
)
|
||||
await this.onAction(apiAction.deleteBatch(this.state.selectedRowKeys), '删除成功')
|
||||
|
||||
this.setState({
|
||||
selectedRowKeys: []
|
||||
selectedRowKeys: [],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -360,8 +359,8 @@ export default class index extends Component {
|
||||
index = dataSource.indexOf(data)
|
||||
this.form.current.setFieldsValue({
|
||||
[index]: {
|
||||
extCode
|
||||
}
|
||||
extCode,
|
||||
},
|
||||
})
|
||||
dataSource[index].extCode = extCode
|
||||
table.setState({ dataSource })
|
||||
@@ -369,7 +368,6 @@ export default class index extends Component {
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
|
||||
const { selectedRowKeys } = this.state
|
||||
|
||||
return (
|
||||
@@ -387,9 +385,9 @@ export default class index extends Component {
|
||||
rowSelection={{
|
||||
selectedRowKeys,
|
||||
onChange: selectedRowKeys => this.setState({ selectedRowKeys }),
|
||||
getCheckboxProps: (record) => ({
|
||||
disabled: record.id === -1
|
||||
})
|
||||
getCheckboxProps: record => ({
|
||||
disabled: record.id === -1,
|
||||
}),
|
||||
}}
|
||||
query={
|
||||
<Auth auth="sysDictData:page">
|
||||
@@ -409,28 +407,27 @@ export default class index extends Component {
|
||||
title="是否确认批量删除"
|
||||
onConfirm={() => this.onDeleteBatch()}
|
||||
>
|
||||
<Button disabled={!selectedRowKeys.length} danger>批量删除</Button>
|
||||
<Button disabled={!selectedRowKeys.length} danger>
|
||||
批量删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
}
|
||||
footer={
|
||||
() =>
|
||||
<Auth auth="sysDictData:add">
|
||||
<Button
|
||||
block
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onAddRow()}
|
||||
>新增{name}</Button>
|
||||
</Auth>
|
||||
}
|
||||
footer={() => (
|
||||
<Auth auth="sysDictData:add">
|
||||
<Button
|
||||
block
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onAddRow()}
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
</Auth>
|
||||
)}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<ModalForm
|
||||
title="编辑"
|
||||
action={this.onSaveExtCode}
|
||||
ref={this.jsonForm}
|
||||
>
|
||||
<ModalForm title="编辑" action={this.onSaveExtCode} ref={this.jsonForm}>
|
||||
<FormBody />
|
||||
</ModalForm>
|
||||
</Container>
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Form, Input, message as Message, Popconfirm, Radio } from 'antd'
|
||||
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions, QueryTreeLayout } from 'components'
|
||||
import {
|
||||
AntIcon,
|
||||
Auth,
|
||||
Container,
|
||||
ModalForm,
|
||||
QueryTable,
|
||||
QueryTableActions,
|
||||
QueryTreeLayout,
|
||||
} from 'components'
|
||||
import { api } from 'common/api'
|
||||
import auth from 'components/authorized/handler'
|
||||
import { toCamelCase } from 'util/format'
|
||||
@@ -14,17 +22,16 @@ const apiAction = {
|
||||
page: api.sysDictTypePage,
|
||||
add: api.sysDictTypeAdd,
|
||||
edit: api.sysDictTypeEdit,
|
||||
delete: api.sysDictTypeDelete
|
||||
delete: api.sysDictTypeDelete,
|
||||
}
|
||||
|
||||
const name = '字典'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
state = {
|
||||
codes: {
|
||||
commonStatus: []
|
||||
}
|
||||
commonStatus: [],
|
||||
},
|
||||
}
|
||||
|
||||
// 表格实例
|
||||
@@ -43,24 +50,29 @@ export default class index extends Component {
|
||||
{
|
||||
title: '字典名称',
|
||||
dataIndex: 'name',
|
||||
width: 200,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
key: 'type',
|
||||
dataIndex: 'code',
|
||||
width: 120,
|
||||
sorter: true,
|
||||
render: text => text ? '字典类型' : '目录'
|
||||
render: text => (text ? '字典类型' : '目录'),
|
||||
},
|
||||
{
|
||||
title: '唯一编码',
|
||||
dataIndex: 'code',
|
||||
width: 120,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sort',
|
||||
width: 80,
|
||||
sorter: true,
|
||||
defaultSortOrder: 'ascend',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
@@ -71,14 +83,15 @@ export default class index extends Component {
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 80,
|
||||
sorter: true,
|
||||
render: text => this.bindCodeValue(text, 'common_status')
|
||||
render: text => this.bindCodeValue(text, 'common_status'),
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -90,20 +103,22 @@ export default class index extends Component {
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (<QueryTableActions>
|
||||
<Auth auth="sysDict:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysDict:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>)
|
||||
render: (text, record) => (
|
||||
<QueryTableActions>
|
||||
<Auth auth="sysDict:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysDict:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -112,9 +127,9 @@ export default class index extends Component {
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
@@ -127,26 +142,28 @@ export default class index extends Component {
|
||||
componentDidMount() {
|
||||
this.table.current.onLoading()
|
||||
getDictData('common_status').then(res => {
|
||||
this.setState({
|
||||
codes: res
|
||||
}, () => {
|
||||
this.table.current.onLoadData()
|
||||
})
|
||||
this.setState(
|
||||
{
|
||||
codes: res,
|
||||
},
|
||||
() => {
|
||||
this.table.current.onLoadData()
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
|
||||
query = {
|
||||
...query,
|
||||
pid: this.selectId
|
||||
pid: this.selectId,
|
||||
}
|
||||
|
||||
const { data } = await apiAction.page({
|
||||
@@ -157,10 +174,10 @@ export default class index extends Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用树结构数据接口
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
* 调用树结构数据接口
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
*/
|
||||
loadTreeData = async () => {
|
||||
const { data } = await apiAction.tree()
|
||||
return data
|
||||
@@ -169,7 +186,7 @@ export default class index extends Component {
|
||||
/**
|
||||
* 树节点选中事件
|
||||
* [必要]
|
||||
* @param {*} id
|
||||
* @param {*} id
|
||||
*/
|
||||
onSelectTree(id) {
|
||||
this.selectId = id
|
||||
@@ -178,15 +195,15 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
bindCodeValue(code, name) {
|
||||
name = toCamelCase(name)
|
||||
const codes = this.state.codes[name]
|
||||
if (codes) {
|
||||
const c = codes.find((p) => p.code == code)
|
||||
const c = codes.find(p => p.code == code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
@@ -196,21 +213,21 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
modal.current.open({
|
||||
pid: this.selectId,
|
||||
record
|
||||
record,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
@@ -225,13 +242,10 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(record), '删除成功')
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
@@ -242,7 +256,7 @@ export default class index extends Component {
|
||||
<QueryTreeLayout
|
||||
loadData={this.loadTreeData}
|
||||
defaultExpanded={true}
|
||||
onSelect={(key) => this.onSelectTree(key)}
|
||||
onSelect={key => this.onSelectTree(key)}
|
||||
>
|
||||
<Container mode="fluid">
|
||||
<Card bordered={false}>
|
||||
@@ -252,7 +266,7 @@ export default class index extends Component {
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
queryInitialValues={{
|
||||
type: 2
|
||||
type: 2,
|
||||
}}
|
||||
query={
|
||||
<Auth auth="sysDict:page">
|
||||
@@ -275,12 +289,14 @@ export default class index extends Component {
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>新增{name}</Button>
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
</Auth>
|
||||
}
|
||||
expandable={{
|
||||
expandedRowRender: record => <DictData type={record} />,
|
||||
rowExpandable: record => !!record.code
|
||||
rowExpandable: record => !!record.code,
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
@@ -1,23 +1,42 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Alert, Button, Card, Descriptions, Form, Popconfirm, Input, message as Message, Select, DatePicker } from 'antd'
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Form,
|
||||
Popconfirm,
|
||||
Input,
|
||||
message as Message,
|
||||
Select,
|
||||
DatePicker,
|
||||
Tag,
|
||||
} from 'antd'
|
||||
import { Auth, Container, QueryTable } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import { toCamelCase } from 'util/format'
|
||||
import { isEqual } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
import moment from 'moment'
|
||||
import ReactJson from 'react-json-view'
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
const { RangePicker } = DatePicker
|
||||
|
||||
const apiAction = {
|
||||
page: api.sysOpLogPage,
|
||||
delete: api.sysOpLogDelete
|
||||
delete: api.sysOpLogDelete,
|
||||
}
|
||||
|
||||
const methodColor = {
|
||||
POST: 'orange',
|
||||
GET: 'green',
|
||||
}
|
||||
|
||||
export default class index extends Component {
|
||||
state = {
|
||||
codes: {
|
||||
opType: []
|
||||
}
|
||||
opType: [],
|
||||
},
|
||||
}
|
||||
// 表格实例
|
||||
table = React.createRef()
|
||||
@@ -26,37 +45,54 @@ export default class index extends Component {
|
||||
{
|
||||
title: '日志名称',
|
||||
dataIndex: 'name',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '操作类型',
|
||||
dataIndex: 'opType',
|
||||
render: text => (<>{this.bindCodeValue(text, 'op_type')}</>),
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '是否成功',
|
||||
dataIndex: 'success',
|
||||
render: text => (<> {text ? '是' : '否'}</>),
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: 'ip',
|
||||
dataIndex: 'ip',
|
||||
width: 200,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '请求地址',
|
||||
dataIndex: 'url',
|
||||
width: 300,
|
||||
sorter: true,
|
||||
render: (text, record) => (
|
||||
<>
|
||||
<Tag color={methodColor[record.reqMethod.toUpperCase()]}>
|
||||
{record.reqMethod}
|
||||
</Tag>{' '}
|
||||
{text}
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '是否成功',
|
||||
dataIndex: 'success',
|
||||
width: 100,
|
||||
render: text => (
|
||||
<>
|
||||
{text ? (
|
||||
<span className="text-success">是</span>
|
||||
) : (
|
||||
<span className="text-error">否</span>
|
||||
)}
|
||||
</>
|
||||
),
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: 'ip',
|
||||
dataIndex: 'ip',
|
||||
width: 120,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '操作时间',
|
||||
dataIndex: 'opTime',
|
||||
width: 140,
|
||||
sorter: true,
|
||||
defaultSortOrder: 'descend',
|
||||
},
|
||||
{
|
||||
title: '操作人',
|
||||
width: 140,
|
||||
dataIndex: 'account',
|
||||
sorter: true,
|
||||
},
|
||||
@@ -66,9 +102,9 @@ export default class index extends Component {
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
@@ -78,29 +114,20 @@ export default class index extends Component {
|
||||
* 加载字典数据,之后开始加载表格数据
|
||||
* 如果必须要加载字典数据,可直接对表格设置autoLoad=true
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.table.current.onLoading()
|
||||
getDictData('op_type').then(res => {
|
||||
this.setState({
|
||||
codes: res
|
||||
}, () => {
|
||||
this.table.current.onLoadData()
|
||||
})
|
||||
})
|
||||
}
|
||||
componentDidMount() {}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
if (query.dates && query.dates.length) {
|
||||
query.searchBeginTime = moment(query.dates[0]).format('YYYY-MM-DD HH:mm:ss');
|
||||
query.searchEndTime = moment(query.dates[1]).format('YYYY-MM-DD HH:mm:ss');
|
||||
delete query.dates;
|
||||
query.searchBeginTime = moment(query.dates[0]).format('YYYY-MM-DD HH:mm:ss')
|
||||
query.searchEndTime = moment(query.dates[1]).format('YYYY-MM-DD HH:mm:ss')
|
||||
delete query.dates
|
||||
}
|
||||
const { data } = await apiAction.page({
|
||||
...params,
|
||||
@@ -109,16 +136,16 @@ export default class index extends Component {
|
||||
return data
|
||||
}
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
bindCodeValue(code, name) {
|
||||
name = toCamelCase(name)
|
||||
const codes = this.state.codes[name]
|
||||
if (codes) {
|
||||
const c = codes.find((p) => +p.code === code)
|
||||
const c = codes.find(p => +p.code === code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
@@ -129,8 +156,8 @@ export default class index extends Component {
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
@@ -144,27 +171,27 @@ export default class index extends Component {
|
||||
}
|
||||
|
||||
onOpLogClear() {
|
||||
this.onAction(
|
||||
apiAction.delete(),
|
||||
'清空成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(), '清空成功')
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container mode="fluid">
|
||||
<br />
|
||||
<Alert closable type="error" message={
|
||||
<>
|
||||
<div>后端bug:任何操作的操作类型都是增加</div>
|
||||
<div>没有记录请求参数.返回结果等信息</div>
|
||||
</>
|
||||
} />
|
||||
<Alert
|
||||
closable
|
||||
type="error"
|
||||
message={
|
||||
<>
|
||||
<div>后端bug:任何操作的操作类型都是增加</div>
|
||||
<div>没有记录请求参数.返回结果等信息</div>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<br />
|
||||
<Card bordered={false}>
|
||||
<QueryTable
|
||||
ref={this.table}
|
||||
autoLoad={false}
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
query={
|
||||
@@ -172,41 +199,23 @@ export default class index extends Component {
|
||||
<Form.Item label="日志名称" name="name">
|
||||
<Input autoComplete="off" placeholder="请输入日志名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="操作类型" name="opType">
|
||||
<Select placeholder="请选择操作类型">
|
||||
{
|
||||
this.state.codes.opType.map(item => {
|
||||
return <Select.Option
|
||||
key={item.code}
|
||||
value={+item.code}
|
||||
>{item.value}</Select.Option>
|
||||
})
|
||||
}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="是否成功" name="success">
|
||||
<Select placeholder="请选择是否成功" style={{ width: '170px' }}>
|
||||
<Select.Option
|
||||
key='true'
|
||||
>
|
||||
是</Select.Option>
|
||||
<Select.Option
|
||||
key='false'
|
||||
>
|
||||
否</Select.Option>
|
||||
<Select.Option key="true">是</Select.Option>
|
||||
<Select.Option key="false">否</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="操作时间" name="dates">
|
||||
<RangePicker
|
||||
showTime={
|
||||
{
|
||||
hideDisabledOptions: true,
|
||||
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')]
|
||||
}
|
||||
}
|
||||
showTime={{
|
||||
hideDisabledOptions: true,
|
||||
defaultValue: [
|
||||
moment('00:00:00', 'HH:mm:ss'),
|
||||
moment('23:59:59', 'HH:mm:ss'),
|
||||
],
|
||||
}}
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
>
|
||||
</RangePicker>
|
||||
></RangePicker>
|
||||
</Form.Item>
|
||||
</Auth>
|
||||
}
|
||||
@@ -222,8 +231,8 @@ export default class index extends Component {
|
||||
</Auth>
|
||||
}
|
||||
expandable={{
|
||||
expandedRowRender: record =>
|
||||
<Descriptions bordered size="small">
|
||||
expandedRowRender: record => (
|
||||
<Descriptions bordered size="small" labelStyle={{ width: '150px' }}>
|
||||
<Descriptions.Item span="1" label="方法名称">
|
||||
{record.methodName}
|
||||
</Descriptions.Item>
|
||||
@@ -240,20 +249,26 @@ export default class index extends Component {
|
||||
{record.className}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item span="3" label="返回结果">
|
||||
{record.result}
|
||||
<ReactJson
|
||||
src={JSON.parse(record.result || '{}')}
|
||||
collapsed
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item span="3" label="请求参数">
|
||||
{record.param}
|
||||
<ReactJson
|
||||
src={JSON.parse(record.param || '{}')}
|
||||
collapsed
|
||||
/>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item span="3" label="具体消息">
|
||||
{record.message}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
),
|
||||
}}
|
||||
|
||||
/>
|
||||
</Card>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Alert, Button, Card, Descriptions, Form, Popconfirm, Input, message as Message, Select, DatePicker } from 'antd'
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Form,
|
||||
Popconfirm,
|
||||
Input,
|
||||
message as Message,
|
||||
Select,
|
||||
DatePicker,
|
||||
} from 'antd'
|
||||
import { Auth, Container, QueryTable } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import { toCamelCase } from 'util/format'
|
||||
@@ -7,17 +18,17 @@ import { isEqual } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
import moment from 'moment'
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
const { RangePicker } = DatePicker
|
||||
|
||||
const apiAction = {
|
||||
page: api.sysVisLogPage,
|
||||
delete: api.sysVisLogDelete
|
||||
delete: api.sysVisLogDelete,
|
||||
}
|
||||
export default class index extends Component {
|
||||
state = {
|
||||
codes: {
|
||||
visType: []
|
||||
}
|
||||
visType: [],
|
||||
},
|
||||
}
|
||||
// 表格实例
|
||||
table = React.createRef()
|
||||
@@ -26,38 +37,54 @@ export default class index extends Component {
|
||||
{
|
||||
title: '日志名称',
|
||||
dataIndex: 'name',
|
||||
width: 200,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '访问类型',
|
||||
dataIndex: 'visType',
|
||||
render: text => (<>{this.bindCodeValue(text, 'vis_type')}</>),
|
||||
width: 120,
|
||||
render: text => <>{this.bindCodeValue(text, 'vis_type')}</>,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '是否成功',
|
||||
dataIndex: 'success',
|
||||
render: text => (<> {text ? '是' : '否'}</>),
|
||||
width: 120,
|
||||
render: text => (
|
||||
<>
|
||||
{text ? (
|
||||
<span className="text-success">是</span>
|
||||
) : (
|
||||
<span className="text-error">否</span>
|
||||
)}
|
||||
</>
|
||||
),
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: 'ip',
|
||||
dataIndex: 'ip',
|
||||
width: 180,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '浏览器',
|
||||
dataIndex: 'browser',
|
||||
width: 180,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '访问时间',
|
||||
dataIndex: 'visTime',
|
||||
width: 180,
|
||||
sorter: true,
|
||||
defaultSortOrder: 'descend',
|
||||
},
|
||||
{
|
||||
title: '访问人',
|
||||
dataIndex: 'account',
|
||||
width: 180,
|
||||
sorter: true,
|
||||
},
|
||||
]
|
||||
@@ -66,9 +93,9 @@ export default class index extends Component {
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
@@ -81,26 +108,29 @@ export default class index extends Component {
|
||||
componentDidMount() {
|
||||
this.table.current.onLoading()
|
||||
getDictData('vis_type').then(res => {
|
||||
this.setState({
|
||||
codes: res
|
||||
}, () => {
|
||||
this.table.current.onLoadData()
|
||||
})
|
||||
this.setState(
|
||||
{
|
||||
codes: res,
|
||||
},
|
||||
() => {
|
||||
this.table.current.onLoadData()
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
if (query.dates && query.dates.length) {
|
||||
query.searchBeginTime = moment(query.dates[0]).format('YYYY-MM-DD HH:mm:ss');
|
||||
query.searchEndTime = moment(query.dates[1]).format('YYYY-MM-DD HH:mm:ss');
|
||||
delete query.dates;
|
||||
query.searchBeginTime = moment(query.dates[0]).format('YYYY-MM-DD HH:mm:ss')
|
||||
query.searchEndTime = moment(query.dates[1]).format('YYYY-MM-DD HH:mm:ss')
|
||||
delete query.dates
|
||||
}
|
||||
const { data } = await apiAction.page({
|
||||
...params,
|
||||
@@ -109,16 +139,16 @@ export default class index extends Component {
|
||||
return data
|
||||
}
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
bindCodeValue(code, name) {
|
||||
name = toCamelCase(name)
|
||||
const codes = this.state.codes[name]
|
||||
if (codes) {
|
||||
const c = codes.find((p) => +p.code === code)
|
||||
const c = codes.find(p => +p.code === code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
@@ -129,8 +159,8 @@ export default class index extends Component {
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
@@ -144,17 +174,18 @@ export default class index extends Component {
|
||||
}
|
||||
|
||||
onVisLogClear() {
|
||||
this.onAction(
|
||||
apiAction.delete(),
|
||||
'清空成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(), '清空成功')
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container mode="fluid">
|
||||
<br />
|
||||
<Alert closable type="error" message="页面刷新的时候也会有保存登录日志,但是没有ip显示" />
|
||||
<Alert
|
||||
closable
|
||||
type="error"
|
||||
message="页面刷新的时候也会有保存登录日志,但是没有ip显示"
|
||||
/>
|
||||
<br />
|
||||
<Card bordered={false}>
|
||||
<QueryTable
|
||||
@@ -168,43 +199,37 @@ export default class index extends Component {
|
||||
<Input autoComplete="off" placeholder="请输入日志名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="访问类型" name="visType">
|
||||
<Select placeholder="请选择访问类型"
|
||||
<Select
|
||||
placeholder="请选择访问类型"
|
||||
allow-clear
|
||||
style={{ width: '170px' }}
|
||||
>
|
||||
{
|
||||
this.state.codes.visType.map(item => {
|
||||
return <Select.Option
|
||||
key={item.code}
|
||||
value={+item.code}
|
||||
>{item.value}</Select.Option>
|
||||
})
|
||||
}
|
||||
{this.state.codes.visType.map(item => {
|
||||
return (
|
||||
<Select.Option key={item.code} value={+item.code}>
|
||||
{item.value}
|
||||
</Select.Option>
|
||||
)
|
||||
})}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="是否成功" name="success">
|
||||
<Select placeholder="请选择是否成功" style={{ width: '170px' }}>
|
||||
<Select.Option
|
||||
key='true'
|
||||
>
|
||||
是</Select.Option>
|
||||
<Select.Option
|
||||
key='false'
|
||||
>
|
||||
否</Select.Option>
|
||||
<Select.Option key="true">是</Select.Option>
|
||||
<Select.Option key="false">否</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="访问时间" name="dates">
|
||||
<RangePicker
|
||||
showTime={
|
||||
{
|
||||
hideDisabledOptions: true,
|
||||
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')]
|
||||
}
|
||||
}
|
||||
showTime={{
|
||||
hideDisabledOptions: true,
|
||||
defaultValue: [
|
||||
moment('00:00:00', 'HH:mm:ss'),
|
||||
moment('23:59:59', 'HH:mm:ss'),
|
||||
],
|
||||
}}
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
>
|
||||
</RangePicker>
|
||||
></RangePicker>
|
||||
</Form.Item>
|
||||
</Auth>
|
||||
}
|
||||
@@ -220,16 +245,22 @@ export default class index extends Component {
|
||||
</Auth>
|
||||
}
|
||||
expandable={{
|
||||
expandedRowRender: record =>
|
||||
<Descriptions bordered size="small">
|
||||
<Descriptions.Item span="3" label="具体消息">
|
||||
expandedRowRender: record => (
|
||||
<Descriptions
|
||||
bordered
|
||||
size="small"
|
||||
columns={1}
|
||||
labelStyle={{ width: '150px' }}
|
||||
>
|
||||
<Descriptions.Item label="具体消息">
|
||||
{record.message}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
33
web-react/src/pages/system/machine/base.jsx
Normal file
33
web-react/src/pages/system/machine/base.jsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Card, Col, Descriptions } from 'antd'
|
||||
|
||||
export default class base extends Component {
|
||||
render() {
|
||||
const { base } = this.props
|
||||
|
||||
const { hostName, systemOs, wanIp, lanIp, osArchitecture, frameworkDescription } = base
|
||||
|
||||
return (
|
||||
<>
|
||||
<Col span={24}>
|
||||
<Card bordered={false}>
|
||||
<Descriptions
|
||||
column={2}
|
||||
labelStyle={{ fontSize: '14px', color: 'rgba(0,0,0,.45)' }}
|
||||
contentStyle={{ fontSize: '14px' }}
|
||||
>
|
||||
<Descriptions.Item label="主机名称">{hostName}</Descriptions.Item>
|
||||
<Descriptions.Item label="操作系统">{systemOs}</Descriptions.Item>
|
||||
<Descriptions.Item label="外网信息">{wanIp}</Descriptions.Item>
|
||||
<Descriptions.Item label="内网IP">{lanIp}</Descriptions.Item>
|
||||
<Descriptions.Item label="系统架构">{osArchitecture}</Descriptions.Item>
|
||||
<Descriptions.Item label="运行框架">
|
||||
{frameworkDescription}
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</Card>
|
||||
</Col>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
107
web-react/src/pages/system/machine/disk-charts.jsx
Normal file
107
web-react/src/pages/system/machine/disk-charts.jsx
Normal file
@@ -0,0 +1,107 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Card, Col, Row } from 'antd'
|
||||
import * as echarts from 'echarts'
|
||||
|
||||
export default class diskCharts extends Component {
|
||||
diskInfo = []
|
||||
|
||||
diskChart1 = []
|
||||
diskChart2 = []
|
||||
diskChart3 = []
|
||||
diskChart4 = []
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
const { base } = props
|
||||
|
||||
this.diskInfo = base.diskInfo
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.diskInfo.forEach(({ size, freeSpace }, i) => {
|
||||
const dom = this.refs[`disk-chart-${i}`]
|
||||
this[`diskChart${i}`] = echarts.init(dom)
|
||||
|
||||
const usedSpace = size - freeSpace
|
||||
const sizeGB = (size / 1024 / 1024 / 1024).toFixed(1)
|
||||
const usedGB = (usedSpace / 1024 / 1024 / 1024).toFixed(1)
|
||||
const freeGB = (freeSpace / 1024 / 1024 / 1024).toFixed(1)
|
||||
|
||||
const option = {
|
||||
tooltip: false,
|
||||
series: [
|
||||
{
|
||||
name: '磁盘使用量',
|
||||
type: 'pie',
|
||||
radius: ['70%', '100%'],
|
||||
label: {
|
||||
show: true,
|
||||
fontSize: '14',
|
||||
position: 'center',
|
||||
formatter: `共 ${sizeGB} GB`,
|
||||
},
|
||||
emphasis: {
|
||||
label: {
|
||||
show: true,
|
||||
fontSize: '14',
|
||||
formatter: '{b}{c}GB({d}%)',
|
||||
},
|
||||
},
|
||||
labelLine: {
|
||||
show: false,
|
||||
},
|
||||
data: [
|
||||
{
|
||||
value: usedGB,
|
||||
name: '已用',
|
||||
itemStyle: {
|
||||
color: usedGB / sizeGB >= 0.85 ? '#ff4d4f' : '#007bff',
|
||||
},
|
||||
},
|
||||
{
|
||||
value: freeGB,
|
||||
name: '可用',
|
||||
itemStyle: { color: '#e0e0e0' },
|
||||
},
|
||||
],
|
||||
hoverAnimation: false,
|
||||
animation: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
this[`diskChart${i}`].setOption(option)
|
||||
})
|
||||
|
||||
window.addEventListener('resize', this.onResizeCharts)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
window.removeEventListener('resize', this.onResizeCharts)
|
||||
}
|
||||
|
||||
onResizeCharts = () => {
|
||||
this.diskInfo.forEach((item, i) => {
|
||||
this[`diskChart${i}`].resize()
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
const { diskInfo } = this
|
||||
|
||||
return (
|
||||
<>
|
||||
{diskInfo.map((item, i) => (
|
||||
<Col key={i} xl={6} lg={12}>
|
||||
<Card bordered={false}>
|
||||
<div className="h4 mb-md">
|
||||
{item.description}({item.name})
|
||||
</div>
|
||||
<div className="h-200" ref={`disk-chart-${i}`}></div>
|
||||
</Card>
|
||||
</Col>
|
||||
))}
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
44
web-react/src/pages/system/machine/index.jsx
Normal file
44
web-react/src/pages/system/machine/index.jsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Card, Col, Descriptions, Row, Statistic } from 'antd'
|
||||
import { api } from 'common/api'
|
||||
import { Container } from 'components'
|
||||
import { isEqual } from 'lodash'
|
||||
import moment from 'moment'
|
||||
|
||||
import Base from './base'
|
||||
import UseCharts from './use-charts'
|
||||
import DiskCharts from './disk-charts'
|
||||
|
||||
export default class index extends Component {
|
||||
state = {
|
||||
loading: true,
|
||||
base: {},
|
||||
network: {},
|
||||
}
|
||||
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state) || this.props.paneActived !== props.paneActived
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
const { data: base } = await api.sysMachineBase()
|
||||
this.setState({ loading: false, base })
|
||||
}
|
||||
|
||||
render() {
|
||||
const { paneActived } = this.props
|
||||
|
||||
const { loading } = this.state
|
||||
|
||||
return (
|
||||
<Container mode="fluid">
|
||||
<br />
|
||||
<Row gutter={16}>
|
||||
{!loading && <Base {...this.state} />}
|
||||
{!loading && <UseCharts {...this.state} actived={paneActived} />}
|
||||
{!loading && <DiskCharts {...this.state} />}
|
||||
</Row>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
297
web-react/src/pages/system/machine/use-charts.jsx
Normal file
297
web-react/src/pages/system/machine/use-charts.jsx
Normal file
@@ -0,0 +1,297 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Card, Col, Descriptions, Row, Statistic } from 'antd'
|
||||
import * as echarts from 'echarts'
|
||||
import moment from 'moment'
|
||||
import { api } from 'common/api'
|
||||
|
||||
export default class useCharts extends Component {
|
||||
state = {
|
||||
use: {},
|
||||
|
||||
nowMoment: moment(),
|
||||
}
|
||||
|
||||
timer = null
|
||||
timerMoment = null
|
||||
|
||||
systemStart = moment()
|
||||
|
||||
now = Date.now()
|
||||
|
||||
cpuChart = null
|
||||
cpuData = []
|
||||
|
||||
ramChart = null
|
||||
ramData = []
|
||||
|
||||
shouldComponentUpdate(props) {
|
||||
// 当前页签未选中时停止获取状态
|
||||
if (this.props.actived !== props.actived) {
|
||||
if (props.actived) {
|
||||
this.start()
|
||||
} else {
|
||||
this.stop()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.systemStart = moment().add(-this.props.base.runTime)
|
||||
this.initCpuChart()
|
||||
this.initRamChart()
|
||||
|
||||
this.start()
|
||||
|
||||
window.addEventListener('resize', this.onResizeCharts)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.stop()
|
||||
|
||||
window.removeEventListener('resize', this.onResizeCharts)
|
||||
}
|
||||
|
||||
start() {
|
||||
this.timer = setInterval(() => {
|
||||
this.refreshData()
|
||||
}, 3000)
|
||||
this.refreshData()
|
||||
this.timerMoment = setInterval(() => {
|
||||
this.setState({ nowMoment: moment() })
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
stop() {
|
||||
clearInterval(this.timer)
|
||||
clearInterval(this.timerMoment)
|
||||
}
|
||||
|
||||
async refreshData() {
|
||||
const { data: use } = await api.sysMachineUse()
|
||||
|
||||
this.now = Date.now()
|
||||
|
||||
this.cpuData.shift()
|
||||
this.cpuData.push({
|
||||
name: this.now,
|
||||
value: [this.now, use.cpuRate],
|
||||
})
|
||||
this.cpuChart.setOption({
|
||||
series: [{ data: this.cpuData }],
|
||||
})
|
||||
|
||||
this.ramData.shift()
|
||||
this.ramData.push({
|
||||
name: this.now,
|
||||
value: [this.now, use.ramRate],
|
||||
})
|
||||
this.ramChart.setOption({
|
||||
series: [{ data: this.ramData }],
|
||||
})
|
||||
|
||||
this.setState({ use })
|
||||
}
|
||||
|
||||
initCpuChart() {
|
||||
for (let i = 0; i < 60; i++) {
|
||||
const past = this.now - (60 - i) * 1000
|
||||
this.cpuData.push({
|
||||
name: past,
|
||||
value: [past, -1],
|
||||
})
|
||||
}
|
||||
|
||||
const dom = this.refs['cpu-chart']
|
||||
this.cpuChart = echarts.init(dom)
|
||||
const option = {
|
||||
grid: {
|
||||
show: true,
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
borderColor: 'rgba(0, 123, 255, 1)',
|
||||
borderWidth: 2,
|
||||
zlevel: 2,
|
||||
},
|
||||
tooltip: false,
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
axisTick: {
|
||||
show: false,
|
||||
},
|
||||
axisLabel: {
|
||||
show: false,
|
||||
},
|
||||
axisLine: {
|
||||
show: false,
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
max: 100,
|
||||
min: 0,
|
||||
axisLabel: {
|
||||
show: false,
|
||||
},
|
||||
},
|
||||
series: [
|
||||
{
|
||||
type: 'line',
|
||||
showSymbol: false,
|
||||
hoverAnimation: false,
|
||||
animation: false,
|
||||
data: this.cpuData,
|
||||
lineStyle: {
|
||||
width: 1,
|
||||
color: 'rgba(0, 123, 255, .8)',
|
||||
},
|
||||
areaStyle: {
|
||||
color: 'rgba(0, 123, 255, .3)',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
this.cpuChart.setOption(option)
|
||||
}
|
||||
|
||||
initRamChart() {
|
||||
for (let i = 0; i < 60; i++) {
|
||||
const past = this.now - (60 - i) * 1000
|
||||
this.ramData.push({
|
||||
name: past,
|
||||
value: [past, -1],
|
||||
})
|
||||
}
|
||||
|
||||
const dom = this.refs['ram-chart']
|
||||
this.ramChart = echarts.init(dom)
|
||||
const option = {
|
||||
grid: {
|
||||
show: true,
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
borderColor: 'rgba(83, 29, 171, 1)',
|
||||
borderWidth: 2,
|
||||
zlevel: 2,
|
||||
},
|
||||
tooltip: false,
|
||||
xAxis: {
|
||||
type: 'time',
|
||||
axisTick: {
|
||||
show: false,
|
||||
},
|
||||
axisLabel: {
|
||||
show: false,
|
||||
},
|
||||
axisLine: {
|
||||
show: false,
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
max: 100,
|
||||
min: 0,
|
||||
axisLabel: {
|
||||
show: false,
|
||||
},
|
||||
},
|
||||
series: [
|
||||
{
|
||||
type: 'line',
|
||||
showSymbol: false,
|
||||
hoverAnimation: false,
|
||||
animation: false,
|
||||
data: this.ramData,
|
||||
lineStyle: {
|
||||
width: 1,
|
||||
color: 'rgba(83, 29, 171, .8)',
|
||||
},
|
||||
areaStyle: {
|
||||
color: 'rgba(83, 29, 171, .3)',
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
this.ramChart.setOption(option)
|
||||
}
|
||||
|
||||
onResizeCharts = () => {
|
||||
this.cpuChart.resize()
|
||||
this.ramChart.resize()
|
||||
}
|
||||
|
||||
render() {
|
||||
const { base } = this.props
|
||||
const { use, nowMoment } = this.state
|
||||
const { cpuName, cpuBaseSpeed, processorCount, totalRam } = base
|
||||
const { cpuRate, ramRate } = use
|
||||
|
||||
const diffDays = nowMoment.diff(this.systemStart, 'days')
|
||||
const diff =
|
||||
diffDays + ':' + moment(nowMoment.diff(this.systemStart)).utc().format('HH:mm:ss')
|
||||
|
||||
return (
|
||||
<>
|
||||
<Col xl={12} lg={24}>
|
||||
<Card bordered={false}>
|
||||
<Row align="bottom" justify="space-between">
|
||||
<div className="h2">CPU</div>
|
||||
<div className="h5">{cpuName}</div>
|
||||
</Row>
|
||||
<div className="h-200 mt-md mb-md" ref="cpu-chart"></div>
|
||||
<Row>
|
||||
<Col flex="1">
|
||||
<Statistic title="使用率" value={(cpuRate || 0) + ' %'} />
|
||||
<Statistic title="正常运行时间" value={diff} />
|
||||
</Col>
|
||||
<Col flex="1">
|
||||
<Descriptions column={1}>
|
||||
<Descriptions.Item label="基准速度">
|
||||
<b>{((cpuBaseSpeed || 0) / 1000).toFixed(2)} GHz</b>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="逻辑处理器">
|
||||
<b>{processorCount || 0}</b>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xl={12} lg={24}>
|
||||
<Card bordered={false}>
|
||||
<Row align="bottom" justify="space-between">
|
||||
<div className="h2">内存</div>
|
||||
<div className="h5">{((totalRam || 0) / 1024).toFixed(1)} GB</div>
|
||||
</Row>
|
||||
<div className="h-200 mt-md mb-md" ref="ram-chart"></div>
|
||||
<Row>
|
||||
<Col flex="1">
|
||||
<Statistic
|
||||
title="使用中"
|
||||
value={
|
||||
(((totalRam || 0) / 1024) * ((ramRate || 1) / 100)).toFixed(
|
||||
1
|
||||
) + ' GB'
|
||||
}
|
||||
/>
|
||||
<Statistic
|
||||
title="可用"
|
||||
value={
|
||||
(
|
||||
((totalRam || 0) / 1024) *
|
||||
(1 - (ramRate || 1) / 100)
|
||||
).toFixed(1) + ' GB'
|
||||
}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
</Col>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -7,29 +7,31 @@ import { api } from 'common/api'
|
||||
import { EMPTY_ID } from 'util/global'
|
||||
|
||||
const initialValues = {
|
||||
type: '1',
|
||||
openType: '1',
|
||||
type: 1,
|
||||
openType: 1,
|
||||
weight: '2',
|
||||
visible: true,
|
||||
sort: 100
|
||||
sort: 100,
|
||||
}
|
||||
|
||||
export default class form extends Component {
|
||||
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
codes: {
|
||||
menuType: [],
|
||||
openType: []
|
||||
openType: [],
|
||||
menuWeight: [],
|
||||
},
|
||||
options: {
|
||||
appList: [],
|
||||
parentTreeData: []
|
||||
parentTreeData: [],
|
||||
},
|
||||
|
||||
addType: [],
|
||||
type: initialValues.type,
|
||||
openType: initialValues.openType,
|
||||
icon: ''
|
||||
icon: '',
|
||||
}
|
||||
|
||||
// 表单实例
|
||||
@@ -51,45 +53,49 @@ export default class form extends Component {
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
const form = this.form.current
|
||||
this.record = cloneDeep(params.record)
|
||||
//#region 从后端转换成前段所需格式
|
||||
const { menuType, openType } = await getDictData('menu_type', 'open_type')
|
||||
const codes = await getDictData('menu_type', 'open_type', 'menu_weight')
|
||||
const appList = await this.onLoadSysApplist()
|
||||
let parentTreeData = []
|
||||
if (params.isParent) {
|
||||
parentTreeData = await this.onLoadMenuTree(params.parent.application)
|
||||
} else if (params.record) {
|
||||
}
|
||||
|
||||
if (params.record) {
|
||||
parentTreeData = await this.onLoadMenuTree(params.record.application)
|
||||
} else {
|
||||
this.setState({ addType: params.addType })
|
||||
if (params.addType.length) {
|
||||
form.setFieldsValue({
|
||||
type: params.addType[0],
|
||||
})
|
||||
}
|
||||
}
|
||||
const icon = params.record && params.record.icon
|
||||
this.setState({
|
||||
codes: {
|
||||
menuType,
|
||||
openType
|
||||
},
|
||||
codes,
|
||||
options: {
|
||||
appList,
|
||||
parentTreeData
|
||||
parentTreeData,
|
||||
},
|
||||
icon
|
||||
icon,
|
||||
})
|
||||
//#endregion
|
||||
const form = this.form.current
|
||||
if (params.isParent) {
|
||||
form.setFieldsValue({
|
||||
pid: params.parent.id,
|
||||
application: params.parent.application
|
||||
application: params.parent.application,
|
||||
})
|
||||
} else {
|
||||
form.setFieldsValue(this.record)
|
||||
}
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
})
|
||||
this.setState({ loading: false })
|
||||
|
||||
this.onTypeChange()
|
||||
}
|
||||
@@ -98,7 +104,7 @@ export default class form extends Component {
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
@@ -123,30 +129,31 @@ export default class form extends Component {
|
||||
|
||||
async onLoadMenuTree(application) {
|
||||
const { data } = await api.getMenuTree({ application })
|
||||
return [{
|
||||
id: EMPTY_ID,
|
||||
parentId: undefined,
|
||||
title: '顶级',
|
||||
value: EMPTY_ID,
|
||||
pid: undefined,
|
||||
children: data,
|
||||
}]
|
||||
return [
|
||||
{
|
||||
id: EMPTY_ID,
|
||||
parentId: undefined,
|
||||
title: '顶级',
|
||||
value: EMPTY_ID,
|
||||
pid: undefined,
|
||||
children: data,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
onTypeChange() {
|
||||
this.onTypeChangeGroup()
|
||||
const form = this.form.current
|
||||
const { type } = form.getFieldsValue()
|
||||
if (['0', '2'].includes(type)) {
|
||||
form.setFieldsValue({
|
||||
openType: '0'
|
||||
})
|
||||
} else {
|
||||
form.setFieldsValue({
|
||||
openType: '1'
|
||||
})
|
||||
}
|
||||
// const form = this.form.current
|
||||
// const { type } = form.getFieldsValue()
|
||||
// if ([0, 2].includes(type)) {
|
||||
// form.setFieldsValue({
|
||||
// openType: 0,
|
||||
// })
|
||||
// } else {
|
||||
// form.setFieldsValue({
|
||||
// openType: 1,
|
||||
// })
|
||||
// }
|
||||
}
|
||||
|
||||
onOpenTypeChange() {
|
||||
@@ -168,178 +175,221 @@ export default class form extends Component {
|
||||
|
||||
this.setState({
|
||||
type,
|
||||
openType
|
||||
openType,
|
||||
})
|
||||
}
|
||||
|
||||
async onApplicationChange(value) {
|
||||
this.setState({
|
||||
loading: true
|
||||
loading: true,
|
||||
})
|
||||
const parentTreeData = await this.onLoadMenuTree(value)
|
||||
this.setState({
|
||||
loading: false,
|
||||
options: {
|
||||
...this.state.options,
|
||||
parentTreeData
|
||||
}
|
||||
parentTreeData,
|
||||
},
|
||||
})
|
||||
this.form.current.setFieldsValue({
|
||||
pid: undefined
|
||||
pid: undefined,
|
||||
})
|
||||
}
|
||||
|
||||
onSelectIcon(icon) {
|
||||
this.form.current.setFieldsValue({
|
||||
icon
|
||||
icon,
|
||||
})
|
||||
this.setState({ icon })
|
||||
}
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
const { loading, codes, options, addType, type, openType, icon } = this.state
|
||||
|
||||
return (
|
||||
<Form
|
||||
initialValues={initialValues}
|
||||
ref={this.form}
|
||||
className="yo-form"
|
||||
>
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<Form initialValues={initialValues} ref={this.form} className="yo-form">
|
||||
<Spin spinning={loading} indicator={<AntIcon type="loading" />}>
|
||||
<div className="yo-form-group">
|
||||
<h3 className="h3">基本信息</h3>
|
||||
<div className="yo-form-group">
|
||||
<Form.Item
|
||||
label="菜单类型"
|
||||
name="type"
|
||||
help={
|
||||
tooltip={
|
||||
<>
|
||||
目录:默认添加在顶级
|
||||
<br />菜单:
|
||||
<br />按钮:
|
||||
目录:一级菜单,默认添加在顶级
|
||||
<br />
|
||||
菜单:二级菜单
|
||||
<br />
|
||||
按钮:菜单中对应到接口的功能
|
||||
</>
|
||||
}
|
||||
rules={[{ required: true, message: '请选择菜单类型' }]}
|
||||
>
|
||||
<Radio.Group onChange={(e) => this.onTypeChange(e)}>
|
||||
{
|
||||
this.state.codes.menuType.map(item => {
|
||||
return (
|
||||
<Radio.Button
|
||||
key={item.code}
|
||||
value={item.code}
|
||||
>{item.value}</Radio.Button>
|
||||
)
|
||||
})
|
||||
}
|
||||
<Radio.Group onChange={e => this.onTypeChange(e)}>
|
||||
{codes.menuType.map(item => {
|
||||
return (
|
||||
<Radio.Button
|
||||
key={item.code}
|
||||
value={+item.code}
|
||||
disabled={!addType.includes(+item.code)}
|
||||
>
|
||||
{item.value}
|
||||
</Radio.Button>
|
||||
)
|
||||
})}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label="名称" name="name" rules={[{ required: true, message: '请输入名称' }]}>
|
||||
<Form.Item
|
||||
label="名称"
|
||||
name="name"
|
||||
rules={[{ required: true, message: '请输入名称' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入名称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="唯一编码" name="code">
|
||||
<Input autoComplete="off" placeholder="请输入唯一编码" />
|
||||
</Form.Item>
|
||||
<Form.Item label="所属应用" name="application" rules={[{ required: true, message: '请选择所属应用' }]}>
|
||||
<Select placeholder="请选择所属应用" onChange={(value) => this.onApplicationChange(value)}>
|
||||
{
|
||||
this.state.options.appList.map(item => {
|
||||
return (
|
||||
<Select.Option
|
||||
key={item.code}
|
||||
value={item.code}
|
||||
>{item.name}</Select.Option>
|
||||
)
|
||||
})
|
||||
}
|
||||
<Form.Item
|
||||
label="所属应用"
|
||||
name="application"
|
||||
rules={[{ required: true, message: '请选择所属应用' }]}
|
||||
>
|
||||
<Select
|
||||
placeholder="请选择所属应用"
|
||||
onChange={value => this.onApplicationChange(value)}
|
||||
>
|
||||
{options.appList.map(item => {
|
||||
return (
|
||||
<Select.Option key={item.code} value={item.code}>
|
||||
{item.name}
|
||||
</Select.Option>
|
||||
)
|
||||
})}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
{
|
||||
this.state.type != 0 &&
|
||||
<Form.Item label="父级菜单" name="pid" rules={[{ required: true, message: '请选择父级' }]}>
|
||||
{type != 0 && (
|
||||
<Form.Item
|
||||
label="父级菜单"
|
||||
name="pid"
|
||||
rules={[{ required: true, message: '请选择父级' }]}
|
||||
>
|
||||
<TreeSelect
|
||||
dropdownStyle={{ maxHeight: '300px', overflow: 'auto' }}
|
||||
treeData={this.state.options.parentTreeData}
|
||||
treeData={options.parentTreeData}
|
||||
placeholder="请选择父级菜单"
|
||||
/>
|
||||
</Form.Item>
|
||||
}
|
||||
)}
|
||||
<Form.Item
|
||||
label="权重"
|
||||
name="weight"
|
||||
tooltip={
|
||||
<>
|
||||
系统权重:菜单/功能任何角色可用
|
||||
<br />
|
||||
业务权重:菜单/功能为超级管理员不可用,可防止管理员误操作
|
||||
</>
|
||||
}
|
||||
rules={[{ required: true, message: '请选择权重' }]}
|
||||
>
|
||||
<Radio.Group>
|
||||
{codes.menuWeight.map(item => {
|
||||
return (
|
||||
<Radio.Button key={item.code} value={item.code}>
|
||||
{item.value}
|
||||
</Radio.Button>
|
||||
)
|
||||
})}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
</div>
|
||||
<h3 className="h3">扩展信息</h3>
|
||||
<div className="yo-form-group">
|
||||
{
|
||||
this.state.type == 1 &&
|
||||
{type == 1 && (
|
||||
<Form.Item label="打开方式" name="openType">
|
||||
<Radio.Group onChange={(e) => this.onOpenTypeChange(e)}>
|
||||
{
|
||||
this.state.codes.openType.map(item => {
|
||||
return (
|
||||
<Radio.Button
|
||||
key={item.code}
|
||||
value={item.code}
|
||||
>{item.value}</Radio.Button>
|
||||
)
|
||||
})
|
||||
}
|
||||
<Radio.Group onChange={e => this.onOpenTypeChange(e)}>
|
||||
{codes.openType.map(item => {
|
||||
return (
|
||||
<Radio.Button key={item.code} value={+item.code}>
|
||||
{item.value}
|
||||
</Radio.Button>
|
||||
)
|
||||
})}
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
}
|
||||
{
|
||||
this.state.type == 1 && this.state.openType == 1 &&
|
||||
<Form.Item label="前端组件" name="component" rules={[{ required: true, message: '请输入前端组件' }]}>
|
||||
)}
|
||||
{type == 1 && openType == 1 && (
|
||||
<Form.Item
|
||||
label="前端组件"
|
||||
name="component"
|
||||
tooltip="打开新页签并渲染前端组件"
|
||||
rules={[{ required: true, message: '请输入前端组件' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入前端组件" />
|
||||
</Form.Item>
|
||||
}
|
||||
{
|
||||
this.state.type == 1 && this.state.openType == 2 &&
|
||||
<Form.Item label="内链地址" name="router" rules={[{ required: true, message: '请输入内链地址' }]}>
|
||||
)}
|
||||
{type == 1 && openType == 2 && (
|
||||
<Form.Item
|
||||
label="内链地址"
|
||||
name="link"
|
||||
tooltip="打开新页签并使用iframe加载页面"
|
||||
rules={[{ required: true, message: '请输入内链地址' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入内链地址" />
|
||||
</Form.Item>
|
||||
}
|
||||
{
|
||||
this.state.type == 1 && this.state.openType == 3 &&
|
||||
<Form.Item label="外链地址" name="link" rules={[{ required: true, message: '请输入外链地址' }]}>
|
||||
)}
|
||||
{type == 1 && openType == 3 && (
|
||||
<Form.Item
|
||||
label="外链地址"
|
||||
name="redirect"
|
||||
tooltip="打开新的浏览器窗口"
|
||||
rules={[{ required: true, message: '请输入外链地址' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入外链地址" />
|
||||
</Form.Item>
|
||||
}
|
||||
{
|
||||
this.state.type == 2 &&
|
||||
<Form.Item label="权限标识" name="permission" rules={[{ required: true, message: '请输入权限标识' }]}>
|
||||
)}
|
||||
{type == 2 && (
|
||||
<Form.Item
|
||||
label="权限标识"
|
||||
name="permission"
|
||||
rules={[{ required: true, message: '请输入权限标识' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入权限标识" />
|
||||
</Form.Item>
|
||||
}
|
||||
{
|
||||
this.state.type == 2 &&
|
||||
<Form.Item label="关联上级菜单显示" name="visibleParent" valuePropName="checked">
|
||||
)}
|
||||
{type == 2 && (
|
||||
<Form.Item
|
||||
label="关联上级菜单显示"
|
||||
name="visibleParent"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
}
|
||||
)}
|
||||
<Form.Item label="可见性" name="visible" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
{
|
||||
this.state.type != 2 &&
|
||||
{type != 2 && (
|
||||
<Form.Item label="图标" name="icon">
|
||||
<Input
|
||||
disabled
|
||||
placeholder="请选择图标"
|
||||
addonBefore={
|
||||
this.state.icon &&
|
||||
<AntIcon type={this.state.icon} />
|
||||
}
|
||||
addonBefore={icon && <AntIcon type={icon} />}
|
||||
addonAfter={
|
||||
<AntIcon
|
||||
type="setting"
|
||||
onClick={() =>
|
||||
this
|
||||
.iconSelector
|
||||
.current
|
||||
.open(this.form.current.getFieldValue('icon'))
|
||||
this.iconSelector.current.open(
|
||||
this.form.current.getFieldValue('icon')
|
||||
)
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</Form.Item>
|
||||
}
|
||||
)}
|
||||
<Form.Item label="排序" name="sort">
|
||||
<InputNumber
|
||||
max={1000}
|
||||
@@ -355,7 +405,7 @@ export default class form extends Component {
|
||||
</div>
|
||||
</Spin>
|
||||
|
||||
<IconSelector ref={this.iconSelector} onSelect={(icon) => this.onSelectIcon(icon)} />
|
||||
<IconSelector ref={this.iconSelector} onSelect={icon => this.onSelectIcon(icon)} />
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Table, Card, Form, Input, Popconfirm, message as Message, Tag } from 'antd'
|
||||
import { Button, Table, Card, Popconfirm, message as Message, Row, Col, Tooltip, Tag } from 'antd'
|
||||
import { isEqual } from 'lodash'
|
||||
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions } from 'components'
|
||||
import { api } from 'common/api'
|
||||
@@ -24,6 +24,7 @@ export default class index extends Component {
|
||||
codes: {
|
||||
menuType: [],
|
||||
menuWeight: [],
|
||||
openType: [],
|
||||
},
|
||||
}
|
||||
|
||||
@@ -55,16 +56,36 @@ export default class index extends Component {
|
||||
render: text => text && <AntIcon type={text} />,
|
||||
},
|
||||
{
|
||||
title: '前端组件',
|
||||
title: '连接',
|
||||
width: 220,
|
||||
dataIndex: 'component',
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '权限标识',
|
||||
width: 220,
|
||||
dataIndex: 'permission',
|
||||
ellipsis: true,
|
||||
dataIndex: 'openType',
|
||||
render: (text, record) => {
|
||||
switch (text) {
|
||||
case 1:
|
||||
return (
|
||||
<>
|
||||
<Tag color="green">{this.bindCodeValue(text, 'open_type')}</Tag>{' '}
|
||||
{record.component}
|
||||
</>
|
||||
)
|
||||
case 2:
|
||||
return (
|
||||
<>
|
||||
<Tag color="orange">{this.bindCodeValue(text, 'open_type')}</Tag>{' '}
|
||||
{record.link}
|
||||
</>
|
||||
)
|
||||
case 3:
|
||||
return (
|
||||
<>
|
||||
<Tag color="red">{this.bindCodeValue(text, 'open_type')}</Tag>{' '}
|
||||
{record.redirect}
|
||||
</>
|
||||
)
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
@@ -85,19 +106,14 @@ export default class index extends Component {
|
||||
if (flag) {
|
||||
this.columns.push({
|
||||
title: '操作',
|
||||
width: 150,
|
||||
width: 220,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (
|
||||
<QueryTableActions>
|
||||
{record.type < 2 && (
|
||||
<Auth auth="sysMenu:add">
|
||||
<a onClick={() => this.onOpen(this.addForm, record, true)}>
|
||||
新增子菜单
|
||||
</a>
|
||||
</Auth>
|
||||
)}
|
||||
<Auth auth="sysMenu:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
<a onClick={() => this.onOpen({ modal: this.editForm, record })}>
|
||||
编辑
|
||||
</a>
|
||||
</Auth>
|
||||
<Auth auth="sysMenu:delete">
|
||||
<Popconfirm
|
||||
@@ -108,6 +124,22 @@ export default class index extends Component {
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
{record.type < 2 && (
|
||||
<Auth auth="sysMenu:add">
|
||||
<a
|
||||
onClick={() =>
|
||||
this.onOpen({
|
||||
modal: this.addForm,
|
||||
record,
|
||||
isParent: true,
|
||||
addType: record.type == 0 ? [1] : [2],
|
||||
})
|
||||
}
|
||||
>
|
||||
{record.type == 0 ? '新增子菜单' : '新增功能'}
|
||||
</a>
|
||||
</Auth>
|
||||
)}
|
||||
</QueryTableActions>
|
||||
),
|
||||
})
|
||||
@@ -132,7 +164,7 @@ export default class index extends Component {
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.table.current.onLoading()
|
||||
getDictData('menu_type', 'menu_weight').then(res => {
|
||||
getDictData('menu_type', 'menu_weight', 'open_type').then(res => {
|
||||
this.setState(
|
||||
{
|
||||
codes: res,
|
||||
@@ -156,27 +188,8 @@ export default class index extends Component {
|
||||
...params,
|
||||
...query,
|
||||
})
|
||||
return this.onfilterdata(data)
|
||||
//return data
|
||||
}
|
||||
|
||||
onfilterdata(data) {
|
||||
this.findlastChildren(data)
|
||||
return data
|
||||
}
|
||||
findlastChildren(data) {
|
||||
data.forEach(s => {
|
||||
if (s.children && s.children.length > 0) {
|
||||
s.rowExpandable = true
|
||||
s.children.forEach(p => {
|
||||
if (p.children && p.children.length === 0) {
|
||||
p.rowExpandable = false
|
||||
}
|
||||
})
|
||||
this.findlastChildren(s.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
@@ -188,7 +201,7 @@ export default class index extends Component {
|
||||
name = toCamelCase(name)
|
||||
const codes = this.state.codes[name]
|
||||
if (codes) {
|
||||
const c = codes.find(p => p.code === code)
|
||||
const c = codes.find(p => p.code == code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
@@ -201,15 +214,17 @@ export default class index extends Component {
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
onOpen(modal, record, isParent = false) {
|
||||
onOpen({ modal, record, isParent = false, addType = [] }) {
|
||||
const params = isParent
|
||||
? {
|
||||
parent: record,
|
||||
isParent,
|
||||
addType,
|
||||
}
|
||||
: {
|
||||
record,
|
||||
isParent,
|
||||
addType,
|
||||
}
|
||||
|
||||
modal.current.open(params)
|
||||
@@ -240,64 +255,106 @@ export default class index extends Component {
|
||||
this.onAction(apiAction.delete(record), '删除成功')
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
/**
|
||||
* 绘制新的扩展行
|
||||
* @param {*} record
|
||||
*/
|
||||
onRowRender(record) {
|
||||
var arr = []
|
||||
var istag = false
|
||||
record.children.map(s => {
|
||||
if (!s.rowExpandable && s.type == 2) {
|
||||
istag = true
|
||||
var temp = (
|
||||
<Tag color="#87d068" key={s.id}>
|
||||
{s.name} |{' '}
|
||||
<Auth auth="sysMenu:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, s)}>编辑</a>
|
||||
</Auth>{' '}
|
||||
|{' '}
|
||||
<Auth auth="sysMenu:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(s)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</Tag>
|
||||
const grids = []
|
||||
let isFunction = false
|
||||
record.children.map(item => {
|
||||
if (!(item.children && item.children.length) && item.type == 2) {
|
||||
isFunction = true
|
||||
const grid = (
|
||||
<Card.Grid key={item.id}>
|
||||
<p>
|
||||
{item.visibleParent && (
|
||||
<Tooltip placement="top" title="选中此项才会显示菜单">
|
||||
<AntIcon
|
||||
type="eye"
|
||||
style={{ color: '#1890ff' }}
|
||||
className="mr-xxs"
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
<b>{item.name}</b>
|
||||
</p>
|
||||
<span className="block ellipsis text-gray">{item.permission}</span>
|
||||
<div className="text-right">
|
||||
<QueryTableActions>
|
||||
<Auth auth="sysMenu:edit">
|
||||
<Tooltip title="编辑">
|
||||
<a
|
||||
className="link-gray"
|
||||
onClick={() =>
|
||||
this.onOpen({ modal: this.editForm, record: item })
|
||||
}
|
||||
>
|
||||
<AntIcon type="edit" />
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Auth>
|
||||
<Auth auth="sysMenu:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(item)}
|
||||
>
|
||||
<Tooltip title="删除">
|
||||
<a className="link-gray">
|
||||
<AntIcon type="delete" />
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>
|
||||
</div>
|
||||
</Card.Grid>
|
||||
)
|
||||
arr.push(temp)
|
||||
} else if (s.rowExpandable || (!s.rowExpandable && s.type == 1)) {
|
||||
arr.push(s)
|
||||
grids.push(grid)
|
||||
} else if (
|
||||
(item.children && item.children.length) ||
|
||||
(!(item.children && item.children.length) && item.type == 1)
|
||||
) {
|
||||
grids.push(item)
|
||||
}
|
||||
})
|
||||
if (istag) {
|
||||
return arr
|
||||
if (isFunction) {
|
||||
grids.push(
|
||||
<Card.Grid
|
||||
key={0}
|
||||
style={{ padding: '18px 12px', cursor: 'pointer' }}
|
||||
className="text-center"
|
||||
onClick={() =>
|
||||
this.onOpen({ modal: this.addForm, record, isParent: true, addType: [2] })
|
||||
}
|
||||
>
|
||||
<div>
|
||||
<AntIcon type="plus" className="text-normal h2" />
|
||||
</div>
|
||||
<span className="text-gray">新增功能</span>
|
||||
</Card.Grid>
|
||||
)
|
||||
return <Card bordered={false}>{grids}</Card>
|
||||
} else {
|
||||
return (
|
||||
<Table
|
||||
columns={this.columns}
|
||||
showHeader={false}
|
||||
dataSource={arr}
|
||||
dataSource={grids}
|
||||
rowKey={record => record.id}
|
||||
expandable={{
|
||||
expandedRowRender: record => this.onRowRender(record),
|
||||
rowExpandable: record => record.rowExpandable === true,
|
||||
rowExpandable: record => record.children && record.children.length,
|
||||
}}
|
||||
childrenColumnName="11"
|
||||
childrenColumnName="none"
|
||||
bordered={true}
|
||||
pagination={false}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
async onSetDefault(record) {
|
||||
this.onAction(apiAction.setDefault(record), '设置成功')
|
||||
}
|
||||
//#endregion
|
||||
|
||||
render() {
|
||||
@@ -306,23 +363,25 @@ export default class index extends Component {
|
||||
<br />
|
||||
<Card bordered={false}>
|
||||
<QueryTable
|
||||
className="yo-inner-table"
|
||||
childrenColumnName="111"
|
||||
className="yo-menu-table"
|
||||
childrenColumnName="none"
|
||||
ref={this.table}
|
||||
autoLoad={false}
|
||||
loadData={this.loadData}
|
||||
columns={this.columns}
|
||||
expandable={{
|
||||
expandedRowRender: record => this.onRowRender(record),
|
||||
rowExpandable: record => record.rowExpandable === true,
|
||||
rowExpandable: record => record.children && record.children.length,
|
||||
}}
|
||||
operator={
|
||||
<Auth auth="sysMenu:add">
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
onClick={() =>
|
||||
this.onOpen({ modal: this.addForm, addType: [0, 1] })
|
||||
}
|
||||
>
|
||||
新增{name}
|
||||
新增目录/菜单
|
||||
</Button>
|
||||
</Auth>
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Form, Input, message as Message, Popconfirm } from 'antd'
|
||||
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions, QueryTreeLayout } from 'components'
|
||||
import {
|
||||
AntIcon,
|
||||
Auth,
|
||||
Container,
|
||||
ModalForm,
|
||||
QueryTable,
|
||||
QueryTableActions,
|
||||
QueryTreeLayout,
|
||||
} from 'components'
|
||||
import { api } from 'common/api'
|
||||
import auth from 'components/authorized/handler'
|
||||
import { toCamelCase } from 'util/format'
|
||||
@@ -13,17 +21,16 @@ const apiAction = {
|
||||
page: api.getOrgPage,
|
||||
add: api.sysOrgAdd,
|
||||
edit: api.sysOrgEdit,
|
||||
delete: api.sysOrgDelete
|
||||
delete: api.sysOrgDelete,
|
||||
}
|
||||
|
||||
const name = '机构'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
state = {
|
||||
codes: {
|
||||
orgType: []
|
||||
}
|
||||
orgType: [],
|
||||
},
|
||||
}
|
||||
|
||||
// 树框架实例
|
||||
@@ -44,13 +51,13 @@ export default class index extends Component {
|
||||
columns = [
|
||||
{
|
||||
title: '机构名称',
|
||||
width: '400px',
|
||||
width: 400,
|
||||
dataIndex: 'name',
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '唯一编码',
|
||||
width: '200px',
|
||||
width: 200,
|
||||
dataIndex: 'code',
|
||||
sorter: true,
|
||||
},
|
||||
@@ -58,24 +65,26 @@ export default class index extends Component {
|
||||
title: '机构类型',
|
||||
dataIndex: 'type',
|
||||
sorter: true,
|
||||
render: text => (<>{this.bindCodeValue(text, 'org_type')}</>)
|
||||
render: text => <>{this.bindCodeValue(text, 'org_type')}</>,
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
width: '80px',
|
||||
width: 80,
|
||||
dataIndex: 'sort',
|
||||
sorter: true,
|
||||
defaultSortOrder: 'ascend',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
width: 400,
|
||||
sorter: true,
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -87,20 +96,22 @@ export default class index extends Component {
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (<QueryTableActions>
|
||||
<Auth auth="sysOrg:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysOrg:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>)
|
||||
render: (text, record) => (
|
||||
<QueryTableActions>
|
||||
<Auth auth="sysOrg:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysOrg:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -109,9 +120,9 @@ export default class index extends Component {
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
@@ -124,26 +135,28 @@ export default class index extends Component {
|
||||
componentDidMount() {
|
||||
this.table.current.onLoading()
|
||||
getDictData('org_type').then(res => {
|
||||
this.setState({
|
||||
codes: res
|
||||
}, () => {
|
||||
this.table.current.onLoadData()
|
||||
})
|
||||
this.setState(
|
||||
{
|
||||
codes: res,
|
||||
},
|
||||
() => {
|
||||
this.table.current.onLoadData()
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
|
||||
query = {
|
||||
...query,
|
||||
pid: this.selectId
|
||||
pid: this.selectId,
|
||||
}
|
||||
|
||||
const { data } = await apiAction.page({
|
||||
@@ -166,7 +179,7 @@ export default class index extends Component {
|
||||
/**
|
||||
* 树节点选中事件
|
||||
* [必要]
|
||||
* @param {*} id
|
||||
* @param {*} id
|
||||
*/
|
||||
onSelectTree(id) {
|
||||
this.selectId = id
|
||||
@@ -175,15 +188,15 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
bindCodeValue(code, name) {
|
||||
name = toCamelCase(name)
|
||||
const codes = this.state.codes[name]
|
||||
if (codes) {
|
||||
const c = codes.find((p) => p.code === code)
|
||||
const c = codes.find(p => p.code == code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
@@ -193,21 +206,21 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
modal.current.open({
|
||||
orgId: this.selectId,
|
||||
record
|
||||
record,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
@@ -227,13 +240,10 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(record), '删除成功')
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
@@ -245,7 +255,7 @@ export default class index extends Component {
|
||||
ref={this.treeLayout}
|
||||
loadData={this.loadTreeData}
|
||||
defaultExpanded={true}
|
||||
onSelect={(key) => this.onSelectTree(key)}
|
||||
onSelect={key => this.onSelectTree(key)}
|
||||
>
|
||||
<Container mode="fluid">
|
||||
<Card bordered={false}>
|
||||
@@ -265,7 +275,9 @@ export default class index extends Component {
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>新增{name}</Button>
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
@@ -2,24 +2,22 @@ import React, { Component } from 'react'
|
||||
import { Button, Card, Form, Input, Popconfirm, message as Message } from 'antd'
|
||||
import { isEqual } from 'lodash'
|
||||
import { AntIcon, Auth, Container, ModalForm, QueryTable, QueryTableActions } from 'components'
|
||||
import { api } from "common/api"
|
||||
import { api } from 'common/api'
|
||||
import auth from 'components/authorized/handler'
|
||||
import FormBody from './form'
|
||||
|
||||
|
||||
// 配置页面所需接口函数
|
||||
const apiAction = {
|
||||
page: api.sysPosPage,
|
||||
add: api.sysPosAdd,
|
||||
edit: api.sysPosEdit,
|
||||
delete: api.sysPosDelete
|
||||
delete: api.sysPosDelete,
|
||||
}
|
||||
|
||||
// 用于弹窗标题
|
||||
const name = '职位'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
// 表格实例
|
||||
table = React.createRef()
|
||||
|
||||
@@ -32,29 +30,34 @@ export default class index extends Component {
|
||||
{
|
||||
title: '职位名称',
|
||||
dataIndex: 'name',
|
||||
width: 400,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '唯一编码',
|
||||
dataIndex: 'code',
|
||||
width: 400,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sort',
|
||||
width: 80,
|
||||
sorter: true,
|
||||
defaultSortOrder: 'ascend',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
width: 400,
|
||||
sorter: true,
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
*/
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
@@ -65,20 +68,22 @@ export default class index extends Component {
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (<QueryTableActions>
|
||||
<Auth auth="sysApp:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysApp:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>)
|
||||
render: (text, record) => (
|
||||
<QueryTableActions>
|
||||
<Auth auth="sysApp:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysApp:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -87,9 +92,9 @@ export default class index extends Component {
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
@@ -98,9 +103,9 @@ export default class index extends Component {
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
const { data } = await apiAction.page({
|
||||
@@ -111,21 +116,21 @@ export default class index extends Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
modal.current.open({
|
||||
record
|
||||
record,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
@@ -140,13 +145,10 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(record), '删除成功')
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -172,11 +174,11 @@ export default class index extends Component {
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>新增{name}</Button>
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
|
||||
</QueryTable>
|
||||
></QueryTable>
|
||||
</Card>
|
||||
<ModalForm
|
||||
title={`新增${name}`}
|
||||
@@ -198,4 +200,4 @@ export default class index extends Component {
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ const { SHOW_PARENT } = TreeSelect
|
||||
const initialValues = {}
|
||||
|
||||
export default class data extends Component {
|
||||
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
@@ -19,7 +18,7 @@ export default class data extends Component {
|
||||
arerTreeData: [],
|
||||
orgCheckedKeys: [],
|
||||
|
||||
isDefine: false
|
||||
isDefine: false,
|
||||
}
|
||||
|
||||
// 表单实例
|
||||
@@ -39,10 +38,9 @@ export default class data extends Component {
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
|
||||
this.record = cloneDeep(params.record)
|
||||
//#region 从后端转换成前段所需格式
|
||||
const { dataScopeType } = await getDictData('data_scope_type')
|
||||
@@ -53,17 +51,17 @@ export default class data extends Component {
|
||||
dataScopeType,
|
||||
orgTreeData,
|
||||
arerTreeData,
|
||||
orgCheckedKeys
|
||||
orgCheckedKeys,
|
||||
})
|
||||
//#endregion
|
||||
this.form.current.setFieldsValue({
|
||||
dataScopeType: this.record.dataScopeType.toString()
|
||||
dataScopeType: this.record.dataScopeType.toString(),
|
||||
})
|
||||
|
||||
this.onChange(this.record.dataScopeType)
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
loading: false,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -71,7 +69,7 @@ export default class data extends Component {
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
@@ -107,11 +105,11 @@ export default class data extends Component {
|
||||
onChange(value) {
|
||||
if (value == 5) {
|
||||
this.setState({
|
||||
isDefine: true
|
||||
isDefine: true,
|
||||
})
|
||||
} else {
|
||||
this.setState({
|
||||
isDefine: false
|
||||
isDefine: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -119,29 +117,24 @@ export default class data extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
initialValues={initialValues}
|
||||
ref={this.form}
|
||||
className="yo-form"
|
||||
>
|
||||
<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
|
||||
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 &&
|
||||
{this.state.isDefine && (
|
||||
<>
|
||||
<Form.Item label="选择机构" name="grantOrgIdList">
|
||||
<TreeSelect
|
||||
@@ -151,7 +144,11 @@ export default class data extends Component {
|
||||
treeCheckable
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="选择区域" name="grantAreaCodeList" help="缺少获取已保存的列表,react版本节点名无法设置">
|
||||
<Form.Item
|
||||
label="选择区域"
|
||||
name="grantAreaCodeList"
|
||||
help="缺少获取已保存的列表,react版本节点名无法设置"
|
||||
>
|
||||
<TreeSelect
|
||||
showCheckedStrategy={SHOW_PARENT}
|
||||
treeData={this.state.arerTreeData}
|
||||
@@ -160,7 +157,7 @@ export default class data extends Component {
|
||||
/>
|
||||
</Form.Item>
|
||||
</>
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
</Spin>
|
||||
</Form>
|
||||
|
||||
@@ -16,14 +16,13 @@ const apiAction = {
|
||||
delete: api.sysRoleDelete,
|
||||
|
||||
grantMenu: api.sysRoleGrantMenu,
|
||||
grantData: api.sysRoleGrantData
|
||||
grantData: api.sysRoleGrantData,
|
||||
}
|
||||
|
||||
// 用于弹窗标题
|
||||
const name = '角色'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
// 表格实例
|
||||
table = React.createRef()
|
||||
|
||||
@@ -39,23 +38,27 @@ export default class index extends Component {
|
||||
{
|
||||
title: '角色名',
|
||||
dataIndex: 'name',
|
||||
width: 400,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '唯一编码',
|
||||
dataIndex: 'code',
|
||||
width: 400,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sort',
|
||||
width: 80,
|
||||
sorter: true,
|
||||
}
|
||||
defaultSortOrder: 'ascend',
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -67,44 +70,58 @@ export default class index extends Component {
|
||||
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>)
|
||||
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>
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -113,9 +130,9 @@ export default class index extends Component {
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
@@ -124,9 +141,9 @@ export default class index extends Component {
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
const { data } = await apiAction.page({
|
||||
@@ -138,20 +155,20 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
modal.current.open({
|
||||
record
|
||||
record,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
@@ -166,13 +183,10 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(record), '删除成功')
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
@@ -202,7 +216,9 @@ export default class index extends Component {
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>新增{name}</Button>
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
</Auth>
|
||||
}
|
||||
/>
|
||||
|
||||
115
web-react/src/pages/system/user/data.jsx
Normal file
115
web-react/src/pages/system/user/data.jsx
Normal file
@@ -0,0 +1,115 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Spin, TreeSelect } from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { api } from 'common/api'
|
||||
|
||||
export default class data extends Component {
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
|
||||
options: {
|
||||
orgData: [],
|
||||
areaData: [],
|
||||
orgCheckedKeys: [],
|
||||
},
|
||||
}
|
||||
|
||||
// 表单实例
|
||||
form = React.createRef()
|
||||
|
||||
// 初始化数据
|
||||
id = ''
|
||||
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.props.created && this.props.created(this)
|
||||
}
|
||||
async fillData(params) {
|
||||
this.id = params.id
|
||||
//#region 从后端转换成前段所需格式
|
||||
const orgData = await this.loadOrgData()
|
||||
const areaData = await this.loadAreaData()
|
||||
const orgCheckedKeys = await this.loadMemberOwn(this.id)
|
||||
this.setState({
|
||||
options: {
|
||||
orgData,
|
||||
areaData,
|
||||
orgCheckedKeys,
|
||||
},
|
||||
})
|
||||
this.form.current.setFieldsValue({
|
||||
id: this.id,
|
||||
grantOrgIdList: orgCheckedKeys,
|
||||
grantAreaCodeList: [],
|
||||
})
|
||||
|
||||
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.id) {
|
||||
postData.id = this.id
|
||||
}
|
||||
//#region 从前段转换后端所需格式
|
||||
//#endregion
|
||||
return postData
|
||||
}
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
async loadOrgData() {
|
||||
const { data } = await api.getOrgTree()
|
||||
return data
|
||||
}
|
||||
|
||||
async loadAreaData() {
|
||||
const { data } = await api.getAreaTree()
|
||||
return data
|
||||
}
|
||||
async loadMemberOwn(id) {
|
||||
const { data } = await api.sysUserOwnData({ id })
|
||||
return data
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<Form ref={this.form} className="yo-form">
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<div className="yo-form-group">
|
||||
<Form.Item label="选择机构" name="grantOrgIdList">
|
||||
<TreeSelect
|
||||
showCheckedStrategy="SHOW_PARENT"
|
||||
treeData={this.state.options.orgData}
|
||||
placeholder="请选择机构"
|
||||
treeCheckable
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="选择区域" name="grantAreaCodeList">
|
||||
<TreeSelect
|
||||
showCheckedStrategy="SHOW_PARENT"
|
||||
treeData={this.state.options.areaData}
|
||||
placeholder="请选择所属区域"
|
||||
treeCheckable
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Spin>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,17 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Row, Col, Form, Input, DatePicker, Radio, Table, Select, Spin, TreeSelect } from 'antd'
|
||||
import {
|
||||
Button,
|
||||
Row,
|
||||
Col,
|
||||
Form,
|
||||
Input,
|
||||
DatePicker,
|
||||
Radio,
|
||||
Table,
|
||||
Select,
|
||||
Spin,
|
||||
TreeSelect,
|
||||
} from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
@@ -9,25 +21,24 @@ import moment from 'moment'
|
||||
|
||||
const initialValues = {
|
||||
sex: 0,
|
||||
sysEmpParam: {}
|
||||
sysEmpParam: {},
|
||||
}
|
||||
|
||||
export default class form extends Component {
|
||||
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
codes: {
|
||||
orgType: []
|
||||
orgType: [],
|
||||
},
|
||||
|
||||
options: {
|
||||
orgData: [],
|
||||
posData: []
|
||||
posData: [],
|
||||
},
|
||||
sysEmpParam: {
|
||||
extIds: []
|
||||
}
|
||||
extIds: [],
|
||||
},
|
||||
}
|
||||
extColumns = [
|
||||
{
|
||||
@@ -45,7 +56,7 @@ export default class form extends Component {
|
||||
placeholder="请选择附加组织机构"
|
||||
/>
|
||||
</Form.Item>
|
||||
)
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '附属岗位',
|
||||
@@ -56,33 +67,28 @@ export default class form extends Component {
|
||||
<Select
|
||||
defaultValue={text}
|
||||
className="w-100-p"
|
||||
placeholder="请选择附加职位信息">
|
||||
{
|
||||
this.state.options.posData.map(item => {
|
||||
return <Select.Option
|
||||
key={item.id}
|
||||
value={item.id}
|
||||
>
|
||||
{item.name}</Select.Option>
|
||||
})
|
||||
}
|
||||
placeholder="请选择附加职位信息"
|
||||
>
|
||||
{this.state.options.posData.map(item => {
|
||||
return (
|
||||
<Select.Option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</Select.Option>
|
||||
)
|
||||
})}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
)
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: '70px',
|
||||
render: (text, record) => (
|
||||
<Button
|
||||
onClick={() => this.onRemoveExtData(record)}
|
||||
size="small"
|
||||
danger
|
||||
>
|
||||
<Button onClick={() => this.onRemoveExtData(record)} size="small" danger>
|
||||
删除
|
||||
</Button>
|
||||
)
|
||||
),
|
||||
},
|
||||
]
|
||||
// 表单实例
|
||||
@@ -102,11 +108,13 @@ export default class form extends Component {
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} params
|
||||
*/
|
||||
async fillData(params) {
|
||||
this.record = cloneDeep(params.record || {})
|
||||
//#region 从后端转换成前段所需格式
|
||||
if (params.id) {
|
||||
this.record = (await api.sysUserDetail({ id: params.id })).data
|
||||
}
|
||||
const orgData = await this.loadOrgData()
|
||||
const posData = await this.loadPosData()
|
||||
const codes = await getDictData('org_type')
|
||||
@@ -118,17 +126,17 @@ export default class form extends Component {
|
||||
|
||||
// 提交的时候是"param",而获取下来却是"info",在这里转换一下
|
||||
if (this.record.sysEmpInfo) {
|
||||
this.record.sysEmpParam = this.record.sysEmpInfo;
|
||||
delete this.record.sysEmpInfo;
|
||||
this.record.sysEmpParam = this.record.sysEmpInfo
|
||||
delete this.record.sysEmpInfo
|
||||
} else if (!this.record.sysEmpParam) {
|
||||
this.record.sysEmpParam = {
|
||||
extIds: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 转换职位信息列表
|
||||
if (this.record.sysEmpParam.positions) {
|
||||
this.record.sysEmpParam.posIdList = this.record.sysEmpParam.positions.map((p) => p.posId);
|
||||
this.record.sysEmpParam.posIdList = this.record.sysEmpParam.positions.map(p => p.posId)
|
||||
}
|
||||
|
||||
// 附加信息
|
||||
@@ -138,12 +146,12 @@ export default class form extends Component {
|
||||
key: i,
|
||||
orgId: p.orgId,
|
||||
posId: p.posId,
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (params.orgId) {
|
||||
this.record.sysEmpParam.orgId = params.orgId;
|
||||
this.record.sysEmpParam.orgId = params.orgId
|
||||
}
|
||||
|
||||
this.setState({
|
||||
@@ -154,18 +162,18 @@ export default class form extends Component {
|
||||
posData,
|
||||
},
|
||||
sysEmpParam: {
|
||||
...this.record.sysEmpParam
|
||||
}
|
||||
...this.record.sysEmpParam,
|
||||
},
|
||||
})
|
||||
|
||||
this.record = {
|
||||
...this.record
|
||||
...this.record,
|
||||
}
|
||||
//#endregion
|
||||
this.form.current.setFieldsValue(this.record)
|
||||
|
||||
this.setState({
|
||||
loading: false
|
||||
loading: false,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -173,7 +181,7 @@ export default class form extends Component {
|
||||
* 获取数据
|
||||
* 可以对postData进行数据结构调整
|
||||
* [异步,必要]
|
||||
* @returns
|
||||
* @returns
|
||||
*/
|
||||
async getData() {
|
||||
const form = this.form.current
|
||||
@@ -206,24 +214,26 @@ export default class form extends Component {
|
||||
const record = {
|
||||
key: extIds.length > 0 ? extIds[extIds.length - 1].key + 1 : 0,
|
||||
orgId: undefined,
|
||||
posId: undefined
|
||||
posId: undefined,
|
||||
}
|
||||
|
||||
this.setState({
|
||||
sysEmpParam: {
|
||||
extIds: [...extIds, record]
|
||||
this.setState(
|
||||
{
|
||||
sysEmpParam: {
|
||||
extIds: [...extIds, record],
|
||||
},
|
||||
},
|
||||
() => {
|
||||
console.log(this.form.current.getFieldsValue())
|
||||
}
|
||||
}, () => {
|
||||
console.log(this.form.current.getFieldsValue())
|
||||
})
|
||||
|
||||
)
|
||||
}
|
||||
onRemoveExtData(record) {
|
||||
const ext = this.state.sysEmpParam.extIds,
|
||||
remove = ext.find((p) => p.key === record.key),
|
||||
index = ext.indexOf(remove);
|
||||
remove = ext.find(p => p.key === record.key),
|
||||
index = ext.indexOf(remove)
|
||||
|
||||
ext.splice(index, 1);
|
||||
ext.splice(index, 1)
|
||||
console.log(ext)
|
||||
|
||||
// this.form.current.setFieldsValue({
|
||||
@@ -232,14 +242,16 @@ export default class form extends Component {
|
||||
// }
|
||||
// })
|
||||
|
||||
this.setState({
|
||||
sysEmpParam: {
|
||||
extIds: ext
|
||||
this.setState(
|
||||
{
|
||||
sysEmpParam: {
|
||||
extIds: ext,
|
||||
},
|
||||
},
|
||||
() => {
|
||||
//console.log(this.form.current.getFieldsValue())
|
||||
}
|
||||
}, () => {
|
||||
//console.log(this.form.current.getFieldsValue())
|
||||
})
|
||||
|
||||
)
|
||||
}
|
||||
//#endregion
|
||||
renderExtInfoTable() {
|
||||
@@ -251,79 +263,100 @@ export default class form extends Component {
|
||||
pagination={false}
|
||||
size="small"
|
||||
bordered
|
||||
rowKey={(record) => record.key}
|
||||
footer={
|
||||
() =>
|
||||
<Button
|
||||
block
|
||||
icon={
|
||||
<AntIcon type="plus" />
|
||||
}
|
||||
type="dashed"
|
||||
onClick={() => this.onAddExtData()}>
|
||||
新增一项</Button>
|
||||
}
|
||||
>
|
||||
</Table>
|
||||
rowKey={record => record.key}
|
||||
footer={() => (
|
||||
<Button
|
||||
block
|
||||
icon={<AntIcon type="plus" />}
|
||||
type="dashed"
|
||||
onClick={() => this.onAddExtData()}
|
||||
>
|
||||
新增一项
|
||||
</Button>
|
||||
)}
|
||||
></Table>
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
initialValues={initialValues}
|
||||
ref={this.form}
|
||||
className="yo-form"
|
||||
>
|
||||
<Spin
|
||||
spinning={this.state.loading}
|
||||
indicator={<AntIcon type="loading" />}>
|
||||
<Form initialValues={initialValues} ref={this.form} className="yo-form">
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<h3 className="h3">基本信息</h3>
|
||||
<div className="yo-form-group">
|
||||
<Form.Item label="账号" name="account" rules={[{ required: true, message: '请输入账号', trigger: 'blur' }]}>
|
||||
<Form.Item
|
||||
label="账号"
|
||||
name="account"
|
||||
rules={[{ required: true, message: '请输入账号', trigger: 'blur' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入账号" />
|
||||
</Form.Item>
|
||||
<Form.Item label="姓名" name="name" rules={[{ required: true, message: '请输入姓名', trigger: 'blur' }]}>
|
||||
<Form.Item
|
||||
label="姓名"
|
||||
name="name"
|
||||
rules={[{ required: true, message: '请输入姓名', trigger: 'blur' }]}
|
||||
>
|
||||
<Input autoComplete="off" placeholder="请输入姓名" />
|
||||
</Form.Item>
|
||||
{this.props.mode == 'add' && <>
|
||||
<Form.Item label="密码" name="password" rules={[{ required: true, message: '请输入密码', trigger: 'blur' }]}>
|
||||
<Input.Password autoComplete="off" placeholder="请输入密码" />
|
||||
</Form.Item>
|
||||
<Form.Item label="确认密码" name="confirm" rules={[{ required: true, message: '请确认密码', trigger: 'blur' }]}>
|
||||
<Input.Password autoComplete="off" placeholder="请确认密码" />
|
||||
</Form.Item>
|
||||
</>
|
||||
}
|
||||
<Form.Item label="昵称" name="nickName" >
|
||||
{this.props.mode == 'add' && (
|
||||
<>
|
||||
<Form.Item
|
||||
label="密码"
|
||||
name="password"
|
||||
rules={[
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
]}
|
||||
>
|
||||
<Input.Password autoComplete="off" placeholder="请输入密码" />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="确认密码"
|
||||
name="confirm"
|
||||
rules={[
|
||||
{ required: true, message: '请确认密码', trigger: 'blur' },
|
||||
]}
|
||||
>
|
||||
<Input.Password autoComplete="off" placeholder="请确认密码" />
|
||||
</Form.Item>
|
||||
</>
|
||||
)}
|
||||
<Form.Item label="昵称" name="nickName">
|
||||
<Input autoComplete="off" placeholder="请输入昵称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="生日" name="birthday" >
|
||||
<Form.Item label="生日" name="birthday">
|
||||
<DatePicker className="w-100-p" />
|
||||
</Form.Item>
|
||||
<Form.Item label="性别" name="sex" >
|
||||
<Radio.Group >
|
||||
<Form.Item label="性别" name="sex">
|
||||
<Radio.Group>
|
||||
<Radio.Button value={0}>
|
||||
<AntIcon className="mr-xxs" type="stop" />
|
||||
<span>保密</span>
|
||||
</Radio.Button>
|
||||
<Radio.Button value={1}>
|
||||
<AntIcon style={{ color: '#1890ff' }} className="mr-xxs" type="man" />
|
||||
<AntIcon
|
||||
style={{ color: '#1890ff' }}
|
||||
className="mr-xxs"
|
||||
type="man"
|
||||
/>
|
||||
<span>男</span>
|
||||
</Radio.Button>
|
||||
<Radio.Button value={2}>
|
||||
<AntIcon style={{ color: '#eb2f96' }} className="mr-xxs" type="woman" />
|
||||
<AntIcon
|
||||
style={{ color: '#eb2f96' }}
|
||||
className="mr-xxs"
|
||||
type="woman"
|
||||
/>
|
||||
<span>女</span>
|
||||
</Radio.Button>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item label="邮箱" name="email" >
|
||||
<Form.Item label="邮箱" name="email">
|
||||
<Input autoComplete="off" placeholder="请输入邮箱" />
|
||||
</Form.Item>
|
||||
<Form.Item label="手机号" name="phone" >
|
||||
<Form.Item label="手机号" name="phone">
|
||||
<Input autoComplete="off" placeholder="请输入手机号" />
|
||||
</Form.Item>
|
||||
<Form.Item label="电话" name="tel" >
|
||||
<Form.Item label="电话" name="tel">
|
||||
<Input autoComplete="off" placeholder="请输入电话" />
|
||||
</Form.Item>
|
||||
</div>
|
||||
@@ -332,7 +365,8 @@ export default class form extends Component {
|
||||
<Form.Item
|
||||
label="所属组织机构"
|
||||
name={['sysEmpParam', 'orgId']}
|
||||
rules={[{ required: true, message: '所属组织机构' }]}>
|
||||
rules={[{ required: true, message: '所属组织机构' }]}
|
||||
>
|
||||
<TreeSelect
|
||||
treeData={this.state.options.orgData}
|
||||
dropdownStyle={{ maxHeight: '300px', overflow: 'auto' }}
|
||||
@@ -340,26 +374,18 @@ export default class form extends Component {
|
||||
placeholder="请选择所属组织机构"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="工号"
|
||||
name={['sysEmpParam', 'jobNum']} >
|
||||
<Input
|
||||
autoComplete="off"
|
||||
placeholder="请输入工号" />
|
||||
<Form.Item label="工号" name={['sysEmpParam', 'jobNum']}>
|
||||
<Input autoComplete="off" placeholder="请输入工号" />
|
||||
</Form.Item>
|
||||
<Form.Item label="职位信息" name={['sysEmpParam', 'posIdList']}>
|
||||
<Select
|
||||
mode="multiple"
|
||||
placeholder="请选择职位信息">
|
||||
{
|
||||
this.state.options.posData.map(item => {
|
||||
return <Select.Option
|
||||
key={item.id}
|
||||
value={item.id}
|
||||
>
|
||||
{item.name}</Select.Option>
|
||||
})
|
||||
}
|
||||
<Select mode="multiple" placeholder="请选择职位信息">
|
||||
{this.state.options.posData.map(item => {
|
||||
return (
|
||||
<Select.Option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</Select.Option>
|
||||
)
|
||||
})}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,27 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Button, Card, Descriptions, Form, Input, List, message as Message, Popconfirm, Select, Switch } from 'antd'
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Form,
|
||||
Input,
|
||||
List,
|
||||
message as Message,
|
||||
Popconfirm,
|
||||
Select,
|
||||
Switch,
|
||||
Dropdown,
|
||||
Menu,
|
||||
} from 'antd'
|
||||
import { AntIcon, Auth, Container, Image, ModalForm, QueryList, QueryTreeLayout } from 'components'
|
||||
import { api } from 'common/api'
|
||||
import { toCamelCase } from 'util/format'
|
||||
import { isEqual } from 'lodash'
|
||||
import getDictData from 'util/dic'
|
||||
import FormBody from './form'
|
||||
import RoleForm from './role'
|
||||
import DataForm from './data'
|
||||
import auth from 'components/authorized/handler'
|
||||
|
||||
// 配置页面所需接口函数
|
||||
const apiAction = {
|
||||
@@ -16,19 +32,21 @@ const apiAction = {
|
||||
delete: api.sysUserDelete,
|
||||
|
||||
changeStatus: api.sysUserChangeStatus,
|
||||
resetPwd: api.sysUserResetPwd
|
||||
resetPwd: api.sysUserResetPwd,
|
||||
|
||||
grantRole: api.sysUserGrantRole,
|
||||
grantData: api.sysUserGrantData,
|
||||
}
|
||||
|
||||
// 用于弹窗标题
|
||||
const name = '用户'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
state = {
|
||||
codes: {
|
||||
sex: [],
|
||||
commonStatus: []
|
||||
}
|
||||
commonStatus: [],
|
||||
},
|
||||
}
|
||||
|
||||
// 表格实例
|
||||
@@ -39,6 +57,8 @@ export default class index extends Component {
|
||||
// 编辑窗口实例
|
||||
editForm = React.createRef()
|
||||
|
||||
roleForm = React.createRef()
|
||||
dataForm = React.createRef()
|
||||
// 树选中节点
|
||||
selectId = undefined
|
||||
|
||||
@@ -46,9 +66,9 @@ export default class index extends Component {
|
||||
* 阻止外部组件引发的渲染,提升性能
|
||||
* 可自行添加渲染条件
|
||||
* [必要]
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
* @param {*} props
|
||||
* @param {*} state
|
||||
* @returns
|
||||
*/
|
||||
shouldComponentUpdate(props, state) {
|
||||
return !isEqual(this.state, state)
|
||||
@@ -61,28 +81,30 @@ export default class index extends Component {
|
||||
componentDidMount() {
|
||||
this.list.current.onLoading()
|
||||
getDictData('sex', 'common_status').then(res => {
|
||||
this.setState({
|
||||
codes: res
|
||||
}, () => {
|
||||
this.list.current.onLoadData()
|
||||
})
|
||||
this.setState(
|
||||
{
|
||||
codes: res,
|
||||
},
|
||||
() => {
|
||||
this.list.current.onLoadData()
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用加载数据接口,可在调用前对query进行处理
|
||||
* [异步,必要]
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
* @param {*} params
|
||||
* @param {*} query
|
||||
* @returns
|
||||
*/
|
||||
loadData = async (params, query) => {
|
||||
|
||||
query = {
|
||||
...query,
|
||||
sysEmpParam: {
|
||||
orgId: this.selectId
|
||||
}
|
||||
orgId: this.selectId,
|
||||
},
|
||||
}
|
||||
|
||||
const { data } = await apiAction.page({
|
||||
@@ -105,7 +127,7 @@ export default class index extends Component {
|
||||
/**
|
||||
* 树节点选中事件
|
||||
* [必要]
|
||||
* @param {*} id
|
||||
* @param {*} id
|
||||
*/
|
||||
onSelectTree(id) {
|
||||
this.selectId = id
|
||||
@@ -114,15 +136,15 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 绑定字典数据
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
* @param {*} code
|
||||
* @param {*} name
|
||||
* @returns
|
||||
*/
|
||||
bindCodeValue(code, name) {
|
||||
name = toCamelCase(name)
|
||||
const codes = this.state.codes[name]
|
||||
if (codes) {
|
||||
const c = codes.find((p) => p.code == code)
|
||||
const c = codes.find(p => p.code == code)
|
||||
if (c) {
|
||||
return c.value
|
||||
}
|
||||
@@ -132,21 +154,21 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
* @param {*} modal
|
||||
* @param {*} id
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
onOpen(modal, id) {
|
||||
modal.current.open({
|
||||
orgId: this.selectId,
|
||||
record
|
||||
id,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.list.current.onLoading()
|
||||
@@ -161,39 +183,63 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(record), '删除成功')
|
||||
}
|
||||
|
||||
//#region 自定义方法
|
||||
renderItem(record) {
|
||||
const { id, account, name, nickName, avatar, sex, phone, email, status } = record
|
||||
return (
|
||||
<List.Item
|
||||
key={record.id}
|
||||
actions={
|
||||
[
|
||||
<Auth auth="sysUser:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>,
|
||||
<Auth auth="sysOrg:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>,
|
||||
<Auth aut="sysUser:resetPwd">
|
||||
<a onClick={() => this.onResetPassword(record)}>重置密码</a>
|
||||
</Auth>
|
||||
]
|
||||
}
|
||||
key={id}
|
||||
actions={[
|
||||
<Auth auth="sysUser:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, id)}>编辑</a>
|
||||
</Auth>,
|
||||
<Auth auth="sysOrg:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(id)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>,
|
||||
<Auth aut="sysUser:resetPwd">
|
||||
<a onClick={() => this.onResetPassword(id)}>重置密码</a>
|
||||
</Auth>,
|
||||
<Auth auth={{ sysUser: [['grantRole'], ['grantData']] }}>
|
||||
<Dropdown
|
||||
placement="bottomRight"
|
||||
overlay={
|
||||
<Menu>
|
||||
{auth('sysUser:grantRole') && (
|
||||
<Menu.Item key="1">
|
||||
<a onClick={() => this.onOpen(this.roleForm, id)}>
|
||||
授权角色
|
||||
</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
{auth('sysUser:grantData') && (
|
||||
<Menu.Item key="2">
|
||||
<a onClick={() => this.onOpen(this.dataForm, id)}>
|
||||
授权额外数据
|
||||
</a>
|
||||
</Menu.Item>
|
||||
)}
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
<a className="ant-dropdown-link">
|
||||
授权
|
||||
<AntIcon type="down" />
|
||||
</a>
|
||||
</Dropdown>
|
||||
</Auth>,
|
||||
]}
|
||||
>
|
||||
<List.Item.Meta
|
||||
avatar={
|
||||
@@ -201,48 +247,42 @@ export default class index extends Component {
|
||||
type="avatar"
|
||||
shape="square"
|
||||
size={48}
|
||||
id={record.avatar}
|
||||
id={avatar}
|
||||
icon={<AntIcon type="user" />}
|
||||
/>
|
||||
}
|
||||
title={record.nickName || record.name}
|
||||
description={record.account}
|
||||
title={nickName || name}
|
||||
description={account}
|
||||
/>
|
||||
<Descriptions className="flex-1" column={2}>
|
||||
<Descriptions.Item label="性别">{this.bindCodeValue(record.sex, 'sex')}</Descriptions.Item>
|
||||
<Descriptions.Item label="手机">{record.phone || '未设置'}</Descriptions.Item>
|
||||
<Descriptions.Item label="邮箱">{record.email || '未设置'}</Descriptions.Item>
|
||||
<Descriptions.Item label="性别">
|
||||
{this.bindCodeValue(sex, 'sex')}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="手机">{phone || '未设置'}</Descriptions.Item>
|
||||
<Descriptions.Item label="邮箱">{email || '未设置'}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
<div className="yo-list-content--h">
|
||||
<Auth auth="sysUser:changeStatus">
|
||||
<div className="yo-list-content--h--item text-center">
|
||||
<Switch
|
||||
checked={!record.status}
|
||||
loading={record.statusChanging}
|
||||
checked={!status}
|
||||
checkedChildren={this.bindCodeValue(0, 'common_status')}
|
||||
unCheckedChildren={this.bindCodeValue(1, 'common_status')}
|
||||
onChange={checked => this.onSetUserStatus(record, checked)}
|
||||
onChange={checked => this.onSetUserStatus(id, checked)}
|
||||
/>
|
||||
</div>
|
||||
</Auth>
|
||||
</div>
|
||||
</List.Item>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
onSetUserStatus(record, checked) {
|
||||
this.onAction(
|
||||
apiAction.changeStatus({ id: record.id, status: +!checked }),
|
||||
'设置成功'
|
||||
)
|
||||
onSetUserStatus(id, checked) {
|
||||
this.onAction(apiAction.changeStatus({ id, status: +!checked }), '设置成功')
|
||||
}
|
||||
|
||||
onResetPassword(record) {
|
||||
this.onAction(
|
||||
apiAction.resetPwd(record),
|
||||
'重置成功'
|
||||
)
|
||||
onResetPassword(id) {
|
||||
this.onAction(apiAction.resetPwd({ id }), '重置成功')
|
||||
}
|
||||
//#endregion
|
||||
|
||||
@@ -251,7 +291,7 @@ export default class index extends Component {
|
||||
<QueryTreeLayout
|
||||
loadData={this.loadTreeData}
|
||||
defaultExpanded={true}
|
||||
onSelect={(key) => this.onSelectTree(key)}
|
||||
onSelect={key => this.onSelectTree(key)}
|
||||
>
|
||||
<Container mode="fluid">
|
||||
<Card bordered={false}>
|
||||
@@ -273,14 +313,13 @@ export default class index extends Component {
|
||||
placeholder="请选择状态"
|
||||
className="w-200"
|
||||
>
|
||||
{
|
||||
this.state.codes.commonStatus.map(item => {
|
||||
return <Select.Option
|
||||
key={item.code}
|
||||
item={item.code}
|
||||
>{item.value}</Select.Option>
|
||||
})
|
||||
}
|
||||
{this.state.codes.commonStatus.map(item => {
|
||||
return (
|
||||
<Select.Option key={item.code} item={item.code}>
|
||||
{item.value}
|
||||
</Select.Option>
|
||||
)
|
||||
})}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Auth>
|
||||
@@ -289,9 +328,11 @@ export default class index extends Component {
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>新增{name}</Button>
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
}
|
||||
renderItem={(record) => this.renderItem(record)}
|
||||
renderItem={record => this.renderItem(record)}
|
||||
/>
|
||||
</Card>
|
||||
</Container>
|
||||
@@ -313,6 +354,24 @@ export default class index extends Component {
|
||||
>
|
||||
<FormBody mode="edit" />
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title="角色授权"
|
||||
action={apiAction.grantRole}
|
||||
ref={this.roleForm}
|
||||
onSuccess={() => this.list.current.onReloadData()}
|
||||
>
|
||||
<RoleForm />
|
||||
</ModalForm>
|
||||
|
||||
<ModalForm
|
||||
title="数据授权"
|
||||
action={apiAction.grantData}
|
||||
ref={this.dataForm}
|
||||
onSuccess={() => this.list.current.onReloadData()}
|
||||
>
|
||||
<DataForm />
|
||||
</ModalForm>
|
||||
</QueryTreeLayout>
|
||||
)
|
||||
}
|
||||
|
||||
99
web-react/src/pages/system/user/role.jsx
Normal file
99
web-react/src/pages/system/user/role.jsx
Normal file
@@ -0,0 +1,99 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Spin, Select } from 'antd'
|
||||
import { AntIcon } from 'components'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { api } from 'common/api'
|
||||
|
||||
export default class role extends Component {
|
||||
state = {
|
||||
// 加载状态
|
||||
loading: true,
|
||||
|
||||
options: {
|
||||
roleData: [],
|
||||
},
|
||||
roles: [],
|
||||
}
|
||||
|
||||
// 表单实例
|
||||
form = React.createRef()
|
||||
|
||||
// 初始化数据
|
||||
id = ''
|
||||
|
||||
/**
|
||||
* mount后回调
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.props.created && this.props.created(this)
|
||||
}
|
||||
async fillData(params) {
|
||||
this.id = params.id
|
||||
//#region 从后端转换成前段所需格式
|
||||
const roleData = await this.loadRoleData()
|
||||
const roles = await this.loadRole(this.id)
|
||||
this.setState({
|
||||
options: {
|
||||
roleData,
|
||||
},
|
||||
roles,
|
||||
})
|
||||
this.form.current.setFieldsValue({
|
||||
id: this.id,
|
||||
grantRoleIdList: roles,
|
||||
})
|
||||
|
||||
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.id) {
|
||||
postData.id = this.id
|
||||
}
|
||||
//#region 从前段转换后端所需格式
|
||||
//#endregion
|
||||
return postData
|
||||
}
|
||||
}
|
||||
async loadRoleData() {
|
||||
const { data } = await api.getRolePage()
|
||||
return data.items
|
||||
}
|
||||
async loadRole(id) {
|
||||
const { data } = await api.sysUserOwnRole({ id })
|
||||
return data
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<Form ref={this.form} className="yo-form">
|
||||
<Spin spinning={this.state.loading} indicator={<AntIcon type="loading" />}>
|
||||
<div className="yo-form-group">
|
||||
<Form.Item label="请选择角色" name="grantRoleIdList">
|
||||
<Select mode="multiple" placeholder="请选择角色">
|
||||
{this.state.options.roleData.map(item => {
|
||||
return (
|
||||
<Select.Option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</Select.Option>
|
||||
)
|
||||
})}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Spin>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user