From 3c019d13764766c7184102dc7e157a1aa2a54403 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 19 May 2024 14:20:01 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/@core/components/ThemeSwitcher.vue | 72 ++++++++++++++++++++++++++ src/ace-config.ts | 9 ++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6a7a1243..fbab93aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moviepilot", - "version": "1.8.9-1", + "version": "1.9.0", "private": true, "bin": "dist/service.js", "scripts": { diff --git a/src/@core/components/ThemeSwitcher.vue b/src/@core/components/ThemeSwitcher.vue index a7a29874..3f03feb8 100644 --- a/src/@core/components/ThemeSwitcher.vue +++ b/src/@core/components/ThemeSwitcher.vue @@ -4,6 +4,8 @@ import { useTheme } from 'vuetify' import type { ThemeSwitcherTheme } from '@layouts/types' import api from '@/api' import { checkPrefersColorSchemeIsDark } from '@/@core/utils' +import { useToast } from 'vue-toast-notification' +import { VAceEditor } from 'vue3-ace-editor' const props = defineProps<{ themes: ThemeSwitcherTheme[] @@ -18,6 +20,17 @@ const { state: currentThemeName, next: getNextThemeName } = useCycleList( { initialValue: savedTheme.value }, ) +const $toast = useToast() + +// 自定义CSS弹窗 +const cssDialog = ref(false) + +// 自定义 CSS +const customCSS = ref('') + +// 编辑器主题 +const editorTheme = computed(() => (currentThemeName.value === 'light' ? 'github' : 'monokai')) + // 主题切换动画 function themeTransition() { const x = performance.now() @@ -134,6 +147,43 @@ watch( () => currentThemeName.value, () => updateTheme(), ) + +// 获取自定义 CSS +async function getCustomCSS() { + try { + const result: { [key: string]: any } = await api.get('system/setting/UserCustomCSS') + if (result && result.success && result.data?.value) { + customCSS.value = result.data?.value ?? '' + if (customCSS.value) { + const style = document.createElement('style') + style.innerHTML = result.data?.value ?? '' + document.head.appendChild(style) + } + } + } catch (error) { + console.error(error) + } +} + +// 保存自定义 CSS +async function saveCustomCSS() { + cssDialog.value = false + try { + const result: { [key: string]: any } = await api.post('system/setting/UserCustomCSS', customCSS.value, { + headers: { + 'Content-Type': 'text/plain', + }, + }) + + if (result.success) $toast.success('自定义CSS保存成功!') + } catch (e) { + console.error('保存自定义 CSS 到服务端失败') + } +} + +onMounted(() => { + getCustomCSS() +}) {{ theme.title }} + + + 自定义 + + + + + + + + + + + 保存 + + + +