index.js
11.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
var $, tab;
top.onbeforeunload = function (event) {
const message = "Are you sure you want to leave? Any unsaved changes will be lost.";
event.returnValue = message; // For most browsers
return message; // For some older browsers
}
layui.config({
base: "/js/"
}).use(['bodyTab', 'form', 'element', 'layer', 'jquery', 'I18nPage'], function () {
var form = layui.form,
layer = layui.layer,
element = layui.element,
$ = layui.jquery,
I18nPage = layui.I18nPage;
var Lang = I18nPage.GetLang();
var MessageContainer = {};
//首页页面
if (1 == 1) {
MessageContainer["HomePage_cn"] = "首页";
MessageContainer["Setting_cn"] = "设置";
MessageContainer["FullScreen_cn"] = "全屏";
MessageContainer["ChagePassword_cn"] = "修改密码";
MessageContainer["LogOut_cn"] = "登出";
MessageContainer["ClearData_cn"] = "清理缓存";
MessageContainer["About_cn"] = "关于";
MessageContainer["PageOperate_cn"] = "页面操作";
MessageContainer["CloseOther_cn"] = "关闭其他";
MessageContainer["CloseAll_cn"] = "关闭全部";
MessageContainer["HomePage_us"] = "Home Page";
MessageContainer["Setting_us"] = "Setting";
MessageContainer["FullScreen_us"] = "Full Screen";
MessageContainer["ChagePassword_us"] = "Change Password";
MessageContainer["LogOut_us"] = "Log Out";
MessageContainer["ClearData_us"] = "Clear Data";
MessageContainer["About_us"] = "About";
MessageContainer["PageOperate_us"] = "Page Operate";
MessageContainer["CloseOther_us"] = "Close Others";
MessageContainer["CloseAll_us"] = "Close All";
}
//首页弹窗
if (2 == 2) {
MessageContainer["CopyRight_cn"] = "版权信息";
MessageContainer["CopyRight_us"] = "CopyRight Info";
MessageContainer["FullScreenError_cn"] = "该浏览器不支持全屏";
MessageContainer["FullScreenError_us"] = "Browser Not Support Full Screen";
}
tab = layui.bodyTab({
openTabNum: "10", //最大可打开窗口数量
url: "/base/UserSession/GetModulesTree" //获取菜单json地址
});
//top.onpopstate = function (event) {
// if (event.state) {
// const url = document.location.pathname;
// const title = event.state.page;
// }
//};
$(document).ready(
function () {
Date.prototype.format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
};
$("#Name").html(window.localStorage.getItem("Account"));
window.setInterval(function () {
$("#time").html((new Date()).format("yyyy-MM-dd hh:mm:ss"));
}, 1000);
if (Lang == "cn") {
$("#Lang_SystemName").html($("#SystemNameCn").html());
document.title = $("#SystemNameCn").html();
}
else {
$("#Lang_SystemName").html($("#SystemNameUs").html());
document.title = $("#SystemNameUs").html();
}
$("#Lang_HomePage").html(MessageContainer["HomePage_" + Lang]);
$("#Lang_Setting").html(MessageContainer["Setting_" + Lang]);
$("#Lang_FullScreen").html(MessageContainer["FullScreen_" + Lang]);
$("#Lang_ChagePassword").html(MessageContainer["ChagePassword_" + Lang]);
$("#Lang_LogOut").html(MessageContainer["LogOut_" + Lang]);
$("#Lang_ClearData").html(MessageContainer["ClearData_" + Lang]);
$("#Lang_About").html(MessageContainer["About_" + Lang]);
$("#Lang_PageOperate").html(MessageContainer["PageOperate_" + Lang]);
$("#Lang_CloseOther").html(MessageContainer["CloseOther_" + Lang]);
$("#Lang_CloseAll").html(MessageContainer["CloseAll_" + Lang]);
}
);
//退出
$(".signOut").click(function () {
window.sessionStorage.removeItem("menu");
menu = [];
window.sessionStorage.removeItem("curmenu");
})
//隐藏左侧导航
$(".hideMenu").click(function () {
$(".layui-layout-admin").toggleClass("showMenu");
//渲染顶部窗口
tab.tabMove();
})
//弹出系统版权信息
$(".About").click(function () {
layer.alert($('#footer').html(), {
icon: 1,
anim: 1,
title: MessageContainer["CopyRight_" + Lang],
area: ['350px', '130px'], //宽高
shadeClose: true,
id: 'layerAbout', //防止重复弹出
shade: 0.5,
zIndex: layer.zIndex, //设定弹出层层叠索引
btn: false,
success: function (layero, index) {
layer.setTop(layero); //指定该层
},
});
})
//清理缓存
$(".ClearData").click(function () {
for (var key in window.sessionStorage) {
if (key.indexOf("Menus_") == 0) {
window.sessionStorage.removeItem(key)
}
}
for (var key in window.localStorage) {
if (key.indexOf("I18nText_") == 0 || key.indexOf("I18nMessage_") == 0 || key.indexOf("I18nTable_") == 0) {
window.localStorage.removeItem(key)
}
}
layer.msg("OK");
})
//渲染左侧菜单
tab.render();
//手机设备的简单适配
var treeMobile = $('.site-tree-mobile'),
shadeMobile = $('.site-mobile-shade')
treeMobile.on('click', function () {
$('body').addClass('site-mobile');
});
shadeMobile.on('click', function () {
$('body').removeClass('site-mobile');
});
// 添加新窗口
$("body").on("click", ".layui-nav.layui-nav-tree .layui-nav-item a", function () {
//如果不存在子级
if ($(this).siblings().length == 0) {
addTab($(this));
$('body').removeClass('site-mobile'); //移动端点击菜单关闭菜单层
}
$(this).parent("li").siblings().removeClass("layui-nav-itemed");
})
//关闭其他
$(".closePageOther").on("click", function () {
if ($("#top_tabs li").length > 2 && $("#top_tabs li.layui-this cite").text() != (MessageContainer["HomePage_"] + Lang)) {
var menu = JSON.parse(window.sessionStorage.getItem("menu"));
$("#top_tabs li").each(function () {
if ($(this).attr("lay-id") != '' && !$(this).hasClass("layui-this")) {
element.tabDelete("bodyTab", $(this).attr("lay-id")).init();
//此处将当前窗口重新获取放入session,避免一个个删除来回循环造成的不必要工作量
for (var i = 0; i < menu.length; i++) {
if ($("#top_tabs li.layui-this cite").text() == menu[i].title) {
menu.splice(0, menu.length, menu[i]);
window.sessionStorage.setItem("menu", JSON.stringify(menu));
}
}
}
})
} else if ($("#top_tabs li.layui-this cite").text() == (MessageContainer["HomePage_"] + Lang) && $("#top_tabs li").length > 1) {
$("#top_tabs li").each(function () {
if ($(this).attr("lay-id") != '' && !$(this).hasClass("layui-this")) {
element.tabDelete("bodyTab", $(this).attr("lay-id")).init();
window.sessionStorage.removeItem("menu");
menu = [];
window.sessionStorage.removeItem("curmenu");
}
})
}
//渲染顶部窗口
tab.tabMove();
})
//关闭全部
$(".closePageAll").on("click", function () {
if ($("#top_tabs li").length > 1) {
$("#top_tabs li").each(function () {
if ($(this).attr("lay-id") != '') {
element.tabDelete("bodyTab", $(this).attr("lay-id")).init();
window.sessionStorage.removeItem("menu");
menu = [];
window.sessionStorage.removeItem("curmenu");
}
})
}
//渲染顶部窗口
tab.tabMove();
})
//修改密码
$(".changepwd").on("click", function () {
layer.open({
title: MessageContainer["ChagePassword_" + Lang],
shift: 2,
type: 2,
content: '/base/SysUser/ChangePassword',
area: ['450px', '280px'], //宽高
shade: 0.9
});
});
//禁用页面F5刷新
$(document).bind("keydown", function (e) {
if (e.which == 116) {
e.preventDefault(); //Skip default behavior of the enter key
}
});
})
//打开新窗口
function addTab(_this) {
tab.tabAdd(_this);
}
var qp = {
//全屏 类
fullScreen: function () {
var isFullScreen = false;
var requestFullScreen = function () { //全屏
var de = document.documentElement;
if (de.requestFullscreen) {
de.requestFullscreen();
} else if (de.mozRequestFullScreen) {
de.mozRequestFullScreen();
} else if (de.webkitRequestFullScreen) {
de.webkitRequestFullScreen();
} else {
alert(MessageContainer["FullScreenError_" + Lang]);
}
};
//退出全屏 判断浏览器种类
var exitFull = function () {
// 判断各种浏览器,找到正确的方法
var exitMethod = document.exitFullscreen || //W3C
document.mozCancelFullScreen || //Chrome等
document.webkitExitFullscreen || //FireFox
document.webkitExitFullscreen; //IE11
if (exitMethod) {
exitMethod.call(document);
} else if (typeof window.ActiveXObject !== "undefined") { //for Internet Explorer
var wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
};
return {
handleFullScreen: function (win) {
if (isFullScreen) {
exitFull();
isFullScreen = false;
} else {
requestFullScreen();
isFullScreen = true;
}
},
};
}()
}