Auth.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import React, { useEffect } from 'react';
  2. import { Table, Collapse } from 'antd';
  3. import { connect } from 'dva';
  4. import router from 'umi/router';
  5. const { Panel } = Collapse;
  6. function Auth(props) {
  7. const {
  8. dispatch,
  9. authList,
  10. authVersionList,
  11. checkedList,
  12. checkedVersionList,
  13. checkedPagination,
  14. typeOptions,
  15. currentUser,
  16. loading,
  17. } = props;
  18. //监测当前用户,有值时调用列表接口
  19. useEffect(() => {
  20. if (!currentUser.ID) return;
  21. dispatch({
  22. type: 'authList/queryAuthList',
  23. payload: { user_id: currentUser.ID },
  24. });
  25. dispatch({
  26. type: 'auth/queryCheckedList',
  27. payload: { user_id: currentUser.ID, params: { page_size: 99999 } },
  28. });
  29. }, [currentUser]);
  30. useEffect(() => {
  31. //分类列表
  32. dispatch({ type: 'auth/queryClassify' });
  33. }, []);
  34. const columns = [
  35. { title: '流程名称', dataIndex: 'name' },
  36. { title: '所属项目', dataIndex: 'project_name' },
  37. ];
  38. const flowColumns = [
  39. { title: '名称', dataIndex: 'version_name' },
  40. { title: '节点', dataIndex: 'node_name' },
  41. { title: '创建人', dataIndex: 'author' },
  42. {
  43. title: '分类',
  44. render: (_, record) => typeOptions.find(cur => cur.id == record.classify_id)?.name,
  45. },
  46. { title: '操作', render: (_, record) => <a onClick={() => loadNode(record)}>加载</a> },
  47. ];
  48. const loadNode = item => {
  49. //直接从未处理的列表获取version,下面注释的请求得到的不全。大部分没有;
  50. let version = {};
  51. if (item.type == 'checked') {
  52. version = checkedVersionList.find(v => v.id == item.id);
  53. localStorage.excelItem = JSON.stringify(version);
  54. router.push(`/home/detail/${item.project_id}/${item.template_id}?version_id=${version.version_id}`);
  55. } else {
  56. //调用接口获取version信息
  57. dispatch({
  58. type: 'auth/queryVersionByNode',
  59. payload: { template_node_id: item.node_id },
  60. callback: checkedVersionList => {
  61. let version = checkedVersionList.find(v => v.id == item.id) || {};
  62. localStorage.excelItem = JSON.stringify(version);
  63. router.push(`/home/detail/${item.project_id}/${item.template_id}?version_id=${version.version_id}`);
  64. },
  65. });
  66. }
  67. };
  68. const renderUnauth = data => (
  69. <Table columns={flowColumns} dataSource={data} pagination={false} rowKey="id" />
  70. );
  71. const renderAuth = data => (
  72. <Table columns={flowColumns} dataSource={data} pagination={false} rowKey="id" />
  73. );
  74. return (
  75. <Collapse defaultActiveKey={['0']}>
  76. <Panel header="未审批" key="0">
  77. <Table
  78. columns={columns}
  79. dataSource={authList}
  80. expandable={{ expandedRowRender: record => renderUnauth(record.nodes) }}
  81. pagination={false}
  82. rowKey="key"
  83. loading={loading.effects['auth/queryVersionByNode'] || loading.models.authList}
  84. />
  85. </Panel>
  86. <Panel header="已审批" key="1">
  87. <Table
  88. columns={columns}
  89. dataSource={checkedList}
  90. expandable={{ expandedRowRender: record => renderAuth(record.nodes) }}
  91. pagination={false}
  92. rowKey="key"
  93. loading={loading.models.auth}
  94. />
  95. </Panel>
  96. </Collapse>
  97. );
  98. }
  99. export default connect(({ auth, authList, loading, user }) => ({
  100. authList: authList.authList,
  101. authVersionList: authList.authVersionList,
  102. checkedVersionList: auth.checkedVersionList,
  103. checkedList: auth.checkedList.list,
  104. checkedPagination: auth.checkedList.pagination,
  105. typeOptions: auth.typeOptions,
  106. currentUser: user.currentUser,
  107. loading,
  108. }))(Auth);