赖素文
authored
|
1
|
|
赖素文
authored
|
2
|
let action = null;
|
赖素文
authored
|
3
|
let mapObj = null;
|
赖素文
authored
|
4
|
var app = null;
|
赖素文
authored
|
5
|
|
赖素文
authored
|
6
7
8
9
10
11
12
13
14
|
layui.config({
base: "/js/",
version: 1
}).use(['system'], function () {
var form = layui.form,
$ = layui.jquery,
element = layui.element,
table = layui.table,
system = layui.system,
|
|
15
16
17
18
19
20
|
laypage = layui.laypage,
sentData = {
page: 1,
limit: 20,
isPage: true
},
|
赖素文
authored
|
21
22
23
24
|
sysU = new system.u(),
sendDataWhere = null,
areaName = "configure",
controllerName = "BaseProject",
|
王硕
authored
|
25
26
|
sysNowClickEle = -1;
vueApp = null;
|
赖素文
authored
|
27
28
29
30
31
32
33
|
action = {
}
app = {
data: {
|
赖素文
authored
|
34
|
mapEle: "container",
|
|
35
36
37
38
39
|
refreshDataTimeEle: document.getElementById('refreshDataTime'),
clicktaberightEle: document.getElementById('xiangmu'),
timeoutTime: null,
projectData: null
|
赖素文
authored
|
40
41
|
},
methods: {
|
赖素文
authored
|
42
43
44
|
/**
* 初始化地图
*/
|
赖素文
authored
|
45
|
initMap() {
|
|
46
47
48
49
|
try {
mapObj = mapApp(app.data.mapEle).initMap();
} catch (e) {
mapObj = null;
|
赖素文
authored
|
50
51
52
|
layer.alert(`百度地图加载失败!请确认本地电脑能否浏览外网(https://map.baidu.com),或者有VPN操作设置
【Edge浏览器=>此网站的跟踪防护(严格)选项要关闭】
错误原因: ${e.message}`, { icon: sysU.config.iconoError, shade: 0.4, time: sysU.config.errorTime });
|
|
53
|
}
|
赖素文
authored
|
54
|
},
|
王硕
authored
|
55
|
|
赖素文
authored
|
56
57
58
|
/**
* 获取项目数据
*/
|
赖素文
authored
|
59
|
getProjectDataList() {
|
赖素文
authored
|
60
|
var ajaxConfig = {
|
赖素文
authored
|
61
62
|
data: null,
url: `/configure/BaseProject/GetProjectMapList`,
|
赖素文
authored
|
63
|
loading: false,
|
赖素文
authored
|
64
|
success: function (result) {
|
赖素文
authored
|
65
|
if (sysU.successBefore(result)) return false;
|
|
66
|
if (mapObj == null) return;
|
赖素文
authored
|
67
|
result.Result.list = result.Result.list.uniqueFunc("projectCode")
|
赖素文
authored
|
68
69
|
app.methods.createMarkerInfo(result);
app.methods.initVueDataValue(result);
|
|
70
|
|
赖素文
authored
|
71
|
app.methods.createSidebarList(result);
|
|
72
73
|
app.methods.initPagination(result.sumEqCount);
|
王硕
authored
|
74
75
76
|
if (sysNowClickEle != -1) {
$("#a_" + sysNowClickEle).click().css("color", "#42b983");
}
|
赖素文
authored
|
77
78
79
80
|
}
};
sysU.ajax(ajaxConfig);
},
|
赖素文
authored
|
81
82
83
|
/**
* 创建marker标注
*/
|
赖素文
authored
|
84
|
createMarkerInfo(json) {
|
王硕
authored
|
85
|
let index = 1
|
赖素文
authored
|
86
87
|
json.Result.list.forEach(item => {
var content = `<h4 style = 'margin:0;'>地址:${item.projectAddress}</h4>
|
HuXiYu
authored
|
88
|
设备总数:${item.eqCount}、
|
赖素文
authored
|
89
|
运行:<span style='color:blue;'>${item.eqRunCount}</span>、
|
赖素文
authored
|
90
91
|
待机:${item.eqFreeCount}
故障:${item.eqFailureCount}<br/>
|
赖素文
authored
|
92
|
离线(5m):<span style='color:red;'>${item.eqOfflineCount}</span>
|
HuXiYu
authored
|
93
94
|
<span style='color:red;font-weight:bold'>${item.isHaveAlarm ? "有未处理报警" : ""}</span>
<span style='color:red;font-weight:bold'>${item.isHaveMaintain ? "有待保养设备" : ""}</span>
|
赖素文
authored
|
95
|
<div style = 'display: flex;' >
|
赖素文
authored
|
96
|
<div><a style='text-decoration: underline;color: blue;' onclick='app.methods.projectOverviewClick(${JSON.stringify(item)})' href='#'>项目概述</a></div>
|
赖素文
authored
|
97
|
<div><a style='text-decoration: underline;color: blue;margin-left:12px' onclick='app.methods.projectAreasMapClick(${JSON.stringify(item)})' href='#'>设备区域图</a></div>
|
赖素文
authored
|
98
|
</div >` ;//定义大标题 写html语句标签
|
赖素文
authored
|
99
|
mapObj.createMarkerInfo(content, {
|
王硕
authored
|
100
|
title: `项目名称[${index++}]:` + item.projectName,
|
赖素文
authored
|
101
|
longitude: item.longitude,
|
赖素文
authored
|
102
103
|
latitude: item.latitude,
id: item.id
|
赖素文
authored
|
104
105
|
});
})
|
赖素文
authored
|
106
107
|
//设置默认选择的地图定位的项目
|
赖素文
authored
|
108
109
110
111
112
113
|
setTimeout(() => {
var defaultSelectProjectId = localStorage.getItem("defaultSelectProjectId");
if (defaultSelectProjectId) {
$("#a_" + defaultSelectProjectId).click().css("color", "#42b983");
}
}, 200)
|
赖素文
authored
|
114
|
},
|
赖素文
authored
|
115
116
117
|
//项目概述点击
projectOverviewClick(item) {
var title = "项目概述";
|
赖素文
authored
|
118
119
|
localStorage.setItem("projectMapKeys", item.keys);
localStorage.setItem("projectMapName", item.projectName);
|
|
120
|
localStorage.setItem("projectCode", item.projectCode);
|
赖素文
authored
|
121
122
|
var tabsEle = window.parent.document.querySelectorAll("#top_tabs cite");
for (var i = 0; i < tabsEle.length; i++) {
|
赖素文
authored
|
123
|
if (tabsEle[i].innerText == title) {
|
赖素文
authored
|
124
125
126
127
|
$(tabsEle[i]).next().click()
break;
}
}
|
赖素文
authored
|
128
|
var url = `/configure/BaseProject/ProjectOverview?id=${item.id}&keys=${item.keys}&projectName=${item.projectName}&projectCode=${item.projectCode}`;
|
赖素文
authored
|
129
|
var urlHtml = $(`<a title="${title}" data-url="${url}"><i class="layui-icon" data-icon=""></i><cite>${title}</cite></a>`)
|
赖素文
authored
|
130
|
window.top.tab.tabAdd(urlHtml);
|
赖素文
authored
|
131
|
},
|
|
132
|
//项目区域图点击
|
赖素文
authored
|
133
134
|
projectAreasMapClick(item) {
var title = "项目设备区域图";
|
王硕
authored
|
135
136
|
localStorage.setItem("projectMapKeys", item.keys);
localStorage.setItem("projectMapName", item.projectName);
|
|
137
|
localStorage.setItem("projectCode", item.projectCode);
|
王硕
authored
|
138
139
|
var tabsEle = window.parent.document.querySelectorAll("#top_tabs cite");
for (var i = 0; i < tabsEle.length; i++) {
|
赖素文
authored
|
140
|
if (tabsEle[i].innerText == title) {
|
王硕
authored
|
141
142
143
144
|
$(tabsEle[i]).next().click();
break;
}
}
|
赖素文
authored
|
145
146
|
debugger
var url = `/configure/BaseProject/ProjectEqAreaView?id=${item.id}&keys=${item.keys}&projectName=${item.projectName}&projectCode=${item.projectCode}`;
|
赖素文
authored
|
147
|
var urlHtml = $(`<a title="${title}" data-url="${url}"><i class="layui-icon" data-icon=""></i><cite>${title}</cite></a>`);
|
王硕
authored
|
148
149
|
window.top.tab.tabAdd(urlHtml);
},
|
赖素文
authored
|
150
151
152
153
154
|
/**
* 创建右侧项目列表
*/
createSidebarList(json) {
var sidebarList = [];
|
赖素文
authored
|
155
|
var index = 1;
|
|
156
157
|
this.projectData = json.Result.list
|
赖素文
authored
|
158
|
json.Result.list.forEach(item => {
|
|
159
|
var content = `<dd><a id='a_${item.id}' title='${item.projectName}' class='projectListA' onclick='app.methods.findLocateMarker(${item.id.toString()},event)' href="javascript:;">【${index++}】${item.projectName} </a></dd>`;//定义大标题 写html语句标签
|
赖素文
authored
|
160
161
162
163
164
165
|
sidebarList.push(content)
})
if (sidebarList.length > 0) {
$(".sidebar-list-item").empty().append(sidebarList.join(" "))
}
},
|
|
166
|
//分页初始化
|
赖素文
authored
|
167
|
initPagination(sumEqCount) {
|
|
168
169
170
171
172
173
174
175
176
177
178
|
laypage.render({
elem: 'pagination',
count: 100,
limit: 10,
jump: function (obj, first) {
if (!first) {
fetchData(obj.curr);
}
}
});
},
|
赖素文
authored
|
179
180
181
|
/**
* 查找Marker并打开对应的infoWindow信息框
*/
|
赖素文
authored
|
182
|
findLocateMarker(markerId, event) {
|
赖素文
authored
|
183
|
mapObj.getLocateMarker(markerId);
|
王硕
authored
|
184
|
sysNowClickEle = markerId;
|
赖素文
authored
|
185
186
|
$(".projectListA").css("color", "rgba(255, 255, 255, .7)")
$(event.currentTarget).css("color", "#42b983")
|
赖素文
authored
|
187
|
localStorage.setItem("defaultSelectProjectId", markerId);
|
|
188
|
|
赖素文
authored
|
189
|
},
|
|
190
|
/**
|
赖素文
authored
|
191
192
193
194
195
196
197
198
199
|
* 初始化vue
*/
initVue: function () {
vueApp = new Vue({
el: '.vueApp',
data: {
footer: {
projectCount: 0,
eqCount: 0,
|
HuXiYu
authored
|
200
|
eqOnlineRate: ""
|
赖素文
authored
|
201
202
203
204
205
206
207
208
209
210
|
}
},
methods: {
}
});
},
/**
* vue 集合赋值
*/
|
赖素文
authored
|
211
|
initVueDataValue: (result) => {
|
HuXiYu
authored
|
212
|
var res = result.Result;
|
HuXiYu
authored
|
213
214
215
|
vueApp.footer.projectCount = res.list.length;//项目总数
vueApp.footer.eqCount = res.sumEqCount;//设备总数
vueApp.footer.eqOnlineRate = res.onlineRate;//在线率
|
王硕
authored
|
216
|
},
|
王硕
authored
|
217
|
|
王硕
authored
|
218
|
refreshDataMethod: function () {
|
王硕
authored
|
219
220
221
222
|
const tabsEle = Array.from(window.parent.document.querySelectorAll("#top_tabs .layui-this"));
const isOK = tabsEle.some(tab => tab.innerText === "项目地图");
if (!isOK) return;
|
王硕
authored
|
223
224
225
226
227
228
229
230
|
let currenttime = parseInt(app.data.refreshDataTimeEle.innerHTML);
if (currenttime === 0) {
currenttime = 20;
app.methods.getProjectDataList();
} else {
currenttime--;
}
app.data.refreshDataTimeEle.innerHTML = currenttime;
|
|
231
232
233
234
|
},
// 控制项目列表输入框
clicktaberightEleMethod: function () {
|
赖素文
authored
|
235
|
$(app.data.clicktaberightEle).toggle();
|
|
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
},
// 项目列表-支持模糊查询
debouncedCheckInputValue: function () {
clearTimeout(this.timeoutTime);
this.timeoutTime = setTimeout(() => {
const inputField = app.data.clicktaberightEle;
const inputValue = inputField.value.trim();
const allProjects = this.projectData;
if (inputValue) {
app.stopDataRefresh();
} else {
app.startDataRefresh()
}
// 每次清空前面旧数据
$(".sidebar-list-item").empty();
if (inputValue) {
const firstChar = inputValue.charAt(0);
const filteredProjects = allProjects.filter(project =>
project.projectName.startsWith(firstChar)
);
if (filteredProjects.length > 0) {
app.methods.assignmentRightList(filteredProjects)
} else {
$(".sidebar-list-item").append(`
<div style="text-align: center; font-size: 12px; color: #999;">
<dd>没有符合条件的项目</dd>
</div>
`);
}
} else {
inputField.value =''
app.methods.assignmentRightListAll(allProjects)
}
}, 900);
},
// 项目列表筛选后的数据赋值
assignmentRightList: function (filteredProjects) {
const sidebarList = filteredProjects.map((project, index) => {
return `<dd><a id='a_${project.id}' title='${project.projectName}' class='projectListA' onclick='app.methods.findLocateMarker(${project.id.toString()},event)' href="javascript:;">【${index + 1}】${project.projectName}</a></dd>`;
});
$(".sidebar-list-item").append(sidebarList.join(" "));
},
// 项目列表所有数据赋值
assignmentRightListAll: function (allProjects) {
const sidebarList = allProjects.map((project, index) => {
return `<dd><a id='a_${project.id}' title='${project.projectName}' class='projectListA' onclick='app.methods.findLocateMarker(${project.id.toString()},event)' href="javascript:;">【${index + 1}】${project.projectName}</a></dd>`;
});
$(".sidebar-list-item").append(sidebarList.join(" "));
|
赖素文
authored
|
288
|
}
|
|
289
|
|
赖素文
authored
|
290
|
},
|
|
291
|
|
赖素文
authored
|
292
|
registerEvent: function () {
|
王硕
authored
|
293
|
|
赖素文
authored
|
294
|
},
|
|
295
296
297
298
299
300
|
startDataRefresh: function () {
this.dataRefreshInterval = setInterval(app.methods.refreshDataMethod, 1000);
},
stopDataRefresh: function () {
clearInterval(this.dataRefreshInterval);
},
|
王硕
authored
|
301
|
|
赖素文
authored
|
302
303
|
init: function () {
app.methods.initMap();
|
赖素文
authored
|
304
305
|
app.methods.initVue();
app.methods.getProjectDataList();
|
|
306
|
app.startDataRefresh();
|
赖素文
authored
|
307
|
app.registerEvent();
|
赖素文
authored
|
308
|
}
|
赖素文
authored
|
309
310
311
|
};
app.init();
});
|