DataActions.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. let actions = {
  2. // 刷新按钮
  3. refreshAction: function (Dcat) {
  4. $('[data-action="refresh"]').off('click').click(function () {
  5. Dcat.reload($(this).data('url'));
  6. });
  7. },
  8. // 删除按钮初始化
  9. deleteAction: function (Dcat) {
  10. let lang = Dcat.lang;
  11. $('[data-action="delete"]').off('click').click(function() {
  12. let url = $(this).data('url'),
  13. redirect = $(this).data('redirect');
  14. Dcat.confirm(lang.delete_confirm, url, function () {
  15. Dcat.NP.start();
  16. $.ajax({
  17. method: 'post',
  18. url: url,
  19. data: {
  20. _method: 'delete',
  21. _token: Dcat.token,
  22. },
  23. success: function (data) {
  24. Dcat.NP.done();
  25. if (data.status) {
  26. Dcat.reload(redirect);
  27. Dcat.swal.success(data.message);
  28. } else {
  29. Dcat.swal.error(data.message);
  30. }
  31. }
  32. });
  33. });
  34. });
  35. },
  36. // 批量删除按钮初始化
  37. batchDeleteAction: function (Dcat) {
  38. $('[data-action="batch-delete"]').off('click').on('click', function() {
  39. let url = $(this).data('url'),
  40. name = $(this).data('name'),
  41. keys = Dcat.grid.selected(name),
  42. lang = Dcat.lang;
  43. if (! keys.length) {
  44. return;
  45. }
  46. Dcat.confirm(lang.delete_confirm, keys.join(', '), function () {
  47. Dcat.NP.start();
  48. $.ajax({
  49. method: 'post',
  50. url: url + '/' + keys.join(','),
  51. data: {
  52. _method: 'delete',
  53. _token: Dcat.token,
  54. },
  55. success: function (data) {
  56. Dcat.NP.done();
  57. if (data.status) {
  58. Dcat.reload();
  59. Dcat.swal.success(data.message);
  60. } else {
  61. Dcat.swal.error(data.message);
  62. }
  63. }
  64. });
  65. });
  66. });
  67. },
  68. // 图片预览
  69. imagePreview: function (Dcat) {
  70. $('[data-action="preview"]').off('click').click(function () {
  71. return Dcat.previewImage($(this).attr('src'));
  72. });
  73. },
  74. popover: function () {
  75. $('.popover').remove();
  76. $('[data-action="popover"]').popover();
  77. },
  78. // box-collapse
  79. boxActions: function () {
  80. $('.box [data-action="collapse"]').click(function (e) {
  81. e.preventDefault();
  82. $(this).find('i').toggleClass('icon-minus icon-plus');
  83. $(this).closest('.box').find('.box-body').first().collapse("toggle");
  84. });
  85. // Close box
  86. $('.box [data-action="remove"]').click(function () {
  87. $(this).closest(".box").removeClass().slideUp("fast");
  88. });
  89. }
  90. };
  91. export default class DataActions {
  92. constructor(Dcat) {
  93. for (let name in actions) {
  94. actions[name](Dcat)
  95. }
  96. }
  97. }