v1.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * The priPicker widget class file of zin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(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 sunhao<sunhao@easycorp.ltd>
  8. * @package zin
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. /**
  13. * 优先级选择器(priPicker)部件类
  14. * The priPicker widget class
  15. */
  16. class priPicker extends wg
  17. {
  18. /**
  19. * Define widget properties.
  20. *
  21. * @var array
  22. * @access protected
  23. */
  24. protected static $defineProps = array
  25. (
  26. 'id?: string="$GID"', // 组件根元素的 ID。
  27. 'formID?: string', // 组件隐藏的表单元素 ID。
  28. 'className?: string|array', // 类名。
  29. 'style?: array', // 样式。
  30. 'tagName?: string', // 组件根元素的标签名。
  31. 'attrs?: array', // 附加到组件根元素上的属性。
  32. 'clickType?: "toggle"|"open"', // 点击类型,`toggle` 表示点击按钮时切换显示隐藏,`open` 表示点击按钮时只打。
  33. 'afterRender?: function', // 渲染完成后的回调函数。
  34. 'beforeDestroy?: function', // 销毁前的回调函数。
  35. 'name?: string', // 作为表单项的名称。
  36. 'value?: string|string[]', // 默认值。
  37. 'onChange?: function', // 值变更回调函数。
  38. 'disabled?: boolean', // 是否禁用。
  39. 'readonly?: boolean', // 是否只读。
  40. 'multiple?: boolean|number=false', // 是否允许选择多个值,如果指定为数字,则限制多选的数目,默认 `false`。
  41. 'required?: boolean', // 是否必选(不允许空值,不可以被清除)。
  42. 'placeholder?: string', // 选择框上的占位文本。
  43. 'items?: string[]|array' // 选项列表,默认为 $lang->$moduleName->priList。
  44. );
  45. /**
  46. * Build widget.
  47. *
  48. * @access protected
  49. */
  50. protected function build()
  51. {
  52. list($props, $restProps) = $this->props->split(array_keys(static::definedPropsList()));
  53. if(isset($props['id']))
  54. {
  55. $props['_id'] = $props['id'];
  56. unset($props['id']);
  57. }
  58. if(!isset($props['required']) || is_null($props['required'])) $props['required'] = true;
  59. if(isset($restProps['width']))
  60. {
  61. $width = $restProps['width'];
  62. if(is_numeric($width)) $restProps['style']['width'] = "{$width}px";
  63. elseif(str_ends_with($width, 'px')) $restProps['style']['width'] = $width;
  64. else $restProps['class'][] = "w-$width";
  65. }
  66. if(!isset($props['items']))
  67. {
  68. global $app, $lang;
  69. $moduleName = $app->getModuleName();
  70. if(isset($lang->$moduleName->priList)) $props['items'] = $lang->$moduleName->priList;
  71. }
  72. if(isset($props['items'][0])) unset($props['items'][0]);
  73. return zui::priPicker
  74. (
  75. set::_class('form-group-wrapper'),
  76. set::_map(array('value' => 'defaultValue', 'formID' => 'id')),
  77. set::_props($restProps),
  78. set::popWidth('100%'),
  79. set($props),
  80. $this->children()
  81. );
  82. }
  83. }