On this page
8 定制主题风格
概述
默认情况下,Zabbix 提供了多个预定义的前端 主题。 要创建自定义主题,请按照此处提供的分步流程进行操作。
第 1 步:创建您的主题
要创建您自己的主题:
- 从头创建一个 CSS 文件,或者从
assets/styles/目录中复制一个现有主题(例如blue-theme.css、dark-theme.css或其他主题)并进行修改。 - 将您的主题(例如
custom-theme.css)保存到assets/styles/目录中。
第 2 步:在主题列表中启用你的主题
要使你的自定义主题在前端中可用,必须将其添加到 APP::getThemes() 方法返回的主题列表中。
这可以通过在 APP 类中重写 ZBase::getThemes() 方法来实现,如下所示:
- 打开
include/classes/core/APP.php文件并找到APP类:
class APP extends ZBase {
}
- 在类内部、最终结束括号
}之前,添加以下方法:
public static function getThemes() {
return array_merge(parent::getThemes(), [
'custom-theme' => _('Custom theme')
]);
}
其中:
custom-theme- 主题的内部标识符,必须与 CSS 文件名一致,但不包括.css扩展名;Custom theme- 你将在前端中看到的显示名称。
要添加多个主题,请将它们列在数组中,并用逗号分隔每一项。 最后一项后面的尾随逗号是可选的。
例如:
public static function getThemes() {
return array_merge(parent::getThemes(), [
'custom-theme' => _('Custom theme'),
'anothertheme' => _('Another theme'),
'onemoretheme' => _('One more theme')
]);
}
更改图形颜色
要更改图形颜色,必须在 graph_theme 数据库表中为新主题添加一条记录。
在 MySQL/MariaDB 数据库中添加记录的示例:
mysql -u zabbix -p
# Enter password:
mysql> USE zabbix;
mysql> INSERT INTO graph_theme (
graphthemeid,
theme,
backgroundcolor,
graphcolor,
gridcolor,
maingridcolor,
gridbordercolor,
textcolor,
highlightcolor,
leftpercentilecolor,
rightpercentilecolor,
nonworktimecolor,
colorpalette
)
VALUES (
5,
'custom-theme',
'FFFFFF',
'FFFFFF',
'CCD5D9',
'ACBBC2',
'ACBBC2',
'1F2C33',
'CC745E',
'5ECCAB',
'CC745E',
'EBEBEB',
'329F7E,C2583D,346D91,B26E44,CC6C91,7A6DC2,C4AA56,7C2731,BF75B8,73A350,B04833,633A60,879CCC,7FAD6C,324978,3F5C3D,795C94,D66B58,732230,809C5D,C79DD1'
);