app.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /** iwb_admin-v1.1.0 MIT License By http://www.iwbnet.com e-mail:yueyy@iwbnet.com */
  2. ;/**
  3. * Name:app.js
  4. * Author:Van
  5. * E-mail:yueyy@iwbnet.com
  6. * Website:http://www.iwbnet.com
  7. * LICENSE:MIT
  8. */
  9. var tab;
  10. layui.define(['element', 'nprogress', 'form', 'table', 'loader', 'tab', 'navbar', 'onelevel', 'laytpl', 'spa'], function (exports) {
  11. var $ = layui.jquery,
  12. element = layui.element,
  13. layer = layui.layer,
  14. win = $(window),
  15. doc = $(document),
  16. body = $('.iwb-body'),
  17. form = layui.form,
  18. table = layui.table,
  19. loader = layui.loader,
  20. navbar = layui.navbar,
  21. componentPath = 'components/',
  22. spa = layui.spa,
  23. tab = layui.tab;
  24. var app = {
  25. hello: function (str) {
  26. layer.alert('Hello ' + (str || 'test'));
  27. },
  28. config: {
  29. type: 'iframe',
  30. navElem: undefined,
  31. tabElem:undefined
  32. },
  33. set: function (options) {
  34. var that = this;
  35. $.extend(true, that.config, options);
  36. return that;
  37. },
  38. init: function () {
  39. var that = this,
  40. config = that.config;
  41. if (config.type === 'spa') {
  42. navbar.bind(function (data) {
  43. spa.render(data.url, function () {
  44. console.log('渲染完成..');
  45. });
  46. });
  47. }
  48. if (config.type === 'page') {
  49. tab.set({
  50. renderType: 'page',
  51. mainUrl: '/Main/Home',
  52. elem: '#container',
  53. onSwitch: function (data) { //选项卡切换时触发
  54. //console.log(data.layId); //lay-id值
  55. //console.log(data.index); //得到当前Tab的所在下标
  56. //console.log(data.elem); //得到当前的Tab大容器
  57. },
  58. closeBefore: function (data) { //关闭选项卡之前触发
  59. // console.log(data);
  60. // console.log(data.icon); //显示的图标
  61. // console.log(data.id); //lay-id
  62. // console.log(data.title); //显示的标题
  63. // console.log(data.url); //跳转的地址
  64. return true; //返回true则关闭
  65. }
  66. }).render();
  67. //navbar加载方式一,直接绑定已有的dom元素事件
  68. navbar.bind(function (data) {
  69. tab.tabAdd(data);
  70. });
  71. }
  72. if (config.type === 'iframe') {
  73. tab.set({
  74. //renderType: 'iframe',
  75. //mainUrl: 'table.html',
  76. //openWait: false,
  77. elem: config.tabElem,
  78. onSwitch: function (data) { //选项卡切换时触发
  79. //console.log(data.layId); //lay-id值
  80. //console.log(data.index); //得到当前Tab的所在下标
  81. //console.log(data.elem); //得到当前的Tab大容器
  82. },
  83. closeBefore: function (data) { //关闭选项卡之前触发
  84. // console.log(data);
  85. // console.log(data.icon); //显示的图标
  86. // console.log(data.id); //lay-id
  87. // console.log(data.title); //显示的标题
  88. // console.log(data.url); //跳转的地址
  89. return true; //返回true则关闭
  90. }
  91. }).render();
  92. //navbar加载方式一,直接绑定已有的dom元素事件
  93. //navbar.bind(function (data) {
  94. // tab.tabAdd(data);
  95. //});
  96. //navbar加载方式二,设置远程地址加载
  97. navbar.set({
  98. remote: {
  99. url: '/Main/GetMenusTree/'
  100. },
  101. elem: config.navElem
  102. }).render(function(data) {
  103. tab.tabAdd(data);
  104. });
  105. //navbar加载方式三,设置data本地数据
  106. // navbar.set({
  107. // data: [{
  108. // id: "1",
  109. // title: "基本元素",
  110. // icon: "fa-cubes",
  111. // spread: true,
  112. // children: [{
  113. // id: "7",
  114. // title: "表格",
  115. // icon: "",
  116. // url: "test.html"
  117. // }, {
  118. // id: "8",
  119. // title: "表单",
  120. // icon: "",
  121. // url: "form.html"
  122. // }]
  123. // }, {
  124. // id: "5",
  125. // title: "这是一级导航",
  126. // icon: "fa-stop-circle",
  127. // url: "https://www.baidu.com",
  128. // spread: false
  129. // }]
  130. // }).render(function(data) {
  131. // tab.tabAdd(data);
  132. // });
  133. //处理顶部一级菜单
  134. //var onelevel = layui.onelevel;
  135. //if (onelevel.hasElem()) {
  136. // onelevel.set({
  137. // data:[{ "title":"2","id":1,"icon":"fa-user" }],
  138. // onClicked: function (id) {
  139. // switch (id) {
  140. // case 1:
  141. // navbar.set({
  142. // remote: {
  143. // url: '/Main/GetMenusTree/'
  144. // }
  145. // }).render(function (data) {
  146. // //tab.tabAdd(data);
  147. // });
  148. // break;
  149. // //case 2:
  150. // // navbar.set({
  151. // // remote: {
  152. // // url: '/datas/navbar2.json'
  153. // // }
  154. // // }).render(function (data) {
  155. // // tab.tabAdd(data);
  156. // // });
  157. // // break;
  158. // default:
  159. // navbar.set({
  160. // remote: {
  161. // url: '/Main/GetMenusTree/'
  162. // }
  163. // }).render(function (data) {
  164. // //tab.tabAdd(data);
  165. // });
  166. // break;
  167. // }
  168. // },
  169. // renderAfter: function (elem) {
  170. // elem.find('li').eq(0).click(); //模拟点击第一个
  171. // }
  172. // }).render();
  173. //}
  174. }
  175. // ripple start
  176. //var addRippleEffect = function (e) {
  177. // // console.log(e);
  178. // layui.stope(e)
  179. // var target = e.target;
  180. // if (target.localName !== 'button' && target.localName !== 'a') return false;
  181. // var rect = target.getBoundingClientRect();
  182. // var ripple = target.querySelector('.ripple');
  183. // if (!ripple) {
  184. // ripple = document.createElement('span');
  185. // ripple.className = 'ripple'
  186. // ripple.style.height = ripple.style.width = Math.max(rect.width, rect.height) + 'px'
  187. // target.appendChild(ripple);
  188. // }
  189. // ripple.classList.remove('show');
  190. // var top = e.pageY - rect.top - ripple.offsetHeight / 2 - document.body.scrollTop;
  191. // var left = e.pageX - rect.left - ripple.offsetWidth / 2 - document.body.scrollLeft;
  192. // ripple.style.top = top + 'px';
  193. // ripple.style.left = left + 'px';
  194. // ripple.classList.add('show');
  195. // return false;
  196. //}
  197. //document.addEventListener('click', addRippleEffect, false);
  198. //// ripple end
  199. return that;
  200. }
  201. };
  202. //输出test接口
  203. exports('app', app);
  204. });