Skip to content

Commit bd9671f

Browse files
committed
v1
1 parent f6d6b6a commit bd9671f

File tree

3 files changed

+190
-77
lines changed

3 files changed

+190
-77
lines changed

org/ComponentViewer.php

Lines changed: 73 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,87 @@ class ComponentViewer
1818
/**
1919
* 点
2020
* @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严格模式
2526
*/
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)
2728
{
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+
}
3036
self::script(<<<EOF
3137
componentDot("{$column}",JSON.parse('$selected'),JSON.parse('$select'));
3238
EOF
3339
);
34-
$form->html("<div id='{$column}'></div>",$title);
40+
$form->html("<div id='{$column}'></div>", $title);
3541
}
3642

3743
/**
3844
* 线
3945
* @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严格模式
4451
*/
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)
4653
{
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+
}
4859
$data = self::safeJson($data);
4960
self::script(<<<EOF
50-
componentLine("{$column}",JSON.parse('$setting'),JSON.parse('$data'));
61+
componentLine("{$column}",JSON.parse('$settings'),JSON.parse('$data'));
5162
EOF
5263
);
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">&nbsp;&nbsp;新增</span>
89+
</a>
90+
</div>
91+
EOF;
92+
}
93+
});
5494
}
5595

5696
/**
5797
* 创建弹窗新增表单-按钮
5898
* @param Grid $grid
5999
*/
60-
public static function makeAddFormAction(Grid $grid){
100+
public static function makeAddFormAction(Grid $grid)
101+
{
61102
$url = Request::capture()->getPathInfo();
62103
Admin::script(<<<EOF
63104
$('.CAForm').click(function(){
@@ -67,8 +108,7 @@ public static function makeAddFormAction(Grid $grid){
67108
);
68109
$grid->disableCreateButton();
69110
$grid->tools->append(new
70-
class extends RowAction
71-
{
111+
class extends RowAction {
72112
public function render()
73113
{
74114
return <<<EOF
@@ -100,8 +140,7 @@ public static function makeEditFormAction(Grid $grid)
100140
);
101141

102142
$actions->add(new
103-
class extends RowAction
104-
{
143+
class extends RowAction {
105144
public function render()
106145
{
107146
$id = $this->getKey();
@@ -112,8 +151,7 @@ public function render()
112151
}
113152

114153
/**
115-
* 创建弹窗修改表单-按钮
116-
* 旧版图标模式
154+
* 创建弹窗修改表单-按钮 (旧版图标模式)
117155
* @param Grid $grid
118156
*/
119157
public static function _makeEditFormAction(Grid &$grid)
@@ -134,7 +172,7 @@ public static function _makeEditFormAction(Grid &$grid)
134172
}
135173

136174
/**
137-
* 弹窗表单内容生成
175+
* 弹窗表单视图生成
138176
* @param Content $content
139177
* @return array|string
140178
* @throws \Throwable
@@ -154,14 +192,14 @@ public static function makeForm(Content $content)
154192
* @param array $data
155193
* @return \Illuminate\Http\JsonResponse
156194
*/
157-
public static function result($success=true,$message='OK',$data=[])
195+
public static function result($success = true, $message = 'OK', $data = [])
158196
{
159197
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')
165203
->header('Access-Control-Allow-Origin', '*');
166204
}
167205

@@ -189,16 +227,16 @@ public static function script($script)
189227
protected static function safeJson(array $data)
190228
{
191229
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));
193231
}
194232

195233
private static function recursiveJsonArray(array &$data)
196234
{
197-
foreach ($data as &$d){
198-
if(is_array($d)){
235+
foreach ($data as &$d) {
236+
if (is_array($d)) {
199237
self::recursiveJsonArray($d);
200-
}else{
201-
$d = str_replace(['"','\'',':','\\','/','{','}','[',']'],'',$d);
238+
} else {
239+
$d = str_replace(['"', '\'', ':', '\\', '/', '{', '}', '[', ']'], '', $d);
202240
}
203241
}
204242
}

resources/assets/component.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,11 @@ function componentPlane(url,method='POST'){
325325
_componentMegaBlock._request(url,'GET',{},function (response) {
326326
Form._loading(true);
327327
$('.modal-body').append(response);
328-
$('.modal-body button[type="submit"]').click(function (){
329-
Form._submitEvent(this,url)
330-
});
328+
if($('.modal-body button[type="submit"]')) {
329+
$('.modal-body button[type="submit"]').click(function () {
330+
Form._submitEvent(this, url)
331+
});
332+
}
331333
});
332334
},
333335
_submitEvent:function (obj,url) {

0 commit comments

Comments
 (0)