1. 拼接一段话
function mean_sum(id,title,state){
var html=""
for(var i=0;i<state.length;i++){
sum=state[i].iPActiveCount+state[i].offlineIPCount;
percent=(state[i].iPActiveCount/sum*100).toFixed(0)+"%"
html=state[i].ips+"共有网段"+state[i].port+"个,其中终端网段"+state[i].port+"个。 IP地址空间总数"+state[i].iPTotalCount+"个,总资产数"+sum+"个,其中在线"+state[i].iPActiveCount+"个,在线率为"+percent
}
content = document.getElementById(id);
var div=document.createElement("div");
title=document.createTextNode(title);
div.className = "report_h report_h2"
div.appendChild(title)
content.appendChild(div)
var condiv=document.createElement("div");
content.appendChild(condiv)
var context = document.createElement("div");
context.style="font-weight: normal;font-size:14px"
contitle=document.createTextNode(html);
context.appendChild(contitle)
condiv.appendChild(context)
}
var data10=[
{
ips:"10.8.8.8",
port:1,
iPTotalCount:256,
iPActiveCount:13,
offlineIPCount:13,
}
]
//调用
mean_sum('mean_sum',"1.资产状态总览",data10)
2.拼接一个模块
//排序
var a=1
//防止id重复
var count=0
function special(id,title,tabletitle,topData){
var topID="special"+count
console.log(topID)
content = document.getElementById(id);
//不重复调用同个标题
if(title!=null){
var div=document.createElement("div");
title=document.createTextNode(title);
div.className = "report_h report_h2"
div.appendChild(title)
content.appendChild(div)
}
var tab=document.createElement("div")
tabletitle=document.createTextNode("3."+a+tabletitle+"--共"+topData.length+"个");
tab.appendChild(tabletitle)
content.appendChild(tab)
var tableID=document.createElement("div")
tableID.id=topID
tab.appendChild(tableID)
//表格封装,可看我另一篇文章
new Tablefive({
tableId: topID,
theader: ["序号", "IP地址", "端口号","服务信息",'IP类型','所属网段','组织结构位置','接入信息','扫描时间'],
style: true,
data: topData
})
count++
a++
}
special("special_sum","3.详情","开放详情(TCP/21)",data30)
special("special_sum",null,"开放详情(TCP/23)",data30)