feat: support custom css
This commit is contained in:
+28
-4
@@ -46,9 +46,12 @@ spec:
|
||||
value: "system"
|
||||
- $formkit: select
|
||||
name: dark_color_schema
|
||||
id: dark_color_schema
|
||||
label: 深色模式配色方案
|
||||
value: "night"
|
||||
options:
|
||||
- label: "custom"
|
||||
value: "custom"
|
||||
- label: "day"
|
||||
value: "day"
|
||||
- label: "night"
|
||||
@@ -63,19 +66,27 @@ spec:
|
||||
value: "hopbush"
|
||||
- label: "pistachio"
|
||||
value: "pistachio"
|
||||
- label: "hopbush"
|
||||
value: "hopbush"
|
||||
- label: "blue"
|
||||
value: "blue"
|
||||
- label: "studio"
|
||||
value: "studio"
|
||||
- label: "vanilla"
|
||||
value: "vanilla"
|
||||
- $formkit: text
|
||||
name: custom_dark
|
||||
if: "$get(dark_color_schema).value === 'custom'"
|
||||
value: ""
|
||||
help: "在此填写自定义配色的名称"
|
||||
validation: "required"
|
||||
|
||||
- $formkit: select
|
||||
name: light_color_schema
|
||||
id: light_color_schema
|
||||
label: 浅色模式配色方案
|
||||
value: "day"
|
||||
options:
|
||||
- label: "custom"
|
||||
value: "custom"
|
||||
- label: "day"
|
||||
value: "day"
|
||||
- label: "night"
|
||||
@@ -90,14 +101,27 @@ spec:
|
||||
value: "hopbush"
|
||||
- label: "pistachio"
|
||||
value: "pistachio"
|
||||
- label: "hopbush"
|
||||
value: "hopbush"
|
||||
- label: "blue"
|
||||
value: "blue"
|
||||
- label: "studio"
|
||||
value: "studio"
|
||||
- label: "vanilla"
|
||||
value: "vanilla"
|
||||
- $formkit: text
|
||||
name: custom_light
|
||||
if: "$get(light_color_schema).value === 'custom'"
|
||||
value: ""
|
||||
help: "在此填写自定义配色的名称"
|
||||
validation: "required"
|
||||
|
||||
- $formkit: code
|
||||
name: custom
|
||||
label: 自定义样式
|
||||
language: css
|
||||
height: 150px
|
||||
value: ""
|
||||
help: 可填写自定义的 CSS, 会覆盖主题的样式
|
||||
|
||||
- group: icp
|
||||
label: 备案设置
|
||||
formSchema:
|
||||
|
||||
@@ -10,13 +10,23 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<title th:text="${title}"></title>
|
||||
<script no-pjax th:inline="javascript">
|
||||
const dark_theme = /*[[${theme.config.style.dark_color_schema}]]*/;
|
||||
const light_theme = /*[[${theme.config.style.light_color_schema}]]*/;
|
||||
let dark_theme = /*[[${theme.config.style.dark_color_schema}]]*/;
|
||||
let light_theme = /*[[${theme.config.style.light_color_schema}]]*/;
|
||||
const default_mode = /*[[${theme.config.style.default_schema_mode}]]*/;
|
||||
|
||||
if (dark_theme === 'custom') {
|
||||
dark_theme = /*[[${theme.config.style.custom_dark}]]*/
|
||||
}
|
||||
if (light_theme === 'custom') {
|
||||
light_theme = /*[[${theme.config.style.custom_light}]]*/
|
||||
}
|
||||
|
||||
let storedMode = localStorage.getItem("theme-mode");
|
||||
|
||||
function getSystemScheme() {
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
function applyTheme(mode) {
|
||||
const actualMode = mode === 'system' ? getSystemScheme() : mode;
|
||||
const targetTheme = actualMode === "light" ? light_theme : dark_theme;
|
||||
@@ -50,6 +60,16 @@
|
||||
<script no-pjax type="module" th:src="@{/assets/dist/main.js?v={version}(version=${theme.spec.version})}"></script>
|
||||
<script no-pjax type="module" th:if="${theme.config.basic.pjax}"
|
||||
th:src="@{/assets/dist/libs/pjax.js?v={version}(version=${theme.spec.version})}"></script>
|
||||
<script no-pjax th:inline="javascript">
|
||||
function applyRawCss(text) {
|
||||
const style = document.createElement('style');
|
||||
style.textContent = text;
|
||||
document.head.appendChild(style);
|
||||
}
|
||||
|
||||
const custom = /*[[${theme.config.style.custom}]]*/;
|
||||
applyRawCss(custom);
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user