laravel-admin 使用中遇到的问题及临时性解决方案
2019-11-25 admin laravel 2168
1. 后台不能适应手机端
解决办法:在bootstrap.php加入:
Admin::style('html>body>div>header>nav>ul.navbar-nav {float:left;}');
2. 小屏幕分辨率下,或者表格列很多时,新的下拉action点击会使弹出的菜单移出屏幕
解决办法:编写一个自定义的Actions类集成官方的Actions类覆盖掉addScript方法:
namespace App\Admin\Actions; use Encore\Admin\Grid\Displayers\DropdownActions as DropdownActionsAdmin; class DropdownActions extends DropdownActionsAdmin { protected function addScript() { } }
修改config/admin.php
'grid_action_class'=> \App\Admin\Actions\DropdownActions::class
3. file 类型字段上传office文档时在编辑页面预览撕裂
解决办法:覆盖Form表单自动猜测的filetype,强制指定为object:
$form->file('office', 'office文档')->rules('mimes:doc,docx,xls,xlsx')->uniqueName()->options([ 'initialPreviewConfig' => [['type'=>'object']] ]);
4. 删除一行数据,无法获取该行id:
解决办法:修改/vendor/encore/laravel-admin/src/Grid/Actions/Delete.php
namespace Encore\Admin\Grid\Actions; use Encore\Admin\Actions\Response; use Encore\Admin\Actions\RowAction; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Schema; class Delete extends RowAction { /** * @return array|null|string */ public function name() { return __('admin.delete'); } /** * @param Model $model * * @return Response */ public function handle(Model $model) { $trans = [ 'failed' => trans('admin.delete_failed'), 'succeeded' => trans('admin.delete_succeeded'), ]; try { if (isset($model->bm)){ $bm = $model->bm;//查询项目的表名 Schema::dropIfExists($bm);//先删除项目表,再删除bgsx这行 } if (isset($model->cjdb)){ $cjdb = $model->cjdb;//成绩对比表 Schema::dropIfExists($cjdb);//先删除成绩对比表,再删除bgsx这行 } $model->delete(); } catch (\Exception $exception) { return $this->response()->error("{$trans['failed']} : {$exception->getMessage()}"); } return $this->response()->success($trans['succeeded'])->refresh(); } /** * @return void */ public function dialog() { $this->question(trans('admin.delete_confirm'), '', ['confirmButtonColor' => '#d33']); } }
5. 批量操作无法获取id问题
官网的方案:ids: selectedRows(),在1.7.2版本是无法获取id的,会报错:
Uncaught ReferenceError: selectedRows is not defined
解决办法:
selectedRow()换成$.admin.grid.selected()
data: { _token:LA.token, ids: $.admin.grid.selected().join(), action: {$this->action} },
持续更新……