index.js
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
var messages = {
text_info: "",
text_error: "",
init_plugin_error: ""
};
// 首先加载语言
loadLanguage(onLangReady, messages);
// 当语言文件加载成功,执行页面的其他逻辑
function onLangReady() {
$().ready(function() {
// 动态加载easyui
loadEasyuiModules(["panel", "messager", "layout"], function() {
appModel.loadMenuData();
});
// 页面的其他一些配置
document.onkeydown = function() {
if (event.keyCode == 8) {
event.keyCode = 27;
}
};
window.onbeforeunload = function() {
// alert("你点击了关闭浏览器,服务器资源即将销毁");
var Url = "/do/trafficController/destructionResources";
$.get(
Url,
null,
function(data) {
if (!data.error) {
$.messager.alert(
messages.messager_alert_title,
"资源销毁失败!原因:" + data.feedback.Msg,
"error"
);
}
},
"json"
);
};
});
}
function getMenuIcon(icon) {
return "background-image:url(images/index/menu/" + icon + ".png)";
}
//登出功能
function loginout() {
var loginoutUrl =
"/do/trafficController/userLogout?t=" + new Date().getTime();
$.get(
loginoutUrl,
null,
function(data) {
if (data.error) {
// 获取语言
var lang = $.i18n.normaliseLanguageCode();
var loginUrl = "login.html";
if (lang) {
loginUrl += "?lang=" + lang;
}
window.location.href = loginUrl;
} else {
$.messager.alert(
messages.messager_alert_title,
data.feedback.Msg,
"error"
);
}
},
"json"
);
}
function MainPageModel() {
var self = this;
var mainFrameObj; //主IFrame框架
var isLeftMenuShowed = true;
var panelWestWidth = null; //左侧框架的宽度
self.menuData = ko.observable(null); //菜单
self.appSettings = new Array(); //程序设置
self.selectedMenuLevel1 = ko.observable(null); //选择的第一级目录
//选择的一级菜单下的二级菜单列表
self.selectedMenuItems = ko.computed(function() {
if (self.selectedMenuLevel1() != null)
return self.selectedMenuLevel1().children;
else {
return [];
}
}, self);
/*-----------------------------------菜单相关的逻辑-------------------------*/
//当选择的二级菜单变化时,动态显示或隐藏左侧的菜单
self.selectedMenuItems.subscribe(function(newValue) {
var mainLayout = $("#mainLayout");
var panelWest = null;
var panelCenter = null;
try {
panelWest = mainLayout.layout("panel", "west");
panelCenter = mainLayout.layout("panel", "center");
} catch (e) {}
if (!panelWest || !panelCenter) {
return;
}
//保存最初的左侧菜单框架的宽度
if (!panelWestWidth) {
panelWestWidth = panelWest.width();
}
var centerHeight = panelCenter.height();
var centerWidth = panelCenter.width();
if (newValue != null && newValue.length > 0) {
//只在左侧菜单不显示的时候才显示菜单
if (!isLeftMenuShowed) {
panelWest.panel("open");
panelCenter.panel("resize", {
height: centerHeight,
width: centerWidth - panelWestWidth
});
panelCenter.panel("move", {
left: panelWestWidth
});
isLeftMenuShowed = true;
}
} else {
if (isLeftMenuShowed) {
panelWest.panel("close");
panelCenter.panel("resize", {
height: centerHeight,
width: centerWidth + panelWestWidth
});
panelCenter.panel("move", {
left: 0
});
isLeftMenuShowed = false;
}
}
});
//加载菜单数据的
self.loadMenuData = function() {
// 确定现在的语言,加载对应的菜单
var lang = $.i18n.normaliseLanguageCode();
var menuUrl = "i18n/menu_" + lang + ".json";
$.getJSON(menuUrl, function(data) {
if (data) {
self.menuData(data);
//默认选择首页
self.selectedMenuLevel1(data.menus[0]);
//发送数据
self.loadData();
showPage(data.menus[0].url);
//第一次加载,设置首页的图标样式
$(".menu_level1_icon:eq(0)").addClass("selectedMenuLevel1");
}
});
};
self.loadData = function() {
$.get(
"/do/trafficController/setTrafficCamera?command=resultdata_send&value=1"
);
};
self.stopLoadData = function() {
$.get(
"/do/trafficController/setTrafficCamera?command=resultdata_send&value=0"
);
};
//选择一级菜单,显示左侧菜单
self.selectMenuLv1 = function(menu, event) {
//选中单击的一级菜单
self.selectedMenuLevel1(menu);
if (menu.id == "index") {
self.loadData();
} else {
self.stopLoadData();
}
if (menu.url) {
showPage(menu.url);
} else {
//当有二级菜单时,选中二级菜单下的第一项
setTimeout(function() {
var firstLevel2MenuItem = $(".menuLv2Item:eq(0)");
if (firstLevel2MenuItem.length > 0) {
firstLevel2MenuItem.trigger("click");
}
}, 200);
}
//一菜菜单图标
$(".menu_level1_icon").removeClass("selectedMenuLevel1");
$(event.currentTarget)
.find(".menu_level1_icon")
.addClass("selectedMenuLevel1");
};
//选择左侧的二级菜单
self.selectMenuLv2 = function(menu, event) {
if (menu.url) {
showPage(menu.url);
}
//二级菜单选中的效果
$(event.currentTarget)
.toggleClass("selected")
.siblings()
.removeClass("selected");
//默认选中第一个菜单
var firstChildMenu = $(event.currentTarget).find(
"li.menuLv3Item:eq(0)"
);
if (firstChildMenu.length > 0) {
firstChildMenu.trigger("click");
}
};
//选择左侧的三级菜单
self.selectMenuLv3 = function(menu, event) {
if (menu.url && !menu.disabled) {
showPage(menu.url);
//三级菜单选中效果
$(".menuLv3Item").removeClass("selected");
$(event.currentTarget).toggleClass("selected");
}
};
self.isLv1MenuDisabled = function(menuLv1) {
//当用户不是admin时,不显示用户管理菜单
if (menuLv1.id == "userManage" || menuLv1.id === "settings") {
var loginedUser = '<%= getSessionVar("loginedUser") %>';
console.log("当前登录用户: " + loginedUser);
var isAdmin = loginedUser != "admin";
return !isAdmin;
} else {
//当一级菜单没有url,且没有子菜单项时才禁用
return !menuLv1.url && !menuLv1.children;
}
};
self.isLv3MenuDisabled = function(menuLv3) {
//当相机模式是公交时,显示“线路编辑”菜单
if (menuLv3.id == "roadList") {
return !menuLv3.disabled && cameraRunMode != 3;
} else {
return menuLv3.disabled;
}
};
//获取应用设置
self.getSetting = function(key) {
return self.appSettings[key] || null;
};
//设置应用设置项
self.setSetting = function(key, value) {
if (!key) return;
self.appSettings[key] = value;
};
//计算可用的子项(菜单)的数量
self.isLevel2MenuValid = function(url, children) {
var count = 0;
if (url) return true;
if (children && children.length) {
for (var i = 0; i < children.length; i++) {
if (!children[i].disabled) {
count++;
}
}
}
return count > 0;
};
//加载页面
function showPage(url) {
getMainFrameObj();
var currentUrl = mainFrameObj.attr("src");
if (currentUrl != url) {
mainFrameObj.attr("src", url);
}
}
function getMainFrameObj() {
if (!mainFrameObj) {
mainFrameObj = $("#mainPageFrame");
}
return mainFrameObj;
}
}
// 获取相机运行模式?
var cameraRunMode = -1;
// 加载相机运行模式
getCameraBusinessMode(function(mode) {
cameraRunMode = mode;
// 保存相机运行模式
appModel.setSetting("captureMode", cameraRunMode);
});
//初始化主页ViewModel
var appModel = new MainPageModel();
//绑定模型
ko.applyBindings(appModel);
//初始化信息推送的Ocx
function initResultOcx() {
var ip = window.location.hostname;
var result = infoOcxObj.Init(ip, 41066);
if (result != 1) {
$.messager.alert(
messages.text_error,
messages.init_plugin_error,
"error"
);
console.log(messages.init_plugin_error + "(ip:" + ip + ",port:41066)");
console.log("RecResultOcx.ocx Init()");
} else {
console.log("RecResultOcx.ocx Init() return 1");
}
}
//反初始化信息推送的Ocx
function uninitResultOcx() {
console.log("RecResultOcx.ocx Uninit()");
infoOcxObj.Uninit();
}
function getInfoOcx() {
return document.getElementById("infoOcxObj");
}
window.onbeforeunload = function() {
infoOcxObj.Uninit();
};