H-ui.admin.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /* -----------H-ui前端框架-------------
  2. * H-ui.admin.js v3.1
  3. * http://www.h-ui.net/
  4. * Created & Modified by guojunhui
  5. * Date modified 2017.02.03
  6. * Copyright 2013-2017 北京颖杰联创科技有限公司 All rights reserved.
  7. * Licensed under MIT license.
  8. * http://opensource.org/licenses/MIT
  9. */
  10. var num=0,oUl=$("#min_title_list"),hide_nav=$("#Hui-tabNav");
  11. /*获取顶部选项卡总长度*/
  12. function tabNavallwidth(){
  13. var taballwidth=0,
  14. $tabNav = hide_nav.find(".acrossTab"),
  15. $tabNavWp = hide_nav.find(".Hui-tabNav-wp"),
  16. $tabNavitem = hide_nav.find(".acrossTab li"),
  17. $tabNavmore =hide_nav.find(".Hui-tabNav-more");
  18. if (!$tabNav[0]){return}
  19. $tabNavitem.each(function(index, element) {
  20. taballwidth += Number(parseFloat($(this).width()+60))
  21. });
  22. $tabNav.width(taballwidth+25);
  23. var w = $tabNavWp.width();
  24. if(taballwidth+25>w){
  25. $tabNavmore.show()}
  26. else{
  27. $tabNavmore.hide();
  28. $tabNav.css({left:0});
  29. }
  30. }
  31. /*左侧菜单响应式*/
  32. function Huiasidedisplay(){
  33. if($(window).width()>=768){
  34. $(".Hui-aside").show();
  35. }
  36. }
  37. /*获取皮肤cookie*/
  38. function getskincookie(){
  39. var v = $.cookie("Huiskin");
  40. var hrefStr=$("#skin").attr("href");
  41. if(v==null||v==""){
  42. v="default";
  43. }
  44. if(hrefStr!=undefined){
  45. var hrefRes=hrefStr.substring(0,hrefStr.lastIndexOf('skin/'))+'skin/'+v+'/skin.css';
  46. $("#skin").attr("href",hrefRes);
  47. }
  48. }
  49. /*菜单导航*/
  50. function Hui_admin_tab(obj){
  51. var bStop = false,
  52. bStopIndex = 0,
  53. href = $(obj).attr('data-href'),
  54. title = $(obj).attr("data-title"),
  55. topWindow = $(window.parent.document),
  56. show_navLi = topWindow.find("#min_title_list li"),
  57. iframe_box = topWindow.find("#iframe_box");
  58. //console.log(topWindow);
  59. if(!href||href==""){
  60. alert("data-href不存在,v2.5版本之前用_href属性,升级后请改为data-href属性");
  61. return false;
  62. }if(!title){
  63. alert("v2.5版本之后使用data-title属性");
  64. return false;
  65. }
  66. if(title==""){
  67. alert("data-title属性不能为空");
  68. return false;
  69. }
  70. show_navLi.each(function() {
  71. if($(this).find('span').attr("data-href")==href){
  72. bStop=true;
  73. bStopIndex=show_navLi.index($(this));
  74. return false;
  75. }
  76. });
  77. if(!bStop){
  78. creatIframe(href,title);
  79. min_titleList();
  80. }
  81. else{
  82. show_navLi.removeClass("active").eq(bStopIndex).addClass("active");
  83. iframe_box.find(".show_iframe").hide().eq(bStopIndex).show().find("iframe").attr("src",href);
  84. }
  85. }
  86. /*最新tab标题栏列表*/
  87. function min_titleList(){
  88. var topWindow = $(window.parent.document),
  89. show_nav = topWindow.find("#min_title_list"),
  90. aLi = show_nav.find("li");
  91. }
  92. /*创建iframe*/
  93. function creatIframe(href,titleName){
  94. var topWindow=$(window.parent.document),
  95. show_nav=topWindow.find('#min_title_list'),
  96. iframe_box=topWindow.find('#iframe_box'),
  97. iframeBox=iframe_box.find('.show_iframe'),
  98. $tabNav = topWindow.find(".acrossTab"),
  99. $tabNavWp = topWindow.find(".Hui-tabNav-wp"),
  100. $tabNavmore =topWindow.find(".Hui-tabNav-more");
  101. var taballwidth=0;
  102. show_nav.find('li').removeClass("active");
  103. show_nav.append('<li class="active"><span data-href="'+href+'">'+titleName+'</span><i></i><em></em></li>');
  104. if('function'==typeof $('#min_title_list li').contextMenu){
  105. $("#min_title_list li").contextMenu('Huiadminmenu', {
  106. bindings: {
  107. 'closethis': function(t) {
  108. var $t = $(t);
  109. if($t.find("i")){
  110. $t.find("i").trigger("click");
  111. }
  112. },
  113. 'closeall': function(t) {
  114. $("#min_title_list li i").trigger("click");
  115. },
  116. }
  117. });
  118. }else {
  119. }
  120. var $tabNavitem = topWindow.find(".acrossTab li");
  121. if (!$tabNav[0]){return}
  122. $tabNavitem.each(function(index, element) {
  123. taballwidth+=Number(parseFloat($(this).width()+60))
  124. });
  125. $tabNav.width(taballwidth+25);
  126. var w = $tabNavWp.width();
  127. if(taballwidth+25>w){
  128. $tabNavmore.show()}
  129. else{
  130. $tabNavmore.hide();
  131. $tabNav.css({left:0})
  132. }
  133. iframeBox.hide();
  134. iframe_box.append('<div class="show_iframe"><div class="loading"></div><iframe frameborder="0" src='+href+'></iframe></div>');
  135. var showBox=iframe_box.find('.show_iframe:visible');
  136. showBox.find('iframe').load(function(){
  137. showBox.find('.loading').hide();
  138. });
  139. }
  140. /*关闭iframe*/
  141. function removeIframe(){
  142. var topWindow = $(window.parent.document),
  143. iframe = topWindow.find('#iframe_box .show_iframe'),
  144. tab = topWindow.find(".acrossTab li"),
  145. showTab = topWindow.find(".acrossTab li.active"),
  146. showBox=topWindow.find('.show_iframe:visible'),
  147. i = showTab.index();
  148. tab.eq(i-1).addClass("active");
  149. tab.eq(i).remove();
  150. iframe.eq(i-1).show();
  151. iframe.eq(i).remove();
  152. }
  153. /*关闭所有iframe*/
  154. function removeIframeAll(){
  155. var topWindow = $(window.parent.document),
  156. iframe = topWindow.find('#iframe_box .show_iframe'),
  157. tab = topWindow.find(".acrossTab li");
  158. for(var i=0;i<tab.length;i++){
  159. if(tab.eq(i).find("i").length>0){
  160. tab.eq(i).remove();
  161. iframe.eq(i).remove();
  162. }
  163. }
  164. }
  165. /*弹出层*/
  166. /*
  167. 参数解释:
  168. title 标题
  169. url 请求的url
  170. id 需要操作的数据id
  171. w 弹出层宽度(缺省调默认值)
  172. h 弹出层高度(缺省调默认值)
  173. */
  174. function layer_show(title,url,w,h){
  175. if (title == null || title == '') {
  176. title=false;
  177. };
  178. if (url == null || url == '') {
  179. url="404.html";
  180. };
  181. if (w == null || w == '') {
  182. w=800;
  183. };
  184. if (h == null || h == '') {
  185. h=($(window).height() - 50);
  186. };
  187. layer.open({
  188. type: 2,
  189. area: [w+'px', h +'px'],
  190. fix: false, //不固定
  191. maxmin: true,
  192. shade:0.4,
  193. title: title,
  194. content: url
  195. });
  196. }
  197. /*关闭弹出框口*/
  198. function layer_close(){
  199. var index = parent.layer.getFrameIndex(window.name);
  200. parent.layer.close(index);
  201. }
  202. /*时间*/
  203. function getHTMLDate(obj) {
  204. var d = new Date();
  205. var weekday = new Array(7);
  206. var _mm = "";
  207. var _dd = "";
  208. var _ww = "";
  209. weekday[0] = "星期日";
  210. weekday[1] = "星期一";
  211. weekday[2] = "星期二";
  212. weekday[3] = "星期三";
  213. weekday[4] = "星期四";
  214. weekday[5] = "星期五";
  215. weekday[6] = "星期六";
  216. _yy = d.getFullYear();
  217. _mm = d.getMonth() + 1;
  218. _dd = d.getDate();
  219. _ww = weekday[d.getDay()];
  220. obj.html(_yy + "年" + _mm + "月" + _dd + "日 " + _ww);
  221. };
  222. $(function(){
  223. getHTMLDate($("#top_time"));
  224. getskincookie();
  225. //layer.config({extend: 'extend/layer.ext.js'});
  226. Huiasidedisplay();
  227. var resizeID;
  228. $(window).resize(function(){
  229. clearTimeout(resizeID);
  230. resizeID = setTimeout(function(){
  231. Huiasidedisplay();
  232. },500);
  233. });
  234. $(".nav-toggle").click(function(){
  235. $(".Hui-aside").slideToggle();
  236. });
  237. $(".Hui-aside").on("click",".menu_dropdown dd li a",function(){
  238. if($(window).width()<768){
  239. $(".Hui-aside").slideToggle();
  240. }
  241. });
  242. /*左侧菜单*/
  243. $(".Hui-aside").Huifold({
  244. titCell:'.menu_dropdown dl dt',
  245. mainCell:'.menu_dropdown dl dd',
  246. });
  247. /*选项卡导航*/
  248. $(".Hui-aside").on("click",".menu_dropdown a",function(){
  249. Hui_admin_tab(this);
  250. });
  251. $(document).on("click","#min_title_list li",function(){
  252. var bStopIndex=$(this).index();
  253. var iframe_box=$("#iframe_box");
  254. $("#min_title_list li").removeClass("active").eq(bStopIndex).addClass("active");
  255. iframe_box.find(".show_iframe").hide().eq(bStopIndex).show();
  256. });
  257. $(document).on("click","#min_title_list li i",function(){
  258. var aCloseIndex=$(this).parents("li").index();
  259. $(this).parent().remove();
  260. $('#iframe_box').find('.show_iframe').eq(aCloseIndex).remove();
  261. num==0?num=0:num--;
  262. tabNavallwidth();
  263. });
  264. $(document).on("dblclick","#min_title_list li",function(){
  265. var aCloseIndex=$(this).index();
  266. var iframe_box=$("#iframe_box");
  267. if(aCloseIndex>0){
  268. $(this).remove();
  269. $('#iframe_box').find('.show_iframe').eq(aCloseIndex).remove();
  270. num==0?num=0:num--;
  271. $("#min_title_list li").removeClass("active").eq(aCloseIndex-1).addClass("active");
  272. iframe_box.find(".show_iframe").hide().eq(aCloseIndex-1).show();
  273. tabNavallwidth();
  274. }else{
  275. return false;
  276. }
  277. });
  278. tabNavallwidth();
  279. $('#js-tabNav-next').click(function(){
  280. num==oUl.find('li').length-1?num=oUl.find('li').length-1:num++;
  281. toNavPos();
  282. });
  283. $('#js-tabNav-prev').click(function(){
  284. num==0?num=0:num--;
  285. toNavPos();
  286. });
  287. function toNavPos(){
  288. oUl.stop().animate({'left':-num*100},100);
  289. }
  290. /*换肤*/
  291. $("#Hui-skin .dropDown-menu a").click(function(){
  292. var v = $(this).attr("data-val");
  293. $.cookie("Huiskin", v);
  294. var hrefStr=$("#skin").attr("href");
  295. var hrefRes=hrefStr.substring(0,hrefStr.lastIndexOf('skin/'))+'skin/'+v+'/skin.css';
  296. $(window.frames.document).contents().find("#skin").attr("href",hrefRes);
  297. });
  298. });