index.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. }
  47. } else {
  48. var iframe = admin.tabsBody(admin.tabsPage.index).find('.layadmin-iframe');
  49. iframe[0].contentWindow.location.href = url;
  50. }
  51. //定位当前tabs
  52. element.tabChange(FILTER_TAB_TBAS, url);
  53. admin.tabsBodyChange(tabsPage.index, {
  54. url: url
  55. ,text: text
  56. });
  57. }
  58. ,APP_BODY = '#LAY_app_body', FILTER_TAB_TBAS = 'layadmin-layout-tabs'
  59. ,$ = layui.$, $win = $(window);
  60. //初始
  61. if(admin.screen() < 2) admin.sideFlexible();
  62. //将模块根路径设置为 controller 目录
  63. layui.config({
  64. base: setter.base + 'modules/'
  65. });
  66. //扩展 lib 目录下的其它模块
  67. layui.each(setter.extend, function(index, item){
  68. var mods = {};
  69. mods[item] = '{/}' + setter.base + 'lib/extend/' + item;
  70. layui.extend(mods);
  71. });
  72. view().autoRender();
  73. //加载公共模块
  74. layui.use('common');
  75. //对外输出
  76. exports('index', {
  77. openTabsPage: openTabsPage
  78. });
  79. });