Flow.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import Flow, { FLOW_TYPE } from '@/components/Flow';
  2. import { connect } from 'dva';
  3. import React, { useEffect } from 'react';
  4. import { UnityAction } from '@/utils/utils';
  5. import { Button, Spin } from 'antd';
  6. import router from 'umi/router';
  7. @connect(({ xflow, user }) => ({
  8. flowDetail: xflow.flowDetail,
  9. currentUser: user.currentUser,
  10. permission: user.currentUser.Permission,
  11. }))
  12. class FlowPage extends React.PureComponent {
  13. constructor(props) {
  14. super(props);
  15. this.state = { spinning: false };
  16. }
  17. onUpdate(node) {
  18. const { dispatch, flowDetail } = this.props;
  19. let params = {
  20. ...node,
  21. id: node.Id,
  22. node_type: node.name == 'custom-circle' ? 1 : 0,
  23. data: JSON.stringify(node.data),
  24. project_id: flowDetail.ProjectId,
  25. template_id: flowDetail.Id,
  26. template_name: flowDetail.Name,
  27. };
  28. delete params.node_id;
  29. dispatch({
  30. type: 'flow/updateNode',
  31. payload: {
  32. templateId: flowDetail.Id,
  33. nodeId: node.Id,
  34. body: params,
  35. },
  36. callback: () => {
  37. // this.setState({ spinning: false });
  38. },
  39. });
  40. }
  41. componentDidMount() {
  42. const {
  43. dispatch,
  44. match: {
  45. params: { flowId },
  46. },
  47. } = this.props;
  48. dispatch({
  49. type: 'xflow/queryOSSData',
  50. });
  51. dispatch({
  52. type: 'xflow/queryBoomFlowDetail',
  53. payload: {
  54. id: flowId,
  55. },
  56. });
  57. dispatch({
  58. type: 'xflow/queryAuditList',
  59. });
  60. dispatch({
  61. type: 'xflow/fetchDepV2',
  62. });
  63. UnityAction.on('NODE_SAVE', nodeConfig => {
  64. this.onUpdate(nodeConfig);
  65. // this.setState({ spinning: true });
  66. });
  67. }
  68. componentWillUnmount() {
  69. UnityAction.off('NODE_SAVE');
  70. }
  71. getEditMode() {
  72. const { flowDetail, permission } = this.props;
  73. return 2;
  74. }
  75. render() {
  76. const { flowDetail, permission, currentUser } = this.props;
  77. let editMode = 2;
  78. if (
  79. // 判断是否有权限
  80. permission['func-01-point-bom-flow'] ||
  81. // 判断是否为管理员
  82. currentUser.IsSuper
  83. ) {
  84. editMode = 1;
  85. }
  86. return (
  87. <Spin spinning={this.state.spinning}>
  88. {/* <Form></Form> */}
  89. <Button style={{ marginBottom: 20 }} onClick={() => router.go(-1)}>
  90. 返回
  91. </Button>
  92. {currentUser.ID && (
  93. <Flow
  94. meta={{ type: 'edit', editMode, flowId: 1 }}
  95. flowDetail={flowDetail}
  96. // onUpdate={node => this.onUpdate(node)}
  97. />
  98. )}
  99. </Spin>
  100. );
  101. }
  102. }
  103. export default FlowPage;