DataActions.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. // 数字动画初始化
  75. counterUp: function() {
  76. var boot = function(k, obj) {
  77. try {
  78. obj = $(obj);
  79. obj.counterUp({
  80. delay: obj.attr('data-delay') || 100,
  81. time: obj.attr('data-time') || 1200
  82. });
  83. } catch (e) {}
  84. };
  85. $('[data-action="counterup"]').each(boot);
  86. $('number').each(boot);
  87. },
  88. popover: function () {
  89. $('.popover').remove();
  90. $('[data-action="popover"]').popover();
  91. },
  92. };
  93. export default class DataActions {
  94. constructor(Dcat) {
  95. for (let name in actions) {
  96. actions[name](Dcat)
  97. }
  98. }
  99. }