index.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. @Name:layuiAdmin iframe版主入口
  3. @Author:贤心
  4. @Site:http://www.layui.com/admin/
  5. @License:LPPL
  6. */
  7. layui.extend({
  8. setter: 'config' //配置模块
  9. ,admin: 'lib/admin' //核心模块
  10. ,view: 'lib/view' //视图渲染模块
  11. }).define(['setter', 'admin'], function(exports){
  12. var setter = layui.setter
  13. ,element = layui.element
  14. ,admin = layui.admin
  15. ,tabsPage = admin.tabsPage
  16. ,view = layui.view
  17. //打开标签页
  18. ,openTabsPage = function(url, text){
  19. //遍历页签选项卡
  20. var matchTo
  21. ,tabs = $('#LAY_app_tabsheader>li')
  22. ,path = url.replace(/(^http(s*):)|(\?[\s\S]*$)/g, '');
  23. tabs.each(function(index){
  24. var li = $(this)
  25. ,layid = li.attr('lay-id');
  26. if(layid === url){
  27. matchTo = true;
  28. tabsPage.index = index;
  29. }
  30. });
  31. text = text || '新标签页';
  32. if(setter.pageTabs){
  33. //如果未在选项卡中匹配到,则追加选项卡
  34. if(!matchTo){
  35. $(APP_BODY).append([
  36. '<div class="layadmin-tabsbody-item layui-show">'
  37. ,'<iframe src="'+ url +'" frameborder="0" class="layadmin-iframe"></iframe>'
  38. ,'</div>'
  39. ].join(''));
  40. tabsPage.index = tabs.length;
  41. element.tabAdd(FILTER_TAB_TBAS, {
  42. title: '<span>'+ text +'</span>'
  43. ,id: url
  44. ,attr: path
  45. });
  46. }else {
  47. var iframe = admin.tabsBody(admin.tabsPage.index).find('.layadmin-iframe');
  48. iframe[0].contentWindow.location.href = url;
  49. }
  50. } else {
  51. var iframe = admin.tabsBody(admin.tabsPage.index).find('.layadmin-iframe');
  52. iframe[0].contentWindow.location.href = url;
  53. }
  54. //定位当前tabs
  55. element.tabChange(FILTER_TAB_TBAS, url);
  56. admin.tabsBodyChange(tabsPage.index, {
  57. url: url
  58. ,text: text
  59. });
  60. }
  61. ,APP_BODY = '#LAY_app_body', FILTER_TAB_TBAS = 'layadmin-layout-tabs'
  62. ,$ = layui.$, $win = $(window);
  63. //初始
  64. if(admin.screen() < 2) admin.sideFlexible();
  65. //将模块根路径设置为 controller 目录
  66. layui.config({
  67. base: setter.base + 'modules/'
  68. });
  69. //扩展 lib 目录下的其它模块
  70. layui.each(setter.extend, function(index, item){
  71. var mods = {};
  72. mods[item] = '{/}' + setter.base + 'lib/extend/' + item;
  73. layui.extend(mods);
  74. });
  75. view().autoRender();
  76. //加载公共模块
  77. layui.use('common');
  78. //对外输出
  79. exports('index', {
  80. openTabsPage: openTabsPage
  81. });
  82. });