Files

673 lines
27 KiB
JavaScript
Raw Permalink Normal View History

2026-01-16 14:13:44 +08:00
function drawPath(configOptions) {
setContainer(configOptions);
container.innerHTML = '';
container.ondrop = function(event){
drop(event, configOptions, pointsLinkedList);
};
container.ondragover = function(event){
allowDrop(event);
};
var pointInflectionStyle = configOptions.pointsStyle.pointInflectionStyle;
var pointDefaultStyle = configOptions.pointsStyle.pointDefaultStyle;
var pointCompleteStyle = configOptions.pointsStyle.pointCompleteStyle;
var pointAbnormalStyle = configOptions.pointsStyle.pointAbnormalStyle;
var pointAlarmStyle = configOptions.pointsStyle.pointAlarmStyle;
var lineDefaultStyle = configOptions.linesStyle.lineDefaultStyle;
var lineCompleteStyle = configOptions.linesStyle.lineCompleteStyle;
var lineAbnormalStyle = configOptions.linesStyle.lineAbnormalStyle;
var lineAlarmStyle = configOptions.linesStyle.lineAlarmStyle;
var pointsLinkedList = new LinkedList();
configOptions.points.forEach(function(item,index) {
if(item['type'] === '1') {
item['pointStyle'] = pointInflectionStyle;
} else {
item['pointStyle'] = pointDefaultStyle;
}
item['patrolPlanId'] = configOptions.patrolPlanId;
pointsLinkedList.add(index,item);
});
pointsLinkedList.getItems().forEach(function(item, index) {
pointsLinkedList.set(index,item);
})
var points = deepClone(pointsLinkedList.getItems());
if(points.length && points.length === 1) {
if(points[0].type === '1') {
points[0]["pointStyle"] = pointInflectionStyle;
} else {
points[0]["pointStyle"] = pointDefaultStyle;
}
drawPoint(points[0], configOptions, pointsLinkedList);
} else {
for(var i = 0, len = points.length; i < len; i++) {
if(points[i].type === "1") {
points[i]["pointStyle"] = pointInflectionStyle;
} else {
switch(points[i].infos.state) {
// case 1:
// points[i]["pointStyle"] = pointCompleteStyle;
// break;
// case 2:
// points[i]["pointStyle"] = pointAbnormalStyle;
// break;
case 3:
// points[i]["pointStyle"] = pointAlarmStyle;
points[i]["pointStyle"] = pointCompleteStyle;
break;
default:
points[i]["pointStyle"] = pointDefaultStyle;
}
}
if(i === 0) {
drawPoint(points[i], configOptions, pointsLinkedList);
}
if (i < len - 1) {
if(points[i+1].type === "1"){
points[i+1]["pointStyle"] = pointInflectionStyle;
drawLine(points[i], points[i+1], lineDefaultStyle, configOptions, pointsLinkedList);
} else {
switch(points[i+1].infos.state) {
// case 1:
// drawLine(points[i], points[i+1], lineCompleteStyle, configOptions, pointsLinkedList);
// break;
// case 2:
// drawLine(points[i], points[i+1], lineAbnormalStyle, configOptions, pointsLinkedList);
// break;
case 3:
// drawLine(points[i], points[i+1], lineAlarmStyle, configOptions, pointsLinkedList);
drawLine(points[i], points[i+1], lineCompleteStyle, configOptions, pointsLinkedList);
break;
default:
drawLine(points[i], points[i+1], lineDefaultStyle, configOptions, pointsLinkedList);
}
}
}
}
}
}
function setContainer(configOptions) {
var container = document.getElementById(configOptions.container);
container.style.width = (configOptions.containerWidth + '').indexOf('%') > -1 ? configOptions.containerWidth : configOptions.containerWidth + "px";
container.style.height = (configOptions.containerHeight + '').indexOf('%') > -1 ? configOptions.containerHeight : configOptions.containerHeight + 'px';
container.style.backgroundColor = configOptions.containerBgColor;
}
// 画点函数
function drawPoint(p, configOptions, pl) {
var point = document.createElement("div");
var pointInfo = document.createElement("div");
point.setAttribute("class", "patrol-point");
point.setAttribute("id", (p.routeId.indexOf("patrol-point-") > -1 ? "" : "patrol-point-") + p.routeId.replace("patrol-point-", ""));
pointInfo.setAttribute("id", "patrol-point-info-" + p.routeId);
var containerWidth = container.clientWidth || container.offsetWidth;
var containerHeight = container.clientHeight || container.offsetHeight;
point.style.cssText += ";width:" + 2 * p.pointStyle.radius + "px;height: " + 2 * p.pointStyle.radius + "px;position:absolute;left:" + p.posX
+ "px;top:" + p.posY + "px;line-height: " + 2 * p.pointStyle.radius + "px;border: " + p.pointStyle.borderWidth + "px " + p.pointStyle.borderStyle + " " + p.pointStyle.borderColor + ";border-radius: 50%;text-align: center;font-size: " + p.pointStyle.fontSize + "px;font-weight:800;vertical-align: middle;color:" + p.pointStyle.fontColor + ";text-shadow:" + p.pointStyle.shadow + ";box-shadow:" + p.pointStyle.shadow + ";z-index:800;cursor:move;background-color:#1c1d1f;";
if(p.type === '0') {
point.style.cssText += "background-size: 4px 4px;background-image:-webkit-linear-gradient( 0deg, hsla(0,0%,0%,0) 75%, hsla(0,0%,0%,.4) 75% ), -webkit-linear-gradient( 90deg, hsla(0,0%,0%,0) 75%, hsla(0,0%,0%,.4) 75% );";
// point.innerHTML = p.name ? p.name[0] : '巡';
point.innerHTML = '';
}
var mark = {
width: 20,
height: 20,
arrowWidth: 10,
arrowHeight: 25,
fontSize: 0
}
pointInfo.style.cssText = ";display:none;position:absolute;top:-" + (mark.height - 3 * p.pointStyle.radius / 4 + mark.arrowHeight) + "px;left:-" + (mark.width / 2 - 3 * p.pointStyle.radius / 4) + "px;width:" + mark.width + "px;height:" + mark.height + "px;background-color:" + p.pointStyle.borderColor + ";border-top-left-radius: 50%;border-top-right-radius: 50%;border-bottom-left-radius: 40%;border-bottom-right-radius: 40%;box-shadow:" + p.pointStyle.shadow + ";color:rgb(28,29,31);font-size:" + mark.fontSize + "px;font-family: '微软雅黑';";
document.styleSheets[0].insertRule('#patrol-point-info-' + p.routeId + ':before{position:absolute;top:' + (mark.height - 3 * p.pointStyle.radius / 4) + 'px;left:' + (mark.width/ 2 - p.pointStyle.radius) + 'px;border: ' + mark.arrowWidth + 'px solid transparent;border-top:' + mark.arrowHeight + 'px solid ' + p.pointStyle.borderColor + ';content:"";width:0;height:0;animation:alarm-arrow 1s infinite;}', 0);
pointInfo.innerHTML = '<div id="patrol-point-info-titie-' + p.routeId + '" style="width:120px;height:20px;padding:0;position: absolute;left: -40px;top: -25px;color:' + p.pointStyle.borderColor + ';white-space: nowrap;font-size:14px;">' + (p.patrolPoint ? p.patrolPoint.name : p.name) + '</div>';
if(p.infos === undefined) {
p['infos'] = {
state: 1
}
}
if(p.infos.state >= 0) {
point.appendChild(pointInfo);
}
if (configOptions.draggable) {
new LimitDrag(point, p, pl);
}
container.appendChild(point);
point.ondrop = function(event){
drop(event, configOptions, pl);
};
point.ondragover = function(event){
allowDrop(event);
};
if(p.type === '0') {
pointInfo.style.display = 'block';
} else {
pointInfo.style.display = 'none';
}
point.addEventListener("mouseover",function() {
point.style.backgroundSize = "";
point.style.backgroundImage = "";
point.style.borderColor = '#0f0';
if(p.type === '0'){
point.title = '点击右键删除该巡检点!';
} else {
point.title = '点击右键删除该拐点!';
}
});
point.addEventListener("mouseout",function() {
// pointInfo.style.display = 'none';
point.style.borderColor = p.pointStyle.borderColor;
if(p.type === '0') {
point.style.backgroundSize = "4px 4px";
point.style.backgroundImage = "-webkit-linear-gradient( 0deg, hsla(0,0%,0%,0) 75%, hsla(0,0%,0%,.4) 75% ), -webkit-linear-gradient( 90deg, hsla(0,0%,0%,0) 75%, hsla(0,0%,0%,.4) 75% )";
}
});
$("#patrol-point-container").hide();
point.addEventListener("contextmenu", function(e) {
if(e.button === 2) {
deleteRoutePoint(p,function(data) {
if(JSON.parse(data).res === '1') {
var floorId = configOptions.floorId;
var patrolPlanId = configOptions.patrolPlanId;
if(p.type === '0') {
var newP = replaceJsonWhiteSpace(p);
newP['id'] = newP['patrolPointId'];
delete newP.nextId;
delete newP.previousId;
delete newP.prevId;
var patrolPointStr = JSON.stringify(newP);
$("#patro-list-" + floorId).append('<li class="patro-point" draggable="true" id="patrol-point-' + newP['patrolPointId'] + '" ondragstart="drag(event)" data-obj=' + patrolPointStr + ' style="font-size:14px;list-style:none;padding: 10px;height:20px;line-height:20px;cursor: move;">' + (newP["name"] ? newP["name"] : newP["patrolPoint"].name) + '</li>');
}
getRoutePoints(floorId,patrolPlanId,configOptions);
}
});
}
// }
});
}
/****************拖拽功能模块(开始)****************/
function Drag(element,elementData, pl){
this.elem = element;
this.elementData = elementData;
this.pl = pl;
var self = this;
this.elem.onmousedown = function (e){
var e = e || window.event;
e.preventDefault();
if(e.button === 0) {
self.posX = e.clientX - self.elem.offsetLeft;
self.posY = e.clientY - self.elem.offsetTop;
self.start();
document.onmouseup = function (){
self.stop();
};
}
};
}
Drag.prototype.start = function (){
var self = this;
document.onmousemove = function (e){
var x = e.clientX - self.posX;
var y = e.clientY - self.posY;
self.move(x, y);
};
};
Drag.prototype.move = function (x , y){
var self = this;
self.elem.style.left = x + "px";
self.elem.style.top = y + "px";
};
Drag.prototype.stop = function (e){
var self = this;
var configOptions = JSON.parse(localStorage.getItem('configOptions'));
var points = self.pl.getItems();
if(this.elementData && configOptions) {
points.forEach(function(item) {
if(item.id === self.elementData.id) {
item['posX'] = self.elem.offsetLeft;
item['posY'] = self.elem.offsetTop;
}
});
points.forEach(function(item) {
if (item.id === self.elementData.id) {
updateRoutePoint({
id: item.routeId,
posx: item.posX,
posy: item.posY,
containerWidth: configOptions.containerWidth,
containerHeight: configOptions.containerHeight
}, function(data) {
var floorId = configOptions.floorId;
var patrolPlanId = configOptions.patrolPlanId;
getRoutePoints(floorId,patrolPlanId,configOptions);
});
}
});
}
document.onmousemove = null;
document.onmouseup = null;
}
/*继承*/
function LimitDrag(element,elementData, pl) {
Drag.call(this,element,elementData, pl);
};
for(var i in Drag.prototype) {
LimitDrag.prototype[i]=Drag.prototype[i];
};
LimitDrag.prototype.move=function(x , y) {
var container = document.getElementById("container");
var patrolPointInfoTitle = document.getElementById(this.elem.id.replace("patrol-point-", "patrol-point-info-titie-"));
if(x < patrolPointInfoTitle.offsetWidth / 2 - this.elem.offsetWidth) {
if(this.elementData.type === '0') {
x = patrolPointInfoTitle.offsetWidth / 2 - this.elem.offsetWidth;
} else {
x = patrolPointInfoTitle.offsetWidth / 2;
}
} else if(x > container.clientWidth - patrolPointInfoTitle.offsetWidth / 2 - this.elem.offsetWidth) {
x = container.clientWidth - patrolPointInfoTitle.offsetWidth / 2 - this.elem.offsetWidth;
}
if(y < patrolPointInfoTitle.offsetHeight * 2 + this.elem.offsetWidth) {
if(this.elementData.type === '0') {
y = patrolPointInfoTitle.offsetHeight * 2 + this.elem.offsetWidth;
} else {
y = patrolPointInfoTitle.offsetHeight * 2;
}
} else if(y > container.clientHeight - this.elem.offsetHeight) {
y = container.clientHeight - this.elem.offsetHeight;
}
this.elem.style.left = x + 'px';
this.elem.style.top = y + 'px';
};
/****************拖拽功能模块(结束)****************/
// 画线函数
function drawLine(startPoint, endPoint, lineStyle,configOptions, pl) {
var line = document.createElement("div");
line.setAttribute("class","patrol-line");
line.setAttribute("id","patrol-line-" + endPoint.routeId);
line.style.cssText += ";width: " + Math.sqrt(Math.pow((endPoint.posX + endPoint.pointStyle.radius + endPoint.pointStyle.borderWidth - startPoint.posX - startPoint.pointStyle.radius - startPoint.pointStyle.borderWidth), 2) + Math.pow((endPoint.posY + endPoint.pointStyle.radius + endPoint.pointStyle.borderWidth - startPoint.posY - startPoint.pointStyle.radius - startPoint.pointStyle.borderWidth), 2)) + "px;position:absolute;left:" + (startPoint.posX + startPoint.pointStyle.radius + startPoint.pointStyle.borderWidth) + "px;top:" + (startPoint.posY + startPoint.pointStyle.radius + startPoint.pointStyle.borderWidth - lineStyle.lineWidth / 2) + "px;border-top: " + lineStyle.lineWidth + "px " + lineStyle.lineStyle + " " + lineStyle.lineColor + ";transform-origin: 0;transform:rotate(" + getAangle(startPoint, endPoint) + "deg);box-shadow:" + lineStyle.shadow + ";z-index:799;";
drawPoint(endPoint, configOptions, pl);
container.appendChild(line);
document.oncontextmenu = function(e) {
e.preventDefault();
};
line.onmouseover = function(e) {
line.style.borderColor = "#0f0";
line.style.cursor = 'pointer';
line.title = '点击右键新增拐点!';
e.preventDefault();
}
line.onmouseout = function(e) {
line.style.borderColor = lineStyle.lineColor;
e.preventDefault();
}
line.oncontextmenu = function(e) {
if(e.button === 2){
var newInflectionPoint = {
id: guid(),
type: '1',
patrolPlanId: configOptions.patrolPlanId,
floorId: configOptions.floorId,
containerWidth: configOptions.containerWidth,
containerHeight: configOptions.containerHeight,
infos: {
text: "拐点",
state: 0,
message: "拐"
}
}
newInflectionPoint['patrolPointId'] = newInflectionPoint.id;
newInflectionPoint['routeId'] = guid();
newInflectionPoint['pointStyle'] = deepClone(configOptions.pointsStyle.pointInflectionStyle);
newInflectionPoint['posX'] = e.clientX - $("#container").offset().left - newInflectionPoint.pointStyle.radius - newInflectionPoint.pointStyle.borderWidth;
newInflectionPoint['posY'] = e.clientY - $("#container").offset().top - newInflectionPoint.pointStyle.radius - newInflectionPoint.pointStyle.borderWidth;
if(e.target.id.indexOf("patrol-line-") > -1 && e.target.id !== "container" && !e.target.id.indexOf("patrol-point-") > -1) {
pl.getItems().forEach(function(item, index){
if(e.target.id === "patrol-line-" + item.routeId) {
pl.add(item.index, newInflectionPoint);
}
});
}
pl.getItems().forEach(function(item, index) {
pl.set(index, item);
});
pl.getItems().forEach(function(item, index) {
if(newInflectionPoint.routeId === item.routeId){
var newPoint = item;
saveRoutePoint({
id: newPoint.routeId,
patrolPlanId: newPoint.patrolPlanId,
previousId: newPoint.prevId ? newPoint.prevId : "",
nextId: newPoint.nextId ? newPoint.nextId : "", //
type: newPoint.type,
patrolPointId: newPoint.id,
posx: newPoint.posX,
posy: newPoint.posY,
containerWidth: configOptions.containerWidth,
containerHeight: configOptions.containerHeight,
structureCardPictureId: configOptions.floorId
},function(data) {
if(JSON.parse(data).res === '1') {
configOptions.points = deepClone(pl.getItems());
drawAllPath(configOptions);
} else {
pl.remove(item.index);
}
});
}
});
}
e.preventDefault();
};
if(endPoint.infos.state > -1) {
if(endPoint.type === '0') {
document.styleSheets[0].insertRule('#patrol-line-' + endPoint.routeId + ':before {position: absolute;bottom: -' + lineStyle.lineWidth + 'px;right: -' + lineStyle.lineWidth + 'px;margin-right: ' + (endPoint.pointStyle.radius - endPoint.pointStyle.borderWidth) + 'px;display: block;width: 0;height: 0;content: "";border: ' + 1.5 * lineStyle.lineWidth + 'px solid transparent;border-left: ' + 4 * lineStyle.lineWidth + 'px solid ' + lineStyle.lineColor + ';}', 0);
}
}
function getAangle(startP, endP) {
var radiusDiff = endP.pointStyle.radius + endP.pointStyle.borderWidth - startP.pointStyle.radius - startP.pointStyle.borderWidth;
var x = endP.posX - startP.posX + radiusDiff;
var y = endP.posY - startP.posY + radiusDiff;
if (x < 0 && y < 0) {// 第一象限
return 360 * Math.atan(y / x) / (2 * Math.PI) - 180;
}
// ?
if (x < 0 && y > 0) {// 第三象限
return 360 * Math.atan(y / x) / (2 * Math.PI) + 180;
}
if (x > 0 && y < 0) {// 第一象限
return 360 * Math.atan(y / x) / (2 * Math.PI);
}
// ?
if (x > 0 && y > 0) {// 第三象限
return 360 * Math.atan(y / x) / (2 * Math.PI);
}
if (x < 0 && y === 0) {// 鼠标在x轴负方向
return 360 * Math.atan(y / x) / (2 * Math.PI) + 180;
}
if (x > 0 && y === 0) {
return 360 * Math.atan(y / x) / (2 * Math.PI);
}
if (x === 0 && y < 0) {
return 180 - 360 * Math.atan(y / x) / (2 * Math.PI);
}
if (x === 0 && y > 0) {
return 360 * Math.atan(y / x) / (2 * Math.PI);
}
return 360 * Math.atan(y / x) / (2 * Math.PI);
}
}
function deepClone(obj) {
var str, newobj = obj.constructor === Array ? [] : {};
if (typeof obj !== 'object') {
return;
} else if (JSON) {
str = JSON.stringify(obj), // 系列化对象
newobj = JSON.parse(str); // 还原
} else {
for (var i in obj) {
newobj[i] = typeof obj[i] === 'object' ? this.deepClone(obj[i]) : obj[i];
}
}
return newobj;
}
function getStyle(element, attr) {
if(element.currentStyle) {
return element.currentStyle[attr];
} else {
return getComputedStyle(element, false)[attr];
}
}
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
var obj = $('#' + ev.target.id).data('obj');
ev.dataTransfer.setData("obj",JSON.stringify(obj));
ev.dataTransfer.setData("ID",ev.target.id);
}
function drop(ev,configOptions, pl) {
ev.stopPropagation();
var data = ev.dataTransfer.getData("ID");
var pointStr = ev.dataTransfer.getData("obj");
var pointObj = JSON.parse(pointStr.replace(" ", "kongbai"));
var infos = {
text: pointObj['name'] ? pointObj['name']: "巡检点",
state: 0,
message: pointObj['name'] ? pointObj['name']: "巡检点"
};
pointObj['routeId'] = guid();
pointObj['pointStyle'] = deepClone(configOptions.pointsStyle.pointDefaultStyle);
pointObj['patrolPlanId'] = configOptions.patrolPlanId;
pointObj['patrolPointId'] = pointObj.id;
pointObj['type'] = '0';
pointObj['infos'] = infos;
// 拖拽到点上
if(ev.target.id === 'container' && !ev.target.id.indexOf("patrol-line-") > -1 && !ev.target.id.indexOf("patrol-point-") > -1) {
// pointObj['prevId'] = null;
// pointObj['nextId'] = null;
pointObj['posX'] = ev.offsetX - pointObj['pointStyle'].radius - pointObj['pointStyle'].borderWidth;
pointObj['posY'] = ev.offsetY - pointObj['pointStyle'].radius - pointObj['pointStyle'].borderWidth;
} else if(ev.target.id.indexOf('patrol-line-') > -1 && ev.target.id !== "container" && !ev.target.id.indexOf("patrol-point-") > -1) {
// pointObj['prevId'] = null;
// pointObj['nextId'] = null;
pointObj['posX'] = ev.clientX - $("#container").offset().left - pointObj.pointStyle.radius - pointObj.pointStyle.borderWidth;
pointObj['posY'] = ev.clientY - $("#container").offset().top - pointObj.pointStyle.radius - pointObj.pointStyle.borderWidth;
} else if(ev.target.id.indexOf('patrol-point-') > -1 && ev.target.id !== "container" && !ev.target.id.indexOf("patrol-line-") > -1) {
// pointObj['prevId'] = null;
// pointObj['nextId'] = null;
pointObj['posX'] = document.getElementById(ev.target.id).offsetLeft + pointObj['pointStyle'].radius + pointObj['pointStyle'].borderWidth;
pointObj['posY'] = document.getElementById(ev.target.id).offsetTop + pointObj['pointStyle'].radius + pointObj['pointStyle'].borderWidth;
} else {
}
if(pl.getItems().length === 0) {
pl.addFirst(pointObj);
} else {
if(ev.target.id === "container" && !ev.target.id.indexOf("patrol-line-") > -1 && !ev.target.id.indexOf("patrol-point-") > -1) {
pl.addLast(pointObj);
} else if(ev.target.id.indexOf("patrol-line-") > -1 && ev.target.id !== "container" && !ev.target.id.indexOf("patrol-point-") > -1) {
pl.getItems().forEach(function(item, index) {
if(ev.target.id === "patrol-line-" + item.routeId) {
pl.add(item.index, pointObj);
}
});
} else if(ev.target.id.indexOf("patrol-point-") > -1 && ev.target.id !== "container" && !ev.target.id.indexOf("patrol-line-") > -1) {
pl.getItems().forEach(function(item, index) {
if(ev.target.id === "patrol-point-" + item.routeId) {
pl.add(item.index + 1, pointObj);
}
});
} else {
}
}
pl.getItems().forEach(function(item, index) {
pl.set(index, item);
});
pl.getItems().forEach(function(item, index) {
if(pointObj.routeId === item.routeId){
var newPoint = item;
saveRoutePoint({
id: newPoint.routeId,
patrolPlanId: newPoint.patrolPlanId,
previousId: newPoint.prevId ? newPoint.prevId : null,
nextId: newPoint.nextId ? newPoint.nextId : null, //
type: newPoint.type,
patrolPointId: newPoint.id,
posx: newPoint.posX,
posy: newPoint.posY,
containerWidth: configOptions.containerWidth,
containerHeight: configOptions.containerHeight,
structureCardPictureId: configOptions.floorId
},function(data) {
if(JSON.parse(data).res === '1') {
configOptions.points = deepClone(pl.getItems());
drawAllPath(configOptions);
$("#patrol-point-" + pointObj.id).remove();
} else {
pl.remove(item.index);
}
});
}
});
ev.preventDefault();
}
// 获取底图信息
function getAllFloorList(structureCardPictureId,unitId,callback) {
$.post(ext.contextPath + '/structure/structureCardPicture/getPictureList.do', {structureCardPictureId,unitId} , function(data) {
callback(data);
});
}
// 获取巡检点数据
function getPatrolPointsList(configOptions, patrolPointInContainer) {
$("#patro-list-" + configOptions.floorId).html("");
var configOptions = JSON.parse(localStorage.getItem("configOptions"));
var patrolPointInContainer = deepClone(configOptions.points.filter(function(item){return item['type'] === '0'}));
$.post(ext.contextPath + '/structure/structureCardPicture/getPatrolPoints.do', {
floorId: configOptions.floorId,
type: configOptions.type,
unitId: configOptions.unitId
// patrolAreaId:configOptions.patrolAreaId
} , function(data) {
var patrolPointItem = "";
JSON.parse(data).forEach(function(item) {
var itemStr = JSON.stringify(replaceJsonWhiteSpace(item));
patrolPointItem += '<li class="patro-point" draggable="true" id="patrol-point-' + item['id'] + '" ondragstart="drag(event)" data-obj=' + itemStr + ' style="font-size:14px;list-style:none;padding: 10px;height:20px;line-height:20px;cursor: move;">' + item['name'] + '</li>';
});
$("#patro-list-" + configOptions.floorId).html(patrolPointItem);
console.log(patrolPointInContainer);
patrolPointInContainer.forEach(function(point) {
$("#patrol-point-" + point.patrolPointId).remove();
});
$("#patrol-point-container").show();
});
}
function getPatrolPointsList1(configOptions) {
$.post(ext.contextPath + '/timeEfficiency/patrolArea/getPatrolPoints.do', {
floorId: configOptions.floorId,
type: configOptions.type,
unitId: configOptions.unitId
// patrolAreaId:configOptions.patrolAreaId
} , function(data) {
$("#patro-list-" + configOptions.floorId).html("");
JSON.parse(data).forEach(function(item) {
var itemStr = JSON.stringify(replaceJsonWhiteSpace(item));
var patrolPointItem = '<li class="patro-point" draggable="true" id="patrol-point-' + item['id'] + '" ondragstart="drag(event)" data-obj=' + itemStr + ' style="font-size:14px;list-style:none;padding: 10px;height:20px;line-height:20px;cursor: move;">' + item['name'] + '</li>';
$("#patro-list-" + configOptions.floorId).append(patrolPointItem);
});
$("#patrol-point-container").show();
});
}
// 首次获取巡检路径点信息
function getRoutePointsFirst(floorId,patrolPlanId,callback) {
$.post(ext.contextPath + '/structure/structureCardPicture/getRoutePoints.do?patrolPlanId=' + patrolPlanId + '&floorId=' + floorId, function(data) {
callback(data);
});
}
// 获取巡检路径点信息
function getRoutePoints(floorId,patrolPlanId,configOptions) {
$.post(ext.contextPath + '/structure/structureCardPicture/getRoutePoints.do?patrolPlanId=' + patrolPlanId + '&floorId=' + floorId, function(data) {
var copyPoints = deepClone(JSON.parse(data).rows);
// console.log(copyPoints);
copyPoints.forEach(function(item,index) {
var insdt1 = item['insdt'].replace(' ', 'kongbai');
var infos = {
text: "新",
state: 0,
message: "新"
};
item['routeId'] = item['id'];
item['insdt'] = insdt1;
item['infos'] = infos;
item['posX'] = item['posx'];
item['posY'] = item['posy'];
// if(item['previousId'] === "undefined") {
// item['prevId'] = null;
// item['previousId'] = null;
// } else {
// item['prevId'] = item['previousId'];
// item['previousId'] = item['previousId'];
// }
});
// console.log(copyPoints);
configOptions.points = copyPoints;
drawAllPath(configOptions);
});
}
function drawAllPath(configOptions) {
drawPath(configOptions);
localStorage.setItem("configOptions", JSON.stringify(configOptions));
$("#patrol-point-container").show();
}
function saveRoutePoint(param, callback) {
$.post(ext.contextPath + '/structure/structureCardPicture/saveRoutePoint.do', param, function(data) {
callback(data);
});
}
function updateRoutePoint(param, callback) {
$.post(ext.contextPath + '/structure/structureCardPicture/updateRoutePoint.do', param, function(data) {
callback(data);
});
}
function deleteRoutePoint(point,callback) {
$.post(ext.contextPath + '/structure/structureCardPicture/deleteRoutePoint.do?id=' + point.routeId + '&previousId=' + (point.prevId ? point.prevId : "") + '&nextId=' + (point.nextId ? point.nextId : ""), function(data) {
callback(data);
});
}
function replaceJsonWhiteSpace(jsonObj) {
for(var key in jsonObj) {
//如果对象类型为object类型且数组长度大于0 或者 是对象 ,继续递归解析
var element = jsonObj[key];
if(typeof element === 'string') {
jsonObj[key] = element.replace(" ", "kongbai");
}
if(element && element.length > 0 && typeof(element) == "object" || typeof(element) == "object") {
replaceJsonWhiteSpace(element);
} else { //不是对象或数组、直接输出
// console.log("----eles --> " + key + ":" + element + " ");
}
}
return jsonObj;
}
//生成唯一路径点ID
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
return (S4()+S4()+""+S4()+""+S4()+""+S4()+""+S4()+S4()+S4());
}