xadmin.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. ;!function (win) {
  2. "use strict";
  3. var doc = document
  4. ,Xadmin = function(){
  5. this.v = '2.2'; //版本号
  6. }
  7. Xadmin.prototype.init = function() {
  8. var tab_list = this.get_data();
  9. for(var i in tab_list){
  10. this.add_lay_tab(tab_list[i].title,tab_list[i].url,i);
  11. }
  12. element.tabChange('xbs_tab', i);
  13. };
  14. /**
  15. * [end 执行结束要做的]
  16. * @return {[type]} [description]
  17. */
  18. Xadmin.prototype.end = function() {
  19. var cate_list = this.get_cate_data();
  20. for(var i in cate_list){
  21. if(cate_list[i]!=null){
  22. $('.left-nav #nav li').eq(cate_list[i]).click();
  23. }
  24. }
  25. };
  26. Xadmin.prototype.add_tab = function (title,url,is_refresh) {
  27. var id = md5(url);//md5每个url
  28. //重复点击
  29. for (var i = 0; i <$('.x-iframe').length; i++) {
  30. if($('.x-iframe').eq(i).attr('tab-id')==id){
  31. element.tabChange('xbs_tab', id);
  32. if(is_refresh)
  33. $('.x-iframe').eq(i).attr("src",$('.x-iframe').eq(i).attr('src'));
  34. return;
  35. }
  36. };
  37. this.add_lay_tab(title,url,id);
  38. this.set_data(title,url,id);
  39. element.tabChange('xbs_tab', id);
  40. }
  41. Xadmin.prototype.del_tab = function (id) {
  42. if(id){
  43. console.log(88);
  44. }else{
  45. var id = $(window.frameElement).attr('tab-id');
  46. parent.element.tabDelete('xbs_tab', id);
  47. }
  48. }
  49. Xadmin.prototype.add_lay_tab = function(title,url,id) {
  50. element.tabAdd('xbs_tab', {
  51. title: title
  52. ,content: '<iframe tab-id="'+id+'" frameborder="0" src="'+url+'" scrolling="yes" class="x-iframe"></iframe>'
  53. ,id: id
  54. })
  55. }
  56. Xadmin.prototype.del_all = function () {
  57. $('.layui-tab-title li[lay-id]').find('.layui-tab-close').click();
  58. $('#tab_right').hide();
  59. $('#tab_show').hide();
  60. }
  61. /**
  62. * [open 打开弹出层]
  63. * @param {[type]} title [弹出层标题]
  64. * @param {[type]} url [弹出层地址]
  65. * @param {[type]} w [宽]
  66. * @param {[type]} h [高]
  67. * @param {Boolean} full [全屏]
  68. * @return {[type]} [description]
  69. */
  70. Xadmin.prototype.open = function (title,url,w,h,full) {
  71. if (title == null || title == '') {
  72. var title=false;
  73. };
  74. if (url == null || url == '') {
  75. var url="404.html";
  76. };
  77. if (w == null || w == '') {
  78. var w=($(window).width()*0.9);
  79. };
  80. if (h == null || h == '') {
  81. var h=($(window).height() - 50);
  82. };
  83. var index = layer.open({
  84. type: 2,
  85. area: [w+'px', h +'px'],
  86. fix: false, //不固定
  87. maxmin: true,
  88. shadeClose: true,
  89. shade:0.4,
  90. title: title,
  91. content: url
  92. });
  93. if(full){
  94. layer.full(index);
  95. }
  96. }
  97. /**
  98. * [close 关闭弹出层]
  99. * @return {[type]} [description]
  100. */
  101. Xadmin.prototype.close = function() {
  102. var index = parent.layer.getFrameIndex(window.name);
  103. parent.layer.close(index);
  104. };
  105. /**
  106. * [close 关闭弹出层父窗口关闭]
  107. * @return {[type]} [description]
  108. */
  109. Xadmin.prototype.father_reload = function() {
  110. parent.location.reload();
  111. };
  112. /**
  113. * [get_data 获取所有项]
  114. * @return {[type]} [description]
  115. */
  116. Xadmin.prototype.get_data = function () {
  117. if(typeof is_remember!="undefined")
  118. return false;
  119. return layui.data('tab_list')
  120. }
  121. /**
  122. * [set_data 增加某一项]
  123. * @param {[type]} id [description]
  124. */
  125. Xadmin.prototype.set_data = function(title,url,id) {
  126. if(typeof is_remember!="undefined")
  127. return false;
  128. layui.data('tab_list', {
  129. key: id
  130. ,value: {title:title,url:url}
  131. });
  132. };
  133. /**
  134. * [get_data 获取所有项]
  135. * @return {[type]} [description]
  136. */
  137. Xadmin.prototype.get_cate_data = function () {
  138. if(typeof is_remember!="undefined")
  139. return false;
  140. return layui.data('cate')
  141. }
  142. /**
  143. * [set_data 增加某一项]
  144. * @param {[type]} id [description]
  145. */
  146. Xadmin.prototype.set_cate_data = function(data) {
  147. if(typeof is_remember!="undefined")
  148. return false;
  149. layui.data('cate', data);
  150. };
  151. /**
  152. * [del_data 删除某一项]
  153. * @param {[type]} id [description]
  154. * @return {[type]} [description]
  155. */
  156. Xadmin.prototype.del_data = function(id) {
  157. if(typeof is_remember!="undefined")
  158. return false;
  159. if(typeof id!="undefined"){
  160. layui.data('tab_list', {
  161. key: id
  162. ,remove: true
  163. });
  164. }else{
  165. layui.data('tab_list',null);
  166. }
  167. };
  168. /**
  169. * [del_other_data 删除其它]
  170. * @param {[type]} id [description]
  171. * @return {[type]} [description]
  172. */
  173. Xadmin.prototype.del_other_data = function(id) {
  174. if(typeof is_remember!="undefined")
  175. return false;
  176. var tab_list = this.get_data();
  177. layui.data('tab_list',null);
  178. layui.data('tab_list', {
  179. key: id
  180. ,value: tab_list[id]
  181. });
  182. };
  183. win.xadmin = new Xadmin();
  184. }(window);
  185. layui.use(['layer','element','jquery'],function() {
  186. layer = layui.layer;
  187. element = layui.element;
  188. $ = layui.jquery;
  189. // 打开页面初始
  190. xadmin.init();
  191. //关闭tab清除记忆
  192. element.on('tabDelete(xbs_tab)', function(data){
  193. var id = $(this).parent().attr('lay-id');
  194. xadmin.del_data(id);
  195. });
  196. //左侧菜单
  197. $('.left-nav #nav').on('click', 'li', function(event) {
  198. if($(this).parent().attr('id')=='nav'){
  199. xadmin.set_cate_data({key:'f1',value:$('.left-nav #nav li').index($(this))})
  200. xadmin.set_cate_data({key:'f2',value:null})
  201. xadmin.set_cate_data({key:'f3',value:null})
  202. }
  203. if($(this).parent().parent().parent().attr('id')=='nav'){
  204. xadmin.set_cate_data({key:'f2',value:$('.left-nav #nav li').index($(this))})
  205. xadmin.set_cate_data({key:'f3',value:null})
  206. }
  207. if($(this).parent().parent().parent().parent().parent().attr('id')=='nav'){
  208. xadmin.set_cate_data({key:'f3',value:$('.left-nav #nav li').index($(this))})
  209. }
  210. if($('.left-nav').css('width')=='60px'){
  211. $('.left-nav').animate({width: '220px'}, 100);
  212. $('.page-content').animate({left: '220px'}, 100);
  213. $('.left-nav i').css('font-size','14px');
  214. $('.left-nav cite,.left-nav .nav_right').show();
  215. }
  216. if($(window).width()<768){
  217. $('.page-content-bg').show();
  218. }
  219. $('.left-nav').find('a').removeClass('active');
  220. $(this).children('a').addClass('active');
  221. // <ul class="sub-menu" style="display: block;">
  222. if($(this).children('.sub-menu').length){
  223. if($(this).hasClass('open')){
  224. $(this).removeClass('open');
  225. $(this).find('.nav_right').html('&#xe697;');
  226. $(this).children('.sub-menu').stop(true,true).slideUp();
  227. $(this).siblings().children('.sub-menu').slideUp();
  228. }else{
  229. $(this).addClass('open');
  230. $(this).children('a').find('.nav_right').html('&#xe6a6;');
  231. $(this).children('.sub-menu').stop(true,true).slideDown();
  232. $(this).siblings().children('.sub-menu').stop(true,true).slideUp();
  233. $(this).siblings().find('.nav_right').html('&#xe697;');
  234. $(this).siblings().removeClass('open');
  235. }
  236. }
  237. event.stopPropagation();
  238. })
  239. var left_tips_index = null;
  240. $('.left-nav #nav').on('mouseenter', '.left-nav-li', function(event) {
  241. if($('.left-nav').css('width')!='220px'){
  242. var tips = $(this).attr('lay-tips');
  243. left_tips_index = layer.tips(tips, $(this));
  244. }
  245. })
  246. $('.left-nav #nav').on('mouseout', '.left-nav-li', function(event) {
  247. layer.close(left_tips_index);
  248. })
  249. // 隐藏左侧
  250. $('.container .left_open i').click(function(event) {
  251. if($('.left-nav').css('width')=='220px'){
  252. $('.left-nav .open').click();
  253. $('.left-nav i').css('font-size','18px');
  254. $('.left-nav').animate({width: '60px'}, 100);
  255. $('.left-nav cite,.left-nav .nav_right').hide();
  256. $('.page-content').animate({left: '60px'}, 100);
  257. $('.page-content-bg').hide();
  258. }else{
  259. $('.left-nav').animate({width: '220px'}, 100);
  260. $('.page-content').animate({left: '220px'}, 100);
  261. $('.left-nav i').css('font-size','14px');
  262. $('.left-nav cite,.left-nav .nav_right').show();
  263. if($(window).width()<768){
  264. $('.page-content-bg').show();
  265. }
  266. }
  267. });
  268. $('.page-content-bg').click(function(event) {
  269. $('.left-nav .open').click();
  270. $('.left-nav i').css('font-size','18px');
  271. $('.left-nav').animate({width: '60px'}, 100);
  272. $('.left-nav cite,.left-nav .nav_right').hide();
  273. $('.page-content').animate({left: '60px'}, 100);
  274. $(this).hide();
  275. });
  276. $(".layui-tab-title").on('contextmenu', 'li', function(event) {
  277. var tab_left = $(this).position().left;
  278. var tab_width = $(this).width();
  279. var left = $(this).position().top;
  280. var this_index = $(this).attr('lay-id');
  281. $('#tab_right').css({'left':tab_left+tab_width/2}).show().attr('lay-id',this_index);
  282. $('#tab_show').show();
  283. return false;
  284. });
  285. $('#tab_right').on('click', 'dd', function(event) {
  286. var data_type = $(this).attr('data-type');
  287. var lay_id = $(this).parents('#tab_right').attr('lay-id');
  288. if(data_type=='this'){
  289. $('.layui-tab-title li[lay-id='+lay_id+']').find('.layui-tab-close').click();
  290. }else if(data_type=='other'){
  291. $('.layui-tab-title li').eq(0).find('.layui-tab-close').remove();
  292. $('.layui-tab-title li[lay-id!='+lay_id+']').find('.layui-tab-close').click();
  293. }else if(data_type=='all'){
  294. $('.layui-tab-title li[lay-id]').find('.layui-tab-close').click();
  295. }
  296. $('#tab_right').hide();
  297. $('#tab_show').hide();
  298. })
  299. $('.page-content,#tab_show,.container,.left-nav').click(function(event) {
  300. $('#tab_right').hide();
  301. $('#tab_show').hide();
  302. });
  303. // 页面加载完要做的
  304. xadmin.end();
  305. })
  306. // md5-----------------------------------------------------------------------------------
  307. /*
  308. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  309. * to work around bugs in some JS interpreters.
  310. */
  311. function safeAdd (x, y) {
  312. var lsw = (x & 0xffff) + (y & 0xffff)
  313. var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
  314. return (msw << 16) | (lsw & 0xffff)
  315. }
  316. /*
  317. * Bitwise rotate a 32-bit number to the left.
  318. */
  319. function bitRotateLeft (num, cnt) {
  320. return (num << cnt) | (num >>> (32 - cnt))
  321. }
  322. /*
  323. * These functions implement the four basic operations the algorithm uses.
  324. */
  325. function md5cmn (q, a, b, x, s, t) {
  326. return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b)
  327. }
  328. function md5ff (a, b, c, d, x, s, t) {
  329. return md5cmn((b & c) | (~b & d), a, b, x, s, t)
  330. }
  331. function md5gg (a, b, c, d, x, s, t) {
  332. return md5cmn((b & d) | (c & ~d), a, b, x, s, t)
  333. }
  334. function md5hh (a, b, c, d, x, s, t) {
  335. return md5cmn(b ^ c ^ d, a, b, x, s, t)
  336. }
  337. function md5ii (a, b, c, d, x, s, t) {
  338. return md5cmn(c ^ (b | ~d), a, b, x, s, t)
  339. }
  340. /*
  341. * Calculate the MD5 of an array of little-endian words, and a bit length.
  342. */
  343. function binlMD5 (x, len) {
  344. /* append padding */
  345. x[len >> 5] |= 0x80 << (len % 32)
  346. x[((len + 64) >>> 9 << 4) + 14] = len
  347. var i
  348. var olda
  349. var oldb
  350. var oldc
  351. var oldd
  352. var a = 1732584193
  353. var b = -271733879
  354. var c = -1732584194
  355. var d = 271733878
  356. for (i = 0; i < x.length; i += 16) {
  357. olda = a
  358. oldb = b
  359. oldc = c
  360. oldd = d
  361. a = md5ff(a, b, c, d, x[i], 7, -680876936)
  362. d = md5ff(d, a, b, c, x[i + 1], 12, -389564586)
  363. c = md5ff(c, d, a, b, x[i + 2], 17, 606105819)
  364. b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330)
  365. a = md5ff(a, b, c, d, x[i + 4], 7, -176418897)
  366. d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426)
  367. c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341)
  368. b = md5ff(b, c, d, a, x[i + 7], 22, -45705983)
  369. a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416)
  370. d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417)
  371. c = md5ff(c, d, a, b, x[i + 10], 17, -42063)
  372. b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162)
  373. a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682)
  374. d = md5ff(d, a, b, c, x[i + 13], 12, -40341101)
  375. c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290)
  376. b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329)
  377. a = md5gg(a, b, c, d, x[i + 1], 5, -165796510)
  378. d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632)
  379. c = md5gg(c, d, a, b, x[i + 11], 14, 643717713)
  380. b = md5gg(b, c, d, a, x[i], 20, -373897302)
  381. a = md5gg(a, b, c, d, x[i + 5], 5, -701558691)
  382. d = md5gg(d, a, b, c, x[i + 10], 9, 38016083)
  383. c = md5gg(c, d, a, b, x[i + 15], 14, -660478335)
  384. b = md5gg(b, c, d, a, x[i + 4], 20, -405537848)
  385. a = md5gg(a, b, c, d, x[i + 9], 5, 568446438)
  386. d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690)
  387. c = md5gg(c, d, a, b, x[i + 3], 14, -187363961)
  388. b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501)
  389. a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467)
  390. d = md5gg(d, a, b, c, x[i + 2], 9, -51403784)
  391. c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473)
  392. b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734)
  393. a = md5hh(a, b, c, d, x[i + 5], 4, -378558)
  394. d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463)
  395. c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562)
  396. b = md5hh(b, c, d, a, x[i + 14], 23, -35309556)
  397. a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060)
  398. d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353)
  399. c = md5hh(c, d, a, b, x[i + 7], 16, -155497632)
  400. b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640)
  401. a = md5hh(a, b, c, d, x[i + 13], 4, 681279174)
  402. d = md5hh(d, a, b, c, x[i], 11, -358537222)
  403. c = md5hh(c, d, a, b, x[i + 3], 16, -722521979)
  404. b = md5hh(b, c, d, a, x[i + 6], 23, 76029189)
  405. a = md5hh(a, b, c, d, x[i + 9], 4, -640364487)
  406. d = md5hh(d, a, b, c, x[i + 12], 11, -421815835)
  407. c = md5hh(c, d, a, b, x[i + 15], 16, 530742520)
  408. b = md5hh(b, c, d, a, x[i + 2], 23, -995338651)
  409. a = md5ii(a, b, c, d, x[i], 6, -198630844)
  410. d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415)
  411. c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905)
  412. b = md5ii(b, c, d, a, x[i + 5], 21, -57434055)
  413. a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571)
  414. d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606)
  415. c = md5ii(c, d, a, b, x[i + 10], 15, -1051523)
  416. b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799)
  417. a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359)
  418. d = md5ii(d, a, b, c, x[i + 15], 10, -30611744)
  419. c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380)
  420. b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649)
  421. a = md5ii(a, b, c, d, x[i + 4], 6, -145523070)
  422. d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379)
  423. c = md5ii(c, d, a, b, x[i + 2], 15, 718787259)
  424. b = md5ii(b, c, d, a, x[i + 9], 21, -343485551)
  425. a = safeAdd(a, olda)
  426. b = safeAdd(b, oldb)
  427. c = safeAdd(c, oldc)
  428. d = safeAdd(d, oldd)
  429. }
  430. return [a, b, c, d]
  431. }
  432. /*
  433. * Convert an array of little-endian words to a string
  434. */
  435. function binl2rstr (input) {
  436. var i
  437. var output = ''
  438. var length32 = input.length * 32
  439. for (i = 0; i < length32; i += 8) {
  440. output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xff)
  441. }
  442. return output
  443. }
  444. /*
  445. * Convert a raw string to an array of little-endian words
  446. * Characters >255 have their high-byte silently ignored.
  447. */
  448. function rstr2binl (input) {
  449. var i
  450. var output = []
  451. output[(input.length >> 2) - 1] = undefined
  452. for (i = 0; i < output.length; i += 1) {
  453. output[i] = 0
  454. }
  455. var length8 = input.length * 8
  456. for (i = 0; i < length8; i += 8) {
  457. output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << (i % 32)
  458. }
  459. return output
  460. }
  461. /*
  462. * Calculate the MD5 of a raw string
  463. */
  464. function rstrMD5 (s) {
  465. return binl2rstr(binlMD5(rstr2binl(s), s.length * 8))
  466. }
  467. /*
  468. * Calculate the HMAC-MD5, of a key and some data (raw strings)
  469. */
  470. function rstrHMACMD5 (key, data) {
  471. var i
  472. var bkey = rstr2binl(key)
  473. var ipad = []
  474. var opad = []
  475. var hash
  476. ipad[15] = opad[15] = undefined
  477. if (bkey.length > 16) {
  478. bkey = binlMD5(bkey, key.length * 8)
  479. }
  480. for (i = 0; i < 16; i += 1) {
  481. ipad[i] = bkey[i] ^ 0x36363636
  482. opad[i] = bkey[i] ^ 0x5c5c5c5c
  483. }
  484. hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8)
  485. return binl2rstr(binlMD5(opad.concat(hash), 512 + 128))
  486. }
  487. /*
  488. * Convert a raw string to a hex string
  489. */
  490. function rstr2hex (input) {
  491. var hexTab = '0123456789abcdef'
  492. var output = ''
  493. var x
  494. var i
  495. for (i = 0; i < input.length; i += 1) {
  496. x = input.charCodeAt(i)
  497. output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f)
  498. }
  499. return output
  500. }
  501. /*
  502. * Encode a string as utf-8
  503. */
  504. function str2rstrUTF8 (input) {
  505. return unescape(encodeURIComponent(input))
  506. }
  507. /*
  508. * Take string arguments and return either raw or hex encoded strings
  509. */
  510. function rawMD5 (s) {
  511. return rstrMD5(str2rstrUTF8(s))
  512. }
  513. function hexMD5 (s) {
  514. return rstr2hex(rawMD5(s))
  515. }
  516. function rawHMACMD5 (k, d) {
  517. return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d))
  518. }
  519. function hexHMACMD5 (k, d) {
  520. return rstr2hex(rawHMACMD5(k, d))
  521. }
  522. function md5 (string, key, raw) {
  523. if (!key) {
  524. if (!raw) {
  525. return hexMD5(string)
  526. }
  527. return rawMD5(string)
  528. }
  529. if (!raw) {
  530. return hexHMACMD5(key, string)
  531. }
  532. return rawHMACMD5(key, string)
  533. }