@@ -20,8 +20,8 @@ class DLPViewer
20
20
* @param Form $form
21
21
* @param string $column 字段名
22
22
* @param string $title 名称
23
- * @param array $select 全部选项
24
- * @param array $selected 已选择选项
23
+ * @param array $select [[id=>value],[id=>value]...], 所有选择项
24
+ * @param array $selected [[id=>value],[id=>value]...], 已选择选项
25
25
* @param bool $strict json严格模式 消除json敏感字符问题
26
26
*/
27
27
public static function makeComponentDot (Form $ form , string $ column , string $ title , array $ select = [], array $ selected = [],bool $ strict = false )
@@ -43,17 +43,23 @@ public static function makeComponentDot(Form $form, string $column, string $titl
43
43
/**
44
44
* 线
45
45
* @param Form $form
46
- * @param string $column 字段名
47
- * @param string $title 名称
48
- * @param array $settings 设置项
49
- * @param array $data 数据
50
- * @param bool $strict json严格模式 消除json敏感字符问题
46
+ * @param string $column 字段名
47
+ * @param string $title 名称
48
+ * @param array $settings 配置项
49
+ * $settings = [
50
+ * 'column1'=> ['name' => 'name1', 'type' => 'input', 'style' => 'width:60px'],
51
+ * 'column2'=> ['name' => 'name2', 'type' => 'text'],
52
+ * 'column3'=> ['name' => 'name3', 'type' => 'hidden'],
53
+ * ...
54
+ * ]
55
+ * @param array $data 数据
56
+ * @param bool $strict json严格模式 消除json敏感字符问题
51
57
*/
52
58
public static function makeComponentLine (Form $ form , string $ column , string $ title , array $ settings = [], array $ data = [], bool $ strict = false )
53
59
{
54
- if ($ strict ) {
60
+ if ($ strict ) {
55
61
$ data = DLPHelper::safeJson ($ data );
56
- }else {
62
+ } else {
57
63
$ data = json_encode ($ data , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
58
64
}
59
65
$ settings = json_encode ($ settings , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
@@ -74,29 +80,31 @@ public static function makeComponentLine(Form $form, string $column, string $tit
74
80
* setting.xhr_url ajax提交地址
75
81
* setting.method ajax提交方法
76
82
*/
77
- public static function makeHeadPlaneAction (Grid $ grid ,array $ settings = [
78
- ['document_id ' => '' ,'title ' => '' ,'url ' => '' ,'xhr_url ' => '' ,'method ' => 'POST ' ]
83
+ public static function makeHeadPlaneAction (Grid $ grid , array $ settings = [
84
+ ['document_id ' => '' , 'title ' => '' , 'url ' => '' , 'xhr_url ' => '' , 'method ' => 'POST ' ]
79
85
])
80
86
{
81
87
$ script = '' ;
82
- foreach ($ settings as $ setting ){
88
+ foreach ($ settings as $ setting ) {
83
89
$ xhr_url = isset ($ setting ['xhr_url ' ]) ? $ setting ['xhr_url ' ] : $ setting ['url ' ];
84
90
$ method = isset ($ setting ['method ' ]) ? $ setting ['method ' ] : 'POST ' ;
85
- $ script.= <<<EOF
91
+ $ script .= <<<EOF
86
92
$('# {$ setting ['document_id ' ]}').click(function(){
87
93
new ComponentPlane(' {$ setting ['url ' ]}',' {$ xhr_url }',' {$ method }');
88
94
});
89
95
EOF ;
90
96
Admin::script ($ script );
91
- $ grid ->tools ->append (new class ($ setting ['title ' ],$ setting ['document_id ' ]) extends RowAction {
97
+ $ grid ->tools ->append (new class ($ setting ['title ' ], $ setting ['document_id ' ]) extends RowAction {
92
98
private $ title ;
93
99
private $ document_id ;
94
- public function __construct ($ title ,$ document_id )
100
+
101
+ public function __construct ($ title , $ document_id )
95
102
{
96
103
parent ::__construct ();
97
104
$ this ->title = $ title ;
98
105
$ this ->document_id = $ document_id ;
99
106
}
107
+
100
108
public function render ()
101
109
{
102
110
return <<<EOF
@@ -122,16 +130,16 @@ public function render()
122
130
* setting.method ajax提交方法
123
131
* @param array $disable ['view','edit','delete']
124
132
*/
125
- public static function makeRowPlaneAction (Grid $ grid ,array $ settings = [
126
- ['document_class ' => '' ,'title ' => '' ,'url ' => '' ,'xhr_url ' => '' ,'method ' => 'POST ' ]
127
- ],array $ disable= [])
133
+ public static function makeRowPlaneAction (Grid $ grid , array $ settings = [
134
+ ['document_class ' => '' , 'title ' => '' , 'url ' => '' , 'xhr_url ' => '' , 'method ' => 'POST ' ]
135
+ ], array $ disable = [])
128
136
{
129
137
$ script = '' ;
130
- foreach ($ settings as $ setting ){
138
+ foreach ($ settings as $ setting ) {
131
139
$ url = $ setting ['url ' ];
132
140
$ method = isset ($ setting ['method ' ]) ? $ setting ['method ' ] : 'POST ' ;
133
141
$ xhr_url = isset ($ setting ['xhr_url ' ]) ? $ setting ['xhr_url ' ] : $ url ;
134
- $ script.= <<<EOF
142
+ $ script .= <<<EOF
135
143
$('. {$ setting ['document_class ' ]}').click(function(){
136
144
let url = ' $ url'.replace('{id}',$(this).attr('data-id'));
137
145
let xhr_url = ' $ xhr_url'.replace('{id}',$(this).attr('data-id'));
@@ -140,25 +148,27 @@ public static function makeRowPlaneAction(Grid $grid,array $settings = [
140
148
EOF ;
141
149
}
142
150
Admin::script ($ script );
143
- $ grid ->actions (function ($ actions )use ($ settings ,$ disable ) {
151
+ $ grid ->actions (function ($ actions ) use ($ settings , $ disable ) {
144
152
foreach ($ settings as $ setting ) {
145
153
$ actions ->add (new
146
154
class ($ setting ['document_class ' ], $ setting ['title ' ]) extends RowAction {
147
155
private $ title ;
148
156
private $ document_class ;
157
+
149
158
public function __construct ($ document_class , $ title )
150
159
{
151
160
parent ::__construct ();
152
161
$ this ->document_class = $ document_class ;
153
162
$ this ->title = $ title ;
154
163
}
164
+
155
165
public function render ()
156
166
{
157
167
return "<a href='javascript:void(0);' class=' {$ this ->document_class }' data-id=' {$ this ->getKey ()}'> {$ this ->title }</a> " ;
158
168
}
159
169
});
160
170
}
161
- foreach ($ disable as $ dis ){
171
+ foreach ($ disable as $ dis ) {
162
172
$ dis == 'view ' && $ actions ->disableView ();
163
173
$ dis == 'edit ' && $ actions ->disableEdit ();
164
174
$ dis == 'delete ' && $ actions ->disableDelete ();
@@ -177,28 +187,28 @@ public function render()
177
187
* setting.method ajax提交方法
178
188
* @param array $disable ['view','edit','delete']
179
189
*/
180
- public static function _makeRowPlaneAction (Grid $ grid ,array $ settings = [
181
- ['document_class ' => '' ,'title ' => '' ,'url ' => '' ,'xhr_url ' => '' ,'method ' => 'POST ' ]
182
- ],array $ disable= [])
190
+ public static function _makeRowPlaneAction (Grid $ grid , array $ settings = [
191
+ ['document_class ' => '' , 'title ' => '' , 'url ' => '' , 'xhr_url ' => '' , 'method ' => 'POST ' ]
192
+ ], array $ disable = [])
183
193
{
184
194
$ script = '' ;
185
- foreach ($ settings as $ setting ){
195
+ foreach ($ settings as $ setting ) {
186
196
$ url = $ setting ['url ' ];
187
197
$ method = isset ($ setting ['method ' ]) ? $ setting ['method ' ] : 'POST ' ;
188
198
$ xhr_url = isset ($ setting ['xhr_url ' ]) ? $ setting ['xhr_url ' ] : $ url ;
189
- $ script.= <<<EOF
199
+ $ script .= <<<EOF
190
200
$('. {$ setting ['document_class ' ]}').click(function(){
191
201
let url = ' $ url'.replace('{id}',$(this).attr('data-id'));
192
202
new ComponentPlane(url,' {$ xhr_url }',' {$ method }');
193
203
});
194
204
EOF ;
195
205
}
196
206
Admin::script ($ script );
197
- $ grid ->actions (function ($ actions )use ($ settings ,$ disable ) {
207
+ $ grid ->actions (function ($ actions ) use ($ settings , $ disable ) {
198
208
foreach ($ settings as $ setting ) {
199
209
$ actions ->append ("<a data-id=' {$ actions ->getKey ()}' href='javascript:void(0);' class=' {$ setting ['document_class ' ]}'><i class='fa {$ setting ['title ' ]}'></i></a> " );
200
210
}
201
- foreach ($ disable as $ dis ){
211
+ foreach ($ disable as $ dis ) {
202
212
$ dis == 'view ' && $ actions ->disableView ();
203
213
$ dis == 'edit ' && $ actions ->disableEdit ();
204
214
$ dis == 'delete ' && $ actions ->disableDelete ();
0 commit comments