@@ -19,13 +19,15 @@ public function render()
19
19
$ limit = isset ($ this ->attributes ['limit ' ]) ? (int )$ this ->attributes ['limit ' ] : 0 ;
20
20
$ width = isset ($ this ->attributes ['width ' ]) ? $ this ->attributes ['width ' ] : '100% ' ;
21
21
$ height = isset ($ this ->attributes ['height ' ]) ? $ this ->attributes ['height ' ] : '200px ' ;
22
- $ menu_mode = isset ($ this ->attributes ['mode ' ]) && $ this ->attributes ['mode ' ] === true ? 'true ' : 'false ' ;
23
- $ menu_placeholder = isset ($ this ->attributes ['placeholder ' ]) ? $ this ->attributes ['placeholder ' ] : '未选择 ' ;
22
+ $ menu = json_encode ([
23
+ 'mode ' =>isset ($ this ->attributes ['mode ' ]) && $ this ->attributes ['mode ' ] === true ? true : false ,
24
+ 'placeholder ' =>isset ($ this ->attributes ['placeholder ' ]) ? $ this ->attributes ['placeholder ' ] : '未选择 ' ,
25
+ 'height ' =>isset ($ this ->attributes ['menu_height ' ]) ? $ this ->attributes ['menu_height ' ] : '150px ' ]);
24
26
$ this ->addVariables (['width ' => $ width , 'height ' => $ height ]);
25
27
$ select = json_encode ($ this ->options , JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
26
28
$ selected = json_encode ($ this ->checked );
27
29
$ this ->script = <<<EOT
28
- new ComponentDot(" {$ id }",JSON.parse(' {$ select }'),JSON.parse(' {$ selected }'), {$ limit }, {$ menu_mode } ,' { $ menu_placeholder } ' );
30
+ new ComponentDot(" {$ id }",JSON.parse(' {$ select }'),JSON.parse(' {$ selected }'), {$ limit }, {$ menu } );
29
31
EOT ;
30
32
return parent ::render ();
31
33
}
@@ -36,26 +38,24 @@ public function render()
36
38
* @param array $select 全部选项
37
39
* @param array $selected 已选择id组 [1,2,3...]
38
40
* @param int $limit 选择限制数 默认0:无限
39
- * @param array $style 组件样式设置 宽:width 高:height
40
- * @param array $menu 组件外观模式配置
41
- * menu.mode false:默认DOT模式 true:下拉列表模式
42
- * menu.placeholder 下拉列表模式开启时 默认未选择占位
41
+ * @param array $setting 组件配置
42
+ * mode 选择器下拉列表模式 false:默认经典模式 true:下拉模式
43
+ * placeholder 下拉列表默认展位
44
+ * width 容器宽 例.100% 100px
45
+ * height 容器高 例.200px
46
+ * menu_height 下拉列表高度限制 例.200px
43
47
* @return string
44
48
*/
45
- public static function panel ($ name , array $ select , array $ selected , int $ limit = 0 , array $ style = [], $ menu = [ ' mode ' => false , ' placeholder ' => ' 请选择 ' ])
49
+ public static function panel ($ name , array $ select , array $ selected , int $ limit = 0 , array $ setting = [])
46
50
{
47
51
$ selected = json_encode ($ selected , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
48
52
$ select = json_encode ($ select , JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
49
- $ style = array_merge (['width ' => '100% ' , 'height ' => '200px ' ], $ style );
50
- $ style_string = '' ;
51
- foreach ($ style as $ k => $ s ) {
52
- $ style_string .= "$ k: $ s; " ;
53
- }
54
- $ menu = array_merge (['mode ' =>false ,'placeholder ' =>'请选择 ' ], $ style );
55
- $ menu_mode = isset ($ menu ['mode ' ]) && $ menu ['mode ' ] === true ? 'true ' : 'false ' ;
53
+ $ setting = array_merge (['mode ' =>false ,'placeholder ' =>'请选择 ' ,'width ' => '100% ' ,'height ' =>'200px ' ,'menu_height ' =>'150px ' ], $ setting );
54
+ $ style = $ setting ['mode ' ] === true ? "witdh: {$ setting ['width ' ]}; " : "witdh: {$ setting ['width ' ]};height: {$ setting ['height ' ]}" ;
56
55
56
+ $ menu = json_encode (['mode ' =>$ setting ['mode ' ],'placeholder ' =>$ setting ['placeholder ' ],'height ' =>$ setting ['menu_height ' ]]);
57
57
return <<<EOF
58
- <div id=" {$ name }" style=" $ style_string "></div><script>new ComponentDot(" {$ name }",JSON.parse(' {$ select }'),JSON.parse(' {$ selected }'), {$ limit }, {$ menu_mode } , { $ menu[ ' placeholder ' ] });</script>
58
+ <div id=" {$ name }" style=" $ style "></div><script>new ComponentDot(" {$ name }",JSON.parse(' {$ select }'),JSON.parse(' {$ selected }'), {$ limit }, {$ menu} });</script>
59
59
EOF ;
60
60
}
61
61
}
0 commit comments