DictDatasModal.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { useEffect, useState } from 'react'
  21. import { Modal, Form, Button, Input, Col, Table, Row, Divider } from 'antd'
  22. import { FormComponentProps } from 'antd/lib/form'
  23. import { ICatalogue, IDictData, IViewBase } from '../types'
  24. import { ColumnProps } from 'antd/lib/table'
  25. import ButtonGroup from 'antd/es/button/button-group'
  26. import api from 'utils/api'
  27. import request from 'utils/request'
  28. interface IDictDatasModalProps {
  29. visible: boolean
  30. dictType: string
  31. onCancel: () => void
  32. }
  33. const DictDatasModal = (props: IDictDatasModalProps) => {
  34. const { visible, onCancel, dictType } = props
  35. const [tableLoading, setTableLoading] = useState(false)
  36. const [dictDatas, setDictDatas] = useState<IDictData[]>([])
  37. const queryDictDatas = async() => {
  38. if (!dictType) {
  39. return
  40. }
  41. try {
  42. setTableLoading(true)
  43. const data = await request(api.dictDatas + `?dictType=${dictType}`, { method: 'GET' })
  44. setDictDatas(data?.payload ?? [])
  45. } finally {
  46. setTableLoading(false)
  47. }
  48. }
  49. const tableColumns: Array<ColumnProps<IDictData>> = [
  50. {
  51. title: '字典编码',
  52. dataIndex: 'dictCode'
  53. },
  54. {
  55. title: '字典标签',
  56. dataIndex: 'dictLabel'
  57. },
  58. {
  59. title: '字典键值',
  60. dataIndex: 'dictValue'
  61. },
  62. {
  63. title: '字典排序',
  64. dataIndex: 'dictSort'
  65. },
  66. {
  67. title: '状态',
  68. dataIndex: 'status',
  69. render: (text) => (
  70. <>
  71. {text === 0 && <span style={{ padding: '2px 4px', background: 'green', color: '#fff' }}>正常</span>}
  72. {text === 1 && <span style={{ padding: '2px 4px', background: 'red', color: '#fff' }}>停用</span>}
  73. </>
  74. )
  75. },
  76. {
  77. title: '备注',
  78. dataIndex: 'remark'
  79. },
  80. {
  81. title: '创建时间'
  82. // dataIndex: 'isDefault'
  83. },
  84. {
  85. title: '操作',
  86. render: () => {
  87. return (
  88. <>
  89. <a>编辑</a>
  90. <Divider type='vertical' />
  91. <a>删除</a>
  92. </>
  93. )
  94. }
  95. }
  96. ]
  97. useEffect(() => {
  98. queryDictDatas()
  99. }, [dictType])
  100. return (
  101. <Modal
  102. title='数据字典数据'
  103. // wrapClassName='ant-modal-small'
  104. visible={visible}
  105. footer={null}
  106. onCancel={onCancel}
  107. destroyOnClose
  108. width={'80%'}
  109. >
  110. <Row>
  111. <Col span={24}>
  112. <Table
  113. bordered
  114. rowKey='dictCode'
  115. loading={tableLoading}
  116. dataSource={dictDatas}
  117. columns={tableColumns}
  118. pagination={false}
  119. // onChange={this.tableChange}
  120. />
  121. </Col>
  122. </Row>
  123. </Modal>
  124. )
  125. }
  126. export default (DictDatasModal)