index.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import React, { useEffect, useState } from 'react'
  2. import Helmet from 'react-helmet'
  3. import Container, { ContainerBody } from 'components/Container'
  4. import Box from 'components/Box'
  5. import { Button, Col, Divider, Icon, Popconfirm, Row, Table, Tooltip } from 'antd'
  6. import { ColumnProps } from 'antd/lib/table'
  7. import { compose } from 'redux'
  8. import request from 'utils/request'
  9. import api from 'utils/api'
  10. import DictDatasModal from 'containers/DataManagerDictionary/components/DictDatasModal'
  11. import { IDictType } from 'containers/DataManagerDictionary/types'
  12. import DictTypeFormModal from 'containers/DataManagerDictionary/components/DictTypeFormModal'
  13. function DataDictionary() {
  14. const [tableLoading, setTableLoading] = useState(false)
  15. const [dictTypes, setDictTypes] = useState<IDictType[]>([])
  16. const [visible, setVisible] = useState(false)
  17. const [dictType, setDictType] = useState<string>(null)
  18. const [dictTypeFormVisible, setDictTypeFormVisible] = useState(false)
  19. const [dictTypeFormLoading, setDictTypeFormLoading] = useState(false)
  20. const [dictTypeForm, setDictTypeForm] = useState<IDictType>(null)
  21. const tableColumns: Array<ColumnProps<IDictType>> = [
  22. {
  23. title: '字典主键',
  24. dataIndex: 'dictId'
  25. },
  26. {
  27. title: '字典名称',
  28. dataIndex: 'dictName'
  29. },
  30. {
  31. title: '字典类型',
  32. dataIndex: 'dictType'
  33. },
  34. {
  35. title: '状态',
  36. dataIndex: 'status',
  37. render: (text) => (
  38. <>
  39. {text === 0 && (
  40. <span
  41. style={{ padding: '2px 4px', background: 'green', color: '#fff' }}
  42. >
  43. 正常
  44. </span>
  45. )}
  46. {text === 1 && (
  47. <span
  48. style={{ padding: '2px 4px', background: 'red', color: '#fff' }}
  49. >
  50. 停用
  51. </span>
  52. )}
  53. </>
  54. )
  55. },
  56. {
  57. title: '备注',
  58. dataIndex: 'remark'
  59. },
  60. {
  61. title: '创建时间'
  62. // dataIndex: 'isDefault'
  63. },
  64. {
  65. title: '操作',
  66. render: (_, data) => (
  67. <>
  68. <a
  69. onClick={() => {
  70. setDictTypeFormVisible(true)
  71. setDictTypeForm(data)
  72. }}
  73. >
  74. 编辑
  75. </a>
  76. <Divider type='vertical' />
  77. <a
  78. onClick={() => {
  79. setDictType(data.dictType)
  80. setVisible(true)
  81. }}
  82. >
  83. 列表
  84. </a>
  85. <Divider type='vertical' />
  86. <Popconfirm
  87. title='确定删除?'
  88. placement='bottom'
  89. onConfirm={() => handleDeleteDictType(data.dictId)}
  90. >
  91. <a>删除</a>
  92. </Popconfirm>
  93. </>
  94. )
  95. }
  96. ]
  97. const queryDictTypes = async() => {
  98. try {
  99. setTableLoading(true)
  100. const data = await request(api.dictTypes, { method: 'GET' })
  101. setDictTypes(data?.payload ?? [])
  102. } finally {
  103. setTableLoading(false)
  104. }
  105. }
  106. const handleDeleteDictType = async(dictId) => {
  107. try {
  108. setTableLoading(true)
  109. await request(`${api.deleteDictType}/${dictId}`, { method: 'delete' })
  110. queryDictTypes()
  111. } finally {
  112. setTableLoading(false)
  113. }
  114. }
  115. const handleSaveDictType = async(dt: IDictType) => {
  116. // // 0=正常,1=停用
  117. try {
  118. setDictTypeFormLoading(true)
  119. const url = dictTypeForm?.dictId
  120. ? `${api.updateDictType}/${dictTypeForm.dictId}`
  121. : api.createDictType
  122. await request(url, {
  123. method: dictTypeForm?.dictId ? 'PUT' : 'POST',
  124. data: { ...(dictTypeForm ?? {}), ...dt, status: dt.status ? 0 : 1 }
  125. })
  126. setDictTypeFormVisible(false)
  127. queryDictTypes()
  128. } finally {
  129. setDictTypeFormLoading(false)
  130. }
  131. }
  132. useEffect(() => {
  133. queryDictTypes()
  134. }, [])
  135. return (
  136. <Container>
  137. <Helmet title='数据字典' />
  138. <ContainerBody>
  139. <Box>
  140. <Box.Header>
  141. <Box.Title>
  142. <Icon type='bars' />
  143. 数据字典列表
  144. </Box.Title>
  145. <Box.Tools>
  146. <Tooltip placement='bottom' title='新增'>
  147. <Button
  148. type='primary'
  149. icon='plus'
  150. onClick={() => {
  151. setDictTypeFormVisible(true)
  152. setDictTypeForm(null)
  153. }}
  154. />
  155. </Tooltip>
  156. </Box.Tools>
  157. </Box.Header>
  158. <Box.Body>
  159. <Row>
  160. <Col span={24}>
  161. <Table
  162. bordered
  163. rowKey='dictId'
  164. loading={tableLoading}
  165. dataSource={dictTypes}
  166. columns={tableColumns}
  167. pagination={false}
  168. // onChange={this.tableChange}
  169. />
  170. <div style={{ height: 20 }} />
  171. </Col>
  172. </Row>
  173. </Box.Body>
  174. </Box>
  175. </ContainerBody>
  176. <DictDatasModal
  177. visible={visible}
  178. dictType={dictType}
  179. onCancel={() => setVisible(false)}
  180. />
  181. <DictTypeFormModal
  182. visible={dictTypeFormVisible}
  183. loading={dictTypeFormLoading}
  184. fromView={dictTypeForm}
  185. onSave={handleSaveDictType}
  186. onCancel={() => setDictTypeFormVisible(false)}
  187. />
  188. </Container>
  189. )
  190. }
  191. // const mapDispatchToProps = (dispatch: Dispatch<ViewActionType>) => ({
  192. // onLoadViews: (projectId) => dispatch(ViewActions.loadViews(projectId)),
  193. // onDeleteView: (viewId, resolve) => dispatch(ViewActions.deleteView(viewId, resolve)),
  194. // onCopyView: (view, resolve) => dispatch(ViewActions.copyView(view, resolve)),
  195. // onCheckName: (data, resolve, reject) => dispatch(checkNameUniqueAction('view', data, resolve, reject))
  196. // })
  197. //
  198. // const mapStateToProps = createStructuredSelector({
  199. // views: makeSelectViews(),
  200. // currentProject: makeSelectCurrentProject(),
  201. // loading: makeSelectLoading()
  202. // })
  203. // const withConnect = connect<IViewListStateProps, IViewListDispatchProps, RouteComponentWithParams>(mapStateToProps, mapDispatchToProps)
  204. // const withReducer = injectReducer({ key: 'view', reducer })
  205. // const withSaga = injectSaga({ key: 'view', saga: sagas })
  206. export default compose()(DataDictionary)
  207. // withReducer,
  208. // withSaga,
  209. // withConnect