@@ -18,46 +18,87 @@ class ComponentViewer
18
18
/**
19
19
* 点
20
20
* @param Form $form
21
- * @param $column
22
- * @param $title
23
- * @param array $select
24
- * @param array $selected
21
+ * @param string $column 字段名
22
+ * @param string $title 名称
23
+ * @param array $select 全部选项
24
+ * @param array $selected 已选择选项
25
+ * @param bool $strict json严格模式
25
26
*/
26
- public static function makeComponentDot (Form $ form ,$ column ,$ title ,$ select= [],$ selected=[] )
27
+ public static function makeComponentDot (Form $ form , string $ column , string $ title , array $ select = [], array $ selected = [], bool $ strict = true )
27
28
{
28
- $ select =self ::safeJson ($ select );
29
- $ selected =self ::safeJson ($ selected );
29
+ if ($ strict ) {
30
+ $ select = self ::safeJson ($ select );
31
+ $ selected = self ::safeJson ($ selected );
32
+ } else {
33
+ $ select = json_encode ($ select , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS );
34
+ $ selected = json_encode ($ selected , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS );
35
+ }
30
36
self ::script (<<<EOF
31
37
componentDot(" {$ column }",JSON.parse(' $ selected'),JSON.parse(' $ select'));
32
38
EOF
33
39
);
34
- $ form ->html ("<div id=' {$ column }'></div> " ,$ title );
40
+ $ form ->html ("<div id=' {$ column }'></div> " , $ title );
35
41
}
36
42
37
43
/**
38
44
* 线
39
45
* @param Form $form
40
- * @param $column
41
- * @param $title
42
- * @param $setting
43
- * @param array $data
46
+ * @param string $column 字段名
47
+ * @param string $title 名称
48
+ * @param array $settings 设置项
49
+ * @param array $data 数据
50
+ * @param bool $strict json严格模式
44
51
*/
45
- public static function makeComponentLine (Form $ form ,$ column ,$ title ,array $ setting , array $ data=[] )
52
+ public static function makeComponentLine (Form $ form , string $ column , string $ title , array $ settings = [], array $ data = [], bool $ strict = true )
46
53
{
47
- $ setting = self ::safeJson ($ setting );
54
+ if ($ strict ) {
55
+ $ data = self ::safeJson ($ data );
56
+ }else {
57
+ $ data = json_encode ($ data , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS );
58
+ }
48
59
$ data = self ::safeJson ($ data );
49
60
self ::script (<<<EOF
50
- componentLine(" {$ column }",JSON.parse(' $ setting '),JSON.parse(' $ data'));
61
+ componentLine(" {$ column }",JSON.parse(' $ settings '),JSON.parse(' $ data'));
51
62
EOF
52
63
);
53
- $ form ->html ("<div id=' {$ column }'></div> " ,$ title );
64
+ $ form ->html ("<div id=' {$ column }'></div> " , $ title );
65
+ }
66
+
67
+ /**
68
+ * 创建弹窗页-按钮
69
+ * @param Grid $grid
70
+ */
71
+ public static function makePlaneAction (Grid $ grid ,$ class ='' )
72
+ {
73
+ $ url = Request::capture ()->getPathInfo ();
74
+ Admin::script (<<<EOF
75
+ $('. {$ class }').click(function(){
76
+ componentPlane(' {$ url }/create');
77
+ });
78
+ EOF
79
+ );
80
+ $ grid ->disableCreateButton ();
81
+ $ grid ->tools ->append (new
82
+ class extends RowAction {
83
+ public function render ()
84
+ {
85
+ return <<<EOF
86
+ <div class="btn-group pull-right grid-create-btn" style="margin-right: 10px">
87
+ <a href='javascript:void(0);' class="btn btn-sm btn-success CAForm" title="新增">
88
+ <i class="fa fa-plus"></i><span class="hidden-xs"> 新增</span>
89
+ </a>
90
+ </div>
91
+ EOF ;
92
+ }
93
+ });
54
94
}
55
95
56
96
/**
57
97
* 创建弹窗新增表单-按钮
58
98
* @param Grid $grid
59
99
*/
60
- public static function makeAddFormAction (Grid $ grid ){
100
+ public static function makeAddFormAction (Grid $ grid )
101
+ {
61
102
$ url = Request::capture ()->getPathInfo ();
62
103
Admin::script (<<<EOF
63
104
$('.CAForm').click(function(){
@@ -67,8 +108,7 @@ public static function makeAddFormAction(Grid $grid){
67
108
);
68
109
$ grid ->disableCreateButton ();
69
110
$ grid ->tools ->append (new
70
- class extends RowAction
71
- {
111
+ class extends RowAction {
72
112
public function render ()
73
113
{
74
114
return <<<EOF
@@ -100,8 +140,7 @@ public static function makeEditFormAction(Grid $grid)
100
140
);
101
141
102
142
$ actions ->add (new
103
- class extends RowAction
104
- {
143
+ class extends RowAction {
105
144
public function render ()
106
145
{
107
146
$ id = $ this ->getKey ();
@@ -112,8 +151,7 @@ public function render()
112
151
}
113
152
114
153
/**
115
- * 创建弹窗修改表单-按钮
116
- * 旧版图标模式
154
+ * 创建弹窗修改表单-按钮 (旧版图标模式)
117
155
* @param Grid $grid
118
156
*/
119
157
public static function _makeEditFormAction (Grid &$ grid )
@@ -134,7 +172,7 @@ public static function _makeEditFormAction(Grid &$grid)
134
172
}
135
173
136
174
/**
137
- * 弹窗表单内容生成
175
+ * 弹窗表单视图生成
138
176
* @param Content $content
139
177
* @return array|string
140
178
* @throws \Throwable
@@ -154,14 +192,14 @@ public static function makeForm(Content $content)
154
192
* @param array $data
155
193
* @return \Illuminate\Http\JsonResponse
156
194
*/
157
- public static function result ($ success= true ,$ message= 'OK ' ,$ data= [])
195
+ public static function result ($ success = true , $ message = 'OK ' , $ data = [])
158
196
{
159
197
return response ()->json ([
160
- 'code ' => $ success? 0 : 1 ,
161
- 'data ' => $ data ,
162
- 'message ' => $ message
163
- ],200 )
164
- ->header ('Content-Type ' ,'application/json;charset=utf-8 ' )
198
+ 'code ' => $ success ? 0 : 1 ,
199
+ 'data ' => $ data ,
200
+ 'message ' => $ message
201
+ ], 200 )
202
+ ->header ('Content-Type ' , 'application/json;charset=utf-8 ' )
165
203
->header ('Access-Control-Allow-Origin ' , '* ' );
166
204
}
167
205
@@ -189,16 +227,16 @@ public static function script($script)
189
227
protected static function safeJson (array $ data )
190
228
{
191
229
self ::recursiveJsonArray ($ data );
192
- return strip_tags (json_encode ($ data ,JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS ));
230
+ return strip_tags (json_encode ($ data , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS ));
193
231
}
194
232
195
233
private static function recursiveJsonArray (array &$ data )
196
234
{
197
- foreach ($ data as &$ d ){
198
- if (is_array ($ d )){
235
+ foreach ($ data as &$ d ) {
236
+ if (is_array ($ d )) {
199
237
self ::recursiveJsonArray ($ d );
200
- }else {
201
- $ d = str_replace (['" ' ,'\'' ,': ' ,'\\' ,'/ ' ,'{ ' ,'} ' ,'[ ' ,'] ' ],'' ,$ d );
238
+ } else {
239
+ $ d = str_replace (['" ' , '\'' , ': ' , '\\' , '/ ' , '{ ' , '} ' , '[ ' , '] ' ], '' , $ d );
202
240
}
203
241
}
204
242
}
0 commit comments