Commit 9110e068 authored by 邓超's avatar 邓超

fix: 工作流编辑器添加序号并修改颜色

parent af66ac75
Pipeline #47519 skipped with stages
...@@ -27,6 +27,7 @@ const FlowChart = props => { ...@@ -27,6 +27,7 @@ const FlowChart = props => {
Lines: [], Lines: [],
}); // 组件内得流程图数据 }); // 组件内得流程图数据
const [showLeaveTip, setShowLeaveTip] = useState(false); // 离开路由是否又提醒 const [showLeaveTip, setShowLeaveTip] = useState(false); // 离开路由是否又提醒
const [newSerialNo, setNewSerialNo] = useState(0);
const objGo = go.GraphObject.make; const objGo = go.GraphObject.make;
// 监听删除,给删除数组里添加删除id // 监听删除,给删除数组里添加删除id
useEffect(() => { useEffect(() => {
...@@ -165,16 +166,34 @@ const FlowChart = props => { ...@@ -165,16 +166,34 @@ const FlowChart = props => {
new go.Binding('height', 'NodeType', v => (v === '0' ? 75 : 105)), new go.Binding('height', 'NodeType', v => (v === '0' ? 75 : 105)),
new go.Binding('figure', 'NodeType', v => (v === '0' ? 'RoundedRectangle' : 'Ellipse')), new go.Binding('figure', 'NodeType', v => (v === '0' ? 'RoundedRectangle' : 'Ellipse')),
new go.Binding('strokeWidth', 'NodeType', v => (v === '0' ? 1 : 15)), new go.Binding('strokeWidth', 'NodeType', v => (v === '0' ? 1 : 15)),
new go.Binding('stroke', 'NodeType', v => (v === '0' ? '#0587E0' : '#D7EFFF')),
new go.Binding('stroke', 'NodeType', v => {
// 普通节点
if (v === '0') {
return '#0587E0';
}
// 开始节点
if (v === '1') {
return '#d7efff';
}
// 结束节点
if (v === '2') {
return '#d7efff';
}
return '';
}),
new go.Binding('fill', 'NodeType', v => { new go.Binding('fill', 'NodeType', v => {
// 普通节点
if (v === '0') { if (v === '0') {
return '#DCF2FE'; return '#FAAD14';
} }
// 开始节点
if (v === '1') { if (v === '1') {
return '#077BD6'; return '#0AC03D';
} }
// 结束节点
if (v === '2') { if (v === '2') {
return '#077BD6'; return '#8585FF';
} }
return ''; return '';
}), }),
...@@ -184,8 +203,8 @@ const FlowChart = props => { ...@@ -184,8 +203,8 @@ const FlowChart = props => {
objGo( objGo(
go.TextBlock, go.TextBlock,
{ maxSize: new go.Size(130, NaN), wrap: go.TextBlock.WrapFit }, { maxSize: new go.Size(130, NaN), wrap: go.TextBlock.WrapFit },
new go.Binding('text', 'NodeName'), new go.Binding('text', 'NodeName', v => v.slice(0, 6)),
new go.Binding('stroke', 'NodeType', v => (v === '0' ? '#077BD6' : '#fff')), new go.Binding('stroke', 'NodeType', v => (v === '0' ? '#fff' : '#fff')),
), ),
objGo( objGo(
go.Picture, go.Picture,
...@@ -282,19 +301,62 @@ const FlowChart = props => { ...@@ -282,19 +301,62 @@ const FlowChart = props => {
}; };
// 新增节点 // 新增节点
const addNode = () => { const addNode = () => {
const list = JSON.parse(diagram.model.toJson()).nodeDataArray;
console.log(list, 'list');
let newNum;
if (list.length > 0) {
// eslint-disable-next-line prefer-spread
newNum = Math.max.apply(Math, list.map(item => item.SerialNo)) + 1;
} else {
newNum = 1;
}
console.log(newNum);
setNewSerialNo(newNum);
setModalType('add'); setModalType('add');
setVisible(true); setVisible(true);
}; };
// 节点配置回调 // 节点配置回调
const nodeCallBack = obj => { const nodeCallBack = obj => {
let nameIsRepeat;
let numIsRepeat;
let { nodes } = diagram;
let keyArr = [];
// 遍历输出节点对象
nodes.each(node => {
keyArr = [...keyArr, Number(node.data.key)];
if (obj.NodeName === node.data.NodeName) {
nameIsRepeat = true;
if (modalType === 'edit' && obj.NodeName === editMsg.NodeName) {
nameIsRepeat = false;
}
}
if (Number(obj.SerialNo) === Number(node.data.SerialNo)) {
numIsRepeat = true;
if (modalType === 'edit' && Number(obj.SerialNo) === Number(editMsg.SerialNo)) {
numIsRepeat = false;
}
}
});
if (nameIsRepeat) {
notification.error({
message: '提示',
duration: 3,
description: '节点名称不能重复',
});
return;
}
if (numIsRepeat) {
notification.error({
message: '提示',
duration: 3,
description: '序号不能重复',
});
return;
}
if (modalType === 'add') { if (modalType === 'add') {
// 新增节点 // 新增节点
let { nodes } = diagram;
let keyArr = [];
// 遍历输出节点对象
nodes.each(node => {
keyArr = [...keyArr, Number(node.data.key)];
});
// 新增得key比最大得key值+1 // 新增得key比最大得key值+1
let newKey; let newKey;
if (keyArr.length === 0) { if (keyArr.length === 0) {
...@@ -312,11 +374,12 @@ const FlowChart = props => { ...@@ -312,11 +374,12 @@ const FlowChart = props => {
if (modalType === 'edit') { if (modalType === 'edit') {
// 编辑节点 // 编辑节点
let nodeData = diagram.model.findNodeDataForKey(nodeKey); let nodeData = diagram.model.findNodeDataForKey(nodeKey);
const { NodeName, NodeType, roleList } = obj; const { NodeName, NodeType, roleList, SerialNo } = obj;
nodeData.NodeName = NodeName; nodeData.NodeName = NodeName;
nodeData.NodeType = NodeType; nodeData.NodeType = NodeType;
nodeData.NodeId = nodeKey; nodeData.NodeId = nodeKey;
nodeData.roleList = roleList; nodeData.roleList = roleList;
nodeData.SerialNo = SerialNo;
diagram.model.updateTargetBindings(nodeData); diagram.model.updateTargetBindings(nodeData);
} }
// 关闭时进行数据比对看数据是否改变 // 关闭时进行数据比对看数据是否改变
...@@ -410,6 +473,7 @@ const FlowChart = props => { ...@@ -410,6 +473,7 @@ const FlowChart = props => {
<NodeModal <NodeModal
visible={visible} visible={visible}
editMsg={editMsg} editMsg={editMsg}
newSerialNo={newSerialNo}
modalType={modalType} modalType={modalType}
handleCancel={() => setVisible(false)} handleCancel={() => setVisible(false)}
onSubumit={obj => nodeCallBack(obj)} onSubumit={obj => nodeCallBack(obj)}
......
...@@ -5,7 +5,6 @@ import { ...@@ -5,7 +5,6 @@ import {
Space, Space,
Button, Button,
Input, Input,
notification,
Select, Select,
Divider, Divider,
Table, Table,
...@@ -20,7 +19,7 @@ import Undertaker from './nodeModalComponents/Undertaker'; ...@@ -20,7 +19,7 @@ import Undertaker from './nodeModalComponents/Undertaker';
const { Option } = Select; const { Option } = Select;
const NodeModal = props => { const NodeModal = props => {
const { onSubumit, handleCancel, visible, modalType, editMsg } = props; const { onSubumit, handleCancel, visible, modalType, editMsg, newSerialNo } = props;
const [form] = Form.useForm(); const [form] = Form.useForm();
const [showRoal, setShowRoal] = useState(false); // 是否显示选择角色用户弹窗 const [showRoal, setShowRoal] = useState(false); // 是否显示选择角色用户弹窗
const [showUnderTaker, setShowUnderTaker] = useState(false); // 是否显示选择默认承办人弹窗 const [showUnderTaker, setShowUnderTaker] = useState(false); // 是否显示选择默认承办人弹窗
...@@ -29,6 +28,7 @@ const NodeModal = props => { ...@@ -29,6 +28,7 @@ const NodeModal = props => {
const [nodeMsg, setNodeMsg] = useState({ const [nodeMsg, setNodeMsg] = useState({
NodeName: '', NodeName: '',
NodeType: '', NodeType: '',
SerialNo: '',
roleList: [], roleList: [],
}); });
useEffect(() => { useEffect(() => {
...@@ -37,20 +37,23 @@ const NodeModal = props => { ...@@ -37,20 +37,23 @@ const NodeModal = props => {
if (modalType === 'edit') { if (modalType === 'edit') {
getFormData(); getFormData();
} else { } else {
setNodeMsg({ ...nodeMsg, roleList: [] }); setNodeMsg({ ...nodeMsg, newSerialNo, roleList: [] });
form.setFieldsValue({ SerialNo: newSerialNo });
} }
} }
}, [visible]); }, [visible]);
// 获取表单回显 // 获取表单回显
const getFormData = () => { const getFormData = () => {
setNodeMsg(editMsg); setNodeMsg(editMsg);
const { NodeName, NodeType } = editMsg; console.log(editMsg, 'editMsg');
form.setFieldsValue({ NodeName, NodeType }); const { NodeName, NodeType, SerialNo } = editMsg;
form.setFieldsValue({ NodeName, NodeType, SerialNo });
}; };
// 提交表单 // 提交表单
const onFinish = () => { const onFinish = () => {
form.validateFields().then(validate => { form.validateFields().then(validate => {
if (validate) { if (validate) {
validate.SerialNo = Number(validate.SerialNo);
let obj = { ...validate, roleList: nodeMsg.roleList }; let obj = { ...validate, roleList: nodeMsg.roleList };
onSubumit(obj); onSubumit(obj);
} }
...@@ -192,17 +195,24 @@ const NodeModal = props => { ...@@ -192,17 +195,24 @@ const NodeModal = props => {
节点信息 节点信息
</Divider> </Divider>
<Form form={form} labelCol={{ span: 5 }} wrapperCol={{ span: 18 }}> <Form form={form} labelCol={{ span: 5 }} wrapperCol={{ span: 18 }}>
<Form.Item
label="序号"
name="SerialNo"
rules={[{ required: true, message: '请输入序号' }]}
>
<Input placeholder="请输入序号" />
</Form.Item>
<Form.Item <Form.Item
label="节点名称" label="节点名称"
name="NodeName" name="NodeName"
rules={[ rules={[
{ required: true, message: '请输入节点名称' }, { required: true, message: '请输入节点名称' },
{ // {
validator: (_, value) => // validator: (_, value) =>
value.length > 6 // value.length > 12
? Promise.reject(new Error('节点名称太长啦~')) // ? Promise.reject(new Error('节点名称太长啦~'))
: Promise.resolve(), // : Promise.resolve(),
}, // },
]} ]}
> >
<Input placeholder="请输入节点名称(最多6个字)" /> <Input placeholder="请输入节点名称(最多6个字)" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment