|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
|
|
use App\Admin\Repositories\DistAdminDistributor;
|
|
|
+use App\Admin\Repositories\DistAppearance;
|
|
|
use Dcat\Admin\Form;
|
|
|
use Dcat\Admin\Grid;
|
|
|
use Dcat\Admin\Show;
|
|
@@ -31,7 +32,7 @@ class DistAdminDistributorController extends AdminController
|
|
|
*/
|
|
|
protected function grid()
|
|
|
{
|
|
|
- return Grid::make(new DistAdminDistributor(), function (Grid $grid) {
|
|
|
+ return Grid::make(DistAdminDistributor::with(['appearance']), function (Grid $grid) {
|
|
|
$grid->column('id')->sortable();
|
|
|
$grid->column('company_name','Company Name');
|
|
|
$grid->column('site_name');
|
|
@@ -39,6 +40,7 @@ class DistAdminDistributorController extends AdminController
|
|
|
$grid->column('country');
|
|
|
$grid->column('contact_number');
|
|
|
$grid->column('service_hotline');
|
|
|
+ $grid->column('appearance.title' ,'appearance');
|
|
|
$grid->column('enabled')->switch();
|
|
|
$grid->column('created_at');
|
|
|
$grid->column('updated_at')->sortable();
|
|
@@ -71,12 +73,13 @@ class DistAdminDistributorController extends AdminController
|
|
|
*/
|
|
|
protected function detail($id)
|
|
|
{
|
|
|
- return Show::make($id, new DistAdminDistributor(), function (Show $show) {
|
|
|
+ return Show::make($id, DistAdminDistributor::with(['appearance']), function (Show $show) {
|
|
|
$show->field('id');
|
|
|
$show->field('company_name','Company Name');
|
|
|
$show->field('company_address','Company Address');
|
|
|
$show->field('site_name');
|
|
|
$show->field('level_domain');
|
|
|
+ $show->field('appearance.title' ,'appearance');
|
|
|
$show->field('country');
|
|
|
$show->field('contact_number');
|
|
|
$show->field('service_hotline');
|
|
@@ -87,7 +90,7 @@ class DistAdminDistributorController extends AdminController
|
|
|
$show->field('linkedin');
|
|
|
$show->field('tiktok');
|
|
|
$show->field('remark');
|
|
|
- $show->width(6)->field('enabled')->using(config('dictionary.enabled'));
|
|
|
+ $show->field('enabled')->using(config('dictionary.enabled'));
|
|
|
$show->field('created_at');
|
|
|
$show->field('updated_at');
|
|
|
// 按钮
|
|
@@ -108,6 +111,7 @@ class DistAdminDistributorController extends AdminController
|
|
|
$form->text('company_address','Company Address');
|
|
|
$form->text('site_name')->required();
|
|
|
$form->text('level_domain')->required();
|
|
|
+ $form->select('appearance_id','select appearance')->options(DistAppearance::selectOptions())->required();
|
|
|
$form->text('country')->required();
|
|
|
$form->text('contact_number');
|
|
|
$form->text('service_hotline');
|
|
@@ -119,6 +123,16 @@ class DistAdminDistributorController extends AdminController
|
|
|
$form->text('tiktok');
|
|
|
$form->textarea('remark');
|
|
|
$form->switch('enabled')->default(1);
|
|
|
+ //保存前回调
|
|
|
+ $form->saving(function (Form $form) {
|
|
|
+ if (!$form->isCreating()) {
|
|
|
+ //如果appearance_id有变化,则更新模版与变量
|
|
|
+ if ($form->model()->appearance_id != $form->input('appearance_id')) {
|
|
|
+ $id = $form->model()->id;
|
|
|
+ DistAppearance::switchTheme($form->input('appearance_id'), $id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
//保存后回调
|
|
|
$form->saved(function (Form $form, $result) {
|
|
|
if ($form->isCreating()) {
|
|
@@ -131,9 +145,10 @@ class DistAdminDistributorController extends AdminController
|
|
|
'enabled' => 1,
|
|
|
'dist_id'=>$newId,
|
|
|
]);
|
|
|
+ //更新模版与变量
|
|
|
+ DistAppearance::switchTheme($form->input('appearance_id'), $newId);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
-
|
|
|
}
|
|
|
}
|