多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

34 lines
858 B

import type { MaybeRef } from '@vueuse/core'
import { unref } from '@vue/reactivity'
import { tryOnScopeDispose } from '#build/imports'
import { useNuxtApp } from '#app'
import theme from '~/utils/colorsUtils'
export default function useColors(darkMode?: MaybeRef<boolean>) {
const scope = effectScope()
let mode = $ref(unref(darkMode))
const { $state } = useNuxtApp()
if (!mode) mode = $state.value.darkMode
scope.run(() => {
watch(
() => $state.value.darkMode,
(newMode) => {
mode = newMode
},
)
watchEffect(() => {
const newMode = unref(darkMode)
if (newMode) mode = newMode
})
})
tryOnScopeDispose(() => scope.stop())
const colors = computed(() => (mode ? theme.dark : theme.light))
return { colors, getColorByIndex: (i: number) => colors.value[i % colors.value.length] }
}