Skip to content

Commit 26a80fa

Browse files
committed
添加批量操作自定义组件
1 parent 9663955 commit 26a80fa

File tree

35 files changed

+11011
-5352
lines changed

35 files changed

+11011
-5352
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
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
99
"prod": "npm run production",
1010
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
11-
"start":"concurrently -r \"npm:watch*\""
11+
"start": "concurrently -r \"npm:watch*\""
1212
},
1313
"devDependencies": {
1414
"@chenfengyuan/vue-qrcode": "^1.0.2",

public/1.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ __webpack_require__.r(__webpack_exports__);
112112
ItemIf: _ItemIf__WEBPACK_IMPORTED_MODULE_1__["default"]
113113
},
114114
props: {
115-
attrs: Object
115+
attrs: Object,
116+
keys: String
116117
},
117118
data: function data() {
118119
return {
@@ -124,6 +125,12 @@ __webpack_require__.r(__webpack_exports__);
124125
mounted: function mounted() {
125126
this.formData = this._.cloneDeep(this.attrs.formItemsValue);
126127
},
128+
computed: {
129+
actionUrl: function actionUrl() {
130+
var keys = this.$store.getters.thisPage.grids.selectionKeys;
131+
return this._.replace(this.attrs.action, "selectionKeys", keys);
132+
}
133+
},
127134
methods: {
128135
submitForm: function submitForm(formName) {
129136
var _this = this;
@@ -132,7 +139,7 @@ __webpack_require__.r(__webpack_exports__);
132139
if (valid) {
133140
_this.loading = true;
134141

135-
_this.$http.post(_this.attrs.action, _this.formData).then(function (_ref) {
142+
_this.$http.post(_this.actionUrl, _this.formData).then(function (_ref) {
136143
var data = _ref.data,
137144
code = _ref.code,
138145
message = _ref.message;

0 commit comments

Comments
 (0)