DataActions.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. id = $(this).data('id');
  15. Dcat.confirm(lang.delete_confirm, url, function () {
  16. Dcat.NP.start();
  17. $.ajax({
  18. method: 'post',
  19. url: url,
  20. data: {
  21. _method: 'delete',
  22. _token: Dcat.token,
  23. },
  24. success: function (data) {
  25. Dcat.NP.done();
  26. if (data.status) {
  27. Dcat.reload(redirect);
  28. Dcat.swal.success(data.message);
  29. } else {
  30. Dcat.swal.error(data.message);
  31. }
  32. }
  33. });
  34. });
  35. });
  36. },
  37. // 批量删除按钮初始化
  38. batchDeleteAction: function (Dcat) {
  39. $('[data-action="batch-delete"]').off('click').on('click', function() {
  40. let url = $(this).data('url'),
  41. name = $(this).data('name'),
  42. keys = Dcat.grid.selected(name),
  43. lang = Dcat.lang;
  44. if (! keys.length) {
  45. return;
  46. }
  47. Dcat.confirm(lang.delete_confirm, keys.join(', '), function () {
  48. Dcat.NP.start();
  49. $.ajax({
  50. method: 'post',
  51. url: url + '/' + keys.join(','),
  52. data: {
  53. _method: 'delete',
  54. _token: Dcat.token,
  55. },
  56. success: function (data) {
  57. Dcat.NP.done();
  58. if (data.status) {
  59. Dcat.reload();
  60. Dcat.swal.success(data.message);
  61. } else {
  62. Dcat.swal.error(data.message);
  63. }
  64. }
  65. });
  66. });
  67. });
  68. },
  69. // 进度条初始化
  70. progressBar: function () {
  71. $('.progress-bar').each(function (k, v) {
  72. v = $(v);
  73. var w = v.data('width');
  74. if (w) {
  75. setTimeout(function () {
  76. v.css({width: w});
  77. }, 80);
  78. }
  79. });
  80. },
  81. // 图片预览
  82. imagePreview: function (Dcat) {
  83. $('[data-action="preview"]').off('click').click(function () {
  84. return Dcat.previewImage($(this).attr('src'));
  85. });
  86. },
  87. // 数字动画初始化
  88. counterUp: function() {
  89. var boot = function(k, obj) {
  90. try {
  91. obj = $(obj);
  92. obj.counterUp({
  93. delay: obj.attr('data-delay') || 100,
  94. time: obj.attr('data-time') || 1200
  95. });
  96. } catch (e) {}
  97. };
  98. $('[data-action="counterup"]').each(boot);
  99. $('number').each(boot);
  100. },
  101. popover: function () {
  102. $('.popover').remove();
  103. $('[data-action="popover"]').popover();
  104. },
  105. };
  106. export default class DataActions {
  107. constructor(Dcat) {
  108. for (let name in actions) {
  109. actions[name](Dcat)
  110. }
  111. }
  112. }