Skip to content

Commit 3b92f85

Browse files
committed
feat: 优化路径加载和主题切换
1 parent 037ffdc commit 3b92f85

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

frontend/src/App.vue

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,31 @@ const { open, like, resetLike } = useLike()
6565
6666
const defInfo = reactive({ path: '' })
6767
68-
onBeforeMount(async () => {
69-
defInfo.path = await getPath()
70-
})
71-
72-
const getPath = async (): Promise<string> => {
68+
onBeforeMount(() => {
7369
const query = new URLSearchParams(window.location.search).get('path') || ''
7470
if (query) {
75-
return query
71+
defInfo.path = query
72+
} else {
73+
inputPath(true)
7674
}
75+
})
7776
78-
return inputPath()
79-
}
80-
81-
const inputPath = async () => {
77+
const inputPath = async (force?: boolean) => {
8278
return await ElMessageBox.prompt(
8379
'部分文件可在文件管理中双击文件进行编辑,详见应用介绍',
8480
'请输入文件路径',
8581
{
82+
showClose: false,
83+
closeOnClickModal: false,
84+
closeOnPressEscape: false,
85+
closeOnHashChange: false,
86+
showCancelButton: !force,
8687
confirmButtonText: '确认',
8788
cancelButtonText: '取消',
8889
},
8990
).then(({ value }) => {
9091
if (value) {
91-
return defInfo.path = value
92-
} else {
93-
return value
92+
defInfo.path = value
9493
}
9594
})
9695
}
@@ -103,6 +102,17 @@ body,
103102
height: 100%;
104103
}
105104
105+
html {
106+
&.dark {
107+
#app {
108+
> .header,
109+
> .footer {
110+
background-color: #1c1c1c;
111+
}
112+
}
113+
}
114+
}
115+
106116
#app {
107117
height: 100%;
108118
display: flex;
@@ -114,7 +124,6 @@ body,
114124
display: flex;
115125
align-items: center;
116126
gap: 4px;
117-
background-color: #1c1c1c;
118127
padding: 0 12px;
119128
120129
> * {
@@ -123,22 +132,22 @@ body,
123132
}
124133
125134
> .header {
126-
border-bottom: solid 1px rgba(255, 255, 255, 0.2);
135+
border-bottom: solid 1px var(--el-border-color);
127136
128137
> .title {
129138
font-size: 14px;
130139
line-height: 32px;
131-
color: #fff;
140+
color: var(--el-text-color-primary);
132141
}
133142
}
134143
135144
> .footer {
136-
border-top: solid 1px rgba(255, 255, 255, 0.2);
145+
border-top: solid 1px var(--el-border-color);
137146
138147
> .developed {
139148
font-size: 12px;
140149
line-height: 32px;
141-
color: gray;
150+
color: var(--el-text-color-placeholder);
142151
}
143152
}
144153

frontend/src/hooks/useLike.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { reactive, ref, toRaw, watch } from 'vue'
1+
import { onMounted, reactive, ref, toRaw, watch, watchEffect } from 'vue'
22

33
import localStorage from '@/utils/localStorage'
4+
import { THEME_OPTIONS } from '@/utils/option'
45

56
export interface LikeModel {
67
theme: string
@@ -25,9 +26,16 @@ export default function useCode() {
2526
localStorage.set(key, toRaw(like))
2627
})
2728

29+
watchEffect(() => {
30+
const dark = THEME_OPTIONS.find((i) => i.value === like.theme)?.dark
31+
document.documentElement.className = dark ? 'dark' : ''
32+
})
33+
2834
const resetLike = () => {
2935
Object.assign(like, { ...defLike })
3036
}
3137

38+
onMounted(() => {})
39+
3240
return { open, like, resetLike }
3341
}

frontend/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'normalize.css'
88
import 'element-plus/theme-chalk/el-input.css'
99
import 'element-plus/theme-chalk/el-message.css'
1010
import 'element-plus/theme-chalk/el-message-box.css'
11+
import 'element-plus/theme-chalk/dark/css-vars.css'
1112

1213
import '@/utils/monaco'
1314
;(window as any).Buffer = Buffer

frontend/src/utils/option.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export const LANG_OPTIONS = [...new Set(Object.values(LANG_MAP))].map((t) => ({
3737
value: t,
3838
}))
3939

40-
export const THEME_OPTIONS: { label: string; value: string }[] = [
41-
{ label: 'VS Light', value: 'vs' },
42-
{ label: 'VS Dark', value: 'vs-dark' },
43-
{ label: 'High Contrast Black', value: 'hc-black' },
44-
{ label: 'High Contrast Light', value: 'hc-light' },
40+
export const THEME_OPTIONS: { label: string; value: string; dark: boolean }[] = [
41+
{ label: 'VS Light', value: 'vs', dark: false },
42+
{ label: 'VS Dark', value: 'vs-dark', dark: true },
43+
{ label: 'High Contrast Light', value: 'hc-light', dark: false },
44+
{ label: 'High Contrast Black', value: 'hc-black', dark: true },
4545
]
4646

4747
export const ENCODING_OPTIONS = [

0 commit comments

Comments
 (0)