feat: add useDark
This commit is contained in:
parent
83ae5fdfb5
commit
d73ab2d0ef
10
index.html
10
index.html
@ -6,16 +6,6 @@
|
|||||||
<link rel="apple-touch-icon" href="/pwa-192x192.png" />
|
<link rel="apple-touch-icon" href="/pwa-192x192.png" />
|
||||||
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#00aba9" />
|
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#00aba9" />
|
||||||
<meta name="msapplication-TileColor" content="#00aba9" />
|
<meta name="msapplication-TileColor" content="#00aba9" />
|
||||||
<script>
|
|
||||||
(function () {
|
|
||||||
const prefersDark
|
|
||||||
= window.matchMedia
|
|
||||||
&& window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
||||||
const setting = localStorage.getItem('vueuse-color-scheme') || 'auto'
|
|
||||||
if (setting === 'dark' || (prefersDark && setting !== 'light'))
|
|
||||||
document.documentElement.classList.toggle('dark', true)
|
|
||||||
})()
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="font-sans">
|
<body class="font-sans">
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
const { isDark } = useDark()
|
||||||
|
|
||||||
useHead({
|
useHead({
|
||||||
title: '合肥市南园学校19预科2班',
|
title: '合肥市南园学校19预科2班',
|
||||||
meta: [
|
meta: [
|
||||||
{ name: 'description', content: '合肥市南园学校19预科2班纪念项目' },
|
{ name: 'description', content: '合肥市南园学校19预科2班纪念项目' },
|
||||||
{
|
{
|
||||||
name: 'theme-color',
|
name: 'theme-color',
|
||||||
content: computed(() => isDark.value ? '#00aba9' : '#ffffff'),
|
content: computed(() => isDark ? '#00aba9' : '#ffffff'),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
link: [
|
link: [
|
||||||
|
13
src/auto-imports.d.ts
vendored
13
src/auto-imports.d.ts
vendored
@ -105,6 +105,7 @@ declare global {
|
|||||||
const toRefs: typeof import('vue')['toRefs']
|
const toRefs: typeof import('vue')['toRefs']
|
||||||
const toValue: typeof import('vue')['toValue']
|
const toValue: typeof import('vue')['toValue']
|
||||||
const toggleDark: typeof import('./composables/dark')['toggleDark']
|
const toggleDark: typeof import('./composables/dark')['toggleDark']
|
||||||
|
const toggleTheme: typeof import('./composables/dark')['toggleTheme']
|
||||||
const triggerRef: typeof import('vue')['triggerRef']
|
const triggerRef: typeof import('vue')['triggerRef']
|
||||||
const tryOnBeforeMount: typeof import('@vueuse/core')['tryOnBeforeMount']
|
const tryOnBeforeMount: typeof import('@vueuse/core')['tryOnBeforeMount']
|
||||||
const tryOnBeforeUnmount: typeof import('@vueuse/core')['tryOnBeforeUnmount']
|
const tryOnBeforeUnmount: typeof import('@vueuse/core')['tryOnBeforeUnmount']
|
||||||
@ -148,7 +149,7 @@ declare global {
|
|||||||
const useCssVars: typeof import('vue')['useCssVars']
|
const useCssVars: typeof import('vue')['useCssVars']
|
||||||
const useCurrentElement: typeof import('@vueuse/core')['useCurrentElement']
|
const useCurrentElement: typeof import('@vueuse/core')['useCurrentElement']
|
||||||
const useCycleList: typeof import('@vueuse/core')['useCycleList']
|
const useCycleList: typeof import('@vueuse/core')['useCycleList']
|
||||||
const useDark: typeof import('@vueuse/core')['useDark']
|
const useDark: typeof import('./composables/dark')['useDark']
|
||||||
const useDateFormat: typeof import('@vueuse/core')['useDateFormat']
|
const useDateFormat: typeof import('@vueuse/core')['useDateFormat']
|
||||||
const useDebounce: typeof import('@vueuse/core')['useDebounce']
|
const useDebounce: typeof import('@vueuse/core')['useDebounce']
|
||||||
const useDebounceFn: typeof import('@vueuse/core')['useDebounceFn']
|
const useDebounceFn: typeof import('@vueuse/core')['useDebounceFn']
|
||||||
@ -342,7 +343,6 @@ declare module 'vue' {
|
|||||||
readonly h: UnwrapRef<typeof import('vue')['h']>
|
readonly h: UnwrapRef<typeof import('vue')['h']>
|
||||||
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
|
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
|
||||||
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
||||||
readonly isDark: UnwrapRef<typeof import('./composables/dark')['isDark']>
|
|
||||||
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
|
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
|
||||||
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
||||||
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
|
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
|
||||||
@ -371,7 +371,6 @@ declare module 'vue' {
|
|||||||
readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
|
readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
|
||||||
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
|
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
|
||||||
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
|
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
|
||||||
readonly preferredDark: UnwrapRef<typeof import('./composables/dark')['preferredDark']>
|
|
||||||
readonly provide: UnwrapRef<typeof import('vue')['provide']>
|
readonly provide: UnwrapRef<typeof import('vue')['provide']>
|
||||||
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
|
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
|
||||||
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
|
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
|
||||||
@ -402,7 +401,6 @@ declare module 'vue' {
|
|||||||
readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
|
readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
|
||||||
readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
|
readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
|
||||||
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
|
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
|
||||||
readonly toggleDark: UnwrapRef<typeof import('./composables/dark')['toggleDark']>
|
|
||||||
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
|
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
|
||||||
readonly tryOnBeforeMount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeMount']>
|
readonly tryOnBeforeMount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeMount']>
|
||||||
readonly tryOnBeforeUnmount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeUnmount']>
|
readonly tryOnBeforeUnmount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeUnmount']>
|
||||||
@ -446,7 +444,7 @@ declare module 'vue' {
|
|||||||
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
|
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
|
||||||
readonly useCurrentElement: UnwrapRef<typeof import('@vueuse/core')['useCurrentElement']>
|
readonly useCurrentElement: UnwrapRef<typeof import('@vueuse/core')['useCurrentElement']>
|
||||||
readonly useCycleList: UnwrapRef<typeof import('@vueuse/core')['useCycleList']>
|
readonly useCycleList: UnwrapRef<typeof import('@vueuse/core')['useCycleList']>
|
||||||
readonly useDark: UnwrapRef<typeof import('@vueuse/core')['useDark']>
|
readonly useDark: UnwrapRef<typeof import('./composables/dark')['useDark']>
|
||||||
readonly useDateFormat: UnwrapRef<typeof import('@vueuse/core')['useDateFormat']>
|
readonly useDateFormat: UnwrapRef<typeof import('@vueuse/core')['useDateFormat']>
|
||||||
readonly useDebounce: UnwrapRef<typeof import('@vueuse/core')['useDebounce']>
|
readonly useDebounce: UnwrapRef<typeof import('@vueuse/core')['useDebounce']>
|
||||||
readonly useDebounceFn: UnwrapRef<typeof import('@vueuse/core')['useDebounceFn']>
|
readonly useDebounceFn: UnwrapRef<typeof import('@vueuse/core')['useDebounceFn']>
|
||||||
@ -634,7 +632,6 @@ declare module '@vue/runtime-core' {
|
|||||||
readonly h: UnwrapRef<typeof import('vue')['h']>
|
readonly h: UnwrapRef<typeof import('vue')['h']>
|
||||||
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
|
readonly ignorableWatch: UnwrapRef<typeof import('@vueuse/core')['ignorableWatch']>
|
||||||
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
readonly inject: UnwrapRef<typeof import('vue')['inject']>
|
||||||
readonly isDark: UnwrapRef<typeof import('./composables/dark')['isDark']>
|
|
||||||
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
|
readonly isDefined: UnwrapRef<typeof import('@vueuse/core')['isDefined']>
|
||||||
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
|
||||||
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
|
readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
|
||||||
@ -663,7 +660,6 @@ declare module '@vue/runtime-core' {
|
|||||||
readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
|
readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
|
||||||
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
|
readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
|
||||||
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
|
readonly pausableWatch: UnwrapRef<typeof import('@vueuse/core')['pausableWatch']>
|
||||||
readonly preferredDark: UnwrapRef<typeof import('./composables/dark')['preferredDark']>
|
|
||||||
readonly provide: UnwrapRef<typeof import('vue')['provide']>
|
readonly provide: UnwrapRef<typeof import('vue')['provide']>
|
||||||
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
|
readonly reactify: UnwrapRef<typeof import('@vueuse/core')['reactify']>
|
||||||
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
|
readonly reactifyObject: UnwrapRef<typeof import('@vueuse/core')['reactifyObject']>
|
||||||
@ -694,7 +690,6 @@ declare module '@vue/runtime-core' {
|
|||||||
readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
|
readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
|
||||||
readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
|
readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
|
||||||
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
|
readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
|
||||||
readonly toggleDark: UnwrapRef<typeof import('./composables/dark')['toggleDark']>
|
|
||||||
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
|
readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
|
||||||
readonly tryOnBeforeMount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeMount']>
|
readonly tryOnBeforeMount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeMount']>
|
||||||
readonly tryOnBeforeUnmount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeUnmount']>
|
readonly tryOnBeforeUnmount: UnwrapRef<typeof import('@vueuse/core')['tryOnBeforeUnmount']>
|
||||||
@ -738,7 +733,7 @@ declare module '@vue/runtime-core' {
|
|||||||
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
|
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
|
||||||
readonly useCurrentElement: UnwrapRef<typeof import('@vueuse/core')['useCurrentElement']>
|
readonly useCurrentElement: UnwrapRef<typeof import('@vueuse/core')['useCurrentElement']>
|
||||||
readonly useCycleList: UnwrapRef<typeof import('@vueuse/core')['useCycleList']>
|
readonly useCycleList: UnwrapRef<typeof import('@vueuse/core')['useCycleList']>
|
||||||
readonly useDark: UnwrapRef<typeof import('@vueuse/core')['useDark']>
|
readonly useDark: UnwrapRef<typeof import('./composables/dark')['useDark']>
|
||||||
readonly useDateFormat: UnwrapRef<typeof import('@vueuse/core')['useDateFormat']>
|
readonly useDateFormat: UnwrapRef<typeof import('@vueuse/core')['useDateFormat']>
|
||||||
readonly useDebounce: UnwrapRef<typeof import('@vueuse/core')['useDebounce']>
|
readonly useDebounce: UnwrapRef<typeof import('@vueuse/core')['useDebounce']>
|
||||||
readonly useDebounceFn: UnwrapRef<typeof import('@vueuse/core')['useDebounceFn']>
|
readonly useDebounceFn: UnwrapRef<typeof import('@vueuse/core')['useDebounceFn']>
|
||||||
|
1
src/components.d.ts
vendored
1
src/components.d.ts
vendored
@ -8,7 +8,6 @@ export {}
|
|||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
ChangeLog: typeof import('./components/ChangeLog.vue')['default']
|
ChangeLog: typeof import('./components/ChangeLog.vue')['default']
|
||||||
Footer: typeof import('./components/Footer.vue')['default']
|
|
||||||
Nav: typeof import('./components/Nav.vue')['default']
|
Nav: typeof import('./components/Nav.vue')['default']
|
||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
RouterView: typeof import('vue-router')['RouterView']
|
RouterView: typeof import('vue-router')['RouterView']
|
||||||
|
@ -19,10 +19,12 @@ const pages = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const { isDark, toggleDark } = useDark()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<v-app-bar class="!static">
|
<v-app-bar app class="!static">
|
||||||
<img class="mx-3 w-40px" src="/favicon.svg">
|
<img class="mx-3 w-40px" src="/favicon.svg">
|
||||||
|
|
||||||
<router-link to="/">
|
<router-link to="/">
|
||||||
@ -50,7 +52,7 @@ const { t } = useI18n()
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<v-list :lines="false" density="compact" nav>
|
<v-list :lines="false" density="compact" nav>
|
||||||
<v-list-item v-for="(page, index) in pages" :key="index" color="primary" :value="index" :to="page.page">
|
<v-list-item v-for="(page, index) in pages" :key="index" :value="index" :to="page.page">
|
||||||
<v-list-item-title>{{ page.title }}</v-list-item-title>
|
<v-list-item-title>{{ page.title }}</v-list-item-title>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
// these APIs are auto-imported from @vueuse/core
|
import { useTheme } from 'vuetify'
|
||||||
export const isDark = useDark()
|
|
||||||
export const toggleDark = useToggle(isDark)
|
export function useDark() {
|
||||||
export const preferredDark = usePreferredDark()
|
const theme = useTheme()
|
||||||
|
|
||||||
|
const isDark = theme.global.current.value.dark
|
||||||
|
|
||||||
|
const toggleDark = () => theme.global.name.value = theme.global.current.value.dark
|
||||||
|
? 'light'
|
||||||
|
: 'dark'
|
||||||
|
|
||||||
|
return { isDark, toggleDark }
|
||||||
|
}
|
||||||
|
@ -4,7 +4,7 @@ const { t } = useI18n()
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main class="p-x4 p-y10 text-center text-teal-700 dark:text-gray-200">
|
<main class="p-x4 p-y10 text-center">
|
||||||
<div class="text-4xl">
|
<div class="text-4xl">
|
||||||
<div class="i-carbon-warning inline-block" />
|
<div class="i-carbon-warning inline-block" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-theme-provider :theme="isDark ? 'dark' : 'light'">
|
<v-app class="flex flex-col">
|
||||||
<v-layout class="text-gray-700 dark:text-gray-200 flex flex-col">
|
|
||||||
<Nav />
|
<Nav />
|
||||||
|
|
||||||
<v-main style="--v-layout-top: 25px;--v-layout-bottom: 70px;">
|
<v-main style="--v-layout-top: 25px;--v-layout-bottom: 70px;">
|
||||||
@ -12,6 +11,5 @@
|
|||||||
</transition>
|
</transition>
|
||||||
</router-view>
|
</router-view>
|
||||||
</v-main>
|
</v-main>
|
||||||
</v-layout>
|
</v-app>
|
||||||
</v-theme-provider>
|
|
||||||
</template>
|
</template>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-theme-provider :theme="isDark ? 'dark' : 'light'">
|
<v-app class="flex flex-col">
|
||||||
<v-app class="text-gray-700 dark:text-gray-200 flex flex-col">
|
|
||||||
<Nav />
|
<Nav />
|
||||||
|
|
||||||
<div style="--v-layout-top: 25px" class="m-auto">
|
<div style="--v-layout-top: 25px" class="m-auto">
|
||||||
@ -13,5 +12,4 @@
|
|||||||
</router-view>
|
</router-view>
|
||||||
</div>
|
</div>
|
||||||
</v-app>
|
</v-app>
|
||||||
</v-theme-provider>
|
|
||||||
</template>
|
</template>
|
||||||
|
@ -4,7 +4,58 @@ import { aliases, mdi } from 'vuetify/iconsets/mdi'
|
|||||||
|
|
||||||
import '@mdi/font/css/materialdesignicons.css'
|
import '@mdi/font/css/materialdesignicons.css'
|
||||||
|
|
||||||
|
const light = {
|
||||||
|
dark: false,
|
||||||
|
colors: {
|
||||||
|
'primary': '#9155FD',
|
||||||
|
'secondary': '#8A8D93',
|
||||||
|
'surface': '#F4F5FA',
|
||||||
|
'background': '#F4F5FA',
|
||||||
|
|
||||||
|
'success': '#56CA00',
|
||||||
|
'info': '#16B1FF',
|
||||||
|
'warning': '#FFB400',
|
||||||
|
'error': '#FF4C51',
|
||||||
|
|
||||||
|
'on-primary': '#FFFFFF',
|
||||||
|
'on-success': '#FFFFFF',
|
||||||
|
'on-warning': '#FFFFFF',
|
||||||
|
'on-secondary': '#FFFFFF',
|
||||||
|
'on-background': '#3A3541',
|
||||||
|
'on-surface': '#3A3541',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const dark = {
|
||||||
|
dark: true,
|
||||||
|
colors: {
|
||||||
|
'primary': '#9155FD',
|
||||||
|
'secondary': '#8A8D93',
|
||||||
|
'surface': '#212121',
|
||||||
|
'background': '#121212',
|
||||||
|
|
||||||
|
'success': '#56CA00',
|
||||||
|
'info': '#16B1FF',
|
||||||
|
'warning': '#FFB400',
|
||||||
|
'error': '#FF4C51',
|
||||||
|
|
||||||
|
'on-primary': '#FFFFFF',
|
||||||
|
'on-success': '#FFFFFF',
|
||||||
|
'on-warning': '#FFFFFF',
|
||||||
|
'on-secondary': '#FFFFFF',
|
||||||
|
'on-background': '#FFFFFF',
|
||||||
|
'on-surface': '#FFFFFF',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
export default createVuetify({
|
export default createVuetify({
|
||||||
|
theme: {
|
||||||
|
defaultTheme: 'light',
|
||||||
|
themes: {
|
||||||
|
light,
|
||||||
|
dark,
|
||||||
|
},
|
||||||
|
},
|
||||||
icons: {
|
icons: {
|
||||||
defaultSet: 'mdi',
|
defaultSet: 'mdi',
|
||||||
aliases,
|
aliases,
|
||||||
|
@ -11,11 +11,6 @@ body,
|
|||||||
font-family: "LXGW WenKai Mono", sans-serif;
|
font-family: "LXGW WenKai Mono", sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
html.dark {
|
|
||||||
background: #121212;
|
|
||||||
color-scheme: dark;
|
|
||||||
}
|
|
||||||
|
|
||||||
#nprogress {
|
#nprogress {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user