📄 topflow.js
字号:
this.Modified = false;
this.Steps = [];
this.Procs = [];
this.SelectedObject = null;
this.Password = "";
this.Config = {
_ProcColor : "#FF0000", //开始/结束
_ProcTextColor : "#FF0000", //开始/结束
ProcColor : "#0000FF",
ProcTextColor : "#0000FF",
ProcFocusedStrokeColor : "#FFFF00",
IsProcShadow : "T",
ProcShadowColor : "#B3B3B3",
ProcColor1 : "#FFFFFF",
ProcColor2 : "#FFFFFF",
IsProc3D : "F",
Proc3DDepth : "20",
StepFocusedStrokeColor : "#904E80",
StepColor : "#0000FF"
}
}
//
TTopFlow.prototype.getInnerObject = function(){
for(var i = 0;i<this.Procs.length; i++)
this.Procs[i].getInnerObject();
for(i = 0;i<this.Steps.length; i++)
this.Steps[i].getInnerObject();
}
//选中某个对象
TTopFlow.prototype.selectObject = function(aID, aType){
this.unSelectObject();
this.SelectedObject = (aType == "Proc")?this.getProcByID(aID):this.getStepByID(aID);
this.SelectedObject.setFocus();
}
//取消选中某个对象
TTopFlow.prototype.unSelectObject = function(){
if(this.SelectedObject != null) this.SelectedObject.lostFocus();
this.SelectedObject = null;
}
//清除流程图的内容
TTopFlow.prototype.clear = function(){
this.FileName = '';
this.Steps.length = 0;
this.Procs.length = 0;
}
//新建流程图
TTopFlow.prototype.createNew = function(AName){
this.clear();
//增加开始结点
Proc = new TProc(this, "begin");
Proc.Text = "开始";
Proc.ShapeType = "Oval";
Proc.ProcType = "BeginProc";
Proc.X = "0";
Proc.Y = "30";
this.addProc(Proc);
//增加结束结点
Proc = new TProc(this, "end");
Proc.Text = "结束";
Proc.ShapeType = "Oval";
Proc.ProcType = "EndProc";
Proc.X = "700";
Proc.Y = "350";
this.addProc(Proc);
}
//添加流程图的[任务]元素对象
TTopFlow.prototype.addProc = function(AProc){
if(this.Procs.length >= 20){
alert("根据比赛要求,最多不允许超过20个任务!");
return false;
}
this.Modified = true;
this.Procs[this.Procs.length] = AProc;
}
//添加流程图的[路径]元素对象
TTopFlow.prototype.addStep = function(AStep){
this.Steps[this.Steps.length] = AStep;
this.Modified = true;
}
TTopFlow.prototype.changeProcID = function(OldID, NewID){alert("changeProcID");
var Step;
for(var i = 0; i< this.Steps.length; i++){
Step = this.Steps[i];
if(Step.FromProc == OldID) Step.FromProc = NewID;
if(Step.ToProc == OldID) Step.ToProc = NewID;
}
}
//获取一个[任务]的二维数据集视图
TTopFlow.prototype.getProcDataView = function(AProcID){
var arr = [], Step;
for(var i = 0; i < this.Steps.length; i++){
Step = this.Steps[i];
if(Step.ToProc == AProcID){
S = this.getProcByID(Step.FromProc).Text;
arr[arr.length] = new Array(Step.ID, S, Step.Cond);
}
}
return arr;
}
//获取整个[流程图]的二维数据集视图
TTopFlow.prototype.DataView = function(){
var Proc; arrDataView = [], arr = [];
var i,j, u, k = 0;
for(i = 0; i < this.Procs.length; i++){
Proc = this.Procs[i];
arr.length = 0;
arr = this.getProcDataView(Proc.ID);
u = arr.length;
if(u != undefined && u != null && u > 0){
for(j = 0; j < arr.length; j++){
arrDataView[k++] = {
"ProcID" : Proc.ID,
"ProcText" : Proc.Text,
"Idx" : j + 1,
"PreProcID" : arr[j][0],
"PreProcText" : arr[j][1],
"Cond" : arr[j][2]
}
}
}
}
return arrDataView;
}
TTopFlow.prototype.hasPriorProc = function(AProcID){
for(var i = 0; i < this.Steps.length; i++)
if(this.Steps[i].ToProc == AProcID) return true;
return false;
}
TTopFlow.prototype.hasNextProc = function(AProcID){
for(var i = 0; i < this.Steps.length; i++)
if(this.Steps[i].FromProc == AProcID) return true;
return false;
}
TTopFlow.prototype.validate = function(){
var ErrMsg = []; WarnMsg = [];
var Proc, PType;
for(var i = 0; i < this.Procs.length; i++){
Proc = this.Procs[i];
PType = (Proc.ProcType == "NormalProc"?"中间任务":(Proc.ProcType == "BeginProc"?"开始任务":"结束任务"));
if(Proc.ProcType == "NormalProc" || Proc.ProcType == "EndProc")
if(!this.hasPriorProc(Proc.ID)) ErrMsg.push("[" + Proc.Text + "] - " + PType + "必须有输入路径");
if(Proc.ProcType == "NormalProc" || Proc.ProcType == "BeginProc")
if(!this.hasNextProc(Proc.ID)) ErrMsg.push("[" + Proc.Text + "] - " + PType + "必须有输出路径");
}
return ErrMsg.join("\n") + WarnMsg.join("\n");
}
//从XML文件中载入流程图
TTopFlow.prototype.loadFromXML = function(AFileName){
this.clear();
this.FileName = AFileName;
var xmlDoc = new ActiveXObject('MSXML2.DOMDocument');
xmlDoc.async = false;
var flag = xmlDoc.load('data/' + AFileName);
//var flag = xmlDoc.load('/_CommitSys/_CommitFlow/_createFlowXML.asp?defid='+AFileName);
if (!flag) {
alert('文件[' + AFileName + '载入失败!');
this.createNew("");
return false;
}
var xmlRoot = xmlDoc.documentElement;
this.Text = xmlRoot.getAttribute("text");
this.Password = xmlRoot.getAttribute("password");
this.ID = xmlRoot.getAttribute("id");
this.FormID = xmlRoot.getAttribute("formid");
//Load Proc
var Procs = xmlRoot.getElementsByTagName("Procs").item(0);
var id, oNode, Prop;
for (i = 0;i < Procs.childNodes.length;i++) {
var Proc = Procs.childNodes.item(i);
Prop = Proc.getElementsByTagName("BaseProperties").item(0);
id = Prop.getAttribute("id");
oNode = new TProc(this,id);
oNode.Text = Prop.getAttribute("text");
oNode.ProcType = Prop.getAttribute("procType");
//新增
oNode.actFlag = Prop.getAttribute("actFlag");
oNode.waittime = Prop.getAttribute("waittime");
oNode.isSltTrans = Prop.getAttribute("isSltTrans");
oNode.isSameCredit = Prop.getAttribute("isSameCredit");
Prop = Proc.getElementsByTagName("VMLProperties").item(0);
oNode.ShapeType = Prop.getAttribute("shapetype");
oNode.Width = Prop.getAttribute("width");
oNode.Height = Prop.getAttribute("height");
oNode.X = Prop.getAttribute("x");
oNode.Y = Prop.getAttribute("y");
oNode.TextWeight = Prop.getAttribute("textWeight");
oNode.StrokeWeight = Prop.getAttribute("strokeWeight");
oNode.zIndex = Prop.getAttribute("zIndex");
if(oNode.zIndex =='') oNode.zIndex = this.getMinZIndex() - 1;
this.addProc(oNode);
}
//Load Step
var Steps = xmlRoot.getElementsByTagName("Steps").item(0);
for (i = 0;i < Steps.childNodes.length;i++){
var Step = Steps.childNodes.item(i);
Prop = Step.getElementsByTagName("BaseProperties").item(0);
id = Prop.getAttribute("id");
oNode = new TStep(this,id);
oNode.Text = Prop.getAttribute("text");
oNode.FromProc = Prop.getAttribute("from");
oNode.ToProc = Prop.getAttribute("to");
oNode.Cond = Prop.getAttribute("cond");
oNode.Cond = oNode.Cond.replace(/\'/g,'"')
Prop = Step.getElementsByTagName("VMLProperties").item(0);
oNode.Points = Prop.getAttribute("points");
oNode.fromRelX = Prop.getAttribute("fromRelX");
oNode.fromRelY = Prop.getAttribute("fromRelY");
oNode.toRelX = Prop.getAttribute("toRelX");
oNode.toRelY = Prop.getAttribute("toRelY");
oNode.ShapeType = Prop.getAttribute("shapetype");
oNode.StartArrow = Prop.getAttribute("startArrow");
oNode.EndArrow = Prop.getAttribute("endArrow");
oNode.StrokeWeight = Prop.getAttribute("strokeWeight");
oNode.zIndex = Prop.getAttribute("zIndex");
if(oNode.zIndex =='') oNode.zIndex = this.getMinZIndex() - 1;
this.addStep(oNode);
}
this.Modified = false;
return true;
}
//将流程图保存至服务器上的XML文件中
TTopFlow.prototype.SaveToXML = function(AUrl){
var xmlDoc = new ActiveXObject('MSXML2.DOMDocument');
xmlDoc.async = false;
xmlDoc.loadXML('<?xml version="1.0" encoding="GBK"?><TopFlow/>');
var xmlRoot = xmlDoc.documentElement;
var xmlNodeGrp, xmlNode, xmlNode2;
xmlRoot.setAttribute("id", this.ID);
xmlRoot.setAttribute("formid", this.FormID);//新增
xmlRoot.setAttribute("filename", this.FileName);
xmlRoot.setAttribute("text", this.Text);
xmlRoot.setAttribute("password", this.Password);
//Save Proc
var xmlNodeGrp = xmlDoc.createNode(1,"Procs","");
xmlRoot.appendChild(xmlNodeGrp);
for(var i = 0; i < this.Procs.length; i++){
Proc = this.Procs[i];
xmlNode = xmlDoc.createNode(1, "Proc", "");
xmlNode2 = xmlDoc.createNode(1, "BaseProperties", "");
xmlNode2.setAttribute("id", Proc.ID);
xmlNode2.setAttribute("text", Proc.Text);
xmlNode2.setAttribute("procType", Proc.ProcType);
xmlNode2.setAttribute("actFlag", Proc.actFlag);
xmlNode2.setAttribute("waittime", Proc.waittime);
xmlNode2.setAttribute("isSltTrans", Proc.isSltTrans);
xmlNode2.setAttribute("isSameCredit", Proc.isSameCredit);
xmlNode.appendChild(xmlNode2);
xmlNode2 = xmlDoc.createNode(1, "VMLProperties", "");
xmlNode2.setAttribute("shapetype", Proc.ShapeType);
xmlNode2.setAttribute("width", Proc.Width);
xmlNode2.setAttribute("height", Proc.Height);
xmlNode2.setAttribute("x", Proc.X);
xmlNode2.setAttribute("y", Proc.Y);
xmlNode2.setAttribute("textWeight", Proc.TextWeight);
xmlNode2.setAttribute("strokeWeight", Proc.StrokeWeight);
xmlNode2.setAttribute("zIndex", Proc.zIndex);
xmlNode.appendChild(xmlNode2);
xmlNodeGrp.appendChild(xmlNode);
}
//Save Step
xmlNodeGrp = xmlDoc.createNode(1,"Steps","");
xmlRoot.appendChild(xmlNodeGrp);
for(i = 0; i < this.Steps.length; i++){
Step = this.Steps[i];
xmlNode = xmlDoc.createNode(1, "Step", "");
xmlNode2 = xmlDoc.createNode(1, "BaseProperties", "");
xmlNode2.setAttribute("id", Step.ID);
xmlNode2.setAttribute("text", Step.Text);
xmlNode2.setAttribute("from", Step.FromProc);
xmlNode2.setAttribute("to", Step.ToProc);
xmlNode2.setAttribute("cond", Step.Cond);
xmlNode.appendChild(xmlNode2);
xmlNode2 = xmlDoc.createNode(1, "VMLProperties", "");
xmlNode2.setAttribute("points", Step.Points);
xmlNode2.setAttribute("fromRelX", Step.fromRelX);
xmlNode2.setAttribute("fromRelY", Step.fromRelY);
xmlNode2.setAttribute("toRelX", Step.toRelX);
xmlNode2.setAttribute("toRelY", Step.toRelY);
xmlNode2.setAttribute("shapetype", Step.ShapeType);
xmlNode2.setAttribute("startArrow", Step.StartArrow);
xmlNode2.setAttribute("endArrow", Step.EndArrow);
xmlNode2.setAttribute("strokeWeight", Step.StrokeWeight);
xmlNode2.setAttribute("zIndex", Step.zIndex);
xmlNode.appendChild(xmlNode2);
xmlNodeGrp.appendChild(xmlNode);
}
var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.open("POST", "_saveFlowXML.asp?defid=" + this.ID, false);
xmlHttp.send(xmlDoc.xml);
S = xmlHttp.responseText.trim();
this.Modified = (S != "");
return S;
}
//根据[任务]的ID获取[任务]对象
TTopFlow.prototype.getProcByID = function(id){
for(var i = 0; i<this.Procs.length; i++)
if(this.Procs[i].ID == id) return this.Procs[i];
return null;
}
//根据[路径]的ID获取[路径]对象
TTopFlow.prototype.getStepByID = function(id){
for(var i = 0; i<this.Steps.length; i++)
if(this.Steps[i].ID == id) return this.Steps[i];
return null;
}
TTopFlow.prototype.getProcAtXY = function(x, y){
var Proc;
for(var i = 0; i < this.Procs.length; i++){
Proc = this.Procs[i];
if(x >= parseInt(Proc.X) && x <= parseInt(Proc.X) + parseInt(Proc.Width) && y >= parseInt(Proc.Y) && y <= parseInt(Proc.Y) + parseInt(Proc.Height)){
return Proc;
}
}
return null;
}
TTopFlow.prototype.IDExists = function(id){
var obj = _FLOW.getProcByID(id);
if(obj != null) return true;
var obj = _FLOW.getStepByID(id);
return (obj != null);
}
TTopFlow.prototype.StepPathExists = function(FromProc, ToProc){
var Step;
for(var i = 0; i< this.Steps.length; i++){
Step = this.Steps[i];
if(Step.FromProc == FromProc && Step.ToProc == ToProc) return Step;
}
return null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -