在App.vue中添加主题支持以配置ApexCharts

This commit is contained in:
jxxghp
2025-07-04 08:12:10 +08:00
parent 3186c6ca0e
commit 011902598b
2 changed files with 21 additions and 5 deletions
+20 -1
View File
@@ -45,6 +45,10 @@ declare global {
function configureApexCharts() { function configureApexCharts() {
if (typeof window !== 'undefined' && window.Apex) { if (typeof window !== 'undefined' && window.Apex) {
try { try {
// 获取当前主题
const currentTheme = globalTheme.name.value
const isDark = currentTheme === 'dark' || currentTheme === 'transparent'
// 数据标签 // 数据标签
window.Apex.dataLabels = { window.Apex.dataLabels = {
formatter: function (_: number, { seriesIndex, w }: { seriesIndex: number; w: any }) { formatter: function (_: number, { seriesIndex, w }: { seriesIndex: number; w: any }) {
@@ -65,6 +69,10 @@ function configureApexCharts() {
color: 'rgba(var(--v-theme-on-surface), var(--v-high-emphasis-opacity))', color: 'rgba(var(--v-theme-on-surface), var(--v-high-emphasis-opacity))',
}, },
} }
// 鼠标悬浮提示
window.Apex.tooltip = {
theme: isDark ? 'dark' : 'light',
}
} catch (error) { } catch (error) {
console.warn('ApexCharts 全局配置失败:', error) console.warn('ApexCharts 全局配置失败:', error)
} }
@@ -176,6 +184,17 @@ onMounted(async () => {
// 初始化data-theme属性 // 初始化data-theme属性
updateHtmlThemeAttribute(globalTheme.name.value) updateHtmlThemeAttribute(globalTheme.name.value)
// 监听主题变化
watch(
() => globalTheme.name.value,
newTheme => {
// 更新HTML主题属性
updateHtmlThemeAttribute(newTheme)
// 重新配置ApexCharts以适应新主题
configureApexCharts()
},
)
// 默认隐藏页面 // 默认隐藏页面
show.value = false show.value = false
@@ -249,7 +268,7 @@ onUnmounted(() => {
class="background-image" class="background-image"
:class="{ 'active': index === activeImageIndex }" :class="{ 'active': index === activeImageIndex }"
:style="{ 'backgroundImage': `url(${imageUrl})` }" :style="{ 'backgroundImage': `url(${imageUrl})` }"
></div> />
<!-- 全局磨砂层 --> <!-- 全局磨砂层 -->
<div v-if="isLogin && isTransparentTheme" class="global-blur-layer"></div> <div v-if="isLogin && isTransparentTheme" class="global-blur-layer"></div>
</div> </div>
+1 -4
View File
@@ -67,10 +67,7 @@ const chartOptions = controlledComputed(
animations: { enabled: false }, animations: { enabled: false },
}, },
tooltip: { tooltip: {
enabled: true, enabled: false,
y: {
formatter: (value: number) => formatBytes(value),
},
}, },
grid: { grid: {
borderColor: `rgba(${hexToRgb(String(variableTheme.value['border-color']))},${ borderColor: `rgba(${hexToRgb(String(variableTheme.value['border-color']))},${