init local code

This commit is contained in:
chenxing
2026-09-07 09:09:39 +08:00
commit 99cd26b3d2
259 changed files with 20554 additions and 0 deletions
@@ -0,0 +1,62 @@
package com.yunhai.cms.service.impl;
import com.yunhai.cms.model.vo.ThemeVo;
import com.yunhai.cms.theme.ThemeInfo;
import com.yunhai.cms.theme.ThemeRegistry;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* 主题管理(方案 §5.1/§5.2):主题列表(含参数 schema)供管理端卡片选择与
* 参数表单动态生成;screenshot 与预览资产经 /api/theme/{name}/asset/** 代理。
*/
@Service
@RequiredArgsConstructor
public class ThemeService {
private final ThemeRegistry themeRegistry;
/** 可用主题(default 优先,其余按名称排序),管理端建站向导与站点编辑共用 */
public List<ThemeVo> list() {
List<ThemeVo> result = new ArrayList<>();
for (ThemeInfo info : themeRegistry.list()) {
result.add(ThemeVo.of(info));
}
return result;
}
/** 未注册主题返回 null(白名单判断用) */
public ThemeInfo get(String name) {
return themeRegistry.get(name);
}
/** 未注册主题抛 PARAM_ERROR(预览接口明确 400 语义,不静默回退,方案 §5.5/T27) */
public ThemeInfo requireRegistered(String name) {
ThemeInfo info = themeRegistry.get(name);
if (info == null) {
throw new com.yunhai.platform.apistd.BizException(
com.yunhai.platform.utils.exception.ErrorCode.PARAM_ERROR, "皮肤包未注册:" + name);
}
return info;
}
/**
* 提取预览 p_* 前缀参数并按主题 schema 过滤(方案 §5.5):
* key 为 theme.json 声明过的,# 由前端 URLSearchParams 自动编码为 %23(容器已解码)。
*/
public java.util.Map<String, String> extractPreviewParams(ThemeInfo info,
java.util.Map<String, String[]> parameterMap) {
java.util.Map<String, Object> raw = new java.util.LinkedHashMap<>();
if (parameterMap != null) {
for (java.util.Map.Entry<String, String[]> e : parameterMap.entrySet()) {
if (e.getKey().startsWith("p_") && e.getValue() != null && e.getValue().length > 0) {
raw.put(e.getKey().substring(2), e.getValue()[0]);
}
}
}
return info.filterValidValues(raw);
}
}