Authored by 袁晋鹏

优化选择设备和业务类型

... ... @@ -8,7 +8,6 @@ layui.define(['form', 'admin', 'laydate', 'common','sessions','reskpilist','tabl
var domainName = common.domainName;
var table = layui.table;
var xmSelect = layui.xmSelect;
//对外暴露的接口
exports('alarmpolicyAdd', function (data) {
var sessions = layui.sessions;
... ... @@ -254,11 +253,69 @@ layui.define(['form', 'admin', 'laydate', 'common','sessions','reskpilist','tabl
}
});
}
function handleTree(data, id, parentId, children, title) {
let config = {
id: id || 'id',
parentId: parentId || 'parentId',
childrenList: children || 'children',
title: title || 'title'
};
var childrenListMap = {};
var nodeIds = {};
var tree = [];
for (let d of data) {
let parentId = d[config.parentId];
let title = d[config.title]
if (childrenListMap[parentId] == null) {
childrenListMap[parentId] = [];
}
d.title = title;
nodeIds[d[config.id]] = d;
childrenListMap[parentId].push(d);
}
for (let d of data) {
let parentId = d[config.parentId];
let title = d[config.title]
d.title = title;
if (nodeIds[parentId] == null) {
tree.push(d);
}
}
for (let t of tree) {
adaptToChildrenList(t);
}
function adaptToChildrenList(o) {
if (childrenListMap[o[config.id]] !== null) {
o[config.childrenList] = childrenListMap[o[config.id]];
}
if (o[config.childrenList]) {
for (let c of o[config.childrenList]) {
adaptToChildrenList(c);
}
}
}
return tree;
};
form.on('select(serious_policy_param)', function(data){
var seriousvalue =$(this).closest(".cont-base").find("div#seriousvalue");
var devTypevalue =$(this).closest(".cont-base").find("div#seriousdevTypevalue");
var joinTypevalue =$(this).closest(".cont-base").find("div#seriousjoinTypevalue");
if(seriousvalue){
seriousvalue.remove();
}
if(devTypevalue){
devTypevalue.remove();
}
if(joinTypevalue){
joinTypevalue.remove();
}
if (data.value != ''){
//加载对应的参数
if(data.value == "device_id"){
... ... @@ -286,47 +343,165 @@ layui.define(['form', 'admin', 'laydate', 'common','sessions','reskpilist','tabl
})
}else if(data.value== "dev_type"){
var dev_type = $(this).closest(".cont-base").find("input[type=tel]");
//var dev_type = $(this).closest(".cont-base").find("input[type=tel]");
$(this).closest(".cont-base").find("input[type=tel]").before('<div id="seriousdevTypevalue" class="xm-select-demo" style="width:478px;position: absolute;z-index: 999"></div>');
var dev_type= $(this).closest(".cont-base").find("input[type=tel]");
$(this).closest(".cont-base").find("input[type=tel]").unbind('click').on("click",function () {
//回填数据
common.openWin("baseconfig/resourcetype/index", "选择设备类型",
{
"resTypes": seriousresTypes
}, ["选择"], function () {
//找到选择的资源类型 并且订阅
var resourcetype = layui.resourcetype({"resTypes": seriousresTypes});
var data = resourcetype.getResTypeChecks();
var resTypes = ''
seriousresTypes = [];
if(data.length>0){
resTypes = data.substring(1,data.length)
}
seriousresTypes.push(resTypes.split(",")[0])
dev_type.val(resTypes);
return resTypes;
});
// common.openWin("baseconfig/resourcetype/index", "选择设备类型",
// {
// "resTypes": seriousresTypes
// }, ["选择"], function () {
// //找到选择的资源类型 并且订阅
// var resourcetype = layui.resourcetype({"resTypes": seriousresTypes});
// var data = resourcetype.getResTypeChecks();
// var resTypes = ''
// seriousresTypes = [];
// if(data.length>0){
// resTypes = data.substring(1,data.length)
// }
// seriousresTypes.push(resTypes.split(",")[0])
// dev_type.val(resTypes);
// return resTypes;
// });
$.ajax({
url:'http://192.168.0.44:8080' +"/log-access/v1/lm2_logfmt_dirs/queryTreeList?access_token="+accessToken,
method:"get",
success(res){
if (res.code==200)
// 资源类型下拉框
var data = res.data;
var logFmtList = res.data.map(item => {
return {
name: item.name,
value: item.id,
parentId: item.pId
}
});
let option = handleTree(res.data, 'id', 'pId','children','name');
xmSelect.render({
el: '#seriousdevTypevalue',
name:'devType',
tips: '=设备类型=',
radio: false,
clickClose: false,
//checkChild:true,
//radio: true,
//clickClose: true,
// initValue: [resType],
prop: {
name: 'name',
value: 'id'
},
filterable: true,
layVerify: 'required',
//layVerType: 'msg',
//initValue: [seriousInkeys.split(",")[0]],
toolbar: {
show: true,
list: ['CLEAR']
},
tree: {
//是否显示树状结构
show: true,
//是否展示三角图标
showFolderIcon: true,
//是否显示虚线
showLine: false,
//是否严格遵守父子模式
strict: true
},
data:option,
on: function (data) {
seriousresTypes = data.arr.map(item => item.id).join(',');
dev_type.val(seriousresTypes);
if(data && data.isAdd) {
//seriousvalue.remove();
//inkeys.show();
}
return seriousresTypes
}
});
return data;
}
});
});
}else if(data.value == "join_type"){
$(this).closest(".cont-base").find("input[type=tel]").before('<div id="seriousjoinTypevalue" class="xm-select-demo" style="width:478px;position: absolute;z-index: 999"></div>');
var join_type= $(this).closest(".cont-base").find("input[type=tel]");
$(this).closest(".cont-base").find("input[type=tel]").unbind('click').on("click",function () {
//回填数据
common.openWin("baseconfig/bustype/index", "选择业务类型",
{
"busIds": seriousJoinTypes
}, ["选择"], function () {
//找到选择的所有业务 并且订阅
var bustype = layui.bustype({"busIds": seriousJoinTypes});
var data = bustype.getData();
var joinTypes = ''
seriousJoinTypes = [];
if(data.length>0){
joinTypes = data.substring(1,data.length)
}
seriousJoinTypes.push(joinTypes.split(",")[0]);
console.log(seriousJoinTypes);
join_type.val(joinTypes);
return joinTypes
});
// common.openWin("baseconfig/bustype/index", "选择业务类型",
// {
// "busIds": seriousJoinTypes
// }, ["选择"], function () {
// //找到选择的所有业务 并且订阅
// var bustype = layui.bustype({"busIds": seriousJoinTypes});
// var data = bustype.getData();
// var joinTypes = ''
// seriousJoinTypes = [];
// if(data.length>0){
// joinTypes = data.substring(1,data.length)
// }
// seriousJoinTypes.push(joinTypes.split(",")[0]);
// console.log(seriousJoinTypes);
// join_type.val(joinTypes);
// return joinTypes
// });
$.ajax({
url:'http://192.168.0.44:8080' +"/log-access/v1/lm2_logjoin_dirs/queryTreeList?access_token="+accessToken,
method:"get",
success(res){
if (res.code==200)
// 资源类型下拉框
var data = res.data;
let option = handleTree(res.data, 'id', 'pId','children','name');
xmSelect.render({
el: '#seriousjoinTypevalue',
name:'joinType',
tips: '=业务类型=',
radio: false,
clickClose: false,
//checkChild:true,
//radio: true,
//clickClose: true,
// initValue: [resType],
prop: {
name: 'name',
value: 'id'
},
filterable: true,
layVerify: 'required',
//layVerType: 'msg',
//initValue: [seriousInkeys.split(",")[0]],
toolbar: {
show: true,
list: ['CLEAR']
},
tree: {
//是否显示树状结构
show: true,
//是否展示三角图标
showFolderIcon: true,
//是否显示虚线
showLine: false,
//是否严格遵守父子模式
strict: true
},
data:option,
on: function (data) {
seriousJoinTypes = data.arr.map(item => item.id).join(',');
join_type.val(seriousJoinTypes);
if(data && data.isAdd) {
//seriousvalue.remove();
//inkeys.show();
}
return seriousJoinTypes
}
});
return data;
}
});
});
}else if(data.value == "inKey"){
//绑定资源类型下拉选择
... ... @@ -379,6 +554,15 @@ layui.define(['form', 'admin', 'laydate', 'common','sessions','reskpilist','tabl
if(importantvalue){
importantvalue.remove();
}
var devTypevalue =$(this).closest(".cont-base").find("div#importantdevTypevalue");
var joinTypevalue =$(this).closest(".cont-base").find("div#importantjoinTypevalue");
if(devTypevalue){
devTypevalue.remove();
}
if(joinTypevalue){
joinTypevalue.remove();
}
if (data.value != ''){
//加载对应的参数
if(data.value == "device_id"){
... ... @@ -407,46 +591,122 @@ layui.define(['form', 'admin', 'laydate', 'common','sessions','reskpilist','tabl
})
}else if(data.value== "dev_type"){
var dev_type = $(this).closest(".cont-base").find("input[type=tel]");
$(this).closest(".cont-base").find("input[type=tel]").before('<div id="importantdevTypevalue" class="xm-select-demo" style="width:478px;position: absolute;z-index: 999"></div>');
var dev_type= $(this).closest(".cont-base").find("input[type=tel]");
$(this).closest(".cont-base").find("input[type=tel]").unbind('click').on("click",function () {
//回填数据
common.openWin("baseconfig/resourcetype/index", "选择设备类型",
{
"resTypes": importantresTypes
}, ["选择"], function () {
//找到选择的资源类型 并且订阅
var resourcetype = layui.resourcetype({"resTypes": importantresTypes});
var data = resourcetype.getResTypeChecks();
var resTypes = ''
importantresTypes = [];
if(data.length>0){
resTypes = data.substring(1,data.length)
}
importantresTypes.push(resTypes.split(",")[0])
dev_type.val(resTypes);
return resTypes;
});
$.ajax({
url:'http://192.168.0.44:8080' +"/log-access/v1/lm2_logfmt_dirs/queryTreeList?access_token="+accessToken,
method:"get",
success(res){
if (res.code==200)
// 资源类型下拉框
var data = res.data;
let option = handleTree(res.data, 'id', 'pId','children','name');
xmSelect.render({
el: '#importantdevTypevalue',
name:'importantdevType',
tips: '=设备类型=',
radio: false,
clickClose: false,
//checkChild:true,
//radio: true,
//clickClose: true,
// initValue: [resType],
prop: {
name: 'name',
value: 'id'
},
filterable: true,
layVerify: 'required',
//layVerType: 'msg',
//initValue: [seriousInkeys.split(",")[0]],
toolbar: {
show: true,
list: ['CLEAR']
},
tree: {
//是否显示树状结构
show: true,
//是否展示三角图标
showFolderIcon: true,
//是否显示虚线
showLine: false,
//是否严格遵守父子模式
strict: true
},
data:option,
on: function (data) {
importantresTypes = data.arr.map(item => item.id).join(',');
dev_type.val(importantresTypes);
if(data && data.isAdd) {
//seriousvalue.remove();
//inkeys.show();
}
return importantresTypes;
}
});
return data;
}
});
});
}else if(data.value == "join_type"){
$(this).closest(".cont-base").find("input[type=tel]").before('<div id="importantjoinTypevalue" class="xm-select-demo" style="width:478px;position: absolute;z-index: 999"></div>');
var join_type= $(this).closest(".cont-base").find("input[type=tel]");
$(this).closest(".cont-base").find("input[type=tel]").unbind('click').on("click",function () {
//回填数据
common.openWin("baseconfig/bustype/index", "选择业务类型",
{
"busIds": importantJoinTypes
}, ["选择"], function () {
//找到选择的所有业务 并且订阅
var bustype = layui.bustype({"busIds": importantJoinTypes});
var data = bustype.getData();
var joinTypes = ''
importantJoinTypes = [];
if(data.length>0){
joinTypes = data.substring(1,data.length)
}
importantJoinTypes.push(joinTypes.split(",")[0]);
join_type.val(joinTypes);
return joinTypes
});
$.ajax({
url:'http://192.168.0.44:8080' +"/log-access/v1/lm2_logjoin_dirs/queryTreeList?access_token="+accessToken,
method:"get",
success(res){
if (res.code==200)
// 资源类型下拉框
var data = res.data;
let option = handleTree(res.data, 'id', 'pId','children','name');
xmSelect.render({
el: '#importantjoinTypevalue',
name:'importantjoinType',
tips: '=业务类型=',
radio: false,
clickClose: false,
//checkChild:true,
//radio: true,
//clickClose: true,
// initValue: [resType],
prop: {
name: 'name',
value: 'id'
},
filterable: true,
layVerify: 'required',
//layVerType: 'msg',
//initValue: [seriousInkeys.split(",")[0]],
toolbar: {
show: true,
list: ['CLEAR']
},
tree: {
//是否显示树状结构
show: true,
//是否展示三角图标
showFolderIcon: true,
//是否显示虚线
showLine: false,
//是否严格遵守父子模式
strict: true
},
data:option,
on: function (data) {
importantJoinTypes = data.arr.map(item => item.id).join(',');
join_type.val(importantJoinTypes);
if(data && data.isAdd) {
//seriousvalue.remove();
//inkeys.show();
}
return importantJoinTypes
}
});
return data;
}
});
});
}else if(data.value == "inKey"){
//绑定资源类型下拉选择
... ... @@ -500,6 +760,15 @@ layui.define(['form', 'admin', 'laydate', 'common','sessions','reskpilist','tabl
if(commonlyvalue){
commonlyvalue.remove();
}
var devTypevalue =$(this).closest(".cont-base").find("div#commonlydevTypevalue");
var joinTypevalue =$(this).closest(".cont-base").find("div#commonlyjoinTypevalue");
if(devTypevalue){
devTypevalue.remove();
}
if(joinTypevalue){
joinTypevalue.remove();
}
if (data.value != ''){
//加载对应的参数
if(data.value == "device_id"){
... ... @@ -528,46 +797,122 @@ layui.define(['form', 'admin', 'laydate', 'common','sessions','reskpilist','tabl
})
}else if(data.value== "dev_type"){
var dev_type = $(this).closest(".cont-base").find("input[type=tel]");
$(this).closest(".cont-base").find("input[type=tel]").before('<div id="commonlydevTypevalue" class="xm-select-demo" style="width:478px;position: absolute;z-index: 999"></div>');
var dev_type= $(this).closest(".cont-base").find("input[type=tel]");
$(this).closest(".cont-base").find("input[type=tel]").unbind('click').on("click",function () {
//回填数据
common.openWin("baseconfig/resourcetype/index", "选择设备类型",
{
"resTypes": commonlyresTypes
}, ["选择"], function () {
//找到选择的资源类型 并且订阅
var resourcetype = layui.resourcetype({"resTypes": commonlyresTypes});
var data = resourcetype.getResTypeChecks();
var resTypes = ''
commonlyresTypes = [];
if(data.length>0){
resTypes = data.substring(1,data.length)
}
commonlyresTypes.push(resTypes.split(",")[0])
dev_type.val(resTypes);
return resTypes;
});
$.ajax({
url:'http://192.168.0.44:8080' +"/log-access/v1/lm2_logfmt_dirs/queryTreeList?access_token="+accessToken,
method:"get",
success(res){
if (res.code==200)
// 资源类型下拉框
var data = res.data;
let option = handleTree(res.data, 'id', 'pId','children','name');
xmSelect.render({
el: '#commonlydevTypevalue',
name:'commonlydevType',
tips: '=设备类型=',
radio: false,
clickClose: false,
//checkChild:true,
//radio: true,
//clickClose: true,
// initValue: [resType],
prop: {
name: 'name',
value: 'id'
},
filterable: true,
layVerify: 'required',
//layVerType: 'msg',
//initValue: [seriousInkeys.split(",")[0]],
toolbar: {
show: true,
list: ['CLEAR']
},
tree: {
//是否显示树状结构
show: true,
//是否展示三角图标
showFolderIcon: true,
//是否显示虚线
showLine: false,
//是否严格遵守父子模式
strict: true
},
data:option,
on: function (data) {
commonlyresTypes = data.arr.map(item => item.id).join(',');
dev_type.val(commonlyresTypes);
if(data && data.isAdd) {
//seriousvalue.remove();
//inkeys.show();
}
return commonlyresTypes;
}
});
return data;
}
});
});
}else if(data.value == "join_type"){
$(this).closest(".cont-base").find("input[type=tel]").before('<div id="commonlyjoinTypevalue" class="xm-select-demo" style="width:478px;position: absolute;z-index: 999"></div>');
var join_type= $(this).closest(".cont-base").find("input[type=tel]");
$(this).closest(".cont-base").find("input[type=tel]").unbind('click').on("click",function () {
//回填数据
common.openWin("baseconfig/bustype/index", "选择业务类型",
{
"busIds": commonlyJoinTypes
}, ["选择"], function () {
//找到选择的所有业务 并且订阅
var bustype = layui.bustype({"busIds": commonlyJoinTypes});
var data = bustype.getData();
var joinTypes = ''
commonlyJoinTypes = [];
if(data.length>0){
joinTypes = data.substring(1,data.length)
}
commonlyJoinTypes.push(joinTypes.split(",")[0]);
join_type.val(joinTypes);
return joinTypes
});
$.ajax({
url:'http://192.168.0.44:8080' +"/log-access/v1/lm2_logjoin_dirs/queryTreeList?access_token="+accessToken,
method:"get",
success(res){
if (res.code==200)
// 资源类型下拉框
var data = res.data;
let option = handleTree(res.data, 'id', 'pId','children','name');
xmSelect.render({
el: '#commonlyjoinTypevalue',
name:'commonlyjoinType',
tips: '=业务类型=',
radio: false,
clickClose: false,
//checkChild:true,
//radio: true,
//clickClose: true,
// initValue: [resType],
prop: {
name: 'name',
value: 'id'
},
filterable: true,
layVerify: 'required',
//layVerType: 'msg',
//initValue: [seriousInkeys.split(",")[0]],
toolbar: {
show: true,
list: ['CLEAR']
},
tree: {
//是否显示树状结构
show: true,
//是否展示三角图标
showFolderIcon: true,
//是否显示虚线
showLine: false,
//是否严格遵守父子模式
strict: true
},
data:option,
on: function (data) {
commonlyJoinTypes = data.arr.map(item => item.id).join(',');
join_type.val(commonlyJoinTypes);
if(data && data.isAdd) {
//seriousvalue.remove();
//inkeys.show();
}
return commonlyJoinTypes;
}
});
return data;
}
});
});
}else if(data.value == "inKey"){
//绑定资源类型下拉选择
... ...