dcat-app.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*=========================================================================================
  2. File Name: app.js
  3. Description: Dcat Admin JS脚本.
  4. ----------------------------------------------------------------------------------------
  5. Item Name: Dcat Admin
  6. Author: Jqh
  7. Author URL: https://github.com/jqhph
  8. ==========================================================================================*/
  9. import Dcat from './Dcat'
  10. import NProgress from './nprogress/NProgress.min'
  11. import Helpers from './extensions/Helpers'
  12. import Ajax from './extensions/Ajax'
  13. import Toastr from './extensions/Toastr'
  14. import SweetAlert2 from './extensions/SweetAlert2'
  15. import RowSelector from './extensions/RowSelector'
  16. import Grid from './extensions/Grid'
  17. import Form from './extensions/Form'
  18. import DialogForm from './extensions/DialogForm'
  19. import Footer from './bootstrappers/Footer'
  20. import Pjax from './bootstrappers/Pjax'
  21. let win = window,
  22. $ = jQuery;
  23. // 扩展Dcat对象
  24. function extend (Dcat) {
  25. new Helpers(Dcat);
  26. new Ajax(Dcat);
  27. new Toastr(Dcat);
  28. new SweetAlert2(Dcat);
  29. new Grid(Dcat);
  30. // NProgress
  31. Dcat.NP = NProgress;
  32. // 行选择器
  33. Dcat.RowSelector = function (options) {
  34. return new RowSelector(options)
  35. };
  36. // ajax表单提交
  37. Dcat.Form = function (options) {
  38. return new Form(options)
  39. };
  40. // 弹窗表单
  41. Dcat.DialogForm = function (options) {
  42. return new DialogForm(Dcat, options);
  43. };
  44. }
  45. // 初始化
  46. function listen(Dcat) {
  47. Dcat.booting(function () {
  48. new Footer(Dcat);
  49. new Pjax(Dcat);
  50. // layer弹窗设置
  51. layer.config({maxmin: true, moveOut: true, shade: false});
  52. // ajax全局设置
  53. $.ajaxSetup({
  54. cache: true,
  55. error: Dcat.handleAjaxError
  56. });
  57. Dcat.NP.configure({parent: '.app-content'});
  58. });
  59. }
  60. // 开始初始化
  61. function boot(Dcat) {
  62. extend(Dcat);
  63. listen(Dcat);
  64. $(Dcat.boot);
  65. return Dcat;
  66. }
  67. win.CreateDcat = function(config) {
  68. return boot(new Dcat(config));
  69. };