feat(config): ThemeResp 增加品牌字段 + 公开品牌信息端点
- ThemeResp 新增 brand_name/brand_slogan/brand_features/brand_copyright 字段 - default_theme 提供品牌默认值 - 新增 PublicBrandResp 和 GET /api/v1/public/brand 公开端点(无需认证) - ConfigModule 增加 public_routes 方法 - 更新测试覆盖品牌字段
This commit is contained in:
@@ -7,7 +7,7 @@ use erp_core::rbac::require_permission;
|
||||
use erp_core::types::{ApiResponse, TenantContext};
|
||||
|
||||
use crate::config_state::ConfigState;
|
||||
use crate::dto::{SetSettingParams, ThemeResp};
|
||||
use crate::dto::{PublicBrandResp, SetSettingParams, ThemeResp};
|
||||
use crate::error::ConfigError;
|
||||
use crate::service::setting_service::SettingService;
|
||||
|
||||
@@ -17,6 +17,10 @@ fn default_theme() -> ThemeResp {
|
||||
primary_color: None,
|
||||
logo_url: None,
|
||||
sidebar_style: None,
|
||||
brand_name: Some("HMS 健康管理平台".into()),
|
||||
brand_slogan: Some("新一代健康管理平台".into()),
|
||||
brand_features: Some("患者管理 · 健康监测 · 随访管理 · AI 智能分析".into()),
|
||||
brand_copyright: Some("HMS 健康管理平台 · ©汕头市智界科技有限公司".into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,16 +111,45 @@ where
|
||||
Ok(JsonResponse(ApiResponse::ok(req)))
|
||||
}
|
||||
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/public/brand",
|
||||
responses(
|
||||
(status = 200, description = "成功", body = ApiResponse<PublicBrandResp>),
|
||||
),
|
||||
tag = "主题设置"
|
||||
)]
|
||||
/// GET /api/v1/public/brand
|
||||
///
|
||||
/// 获取公开品牌信息(无需认证)。
|
||||
pub async fn get_public_brand() -> JsonResponse<ApiResponse<PublicBrandResp>> {
|
||||
let defaults = default_theme();
|
||||
JsonResponse(ApiResponse::ok(PublicBrandResp {
|
||||
brand_name: defaults.brand_name.unwrap_or_else(|| "HMS 健康管理平台".into()),
|
||||
brand_slogan: defaults.brand_slogan.unwrap_or_else(|| "新一代健康管理平台".into()),
|
||||
brand_features: defaults
|
||||
.brand_features
|
||||
.unwrap_or_else(|| "患者管理 · 健康监测 · 随访管理 · AI 智能分析".into()),
|
||||
brand_copyright: defaults
|
||||
.brand_copyright
|
||||
.unwrap_or_else(|| "HMS 健康管理平台 · ©汕头市智界科技有限公司".into()),
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn default_theme_all_fields_none() {
|
||||
fn default_theme_has_brand_defaults() {
|
||||
let theme = default_theme();
|
||||
assert!(theme.primary_color.is_none());
|
||||
assert!(theme.logo_url.is_none());
|
||||
assert!(theme.sidebar_style.is_none());
|
||||
assert_eq!(theme.brand_name, Some("HMS 健康管理平台".to_string()));
|
||||
assert_eq!(theme.brand_slogan, Some("新一代健康管理平台".to_string()));
|
||||
assert!(theme.brand_features.is_some());
|
||||
assert!(theme.brand_copyright.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -125,11 +158,15 @@ mod tests {
|
||||
primary_color: Some("#1890ff".to_string()),
|
||||
logo_url: None,
|
||||
sidebar_style: Some("dark".to_string()),
|
||||
brand_name: Some("测试平台".to_string()),
|
||||
brand_slogan: None,
|
||||
brand_features: None,
|
||||
brand_copyright: None,
|
||||
};
|
||||
let json = serde_json::to_string(&theme).unwrap();
|
||||
let back: ThemeResp = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(back.primary_color, Some("#1890ff".to_string()));
|
||||
assert_eq!(back.logo_url, None);
|
||||
assert_eq!(back.sidebar_style, Some("dark".to_string()));
|
||||
assert_eq!(back.brand_name, Some("测试平台".to_string()));
|
||||
assert!(back.brand_slogan.is_none());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user