@@ -19,39 +19,40 @@ 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
- $ this ->addVariables (['width ' =>$ width ,'height ' => $ height ]);
22
+ $ menu_mode = isset ($ this ->attributes ['menu_mode ' ]) ? (bool )$ this ->attributes ['menu_mode ' ] : false ;
23
+ $ menu_placeholder = isset ($ this ->attributes ['menu_placeholder ' ]) ? $ this ->attributes ['menu_mode ' ] : '未选择 ' ;
24
+ $ this ->addVariables (['width ' => $ width , 'height ' => $ height ]);
23
25
$ select = json_encode ($ this ->options , JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
24
26
$ selected = json_encode ($ this ->checked );
25
27
$ this ->script = <<<EOT
26
- new ComponentDot(" {$ id }",JSON.parse(' {$ selected }'),JSON.parse(' {$ select }'), {$ limit });
28
+ new ComponentDot(" {$ id }",JSON.parse(' {$ selected }'),JSON.parse(' {$ select }'), {$ limit }, { $ menu_mode } ,' { $ menu_placeholder } ' );
27
29
EOT ;
28
30
return parent ::render ();
29
31
}
30
32
31
33
/**
32
34
* 直接调用ComponentDot组件
33
- * @param string $name 名称
34
- * @param array $selected 已选择id组 [1,2,3...]
35
- * @param array $select 全部选项
36
- * @param int $limit 选择限制数 默认0:无限
37
- * @param array $style 组件样式设置 宽:width 高:height
35
+ * @param string $name 名称
36
+ * @param array $selected 已选择id组 [1,2,3...]
37
+ * @param array $select 全部选项
38
+ * @param int $limit 选择限制数 默认0:无限
39
+ * @param array $style 组件样式设置 宽:width 高:height
40
+ * @param boolean $menu_mode 组件模式设置 false:默认模式 true:下拉列表模式
41
+ * @param string $menu_placeholder 下拉列表模式 默认未选择占位
38
42
* @return string
39
43
*/
40
- public static function panel ($ name ,array $ selected ,array $ select ,int $ limit= 1 , array $ style=[] )
44
+ public static function panel ($ name , array $ selected , array $ select , int $ limit = 1 , array $ style = [], $ menu_mode = false , $ menu_placeholder = ' 未选择 ' )
41
45
{
42
46
$ selected = json_encode ($ selected , JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
43
47
$ select = json_encode ($ select , JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT | JSON_HEX_APOS );
44
- $ style = array_merge (['width ' => '100% ' ,'height ' => '200px ' ],$ style );
48
+ $ style = array_merge (['width ' => '100% ' , 'height ' => '200px ' ], $ style );
45
49
$ style_string = '' ;
46
- foreach ($ style as $ k=> $ s ){
47
- $ style_string.= "$ k: $ s; " ;
50
+ foreach ($ style as $ k => $ s ) {
51
+ $ style_string .= "$ k: $ s; " ;
48
52
}
49
53
50
54
return <<<EOF
51
- <div id=" {$ name }" style=" $ style_string"></div>
52
- <script>
53
- new ComponentDot(" {$ name }",JSON.parse(' {$ selected }'),JSON.parse(' {$ select }'), {$ limit });
54
- </script>
55
+ <div id=" {$ name }" style=" $ style_string"></div><script>new ComponentDot(" {$ name }",JSON.parse(' {$ selected }'),JSON.parse(' {$ select }'), {$ limit }, {$ menu_mode }, {$ menu_placeholder });</script>
55
56
EOF ;
56
57
}
57
58
}
0 commit comments