index.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. import React, { useEffect, useState } from 'react'
  2. import Container, { ContainerBody } from 'components/Container'
  3. import Helmet from 'react-helmet'
  4. import Box from 'components/Box'
  5. import styles from 'containers/DataManagerView/index.less'
  6. import {
  7. Button,
  8. Divider,
  9. Dropdown,
  10. Icon,
  11. Menu,
  12. message,
  13. Popconfirm,
  14. Spin,
  15. Table
  16. } from 'antd'
  17. import classnames from 'classnames'
  18. import request from 'utils/request'
  19. import api from 'utils/api'
  20. import { ColumnProps } from 'antd/lib/table'
  21. import {
  22. IClassification,
  23. IQualityTask
  24. } from 'containers/DataGovernanceQualityAudit/types'
  25. import ClassificationsFormModal from 'containers/DataGovernanceQualityAudit/components/ClassificationsFormModal'
  26. import QualityTaskFormModal from 'containers/DataGovernanceQualityAudit/components/QualityTaskFormModal'
  27. import ScheduleFormModal from 'containers/DataGovernanceQualityAudit/components/ScheduleFormModal'
  28. import header from 'containers/Display/Editor/Header'
  29. import SubjectModal from 'containers/DataGovernanceQualityAudit/components/SubjectModal'
  30. export default function DataGovernanceQualityAudit() {
  31. const [tableLoading, setTableLoading] = useState(false)
  32. const [treeLoading, setTreeLoading] = useState(false)
  33. const [selectedKey, setSelectedKey] = useState<number>()
  34. const [qualityTasks, setQualityTasks] = useState<IQualityTask[]>([])
  35. const [qtVisible, setQtVisible] = useState(false)
  36. const [qtLoading, setQtLoading] = useState(false)
  37. // eslint-disable-next-line no-undef
  38. const [qtForm, setQtForm] = useState<Partial<IQualityTask>>({})
  39. const [classifications, setClassifications] = useState<IClassification[]>([])
  40. const [cfVisible, setCfVisible] = useState(false)
  41. const [cfLoading, setCfLoading] = useState(false)
  42. const [cfForm, setCfForm] = useState<IClassification>({})
  43. const [scVisible, setScVisible] = useState(false)
  44. const [scLoading, setSCLoading] = useState(false)
  45. const [scForm, setSCForm] = useState<IClassification>({})
  46. const tableColumns: Array<ColumnProps<IQualityTask>> = [
  47. {
  48. title: '任务名称',
  49. dataIndex: 'taskName'
  50. },
  51. {
  52. title: '元数据名称',
  53. dataIndex: 'metadataName'
  54. },
  55. {
  56. title: '稽核字段个数',
  57. dataIndex: 'standardName'
  58. },
  59. {
  60. title: '操作',
  61. render: (_, data) => (
  62. <>
  63. <a
  64. onClick={() => {
  65. setQtVisible(true)
  66. setQtForm(data)
  67. }}
  68. >
  69. 编辑
  70. </a>
  71. <Divider type="vertical" />
  72. <Dropdown
  73. overlay={
  74. <Menu>
  75. <Menu.Item key="0" onClick={() => setScVisible(true)}>
  76. 设置调度
  77. </Menu.Item>
  78. <Menu.Item key="1">
  79. <Popconfirm
  80. title="确定立即稽查吗?"
  81. placement="bottom"
  82. onConfirm={() => handleSetDispatchRightNow(data)}
  83. >
  84. <a>立即稽查</a>
  85. </Popconfirm>
  86. </Menu.Item>
  87. <Menu.Item key="2">修改</Menu.Item>
  88. <Menu.Item key="3">
  89. <Popconfirm
  90. title="确定删除?"
  91. placement="bottom"
  92. // onConfirm
  93. >
  94. <a>删除</a>
  95. </Popconfirm>
  96. </Menu.Item>
  97. </Menu>
  98. }
  99. >
  100. <a>
  101. {' '}
  102. 更多 <Icon type="down" />
  103. </a>
  104. </Dropdown>
  105. </>
  106. )
  107. }
  108. ]
  109. const handleEditTreeItem = (form: IClassification) => {
  110. setCfForm(form)
  111. setCfVisible(true)
  112. }
  113. const handleDeleteTreeItem = async (c: IClassification) => {
  114. try {
  115. setTreeLoading(true)
  116. const data = await request(`${api.deleteAuditClassification}${c.id}`, {
  117. method: 'DELETE'
  118. })
  119. // @ts-ignore
  120. if (data?.header?.code === 200) {
  121. message.success({ content: '删除成功' })
  122. await queryClassifications()
  123. } else {
  124. // @ts-ignore
  125. // tslint:disable-next-line:no-unused-expression
  126. data?.header?.msg && message.error({ content: data?.header?.msg })
  127. }
  128. } finally {
  129. setTreeLoading(false)
  130. }
  131. }
  132. const renderTree = (catalogues: IClassification[]) => (
  133. <>
  134. {catalogues.map((c, idx) => (
  135. <div
  136. key={c.id ?? idx}
  137. className={classnames(styles.treeNode, {
  138. [styles.treeNodeSelected]: selectedKey === c.id
  139. })}
  140. >
  141. <span
  142. className={styles.treeNodeLeft}
  143. onClick={() => {
  144. setSelectedKey(c.id)
  145. }}
  146. >
  147. <Icon type="file" />
  148. {c.name}
  149. </span>
  150. <Dropdown
  151. overlay={() => (
  152. <Menu>
  153. <Menu.Item key="0" onClick={() => handleEditTreeItem(c)}>
  154. 编辑
  155. </Menu.Item>
  156. <Menu.Item key="1">
  157. <Popconfirm
  158. title="确定删除?"
  159. placement="bottom"
  160. onConfirm={() => handleDeleteTreeItem(c)}
  161. >
  162. <a>删除</a>
  163. </Popconfirm>
  164. </Menu.Item>
  165. </Menu>
  166. )}
  167. trigger={['click']}
  168. >
  169. <Icon type="more" />
  170. </Dropdown>
  171. </div>
  172. ))}
  173. </>
  174. )
  175. const handleSetDispatchRightNow = async (data: IQualityTask) => {
  176. try {
  177. setTableLoading(true)
  178. const result = await request(`${api.setDispatchRightNow}${data.id}`, {
  179. method: 'GET'
  180. })
  181. console.log(result)
  182. // @ts-ignore
  183. if (result.header.code === 200) {
  184. message.success({ content: '立即稽核完成' })
  185. } else {
  186. // @ts-ignore
  187. // tslint:disable-next-line:no-unused-expression
  188. result?.header?.msg && message.error({ content: result.header.msg })
  189. }
  190. } finally {
  191. setTableLoading(false)
  192. }
  193. }
  194. const queryClassifications = async () => {
  195. try {
  196. setTreeLoading(true)
  197. const data = await request(api.getAuditClassification, { method: 'GET' })
  198. // @ts-ignore
  199. setClassifications(data?.payload ?? [])
  200. // @ts-ignore
  201. setSelectedKey(data?.payload?.[0]?.id)
  202. } finally {
  203. setTreeLoading(false)
  204. }
  205. }
  206. const queryQualityTasks = async () => {
  207. try {
  208. setTableLoading(true)
  209. const data = await request(`${api.getQualityTask}?pId=${selectedKey}`, {
  210. method: 'GET'
  211. })
  212. // @ts-ignore
  213. setQualityTasks(data?.payload ?? [])
  214. } finally {
  215. setTableLoading(false)
  216. }
  217. }
  218. const handleSaveCfForm = async (form: IClassification) => {
  219. try {
  220. setCfLoading(true)
  221. const url = cfForm.id
  222. ? api.updateAuditClassification + cfForm.id
  223. : api.createAuditClassification
  224. const result = await request(url, {
  225. method: cfForm.id ? 'PUT' : 'POST',
  226. data: { ...cfForm, ...form }
  227. })
  228. // @ts-ignore
  229. if (result?.header?.code === 200) {
  230. setCfVisible(false)
  231. await queryClassifications()
  232. }
  233. } finally {
  234. setCfLoading(false)
  235. }
  236. }
  237. const handleSaveQtForm = async (view) => {
  238. try {
  239. setQtLoading(true)
  240. const url = qtForm?.id
  241. ? api.updateQualityTask + qtForm?.id
  242. : api.createQualityTask
  243. const result = await request(url, {
  244. method: qtForm?.id ? 'PUT' : 'POST',
  245. data: { ...qtForm, ...view }
  246. })
  247. // @ts-ignore
  248. if (result?.header?.code === 200) {
  249. setQtVisible(false)
  250. await queryQualityTasks()
  251. }
  252. } finally {
  253. setQtLoading(false)
  254. }
  255. }
  256. useEffect(() => {
  257. queryClassifications()
  258. }, [])
  259. useEffect(() => {
  260. if (selectedKey) {
  261. queryQualityTasks()
  262. }
  263. }, [selectedKey])
  264. return (
  265. <Container>
  266. <Helmet title="质量稽核" />
  267. <ContainerBody>
  268. <Box>
  269. <Box.Header>
  270. <Box.Title>质量稽核</Box.Title>
  271. </Box.Header>
  272. <Box.Body>
  273. <div className={styles.treeTableContainer}>
  274. <div className={styles.treeContainer}>
  275. <div className={styles.treeTitle}>
  276. <h6>数据质量</h6>
  277. <div
  278. className={styles.treePlusNode}
  279. onClick={() => {
  280. setCfForm({})
  281. setCfVisible(true)
  282. }}
  283. >
  284. <Icon type="plus" />
  285. </div>
  286. </div>
  287. <div className={styles.treeContent}>
  288. <Spin spinning={treeLoading}>
  289. {renderTree(classifications)}
  290. </Spin>
  291. </div>
  292. </div>
  293. <div style={{ flex: 1 }}>
  294. <div style={{ padding: '0 0 20px' }}>
  295. <Button
  296. type="primary"
  297. icon="plus"
  298. onClick={() => {
  299. setQtVisible(true)
  300. setQtForm(null)
  301. }}
  302. >
  303. 新增
  304. </Button>
  305. </div>
  306. <Table
  307. style={{ flex: 1 }}
  308. bordered
  309. rowKey="id"
  310. loading={tableLoading}
  311. dataSource={qualityTasks}
  312. columns={tableColumns}
  313. pagination={false}
  314. // onChange={this.tableChange}
  315. />
  316. </div>
  317. </div>
  318. <br />
  319. </Box.Body>
  320. </Box>
  321. </ContainerBody>
  322. <ClassificationsFormModal
  323. visible={cfVisible}
  324. formView={cfForm}
  325. onSave={handleSaveCfForm}
  326. loading={cfLoading}
  327. onCancel={() => setCfVisible(false)}
  328. />
  329. <QualityTaskFormModal
  330. pId={selectedKey}
  331. visible={qtVisible}
  332. formView={qtForm}
  333. onSave={handleSaveQtForm}
  334. loading={qtLoading}
  335. onCancel={() => setQtVisible(false)}
  336. />
  337. <ScheduleFormModal
  338. visible={scVisible}
  339. loading={scLoading}
  340. formView={scForm}
  341. onSave={undefined}
  342. onCancel={() => setScVisible(false)}
  343. />
  344. </Container>
  345. )
  346. }