"use strict"; app.controller("sysconfigCtrl", ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "$window", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_sysinfo", "api_is_category", "api_bpm_data", function (t, a, n, e, i, s, r, o, l, u, d, c, g, api_is_category, api_bpm_data) { a.langs = l.getAllLangs(), a.lang = "zh-cn", l.setCurrentLang(a.lang); var f = (t.user, r._, { idx: 0, sum: 1e3 }); // a.autoCloseIncidentHour = 24;//默认24小时自动关单 a.changeAutoCloseIncidentHour = function(e){ var v = parseFloat(e.target.value)?parseFloat(e.target.value):0; a.autoCloseIncidentHour.valueconfig = v > 0 ? v : 0; } a.changeUpdatePwdMonth = function(e){ var v = parseFloat(e.target.value)?parseFloat(e.target.value):0; a.updatePwdMonth.valueconfig = v > 0 ? v : 0; } function convertListToTree(data, treeMap) { var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup var root = null; //Initially set our loop to null var parentNode = null; //loop over data for (var i = 0; i < data.length; i++) { var datum = data[i]; //each node will have children, so let's give it a "children" poperty datum.children = []; //add an entry for this node to the map so that any future children can //lookup the parent idToNodeMap[datum.id] = datum; //Does this node have a parent? if (typeof datum.parent === "undefined" || datum.parent == null) { //Doesn't look like it, so this node is the root of the tree root = datum; treeMap[datum.id] = root; } else { //This node has a parent, so let's look it up using the id parentNode = idToNodeMap[datum.parent.id]; //We don't need this property, so let's delete it. delete datum.parent; //Let's add the current node as a child of the parent node. parentNode.children.push(datum); } } return root; } function convertParentToChildList(data) { var treeMap = {}; var list = []; convertListToTree(data, treeMap); angular.forEach(treeMap, function (item) { list.push(item); }); return list; } // 将事件分类搜索结果返回的数据整理成children模式 function transform(nodes) { var treeConverter = { result: null, //转化后的结果,是根节点,所有节点都是从根节点长出来的 attributeName: 'id', //节点唯一标识符 needFind: true, //是否查询节点在result中已经存在,为了优化效率 transform: function (node) { //转化递归函数,参数:一个待插入节点 if (node.parent != null) { //该节点有父节点 var newNode = this.transform(node.parent); //递归进入,返回值为一个节点,用作父节点,该父节点必然存在于result中,这点由下面的算法可以控制 if (this.needFind) { for (var i = 0; i < newNode.children.length; i++) { //查找要插入的node子节点是否在newNode这个父节点中存在 if (newNode.children[i][this.attributeName] === node[this.attributeName]) { return newNode.children[i]; //存在的话直接返回newNode父节点内的该子节点,该子节点必然存在于result中,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中 } } } this.needFind = false; //不存在的话,关闭之后递归的循环判断,因为待插入node节点不存在于result中,故而它的子节点一定不存在于result中,不用再循环判断 // delete node.parent; //删除该节点的parent属性,如果有的话 node.children = []; //因为确定是要新插入的节点,没有children:[]属性,故给该节点增加children:[]属性 newNode.children.push(node); //将该node节点push进newNode的子节点数组中 return node; //return该新插入节点,作为递归返回值给上层,用作newNode父节点,node存在于result中故newNode存在于result中 } else if (node.parent == null) { //该叶节点没有父节点,即为根节点 // delete node.parent; //删除该节点的parent属性,如果有的话 if (this.result == null) { //根节点不存在 node.children = []; //给该节点增加children:[]属性 return this.result = node; //该节点赋给result,并return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中 } else { node.children = []; // 顶级去重 for (var i = 0; i < this.result.children.length; i++) { if (this.result.children[i][this.attributeName] === node[this.attributeName]) { return this.result.children[i]; } } this.result.children.push(node) return node // 直接return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中 } } }, getWhole: function (nodes, attributeName) { //传入整个叶子节点数组,attributeName作为节点唯一标识符属性,返回整个转化结果 var _node = {}; _node.children = []; this.result = _node; //重置根节点 this.attributeName = attributeName == null ? 'id' : attributeName; //唯一标识符默认为“id” nodes = JSON.parse(JSON.stringify(nodes)); //复制出一个新的节点对象作为参数,保证不改变原有数据 nodes.forEach(item => { //循环调用转化方法 this.needFind = true; //重置开启节点是否已存在判断,保证不插入重复节点 this.transform(item); }) return this.result; //返回根节点 } } var result = treeConverter.getWhole(nodes); //调用 return result; } a.select_treedata = []; t.bala1 = a.try_async_load = function (s, fn, showValue) { if (s) { var filterKeyword = s.filterKeyword; } var postData = { "idx": 0, "sum": 1000 } if (filterKeyword) { postData.incidentcategory = { selectType: "pinyin_qs", category: filterKeyword } } a.my_data = []; a.doing_async = true; api_bpm_data.fetchDataList('incidentcategory', postData).then(function (response) { if (response.status == 200) { var data = response.list; if (filterKeyword) { data.forEach(e => { e.isExpanded = true; }) var li = transform(data).children; console.log(li) fn(li) return; } else { var objects = []; for (var i = 0; i < data.length; i++) { var object = {}; object.id = data[i].id; object.parent = data[i].parent; object.category = data[i].category; object.isExpanded = true; objects.push(object); } a.my_data = convertParentToChildList(objects); a.select_treedata = angular.copy(a.my_data); if(showValue){ console.log(a.select_treedata); var itemValue = a.select_treedata.find(v => v.id == showValue.valueconfig); if(itemValue){ itemValue.selected = true; }else{ selectChildrenItem(a.select_treedata, showValue); } } } if (a.my_data.length > 0) { a.doing_async = false; } } else { SweetAlert.swal({ title: "系统错误!", text: "请刷新重试!", type: "error" }); } }); }; function selectChildrenItem(arr, showValue){ var arrs = []; arr.forEach(v => { if(Array.isArray(v.children) && v.children.length){ arrs = arrs.concat(v.children); } }) var itemValue = arrs.find(v => v.id == showValue.valueconfig); if(itemValue){ itemValue.selected = true; }else{ selectChildrenItem(arrs, showValue); } } //保存 a.savesystem = function () { var arr = {}; arr.systemConfiguration = []; angular.forEach(a.baseConfig, function (v) { if (v.keyconfig == 'pwd' || v.keyconfig == 'conversationSeconds') { arr.systemConfiguration.push(v);//用户默认密码,登录有效时长 } }) arr.systemConfiguration.push(a.repairMain);//报修主体 arr.systemConfiguration.push(a.ifCreate);//自动建单 arr.systemConfiguration.push(a.reqHasCategory);//是否选择事件分类 arr.systemConfiguration.push(a.incidentWithConsumable);//是否需要绑定耗材 arr.systemConfiguration.push(a.wxIncidentWithCmdb);//是否需要绑定资产 arr.systemConfiguration.push(a.requesterLgoinType);//保修人登录方式 arr.systemConfiguration.push(a.autoCloseIncidentHour);//自动关单小时 arr.systemConfiguration.push(a.updatePwdMonth);//密码强制修改时间 if(a.cifilter_classic){ a.alarmCategory.valueconfig = a.cifilter_classic.id + ''; arr.systemConfiguration.push(a.alarmCategory);//默认的告警转换分类 }else{ a.alarmCategory.valueconfig = ''; arr.systemConfiguration.push(a.alarmCategory);//默认的告警转换分类 } console.log(arr,99999); g.addData("systemConfiguration", arr).then(function (t) { if (t.status == 200) { //获取报修主体 api_is_category.isCategory({ "idx": 0, "sum": 1000 }) .then(function (res) { if (res.status == 200) { //存储报修主体到缓存 var list = res.list; var repairMain = list.find((v) => v.keyconfig == "repairMain"); //报修主体 var incidentWithConsumable = list.find( (v) => v.keyconfig == "incidentWithConsumable" ); //是否绑定耗材 var wxIncidentWithCmdb = list.find( (v) => v.keyconfig == "wxIncidentWithCmdb" ); //是否绑定资产 sessionStorage.setItem( "repair_main", JSON.stringify(repairMain) ); sessionStorage.setItem( "incidentWithConsumable", incidentWithConsumable.valueconfig ); sessionStorage.setItem( "wxIncidentWithCmdb", wxIncidentWithCmdb.valueconfig ); o.swal({ title: "保存成功!", type: "success", confirmButtonColor: "#007AFF" }) } }) .catch(function (err) { console.log(err) }) } else { o.swal({ title: "操作异常!", text: "系统异常,请稍后重试,或者联系管理员!", type: "error" }) } }) }, a.ldloading = {}, a.refreshData = function (t, n) { a.ldloading[t.replace("-", "_")] = !0, angular.isUndefined(n) && (n = f), a.myData = [], g.fetchDataList("systemConfiguration", n).then(function (n) { if (n.status == 200) { var e = c.stripRestangular(n); a.myData = e.list, a.ldloading[t.replace("-", "_")] = !1 console.log(a.myData); a.baseConfig = [];//基本配置 a.cacheConfig = [];//缓存配置 a.repairMain = {};//报修主体 console.log(a.myData,77777) angular.forEach(a.myData, function (v, i) { if (v.keyconfig == 'pwd' || v.keyconfig == 'conversationSeconds' || v.keyconfig == 'formUri' || v.keyconfig == 'localhost' || v.keyconfig == 'verificationPath' || v.keyconfig == 'docpath') { a.baseConfig.push(v);//基本配置 } if (v.keyconfig == 'userRedisIp' || v.keyconfig == 'userRedisPort') { a.cacheConfig.push(v);//缓存配置 } if (v.keyconfig == 'repairMain') { a.repairMain = v;//报修主体 } if (v.keyconfig == 'ifCreate') { a.ifCreate = v;//自动建单 } if (v.keyconfig == 'reqHasCategory') { a.reqHasCategory = v;//是否选择事件分类 } if (v.keyconfig == 'incidentWithConsumable') { a.incidentWithConsumable = v;//是否需要绑定耗材 } if (v.keyconfig == 'wxIncidentWithCmdb') { a.wxIncidentWithCmdb = v;//是否需要绑定资产 } if (v.keyconfig == 'requesterLgoinType') { a.requesterLgoinType = v;//报修人登录方式 } if (v.keyconfig == 'autoCloseIncidentHour') { v.valueconfig = parseFloat(v.valueconfig) a.autoCloseIncidentHour = v;//自动关单小时 } if (v.keyconfig == 'updatePwdMonth') { v.valueconfig = parseFloat(v.valueconfig) a.updatePwdMonth = v;//密码强制修改时间 } if (v.keyconfig == 'alarmCategory') { a.alarmCategory = v; a.try_async_load(null, null, v); } }) }else{ console.log(n.status); } }, function () { a.ldloading[t.replace("-", "_")] = !1 }) }, a.refreshData("expand-right", f) }]);