Skip to content

Commit 086681c

Browse files
committed
完善表单事件回调
1 parent 753510b commit 086681c

File tree

7 files changed

+46
-9
lines changed

7 files changed

+46
-9
lines changed

public/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,8 @@ __webpack_require__.r(__webpack_exports__);
18261826
onHandle: function onHandle() {
18271827
var _this = this;
18281828

1829-
this.$http["delete"](this.$route.path + "/" + this.key).then(function (_ref) {
1829+
this.loading = true;
1830+
this.$http["delete"](this.action.resource + "/" + this.key).then(function (_ref) {
18301831
var code = _ref.code;
18311832
if (code === 200) _this.$bus.emit("tableReload");
18321833
})["finally"](function () {

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"/app.js": "/app.js?id=3519231aa2ed59351d3b",
2+
"/app.js": "/app.js?id=16f687ed6c6f1fb127ff",
33
"/manifest.js": "/manifest.js?id=d9708e48a6c10ccee4bb",
44
"/vendor.js": "/vendor.js?id=f4679ac178c0e413cb28"
55
}

resources/js/components/widgets/Actions/DeleteAction.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export default {
2828
},
2929
methods: {
3030
onHandle() {
31+
this.loading = true;
3132
this.$http
32-
.delete(this.$route.path + "/" + this.key)
33+
.delete(this.action.resource + "/" + this.key)
3334
.then(({ code }) => {
3435
if (code === 200) this.$bus.emit("tableReload");
3536
})

src/Actions/BaseAction.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ class BaseAction implements JsonSerializable
1212
protected $className;
1313
protected $style;
1414

15+
protected $resource;
16+
1517
public $hideAttrs = [];
1618

19+
/**
20+
* BaseAction constructor.
21+
*/
22+
public function __construct()
23+
{
24+
$this->resource = url(request()->getPathInfo());
25+
}
26+
27+
1728
public function jsonSerialize()
1829
{
1930
$data = [];

src/Controllers/PermissionController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function grid()
2828

2929
$grid = new Grid(new $permissionModel());
3030

31-
$grid->defaultSort('id', 'asc')->hideViewAction();
31+
$grid->defaultSort('id', 'asc');
3232

3333
$grid->columns([
3434
$grid->column('id', 'ID')->sortable()->width('80px'),
@@ -40,9 +40,12 @@ protected function grid()
4040
})->displayComponent(function () {
4141
return Tag::make();
4242
}),
43-
//$grid->column('created_at', trans('admin::admin.created_at')),
44-
//$grid->column('updated_at', trans('admin::admin.updated_at'))
4543
]);
44+
45+
$grid->actions(function (Grid\Actions $actions) {
46+
$actions->hideViewAction();
47+
});
48+
4649
return $grid;
4750
}
4851

src/Form.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,22 @@ public function getRelations(): array
325325

326326
public function store()
327327
{
328+
329+
if (($result = $this->callSubmitted()) instanceof Response) {
330+
return $result;
331+
}
332+
333+
328334
$data = request()->all();
329335

330336
if ($validationMessages = $this->validatorData($data)) {
331337
return Admin::responseError($validationMessages);
332338
}
333339

340+
if (($result = $this->callSaving()) instanceof Response) {
341+
return $result;
342+
}
343+
334344
if (($response = $this->prepare($data)) instanceof Response) {
335345
return $response;
336346
}
@@ -417,6 +427,9 @@ public function destroy($id)
417427
*/
418428
public function update($id, $data = null)
419429
{
430+
if (($result = $this->callSubmitted()) instanceof Response) {
431+
return $result;
432+
}
420433
$data = ($data) ?: request()->all();
421434

422435
$builder = $this->model();
@@ -425,6 +438,9 @@ public function update($id, $data = null)
425438
if ($validationMessages = $this->validatorData($data)) {
426439
return Admin::responseError($validationMessages);
427440
}
441+
if (($result = $this->callSaving()) instanceof Response) {
442+
return $result;
443+
}
428444

429445
if (($response = $this->prepare($data)) instanceof Response) {
430446
return $response;
@@ -589,6 +605,10 @@ private function updateRelation($relationsData)
589605
*/
590606
public function editData($id)
591607
{
608+
if (($result = $this->callEditing($id)) instanceof Response) {
609+
return $result;
610+
}
611+
592612
$this->setMode(self::MODE_EDIT);
593613
$this->setResourceId($id);
594614
$e_data = $this->model->with($this->getRelations())->findOrFail($this->getResourceId());
@@ -600,7 +620,7 @@ public function editData($id)
600620
$field = $formItem->getField();
601621
$prop = $formItem->getProp();
602622
$component = $formItem->getDisplayComponent();
603-
Arr::set($data, $prop, $formItem->getData(Arr::get($e_data, $prop), $this->model,$component));
623+
Arr::set($data, $prop, $formItem->getData(Arr::get($e_data, $prop), $this->model, $component));
604624
//$data[$prop] = $formItem->getData($e_data->{$prop}, $this->model);
605625
}
606626
foreach ($this->formItems as $formItem) {

src/Form/HasHooks.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ public function deleted(Closure $callback)
126126
/**
127127
* Call editing callbacks.
128128
*
129+
* @param $id
129130
* @return mixed
130131
*/
131-
protected function callEditing()
132+
protected function callEditing($id)
132133
{
133-
return $this->callHooks('editing');
134+
return $this->callHooks('editing',$id);
134135
}
135136

136137
/**

0 commit comments

Comments
 (0)