Skip to content

Commit c50aa49

Browse files
committed
添加Grid toolbars 自定义
1 parent 086681c commit c50aa49

File tree

12 files changed

+510
-58
lines changed

12 files changed

+510
-58
lines changed

public/app.js

Lines changed: 366 additions & 28 deletions
Large diffs are not rendered by default.

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=16f687ed6c6f1fb127ff",
2+
"/app.js": "/app.js?id=7fafe2e9073cecc0d058",
33
"/manifest.js": "/manifest.js?id=d9708e48a6c10ccee4bb",
44
"/vendor.js": "/vendor.js?id=f4679ac178c0e413cb28"
55
}

resources/js/components.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,8 @@ Vue.component('MenuItem', MenuItem);
8282
import EditAction from './components/widgets/Actions/EditAction'
8383
import DeleteAction from './components/widgets/Actions/DeleteAction'
8484
Vue.component('EditAction', EditAction);
85-
Vue.component('DeleteAction', DeleteAction);
85+
Vue.component('DeleteAction', DeleteAction);
86+
87+
//Tools
88+
import GridCreateButton from './components/widgets/Tools/Create'
89+
Vue.component('GridCreateButton', GridCreateButton);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<template>
2+
<div class="grid-actions">
3+
<template v-for="action in action_list">
4+
<span :key="action.componentName">
5+
<component
6+
:is="action.componentName"
7+
:scope="{ row: scope.data, colum: {} }"
8+
:action="action"
9+
:key_name="key_name"
10+
/>
11+
</span>
12+
</template>
13+
</div>
14+
</template>
15+
<script>
16+
import Action from "./Action";
17+
export default {
18+
components: {
19+
Action
20+
},
21+
props: {
22+
key_name: String,
23+
action_list: Array,
24+
scope: Object
25+
},
26+
mounted() {},
27+
computed: {}
28+
};
29+
</script>
30+
<style lang="scss">
31+
.grid-actions {
32+
.el-button + .el-button {
33+
margin-left: 0;
34+
}
35+
span + span {
36+
margin-left: 10px;
37+
}
38+
}
39+
</style>

resources/js/components/grid/Table.vue

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@
2525
</div>
2626
</div>
2727
<div class="grid-top-container-right">
28-
<router-link
29-
:to="path + '/create'"
30-
v-if="!attrs.attributes.hideCreateButton"
31-
>
32-
<el-button type="primary" class="mr-10" icon="el-icon-plus"
33-
>新建</el-button
34-
>
35-
</router-link>
28+
<component
29+
v-for="(component, index) in attrs.toolbars.right"
30+
:key="component.componentName + index"
31+
:is="component.componentName"
32+
/>
3633
<el-divider
3734
direction="vertical"
3835
v-if="!attrs.attributes.hideCreateButton"
@@ -74,7 +71,6 @@
7471
</div>
7572
</div>
7673
</div>
77-
7874
<div>
7975
<el-table
8076
v-loading="loading"
@@ -135,7 +131,10 @@
135131
</template>
136132
</el-table-column>
137133
</template>
138-
<el-table-column v-if="attrs.actions && !attrs.actions.hide" label="操作">
134+
<el-table-column
135+
v-if="attrs.actions && !attrs.actions.hide"
136+
label="操作"
137+
>
139138
<template slot="header"></template>
140139
<template slot-scope="scope">
141140
<Actions
@@ -257,11 +256,6 @@ export default {
257256
onPageCurrentChange(page) {
258257
this.page = page;
259258
this.getData();
260-
},
261-
onEnt(event) {
262-
if (event.keyCode === 13) {
263-
this.getData();
264-
}
265259
}
266260
},
267261
computed: {
@@ -295,7 +289,7 @@ export default {
295289
padding: 8px;
296290
display: flex;
297291
justify-content: space-between;
298-
border-bottom: 1px solid #ebeef5;
292+
//border-bottom: 1px solid #ebeef5;
299293
.grid-top-container-left {
300294
display: flex;
301295
align-items: center;

resources/js/components/grid/Tree.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
</template>
8686
<script>
8787
import TreeColumnDisplay from "./TreeColumnDisplay";
88-
import Actions from "./Actions/Index";
88+
import Actions from "./Actions/TreeAction";
8989
export default {
9090
components: {
9191
TreeColumnDisplay,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export default {
2121
},
2222
methods: {
2323
onHandle() {
24+
console.log(this.scope);
25+
2426
this.$router.push(this.$route.path + "/" + this.key + "/edit");
2527
}
2628
},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<template>
2+
<router-link :to="$route.path + '/create'">
3+
<el-button type="primary" class="mr-10" icon="el-icon-plus">新建</el-button>
4+
</router-link>
5+
</template>
6+
<script>
7+
export default {};
8+
</script>

src/Grid.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
use SmallRuralDog\Admin\Components\Component;
1111
use SmallRuralDog\Admin\Grid\Actions;
1212
use SmallRuralDog\Admin\Grid\Column;
13-
use SmallRuralDog\Admin\Grid\Concerns\HasAttributes;
1413
use SmallRuralDog\Admin\Grid\Concerns\HasDefaultSort;
1514
use SmallRuralDog\Admin\Grid\Concerns\HasGridAttributes;
1615
use SmallRuralDog\Admin\Grid\Concerns\HasPageAttributes;
1716
use SmallRuralDog\Admin\Grid\Concerns\HasQuickSearch;
1817
use SmallRuralDog\Admin\Grid\Model;
1918
use SmallRuralDog\Admin\Grid\Table\Attributes;
19+
use SmallRuralDog\Admin\Grid\Toolbars;
20+
2021

2122
class Grid extends Component implements \JsonSerializable
2223
{
@@ -44,6 +45,8 @@ class Grid extends Component implements \JsonSerializable
4445

4546
private $actions;
4647

48+
private $toolbars;
49+
4750

4851
public function __construct(Eloquent $model, Closure $builder = null)
4952
{
@@ -59,6 +62,7 @@ public function __construct(Eloquent $model, Closure $builder = null)
5962
$this->isGetData = request('get_data') == "true";
6063

6164
$this->actions = new Actions();
65+
$this->toolbars = new Toolbars();
6266

6367
}
6468

@@ -172,6 +176,17 @@ protected function applyQuery()
172176
$this->applyQuickSearch();
173177
}
174178

179+
/**
180+
* 自定义toolbars
181+
* @param $closure
182+
* @return $this
183+
*/
184+
public function toolbars($closure)
185+
{
186+
call_user_func($closure, $this->toolbars);
187+
return $this;
188+
}
189+
175190
/**
176191
* 自定义行操作
177192
* @param $closure
@@ -236,6 +251,7 @@ public function jsonSerialize()
236251
$viewData['perPage'] = $this->perPage;
237252
$viewData['pageBackground'] = $this->pageBackground;
238253
$viewData['actions'] = $this->actions->builderActions();
254+
$viewData['toolbars'] = $this->toolbars->builderData();
239255
$viewData['quickSearch'] = $this->quickSearch;
240256
return $viewData;
241257
}

src/Grid/Concerns/HasGridAttributes.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,6 @@ public function rowKey($rowKey)
135135
return $this;
136136
}
137137

138-
/**
139-
* 隐藏新建按钮
140-
* @param bool $hide
141-
* @return $this
142-
*/
143-
public function hideCreateButton(bool $hide = true)
144-
{
145-
$this->attributes->hideCreateButton = $hide;
146-
return $this;
147-
}
148138

149139
/**
150140
* 开启拖拽排序

0 commit comments

Comments
 (0)