大量的if else
/**
* 判断是哪一种类型的元件
* @param {*节点_name} e
* @param {*返回值} v ==> properties_config
* @param {*当前元素} o
*/
function _chooseisname(e, v, o) {
if (!e) return;
/**
* 文字
*/
if (e._name == "文字") {
return o.addProperties(v.text_properties)
}
/**
* 负荷
*/
if (e._name == "负荷") {
// return (v.fh_properties, v.fhmr_properties)
return (o.addProperties(v.fhmr_properties), o.addProperties(v.fh_properties))
}
/**
* 发电机
*/
if (e._name == "发电机") {
return o.addProperties(v.fdj_properties)
}
/**
* 母线
*/
if (e instanceof ht.MuXian) {
return o.addProperties(v.node_properties)
}
/**
* 线路
*/
if (e instanceof ht.Node) {
return o.addProperties(v.edge_properties)
}
....
}
或者好一点的写 switch case
switch(e._name){
case "文字":
//语句
return o.addProperties(v.text_properties)
break; //可选
case "负荷" :
//语句
return (o.addProperties(v.fhmr_properties), o.addProperties(v.fh_properties))
break; //可选
...
//你可以有任意数量的case语句
default : //可选
....
//语句
}
const active = [
{
name: "文字", data: (e, v, o) => o.addProperties(v.text_properties)
},
{
name: "负荷", data: (e, v, o) => (o.addProperties(v.fhmr_properties), o.addProperties(v.fh_properties), o.addProperties(v.ys_properties))
},
{
name: "发电机", data: (e, v, o) => (o.addProperties(v.fdj_properties), o.addProperties(v.ys_properties))
}
]
function _chooseisname(e, v, o) {
if (!e) return;
let newFundata = active.filter(item => item.name == e._name);
if (newFundata.length == 0) {
/**
* 母线
*/
if (e instanceof ht.MuXian) {
return (o.addProperties(v.node_properties), o.addProperties(v.ys_properties))
}
/**
* 线路
*/
if (e instanceof ht.Node) {
return (o.addProperties(v.edge_properties), o.addProperties(v.ys_properties))
}
} else {
return newFundata[0].data(e, v, o)
}
}
或者
/**
* 元件对应的默认值
*/
const _Allmrz = [{
name: "负荷",
data: [
["MX_ID", "1"],
["KJQK", "1"],
["FH_YGGL", "1000"],
["FH_WGGL", "0"],
["HGL_YGGL", "1000"],
["HGL_WGGL", "0"],
["YYCL", "0"],
["DQB_LV", "15"],
["DJ_GLB", "15"],
["EDZCL", "0.0167"],
["JFS", "5"],
["Rs", "0.0035"],
["Xs", "0.1234"],
["Rr", "0.0133"],
["Xr", "0.1234"],
["xm", "2.0324"],
]
},
{
name: "发电机",
data: [
["MX_ID", "1"],
["MAX_YGGL", "10000"],
["MIN_YGGL", "0"],
["MAX_WGGL", "10000"],
["MIN_WGGL", "-10000"],
["ZT", "开"],
["GZB", "1"],
["XF_Time", "1"],
["YGXCXS", "0"],
["WGXCXS", "0"],
]
},
{
name: "文字",
data: [
["text.color", "#ffff"]
]
}
]
/**
* 判断默认值的元件
* @param {*当前所选的元素} s
*/
function _choosermr(s) {
const isNull = [[]]
if (!s) return;
let newArry = _Allmrz.filter(item => item.name == s._name)
return newArry ? newArry.length > 0 ? newArry[0].data : isNull : isNull
}