v1.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * The iconPicker widget class file of zin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2024 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Gang Liu <liugang@easycorp.ltd>
  8. * @package zin
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. class iconPicker extends wg
  13. {
  14. /**
  15. * @var mixed[]
  16. */
  17. protected static $defineProps = array(
  18. 'name?: string="icon"', // 控件名称。
  19. 'value?: string="flow"', // 控件默认值。
  20. 'items?: array' // 图标列表项。
  21. );
  22. public static function getPageJS()
  23. {
  24. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  25. }
  26. protected function buildIcons()
  27. {
  28. $icons = [];
  29. $items = $this->prop('items', []);
  30. foreach($items as $icon)
  31. {
  32. $icons[] = button
  33. (
  34. setClass('btn square ghost'),
  35. setData(['icon' => $icon]),
  36. on::click('selectIcon'),
  37. icon($icon)
  38. );
  39. }
  40. return $icons;
  41. }
  42. protected function build()
  43. {
  44. $name = $this->prop('name');
  45. $icon = $this->prop('value');
  46. return div
  47. (
  48. setID('iconPicker'),
  49. button
  50. (
  51. setClass('btn'),
  52. setData(['toggle' => 'dropdown']),
  53. span
  54. (
  55. setID('iconPreview'),
  56. setClass('mr-2'),
  57. icon($icon)
  58. ),
  59. icon('angle-down')
  60. ),
  61. div
  62. (
  63. setClass('dropdown-menu menu w-64'),
  64. $this->buildIcons()
  65. ),
  66. formHidden($name, $icon, setID('icon'))
  67. );
  68. }
  69. }