require-frontend.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. require.config({
  2. urlArgs: "v=" + requirejs.s.contexts._.config.config.site.version,
  3. packages: [{
  4. name: 'moment',
  5. location: '../libs/moment',
  6. main: 'moment'
  7. }],
  8. //在打包压缩时将会把include中的模块合并到主文件中
  9. include: ['css', 'layer', 'toastr', 'frontend'],
  10. paths: {
  11. 'lang': "empty:",
  12. 'form': 'require-form',
  13. 'table': 'require-table',
  14. 'upload': 'require-upload',
  15. 'drag': 'jquery.drag.min',
  16. 'drop': 'jquery.drop.min',
  17. 'echarts': 'echarts.min',
  18. 'echarts-theme': 'echarts-theme',
  19. 'adminlte': 'adminlte',
  20. 'bootstrap-table-commonsearch': 'bootstrap-table-commonsearch',
  21. //
  22. // 以下的包从bower的libs目录加载
  23. 'jquery': '../libs/jquery/dist/jquery.min',
  24. 'bootstrap': '../libs/bootstrap/dist/js/bootstrap.min',
  25. 'bootstrap-validator': '../libs/bootstrap-validator/dist/validator.min',
  26. 'bootstrap-typeahead': '../libs/bootstrap3-typeahead/bootstrap3-typeahead.min',
  27. 'bootstrap-tagsinput': '../libs/bootstrap-tagsinput/dist/bootstrap-tagsinput.min',
  28. 'bootstrap-dialog': '../libs/bootstrap3-dialog/dist/js/bootstrap-dialog.min',
  29. 'bootstrap-datetimepicker': '../libs/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min',
  30. 'bootstrap-select': '../libs/bootstrap-select/dist/js/bootstrap-select.min',
  31. 'bootstrap-table': '../libs/bootstrap-table/dist/bootstrap-table.min',
  32. 'bootstrap-table-export': '../libs/bootstrap-table/dist/extensions/export/bootstrap-table-export.min',
  33. 'bootstrap-table-mobile': '../libs/bootstrap-table/dist/extensions/mobile/bootstrap-table-mobile',
  34. 'bootstrap-table-lang': '../libs/bootstrap-table/dist/locale/bootstrap-table-zh-CN',
  35. 'typeahead': '../libs/typeahead.js/dist/typeahead.jquery.min',
  36. 'bloodhound': '../libs/typeahead.js/dist/bloodhound.min',
  37. 'tableexport': '../libs/tableExport.jquery.plugin/tableExport.min',
  38. 'dropzone': '../libs/dropzone/dist/min/dropzone-amd-module.min',
  39. 'less': '../libs/less/dist/less.min',
  40. 'dragsort': '../libs/dragsort/jquery.dragsort',
  41. 'sortable': '../libs/Sortable/Sortable.min',
  42. 'addtabs': '../libs/jquery-addtabs/jquery.addtabs',
  43. 'slimscroll': '../libs/jquery-slimscroll/jquery.slimscroll',
  44. 'crontab': '../libs/jqcron/src/jqCron.cn',
  45. 'summernote': '../libs/summernote/dist/lang/summernote-zh-CN.min',
  46. 'validator': '../libs/nice-validator/dist/jquery.validator.js?local=zh-CN',
  47. 'plupload': '../libs/plupload/js/plupload.min',
  48. 'toastr': '../libs/toastr/toastr',
  49. 'jstree': '../libs/jstree/dist/jstree.min',
  50. 'layer': '../libs/layer/src/layer',
  51. 'cookie': '../libs/jquery.cookie/jquery.cookie',
  52. 'template': '../libs/art-template/dist/template-native',
  53. },
  54. // shim依赖配置
  55. shim: {
  56. 'bootstrap': ['jquery'],
  57. 'bootstrap-table': {
  58. deps: ['bootstrap', 'css!../libs/bootstrap-table/dist/bootstrap-table.min.css'],
  59. exports: '$.fn.bootstrapTable'
  60. },
  61. 'bootstrap-table-lang': {
  62. deps: ['bootstrap-table'],
  63. exports: '$.fn.bootstrapTable.defaults'
  64. },
  65. 'bootstrap-table-export': {
  66. deps: ['bootstrap-table', 'tableexport'],
  67. exports: '$.fn.bootstrapTable.defaults'
  68. },
  69. 'bootstrap-table-mobile': {
  70. deps: ['bootstrap-table'],
  71. exports: '$.fn.bootstrapTable.defaults'
  72. },
  73. 'bootstrap-table-advancedsearch': {
  74. deps: ['bootstrap-table'],
  75. exports: '$.fn.bootstrapTable.defaults'
  76. },
  77. 'bootstrap-table-commonsearch': {
  78. deps: ['bootstrap-table'],
  79. exports: '$.fn.bootstrapTable.defaults'
  80. },
  81. 'tableexport': {
  82. deps: ['jquery'],
  83. exports: '$.fn.extend'
  84. },
  85. 'slimscroll': {
  86. deps: ['jquery'],
  87. exports: '$.fn.extend'
  88. },
  89. 'adminlte': {
  90. deps: ['bootstrap', 'slimscroll'],
  91. exports: '$.AdminLTE'
  92. },
  93. 'typeahead': {
  94. deps: ['jquery'],
  95. init: function ($) {
  96. return require.s.contexts._.registry['typeahead.js'].factory($);
  97. }
  98. },
  99. 'crontab': ['../libs/jqcron/src/jqCron', 'css!../libs/jqcron/src/jqCron.css'],
  100. 'bootstrap-checkbox': ['jquery'],
  101. 'bootstrap-radio': ['jquery'],
  102. 'bootstrap-switch': ['jquery'],
  103. 'bootstrap-dialog': ['css!../libs/bootstrap3-dialog/dist/css/bootstrap-dialog.min.css'],
  104. 'bootstrap-datetimepicker': [
  105. 'css!../libs/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css',
  106. 'moment/locale/zh-cn',
  107. ],
  108. 'bootstrap-tagsinput': [
  109. 'css!../libs/bootstrap-tagsinput/dist/bootstrap-tagsinput-typeahead.css',
  110. 'css!../libs/bootstrap-tagsinput/dist/bootstrap-tagsinput.css',
  111. 'jquery',
  112. 'typeahead'
  113. ],
  114. 'bootstrap-select': ['css!../libs/bootstrap-select/dist/css/bootstrap-select.min.css', ],
  115. 'summernote': ['../libs/summernote/dist/summernote.min', 'css!../libs/summernote/dist/summernote.css'],
  116. // 'toastr': ['css!../libs/toastr/toastr.min.css'],
  117. 'jstree': ['css!../libs/jstree/dist/themes/default/style.css', ],
  118. 'plupload': {
  119. deps: [
  120. '../libs/plupload/js/moxie.min'
  121. ],
  122. exports: "plupload"
  123. },
  124. // 'layer': ['css!../libs/layer/build/skin/default/layer.css'],
  125. },
  126. baseUrl: requirejs.s.contexts._.config.config.site.cdnurl + '/assets/js/', //资源基础路径
  127. map: {
  128. '*': {
  129. 'css': '../libs/require-css/css.min'
  130. }
  131. },
  132. charset: 'utf-8' // 文件编码
  133. });
  134. require(['jquery', 'bootstrap'], function ($, undefined) {
  135. //初始配置
  136. var Config = requirejs.s.contexts._.config.config;
  137. //将Config渲染到全局
  138. window.Config = Config;
  139. // 配置语言包的路径
  140. var paths = {};
  141. paths['lang'] = Config.moduleurl + '/ajax/lang?callback=define&controllername=' + Config.controllername;
  142. // 避免目录冲突
  143. paths['frontend/'] = 'frontend/';
  144. require.config({paths: paths});
  145. // 初始化
  146. $(function () {
  147. require(['frontend'], function (Module) {
  148. // 对相对地址进行处理
  149. $.ajaxSetup({
  150. beforeSend: function (xhr, setting) {
  151. setting.url = Module.api.fixurl(setting.url);
  152. }
  153. });
  154. // 绑定ESC关闭窗口事件
  155. $(window).keyup(function (e) {
  156. if (e.keyCode == 27) {
  157. if ($(".layui-layer").size() > 0) {
  158. var index = 0;
  159. $(".layui-layer").each(function () {
  160. index = Math.max(index, parseInt($(this).attr("times")));
  161. });
  162. if (index) {
  163. Module.api.layer.close(index);
  164. }
  165. }
  166. }
  167. });
  168. //加载相应模块
  169. if (Config.jsname) {
  170. require([Config.jsname], function (Controller) {
  171. Controller[Config.actionname] != undefined && Controller[Config.actionname]();
  172. }, function (e) {
  173. // 这里可捕获模块加载的错误
  174. });
  175. }
  176. });
  177. });
  178. });