RowAction.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Dcat\Admin\Tree;
  3. use Dcat\Admin\Actions\Action;
  4. class RowAction extends Action
  5. {
  6. /**
  7. * @var \Dcat\Admin\Tree\Actions;
  8. */
  9. protected $actions;
  10. /**
  11. * @var \Illuminate\Database\Eloquent\Model
  12. */
  13. protected $row;
  14. public $selectorPrefix = '.tree-row-action-';
  15. /**
  16. * 获取主键值.
  17. *
  18. * @return array|mixed|string
  19. */
  20. public function getKey()
  21. {
  22. if ($key = parent::getKey()) {
  23. return $key;
  24. }
  25. return $this->row->{$this->actions->parent()->getKeyName()};
  26. }
  27. /**
  28. * 获取行数据.
  29. *
  30. * @return \Illuminate\Database\Eloquent\Model
  31. */
  32. public function getRow()
  33. {
  34. return $this->row;
  35. }
  36. /**
  37. * 获取资源路径.
  38. *
  39. * @return string
  40. */
  41. public function resource()
  42. {
  43. return $this->actions->parent()->resource();
  44. }
  45. public function getActions()
  46. {
  47. return $this->actions;
  48. }
  49. public function setParent(Actions $actions)
  50. {
  51. $this->actions = $actions;
  52. }
  53. public function setRow($row)
  54. {
  55. $this->row = $row;
  56. }
  57. /**
  58. * 生成选择器键名.
  59. * 需要保证每个行操作的选择器都不同.
  60. *
  61. * @param string $prefix
  62. * @param string $class
  63. *
  64. * @return string
  65. */
  66. public function getSelectorKey($prefix, $class = null)
  67. {
  68. return parent::getSelectorKey($prefix, $class).$this->getKey();
  69. }
  70. }