|
@@ -1,5 +1,5 @@
|
1
|
1
|
"use strict";
|
2
|
|
-app.controller("sysconfigCtrl", ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "$window", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_sysinfo", "api_is_category", function (t, a, n, e, i, s, r, o, l, u, d, c, g, api_is_category) {
|
|
2
|
+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) {
|
3
|
3
|
a.langs = l.getAllLangs(), a.lang = "zh-cn", l.setCurrentLang(a.lang);
|
4
|
4
|
var f = (t.user, r._, {
|
5
|
5
|
idx: 0,
|
|
@@ -10,6 +10,179 @@ app.controller("sysconfigCtrl", ["$rootScope", "$scope", "$state", "$timeout", "
|
10
|
10
|
var v = parseFloat(e.target.value)?parseFloat(e.target.value):0;
|
11
|
11
|
a.autoCloseIncidentHour.valueconfig = v > 0 ? v : 0;
|
12
|
12
|
}
|
|
13
|
+
|
|
14
|
+ function convertListToTree(data, treeMap) {
|
|
15
|
+ var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
|
|
16
|
+ var root = null; //Initially set our loop to null
|
|
17
|
+ var parentNode = null;
|
|
18
|
+ //loop over data
|
|
19
|
+ for (var i = 0; i < data.length; i++) {
|
|
20
|
+ var datum = data[i];
|
|
21
|
+ //each node will have children, so let's give it a "children" poperty
|
|
22
|
+ datum.children = [];
|
|
23
|
+
|
|
24
|
+ //add an entry for this node to the map so that any future children can
|
|
25
|
+ //lookup the parent
|
|
26
|
+ idToNodeMap[datum.id] = datum;
|
|
27
|
+
|
|
28
|
+ //Does this node have a parent?
|
|
29
|
+ if (typeof datum.parent === "undefined" || datum.parent == null) {
|
|
30
|
+ //Doesn't look like it, so this node is the root of the tree
|
|
31
|
+ root = datum;
|
|
32
|
+ treeMap[datum.id] = root;
|
|
33
|
+ } else {
|
|
34
|
+ //This node has a parent, so let's look it up using the id
|
|
35
|
+ parentNode = idToNodeMap[datum.parent.id];
|
|
36
|
+
|
|
37
|
+ //We don't need this property, so let's delete it.
|
|
38
|
+ delete datum.parent;
|
|
39
|
+
|
|
40
|
+ //Let's add the current node as a child of the parent node.
|
|
41
|
+ parentNode.children.push(datum);
|
|
42
|
+ }
|
|
43
|
+ }
|
|
44
|
+ return root;
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ function convertParentToChildList(data) {
|
|
48
|
+ var treeMap = {};
|
|
49
|
+ var list = [];
|
|
50
|
+ convertListToTree(data, treeMap);
|
|
51
|
+ angular.forEach(treeMap, function (item) {
|
|
52
|
+ list.push(item);
|
|
53
|
+ });
|
|
54
|
+ return list;
|
|
55
|
+ }
|
|
56
|
+ // 将事件分类搜索结果返回的数据整理成children模式
|
|
57
|
+ function transform(nodes) {
|
|
58
|
+ var treeConverter = {
|
|
59
|
+ result: null, //转化后的结果,是根节点,所有节点都是从根节点长出来的
|
|
60
|
+ attributeName: 'id', //节点唯一标识符
|
|
61
|
+ needFind: true, //是否查询节点在result中已经存在,为了优化效率
|
|
62
|
+ transform: function (node) { //转化递归函数,参数:一个待插入节点
|
|
63
|
+
|
|
64
|
+ if (node.parent != null) { //该节点有父节点
|
|
65
|
+ var newNode = this.transform(node.parent); //递归进入,返回值为一个节点,用作父节点,该父节点必然存在于result中,这点由下面的算法可以控制
|
|
66
|
+ if (this.needFind) {
|
|
67
|
+ for (var i = 0; i < newNode.children.length; i++) { //查找要插入的node子节点是否在newNode这个父节点中存在
|
|
68
|
+ if (newNode.children[i][this.attributeName] === node[this.attributeName]) {
|
|
69
|
+ return newNode.children[i]; //存在的话直接返回newNode父节点内的该子节点,该子节点必然存在于result中,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ }
|
|
73
|
+ this.needFind = false; //不存在的话,关闭之后递归的循环判断,因为待插入node节点不存在于result中,故而它的子节点一定不存在于result中,不用再循环判断
|
|
74
|
+ // delete node.parent; //删除该节点的parent属性,如果有的话
|
|
75
|
+ node.children = []; //因为确定是要新插入的节点,没有children:[]属性,故给该节点增加children:[]属性
|
|
76
|
+
|
|
77
|
+ newNode.children.push(node); //将该node节点push进newNode的子节点数组中
|
|
78
|
+ return node; //return该新插入节点,作为递归返回值给上层,用作newNode父节点,node存在于result中故newNode存在于result中
|
|
79
|
+ } else if (node.parent == null) { //该叶节点没有父节点,即为根节点
|
|
80
|
+ // delete node.parent; //删除该节点的parent属性,如果有的话
|
|
81
|
+ if (this.result == null) { //根节点不存在
|
|
82
|
+ node.children = []; //给该节点增加children:[]属性
|
|
83
|
+ return this.result = node; //该节点赋给result,并return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
|
|
84
|
+ } else {
|
|
85
|
+ node.children = [];
|
|
86
|
+ // 顶级去重
|
|
87
|
+ for (var i = 0; i < this.result.children.length; i++) {
|
|
88
|
+ if (this.result.children[i][this.attributeName] === node[this.attributeName]) {
|
|
89
|
+ return this.result.children[i];
|
|
90
|
+ }
|
|
91
|
+ }
|
|
92
|
+ this.result.children.push(node)
|
|
93
|
+ return node // 直接return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
|
|
94
|
+ }
|
|
95
|
+ }
|
|
96
|
+ },
|
|
97
|
+ getWhole: function (nodes, attributeName) { //传入整个叶子节点数组,attributeName作为节点唯一标识符属性,返回整个转化结果
|
|
98
|
+ var _node = {};
|
|
99
|
+ _node.children = [];
|
|
100
|
+ this.result = _node; //重置根节点
|
|
101
|
+ this.attributeName = attributeName == null ? 'id' : attributeName; //唯一标识符默认为“id”
|
|
102
|
+ nodes = JSON.parse(JSON.stringify(nodes)); //复制出一个新的节点对象作为参数,保证不改变原有数据
|
|
103
|
+ nodes.forEach(item => { //循环调用转化方法
|
|
104
|
+ this.needFind = true; //重置开启节点是否已存在判断,保证不插入重复节点
|
|
105
|
+ this.transform(item);
|
|
106
|
+ })
|
|
107
|
+ return this.result; //返回根节点
|
|
108
|
+ }
|
|
109
|
+ }
|
|
110
|
+ var result = treeConverter.getWhole(nodes); //调用
|
|
111
|
+ return result;
|
|
112
|
+ }
|
|
113
|
+ a.select_treedata = [];
|
|
114
|
+ t.bala1 = a.try_async_load = function (s, fn, showValue) {
|
|
115
|
+ if (s) {
|
|
116
|
+ var filterKeyword = s.filterKeyword;
|
|
117
|
+ }
|
|
118
|
+ var postData = {
|
|
119
|
+ "idx": 0,
|
|
120
|
+ "sum": 1000
|
|
121
|
+ }
|
|
122
|
+ if (filterKeyword) {
|
|
123
|
+ postData.incidentcategory = { selectType: "pinyin_qs", category: filterKeyword }
|
|
124
|
+ }
|
|
125
|
+ a.my_data = [];
|
|
126
|
+ a.doing_async = true;
|
|
127
|
+ api_bpm_data.fetchDataList('incidentcategory', postData).then(function (response) {
|
|
128
|
+ if (response.status == 200) {
|
|
129
|
+ var data = response.list;
|
|
130
|
+ if (filterKeyword) {
|
|
131
|
+ data.forEach(e => {
|
|
132
|
+ e.isExpanded = true;
|
|
133
|
+ })
|
|
134
|
+ var li = transform(data).children;
|
|
135
|
+ console.log(li)
|
|
136
|
+ fn(li)
|
|
137
|
+ return;
|
|
138
|
+ } else {
|
|
139
|
+ var objects = [];
|
|
140
|
+ for (var i = 0; i < data.length; i++) {
|
|
141
|
+ var object = {};
|
|
142
|
+ object.id = data[i].id;
|
|
143
|
+ object.parent = data[i].parent;
|
|
144
|
+ object.category = data[i].category;
|
|
145
|
+ object.isExpanded = true;
|
|
146
|
+ objects.push(object);
|
|
147
|
+ }
|
|
148
|
+ a.my_data = convertParentToChildList(objects);
|
|
149
|
+ a.select_treedata = angular.copy(a.my_data);
|
|
150
|
+ if(showValue){
|
|
151
|
+ console.log(a.select_treedata);
|
|
152
|
+ var itemValue = a.select_treedata.find(v => v.id == showValue.valueconfig);
|
|
153
|
+ if(itemValue){
|
|
154
|
+ itemValue.selected = true;
|
|
155
|
+ }else{
|
|
156
|
+ selectChildrenItem(a.select_treedata, showValue);
|
|
157
|
+ }
|
|
158
|
+ }
|
|
159
|
+ }
|
|
160
|
+ if (a.my_data.length > 0) {
|
|
161
|
+ a.doing_async = false;
|
|
162
|
+ }
|
|
163
|
+ } else {
|
|
164
|
+ SweetAlert.swal({
|
|
165
|
+ title: "系统错误!",
|
|
166
|
+ text: "请刷新重试!",
|
|
167
|
+ type: "error"
|
|
168
|
+ });
|
|
169
|
+ }
|
|
170
|
+ });
|
|
171
|
+ };
|
|
172
|
+ function selectChildrenItem(arr, showValue){
|
|
173
|
+ var arrs = [];
|
|
174
|
+ arr.forEach(v => {
|
|
175
|
+ if(Array.isArray(v.children) && v.children.length){
|
|
176
|
+ arrs = arrs.concat(v.children);
|
|
177
|
+ }
|
|
178
|
+ })
|
|
179
|
+ var itemValue = arrs.find(v => v.id == showValue.valueconfig);
|
|
180
|
+ if(itemValue){
|
|
181
|
+ itemValue.selected = true;
|
|
182
|
+ }else{
|
|
183
|
+ selectChildrenItem(arrs, showValue);
|
|
184
|
+ }
|
|
185
|
+ }
|
13
|
186
|
//保存
|
14
|
187
|
a.savesystem = function () {
|
15
|
188
|
var arr = {};
|
|
@@ -26,6 +199,13 @@ app.controller("sysconfigCtrl", ["$rootScope", "$scope", "$state", "$timeout", "
|
26
|
199
|
arr.systemConfiguration.push(a.wxIncidentWithCmdb);//是否需要绑定资产
|
27
|
200
|
arr.systemConfiguration.push(a.requesterLgoinType);//保修人登录方式
|
28
|
201
|
arr.systemConfiguration.push(a.autoCloseIncidentHour);//自动关单小时
|
|
202
|
+ if(a.cifilter_classic){
|
|
203
|
+ a.alarmCategory.valueconfig = a.cifilter_classic.id + '';
|
|
204
|
+ arr.systemConfiguration.push(a.alarmCategory);//默认的告警转换分类
|
|
205
|
+ }else{
|
|
206
|
+ a.alarmCategory.valueconfig = '';
|
|
207
|
+ arr.systemConfiguration.push(a.alarmCategory);//默认的告警转换分类
|
|
208
|
+ }
|
29
|
209
|
console.log(arr,99999);
|
30
|
210
|
g.addData("systemConfiguration", arr).then(function (t) {
|
31
|
211
|
if (t.status == 200) {
|
|
@@ -111,6 +291,10 @@ app.controller("sysconfigCtrl", ["$rootScope", "$scope", "$state", "$timeout", "
|
111
|
291
|
v.valueconfig = parseFloat(v.valueconfig)
|
112
|
292
|
a.autoCloseIncidentHour = v;//自动关单小时
|
113
|
293
|
}
|
|
294
|
+ if (v.keyconfig == 'alarmCategory') {
|
|
295
|
+ a.alarmCategory = v;
|
|
296
|
+ a.try_async_load(null, null, v);
|
|
297
|
+ }
|
114
|
298
|
})
|
115
|
299
|
}else{
|
116
|
300
|
console.log(n.status);
|