Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rapyd转为Lego的手札 #63

Open
hellloveyy opened this issue Mar 29, 2017 · 2 comments
Open

rapyd转为Lego的手札 #63

hellloveyy opened this issue Mar 29, 2017 · 2 comments

Comments

@hellloveyy
Copy link
Contributor

hellloveyy commented Mar 29, 2017

$edit->success(function () {
    return redirect(action('Admin\Decoration\CategoryController@getSubCategoryList'));
});
success 可以直接接受 url 字符串 action(...)
->options(selectOpts(\Area::listCity()))
可替换为
$filter->addSelect(...)->values(City::list())
$grid->add('suite_decoration.suite', '公寓')->cell(function ($_, DecorationCostBill $bill) {
    return $bill->suite_decoration->suite ? \ModelTool::href($bill->suite_decoration->suite) : '';
});
可替换为
$grid->add('suite_decoration.suite|model-href', '公寓')
录入的时候,按录入顺序应该先录入城市,再录入项目名称,示例代码如下:
$city = $edit->addSelect(city_id, ..);
$edit->addText('name', '项目名称')
    ->validator(function ($name) use ($city) {
        $exists = Category::whereCityId($city->getNewValue())->whereName($name)->exists();
        return $exists ? '该项目名称已经存在' : null;
    })
$grid->add('lanjing_price_yuan', '蓝鲸单价', true);
lego不支持第三个排序的参数
$edit->addSelect('status', '状态')->options(selectOpts(Category::constants('status'), '选择状态'))->required();
addConstantsSelect() 后面 options 就可以省略了
设置只读
$edit->addText('type', '区域')->attr(['readonly'])->default($type);

$edit->addText(...)->attr('readonly', true);
设置number最小值
$edit->addNumber('sort', '排序')->rule('min:0');
->min(0)
lego页面里面的表单 name 需要通过 php 代码获取,后续lego扩展 name 会有改变的可能,不能写死。
var onlinePushReason = '{{ $edit->field("online_push_reason")->elementName() }}';
lego自动补全使用例子:
* 重复的自动补全建议按照:https://github.com/wutongwan/Laputa/pull/2975/files 新建一个trait来实现

$edit->addAutoComplete('block.name', '商圈')
    ->required()
    ->placeholder('支持自动补全')
    ->match(function ($keyword) {
        return  \Area::whereLevel(\Area::LEVEL_商圈)
            ->where('name', 'like', '%' . $keyword . '%')
            ->take(10) 
            ->pluck('name', 'id')
            ->toArray();
            });
            
  $edit->addAutoComplete('supplier.name', '供应商名称')
      ->match(function ($keyword) {
          return Supplier::where('status', Supplier::USEABLE_启用)
              ->where('name', 'like', "%{$keyword}%")
              ->take(20)
              ->get()
              ->keyBy('id')
              ->map(function (Supplier $item) {
                  return $item->name . '-' . $item->category->name . '-' . $item->subCategory->name . '-' . $item->city;
              })
              ->toArray();
      })
      ->required();
默认值
->insertValue($number)
->default($number)
多级联动
$form->addDependentSelect('bank_name', '银行名');
$form->addDependentSelect('bank_city', '银行所在城市')
    ->depend('bank_name', function ($bankName) {
        return Bank::whereBankName($bankName)->pluck('city', 'id');
    });
Grid (列表)中的批处理
$grid->addAction('分派')
    ->form(function (Form $form) {
            $form->addAutoComplete('执行人')->match(function ($keyword) {
                    return Corp::where('name', 'like', '%' . $keyword . '%')->pluck('name', 'id');
            });
    })
    ->action(function (Task $task, Form $form) {
        $task->executor_id = $form->field('执行人')->getNewValue();
        $task->save();
    })
lego重写From view
* Group 可以直接渲染
* https://github.com/wutongwan/laravel-lego/pull/61/files 相关pr
@zhwei
Copy link
Collaborator

zhwei commented Jun 23, 2017

再整理整理经验,提个 PR 添加到 docs

@hellloveyy
Copy link
Contributor Author

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants