@@ -18,85 +18,117 @@ class DLPViewer
18
18
/**
19
19
* 点
20
20
* @param Form $form
21
- * @param string $column 字段名
22
- * @param string $title 名称
23
- * @param array $select 全部选项
21
+ * @param string $column 数据字段名
22
+ * @param string $title 名称
23
+ * @param array $select 全部选项
24
24
* @param array $selected 已选择选项
25
- * @param bool $strict json严格模式 消除json敏感字符问题
25
+ * @param array $settings 配置项
26
+ * $settings = [
27
+ * 'strict'=>false, boolean json严格模式消除json敏感字符问题
28
+ * 'width'=>'100%' string 容器宽度设置
29
+ * 'height'=>'200px', string 容器高度设置
30
+ * ]
26
31
*/
27
- public static function makeComponentDot (Form $ form , string $ column , string $ title , array $ select = [], array $ selected = [],bool $ strict = false )
32
+ public static function makeComponentDot (Form $ form , string $ column , string $ title , array $ select = [], array $ selected = [], array $ settings = [] )
28
33
{
34
+ $ strict = isset ($ settings ['strict ' ]) && $ settings ['strict ' ] ? true : false ;
35
+ $ width = isset ($ settings ['width ' ]) ? $ settings ['width ' ] : '100% ' ;
36
+ $ hight = isset ($ settings ['height ' ]) ? $ settings ['height ' ] : '200px ' ;
29
37
if ($ strict ) {
30
- $ select = self ::safeJson ($ select );
31
- $ selected = self ::safeJson ($ selected );
38
+ $ select = DLPHelper ::safeJson ($ select );
39
+ $ selected = DLPHelper ::safeJson ($ selected );
32
40
} else {
33
41
$ select = json_encode ($ select , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
34
42
$ selected = json_encode ($ selected , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
35
43
}
36
44
Admin::script (<<<EOF
37
- componentDot (" {$ column }",JSON.parse(' {$ selected }'),JSON.parse(' {$ select }'));
45
+ new ComponentDot (" {$ column }",JSON.parse(' {$ selected }'),JSON.parse(' {$ select }'));
38
46
EOF
39
47
);
40
- $ form ->html ("<div id=' {$ column }'></div> " , $ title );
48
+ $ form ->html ("<div id=' {$ column }' style='width: { $ width } ;height: { $ hight } ;' ></div> " , $ title );
41
49
}
42
50
43
51
/**
44
52
* 线
45
53
* @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敏感字符问题
54
+ * @param string $column 数据字段名
55
+ * @param string $title 名称
56
+ * @param array $data 数据
57
+ * @param array $settings 配置项[setting,...]
58
+ * $settings = [
59
+ * 'columns'=>[
60
+ * 'name' => ['name' => '名称', 'type' => 'input'],
61
+ * 'name1' => ['name1' => '名称1', 'type' => 'text', style=>'width:50px'],
62
+ * 'name2' => ['name2' => '名称2', 'type' => 'hidden'],
63
+ * ...], array 多列配置项 (必须填)
64
+ * 'strict'=>false, boolean json严格模式消除json敏感字符问题 (选填)
65
+ * 'width'=>'100%', string 容器宽度设置 (选填)
66
+ * 'height'=>'450px', string 容器高度设置 (选填)
67
+ * 'options'=>[
68
+ * 'sortable'=>true,
69
+ * 'delete'=>true
70
+ * ] array 多列操作设置 (选填)
71
+ * ]
51
72
*/
52
- public static function makeComponentLine (Form $ form , string $ column , string $ title , array $ settings = [], array $ data = [], bool $ strict = false )
73
+ public static function makeComponentLine (Form $ form , string $ column , string $ title , array $ data = [], array $ settings = [])
53
74
{
54
- if ($ strict ) {
55
- $ data = self ::safeJson ($ data );
56
- }else {
75
+ $ strict = isset ($ settings ['strict ' ]) && $ settings ['strict ' ] ? true : false ;
76
+ $ width = isset ($ settings ['width ' ]) ? $ settings ['width ' ] : '100% ' ;
77
+ $ hight = isset ($ settings ['height ' ]) ? $ settings ['height ' ] : '450px ' ;
78
+ $ options = isset ($ settings ['options ' ]) ? json_encode ($ settings ['options ' ]) : '[] ' ;
79
+ if (!isset ($ settings ['columns ' ])) return ;
80
+ $ columns = $ settings ['columns ' ];
81
+ if ($ strict ) {
82
+ $ data = DLPHelper::safeJson ($ data );
83
+ } else {
57
84
$ data = json_encode ($ data , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
58
85
}
59
- $ settings = json_encode ($ settings , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
86
+ $ columns = json_encode ($ columns , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
60
87
Admin::script (<<<EOF
61
- componentLine (" {$ column }",JSON.parse(' {$ settings }'),JSON.parse(' {$ data }'));
88
+ new ComponentLine (" {$ column }",JSON.parse(' {$ columns }'),JSON.parse(' {$ data} '),JSON.parse(' { $ options }'));
62
89
EOF
63
90
);
64
- $ form ->html ("<div id=' {$ column }'></div> " , $ title );
91
+ $ form ->html ("<div id=' {$ column }' style='width: { $ width } ;height: { $ hight } ;' ></div> " , $ title );
65
92
}
66
93
67
94
/**
68
95
* 头部-多操作添加
69
96
* @param Grid $grid
70
- * @param array $settings [setting,...]
71
- * setting.document_id 自定义节点ID
72
- * setting.title 自定义按钮名
73
- * setting.url 加载页地址
74
- * setting.xhr_url ajax提交地址
75
- * setting.method ajax提交方法
97
+ * @param array $settings 配置项[setting,...]
98
+ * settings.document_id dom节点id (必须填)
99
+ * settings.title 自定义按钮名 (必须填)
100
+ * settings.url 加载页地址 url/{id}加参数匹配id (必须填)
101
+ * settings.xhr_url ajax提交地址 url/{id}加参数匹配id (选填)
102
+ * settings.method ajax提交方法 (选填)
103
+ * settings.options 弹窗配置项 (选填)
104
+ * options = ['W'=>0.8,'H'=>0.8]
76
105
*/
77
- public static function makeHeadPlaneAction (Grid $ grid ,array $ settings = [
78
- ['document_id ' => '' ,'title ' => '' ,'url ' => '' ,'xhr_url ' => '' ,'method ' => 'POST ' ]
106
+ public static function makeHeadPlaneAction (Grid $ grid , array $ settings = [
107
+ ['document_id ' => '' , 'title ' => '' , 'url ' => '' , 'xhr_url ' => '' , 'method ' => 'POST ' , ' options ' => [] ]
79
108
])
80
109
{
81
110
$ script = '' ;
82
- foreach ($ settings as $ setting ){
111
+ foreach ($ settings as $ setting ) {
83
112
$ xhr_url = isset ($ setting ['xhr_url ' ]) ? $ setting ['xhr_url ' ] : $ setting ['url ' ];
84
113
$ method = isset ($ setting ['method ' ]) ? $ setting ['method ' ] : 'POST ' ;
85
- $ script .=<<<EOF
114
+ $ options = isset ($ setting ['options ' ]) ? json_encode ($ setting ['options ' ]) : '[] ' ;
115
+ $ script .= <<<EOF
86
116
$('# {$ setting ['document_id ' ]}').click(function(){
87
- componentPlane (' {$ setting ['url ' ]}',' {$ xhr_url }',' {$ method }');
117
+ new ComponentPlane (' {$ setting ['url ' ]}',' {$ xhr_url }',' {$ method }',null,JSON.parse(' { $ options } ') );
88
118
});
89
119
EOF ;
90
120
Admin::script ($ script );
91
- $ grid ->tools ->append (new class ($ setting ['title ' ],$ setting ['document_id ' ]) extends RowAction {
121
+ $ grid ->tools ->append (new class ($ setting ['title ' ], $ setting ['document_id ' ]) extends RowAction {
92
122
private $ title ;
93
123
private $ document_id ;
94
- public function __construct ($ title ,$ document_id )
124
+
125
+ public function __construct ($ title , $ document_id )
95
126
{
96
127
parent ::__construct ();
97
128
$ this ->title = $ title ;
98
129
$ this ->document_id = $ document_id ;
99
130
}
131
+
100
132
public function render ()
101
133
{
102
134
return <<<EOF
@@ -115,50 +147,55 @@ public function render()
115
147
* 列-多操作添加
116
148
* @param Grid $grid
117
149
* @param array $settings [setting,...]
118
- * setting.document_class 自定义类名
119
- * setting.title 自定义按钮名
120
- * setting.url 加载页地址 url/{id}加参数匹配id
121
- * setting.xhr_url ajax提交地址 url/{id}加参数匹配id
122
- * setting.method ajax提交方法
150
+ * setting.document_class dom节点classname (必须填)
151
+ * setting.title 自定义按钮名 (必须填)
152
+ * setting.url 加载页地址 url/{id}加参数匹配id (必须填)
153
+ * setting.xhr_url ajax提交地址 url/{id}加参数匹配id (选填)
154
+ * setting.method ajax提交方法 (选填)
155
+ * setting.options 弹窗配置项 (选填)
156
+ * options = ['W'=>0.8,'H'=>0.8]
123
157
* @param array $disable ['view','edit','delete']
124
158
*/
125
- public static function makeRowPlaneAction (Grid $ grid ,array $ settings = [
126
- ['document_class ' => '' ,'title ' => '' ,'url ' => '' ,'xhr_url ' => '' ,'method ' => 'POST ' ]
127
- ],array $ disable= [])
159
+ public static function makeRowPlaneAction (Grid $ grid , array $ settings = [
160
+ ['document_class ' => '' , 'title ' => '' , 'url ' => '' , 'xhr_url ' => '' , 'method ' => 'POST ' , ' options ' => [] ]
161
+ ], array $ disable = [])
128
162
{
129
163
$ script = '' ;
130
- foreach ($ settings as $ setting ){
164
+ foreach ($ settings as $ setting ) {
131
165
$ url = $ setting ['url ' ];
132
166
$ method = isset ($ setting ['method ' ]) ? $ setting ['method ' ] : 'POST ' ;
133
167
$ xhr_url = isset ($ setting ['xhr_url ' ]) ? $ setting ['xhr_url ' ] : $ url ;
134
- $ script .=<<<EOF
168
+ $ options = isset ($ setting ['options ' ]) ? json_encode ($ setting ['options ' ]) : '[] ' ;
169
+ $ script .= <<<EOF
135
170
$('. {$ setting ['document_class ' ]}').click(function(){
136
171
let url = ' $ url'.replace('{id}',$(this).attr('data-id'));
137
172
let xhr_url = ' $ xhr_url'.replace('{id}',$(this).attr('data-id'));
138
- componentPlane (url,xhr_url,' {$ method }');
173
+ new ComponentPlane (url,xhr_url,' {$ method }',null,JSON.parse(' { $ options } ') );
139
174
});
140
175
EOF ;
141
176
}
142
177
Admin::script ($ script );
143
- $ grid ->actions (function ($ actions )use ($ settings ,$ disable ) {
178
+ $ grid ->actions (function ($ actions ) use ($ settings , $ disable ) {
144
179
foreach ($ settings as $ setting ) {
145
180
$ actions ->add (new
146
181
class ($ setting ['document_class ' ], $ setting ['title ' ]) extends RowAction {
147
182
private $ title ;
148
183
private $ document_class ;
184
+
149
185
public function __construct ($ document_class , $ title )
150
186
{
151
187
parent ::__construct ();
152
188
$ this ->document_class = $ document_class ;
153
189
$ this ->title = $ title ;
154
190
}
191
+
155
192
public function render ()
156
193
{
157
194
return "<a href='javascript:void(0);' class=' {$ this ->document_class }' data-id=' {$ this ->getKey ()}'> {$ this ->title }</a> " ;
158
195
}
159
196
});
160
197
}
161
- foreach ($ disable as $ dis ){
198
+ foreach ($ disable as $ dis ) {
162
199
$ dis == 'view ' && $ actions ->disableView ();
163
200
$ dis == 'edit ' && $ actions ->disableEdit ();
164
201
$ dis == 'delete ' && $ actions ->disableDelete ();
@@ -167,38 +204,42 @@ public function render()
167
204
}
168
205
169
206
/**
170
- * 列-多操作添加 (旧版图标按钮模式)
207
+ * 列-多操作添加 (旧版图标按钮模式)
171
208
* @param Grid $grid
172
209
* @param array $settings [setting,...]
173
- * setting.document_class 自定义类名
174
- * setting.title 自定义按钮名 (图标css类 fa-edit fa-...)
175
- * setting.url 加载页地址
176
- * setting.xhr_url ajax提交地址
177
- * setting.method ajax提交方法
210
+ * setting.document_class dom节点classname (必须填)
211
+ * setting.title 自定义按钮名 (必须填)
212
+ * setting.url 加载页地址 url/{id}加参数匹配id (必须填)
213
+ * setting.xhr_url ajax提交地址 url/{id}加参数匹配id (选填)
214
+ * setting.method ajax提交方法 (选填)
215
+ * setting.options 弹窗配置项 (选填)
216
+ * options = ['W'=>0.8,'H'=>0.8]
178
217
* @param array $disable ['view','edit','delete']
179
218
*/
180
- public static function _makeRowPlaneAction (Grid $ grid ,array $ settings = [
181
- ['document_class ' => '' ,'title ' => '' ,'url ' => '' ,'xhr_url ' => '' ,'method ' => 'POST ' ]
182
- ],array $ disable= [])
219
+ public static function _makeRowPlaneAction (Grid $ grid , array $ settings = [
220
+ ['document_class ' => '' , 'title ' => '' , 'url ' => '' , 'xhr_url ' => '' , 'method ' => 'POST ' , ' options ' => [] ]
221
+ ], array $ disable = [])
183
222
{
184
223
$ script = '' ;
185
- foreach ($ settings as $ setting ){
224
+ foreach ($ settings as $ setting ) {
186
225
$ url = $ setting ['url ' ];
187
226
$ method = isset ($ setting ['method ' ]) ? $ setting ['method ' ] : 'POST ' ;
188
227
$ xhr_url = isset ($ setting ['xhr_url ' ]) ? $ setting ['xhr_url ' ] : $ url ;
189
- $ script .=<<<EOF
228
+ $ options = isset ($ setting ['options ' ]) ? json_encode ($ setting ['options ' ]) : '[] ' ;
229
+ $ script .= <<<EOF
190
230
$('. {$ setting ['document_class ' ]}').click(function(){
191
231
let url = ' $ url'.replace('{id}',$(this).attr('data-id'));
192
- componentPlane(url,' {$ xhr_url }',' {$ method }');
232
+ let xhr_url = ' $ xhr_url'.replace('{id}',$(this).attr('data-id'));
233
+ new ComponentPlane(url,xhr_url,' {$ method }',null,JSON.parse(' {$ options }'));
193
234
});
194
235
EOF ;
195
236
}
196
237
Admin::script ($ script );
197
- $ grid ->actions (function ($ actions )use ($ settings ,$ disable ) {
238
+ $ grid ->actions (function ($ actions ) use ($ settings , $ disable ) {
198
239
foreach ($ settings as $ setting ) {
199
240
$ actions ->append ("<a data-id=' {$ actions ->getKey ()}' href='javascript:void(0);' class=' {$ setting ['document_class ' ]}'><i class='fa {$ setting ['title ' ]}'></i></a> " );
200
241
}
201
- foreach ($ disable as $ dis ){
242
+ foreach ($ disable as $ dis ) {
202
243
$ dis == 'view ' && $ actions ->disableView ();
203
244
$ dis == 'edit ' && $ actions ->disableEdit ();
204
245
$ dis == 'delete ' && $ actions ->disableDelete ();
@@ -249,28 +290,4 @@ public static function result($success = true, $message = 'OK', $data = [])
249
290
->header ('Content-Type ' , 'application/json;charset=utf-8 ' )
250
291
->header ('Access-Control-Allow-Origin ' , '* ' );
251
292
}
252
-
253
- /**
254
- * @param array $data
255
- * @return false|string
256
- */
257
- public static function safeJson (array $ data )
258
- {
259
- self ::recursiveJsonArray ($ data );
260
- return json_encode ($ data , JSON_UNESCAPED_UNICODE );
261
- }
262
-
263
- /**
264
- * @param array $data
265
- */
266
- private static function recursiveJsonArray (array &$ data )
267
- {
268
- foreach ($ data as &$ d ) {
269
- if (is_array ($ d )) {
270
- self ::recursiveJsonArray ($ d );
271
- } else {
272
- $ d = str_replace (['" ' , '\'' , ': ' , '\\' , '{ ' , '} ' , '[ ' , '] ' ,'` ' ], '' , $ d );
273
- }
274
- }
275
- }
276
- }
293
+ }
0 commit comments