app.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /** kit_admin-v1.0.5 MIT License By http://kit/zhengjinfan.cn e-mail:zheng_jinfan@126.com */
  2. ;/**
  3. * Name:app.js
  4. * Author:Van
  5. * E-mail:zheng_jinfan@126.com
  6. * Website:http://kit.zhengjinfan.cn/
  7. * LICENSE:MIT
  8. */
  9. var tab;
  10. layui.define(['element', 'form', 'table', 'loader', 'tab', 'navbar'], function(exports) {
  11. var $ = layui.jquery,
  12. element = layui.element,
  13. layer = layui.layer,
  14. _win = $(window),
  15. _doc = $(document),
  16. _body = $('.kit-body'),
  17. form = layui.form,
  18. table = layui.table,
  19. loader = layui.loader,
  20. navbar = layui.navbar,
  21. _componentPath = 'components/';
  22. tab = layui.tab
  23. var app = {
  24. hello: function(str) {
  25. layer.alert('Hello ' + (str || 'test'));
  26. },
  27. config: {
  28. type: 'iframe'
  29. },
  30. set: function(options) {
  31. var that = this;
  32. $.extend(true, that.config, options);
  33. return that;
  34. },
  35. init: function() {
  36. var that = this,
  37. _config = that.config;
  38. if (_config.type === 'page') {
  39. $('a[kit-loader]').on('click', function() {
  40. var url = $(this).data('url'),
  41. name = $(this).data('name'),
  42. id = $(this).data('id');
  43. loader.load({
  44. url: url,
  45. name: name,
  46. id: id === undefined ? new Date().getTime() : id,
  47. onSuccess: success
  48. });
  49. function success(data) {
  50. switch (data.name) {
  51. case 'table':
  52. loader.getScript(_componentPath + 'table/table.js', function() {
  53. var tableIns = table.render(moduleTable.config);
  54. moduleTable.extend({
  55. currTable: tableIns,
  56. table: table,
  57. layer: layer,
  58. form: form,
  59. jquery: $
  60. });
  61. });
  62. break;
  63. case 'form':
  64. form.render();
  65. break;
  66. default:
  67. break;
  68. }
  69. };
  70. });
  71. }
  72. if (_config.type === 'iframe') {
  73. tab.set({
  74. elem: '#container',
  75. onSwitch: function(data) { //选项卡切换时触发
  76. //console.log(data.layId); //lay-id值
  77. //console.log(data.index); //得到当前Tab的所在下标
  78. //console.log(data.elem); //得到当前的Tab大容器
  79. },
  80. closeBefore: function(data) { //关闭选项卡之前触发
  81. // console.log(data);
  82. // console.log(data.icon); //显示的图标
  83. // console.log(data.id); //lay-id
  84. // console.log(data.title); //显示的标题
  85. // console.log(data.url); //跳转的地址
  86. return true; //返回true则关闭
  87. }
  88. }).render();
  89. //navbar加载方式一,直接绑定已有的dom元素事件
  90. navbar.bind(function(data) {
  91. tab.tabAdd(data);
  92. });
  93. }
  94. return that;
  95. }
  96. };
  97. //输出test接口
  98. exports('app', app);
  99. });