diff --git a/web/src/common/utils/applySkinConfig.ts b/web/src/common/utils/applySkinConfig.ts new file mode 100644 index 00000000..1d489d17 --- /dev/null +++ b/web/src/common/utils/applySkinConfig.ts @@ -0,0 +1,21 @@ +export default function (skinConfig: any) { + const root = document.documentElement + const { themeConf, backgroundConf, contentConf } = skinConfig + + if (themeConf?.color) { + // 设置主题颜色 + root.style.setProperty('--primary-color', themeConf?.color) + } + + // 设置背景 + const { color, type, image } = backgroundConf || {} + root.style.setProperty( + '--primary-background', + type === 'image' ? `url(${image}) no-repeat center / cover` : color + ) + + if (contentConf?.opacity.toString()) { + // 设置全局透明度 + root.style.setProperty('--opacity', `${contentConf.opacity / 100}`) + } +} diff --git a/web/src/management/pages/edit/index.vue b/web/src/management/pages/edit/index.vue index 704e0593..6f5425fa 100644 --- a/web/src/management/pages/edit/index.vue +++ b/web/src/management/pages/edit/index.vue @@ -14,22 +14,34 @@ @@ -103,7 +84,7 @@ export default defineComponent({ display: flex; flex-direction: column; align-items: center; - background-color: #f6f7f9; + background: var(--primary-background); } .pagination-wrapper { diff --git a/web/src/render/App.vue b/web/src/render/App.vue index c180f50d..5108916c 100644 --- a/web/src/render/App.vue +++ b/web/src/render/App.vue @@ -6,33 +6,12 @@ import { watch } from 'vue' import { storeToRefs } from 'pinia' import { useSurveyStore } from './stores/survey' +import applySkinConfig from '@/common/utils/applySkinConfig'; const { skinConf } = storeToRefs(useSurveyStore()) -const updateSkinConfig = (value: any) => { - const root = document.documentElement - const { themeConf, backgroundConf, contentConf } = value - - if (themeConf?.color) { - // 设置主题颜色 - root.style.setProperty('--primary-color', themeConf?.color) - } - - // 设置背景 - const { color, type, image } = backgroundConf || {} - root.style.setProperty( - '--primary-background', - type === 'image' ? `url(${image}) no-repeat center center` : color - ) - - if (contentConf?.opacity.toString()) { - // 设置全局透明度 - root.style.setProperty('--opacity', `${parseInt(contentConf.opacity) / 100}`) - } -} - watch(skinConf, (value) => { - updateSkinConfig(value) + applySkinConfig(value) })