BatchAction.php 761 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Dcat\Admin\Grid;
  3. abstract class BatchAction extends GridAction
  4. {
  5. /**
  6. * @var string
  7. */
  8. public $selectorPrefix = '.grid-batch-action-';
  9. /**
  10. * {@inheritdoc}
  11. */
  12. protected function actionScript()
  13. {
  14. $warning = __('No data selected!');
  15. return <<<JS
  16. function (data, target, action) {
  17. var key = {$this->getSelectedKeysScript()}
  18. if (key.length === 0) {
  19. Dcat.warning('{$warning}');
  20. return false;
  21. }
  22. // 设置主键为复选框选中的行ID数组
  23. action.options.key = key;
  24. }
  25. JS;
  26. }
  27. /**
  28. * @return string
  29. */
  30. public function getSelectedKeysScript()
  31. {
  32. return "Dcat.grid.selected('{$this->parent->getName()}');";
  33. }
  34. }