Commit 2a00e476 authored by 邓超's avatar 邓超

fix: 流程中心生成图片优化

parent 14dfe865
Pipeline #68430 passed with stages
This diff was suppressed by a .gitattributes entry.
...@@ -443,14 +443,18 @@ const WorkflowHomePage = () => { ...@@ -443,14 +443,18 @@ const WorkflowHomePage = () => {
{/* <DeleteOutlined onClick={e => delFlow(ele, e)} /> */} {/* <DeleteOutlined onClick={e => delFlow(ele, e)} /> */}
</div> </div>
</div> </div>
<img {ele.PreviewImage ? (
src={`${ <img
window.location.origin src={`${
}/PandaOMS/OMS/FileCenter/DownLoadFiles?filePath=${ window.location.origin
ele.PreviewImage }/PandaOMS/OMS/FileCenter/DownLoadFiles?filePath=${ele.PreviewImage}`}
}&v=${new Date().getTime()}`} />
alt="" ) : (
/> <img
className={styles.noDataImg}
src={require('../../../../assets/images/common/noData.png')}
/>
)}
</div> </div>
<div className={styles.bottom}> <div className={styles.bottom}>
<div className={styles.left}>{ele.CreateUser || ''}</div> <div className={styles.left}>{ele.CreateUser || ''}</div>
......
...@@ -318,7 +318,11 @@ ...@@ -318,7 +318,11 @@
overflow: hidden; overflow: hidden;
img { img {
width: 320px; width: 270px;
}
.noDataImg {
width: 120px;
height: 112px;
} }
} }
......
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
DeleteFlowNodes, DeleteFlowNodes,
SaveWorkFlowImage, SaveWorkFlowImage,
} from '@/services/workflow/workflow'; } from '@/services/workflow/workflow';
import { compress } from '@/utils/utils';
import { ExclamationCircleOutlined, TrophyOutlined } from '@ant-design/icons'; import { ExclamationCircleOutlined, TrophyOutlined } from '@ant-design/icons';
import * as go from 'gojs'; import * as go from 'gojs';
import styles from './FlowBoard.less'; import styles from './FlowBoard.less';
...@@ -968,42 +968,54 @@ const FlowChart = props => { ...@@ -968,42 +968,54 @@ const FlowChart = props => {
); );
}; };
const nodeCallBack = () => { const nodeCallBack = () => {
SaveWorkFlowImage({ compress(
flowName: flowData.flowName, diagram.makeImageData({
base64Data: diagram.makeImageData({
background: 'rgb(239, 248, 250)', background: 'rgb(239, 248, 250)',
maxSize: new go.Size(1260, 500), // maxSize: new go.Size(1260, 500), // 固定区域
scale: 1, // 有效区域
}), }),
}).then(response => { 1.2, // 压缩比例
if (response.code === 0) { base64 => {
FlowNodeSave({ console.log(base64);
PreviewImage: response.data, SaveWorkFlowImage({
CreateUser: sessionStorage.getItem('userName'), flowName: flowData.flowName,
flowID, base64Data: base64,
...currentNode.current, }).then(response => {
CarbonCopyPeopleList: currentNode.current.CarbonCopyPeopleList.map(item => if (response.code === 0) {
Number(item.value), FlowNodeSave({
), PreviewImage: response.data,
}).then(res => { CreateUser: sessionStorage.getItem('userName'),
if (res.code === 0) { flowID,
diagram.model.setDataProperty( ...currentNode.current,
currentNode.current, CarbonCopyPeopleList: currentNode.current.CarbonCopyPeopleList.map(item =>
'FlowTimerList', Number(item.value),
res.data.FlowTimerList, ),
); }).then(res => {
diagram.model.setDataProperty(currentNode.current, 'ActivityId', res.data.ActivityId); if (res.code === 0) {
diagram.model.setDataProperty( diagram.model.setDataProperty(
currentNode.current, currentNode.current,
'FlowNodeExtendId', 'FlowTimerList',
res.data.FlowNodeExtendId, res.data.FlowTimerList,
); );
message.success('保存成功'); diagram.model.setDataProperty(
} else { currentNode.current,
message.error(res.msg); 'ActivityId',
res.data.ActivityId,
);
diagram.model.setDataProperty(
currentNode.current,
'FlowNodeExtendId',
res.data.FlowNodeExtendId,
);
message.success('保存成功');
} else {
message.error(res.msg);
}
});
} }
}); });
} },
}); );
}; };
// 关闭时进行数据比对看数据是否改变 // 关闭时进行数据比对看数据是否改变
const leaveTip = () => { const leaveTip = () => {
...@@ -1126,43 +1138,51 @@ const FlowChart = props => { ...@@ -1126,43 +1138,51 @@ const FlowChart = props => {
return; return;
} }
setButtonLoading(true); setButtonLoading(true);
SaveWorkFlowImage({ compress(
flowName: flowData.flowName, diagram.makeImageData({
base64Data: diagram.makeImageData({
background: 'rgb(239, 248, 250)', background: 'rgb(239, 248, 250)',
maxSize: new go.Size(1260, 500), // maxSize: new go.Size(1260, 500), // 固定区域
scale: 1, // 有效区域
}), }),
}).then(val => { 1.2, // 压缩比例
if (val.code === 0) { base64 => {
SaveNodeChange({ console.log(base64);
FlowId: flowID, SaveWorkFlowImage({
// DeleteNodes, flowName: flowData.flowName,
CreateUser: sessionStorage.getItem('userName'), base64Data: base64,
PreviewImage: val.data, }).then(val => {
DeleteLines, if (val.code === 0) {
Lines: diagramObj.linkDataArray, SaveNodeChange({
Nodes: diagramObj.nodeDataArray, FlowId: flowID,
}) // DeleteNodes,
.then(res => { CreateUser: sessionStorage.getItem('userName'),
setButtonLoading(false); PreviewImage: val.data,
if (res.code === 0) { DeleteLines,
setDeleteNodes([]); Lines: diagramObj.linkDataArray,
setDeleteLines([]); Nodes: diagramObj.nodeDataArray,
setAddNodes([]); })
setDeleteNode(''); .then(res => {
setDeleteLine(''); setButtonLoading(false);
getFlowData(); if (res.code === 0) {
message.success('保存成功'); setDeleteNodes([]);
} else { setDeleteLines([]);
message.error(res.msg); setAddNodes([]);
} setDeleteNode('');
}) setDeleteLine('');
.catch(() => { getFlowData();
setButtonLoading(false); message.success('保存成功');
message.error('网络异常请稍后重试'); } else {
}); message.error(res.msg);
} }
}); })
.catch(() => {
setButtonLoading(false);
message.error('网络异常请稍后重试');
});
}
});
},
);
}; };
const treeChange = newValue => { const treeChange = newValue => {
setSelectValue(newValue); setSelectValue(newValue);
......
export function compress(
base64, // 源图片
rate, // 缩放比例
callback, // 回调
) {
//处理缩放,转格式
var _img = new Image();
_img.src = base64;
_img.onload = function() {
var _canvas = document.createElement('canvas');
var w = this.width / rate;
var h = this.height / rate;
_canvas.setAttribute('width', w);
_canvas.setAttribute('height', h);
_canvas.getContext('2d').drawImage(this, 0, 0, w, h);
var base64 = _canvas.toDataURL('image/jpeg');
_canvas.toBlob(function(blob) {
if (blob.size > 750 * 1334) {
//如果还大,继续压缩
compress(base64, rate, callback);
} else {
callback(base64);
}
}, 'image/jpeg');
};
}
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