12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace App\Admin\Actions\Grid;
- use App\Admin\Forms\AppearanceImPortForm;
- use Dcat\Admin\Grid\RowAction;
- use Dcat\Admin\Widgets\Modal;
- use Illuminate\Http\Request;
- use App\Admin\Repositories\DistAppearance;
- use App\Admin\Repositories\DistAppearanceTemplate;
- class AppearanceImport extends RowAction
- {
- public $sourcePath;
- public $appearanceId;
- /**
- * 返回字段标题
- *
- * @return string
- */
- public function title()
- {
- return admin_trans_label('import_tmpl');
- }
- /**
- * 初始化操作
- */
- public function render()
- {
- $form = AppearanceImPortForm::make()->payload(['id' => $this->getKey()]);
- // 实例化表单类
- return Modal::make()
- ->lg()
- ->title($this->title)
- ->body($form)
- // 因为此处使用了表单异步加载功能,所以一定要用 onLoad 方法
- ->button($this->title());
- }
- public function confirm()
- {
- return [
- "Are you sure you want to import?",
- $this->row->title,
- ];
- }
- /*
- * 处理请求
- */
- /*
- public function handle(Request $request)
- {
- $appearanceId = $this->getKey();
- $folder = $request->get('folder');
- //导入模板
- $path = resource_path().'/appearance/'.$folder;
- if (!is_dir($path)) {
- return $this->response()->error("The directory does not exist")->refresh();
- }
- $this->sourcePath = $path;
- $this->appearanceId = $appearanceId;
- // 清空旧的
- DistAppearanceTemplate::deleteTemplates($appearanceId, config('dictionary.base_dist_id'));
- // 导入模板
- $this->readDirectory($path);
- // 更新状态
- DistAppearance::setStatusToImported($appearanceId);
- // 返回响应结果并刷新页面
- return $this->response()->success("Successfully imported")->refresh();
- }
- */
- /**
- * 设置要POST到接口的数据
- *
- * @return array
- */
- public function parameters()
- {
- return [
- // 发送当前行 username 字段数据到接口
- 'title' => $this->row->title,
- 'folder' => $this->row->folder
- ];
- }
- }
|