* zin: optimize priLabel and severityLabel widget.
This commit is contained in:
@@ -5,27 +5,43 @@ namespace zin;
|
||||
class priLabel extends wg
|
||||
{
|
||||
protected static array $defineProps = array(
|
||||
'pri: int|string'
|
||||
'pri: int|string', // 优先级的值。
|
||||
'text?: string|array' // 优先级显示的文本或优先级文本映射对象。
|
||||
);
|
||||
|
||||
protected function onAddChild(mixed $child): mixed
|
||||
{
|
||||
if(is_string($child) && !$this->props->has('pri'))
|
||||
if(is_string($child) || is_int($child))
|
||||
{
|
||||
$this->props->set('pri', $child);
|
||||
return false;
|
||||
if(!$this->props->has('pri'))
|
||||
{
|
||||
$this->props->set('pri', $child);
|
||||
return false;
|
||||
}
|
||||
if(!$this->props->has('text') && is_string($child))
|
||||
{
|
||||
$this->props->set('text', $child);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $child;
|
||||
}
|
||||
|
||||
protected function build(): wg
|
||||
{
|
||||
$pri = $this->prop('pri');
|
||||
$pri = $this->prop('pri', 0);
|
||||
$text = $this->prop('text');
|
||||
|
||||
if(is_array($text)) $text = isset($text[$pri]) ? $text[$pri] : null;
|
||||
|
||||
$pri = trim("$pri");
|
||||
if($text === null) $text = ($pri === '0' || $pri === '') ? '' : $pri;
|
||||
|
||||
return span
|
||||
(
|
||||
set($this->getRestProps()),
|
||||
setClass("pri-$pri"),
|
||||
$pri
|
||||
$text
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,26 +5,41 @@ namespace zin;
|
||||
class severityLabel extends wg
|
||||
{
|
||||
protected static array $defineProps = array(
|
||||
'text?: string', // 标签文本
|
||||
'level?: string|int', // 严重程度等级
|
||||
'isIcon?: bool=false' // 是否显示为图标
|
||||
'level: string|int', // 严重程度等级。
|
||||
'text?: string|array', // 标签文本或标签文本映射对象。
|
||||
'isIcon?: bool=false' // 是否显示为图标。
|
||||
);
|
||||
|
||||
protected function onAddChild(mixed $child): mixed
|
||||
{
|
||||
if(is_string($child) && !$this->props->has('text'))
|
||||
if(is_string($child) || is_int($child))
|
||||
{
|
||||
$this->props->set('text', $child);
|
||||
return false;
|
||||
if(!$this->props->has('level'))
|
||||
{
|
||||
$this->props->set('level', $child);
|
||||
return false;
|
||||
}
|
||||
if(!$this->props->has('text') && is_string($child))
|
||||
{
|
||||
$this->props->set('text', $child);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $child;
|
||||
}
|
||||
|
||||
protected function build(): wg
|
||||
{
|
||||
$level = $this->prop('level', 0);
|
||||
$text = $this->prop('text');
|
||||
$level = $this->prop('level');
|
||||
$isIcon = $this->prop('isIcon');
|
||||
|
||||
if(is_array($text)) $text = isset($text[$level]) ? $text[$level] : null;
|
||||
|
||||
$level = trim("$level");
|
||||
if($text === null) $text = ($level === '0' || $level === '') ? '' : $level;
|
||||
if($isIcon === null) $isIcon = is_numeric($text);
|
||||
|
||||
return span
|
||||
(
|
||||
set($this->getRestProps()),
|
||||
|
||||
Reference in New Issue
Block a user