📄 setshowposition.js
字号:
// JScript 文件
var bDown = false;
var divObj, divX, divY, divZ;
var ObjSelected = null;
function mousemove()
{
if(!bDown)return;
divObj.style.left = document.documentElement.scrollLeft + event.x - divX;
divObj.style.top = document.documentElement.scrollTop + event.y - divY;
var imgMap = GetElementById("ImgMap");
GetElementById("TxtPointX").value = GetBrowserPositionX(divObj) - GetBrowserPositionX(imgMap);
GetElementById("TxtPointY").value = GetBrowserPositionY(divObj) - GetBrowserPositionY(imgMap);
}
function mousedown()
{
if(event.button!=1)return;
divObj = event.srcElement;
divObj.setCapture();
divZ = divObj.style.zIndex;
divObj.style.zIndex = 100;
divX = event.offsetX;
divY = event.offsetY;
bDown = true;
// SetCheckedByValueInGroup("RdoOperation","Update");
// SetOperationBtnValue('更新展位');
if (ObjSelected != null)
{
SetStyleClass(ObjSelected.id,"ShowPosition");
}
ObjSelected = divObj;
SetStyleClass(ObjSelected.id,"ShowPositionSelected");
}
function mouseup()
{
bDown = false;
divObj.style.zIndex = divZ;
divObj.releaseCapture();
var sp = ShowPositionList[parseInt(divObj.Num)];
if ((sp.PointX != GetBrowserPositionX(divObj)) || (sp.PointY != GetBrowserPositionY(divObj)))
{
if (sp.RowState != RowState.Added)
{
sp.RowState = RowState.Modified;
}
}
}
function mousedbclick()
{
divObj = event.srcElement;
var sp = ShowPositionList[parseInt(divObj.Num)];
SetCheckedByValueInGroup("RdoOperation","Update");
GetElementById("TxtName").value = divObj.innerHTML;
GetElementById("TxtDescription").value = sp.Description;
GetElementById("BtnOK").focus();
GetElementById("SpnId").innerHTML = divObj.Num;
var imgMap = GetElementById("ImgMap");
GetElementById("TxtPointX").value = GetBrowserPositionX(divObj) - GetBrowserPositionX(imgMap);
GetElementById("TxtPointY").value = GetBrowserPositionY(divObj) - GetBrowserPositionY(imgMap);
GetElementById("TxtWidth").value = sp.Width;
GetElementById("TxtHeight").value = sp.Height;
GetElementById("TxtPrice").value = sp.Price;
SetOperationBtnValue('更新展位');
ObjSelected = divObj;
}
function InsertShowPosition()
{
var sp = new ShowPosition();
sp.Id = 0;
sp.Name = GetElementById("TxtName").value;
sp.Description = GetElementById("TxtDescription").value;
var pointX = parseInt(GetElementById("TxtPointX").value);
var pointY = parseInt(GetElementById("TxtPointY").value);
sp.PointX = pointX;
sp.PointY = pointY;
sp.Width = GetElementById("TxtWidth").value;
sp.Height = GetElementById("TxtHeight").value;
sp.Price = GetElementById("TxtPrice").value;
sp.RowState = RowState.Added;
var num = ShowPositionList.length;
ShowPositionList.AddItem(sp);
GetElementById("ShowPositionPanel").insertAdjacentHTML("beforeEnd","<div class=\"ShowPosition\" id=\"SP" + num + "\" Num=\"" + num + "\" onmousedown=\"mousedown();\" onmouseup=\"mouseup();\" onmousemove=\"mousemove();\" ondblclick=\"mousedbclick();\">" + GetElementById("TxtName").value + "</div>");
var imgMap = GetElementById("ImgMap");
var divSp = GetElementById("SP" + num);
divSp.style.left = GetBrowserPositionX(imgMap) + pointX;
divSp.style.top = GetBrowserPositionY(imgMap) + pointY;
divSp.style.width = sp.Width;
divSp.style.height = sp.Height;
}
function UpdateShowPosition()
{
if (ObjSelected != null)
{
var sp = ShowPositionList[parseInt(ObjSelected.Num)];
sp.Name = GetElementById("TxtName").value;
sp.Description = GetElementById("TxtDescription").value;
if (sp.RowState != RowState.Added)
{
sp.RowState = RowState.Modified;
}
ObjSelected.innerHTML = sp.Name;
sp.Width = GetElementById("TxtWidth").value;
sp.Height = GetElementById("TxtHeight").value;
sp.Price = GetElementById("TxtPrice").value;
var imgMap = GetElementById("ImgMap");
ObjSelected.style.left = GetBrowserPositionX(imgMap) + parseInt(GetElementById("TxtPointX").value);
ObjSelected.style.top = GetBrowserPositionY(imgMap) + parseInt(GetElementById("TxtPointY").value);
ObjSelected.style.width = sp.Width;
ObjSelected.style.height = sp.Height;
}
else
{
alert("请双击选择要更新的展位");
}
}
function DeleteShowPosition()
{
if (ObjSelected != null)
{
var index = parseInt(ObjSelected.Num);
var sp = ShowPositionList[index];
if (sp.RowState == RowState.Added)
{
sp.RowState = RowState.None;
}
else
{
sp.RowState = RowState.Deleted;
}
var dataPanel = GetElementById("ShowPositionPanel");
dataPanel.removeChild(ObjSelected);
ObjSelected = null;
}
}
function SaveData()
{
var data = GetData();
if (!data.IsNullOrEmpty())
{
GetElementById("HidData").value = data;
FormSubmit();
}
else
{
alert("未改变任何数据,无须保存");
}
}
function GetData()
{
var result = "";
if (ShowPositionList.length > 0)
{
var saveData = new Array();
var imgMap = GetElementById("ImgMap");
var baseX = GetBrowserPositionX(imgMap);
var baseY = GetBrowserPositionY(imgMap);
var count = 0;
saveData.AddItem("<data>");
for (var i = 0;i < ShowPositionList.length; i++)
{
var sp = ShowPositionList[i];
if ((sp.RowState == RowState.Added) || (sp.RowState == RowState.Modified))
{
var objSP = GetElementById("SP" + i);
saveData.AddItem("<row>");
saveData.AddItem("<id>" + sp.Id + "</id>");
saveData.AddItem("<name>" + sp.Name + "</name>");
saveData.AddItem("<desc><![CDATA[" + sp.Description + "]]></desc>");
saveData.AddItem("<x>" + (GetBrowserPositionX(objSP) - baseX) + "</x>");
saveData.AddItem("<y>" + (GetBrowserPositionY(objSP) - baseY) + "</y>");
saveData.AddItem("<width>" + sp.Width + "</width>");
saveData.AddItem("<height>" + sp.Height + "</height>");
saveData.AddItem("<price>" + sp.Price + "</price>");
saveData.AddItem("<rowstate>" + sp.RowState + "</rowstate>");
saveData.AddItem("</row>");
count ++;
}
else if (sp.RowState == RowState.Deleted)
{
saveData.AddItem("<row>");
saveData.AddItem("<id>" + sp.Id + "</id>");
saveData.AddItem("<name></name>");
saveData.AddItem("<desc><![CDATA[]]></desc>");
saveData.AddItem("<x></x>");
saveData.AddItem("<y></y>");
saveData.AddItem("<width></width>");
saveData.AddItem("<height></height>");
saveData.AddItem("<price></price>");
saveData.AddItem("<rowstate>" + sp.RowState + "</rowstate>");
saveData.AddItem("</row>");
count ++;
}
}
saveData.AddItem("</data>");
if (count > 0)
{
result = saveData.join("");
}
}
return result;
}
function OK()
{
if (FormCheck())
{
if (GetCheckedValueInGroup("RdoOperation") == "Insert")
{
InsertShowPosition();
}
else
{
UpdateShowPosition();
}
}
}
function FormCheck()
{
var formControlList = new Array();
formControlList.AddItem(new FormControl("TxtName",CheckType.CheckEmpty,true,"请输入展位名称"));
formControlList.AddItem(new FormControl("TxtPointX",CheckType.CheckInt,true,"请输入展位X坐标,必须是数字型数据"));
formControlList.AddItem(new FormControl("TxtPointY",CheckType.CheckInt,true,"请输入展位Y坐标,必须是数字型数据"));
formControlList.AddItem(new FormControl("TxtWidth",CheckType.CheckInt,true,"请输入展位宽度,必须是数字型数据"));
formControlList.AddItem(new FormControl("TxtHeight",CheckType.CheckInt,true,"请输入展位高度,必须是数字型数据"));
formControlList.AddItem(new FormControl("TxtPrice",CheckType.CheckFloat,true,"请输入展位价格,必须是数字型数据"));
return CheckControlList(formControlList);
}
function SetOperationBtnValue(value)
{
GetElementById("BtnOK").value = value;
}
function PageInit()
{
var imgMap = GetElementById("ImgMap");
for (var i = 0; i < ShowPositionList.length; i++)
{
var sp = ShowPositionList[i];
var num = i;
GetElementById("ShowPositionPanel").insertAdjacentHTML("beforeEnd","<div style=\"width:" + sp.Width + "px;height:" + sp.Height + "px;\" class=\"ShowPosition\" id=\"SP" + num + "\" Num=\"" + num + "\" onmousedown=\"mousedown();\" onmouseup=\"mouseup();\" onmousemove=\"mousemove();\" ondblclick=\"mousedbclick();\">" + sp.Name + "</div>");
var divSp = GetElementById("SP" + num);
divSp.style.left = GetBrowserPositionX(imgMap) + parseInt(sp.PointX);
divSp.style.top = GetBrowserPositionY(imgMap) + parseInt(sp.PointY);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -