global.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  1. //加载md5算法
  2. (function($) {
  3. 'use strict';
  4. /*
  5. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  6. * to work around bugs in some JS interpreters.
  7. */
  8. function safe_add(x, y) {
  9. var lsw = (x & 0xFFFF) + (y & 0xFFFF),
  10. msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  11. return (msw << 16) | (lsw & 0xFFFF);
  12. }
  13. /*
  14. * Bitwise rotate a 32-bit number to the left.
  15. */
  16. function bit_rol(num, cnt) {
  17. return (num << cnt) | (num >>> (32 - cnt));
  18. }
  19. /*
  20. * These functions implement the four basic operations the algorithm uses.
  21. */
  22. function md5_cmn(q, a, b, x, s, t) {
  23. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
  24. }
  25. function md5_ff(a, b, c, d, x, s, t) {
  26. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  27. }
  28. function md5_gg(a, b, c, d, x, s, t) {
  29. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  30. }
  31. function md5_hh(a, b, c, d, x, s, t) {
  32. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  33. }
  34. function md5_ii(a, b, c, d, x, s, t) {
  35. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  36. }
  37. /*
  38. * Calculate the MD5 of an array of little-endian words, and a bit length.
  39. */
  40. function binl_md5(x, len) {
  41. /* append padding */
  42. x[len >> 5] |= 0x80 << ((len) % 32);
  43. x[(((len + 64) >>> 9) << 4) + 14] = len;
  44. var i, olda, oldb, oldc, oldd,
  45. a = 1732584193,
  46. b = -271733879,
  47. c = -1732584194,
  48. d = 271733878;
  49. for (i = 0; i < x.length; i += 16) {
  50. olda = a;
  51. oldb = b;
  52. oldc = c;
  53. oldd = d;
  54. a = md5_ff(a, b, c, d, x[i], 7, -680876936);
  55. d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
  56. c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
  57. b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
  58. a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
  59. d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
  60. c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
  61. b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
  62. a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
  63. d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
  64. c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
  65. b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
  66. a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
  67. d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
  68. c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
  69. b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
  70. a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
  71. d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
  72. c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
  73. b = md5_gg(b, c, d, a, x[i], 20, -373897302);
  74. a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
  75. d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
  76. c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
  77. b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
  78. a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
  79. d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
  80. c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
  81. b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
  82. a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
  83. d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
  84. c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
  85. b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
  86. a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
  87. d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
  88. c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
  89. b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
  90. a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
  91. d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
  92. c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
  93. b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
  94. a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
  95. d = md5_hh(d, a, b, c, x[i], 11, -358537222);
  96. c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
  97. b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
  98. a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
  99. d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
  100. c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
  101. b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
  102. a = md5_ii(a, b, c, d, x[i], 6, -198630844);
  103. d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
  104. c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
  105. b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
  106. a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
  107. d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
  108. c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
  109. b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
  110. a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
  111. d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
  112. c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
  113. b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
  114. a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
  115. d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
  116. c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
  117. b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
  118. a = safe_add(a, olda);
  119. b = safe_add(b, oldb);
  120. c = safe_add(c, oldc);
  121. d = safe_add(d, oldd);
  122. }
  123. return [a, b, c, d];
  124. }
  125. /*
  126. * Convert an array of little-endian words to a string
  127. */
  128. function binl2rstr(input) {
  129. var i,
  130. output = '';
  131. for (i = 0; i < input.length * 32; i += 8) {
  132. output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF);
  133. }
  134. return output;
  135. }
  136. /*
  137. * Convert a raw string to an array of little-endian words
  138. * Characters >255 have their high-byte silently ignored.
  139. */
  140. function rstr2binl(input) {
  141. var i,
  142. output = [];
  143. output[(input.length >> 2) - 1] = undefined;
  144. for (i = 0; i < output.length; i += 1) {
  145. output[i] = 0;
  146. }
  147. for (i = 0; i < input.length * 8; i += 8) {
  148. output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32);
  149. }
  150. return output;
  151. }
  152. /*
  153. * Calculate the MD5 of a raw string
  154. */
  155. function rstr_md5(s) {
  156. return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
  157. }
  158. /*
  159. * Calculate the HMAC-MD5, of a key and some data (raw strings)
  160. */
  161. function rstr_hmac_md5(key, data) {
  162. var i,
  163. bkey = rstr2binl(key),
  164. ipad = [],
  165. opad = [],
  166. hash;
  167. ipad[15] = opad[15] = undefined;
  168. if (bkey.length > 16) {
  169. bkey = binl_md5(bkey, key.length * 8);
  170. }
  171. for (i = 0; i < 16; i += 1) {
  172. ipad[i] = bkey[i] ^ 0x36363636;
  173. opad[i] = bkey[i] ^ 0x5C5C5C5C;
  174. }
  175. hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
  176. return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
  177. }
  178. /*
  179. * Convert a raw string to a hex string
  180. */
  181. function rstr2hex(input) {
  182. var hex_tab = '0123456789abcdef',
  183. output = '',
  184. x,
  185. i;
  186. for (i = 0; i < input.length; i += 1) {
  187. x = input.charCodeAt(i);
  188. output += hex_tab.charAt((x >>> 4) & 0x0F) +
  189. hex_tab.charAt(x & 0x0F);
  190. }
  191. return output;
  192. }
  193. /*
  194. * Encode a string as utf-8
  195. */
  196. function str2rstr_utf8(input) {
  197. return unescape(encodeURIComponent(input));
  198. }
  199. /*
  200. * Take string arguments and return either raw or hex encoded strings
  201. */
  202. function raw_md5(s) {
  203. return rstr_md5(str2rstr_utf8(s));
  204. }
  205. function hex_md5(s) {
  206. return rstr2hex(raw_md5(s));
  207. }
  208. function raw_hmac_md5(k, d) {
  209. return rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d));
  210. }
  211. function hex_hmac_md5(k, d) {
  212. return rstr2hex(raw_hmac_md5(k, d));
  213. }
  214. $.md5 = function(string, key, raw) {
  215. if (!key) {
  216. if (!raw) {
  217. return hex_md5(string);
  218. } else {
  219. return raw_md5(string);
  220. }
  221. }
  222. if (!raw) {
  223. return hex_hmac_md5(key, string);
  224. } else {
  225. return raw_hmac_md5(key, string);
  226. }
  227. };
  228. }(typeof jQuery === 'function' ? jQuery : this));
  229. var Global = {
  230. ICON_HINT: 0,
  231. ICON_ERROR: 2,
  232. ICON_ASK: 3,
  233. ICON_LOCK: 4,
  234. ICON_OK: 1,
  235. ICON_LOADING: 16,
  236. hRate: 1,
  237. wRate: 1,
  238. _autoLayoutFunc: null,
  239. //页面初始化事件。主要处理元素自适应布局。
  240. RegAutoLayoutFunc: function(func) {
  241. this._autoLayoutFunc = func;
  242. //注册事件后,立即执行一次
  243. func();
  244. },
  245. uiWidth: 1920, ////UI设计稿高度
  246. uiHeight: 1080, //UI设计稿宽度
  247. //自增序列值。通过GetSeqNext获取新的值
  248. _seqvalue: (new Date().getTime() + '').substring(0, 10),
  249. params: {},
  250. AccessUrl: "",
  251. Absolute_path: "/home/go/project/platform_service/", //绝对路径
  252. //初始化接口地址
  253. InitAccessUrl: function() {
  254. if (window.location.hostname == "www.jujutong.cloud" || window.location.hostname == "police-s.jujutong.cloud" || window.location.hostname == "police-o.jujutong.cloud") {
  255. //正式云平台
  256. this.AccessUrl = "http://www.jujutong.cloud:18010/";
  257. this.params.authorityUrl = "/login.html";
  258. } else if (window.location.hostname == "127.0.0.1" || window.location.hostname == "localhost") {
  259. //开发环境
  260. this.AccessUrl = window.location.protocol + "//" + window.location.host;
  261. this.params.authorityUrl = "/static/login.html";
  262. } else {
  263. //无效的访问
  264. this.AccessUrl = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port + "/";
  265. this.params.authorityUrl = "/static/login.html";
  266. }
  267. },
  268. InitRootFontSize: function() {
  269. var contentHeight = $(window).height();
  270. var contentWidth = $(window).width();
  271. hRate = contentHeight / (this.uiHeight == null ? 1080 : this.uiHeight);
  272. wRate = contentWidth / (this.uiWidth == null ? 1920 : this.uiWidth);
  273. $("html").css("font-size", (12 * wRate) + "px");
  274. },
  275. RandomString: function(e) {
  276. e = e || 32;
  277. var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
  278. a = t.length,
  279. n = "";
  280. for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
  281. return n;
  282. },
  283. InitAjaxSetup: function() {
  284. if (typeof $ === 'undefined')
  285. return;
  286. var randomString = function(e) {
  287. e = e || 32;
  288. var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
  289. a = t.length,
  290. n = "";
  291. for (i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
  292. return n;
  293. };
  294. var token = "",
  295. role = "";
  296. token = $.trim(localStorage.getItem("sessionid"));
  297. var userinfo = JSON.parse(localStorage.getItem("userinfo"));
  298. var permission = ["all"];
  299. if (userinfo != null && userinfo.role != 1) {
  300. permission = [];
  301. var funcs = userinfo["funcs"];
  302. for (var i = 0; i < (funcs == null ? 0 : funcs.length); i++) {
  303. var item = funcs[i];
  304. permission.push(item["code"]);
  305. }
  306. }
  307. Global.params = {
  308. authorityUrl: "/static/login.html",
  309. token: token,
  310. roles: userinfo != null ? userinfo.role : "",
  311. permission: permission.join(","),
  312. rootorg: "",
  313. "userinfo": userinfo,
  314. "enable_module": ''
  315. };
  316. this.accessControl();
  317. $.ajaxSetup({
  318. beforeSend: function(jqXHR, settings) {
  319. if (settings.url.indexOf("/api/") > -1) {
  320. var now = new Date().getTime();
  321. var nonce = now + randomString(6);
  322. var postdata = (settings.multipart != null || settings.multipart == true) ? "" : $.trim(settings.data);
  323. var getparam = settings.url.split("?");
  324. var getdata = getparam.length == 0 ? "" : $.trim(getparam[1]);
  325. var signparam = postdata == "" ? getdata : postdata + (getdata != "" ? ("&" + getdata) : "");
  326. signparam = (($.trim(signparam) != "" ? signparam + "&" : "") + "auth_nonce=" + nonce + "&auth_time=" + now).split("&").sort().join("&");
  327. signparam = signparam.replace(/\+/gi, "%20");
  328. signparam = decodeURIComponent(signparam);
  329. jqXHR.setRequestHeader("auth_time", now);
  330. jqXHR.setRequestHeader("auth_nonce", nonce);
  331. jqXHR.setRequestHeader("sign", $.md5(signparam));
  332. //console.log(signparam);
  333. }
  334. },
  335. complete: function(jqXHR, textStatus) {
  336. //请求完成处理
  337. },
  338. statusCode: {
  339. 401: function() {
  340. //跳转到认证页面
  341. if (Global.params.authorityUrl) {
  342. //localStorage.removeItem("sessionid");
  343. //localStorage.removeItem("userinfo");
  344. window.location.href = Global.params.authorityUrl;
  345. }
  346. },
  347. 403: function() {
  348. //跳转到认证页面
  349. if (Global.params.authorityUrl) {
  350. window.location.href = Global.params.authorityUrl;
  351. }
  352. },
  353. 450: function() {
  354. //跳转到登录页面
  355. if (Global.params.authorityUrl) {
  356. window.location.href = "/static/login.html";
  357. }
  358. }
  359. },
  360. headers: {
  361. Authorization: 'Bearer ' + Global.params['token']
  362. },
  363. timeout: (1000 * 60 * 5)
  364. });
  365. },
  366. //保持登录。token自动刷新。在需要一直运行的界面上初始化时调用该方法
  367. KeepAlive: function() {
  368. setInterval(function() {
  369. $.post("/api/keep-alive");
  370. }, 1000 * 60);
  371. },
  372. get: function(key) {
  373. if (this.params.hasOwnProperty(key)) {
  374. return this.params[key];
  375. }
  376. return null;
  377. },
  378. accessControl: function($targetEle) {
  379. //禁用未启用的模块
  380. var modulelist = $.trim(Global.get("enable_module"));
  381. if (modulelist != '') {
  382. modulelist = JSON.parse(modulelist);
  383. for (var k in modulelist) {
  384. var m = modulelist[k].m,
  385. v = modulelist[k].v;
  386. if (v != null && (v == 0 || v == '0' || v == false)) {
  387. $("li[access-code='" + m + "']").remove();
  388. }
  389. }
  390. }
  391. //根据当前用户的权限进行操作控制
  392. var permissionlist = Global.get("permission");
  393. if (permissionlist == "all") {
  394. $("#m_ver_menu li[access-code='pl_init']").remove();
  395. $("#m_ver_menu li[access-code!='pl_init']").removeClass('hidden');
  396. return; //超级管理员
  397. }
  398. if (permissionlist == "pl_init") {
  399. $("#m_ver_menu li[access-code!='pl_init']").remove();
  400. $("#m_ver_menu li[access-code='pl_init']").removeClass('hidden').find('a').trigger('click');
  401. return;
  402. }
  403. permissionlist = "," + permissionlist + ",";
  404. var needControlEle = $targetEle != null ? $targetEle.find(".accessControl") : $(".accessControl"); //获取需要权限控制的元素
  405. //业务权限控制
  406. //需要进行权限控制的元素均添加class:accessControl,并通过access-code属性设置权限代码,权限代码格式:
  407. //pl_MODEL_XXX:MODEL表示模块编码,如pl_deptstaff;XXX表示业务操作代码,如exp表示导出。
  408. $.each(needControlEle, function(ind, e) {
  409. var item = $(e),
  410. code = $.trim(item.attr('access-code'));
  411. if (code != '') {
  412. code = "," + code + ",";
  413. if (permissionlist.indexOf(code) == -1) {
  414. item.remove();
  415. } else {
  416. item.removeClass('hidden');
  417. }
  418. }
  419. });
  420. },
  421. ToTreeData: function(data, childrenArrayName) {
  422. if (childrenArrayName == null || childrenArrayName == "")
  423. childrenArrayName = "children";
  424. if (data == null) return [];
  425. // 删除 所有 children,以防止多次调用
  426. data.forEach(function(item) {
  427. if (childrenArrayName == null)
  428. delete item.children;
  429. else
  430. delete item[childrenArrayName];
  431. });
  432. // 将数据存储为 以 id 为 KEY 的 map 索引数据列
  433. var map = {};
  434. data.forEach(function(item) {
  435. map[item.id] = item;
  436. });
  437. var val = [];
  438. data.forEach(function(item) {
  439. // 以当前遍历项,的pid,去map对象中找到索引的id
  440. var parent = map[item.pid];
  441. if (parent && item.id != item.pid) {
  442. (parent[childrenArrayName] || (parent[childrenArrayName] = [])).push(item);
  443. } else {
  444. val.push(item);
  445. }
  446. });
  447. return val;
  448. },
  449. //创建zTree的异步树,页面上需要引用以下js和css
  450. //<link rel="stylesheet" type="text/css" href="/static/css/zTreeStyle/zTreeStyle.css">
  451. //<script type="text/javascript" src="/static/js/ztree/jquery.ztree.core-3.5.js"></script>
  452. //$ele:显示树节点的元素对象
  453. //opt:初始配置项.{url:"接口地址","idKey":"","pidKey":"","nameKey":"","rootid":"","rootpid":"",callback:{}}
  454. Ztree: {
  455. zTreeObj: null,
  456. Init: function($ele, opt) {
  457. opt = opt || {
  458. callback: {}
  459. };
  460. opt.callback = opt.callback || {};
  461. // zTree 的参数配置,深入使用请参考 API 文档(setting 配置详解)
  462. var zTreeSetting = {
  463. check: opt.check || {
  464. enable: false,
  465. chkStyle: "radio",
  466. radioType: "level"
  467. },
  468. data: {
  469. key: {
  470. name: opt.nameKey || "title",
  471. children: "children"
  472. },
  473. simpleData: {
  474. enable: true,
  475. idKey: opt.idKey || "id",
  476. pIdKey: opt.pidKey || "pid",
  477. rootPId: opt.rootpid || 0
  478. }
  479. },
  480. usericon: {
  481. // 折叠icon
  482. OPEN: "open fa ftopen fa-folder-open", // 打开文件图标
  483. CLOSE: "close fa ftclose fa-folder", // 折叠文件图标
  484. OPENDK: 'open icon-folder ace-icon tree-minus', // 打开状态图标
  485. CLOSEZD: 'close icon-folder ace-icon tree-plus', // 折叠状态图标
  486. DOCU: "docu",
  487. // 子节点图标
  488. CHILDRENNODE: "fa-bookmark",
  489. // 复选框图标
  490. UNFACHECK: "fa fa-check",
  491. FACHECKED: "fa fa-times",
  492. // 编辑图标
  493. EDIT: "fa-pencil-square-o",
  494. // 移除图标
  495. REMOVE: "fa-eraser",
  496. // 增加节点图标
  497. ADDNODE: "fa-plus-square"
  498. },
  499. async: {
  500. enable: true,
  501. dataType: "text",
  502. type: "get",
  503. url: opt.url,
  504. autoParam: [opt.idKey || "id", opt.pidKey || "pid"].concat(opt.AjaxParam || []),
  505. dataFilter: opt.callback.dataFilter || function(treeId, parentNode, childNodes) {
  506. for (var i = 0; i < childNodes["data"].length; i++) {
  507. childNodes["data"][i]["checked"] = parentNode.checked;
  508. }
  509. return childNodes["data"];
  510. }
  511. },
  512. callback: opt.callback,
  513. view: {
  514. fontCss: opt.FontCss || null,
  515. showTitle: false,
  516. selectedMulti: false,
  517. expandSpeed: "",
  518. showLine: false,
  519. addDiyDom: opt.DiyDom || null
  520. }
  521. };
  522. zTreeSetting.usericon.CHILDRENNODE = $.trim(opt.childrenNodeIcon) == "" ? "fa-home" : opt.childrenNodeIcon;
  523. var initQueryParam = {};
  524. initQueryParam[opt.idKey || "id"] = opt.rootid || "";
  525. $.getJSON(opt.url, initQueryParam, function(result) {
  526. if (result["code"] == 0) {
  527. var treeData = result["data"];
  528. Global.Ztree.zTreeObj = $.fn.zTree.init($ele, zTreeSetting, treeData);
  529. //让第一个父节点展开
  530. var rootNode_0 = Global.Ztree.zTreeObj.getNodeByParam((opt.pidKey || "pid"), 0, null);
  531. Global.Ztree.zTreeObj.expandNode(rootNode_0, true, false, false, false);
  532. if (opt.callback != null && opt.callback.onInitLoad != null) {
  533. //初始化数据加载完成回调处理
  534. opt.callback.onInitLoad(rootNode_0);
  535. }
  536. }
  537. });
  538. }
  539. },
  540. setModuleTitle: function(title) {
  541. $(".module_nav").html(title);
  542. },
  543. GetFormData: function(filtername, form) {
  544. form = form || $(".layui-form[lay-filter='" + filtername + "']");
  545. var datas = {};
  546. form.find("input,select,textarea").each(function() {
  547. var t = $(this);
  548. var eleId = $.trim(t.attr("id"));
  549. if (eleId == "") return;
  550. if ("checkbox,radio".indexOf(t[0].type) > -1 && !t[0].checked) return;
  551. datas[eleId] = t.val();
  552. if (t.attr("lay-verify") == "required" && t.parent().is(":visible") && datas[eleId] == "") {
  553. datas = null;
  554. layer.tips("此项为必填项!", t.parent()[0], {
  555. tips: [3, "red"]
  556. });
  557. return false;
  558. }
  559. });
  560. return datas;
  561. },
  562. OpenDialog: function(container, set_margin_left) {
  563. var total_height = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
  564. $(".clearn").show().css("height", total_height + "px");
  565. container.css("z-index", Global.GetSeqNext()).show();
  566. var left = parseInt(container.width() / 2);
  567. left = -left;
  568. var top = parseInt(container.height() / 2);
  569. top = -top;
  570. if (set_margin_left) {
  571. container.css({
  572. "margin-left": left + "px",
  573. "margin-top": top + "px"
  574. });
  575. }
  576. if (container.find("input").length > 0)
  577. container.find("input:first").focus();
  578. },
  579. CloseDialog: function(container) {
  580. if (container == null)
  581. $(".layout_dialog,.clearn").hide();
  582. else {
  583. container.hide();
  584. $(".clearn").hide();
  585. }
  586. },
  587. GetCurrentDate: function() {
  588. var date = new Date();
  589. var year = date.getFullYear();
  590. var month = date.getMonth() + 1;
  591. var day = date.getDate();
  592. return year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  593. },
  594. GetCurrentDateTime: function(type) {
  595. var date = new Date(),
  596. result = "";
  597. var year = date.getFullYear();
  598. var month = date.getMonth() + 1;
  599. var day = date.getDate();
  600. var hour = date.getHours();
  601. result = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  602. if (type == "s") //一般为开始时间
  603. result += " " + "00:00:00";
  604. else if (type == "e")  //-般为结束时间
  605. {
  606. date = date.setDate(date.getDate() + 1);
  607. date = new Date(date);
  608. year = date.getFullYear();
  609. month = date.getMonth() + 1;
  610. day = date.getDate();
  611. result = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day);
  612. result += " 00:00:00";
  613. }
  614. return result;
  615. },
  616. FunctionControl: function() {
  617. var userInfo = localStorage.getItem("userinfo");
  618. userInfo = JSON.parse(userInfo);
  619. $("#login_user_name").html(userInfo["name"]);
  620. if (userInfo["role"] != "1") {
  621. }
  622. },
  623. //获取一个10位长度的序列值。每调用一次其值增加1
  624. GetSeqNext: function() {
  625. this._seqvalue++;
  626. return this._seqvalue;
  627. },
  628. //修改自己的登录密码
  629. ModifyMyPwd: function() {
  630. layer.confirm("<div style='text-align:center;'><span>请输入原密码</span></div>" +
  631. "<div style='text-align:center;'><input id='modify_my_oldpwd' type=password value='' placeholder='请输入6-32个字符' maxlength=32></div>" +
  632. "<div style='text-align:center;'><span>请填写新密码</span></div>" +
  633. "<div style='text-align:center;'><input id='modify_my_pwd' type=password value='' placeholder='请输入6-32个字符' maxlength=32></div>" +
  634. "<div style='text-align:center;'><span>请再次填写密码</span></div>" +
  635. "<div style='text-align:center;'><input id='modify_my_pwd2' type=password value='' placeholder='请输入6-32个字符' maxlength=32></div>", {
  636. "title": "修改密码"
  637. },
  638. function(index) {
  639. var old = $.trim($("#modify_my_oldpwd").val());
  640. if (old == "") {
  641. layer.msg("原密码不能为空!", {});
  642. return false;
  643. }
  644. var v = $.trim($("#modify_my_pwd").val());
  645. if (v == "") {
  646. layer.msg("新密码不能为空!", {});
  647. return false;
  648. }
  649. if (v != $.trim($("#modify_my_pwd2").val())) {
  650. layer.msg("两次密码不一致!", {});
  651. return false;
  652. }
  653. if (v.length < 6 || v.length > 16) {
  654. layer.msg("新密码长度无效!", {});
  655. return;
  656. }
  657. $.post(Global.AccessUrl + "/api/resetUserPwd", {
  658. "newpwd": Tools.GetPassWord(v),
  659. "oldpwd": Tools.GetPassWord(old)
  660. }, function(result) {
  661. if (result["returncode"] == 200) {
  662. layer.msg("操作成功!");
  663. } else {
  664. layer.msg("操作失败:" + result["msg"]);
  665. }
  666. });
  667. });
  668. }
  669. }
  670. Global["SCD_COMP_ATTR_CONST"] = {
  671. "ied.config_version": "配置版本",
  672. "ied.desc": "装置描述",
  673. "ied.manufacturer": "厂商",
  674. "ied.name": "装置名称",
  675. "ied.type": "装置类型",
  676. }
  677. function MqttClient(host, port, topics, callback) {
  678. var self = this;
  679. const options = {
  680. // 超时时间
  681. connectTimeout: 4000,
  682. // 认证信息
  683. clientId: 'police_s_js_' + new Date().getTime(),
  684. //username: "",
  685. //password: "", //$.md5(userinfo["account"] + userinfo["userid"]),
  686. // 心跳时间
  687. keepalive: 30,
  688. clean: true,
  689. //离线时发送的topic
  690. /*will: {
  691. "topic": "",
  692. "payload": "offline",
  693. "QoS": 0,
  694. "retain": true
  695. }*/
  696. }
  697. var WebSocket_URL = "";
  698. if (port == null) port = "8083";
  699. WebSocket_URL = 'ws://' + host + ':' + port + '/mqtt';
  700. this.MqttClient = null;
  701. this.receivedFunList = [];
  702. this.connCallback = callback;
  703. this.Conn = function(host, port) {
  704. this.MqttClient = mqtt.connect(WebSocket_URL, options);
  705. this.MqttClient.on('connect', () => {
  706. console.log('连接成功');
  707. if (self.connCallback != null) self.connCallback();
  708. if (topics != null) {
  709. self.MqttClient.subscribe(
  710. topics, {
  711. qos: 0
  712. },
  713. (err) => {
  714. console.log(err || '订阅成功');
  715. }
  716. );
  717. }
  718. });
  719. this.MqttClient.on('reconnect', (error) => {
  720. console.log('正在重连:', error)
  721. });
  722. this.MqttClient.on('error', (error) => {
  723. console.log('连接失败:', error)
  724. });
  725. this.MqttClient.on('offline', () => {
  726. console.log('连接断开')
  727. });
  728. this.MqttClient.on('close', () => {
  729. console.log('已下线')
  730. });
  731. // 监听接收消息事件
  732. this.MqttClient.on('message', (topic, message) => {
  733. //console.log('收到来自', topic, '的消息', message.toString());
  734. if (self.receivedFunList == null) return;
  735. for (var k in self.receivedFunList) {
  736. if (topic.indexOf(k) > -1) {
  737. if (self.receivedFunList[k] != null) self.receivedFunList[k](topic, message.toString());
  738. }
  739. }
  740. });
  741. }
  742. this.SubscribeTopic = function(topics) {
  743. this.MqttClient.subscribe(
  744. topics, {
  745. qos: 0
  746. },
  747. (err) => {
  748. console.log(err || '订阅成功');
  749. }
  750. );
  751. }
  752. this.AddReceivedMqttMessage = function(topic, callback) {
  753. this.receivedFunList[topic] = callback;
  754. }
  755. this.SendMqttMessage = function(topic, jsonmsg, callback) {
  756. this.MqttClient.publish(topic, jsonmsg, {
  757. qos: 0,
  758. rein: true
  759. }, (error) => {
  760. if (error != null) console.log(error)
  761. else {
  762. if (callback) callback();
  763. }
  764. })
  765. }
  766. if (host == null) {
  767. $.getJSON(Global.AccessUrl + "/api/getSysParamList", {
  768. "param_name": "Mqtt_JS_URL"
  769. }, function(r) {
  770. if (r.code != 0) {
  771. return;
  772. }
  773. if (r.data == null || r.data.length == 0) return;
  774. mqtturl = r.data[0].param_value;
  775. mqtturlPart = mqtturl.split(":");
  776. WebSocket_URL = 'ws://' + mqtturl + '/mqtt';
  777. self.Conn(mqtturlPart[0], mqtturlPart[1]);
  778. })
  779. } else {
  780. this.Conn(host, port);
  781. }
  782. }
  783. var menuObject = {
  784. HrefUrl: function(url) {
  785. if (url == null || url == "")
  786. return false;
  787. $(".main-body").load(url, function(result) {});
  788. }
  789. }
  790. var Tools = {
  791. html_encode: function(str) {
  792. var s = "";
  793. if (str.length == 0) return "";
  794. s = str.replace(/&/g, "&gt;");
  795. s = s.replace(/</g, "&lt;");
  796. s = s.replace(/>/g, "&gt;");
  797. s = s.replace(/ /g, "&nbsp;");
  798. s = s.replace(/\'/g, "&#39;");
  799. s = s.replace(/\"/g, "&quot;");
  800. s = s.replace(/\n/g, "<br>");
  801. return s;
  802. },
  803. GetPassWord: function(str) {
  804. var val = SmCrypto.doSm3AndSm2Encrypt(str) + "0000",
  805. ascCode = 0;
  806. for (var i = 0; i < str.length; i++) {
  807. ascCode = str.charCodeAt(i).toString(16);
  808. if (ascCode.length == 1)
  809. val += "00" + ascCode;
  810. else if (ascCode.length == 2)
  811. val += "0" + ascCode;
  812. else
  813. val += ascCode;
  814. }
  815. return val;
  816. },
  817. BindTable: function(tableParameter) {
  818. var token = $.trim(localStorage.getItem("sessionid"));
  819. var token2 = "police-s-admin-" + Global.RandomString(11);
  820. tableParameter["headers"] = {
  821. "Authorization": "Bearer " + token,
  822. "auth_nonce": token2
  823. };
  824. if (!tableParameter.hasOwnProperty("method"))
  825. tableParameter["method"] = "get";
  826. if (!tableParameter.hasOwnProperty("cellMinWidth"))
  827. tableParameter["cellMinWidth"] = 80;
  828. if (!tableParameter.hasOwnProperty("height")) {
  829. tableParameter["height"] = $(".main-body").height() - 140;
  830. }
  831. if (!tableParameter.hasOwnProperty("page")) {
  832. tableParameter["page"] = true;
  833. }
  834. if (!tableParameter.hasOwnProperty("limit")) {
  835. tableParameter["limit"] = 20;
  836. }
  837. if (!tableParameter.hasOwnProperty("loading")) {
  838. tableParameter["loading"] = true;
  839. }
  840. tableParameter["defaultToolbar"] = [];
  841. if (!tableParameter.hasOwnProperty("request")) {
  842. tableParameter["request"] = {
  843. pageName: 'pageindex',
  844. limitName: 'pagesize'
  845. };
  846. }
  847. layui.use(['table'], function() {
  848. layui.table.render(tableParameter)
  849. });
  850. },
  851. GetOrgName: function(container, orgId, callback) {
  852. $.getJSON("/api/get_org_name", {}, function(rturnData) {
  853. if (rturnData["code"] == 0) {
  854. var data = rturnData["data"];
  855. $.each(data, function(index, item) {
  856. if (orgId != null && orgId != "" && item.id == orgId) {
  857. container.append(new Option(item.name, item.id, false, true));
  858. } else {
  859. container.append(new Option(item.name, item.id));
  860. }
  861. });
  862. layui.form.render("select");
  863. if (callback != null && typeof(callback) === "function") {
  864. callback(data);
  865. }
  866. }
  867. });
  868. },
  869. //设置声音报警开关状态
  870. SetAudioState: function(state) {
  871. window.localStorage.setItem("audio-alert", state);
  872. },
  873. Loading2Ok: function(ele) {
  874. if (ele == null) return;
  875. ele.find(".layui-icon-loading-1").attr("class", "layui-icon layui-icon-ok-circle");
  876. },
  877. OkIcon: function(css) {
  878. var style = css != null ? css : "margin:0 1rem";
  879. var icon = "<i class='layui-icon layui-icon-ok-circle' style='" + style + "'></i>";
  880. return icon;
  881. },
  882. LoadingIcon: function(css) {
  883. var style = css != null ? css : "margin:0 1rem";
  884. var icon = "<i class='layui-icon layui-icon-loading-1 layui-anim layui-anim-rotate layui-anim-loop' style='" + style + "'></i>";
  885. return icon;
  886. },
  887. LoadingText: function(message, color) {
  888. var htmlObject = new Array();
  889. htmlObject.push("<div style='width:100%;padding-top: 0%;text-align:center;font-size:1.8rem;color:" + (color == null ? "#cccccc" : color) + "'>");
  890. htmlObject.push("<i class='layui-icon layui-icon-loading-1 layui-anim layui-anim-rotate layui-anim-loop' style='margin-right:10px'></i>");
  891. if (message != null && message != "")
  892. htmlObject.push("<span>" + message + "</span>");
  893. else
  894. htmlObject.push("<span>正在加载中...</span>");
  895. htmlObject.push("</div>");
  896. return htmlObject.join("");
  897. },
  898. HintText: function(message, color) {
  899. var htmlObject = new Array();
  900. htmlObject.push("<div style='width:100%;padding-top: 0%;text-align:center;font-size:1.8rem;color:" + (color == null ? "#cccccc" : color) + "'>");
  901. htmlObject.push("<i class='layui-icon layui-icon-tips' style='margin-right:10px'></i>");
  902. if (message != null && message != "")
  903. htmlObject.push("<span>" + message + "</span>");
  904. else
  905. htmlObject.push("<span>正在加载中...</span>");
  906. htmlObject.push("</div>");
  907. return htmlObject.join("");
  908. },
  909. ShowBigImg: function(e, sizeW, sizeH) {
  910. var imgThis = $(e),
  911. src = $.trim(imgThis.attr("src"));
  912. if (src == "" || src.indexOf("imgerror.png") > -1 || src.indexOf("userhead.png") > -1) return;
  913. src = src.replace(/0\_small/gi, "_big").replace(/SNAP/gi, "BACKGROUND");
  914. /*var showDiv = $("#imgBigShow");
  915. if (sizeW == null) sizeW = 500;
  916. if (sizeH == null) sizeH = 500;
  917. if (showDiv.length == 0) {
  918. $("body").append("<div style='position: absolute;width: " + sizeW + "px;height: " + sizeW + "px;top: 50%;left: 50%;margin-left: -" + (sizeW / 2) + "px;margin-top: -" + (sizeH / 2) + "px;z-index: " + Global.GetSeqNext() + ";overflow: auto;background-color: #ffffff;border:2px solid #7d7dbf;text-align: center' class='imgBigShow' id='imgBigShow'><div style='float:left;width:100%;height:35px;background-color:#1E9FFF;'><span style='float:right;margin:10px;cursor:pointer;color: #fff;' onclick='$(\"#imgBigShow\").remove()'>X</span></div><a href='" + src + "' target=_blank><img title='点击查看原图' style='padding: 20px;max-width:" + (sizeW - 40) + "px;max-height:" + (sizeH - 20) + "px;' src='" + src + "'></a></div>");
  919. showDiv = $("#imgBigShow");
  920. } else {
  921. showDiv.find("a").attr("href", src).find("img").attr("src", src);
  922. }
  923. showDiv.removeClass("hide");*/
  924. var ind = layui.layer.open({
  925. type: 1,
  926. maxmin: true,
  927. resize: true,
  928. scrollbar: true,
  929. title: "查看原图",
  930. area: [1920 * 0.7 * wRate + "px", 1080 * 0.7 * hRate + "px"],
  931. content: "<img style='width:100%;height:100%' src='" + src + "'>"
  932. });
  933. $("#layui-layer" + ind).css("z-index", Global.GetSeqNext());
  934. },
  935. TransImgUrl: function(sourceSrc) {
  936. if (sourceSrc == null || sourceSrc == "") {
  937. return "/static/images/userhead.png";
  938. }
  939. if (sourceSrc.indexOf("http") == 0) {
  940. return sourceSrc;
  941. }
  942. sourceSrc = sourceSrc.replace("/home/go/project/platform_service", "");
  943. return Global.AccessUrl + sourceSrc;
  944. },
  945. SortBy: function(attr, rev) {
  946. //第二个参数为true or false 若没有传递 默认升序排列
  947. if (rev == undefined) {
  948. rev = 1;
  949. } else {
  950. rev = (rev) ? 1 : -1;
  951. }
  952. return function(a, b) {
  953. a = a[attr];
  954. b = b[attr];
  955. if (a < b) {
  956. return rev * -1;
  957. }
  958. if (a > b) {
  959. return rev * 1;
  960. }
  961. return 0;
  962. }
  963. },
  964. AlertStart: function(ele) {
  965. function alertTable(t) {
  966. this.$t = $(t);
  967. this.border = "2";
  968. var self = this;
  969. this.start = function() {
  970. if (this.$t.length == 0) {
  971. return;
  972. }
  973. setTimeout(function() {
  974. var trs = self.$t.find("tr[isnew='1']");
  975. if (trs.length > 0) {
  976. self.border = self.border == "2" ? "0" : "2";
  977. trs.css("border-bottom", self.border + "px solid red");
  978. }
  979. self.start();
  980. }, 500);
  981. }
  982. }
  983. var newa = new alertTable(ele);
  984. newa.start();
  985. },
  986. AlwaysTimer: function() {
  987. var time = new Date();
  988. var year = time.getFullYear();
  989. var month = time.getMonth() + 1;
  990. var date = time.getDate();
  991. var hour = time.getHours();
  992. var minutes = time.getMinutes();
  993. var seconds = time.getSeconds();
  994. month = month < 10 ? "0" + month : month;
  995. date = date < 10 ? "0" + date : date;
  996. if (hour < 10) {
  997. hour = "0" + hour;
  998. }
  999. if (minutes < 10) {
  1000. minutes = "0" + minutes;
  1001. }
  1002. if (seconds < 10) {
  1003. seconds = "0" + seconds;
  1004. }
  1005. $(".yyyymmdd").html(year + "-" + month + "-" + date);
  1006. $(".week").html(Tools.GetWeek());
  1007. $(".hour_minute").html(hour + ":" + minutes + ":" + seconds);
  1008. setTimeout('Tools.AlwaysTimer()', 1000);
  1009. },
  1010. GetWeek: function() {
  1011. var time = new Date();
  1012. var day = time.getDay();
  1013. var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  1014. return weeks[day];
  1015. },
  1016. PlayVideo: function(title, url, errorCall) {
  1017. var tid = $.trim(localStorage.getItem("tid"));
  1018. if (tid == "") {
  1019. if (errorCall != null) errorCall();
  1020. }
  1021. //获取本地是否安装播放客户端程序.未安装时采用web播放
  1022. $.getJSON(Global.AccessUrl + "/api/version/get_client", {
  1023. "clientname": tid,
  1024. "type": "ffplayer_client"
  1025. }, function(d) {
  1026. if (d.returncode == 200) {
  1027. layer.msg("正在载入远程视频流...需要耐心等待一会(约12秒)", {
  1028. icon: 6,
  1029. time: 15000,
  1030. skin: "tips_css"
  1031. });
  1032. $.post(Global.AccessUrl + "/api/net/video/play", {
  1033. "url": url,
  1034. "title": title,
  1035. "clientname": tid,
  1036. }, function(r) {
  1037. if (r.returncode != 200) {
  1038. layer.msg(r.msg, {
  1039. time: 3000,
  1040. skin: "tips_css"
  1041. });
  1042. return;
  1043. }
  1044. });
  1045. } else {
  1046. if (errorCall != null) errorCall();
  1047. }
  1048. })
  1049. },
  1050. ExpExcel: function(para) {
  1051. layer.msg("正在导出数据中...", {
  1052. timer: 0
  1053. })
  1054. $.post(Global.AccessUrl + "/api/expTableData", para, function(r) {
  1055. layer.closeAll()
  1056. if (r.code != 0) {
  1057. DialogObject.Msg(r["msg"]);
  1058. return;
  1059. } else {
  1060. layer.confirm("<span style='color: #233C7F;'>数据文件已生成完成,<a onclick='layer.closeAll()' target=_blank href='/" + r.data + "' style='color: blue;font-size: 1.6rem;text-decoration-line: revert;'>点击立即下载</a></span>", {
  1061. btn: ['关闭'],
  1062. icon: 1,
  1063. title: "数据导出",
  1064. zIndex: Global.GetSeqNext(),
  1065. btn1: function() {
  1066. layer.closeAll()
  1067. }
  1068. });
  1069. }
  1070. })
  1071. },
  1072. CopyTextData: function(e, txt) {
  1073. //$(e).stopPropagation();
  1074. var textArea = document.createElement("textarea");
  1075. textArea.id = "tmp_copydata_input"
  1076. textArea.style.position = 'fixed';
  1077. textArea.style.top = -1000;
  1078. textArea.style.left = -1000;
  1079. textArea.style.width = '2em';
  1080. textArea.style.height = '2em';
  1081. textArea.style.background = 'transparent';
  1082. textArea.value = txt;
  1083. document.body.appendChild(textArea);
  1084. textArea.select();
  1085. try {
  1086. var successful = document.execCommand('copy');
  1087. var msg = successful ? '数据已成功复制到剪贴板' : '该浏览器不支持点击复制到剪贴板';
  1088. layer.msg(msg);
  1089. $('#tmp_copydata_input').remove();
  1090. } catch (err) {
  1091. layer.msg('该浏览器不支持点击复制到剪贴板');
  1092. }
  1093. },
  1094. GetMapDiffItems: function(t1, t2) {
  1095. var result = {
  1096. "_add_cnt": 0,
  1097. "_del_cnt": 0,
  1098. "_edit_cnt": 0,
  1099. "add": {},
  1100. "del": {},
  1101. "edit": {}
  1102. };
  1103. for (var k in t1) {
  1104. if (t2[k] == null) {
  1105. result.add[k] = t1[k];
  1106. result._add_cnt++;
  1107. } else if ((t2[k] != t1[k])) {
  1108. result.edit[k] = [t1[k], t2[k]];
  1109. result._edit_cnt++;
  1110. }
  1111. }
  1112. for (var k in t2) {
  1113. if (t1[k] == null) {
  1114. result.del[k] = t2[k];
  1115. result._del_cnt++;
  1116. }
  1117. }
  1118. return result
  1119. }
  1120. }
  1121. //报警信息显示
  1122. var AlertWin = {
  1123. window: null,
  1124. Init: function() {
  1125. this.window = $("#alert_window")
  1126. },
  1127. MoveTo: function(t) {
  1128. var $t = $(t);
  1129. var jd = $.trim($t.attr("jd"));
  1130. var wd = $.trim($t.attr("wd"));
  1131. if (jd == "" || wd == "") {
  1132. DialogObject.Msg("设备未设置坐标,定位失败!");
  1133. return;
  1134. }
  1135. if (!$("#container_map").is(":visible")) return;
  1136. if (jd * 1 < 1 || wd * 1 < 1) {
  1137. DialogObject.Msg("设备未设置有效坐标,定位失败!");
  1138. return;
  1139. }
  1140. MapObject.SetMarker({
  1141. "url": "/static/images/marker_point4.png"
  1142. }, jd * 1, wd * 1);
  1143. MapObject.MoveTo(jd * 1, wd * 1, 19);
  1144. },
  1145. RemoveOne: function(t) {
  1146. var $t = $(t);
  1147. $t.parent().remove();
  1148. if (this.window.find(".alert_item").length == 0) {
  1149. this.window.addClass("hidden");
  1150. }
  1151. },
  1152. Show: function(alertinfo) {
  1153. if (alertinfo.devicealert == "doorlock" && ("用户布防,用户撤防".indexOf($.trim(alertinfo.event)) > -1)) {
  1154. return;
  1155. }
  1156. var win = this.window;
  1157. if (win.hasClass("hidden")) {
  1158. var w = win.width(),
  1159. h = win.height();
  1160. win.css({
  1161. position: "absolute",
  1162. top: ($("body").height() * hRate - 100) / 5,
  1163. left: ($("body").width() * wRate - 480) / 2,
  1164. bottom: "auto",
  1165. width: "480px"
  1166. });
  1167. win.removeClass("hidden");
  1168. win.find(".dataitemlist").css({
  1169. "min-height": "100px",
  1170. "max-height": "300px",
  1171. "overflow-y": "auto"
  1172. });
  1173. }
  1174. var h = template("alert_list_item_tpl", alertinfo);
  1175. win.find(".dataitemlist").append(h).find(".alert_item").off().on("mouseover", function() {
  1176. var t = $(this);
  1177. t.find(".btn_cancel").removeClass("hidden");
  1178. }).on("mouseout", function() {
  1179. var t = $(this);
  1180. t.find(".btn_cancel").addClass("hidden");
  1181. });
  1182. win.find(".dataitemlist .camera_location").off().on("click", function() {
  1183. var t = $(this),
  1184. url = t.attr("video_url");
  1185. if (url == "") return;
  1186. Tools.PlayVideo("现场视频", url);
  1187. });
  1188. var startAudio = $.trim(window.localStorage.getItem("audio-alert"));
  1189. if (startAudio != "1") {
  1190. //判断是否开启了声音报警。静音图标未隐藏表示不启用声音报警,反之表示开启声音报警
  1191. return;
  1192. } //判断是否关联的视频,如果关联了则播放视频
  1193. var video_url = $.trim(alertinfo["video_url"]);
  1194. if (video_url != "") {
  1195. Tools.PlayVideo("现场视频", video_url);
  1196. }
  1197. //触发声音报警
  1198. var audio = new Audio("/static/images/14141.mp3");
  1199. audio.play();
  1200. /*
  1201. var strAudio = "<audio id='audioPlay' src='/static/images/14141.mp3' hidden='true'>";
  1202. if ($("body").find("audio").length <= 0)
  1203. $("body").append(strAudio);
  1204. var audio = document.getElementById("audioPlay");
  1205. //浏览器支持 audion
  1206. audio.play();*/
  1207. }
  1208. }
  1209. var setPrefix = function(prefixIndex) {
  1210. let result = '';
  1211. let span = ' '; //缩进长度
  1212. let output = [];
  1213. for (let i = 0; i < prefixIndex; ++i) {
  1214. output.push(span);
  1215. }
  1216. result = output.join('');
  1217. return result;
  1218. };
  1219. var formateXml = function(xmlStr) {
  1220. let that = this;
  1221. let text = xmlStr;
  1222. //使用replace去空格
  1223. text =
  1224. '\n' +
  1225. text
  1226. .replace(/(<\w+)(\s.*?>)/g, ($0, name, props) => {
  1227. return name + ' ' + props.replace(/\s+(\w+=)/g, ' $1');
  1228. })
  1229. .replace(/>\s*?</g, '>\n<');
  1230. //处理注释,对注释进行编码
  1231. text = text
  1232. .replace(/\n/g, '\r')
  1233. .replace(/<!--(.+?)-->/g, function($0, text) {
  1234. return '<!--' + escape(text) + '-->';
  1235. })
  1236. .replace(/\r/g, '\n');
  1237. //调整格式 以压栈方式递归调整缩进
  1238. let rgx = /\n(<(([^\?]).+?)(?:\s|\s*?>|\s*?(\/)>)(?:.*?(?:(?:(\/)>)|(?:<(\/)\2>)))?)/gm;
  1239. let nodeStack = [];
  1240. let output = text.replace(
  1241. rgx,
  1242. ($0, all, name, isBegin, isCloseFull1, isCloseFull2, isFull1, isFull2) => {
  1243. let isClosed = isCloseFull1 == '/' || isCloseFull2 == '/' || isFull1 == '/' || isFull2 == '/';
  1244. let prefix = '';
  1245. if (isBegin == '!') {
  1246. //!开头
  1247. prefix = setPrefix(nodeStack.length);
  1248. } else {
  1249. if (isBegin != '/') {
  1250. ///开头
  1251. prefix = setPrefix(nodeStack.length);
  1252. if (!isClosed) {
  1253. //非关闭标签
  1254. nodeStack.push(name);
  1255. }
  1256. } else {
  1257. nodeStack.pop(); //弹栈
  1258. prefix = setPrefix(nodeStack.length);
  1259. }
  1260. }
  1261. return '\n' + prefix + all;
  1262. },
  1263. );
  1264. let outputText = output.substring(1);
  1265. //还原注释内容
  1266. outputText = outputText
  1267. .replace(/\n/g, '\r')
  1268. .replace(/(\s*)<!--(.+?)-->/g, function($0, prefix, text) {
  1269. if (prefix.charAt(0) == '\r') prefix = prefix.substring(1);
  1270. // 解码
  1271. text = unescape(text).replace(/\r/g, '\n');
  1272. let ret = '\n' + prefix + '<!--' + text.replace(/^\s*/gm, prefix) + '-->';
  1273. return ret;
  1274. });
  1275. outputText = outputText.replace(/\s+$/g, '').replace(/\r/g, '\r\n');
  1276. return outputText;
  1277. };
  1278. Date.prototype.Format = function(fmt) { //author: meizz
  1279. var o = {
  1280. "M+": this.getMonth() + 1, //月份
  1281. "d+": this.getDate(), //日
  1282. "h+": this.getHours(), //小时
  1283. "m+": this.getMinutes(), //分
  1284. "s+": this.getSeconds(), //秒
  1285. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  1286. "S": this.getMilliseconds() //毫秒
  1287. };
  1288. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  1289. for (var k in o)
  1290. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  1291. return fmt;
  1292. }
  1293. //初始化ajax提交
  1294. Global.InitAjaxSetup();
  1295. //初始化接口地址及登录页面地址
  1296. Global.InitAccessUrl();
  1297. window.addEventListener("resize", function() {
  1298. Global.InitRootFontSize();
  1299. if (Global._autoLayoutFunc != null) {
  1300. Global._autoLayoutFunc();
  1301. }
  1302. });
  1303. Global.InitRootFontSize();
  1304. //判断当前用户密码的修改模式,admin时只能管理员修改,其他模式时用户可自行修改密码
  1305. //login_user_name
  1306. setTimeout(function() {
  1307. var uinfo = $.trim(localStorage.getItem("userinfo"));
  1308. if (uinfo != "") {
  1309. uinfo = JSON.parse(uinfo);
  1310. var pwdeditmode = $.trim(uinfo["pwdeditmod"])
  1311. if (pwdeditmode != "" && pwdeditmode != "admin") {
  1312. $("#login_user_name").parent().attr("href", "javascript:void(0)");
  1313. $("#login_user_name").on('click', function() {
  1314. //加载密码修改页面
  1315. var hiddenDiv = $(".layui-side");
  1316. if (hiddenDiv.length > 0) hiddenDiv.addClass("hidden");
  1317. else $("body>div[class!='monitor_center']").addClass("hidden");
  1318. $(".monitor_center .body_content,.layui-body").load("/static/edit_pwd.html")
  1319. })
  1320. } else {
  1321. $("#login_user_name").parent().attr("href", "javascript:void(0)");
  1322. }
  1323. }
  1324. }, 1000)