DataActions.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. progressBar: function () {
  70. $('.progress-bar').each(function (k, v) {
  71. v = $(v);
  72. var w = v.data('width');
  73. if (w) {
  74. setTimeout(function () {
  75. v.css({width: w});
  76. }, 80);
  77. }
  78. });
  79. },
  80. // 图片预览
  81. imagePreview: function (Dcat) {
  82. $('[data-action="preview"]').off('click').click(function () {
  83. return Dcat.previewImage($(this).attr('src'));
  84. });
  85. },
  86. // 数字动画初始化
  87. counterUp: function() {
  88. var boot = function(k, obj) {
  89. try {
  90. obj = $(obj);
  91. obj.counterUp({
  92. delay: obj.attr('data-delay') || 100,
  93. time: obj.attr('data-time') || 1200
  94. });
  95. } catch (e) {}
  96. };
  97. $('[data-action="counterup"]').each(boot);
  98. $('number').each(boot);
  99. },
  100. popover: function () {
  101. $('.popover').remove();
  102. $('[data-action="popover"]').popover();
  103. },
  104. };
  105. export default class DataActions {
  106. constructor(Dcat) {
  107. for (let name in actions) {
  108. actions[name](Dcat)
  109. }
  110. }
  111. }