Merge branch 'master' of http://118.178.224.202:3000/ewide/ewide_core
This commit is contained in:
@@ -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.sysAreaPage,
|
||||
add: api.sysAreaAdd,
|
||||
edit: api.sysAreaEdit,
|
||||
delete: api.sysAreaDelete
|
||||
delete: api.sysAreaDelete,
|
||||
}
|
||||
|
||||
const name = '区域'
|
||||
|
||||
export default class index extends Component {
|
||||
|
||||
state = {
|
||||
codes: {
|
||||
dicAreacodeType: []
|
||||
}
|
||||
areacodeType: [],
|
||||
},
|
||||
}
|
||||
|
||||
// 表格实例
|
||||
@@ -41,37 +48,43 @@ export default class index extends Component {
|
||||
title: '区域类型',
|
||||
dataIndex: 'levelType',
|
||||
sorter: true,
|
||||
render: text => (<>{this.bindCodeValue(text, 'dic_areacode_type')}</>)
|
||||
width: 50,
|
||||
render: text => <>{this.bindCodeValue(text, 'areacode_type')}</>,
|
||||
},
|
||||
{
|
||||
title: '区域名称',
|
||||
dataIndex: 'name',
|
||||
width: 100,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '区域编号',
|
||||
dataIndex: 'code',
|
||||
width: 80,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '行政编号',
|
||||
dataIndex: 'adCode',
|
||||
width: 80,
|
||||
sorter: true,
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'note',
|
||||
width: 200,
|
||||
sorter: false,
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sort',
|
||||
width: 80,
|
||||
sorter: true,
|
||||
},
|
||||
]
|
||||
/**
|
||||
* 构造函数,在渲染前动态添加操作字段等
|
||||
* @param {*} props
|
||||
* @param {*} props
|
||||
*/
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -83,20 +96,22 @@ export default class index extends Component {
|
||||
title: '操作',
|
||||
width: 150,
|
||||
dataIndex: 'actions',
|
||||
render: (text, record) => (<QueryTableActions>
|
||||
<Auth auth="sysArea:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysArea:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>)
|
||||
render: (text, record) => (
|
||||
<QueryTableActions>
|
||||
<Auth auth="sysArea:edit">
|
||||
<a onClick={() => this.onOpen(this.editForm, record)}>编辑</a>
|
||||
</Auth>
|
||||
<Auth auth="sysArea:delete">
|
||||
<Popconfirm
|
||||
placement="topRight"
|
||||
title="是否确认删除"
|
||||
onConfirm={() => this.onDelete(record)}
|
||||
>
|
||||
<a>删除</a>
|
||||
</Popconfirm>
|
||||
</Auth>
|
||||
</QueryTableActions>
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -104,9 +119,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)
|
||||
@@ -118,31 +133,33 @@ export default class index extends Component {
|
||||
*/
|
||||
componentDidMount() {
|
||||
this.table.current.onLoading()
|
||||
getDictData('dic_areacode_type').then(res => {
|
||||
this.setState({
|
||||
codes: res
|
||||
}, () => {
|
||||
this.table.current.onLoadData()
|
||||
})
|
||||
getDictData('areacode_type').then(res => {
|
||||
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,
|
||||
pcode: this.selectCode
|
||||
pcode: this.selectCode,
|
||||
}
|
||||
//首次加载根据code列升序排序
|
||||
if (!params.sortField) {
|
||||
params.sortField = 'code';
|
||||
params.sortOrder = 'ascend';
|
||||
params.sortField = 'code'
|
||||
params.sortOrder = 'ascend'
|
||||
}
|
||||
const { data } = await apiAction.page({
|
||||
...params,
|
||||
@@ -164,7 +181,7 @@ export default class index extends Component {
|
||||
/**
|
||||
* 树节点选中事件
|
||||
* [必要]
|
||||
* @param {*} id
|
||||
* @param {*} id
|
||||
*/
|
||||
onSelectTree(code) {
|
||||
this.selectCode = code
|
||||
@@ -173,15 +190,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
|
||||
}
|
||||
@@ -191,21 +208,21 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 打开新增/编辑弹窗
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
* @param {*} modal
|
||||
* @param {*} record
|
||||
*/
|
||||
onOpen(modal, record) {
|
||||
modal.current.open({
|
||||
pcode: this.pcode,
|
||||
record
|
||||
record,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 对表格上的操作进行统一处理
|
||||
* [异步]
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
* @param {*} action
|
||||
* @param {*} successMessage
|
||||
*/
|
||||
async onAction(action, successMessage) {
|
||||
this.table.current.onLoading()
|
||||
@@ -220,13 +237,10 @@ export default class index extends Component {
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param {*} record
|
||||
* @param {*} record
|
||||
*/
|
||||
onDelete(record) {
|
||||
this.onAction(
|
||||
apiAction.delete(record),
|
||||
'删除成功'
|
||||
)
|
||||
this.onAction(apiAction.delete(record), '删除成功')
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -234,7 +248,7 @@ export default class index extends Component {
|
||||
<QueryTreeLayout
|
||||
loadData={this.loadTreeData}
|
||||
defaultExpanded={true}
|
||||
onSelect={(key) => this.onSelectTree(key)}
|
||||
onSelect={key => this.onSelectTree(key)}
|
||||
replaceFields={{ value: 'code', title: 'name', children: 'children' }}
|
||||
>
|
||||
<Container mode="fluid">
|
||||
@@ -259,12 +273,12 @@ export default class index extends Component {
|
||||
<Button
|
||||
icon={<AntIcon type="plus" />}
|
||||
onClick={() => this.onOpen(this.addForm)}
|
||||
>新增{name}</Button>
|
||||
>
|
||||
新增{name}
|
||||
</Button>
|
||||
</Auth>
|
||||
}
|
||||
>
|
||||
|
||||
</QueryTable>
|
||||
></QueryTable>
|
||||
</Card>
|
||||
</Container>
|
||||
<ModalForm
|
||||
@@ -287,4 +301,4 @@ export default class index extends Component {
|
||||
</QueryTreeLayout>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user