@@ -65,6 +65,7 @@ public static function makeComponentLine(Form $form, string $column, string $tit
65
65
}
66
66
67
67
/**
68
+ * 头部-自定义弹窗按钮
68
69
* @param Grid $grid
69
70
* @param string $document_id
70
71
* @param string $title
@@ -91,8 +92,8 @@ public function render()
91
92
{
92
93
return <<<EOF
93
94
<div class="btn-group pull-right grid-create-btn" style="margin-right: 10px">
94
- <a href='javascript:void(0);' class="btn btn-sm btn-success " id=" {$ this ->document_id }" title=" {$ this ->title }">
95
- <span class="hidden-xs"> {$ this ->title }</span>
95
+ <a href='javascript:void(0);' class="btn btn-sm btn-primary " id=" {$ this ->document_id }" title=" {$ this ->title }">
96
+ <span class="hidden-xs"> {$ this ->title }</span>
96
97
</a>
97
98
</div>
98
99
EOF ;
@@ -101,37 +102,76 @@ public function render()
101
102
}
102
103
103
104
/**
105
+ * 列-多按钮添加
104
106
* @param Grid $grid
105
- * @param string $document_class
106
- * @param string $title
107
- * @param string $url
107
+ * @param array $settings [setting,...]
108
+ * setting.document_class 自定义类名 关键词:CEForm
109
+ * setting.title 自定义按钮名
110
+ * setting.url 加载页地址
111
+ * setting.with_id 加载页面url附加id参数 url/{id}
112
+ * setting.xhr_url ajax提交地址
113
+ * setting.method ajax提交方法
108
114
*/
109
- public static function makeRowPlaneAction (Grid $ grid ,string $ document_class ,string $ title ,string $ url )
115
+ public static function makeRowPlaneAction (Grid $ grid ,array $ settings = [
116
+ ['document_class ' =>'' ,'title ' =>'' ,'url ' =>'' ,'with_id ' =>false ,'xhr_url ' =>'' ,'method ' =>'POST ' ]
117
+ ])
110
118
{
111
- Admin::script (<<<EOF
112
- $('# {$ document_class }').click(function(){
113
- componentPlane(' {$ url }');
119
+ $ grid ->actions (function ($ actions )use ($ settings ) {
120
+ $ script = '' ;
121
+ foreach ($ settings as $ setting ){
122
+ $ url = Request::capture ()->getPathInfo ();
123
+ if ($ setting ['document_class ' ] == 'CEForm ' ){
124
+ $ actions ->disableEdit ();
125
+ $ script .=<<<EOF
126
+ $('.CEForm').click(function(){
127
+ let url = ' {$ url }' + '/'+this.getAttribute('data-id')+'/edit';
128
+ componentPlane(url,url);
114
129
});
115
- EOF
116
- );
117
- $ grid ->tools ->append (new class ($ title ,$ document_class ) extends RowAction {
118
- private $ title ;
119
- private $ document_class ;
120
- public function __construct ($ title ,$ document_class )
121
- {
122
- parent ::__construct ();
123
- $ this ->title = $ title ;
124
- $ this ->document_class = $ document_class ;
130
+ EOF ;
131
+ continue ;
132
+ }
133
+ $ url = $ setting ['url ' ];
134
+ $ method = isset ($ setting ['method ' ]) ? $ setting ['method ' ] : 'POST ' ;
135
+ $ with_id = isset ($ setting ['with_id ' ]) ? $ setting ['with_id ' ] : false ;
136
+ $ xhr_url = isset ($ setting ['xhr_url ' ]) ? $ setting ['xhr_url ' ] : $ url ;
137
+ if ($ with_id ){
138
+ $ script .=<<<EOF
139
+ $('. {$ setting ['document_class ' ]}').click(function(){
140
+ let url = ' {$ url }' + '/'+this.getAttribute('data-id');
141
+ componentPlane(' {$ url }',' {$ xhr_url }',' {$ method }');});
142
+ EOF ;
143
+ continue ;
144
+ }
145
+ $ script .=<<<EOF
146
+ $('. {$ setting ['document_class ' ]}').click(function(){componentPlane(' {$ url }',' {$ xhr_url }',' {$ method }');});
147
+ EOF ;
125
148
}
126
- public function render ()
127
- {
128
- return "<a href='javascript:void(0);' class=' {$ this ->document_class }' data-id=' {$ this ->getKey ()}'> {$ this ->title }</a> " ;
149
+ Admin::script ($ script );
150
+
151
+ foreach ($ settings as $ setting ) {
152
+ $ actions ->add (new
153
+ class ($ setting ['document_class ' ], $ setting ['title ' ]) extends RowAction {
154
+ private $ title ;
155
+ private $ document_class ;
156
+
157
+ public function __construct ($ document_class , $ title )
158
+ {
159
+ parent ::__construct ();
160
+ $ this ->document_class = $ document_class ;
161
+ $ this ->title = $ title ;
162
+ }
163
+
164
+ public function render ()
165
+ {
166
+ return "<a href='javascript:void(0);' class=' {$ this ->document_class }' data-id=' {$ this ->getKey ()}'> {$ this ->title }</a> " ;
167
+ }
168
+ });
129
169
}
130
170
});
131
171
}
132
172
133
173
/**
134
- * 创建弹窗新增表单 -按钮
174
+ * 新增表单 -按钮
135
175
* @param Grid $grid
136
176
*/
137
177
public static function makeAddFormAction (Grid $ grid )
@@ -160,7 +200,7 @@ public function render()
160
200
}
161
201
162
202
/**
163
- * 创建弹窗修改表单 -按钮
203
+ * 修改表单 -按钮
164
204
* @param Grid $grid
165
205
*/
166
206
public static function makeEditFormAction (Grid $ grid )
@@ -187,7 +227,7 @@ public function render()
187
227
}
188
228
189
229
/**
190
- * 创建弹窗修改表单 -按钮 (旧版图标模式)
230
+ * 修改表单 -按钮 (旧版图标模式)
191
231
* @param Grid $grid
192
232
*/
193
233
public static function _makeEditFormAction (Grid &$ grid )
@@ -259,12 +299,19 @@ public static function script($script)
259
299
);
260
300
}
261
301
302
+ /**
303
+ * @param array $data
304
+ * @return false|string
305
+ */
262
306
protected static function safeJson (array $ data )
263
307
{
264
308
self ::recursiveJsonArray ($ data );
265
309
return json_encode ($ data , JSON_UNESCAPED_UNICODE );
266
310
}
267
311
312
+ /**
313
+ * @param array $data
314
+ */
268
315
private static function recursiveJsonArray (array &$ data )
269
316
{
270
317
foreach ($ data as &$ d ) {
0 commit comments