Skip to content

Commit cc91e95

Browse files
authored
chore: version 2.7.3 (Chanzhaoyu#120)
* fix: 用户输入也被渲染的问题 (Chanzhaoyu#117) * fix: 用户输入不转换 * feat: 基础深色模式适配 * feat: 主题模式跟随系统 * feat: 深色适配补漏 * chore: version 2.7.3
1 parent abbdcf9 commit cc91e95

File tree

25 files changed

+1285
-51
lines changed

25 files changed

+1285
-51
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## v2.7.3
2+
3+
`2023-02-25`
4+
5+
### Feature
6+
- 适配系统深色模式 [#118](https://github.com/Chanzhaoyu/chatgpt-web/issues/103)
7+
### BugFix
8+
- 修复用户消息能被渲染为 `HTML` 问题 [#117](https://github.com/Chanzhaoyu/chatgpt-web/issues/117)
9+
110
## v2.7.2
211

312
`2023-02-24`

index.html

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
transform: translateX(100%);
6262
}
6363
}
64+
65+
@media (prefers-color-scheme: dark) {
66+
body {
67+
background: #121212;
68+
}
69+
}
6470
</style>
6571
<div class="loading-wrap">
6672
<div class="balls">

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chatgpt-web",
3-
"version": "2.7.2",
3+
"version": "2.7.3",
44
"private": false,
55
"description": "ChatGPT Web",
66
"author": "ChenZhaoYu <[email protected]>",
@@ -24,7 +24,6 @@
2424
},
2525
"dependencies": {
2626
"@vueuse/core": "^9.13.0",
27-
"github-markdown-css": "^5.2.0",
2827
"highlight.js": "^11.7.0",
2928
"marked": "^4.2.12",
3029
"naive-ui": "^2.34.3",

pnpm-lock.yaml

-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.vue

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
<script setup lang="ts">
22
import { NConfigProvider } from 'naive-ui'
33
import { NaiveProvider } from '@/components/common'
4+
import { useTheme } from '@/hooks/useTheme'
5+
6+
const { theme, themeOverrides } = useTheme()
47
</script>
58

69
<template>
7-
<NConfigProvider class="h-full">
10+
<NConfigProvider
11+
class="h-full"
12+
:theme="theme"
13+
:theme-overrides="themeOverrides"
14+
>
815
<NaiveProvider>
916
<RouterView />
1017
</NaiveProvider>

src/components/common/HoverButton/Button.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function handleClick() {
1212

1313
<template>
1414
<button
15-
class="flex items-center justify-center w-10 h-10 transition rounded-full hover:bg-neutral-100"
15+
class="flex items-center justify-center w-10 h-10 transition rounded-full hover:bg-neutral-100 dark:hover:bg-[#414755]"
1616
@click="handleClick"
1717
>
1818
<slot />

src/components/common/Setting/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ watch(
6363
<p>
6464
此项目开源于
6565
<a class="text-blue-600" href="https://github.com/Chanzhaoyu/chatgpt-web" target="_blank">Github</a>
66-
,免费并且协议为 MIT,其他来源均为盗版,使用时请注意。如果你觉得此项目对你有帮助,请帮我点个 Star,谢谢!
66+
如果你觉得此项目对你有帮助,请帮我点个 Star,谢谢!
6767
</p>
6868
<hr>
6969
<p>API方式:{{ config?.apiModel ?? '-' }}</p>

src/components/custom/GithubSite.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
2-
<div class="text-center text-neutral-500">
3-
<span>❤️ Star on</span>
2+
<div class="text-neutral-400">
3+
<span>Star on</span>
44
<a href="https://github.com/Chanzhaoyu/chatgpt-bot" target="_blank" class="text-blue-500">
55
GitHub
66
</a>

src/hooks/useTheme.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { GlobalThemeOverrides } from 'naive-ui'
2+
import { computed, watch } from 'vue'
3+
import { darkTheme, useOsTheme } from 'naive-ui'
4+
import { useAppStore } from '@/store'
5+
6+
export function useTheme() {
7+
const appStore = useAppStore()
8+
9+
const OsTheme = useOsTheme()
10+
11+
const isDark = computed(() => {
12+
if (appStore.theme === 'auto')
13+
return OsTheme.value === 'dark'
14+
else
15+
return appStore.theme === 'dark'
16+
})
17+
18+
const theme = computed(() => {
19+
return isDark.value ? darkTheme : undefined
20+
})
21+
22+
const themeOverrides = computed<GlobalThemeOverrides>(() => {
23+
if (isDark.value) {
24+
return {
25+
common: {},
26+
}
27+
}
28+
return {}
29+
})
30+
31+
watch(
32+
() => isDark.value,
33+
(dark) => {
34+
if (dark)
35+
document.documentElement.classList.add('dark')
36+
else
37+
document.documentElement.classList.remove('dark')
38+
},
39+
{ immediate: true },
40+
)
41+
42+
return { theme, themeOverrides }
43+
}

src/plugins/assets.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'highlight.js/styles/xcode.css'
2-
import 'github-markdown-css/github-markdown.css'
3-
import '@/styles/global.css'
2+
import '@/styles/lib/tailwind.css'
3+
import '@/styles/lib/github-markdown.less'
4+
import '@/styles/global.less'
45

56
/** Tailwind's Preflight Style Override */
67
function naiveStyleOverride() {

src/store/modules/app/helper.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ import { ss } from '@/utils/storage'
22

33
const LOCAL_NAME = 'appSetting'
44

5+
export type Theme = 'light' | 'dark' | 'auto'
6+
57
export interface AppState {
68
siderCollapsed: boolean
9+
theme: Theme
710
}
811

9-
export function defaultSetting() {
10-
return { siderCollapsed: false }
12+
export function defaultSetting(): AppState {
13+
return { siderCollapsed: false, theme: 'light' }
1114
}
1215

13-
export function getLocalSetting() {
16+
export function getLocalSetting(): AppState {
1417
const localSetting: AppState | undefined = ss.get(LOCAL_NAME)
15-
return localSetting ?? defaultSetting()
18+
return { ...defaultSetting(), ...localSetting }
1619
}
1720

18-
export function setLocalSetting(setting: AppState) {
21+
export function setLocalSetting(setting: AppState): void {
1922
ss.set(LOCAL_NAME, setting)
2023
}

src/store/modules/app/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { defineStore } from 'pinia'
2-
import type { AppState } from './helper'
2+
import type { AppState, Theme } from './helper'
33
import { getLocalSetting, setLocalSetting } from './helper'
44

55
export const useAppStore = defineStore('app-store', {
66
state: (): AppState => getLocalSetting(),
77
actions: {
88
setSiderCollapsed(collapsed: boolean) {
99
this.siderCollapsed = collapsed
10+
this.recordState()
11+
},
12+
13+
setTheme(theme: Theme) {
14+
this.theme = theme
15+
this.recordState()
16+
},
17+
18+
recordState() {
1019
setLocalSetting(this.$state)
1120
},
1221
},

src/styles/global.less

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
html,
2+
body,
3+
#app {
4+
height: 100%;
5+
}

0 commit comments

Comments
 (0)