admin.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. //导航收缩展开
  2. bind_event($(".canvas-nav-item>a"), function () {
  3. if (!$('.canvas-nav-item').hasClass('canvas-nav-small')) {
  4. if ($(this).next().css('display') == "none") {
  5. //展开未展开
  6. $('.canvas-nav-item').children('ul').slideUp(300);
  7. $(this).next('ul').slideDown(300);
  8. $(this).parent('li').addClass('canvas-nav-show').siblings('li').removeClass('canvas-nav-show');
  9. } else {
  10. //收缩已展开
  11. $(this).next('ul').slideUp(300);
  12. $('.canvas-nav-item.canvas-nav-show').removeClass('canvas-nav-show');
  13. }
  14. }
  15. });
  16. // 收放导航列表
  17. bind_event($(".switch-list"), function () {
  18. //收缩按钮切换
  19. if ($(this).children("i").hasClass("layui-icon layui-icon-shrink-right")) {
  20. $(this).children("i").removeClass("layui-icon layui-icon-shrink-right");
  21. $(this).children("i").addClass("layui-icon layui-icon-spread-left");
  22. } else {
  23. $(this).children("i").removeClass("layui-icon layui-icon-spread-left");
  24. $(this).children("i").addClass("layui-icon layui-icon-shrink-right");
  25. }
  26. /*canvas-nav-small切换*/
  27. if ($('.layout-body').hasClass('canvas-nav-small')) {
  28. $('.layout-body').removeClass('canvas-nav-small');
  29. } else {
  30. $('.canvas-nav-item').removeClass('canvas-nav-show');
  31. $('.canvas-nav-item').children('ul').removeAttr('style');
  32. $('.layout-body').addClass('canvas-nav-small');
  33. }
  34. });
  35. //全屏
  36. function fullScreen(id) {
  37. var el = document.documentElement;
  38. var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullscreen;
  39. if (typeof rfs != "undefined" && rfs) {
  40. rfs.call(el);
  41. } else {
  42. msg("浏览器不支持全屏调用,请使用其他浏览器或按F11键切换全屏!");
  43. return;
  44. }
  45. $("#" + id).attr("onclick", "exitScreen('" + id + "')");
  46. $("#" + id).attr("onmouseenter", "getTips(this, '退出全屏')");
  47. $("#" + id).find("i").attr("class", "fa fa-arrows");
  48. }
  49. //退出全屏
  50. function exitScreen(id) {
  51. if (document.exitFullscreen) {
  52. document.exitFullscreen();
  53. } else if (document.mozCancelFullScreen) {
  54. document.mozCancelFullScreen();
  55. } else if (document.webkitCancelFullScreen) {
  56. document.webkitCancelFullScreen();
  57. } else if (document.msExitFullscreen) {
  58. document.msExitFullscreen();
  59. }
  60. if (typeof cfs != "undefined" && cfs) {
  61. cfs.call(el);
  62. }
  63. $("#" + id).find("i").attr("class", "fa fa-arrows-alt");
  64. $("#" + id).attr("onclick", "fullScreen('" + id + "')");
  65. $("#" + id).attr("onmouseenter", "getTips(this, '全屏')");
  66. }
  67. //判断是否IE浏览器
  68. function IEVersion() {
  69. var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
  70. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
  71. var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
  72. var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
  73. if(isIE) {
  74. var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
  75. reIE.test(userAgent);
  76. var fIEVersion = parseFloat(RegExp["$1"]);
  77. if(fIEVersion == 7) {
  78. return 7;
  79. } else if(fIEVersion == 8) {
  80. return 8;
  81. } else if(fIEVersion == 9) {
  82. return 9;
  83. } else if(fIEVersion == 10) {
  84. return 10;
  85. } else {
  86. return 6;//IE版本<=7
  87. }
  88. } else if(isEdge) {
  89. return 'edge';//edge
  90. } else if(isIE11) {
  91. return 11; //IE11
  92. }else{
  93. return -1;//不是ie浏览器
  94. }
  95. }
  96. $(function () {
  97. $('.tabs').on('click', function (event) {
  98. event.preventDefault();
  99. var $this = $(this), url = $this.attr('href'),
  100. title = $.trim($this.text());
  101. var id= $this.attr('id');
  102. var icons = $this.attr('icons');
  103. if (url && url !== 'javascript:;') {
  104. addtabs(id,title,icons,url,true);
  105. }
  106. });
  107. var currentTabMenuId = 'tabs-menu-0';
  108. var currentTabContentId = 'tabs-content-0';
  109. var pageCounter = 0;
  110. /**
  111. * id: tab页签的html标签ID属性格式为"tab-"+id,内容容器的html标签ID格式为"tab-content-"+id
  112. * title: tab页签的显示文本
  113. * url: 打开的iframe的url
  114. * innerTab: 是否是内部弹出页(打开的tab页触发添加新的tab页),默认为undefined/false
  115. */
  116. function addtabs(id,title,icons,url,innerTab) {
  117. //如果某个页面已经打开,则切换到该页显示即可,不会新添加tab页
  118. if ($('#tabs-menu-' + id).length > 0) {
  119. currentTabMenuId = "tabs-menu-"+id;
  120. $('#tabs-menu-' + id).addClass('active').siblings().removeClass('active');
  121. // 标签对应的内容容器切换
  122. currentTabContentId = "tabs-content-"+id;
  123. $(".canvas-tabs-content > div").eq($('#tabs-content-' + id).index()).addClass('active').siblings().removeClass('active');
  124. } else {
  125. var tab_id = "tabs-menu-" + id,
  126. tab_content_id = "tabs-content-" + id;
  127. currentTabMenuId = tab_id;
  128. //添加tab页签
  129. $(".canvas-tabs-menu > li").removeClass("active");
  130. $(".canvas-tabs-menu").append("<li id='" + tab_id + "' class='active'><div class='hover-box'></div><i class=''></i>" + title + "<i class='layui-icon layui-icon-close icon-close-padd'></i></li>");
  131. //添加新的内容显示
  132. currentTabContentId = tab_content_id;
  133. $(".canvas-tabs-content > div").removeClass("active");
  134. $(".canvas-tabs-content").append("<div id='" + tab_content_id + "' class='active'>"
  135. + "<iframe id='iframepage" + (pageCounter++) + "' name='iframepage" + (pageCounter++)
  136. + "' width='100%' frameborder='0' scrolling='yes' src='" + url + "' class='x-iframe'></iframe></div>");
  137. }
  138. }
  139. //切换tab页的显示
  140. $(document).on('click', '.canvas-tabs-menu > li', function (e) {
  141. //清除原来显示的tab页,设置新的显示tab页
  142. var _this = $(this)
  143. currentTabMenuId = _this.attr("id");
  144. _this.addClass('active').siblings(_this).removeClass('active');
  145. // 标签对应的内容容器切换
  146. var t_id=currentTabMenuId.substr(currentTabMenuId.length-1,1);
  147. currentTabContentId = "tabs-content-"+t_id;
  148. $(".canvas-tabs-content > div").eq(_this.index()).addClass('active').siblings().removeClass('active');
  149. })
  150. //删除目标tab页的显示
  151. $(document).on('click', '.canvas-tabs-menu .icon-close-padd', function (e) {
  152. e.stopPropagation();
  153. //获取tabs列表
  154. var u_l = $(".canvas-tabs-menu > li");
  155. //删除目标tab页
  156. var _this = $(this);
  157. //获取当前tabs索引
  158. var num = _this.parent().index();
  159. //获取当前tabs id
  160. var id = _this.parent().attr('id');
  161. //删除当前tabs
  162. $("#"+id).remove();
  163. // 删除目标内容容器
  164. var t_id=id.substr(id.length-1,1);
  165. $("#tabs-content-"+t_id).remove();
  166. var u_t=u_l.eq(num-1).attr('id');
  167. var flag = $("#"+u_t).hasClass("active");
  168. if(flag){
  169. }else{
  170. currentTabMenuId = u_t;
  171. $("#"+u_t).addClass("active").siblings($("#"+u_t)).removeClass('active');
  172. var t_c_id=u_t.substr(u_t.length-1,1);
  173. currentTabContentId = "tabs-content-"+t_c_id;
  174. $("#tabs-content-"+t_c_id).addClass("active").siblings($("#tabs-content-"+t_c_id)).removeClass('active');
  175. }
  176. })
  177. //删除当前页
  178. $(document).on('click', '.closeNowPage', function (e) {
  179. e.stopPropagation();
  180. if(!(currentTabMenuId === 'tabs-menu-0')){
  181. //获取tabs列表
  182. var u_l = $(".canvas-tabs-menu > li");
  183. //获取当前tabs索引
  184. var num = $("#"+currentTabMenuId).index();
  185. //删除当前tabs
  186. $("#"+currentTabMenuId).remove();
  187. // 删除目标内容容器
  188. var t_id=currentTabMenuId.substr(currentTabMenuId.length-1,1);
  189. $("#tabs-content-"+t_id).remove();
  190. var u_t=u_l.eq(num-1).attr('id');
  191. var flag = $("#"+u_t).hasClass("active");
  192. if(!flag){
  193. currentTabMenuId = u_t;
  194. $("#"+u_t).addClass("active").siblings($("#"+u_t)).removeClass('active');
  195. var t_c_id=u_t.substr(u_t.length-1,1);
  196. currentTabContentId = "tabs-content-"+t_c_id;
  197. $("#tabs-content-"+t_c_id).addClass("active").siblings($("#tabs-content-"+t_c_id)).removeClass('active');
  198. }
  199. }
  200. })
  201. //删除其它页
  202. $(document).on('click', '.closeOtherPage', function (e) {
  203. e.stopPropagation();
  204. if(currentTabMenuId === 'tabs-menu-0'){
  205. //删除其它tabs
  206. $("#tabs-menu-0").siblings($("#tabs-menu-0")).remove();
  207. $("#tabs-content-0").siblings($("#tabs-content-0")).remove();
  208. currentTabMenuId = "tabs-menu-0";
  209. $("#tabs-menu-0").addClass("active")
  210. currentTabContentId = "tabs-content-0";
  211. $("#tabs-content-0").addClass("active")
  212. }else{
  213. $("#"+currentTabMenuId).nextAll().remove();
  214. $("#"+currentTabMenuId).prevUntil($("#tabs-menu-0")).remove();
  215. $("#"+currentTabContentId).nextAll().remove();
  216. $("#"+currentTabContentId).prevUntil($("#tabs-content-0")).remove();
  217. }
  218. })
  219. //删除所有页
  220. $(document).on('click', '.closeAllPage', function (e) {
  221. e.stopPropagation();
  222. //删除其它tabs
  223. $("#tabs-menu-0").siblings($("#tabs-menu-0")).remove();
  224. $("#tabs-content-0").siblings($("#tabs-content-0")).remove();
  225. currentTabMenuId = "tabs-menu-0";
  226. $("#tabs-menu-0").addClass("active")
  227. currentTabContentId = "tabs-content-0";
  228. $("#tabs-content-0").addClass("active")
  229. })
  230. // 呼出右侧列表
  231. $(document).on('click', '.dashboard,.user-info', function (e) {
  232. var bar = $(this).attr("tag");
  233. if($(".right-bar").hasClass(bar)){
  234. remove_node($(".right-bar").find($(".tpl-shade")));
  235. if ($("."+bar).css("right") == "-1500px"){
  236. $(".right-bar").css("right","-1500px");
  237. $("."+bar).css("right",0);
  238. $(".tpl-body").css("overflow","hidden");
  239. } else {
  240. $("."+bar).css("right","-1500px");
  241. $(".tpl-body").css("overflow","auto");
  242. }
  243. // shade($("."+bar).find(".right-bar-fluid"),true);
  244. stopPropagation(e);
  245. }else{
  246. msg("配置的tag目标为空");
  247. }
  248. })
  249. $(document).on('click', '.right-bar', function (e) {
  250. stopPropagation(e);
  251. })
  252. // 页面的点击冒泡
  253. $(document).on('click', '.right-bar', function (e) {
  254. $(".right-bar").css("right","-1500px");
  255. })
  256. bind_event($(document),function(){
  257. $(".right-bar").css("right","-1500px");
  258. })
  259. // 点击更换页面主题
  260. bind_event($("#style-list"),function(e){
  261. var style = $(this).attr("theme-style");
  262. var styleName = $(".theme-style").attr("style-name");
  263. $(".theme-style").removeClass(styleName);
  264. $(".theme-style").attr("style-name",style);
  265. $(".theme-style").addClass(style);
  266. /*$.ajax({ //使用服务器端session保存操作
  267. url:"../index/view",
  268. type:"post",
  269. datatype:"json",
  270. data:{
  271. stylename:style // 传递到后台,用session保存即可
  272. },
  273. success:function(data){
  274. l(data);
  275. }
  276. });*/
  277. stopPropagation(e);
  278. },"click","li");
  279. });
  280. layui.define(['layer', 'jquery', 'form', 'carousel', 'element', 'upload'], function (exports) {
  281. var $ = layui.$, $body = $('body');
  282. //弹出层组件
  283. var layer = layui.layer;
  284. //表单组件
  285. var form = layui.form;
  286. var element = layui.element;
  287. //轮播组件
  288. var carousel = layui.carousel;
  289. // 文件上传组件
  290. var upload = layui.upload;
  291. });