|
| 1 | +import {HtmlNode, HtmlNodeModel} from '@logicflow/core'; |
| 2 | +import React from "react"; |
| 3 | +import ReactDOM from "react-dom/client"; |
| 4 | +import "./index.scss"; |
| 5 | +import {InboxOutlined, SettingFilled} from "@ant-design/icons"; |
| 6 | +import CirculateSettingPanel from "@/components/Flow/panel/circulate"; |
| 7 | + |
| 8 | +type CirculateProperties = { |
| 9 | + id: string; |
| 10 | + name: string; |
| 11 | + code: string; |
| 12 | + type: string; |
| 13 | + view: string; |
| 14 | + operatorMatcher: string; |
| 15 | + editable: boolean; |
| 16 | + titleGenerator: string; |
| 17 | + errTrigger: string; |
| 18 | + approvalType: string; |
| 19 | + timeout: number; |
| 20 | +} |
| 21 | + |
| 22 | +interface CirculateProps { |
| 23 | + name: string; |
| 24 | + code?: string; |
| 25 | + update?: (values: any) => void; |
| 26 | + settingVisible?: boolean; |
| 27 | + properties?: CirculateProperties; |
| 28 | +} |
| 29 | + |
| 30 | +export const CirculateView: React.FC<CirculateProps> = (props) => { |
| 31 | + const [visible, setVisible] = React.useState(false); |
| 32 | + |
| 33 | + return ( |
| 34 | + <div className="circulate-node"> |
| 35 | + <InboxOutlined |
| 36 | + className={"icon"} |
| 37 | + /> |
| 38 | + <div> |
| 39 | + <span className={"code"}> |
| 40 | + {props.code && ( |
| 41 | + <> ({props.code})</> |
| 42 | + )} |
| 43 | + </span> |
| 44 | + <span className={"title"}>{props.name}</span> |
| 45 | + </div> |
| 46 | + |
| 47 | + {props.settingVisible && ( |
| 48 | + <SettingFilled |
| 49 | + className={"setting"} |
| 50 | + onClick={() => { |
| 51 | + setVisible(true); |
| 52 | + }} |
| 53 | + /> |
| 54 | + )} |
| 55 | + |
| 56 | + <CirculateSettingPanel |
| 57 | + visible={visible} |
| 58 | + setVisible={setVisible} |
| 59 | + properties={props.properties} |
| 60 | + onSettingChange={(values) => { |
| 61 | + props.update && props.update(values); |
| 62 | + }} |
| 63 | + /> |
| 64 | + </div> |
| 65 | + ); |
| 66 | +} |
| 67 | + |
| 68 | +class CirculateModel extends HtmlNodeModel { |
| 69 | + setAttributes() { |
| 70 | + this.width = 200; |
| 71 | + this.height = 45; |
| 72 | + this.text.editable = false; |
| 73 | + this.menu = []; |
| 74 | + |
| 75 | + this.sourceRules = [ |
| 76 | + { |
| 77 | + message: `不允许输出`, |
| 78 | + validate: (sourceNode: any, targetNode: any, sourceAnchor, targetAnchor) => { |
| 79 | + const edges = this.graphModel.getNodeOutgoingEdge(sourceNode.id); |
| 80 | + if (edges.length >= 1) { |
| 81 | + return false; |
| 82 | + } else { |
| 83 | + return true; |
| 84 | + } |
| 85 | + }, |
| 86 | + }, |
| 87 | + ]; |
| 88 | + |
| 89 | + this.anchorsOffset = [ |
| 90 | + [this.width / 2, 0], |
| 91 | + [0, this.height / 2], |
| 92 | + [-this.width / 2, 0], |
| 93 | + [0, -this.height / 2], |
| 94 | + ]; |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | +} |
| 99 | + |
| 100 | +class CirculateNode extends HtmlNode { |
| 101 | + setHtml(rootEl: SVGForeignObjectElement) { |
| 102 | + const {properties} = this.props.model as HtmlNodeModel<CirculateProperties>; |
| 103 | + const div = document.createElement('div'); |
| 104 | + ReactDOM.createRoot(div).render( |
| 105 | + <CirculateView |
| 106 | + name={properties.name} |
| 107 | + code={properties.code} |
| 108 | + properties={properties} |
| 109 | + settingVisible={true} |
| 110 | + update={async (values) => { |
| 111 | + this.props.model.setProperties(values); |
| 112 | + }}/>, |
| 113 | + ); |
| 114 | + //需要清空 |
| 115 | + rootEl.innerHTML = ''; |
| 116 | + rootEl.appendChild(div); |
| 117 | + super.setHtml(rootEl); |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +export default { |
| 122 | + type: 'circulate-node', |
| 123 | + view: CirculateNode, |
| 124 | + model: CirculateModel, |
| 125 | +}; |
| 126 | + |
0 commit comments