* zin: support to set priList and severityList data automatically.

This commit is contained in:
sunhao
2024-03-06 10:26:02 +08:00
parent 04373fbfa4
commit 18dd95131b
3 changed files with 43 additions and 5 deletions
+27 -3
View File
@@ -118,9 +118,13 @@ class dtable extends wg
*/
public function initCols(string $module)
{
global $app;
$colConfigs = $this->prop('cols');
$dataPairs = $this->prop('userMap', array());
global $app, $lang;
$colConfigs = $this->prop('cols');
$dataPairs = $this->prop('userMap', array());
$hasPriCols = false;
$hasSeverityCols = false;
foreach($colConfigs as $field => &$config)
{
if(is_object($config)) $config = (array)$config;
@@ -140,9 +144,29 @@ class dtable extends wg
$delimiter = is_string($config['delimiter']) ? $config['delimiter'] : ',';
$config['map'] = jsRaw("(value) => {return window.setMultipleCell(value, '" . json_encode($dataPairs). "', '{$delimiter}')}");
}
if(isset($config['type']) && $config['type'] === 'pri')
{
$hasPriCols = true;
}
if(isset($config['type']) && $config['type'] === 'severity')
{
$hasSeverityCols = true;
}
}
$this->setProp('cols', array_values($colConfigs));
if($hasPriCols && !$this->prop('priList'))
{
$moduleName = $app->getModuleName();
if(isset($lang->$moduleName->priList)) $this->setProp('priList', $lang->$moduleName->priList);
}
if($hasSeverityCols && !$this->prop('severityList'))
{
$moduleName = $app->getModuleName();
if(isset($lang->$moduleName->severityList)) $this->setProp('severityList', $lang->$moduleName->severityList);
}
}
/**
+8 -1
View File
@@ -6,7 +6,7 @@ class priLabel extends wg
{
protected static array $defineProps = array(
'pri: int|string', // 优先级的值。
'text?: string|array' // 优先级显示的文本或优先级文本映射对象。
'text?: string|array' // 优先级显示的文本或优先级文本映射对象,如果不指定从 $lang->$moduleName->priList 中获取。
);
protected function onAddChild(mixed $child)
@@ -32,6 +32,13 @@ class priLabel extends wg
$pri = $this->prop('pri', 0);
$text = $this->prop('text');
if(is_null($text))
{
global $app, $lang;
$moduleName = $app->getModuleName();
if(isset($lang->$moduleName->priList)) $text = $lang->$moduleName->priList;
}
if(is_array($text)) $text = isset($text[$pri]) ? $text[$pri] : null;
$pri = trim("$pri");
+8 -1
View File
@@ -6,7 +6,7 @@ class severityLabel extends wg
{
protected static array $defineProps = array(
'level: string|int', // 严重程度等级。
'text?: string|array', // 标签文本或标签文本映射对象。
'text?: string|array', // 标签文本或标签文本映射对象,如果不指定从 $lang->$moduleName->severityList 中获取。
'isIcon?: bool=false' // 是否显示为图标。
);
@@ -34,6 +34,13 @@ class severityLabel extends wg
$text = $this->prop('text');
$isIcon = $this->prop('isIcon');
if(is_null($text))
{
global $app, $lang;
$moduleName = $app->getModuleName();
if(isset($lang->$moduleName->severityList)) $text = $lang->$moduleName->severityList;
}
if(is_array($text)) $text = isset($text[$level]) ? $text[$level] : null;
$level = trim("$level");