Skip to content

Commit

Permalink
✨ feat(darkmode): 添加darkmode
Browse files Browse the repository at this point in the history
✨ feat(darkmode): 添加darkmode
  • Loading branch information
wosiwq authored Dec 25, 2023
2 parents f323808 + 59f8f6d commit 0173b28
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 32 deletions.
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {}
declare module 'vue' {
export interface GlobalComponents {
ElButton: typeof import('element-plus/es')['ElButton']
ElCard: typeof import('element-plus/es')['ElCard']
ElCollapse: typeof import('element-plus/es')['ElCollapse']
ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem']
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
Expand Down
123 changes: 106 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"dependencies": {
"@codemirror/lang-json": "^6.0.1",
"@codemirror/theme-one-dark": "^6.1.2",
"@vueuse/core": "^10.7.0",
"axios": "^1.6.2",
"codemirror": "^6.0.1",
"element-plus": "^2.4.3",
Expand Down
7 changes: 7 additions & 0 deletions src/assets/dark.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<svg viewBox="0 0 24 24" class="dark-icon">
<path
d="M11.01 3.05C6.51 3.54 3 7.36 3 12a9 9 0 0 0 9 9c4.63 0 8.45-3.5 8.95-8c.09-.79-.78-1.42-1.54-.95A5.403 5.403 0 0 1 11.1 7.5c0-1.06.31-2.06.84-2.89c.45-.67-.04-1.63-.93-1.56z"
fill="currentColor" />
</svg>
</template>
7 changes: 7 additions & 0 deletions src/assets/light.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<svg viewBox="0 0 24 24" class="light-icon">
<path
d="M6.05 4.14l-.39-.39a.993.993 0 0 0-1.4 0l-.01.01a.984.984 0 0 0 0 1.4l.39.39c.39.39 1.01.39 1.4 0l.01-.01a.984.984 0 0 0 0-1.4zM3.01 10.5H1.99c-.55 0-.99.44-.99.99v.01c0 .55.44.99.99.99H3c.56.01 1-.43 1-.98v-.01c0-.56-.44-1-.99-1zm9-9.95H12c-.56 0-1 .44-1 .99v.96c0 .55.44.99.99.99H12c.56.01 1-.43 1-.98v-.97c0-.55-.44-.99-.99-.99zm7.74 3.21c-.39-.39-1.02-.39-1.41-.01l-.39.39a.984.984 0 0 0 0 1.4l.01.01c.39.39 1.02.39 1.4 0l.39-.39a.984.984 0 0 0 0-1.4zm-1.81 15.1l.39.39a.996.996 0 1 0 1.41-1.41l-.39-.39a.993.993 0 0 0-1.4 0c-.4.4-.4 1.02-.01 1.41zM20 11.49v.01c0 .55.44.99.99.99H22c.55 0 .99-.44.99-.99v-.01c0-.55-.44-.99-.99-.99h-1.01c-.55 0-.99.44-.99.99zM12 5.5c-3.31 0-6 2.69-6 6s2.69 6 6 6s6-2.69 6-6s-2.69-6-6-6zm-.01 16.95H12c.55 0 .99-.44.99-.99v-.96c0-.55-.44-.99-.99-.99h-.01c-.55 0-.99.44-.99.99v.96c0 .55.44.99.99.99zm-7.74-3.21c.39.39 1.02.39 1.41 0l.39-.39a.993.993 0 0 0 0-1.4l-.01-.01a.996.996 0 0 0-1.41 0l-.39.39c-.38.4-.38 1.02.01 1.41z"
fill="currentColor" />
</svg>
</template>
4 changes: 1 addition & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'element-plus/theme-chalk/dark/css-vars.css'
import 'virtual:uno.css'
import { createApp } from 'vue'
import App from './App.vue'
// import router from './router'

const app = createApp(App)

// app.use(router)

app.mount('#app')
49 changes: 37 additions & 12 deletions src/views/BaseView.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
<template>
<ElContainer v-loading="isLoading" class="bg-gray-100 min-h-screen">
<ElHeader class="flex items-center justify-between bg-blue-700 text-white p-4">
<span class="font-bold sm:text-lg">BILICHAT WEB UI v{{ version }}</span>
<ElContainer v-loading="isLoading" class="bg-gray-100 dark:bg-[#0d1117] min-h-screen">
<ElHeader
class="flex items-center justify-between bg-blue-700 dark:bg-[#010409] text-white p-4">
<div>
<ElButton @click="handleManageCookie" color="rgb(59 130 246 / var(--un-bg-opacity))">
<span class="font-bold text-lg">BILICHAT</span>
<span class="font-bold hidden sm:inline text-lg">&nbsp;WEB UI v{{ version }}</span>
</div>

<div>
<ElButton @click="handleManageCookie" :color="getButtonColor()" :dark="isDark">
管理cookie
</ElButton>
<ElSwitch
class="ml-2"
v-model="isDark"
style="--el-switch-on-color: #2c2c2c"
width="55"
:active-action-icon="Dark"
:inactive-action-icon="Light"></ElSwitch>
</div>
</ElHeader>
<ElMain class="h-full">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 items-start h-full">
<div class="p-2 bg-white rounded-lg shadow">
<h2 class="text-lg font-bold mb-2 mt-2">配置文件</h2>
<ElCard style="border-radius: 0.5rem">
<h2 class="text-lg font-bold mb-2 mt-0">配置文件</h2>
<Codemirror
v-if="formattedBilichat"
@blur="handleFormattedBilichatChange"
Expand All @@ -24,11 +36,11 @@
:phrases="chinesePhrases"
style="max-height: 600px"></Codemirror>
<ElButton class="mt-2 mb-2" @click="saveChange">保存修改</ElButton>
</div>
</ElCard>

<div ref="formDiv" class="p-2 bg-white rounded-lg shadow">
<ElCard ref="formDiv" style="border-radius: 0.5rem">
<ElScrollbar>
<h2 class="text-lg font-bold mt-2 mb-2">可视化修改</h2>
<h2 class="text-lg font-bold mt-0 mb-2">可视化修改</h2>
<ElForm
label-width="8rem"
:model="bilichat"
Expand Down Expand Up @@ -170,7 +182,7 @@
</ElForm>
<span v-else>未读取到bilichat配置</span>
</ElScrollbar>
</div>
</ElCard>
</div>
</ElMain>
</ElContainer>
Expand Down Expand Up @@ -215,14 +227,16 @@
append-to-body
v-model="isQrcodeDialogVisible">
<div class="flex justify-center">
<QrcodeVue :value="qrcodeUrl" :size="300"></QrcodeVue>
<QrcodeVue :value="qrcodeUrl" :size="300" :margin="2"></QrcodeVue>
</div>
</ElDialog>
</ElDialog>
</template>
<script lang="ts" setup>
import Minus from '@/assets/Minus.vue'
import Plus from '@/assets/Plus.vue'
import Dark from '@/assets/dark.vue'
import Light from '@/assets/light.vue'
import type {
AuthInfo,
BiliChat,
Expand All @@ -234,6 +248,7 @@ import type {
} from '@/types'
import { json } from '@codemirror/lang-json'
import { oneDark } from '@codemirror/theme-one-dark'
import { useDark } from '@vueuse/core'
import axios from 'axios'
import QrcodeVue from 'qrcode.vue'
import { Codemirror } from 'vue-codemirror'
Expand All @@ -243,6 +258,7 @@ const isManageCookieDialogVisible = ref(false)
const isQrcodeDialogVisible = ref(false)
const isPopoverVisible = ref(false)
const isLoading = ref(false)
const isDark = useDark({ disableTransition: false })
const formDiv: Ref<HTMLElement | undefined> = ref()
const inputUid = ref<number>()
Expand Down Expand Up @@ -491,7 +507,16 @@ const coverDataToLocalString = (ts: number) => {
}
const getExtensions = () => {
return [json(), oneDark]
if (isDark.value) {
return [json(), oneDark]
}
return [json()]
}
const getButtonColor = () => {
if (isDark.value) {
return 'rgb(25 50 100 / var(--un-bg-opacity))'
}
return 'rgb(59 130 246 / var(--un-bg-opacity))'
}
</script>
<style scoped lang="scss"></style>

0 comments on commit 0173b28

Please sign in to comment.