AppearanceImport.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Admin\Actions\Grid;
  3. use App\Admin\Forms\AppearanceImPortForm;
  4. use Dcat\Admin\Grid\RowAction;
  5. use Dcat\Admin\Widgets\Modal;
  6. use Illuminate\Http\Request;
  7. use App\Admin\Repositories\DistAppearance;
  8. use App\Admin\Repositories\DistAppearanceTemplate;
  9. class AppearanceImport extends RowAction
  10. {
  11. public $sourcePath;
  12. public $appearanceId;
  13. /**
  14. * 返回字段标题
  15. *
  16. * @return string
  17. */
  18. public function title()
  19. {
  20. return admin_trans_label('import_tmpl');
  21. }
  22. /**
  23. * 初始化操作
  24. */
  25. public function render()
  26. {
  27. $form = AppearanceImPortForm::make()->payload(['id' => $this->getKey()]);
  28. // 实例化表单类
  29. return Modal::make()
  30. ->lg()
  31. ->title($this->title)
  32. ->body($form)
  33. // 因为此处使用了表单异步加载功能,所以一定要用 onLoad 方法
  34. ->button($this->title());
  35. }
  36. public function confirm()
  37. {
  38. return [
  39. "Are you sure you want to import?",
  40. $this->row->title,
  41. ];
  42. }
  43. /*
  44. * 处理请求
  45. */
  46. /*
  47. public function handle(Request $request)
  48. {
  49. $appearanceId = $this->getKey();
  50. $folder = $request->get('folder');
  51. //导入模板
  52. $path = resource_path().'/appearance/'.$folder;
  53. if (!is_dir($path)) {
  54. return $this->response()->error("The directory does not exist")->refresh();
  55. }
  56. $this->sourcePath = $path;
  57. $this->appearanceId = $appearanceId;
  58. // 清空旧的
  59. DistAppearanceTemplate::deleteTemplates($appearanceId, config('dictionary.base_dist_id'));
  60. // 导入模板
  61. $this->readDirectory($path);
  62. // 更新状态
  63. DistAppearance::setStatusToImported($appearanceId);
  64. // 返回响应结果并刷新页面
  65. return $this->response()->success("Successfully imported")->refresh();
  66. }
  67. */
  68. /**
  69. * 设置要POST到接口的数据
  70. *
  71. * @return array
  72. */
  73. public function parameters()
  74. {
  75. return [
  76. // 发送当前行 username 字段数据到接口
  77. 'title' => $this->row->title,
  78. 'folder' => $this->row->folder
  79. ];
  80. }
  81. }