handle.js
10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
var maxWidth = 800;
var maxHeight = 600;
var widthViewPage = maxWidth;
var getCanvasHtml = function(workflowBase) {
var nodebases = workflowBase.nodeBases;
for (var i = 0; i < nodebases.length; i++) {
var crtNode = nodebases[i];
if (crtNode.x + 150 > maxWidth) {
maxWidth = crtNode.x + 150;
}
if (crtNode.y + 150 > maxHeight) {
maxHeight = crtNode.y + 150;
}
}
for (var i = 0; i < workflowBase.groups.length; i++) {
var g = workflowBase.groups[i];
if (g.direction == 0) {
if (g.x + g.width > maxWidth) {
maxWidth = g.x + g.width;
}
if (g.y + g.height > maxHeight) {
maxHeight = g.y + g.height;
}
} else if (g.direction == 1) {
if (g.y + g.height > maxHeight) {
maxHeight = g.y + g.height;
}
} else if (g.direction == 2) {
if (g.x + g.width > maxWidth) {
maxWidth = g.x + g.width;
}
}
}
//maxWidth += 50;
if (maxWidth < $(document.body).width()) {
maxWidth = $(document.body).width() - 3;
}
if (maxHeight < window.screen.height) {
//maxHeight = $(document.body).height() - 3;
maxHeight = window.screen.height-300;
}
//console.log($(document.body).height(), $(document.body).width());
return '<canvas id="mainArea" width="' + maxWidth + 'px" height="' + maxHeight + 'px" style="background:#ffffff;" >您的浏览器不支持HTML5 CANCAL元素</canvas>';
}
var canvasHandle = function(canvas, workflowBase) {
canvas.addEventListener('click', function(e) {
popup(e, '', workflowBase);
});
$(canvas).mousemove(function(e) {
showConditioncn(e, workflowBase);
});
$(window).resize(function() {
if (!$('#dialog-box').is(':hidden')) popup();
});
$(document.body).bind("click", function() {
$("#dialog-box, #dialog-overlay").css("display", "none");
//e.stopPropagation();
});
$('#dialog-box').bind('click', function(e) {
if (e.stopPropagation)
e.stopPropagation();
else
e.cancelBubble = true;
});
}
function popup(e, message, workflowBase) {
if (jQuery("#dialog-box, #dialog-overlay").css("display") != "none") {
return;
}
var ev = e ? e : event;
var position = getPointerPosition(ev);
var interY = 0; //$("#titleBlock").height();
var message = isClickNode(new Point(position.left, position.top - interY), workflowBase.nodeBases)
if (message == "") {
return;
}
var maskHeight = $(document).height();
var maskWidth = $(window).width();
var dialogTop = position.top;
var dialogLeft = position.left;
$('#dialog-box').css({
top: dialogTop,
left: dialogLeft
}).show();
$('#dialog-message').html(message);
e.stopPropagation();
}
function getPointerPosition(e) {
var obj = e.currentTarget || document.activeElement;
var position = {
left: e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)),
top: e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop))
};
return position;
}
function isClickNode(oldPoint, nodebases) {
for (var i = 0; i < nodebases.length; i++) {
//console.log(nodebases[i].nodetype);
if (nodebases[i].nodetype === 1) {
if (windingNumber(oldPoint, nodebases[i].getPoints())) {
messageInfoControl(false);
return getShowMessage(nodebases[i]);
}
continue;
}
var x = nodebases[i].x;
var y = nodebases[i].y;
var w = nodebases[i].getWHPoint().x;
var h = nodebases[i].getWHPoint().y;
if (oldPoint.x >= x && oldPoint.x <= x + w && oldPoint.y >= y && oldPoint.y <= y + h) {
messageInfoControl(false);
return getShowMessage(nodebases[i]);
}
}
return "";
}
function getShowMessage(nodebase) {
var rhtml = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
if (nodebase.nodeOptType == 1) {
rhtml += "<tr><td style='word-break : break-all; overflow:hidden; '>";
rhtml += "<img src=\"/workflow/design/h5display/images/imgPersonHead_wev8.png\" title=\"" + operatorMsg + "\">";
rhtml += " " + nodebase.getNotOperators();
rhtml += "</td></tr>";
rhtml += '<tr><td style="height:10px;"></td></tr>'
rhtml += "<tr><td style='word-break : break-all; overflow:hidden; '>";
rhtml += "<img src=\"/workflow/design/h5display/images/icon_resource_wev8.png\" title=\"" + viewerMsg + "\">";
rhtml += " " + nodebase.getViewers();
rhtml += "</td></tr>";
rhtml += '<tr><td style="height:10px;"></td></tr>'
rhtml += "<tr><td style='word-break : break-all; overflow:hidden; '>";
rhtml += "<img src=\"/workflow/design/h5display/images/iconemp_wev8.png\" title=\"" + operatorMsg + "\">";
rhtml += " " + nodebase.getOperators();
rhtml += "</td></tr>";
} else if (nodebase.nodeOptType == 0) {
rhtml += '<tr><td style="height:10px;"></td></tr>';
rhtml += "<tr><td style='word-break : break-all; overflow:hidden;'>";
rhtml += "<img src=\"/workflow/design/h5display/images/iconemp_wev8.png\" title=\"" + operatorMsg + "\">";
rhtml += " " + nodebase.getOperators();
rhtml += "</td></tr>";
rhtml += '<tr><td style="height:10px;"></td></tr>';
} else if (nodebase.nodeOptType == 2) {
rhtml += '<tr><td style="height:10px;"></td></tr>';
rhtml += "<tr><td style='word-break : break-all; overflow:hidden; '>";
rhtml += "<img src=\"/workflow/design/h5display/images/imgPersonHead_wev8.png\" title=\"" + operatorMsg + "\" >";
rhtml += " " + nodebase.getOperators();
rhtml += "</td></tr>";
rhtml += '<tr><td style="height:10px;"></td></tr>';
}
rhtml += "</table>";
return rhtml;
}
function showConditioncn(e, workflowBase) {
var ev = e ? e : event;
var position = getPointerPosition(ev);
var p = {
x: position.left,
y: position.top
};
clearTimeout(timeoutObj);
//console.log(p)
for (var i = 0; i < workflowBase.nodeLinks.length; i++) {
var nl = workflowBase.nodeLinks[i];
//console.log(nl.drawPoints, nl.points, nl.text);
for (var j = 0; j < nl.drawPoints.length - 1; j++) {
var ispointOnSegment = ptOnLine(nl.drawPoints[j].x, nl.drawPoints[j].y, nl.drawPoints[j + 1].x, nl.drawPoints[j + 1].y, p.x, p.y);
//console.log(isPointOnSegment(p, nl.drawPoints[j], nl.drawPoints[j + 1]));
if (ispointOnSegment) {
//console.log(nl.conditoncn);
if (nl.conditoncn != '') {
messageInfoControl(true, nl.conditoncn, p);
return;
}
//console.log('point :' + nl.text);
timeoutObj = setTimeout(function() {
//显示出口信息
var ajaxUrl = '/workflow/design/wfQueryConditions.jsp?nodelinkid=' + nl.id + '&workflowid=' + workflowBase.workflowid;
jQuery.ajax({
url: ajaxUrl,
dataType: "text",
contentType: "charset=UTF-8",
cache: false,
error: function(ajaxrequest) {},
success: function(data) {
//alert(data);
var msg = nl.text;
if (jQuery.trim(data) != '') {
msg += '[' + jQuery.trim(data) + ']';
}
nl.conditoncn = msg;
messageInfoControl(true, msg, p);
}
});
}, 500);
return;
}
}
}
var nodebases = workflowBase.nodeBases;
for (var i = 0; i < nodebases.length; i++) {
//console.log(nodebases[i].nodetype);
var x = nodebases[i].x;
var y = nodebases[i].y;
var w = nodebases[i].getWHPoint().x;
var h = nodebases[i].getWHPoint().y;
if (p.x >= x + 20 && p.x <= x + w - 20 && p.y >= y + h / 2 - 20 && p.y <= y + h / 2) {
messageInfoControl(true, nodebases[i].text, p);
return;
}
if (p.x >= x + 20 && p.x <= x + w - 20 && p.y >= y + h / 2 && p.y <= y + h / 2 + 20) {
messageInfoControl(true, nodebases[i].nodeOperatorName, p);
return;
}
}
messageInfoControl(false);
}
function messageInfoControl(isshow, msg, p) {
//console.log(isshow, msg, p);
if (isshow) {
if ($("#tipdiv").is(':visible')) {
if ($("#tipContent").html() === msg) {
//console.log($("#tipdiv").is(':visible'), $("#tipdiv").is(':hidden'));
return;
}
}
$("#tipContent").html(msg);
//console.log($("#tipdiv").height(), $("#tipdiv").width())
$("#tipdiv").css({
top: p.y + 20,
left: p.x + 10
});
$("#tipdiv").show();
} else {
$("#tipContent").html('');
$("#tipdiv").hide();
}
}
var offsetVal = 5;
/**
* 判断鼠标的点是否在线段上
* @param p1x
* @param p1y
* @param p2x
* @param p2y
* @param x
* @param y
* @return
*/
function onSegment(p1x, p1y, p2x, p2y, x, y) {
if (x >= min(p1x, p2x) && x <= max(p1x, p2x) && y >= min(p1y, p2y) && y <= max(p1y, p2y))
return true;
else
return false;
}
/**
* 判断两点的最小值
* @param x1
* @param x2
* @return
*/
function min(x1, x2) {
if (x1 > x2)
return x2 - offsetVal;
else
return x1 - offsetVal;
}
/**
* 判断连点的最大值
* @param x1
* @param x2
* @return
*/
function max(x1, x2) {
if (x1 < x2)
return x2 + offsetVal;
else
return x1 + offsetVal;
}
/**
* 计算点到直线的距离
* @param x1 线段上的一个端点
* @param y1
* @param x2 线段上的一个端点
* @param y2
* @param x3 待测点
* @param y3
* @return
*/
function ptOnLine(x1, y1, x2, y2,
x3, y3) {
if (!onSegment(x1, y1, x2, y2, x3,
y3))
return false;
var distance = (Math.sqrt(quadratic(x2, x3) + quadratic(y2, y3)) + Math
.sqrt(quadratic(x1, x3) + quadratic(y1, y3)));
var p2pDist = Math.sqrt(quadratic(x2, x1) + quadratic(y2, y1));
//console.log(distance - p2pDist);
if (distance - p2pDist < 1 * offsetVal && distance - p2pDist > -1 * offsetVal)
return true;
else
return false;
}
function quadratic(x, y) {
return (y - x) * (y - x);
}
/**
* @description 回转数法判断点是否在多边形内部
* @param {Object} p 待判断的点,格式:{ x: X坐标, y: Y坐标 }
* @param {Array} poly 多边形顶点,数组成员的格式同 p
* @return {String} 点 p 和多边形 poly 的几何关系
*/
function windingNumber(p, poly) {
var px = p.x,
py = p.y,
sum = 0
//console.log(p, poly);
for (var i = 0, l = poly.length, j = l - 1; i < l; j = i, i++) {
var sx = poly[i].x,
sy = poly[i].y,
tx = poly[j].x,
ty = poly[j].y
// 点与多边形顶点重合或在多边形的边上
if ((sx - px) * (px - tx) >= 0 && (sy - py) * (py - ty) >= 0 && (px - sx) * (ty - sy) === (py - sy) * (tx - sx)) {
return 'on'
}
// 点与相邻顶点连线的夹角
var angle = Math.atan2(sy - py, sx - px) - Math.atan2(ty - py, tx - px)
// 确保夹角不超出取值范围(-π 到 π)
if (angle >= Math.PI) {
angle = angle - Math.PI * 2
} else if (angle <= -Math.PI) {
angle = angle + Math.PI * 2
}
sum += angle
}
//console.log(Math.round(sum / Math.PI), p, poly);
// 计算回转数并判断点和多边形的几何关系
//return Math.round(sum / Math.PI) === 0 ? 'out' : 'in'
return Math.round(sum / Math.PI) != 0;
}
function hideLoadding() {
$('#submitloaddingdiv_out').hide();
$('#submitloaddingdiv').hide();
}