@@ -166,78 +166,42 @@ public function render()
166
166
}
167
167
168
168
/**
169
- * 新增表单-按钮
169
+ * 列-多操作添加 (旧版图标按钮模式)
170
170
* @param Grid $grid
171
+ * @param array $settings [setting,...]
172
+ * setting.document_class 自定义类名
173
+ * setting.title 自定义按钮名 (图标css类 fa-edit fa-...)
174
+ * setting.url 加载页地址
175
+ * setting.xhr_url ajax提交地址
176
+ * setting.method ajax提交方法
177
+ * @param array $disable ['view','edit','delete']
171
178
*/
172
- public static function makeAddFormAction (Grid $ grid )
179
+ public static function _makeRowPlaneAction (Grid $ grid ,array $ settings = [
180
+ ['document_class ' =>'' ,'title ' =>'' ,'url ' =>'' ,'xhr_url ' =>'' ,'method ' =>'POST ' ]
181
+ ],array $ disable =[])
173
182
{
174
- $ url = Request::capture ()->getPathInfo ();
175
- Admin::script (<<<EOF
176
- $('.CAForm').click(function(){
177
- componentPlane(' {$ url }/create',' {$ url }');
183
+ $ script = '' ;
184
+ foreach ($ settings as $ setting ){
185
+ $ url = $ setting ['url ' ];
186
+ $ method = isset ($ setting ['method ' ]) ? $ setting ['method ' ] : 'POST ' ;
187
+ $ xhr_url = isset ($ setting ['xhr_url ' ]) ? $ setting ['xhr_url ' ] : $ url ;
188
+ $ script .=<<<EOF
189
+ $('. {$ setting ['document_class ' ]}').click(function(){
190
+ let url = ' $ url'.replace('{id}',$(this).attr('data-id'));
191
+ componentPlane(url,' {$ xhr_url }',' {$ method }');
178
192
});
179
- EOF
180
- );
181
- $ grid ->disableCreateButton ();
182
- $ grid ->tools ->append (new
183
- class extends RowAction {
184
- public function render ()
185
- {
186
- return <<<EOF
187
- <div class="btn-group pull-right grid-create-btn" style="margin-right: 10px">
188
- <a href='javascript:void(0);' class="btn btn-sm btn-success CAForm" title="新增">
189
- <i class="fa fa-plus"></i><span class="hidden-xs"> 新增</span>
190
- </a>
191
- </div>
192
193
EOF ;
194
+ }
195
+ Admin::script ($ script );
196
+ $ grid ->actions (function ($ actions )use ($ settings ,$ disable ) {
197
+ foreach ($ settings as $ setting ) {
198
+ $ actions ->append ("<a data-id=' {$ actions ->getKey ()}' href='javascript:void(0);' class=' {$ setting ['document_class ' ]}'><i class='fa {$ setting ['title ' ]}'></i></a> " );
199
+ }
200
+ foreach ($ disable as $ dis ){
201
+ $ dis == 'view ' && $ actions ->disableView ();
202
+ $ dis == 'edit ' && $ actions ->disableEdit ();
203
+ $ dis == 'delete ' && $ actions ->disableDelete ();
193
204
}
194
- });
195
- }
196
-
197
- /**
198
- * 修改表单-按钮
199
- * @param Grid $grid
200
- */
201
- public static function makeEditFormAction (Grid $ grid )
202
- {
203
- $ grid ->actions (function ($ actions ) {
204
- $ actions ->disableEdit ();
205
- $ url = Request::capture ()->getPathInfo ();
206
- Admin::script (<<<EOF
207
- $('.CEForm').click(function(){
208
- let url = ' {$ url }' + '/'+this.getAttribute('data-id');
209
- componentPlane(url+'/edit',url);
210
- });
211
- EOF
212
- );
213
-
214
- $ actions ->add (new
215
- class extends RowAction {
216
- public function render ()
217
- {
218
- return "<a href='javascript:void(0);' class='CEForm' data-id=' {$ this ->getKey ()}'>修改</a> " ;
219
- }
220
- });
221
- });
222
- }
223
-
224
- /**
225
- * 修改表单-按钮 (旧版图标模式)
226
- * @param Grid $grid
227
- */
228
- public static function _makeEditFormAction (Grid &$ grid )
229
- {
230
- $ grid ->actions (function ($ actions ) {
231
- $ actions ->disableEdit ();
232
- $ url = Request::capture ()->getPathInfo ();
233
- Admin::script (<<<EOF
234
- $('.CEForm').click(function(){
235
- let url = ' {$ url }' + '/'+this.getAttribute('data-id');
236
- componentPlane(url+'/edit',url);
237
- });
238
- EOF
239
- );
240
- $ actions ->append ("<a data-id=' {$ actions ->getKey ()}' href='javascript:void(0);' class='CEForm'><i class='fa fa-edit'></i></a> " );
241
205
});
242
206
}
243
207
@@ -276,11 +240,10 @@ public static function result($success = true, $message = 'OK', $data = [])
276
240
/**
277
241
* 表单代码段插入js片段代码
278
242
* @param $script
279
- * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
280
243
*/
281
244
public static function script ($ script )
282
245
{
283
- return Admin::script (<<<EOF
246
+ Admin::script (<<<EOF
284
247
new Promise((resolve, reject) => {
285
248
while (true){
286
249
if(document.getElementById('component') instanceof HTMLElement){
0 commit comments