|
@@ -2,49 +2,164 @@ import React, { useEffect, useState } from 'react'
|
|
|
import Helmet from 'react-helmet'
|
|
|
import Container, { ContainerBody } from 'components/Container'
|
|
|
import Box from 'components/Box'
|
|
|
-import { Col, Icon, Row, Table, Tooltip } from 'antd'
|
|
|
-import { PaginationConfig } from 'antd/lib/table'
|
|
|
+import { Button, Col, Divider, Icon, Popconfirm, Row, Table, Tooltip } from 'antd'
|
|
|
+import { ColumnProps } from 'antd/lib/table'
|
|
|
import { compose } from 'redux'
|
|
|
+import request from 'utils/request'
|
|
|
+import api from 'utils/api'
|
|
|
+import DictDatasModal from 'containers/DataManagerDictionary/components/DictDatasModal'
|
|
|
+import { IDictType } from 'containers/DataManagerDictionary/types'
|
|
|
+import DictTypeFormModal from 'containers/DataManagerDictionary/components/DictTypeFormModal'
|
|
|
|
|
|
function DataDictionary() {
|
|
|
- const [screenWidth, setScreenWidth] = useState(
|
|
|
- document.documentElement.clientWidth
|
|
|
- )
|
|
|
+ const [tableLoading, setTableLoading] = useState(false)
|
|
|
+ const [dictTypes, setDictTypes] = useState<IDictType[]>([])
|
|
|
+
|
|
|
+ const [visible, setVisible] = useState(false)
|
|
|
+ const [dictType, setDictType] = useState<string>(null)
|
|
|
+
|
|
|
+ const [dictTypeFormVisible, setDictTypeFormVisible] = useState(false)
|
|
|
+ const [dictTypeFormLoading, setDictTypeFormLoading] = useState(false)
|
|
|
+ const [dictTypeForm, setDictTypeForm] = useState<IDictType>(null)
|
|
|
+
|
|
|
+ const tableColumns: Array<ColumnProps<IDictType>> = [
|
|
|
+ {
|
|
|
+ title: '字典主键',
|
|
|
+ dataIndex: 'dictId'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '字典名称',
|
|
|
+ dataIndex: 'dictName'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '字典类型',
|
|
|
+ dataIndex: 'dictType'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '状态',
|
|
|
+ dataIndex: 'status',
|
|
|
+ render: (text) => (
|
|
|
+ <>
|
|
|
+ {text === 0 && (
|
|
|
+ <span
|
|
|
+ style={{ padding: '2px 4px', background: 'green', color: '#fff' }}
|
|
|
+ >
|
|
|
+ 正常
|
|
|
+ </span>
|
|
|
+ )}
|
|
|
+ {text === 1 && (
|
|
|
+ <span
|
|
|
+ style={{ padding: '2px 4px', background: 'red', color: '#fff' }}
|
|
|
+ >
|
|
|
+ 停用
|
|
|
+ </span>
|
|
|
+ )}
|
|
|
+ </>
|
|
|
+ )
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '备注',
|
|
|
+ dataIndex: 'remark'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '创建时间'
|
|
|
+ // dataIndex: 'isDefault'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ render: (_, data) => (
|
|
|
+ <>
|
|
|
+ <a
|
|
|
+ onClick={() => {
|
|
|
+ setDictTypeFormVisible(true)
|
|
|
+ setDictTypeForm(data)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 编辑
|
|
|
+ </a>
|
|
|
+ <Divider type='vertical' />
|
|
|
+ <a
|
|
|
+ onClick={() => {
|
|
|
+ setDictType(data.dictType)
|
|
|
+ setVisible(true)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 列表
|
|
|
+ </a>
|
|
|
|
|
|
- const handleSetScreenWidth = () => {
|
|
|
- setScreenWidth(document.documentElement.clientWidth)
|
|
|
+ <Divider type='vertical' />
|
|
|
+ <Popconfirm
|
|
|
+ title='确定删除?'
|
|
|
+ placement='bottom'
|
|
|
+ onConfirm={() => handleDeleteDictType(data.dictId)}
|
|
|
+ >
|
|
|
+ <a>删除</a>
|
|
|
+ </Popconfirm>
|
|
|
+ </>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ ]
|
|
|
+
|
|
|
+ const queryDictTypes = async() => {
|
|
|
+ try {
|
|
|
+ setTableLoading(true)
|
|
|
+ const data = await request(api.dictTypes, { method: 'GET' })
|
|
|
+ setDictTypes(data?.payload ?? [])
|
|
|
+ } finally {
|
|
|
+ setTableLoading(false)
|
|
|
+ }
|
|
|
}
|
|
|
- const basePagination: PaginationConfig = {
|
|
|
- defaultPageSize: 20,
|
|
|
- showSizeChanger: true
|
|
|
+ const handleDeleteDictType = async(dictId) => {
|
|
|
+ try {
|
|
|
+ setTableLoading(true)
|
|
|
+ await request(`${api.deleteDictType}/${dictId}`, { method: 'delete' })
|
|
|
+ queryDictTypes()
|
|
|
+ } finally {
|
|
|
+ setTableLoading(false)
|
|
|
+ }
|
|
|
}
|
|
|
- const tablePagination: PaginationConfig = {
|
|
|
- ...basePagination,
|
|
|
- simple: screenWidth <= 768
|
|
|
+ const handleSaveDictType = async(dt: IDictType) => {
|
|
|
+ // // 0=正常,1=停用
|
|
|
+ try {
|
|
|
+ setDictTypeFormLoading(true)
|
|
|
+ const url = dictTypeForm?.dictId
|
|
|
+ ? `${api.updateDictType}/${dictTypeForm.dictId}`
|
|
|
+ : api.createDictType
|
|
|
+ await request(url, {
|
|
|
+ method: dictTypeForm?.dictId ? 'PUT' : 'POST',
|
|
|
+ data: { ...(dictTypeForm ?? {}), ...dt, status: dt.status ? 0 : 1 }
|
|
|
+ })
|
|
|
+ setDictTypeFormVisible(false)
|
|
|
+ queryDictTypes()
|
|
|
+ } finally {
|
|
|
+ setDictTypeFormLoading(false)
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
- window.addEventListener('resize', handleSetScreenWidth, false)
|
|
|
- return () =>
|
|
|
- window.removeEventListener('resize', handleSetScreenWidth, false)
|
|
|
+ queryDictTypes()
|
|
|
}, [])
|
|
|
return (
|
|
|
<Container>
|
|
|
- <Helmet title="数据字典" />
|
|
|
+ <Helmet title='数据字典' />
|
|
|
|
|
|
<ContainerBody>
|
|
|
<Box>
|
|
|
<Box.Header>
|
|
|
<Box.Title>
|
|
|
- <Icon type="bars" />
|
|
|
+ <Icon type='bars' />
|
|
|
数据字典列表
|
|
|
</Box.Title>
|
|
|
<Box.Tools>
|
|
|
- <Tooltip placement="bottom" title="新增">
|
|
|
- {/* <AdminButton */}
|
|
|
- {/* type="primary" */}
|
|
|
- {/* icon="plus" */}
|
|
|
- {/* onClick={this.addView} */}
|
|
|
- {/* /> */}
|
|
|
+ <Tooltip placement='bottom' title='新增'>
|
|
|
+ <Button
|
|
|
+ type='primary'
|
|
|
+ icon='plus'
|
|
|
+ onClick={() => {
|
|
|
+ setDictTypeFormVisible(true)
|
|
|
+ setDictTypeForm(null)
|
|
|
+ }}
|
|
|
+ />
|
|
|
</Tooltip>
|
|
|
</Box.Tools>
|
|
|
</Box.Header>
|
|
@@ -53,18 +168,31 @@ function DataDictionary() {
|
|
|
<Col span={24}>
|
|
|
<Table
|
|
|
bordered
|
|
|
- rowKey="id"
|
|
|
- // loading={loading.view}
|
|
|
- // dataSource={filterViews}
|
|
|
- // columns={tableColumns}
|
|
|
- pagination={tablePagination}
|
|
|
+ rowKey='dictId'
|
|
|
+ loading={tableLoading}
|
|
|
+ dataSource={dictTypes}
|
|
|
+ columns={tableColumns}
|
|
|
+ pagination={false}
|
|
|
// onChange={this.tableChange}
|
|
|
/>
|
|
|
+ <div style={{ height: 20 }} />
|
|
|
</Col>
|
|
|
</Row>
|
|
|
</Box.Body>
|
|
|
</Box>
|
|
|
</ContainerBody>
|
|
|
+ <DictDatasModal
|
|
|
+ visible={visible}
|
|
|
+ dictType={dictType}
|
|
|
+ onCancel={() => setVisible(false)}
|
|
|
+ />
|
|
|
+ <DictTypeFormModal
|
|
|
+ visible={dictTypeFormVisible}
|
|
|
+ loading={dictTypeFormLoading}
|
|
|
+ fromView={dictTypeForm}
|
|
|
+ onSave={handleSaveDictType}
|
|
|
+ onCancel={() => setDictTypeFormVisible(false)}
|
|
|
+ />
|
|
|
</Container>
|
|
|
)
|
|
|
}
|