app.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /** kit_admin-v1.0.4 MIT License By http://kit/zhengjinfan.cn */
  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', 'nprogress', 'form', 'table', 'loader', 'tab', 'navbar', 'onelevel'], 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. //navbar加载方式二,设置远程地址加载
  94. // navbar.set({
  95. // remote: {
  96. // url: '/datas/navbar1.json'
  97. // }
  98. // }).render(function(data) {
  99. // tab.tabAdd(data);
  100. // });
  101. //navbar加载方式三,设置data本地数据
  102. // navbar.set({
  103. // data: [{
  104. // id: "1",
  105. // title: "基本元素",
  106. // icon: "fa-cubes",
  107. // spread: true,
  108. // children: [{
  109. // id: "7",
  110. // title: "表格",
  111. // icon: "",
  112. // url: "test.html"
  113. // }, {
  114. // id: "8",
  115. // title: "表单",
  116. // icon: "",
  117. // url: "form.html"
  118. // }]
  119. // }, {
  120. // id: "5",
  121. // title: "这是一级导航",
  122. // icon: "fa-stop-circle",
  123. // url: "https://www.baidu.com",
  124. // spread: false
  125. // }]
  126. // }).render(function(data) {
  127. // tab.tabAdd(data);
  128. // });
  129. //处理顶部一级菜单
  130. var onelevel = layui.onelevel;
  131. if (onelevel.hasElem()) {
  132. onelevel.set({
  133. remote: {
  134. url: '/datas/onelevel1.json' //远程地址
  135. },
  136. onClicked: function(id) {
  137. switch (id) {
  138. case 1:
  139. navbar.set({
  140. remote: {
  141. url: '/datas/navbar1.json'
  142. }
  143. }).render(function(data) {
  144. tab.tabAdd(data);
  145. });
  146. break;
  147. case 2:
  148. navbar.set({
  149. remote: {
  150. url: '/datas/navbar2.json'
  151. }
  152. }).render(function(data) {
  153. tab.tabAdd(data);
  154. });
  155. break;
  156. default:
  157. navbar.set({
  158. data: [{
  159. id: "1",
  160. title: "基本元素",
  161. icon: "fa-cubes",
  162. spread: true,
  163. children: [{
  164. id: "7",
  165. title: "表格",
  166. icon: "",
  167. url: "test.html"
  168. }, {
  169. id: "8",
  170. title: "表单",
  171. icon: "",
  172. url: "form.html"
  173. }]
  174. }, {
  175. id: "5",
  176. title: "这是一级导航",
  177. icon: "fa-stop-circle",
  178. url: "https://www.baidu.com",
  179. spread: false
  180. }]
  181. }).render(function(data) {
  182. tab.tabAdd(data);
  183. });
  184. break;
  185. }
  186. }
  187. }).render();
  188. }
  189. }
  190. return that;
  191. }
  192. };
  193. //输出test接口
  194. exports('app', app);
  195. });