Skip to content

Commit 0f927a6

Browse files
committed
🔖 Merge branch 'master' into develop
2 parents 2616d52 + 26a80fa commit 0f927a6

File tree

19 files changed

+536
-38
lines changed

19 files changed

+536
-38
lines changed

config/admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
],
9999
//操作日志
100100
'operation_log' => [
101-
'enable' => false,
101+
'enable' => true,
102102
/*
103103
* Only logging allowed methods in the list
104104
*/

docs/components.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,26 @@ $actions->add(ActionButton::make("发货")->order(4)->dialog(function (Dialog $d
284284

285285
这里的dialog展示的是一个表单,当然你可以展示任意组件
286286

287+
### 批量操作组件
288+
289+
#### BatchAction
290+
291+
可用于vue路由导航,异步请求,连接跳转 , Dialog
292+
293+
```php
294+
BatchAction::make("加入活动")
295+
->uri('...')//批量操作路径
296+
->handler(BatchAction::HANDLER_REQUEST)//批量操作响应事件类型
297+
->route('...')//vue路由快捷设置方法
298+
->requestMethod('post')//设置request模式请求类型
299+
->message('...')//确认操作提示信息
300+
->beforeEmit('name','data')//请求前出发事件
301+
->successEmit('name','data')//操作成功后触发事件
302+
->afterEmit('name','data')//操作完成后触发事件,失败成功都会触发
303+
->dialog(Dialog)//设置dialog弹窗
304+
305+
```
306+
287307

288308

289309
### 工具栏组件
@@ -292,8 +312,6 @@ $actions->add(ActionButton::make("发货")->order(4)->dialog(function (Dialog $d
292312

293313
可用于vue路由导航,异步请求,连接跳转 , Dialog
294314

295-
296-
297315
普通演示
298316

299317
```php

docs/grid.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
# 模型表格
24

35
使用[Elememt 的 Table](https://element.eleme.cn/#/zh-CN/component/table)实现,用于展示多条结构类似的数据,可对数据进行排序、筛选、对比或其他自定义操作。
@@ -726,12 +728,57 @@ $actions->deleteAction()->message("确定要删除吗,删除不可恢复?");
726728
$actions->add(new MyAction())
727729
```
728730

731+
## 批量操作
732+
733+
```php
734+
$grid->batchActions(function (Grid\BatchActions $batchActions) {
735+
$batchActions->hideDeleteAction();//隐藏批量删除操作
736+
$batchActions->add(...);//添加批量操作
737+
});
738+
```
739+
740+
#### 获取选择的keys
741+
742+
获取批量选择的keys
743+
744+
> 注意:获取原理为前段字符串替换,后端无法获取具体值
745+
746+
```php
747+
$batchActions->getKeys();
748+
```
749+
750+
可以在设置`url`时使用
751+
752+
```php
753+
$url = $$batchActions->resource . '/' . $$batchActions->getKeys();
754+
Grid\BatchActions\BatchAction::make("批量删除")->url($url);
755+
```
756+
757+
可以在设置`dialog`里的`BaseForm``action`时使用
758+
759+
```php
760+
$grid->batchActions(function (Grid\BatchActions $batchActions) {
761+
$batchActions->add(Grid\BatchActions\BatchAction::make("加入活动")->dialog(function (Dialog $dialog) use ($batchActions) {
762+
$dialog->slot(function (Content $content) use ($batchActions) {
763+
$form = new BaseForm();
764+
765+
$actionUrl = route('activityJoin', ['keys' => $batchActions->getKeys()]);
766+
$form->action($actionUrl);
767+
768+
$form->item('activity_id', '活动');
769+
$content->row($form);
770+
});
771+
}));
772+
});
773+
```
774+
729775

730776

731777
## 工具栏
732778

733779
```php
734780
$grid->toolbars(function (Grid\Toolbars $toolbars) {
781+
735782
$toolbars->hideCreateButton();
736783
$toolbars->createButton()->content("添加商品");//获取创建组件实例,修改属性
737784
});

resources/js/components.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Vue.component('ColorPicker', ColorPicker);
5959
Vue.component('TimePicker', TimePicker);
6060
Vue.component('DatePicker', DatePicker);
6161
Vue.component('DateTimePicker', DateTimePicker);
62-
Vue.component('WangEditor', () => import('./components/widgets/WangEditor'));
63-
Vue.component('ItemSelect', () => import('./components/widgets/Form/ItemSelect'));
62+
Vue.component('WangEditor', () => import('@/components/widgets/WangEditor'));
63+
Vue.component('ItemSelect', () => import('@/components/widgets/Form/ItemSelect'));
6464

6565

6666

@@ -101,6 +101,9 @@ Vue.component('DeleteAction', DeleteAction);
101101
Vue.component('VueRouteAction', VueRouteAction);
102102
Vue.component('ActionButton', ActionButton);
103103

104+
//BatchAction
105+
Vue.component('BatchAction',require('@/components/widgets/BatchActions/BatchAction').default)
106+
104107
//Tools
105108
import GridCreateButton from './components/widgets/Tools/Create'
106109
import ToolButton from './components/widgets/Tools/ToolButton'

resources/js/components/form/BaseForm.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export default {
100100
ItemIf
101101
},
102102
props: {
103-
attrs: Object
103+
attrs: Object,
104+
keys:String
104105
},
105106
data() {
106107
return {
@@ -112,14 +113,23 @@ export default {
112113
mounted() {
113114
this.formData = this._.cloneDeep(this.attrs.formItemsValue)
114115
},
116+
computed:{
117+
actionUrl(){
118+
119+
const keys = this.$store.getters.thisPage.grids.selectionKeys;
120+
121+
122+
return this._.replace(this.attrs.action, "selectionKeys", keys);
123+
}
124+
},
115125
methods: {
116126
submitForm(formName) {
117127
this.$refs[formName].validate(valid => {
118128
if (valid) {
119129
this.loading = true;
120130
121131
this.$http
122-
.post(this.attrs.action, this.formData)
132+
.post(this.actionUrl, this.formData)
123133
.then(({ data, code, message }) => {
124134
if (code == 200) {
125135
this.attrs.emits.map(item => {

resources/js/components/grid/BatchActions/Index.vue

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
<i class="el-icon-arrow-down el-icon--right"></i>
66
</el-button>
77
<el-dropdown-menu slot="dropdown">
8-
<a @click="onBatchDelete">
9-
<el-dropdown-item>批量删除</el-dropdown-item>
10-
</a>
8+
<component
9+
v-for="(component, index) in actions"
10+
:key="component.componentName + index"
11+
:is="component.componentName"
12+
:action="component"
13+
:keys="keys"
14+
/>
1115
</el-dropdown-menu>
1216
</el-dropdown>
1317
</template>
@@ -16,31 +20,10 @@ export default {
1620
props: {
1721
rows: Array,
1822
routers: Object,
19-
key_name: String
20-
},
21-
methods: {
22-
onBatchDelete() {
23-
this.$confirm(
24-
"您确定删除这" + this.rows.length + "条数据吗?",
25-
"批量删除确认"
26-
)
27-
.then(() => {
28-
const deleteUrl = this.routers.resource + "/" + this.keys;
29-
30-
this.$bus.emit("tableSetLoading", true);
31-
32-
this.$http
33-
.delete(deleteUrl)
34-
.then(({ code }) => {
35-
code === 200 && this.$bus.emit("tableReload");
36-
})
37-
.finally(() => {
38-
this.$bus.emit("tableSetLoading", false);
39-
});
40-
})
41-
.catch(() => {});
42-
}
23+
key_name: String,
24+
actions: Array
4325
},
26+
methods: {},
4427
computed: {
4528
keys() {
4629
return this.rows

resources/js/components/grid/Table.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
:routers="attrs.routers"
1414
:key_name="attrs.keyName"
1515
:rows="selectionRows"
16+
:actions="attrs.batchActions"
1617
v-if="attrs.selection"
1718
/>
1819
<div class="search-view mr-10" v-if="attrs.quickSearch">
@@ -387,6 +388,7 @@ export default {
387388
//当选择项发生变化时会触发该事件
388389
onTableselectionChange(selection) {
389390
this.selectionRows = selection;
391+
this.$store.commit("setGridData", { key: "selectionKeys", data: this.keys });
390392
},
391393
//每页大小改变时
392394
onPageSizeChange(per_page) {
@@ -401,6 +403,13 @@ export default {
401403
}
402404
},
403405
computed: {
406+
keys() {
407+
return this.selectionRows
408+
.map(item => {
409+
return item[this.attrs.keyName];
410+
})
411+
.join(",");
412+
},
404413
//当前路径
405414
path() {
406415
return this.$route.path;

resources/js/components/layout/Column.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:key="index"
66
:is="content.componentName"
77
:attrs="content"
8+
v-bind="$props"
89
/>
910
</el-col>
1011
</template>

resources/js/components/layout/Content.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
:key="index"
1212
:is="row.componentName"
1313
:attrs="row"
14+
v-bind="$props"
1415
/>
1516
</div>
1617
</div>

resources/js/components/layout/Row.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:key="index"
66
:is="column.componentName"
77
:attrs="column"
8+
v-bind="$props"
89
/>
910
</el-row>
1011
</template>

0 commit comments

Comments
 (0)