Skip to content

Commit a9752be

Browse files
committed
修复:将ColorDemo.vue中的主题设置函数类型定义为TypeScript,并在路由中根据开发环境动态添加ColorDemo路由
1 parent 8d8ba6a commit a9752be

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

frontend/src/pages/ColorDemo.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,17 @@ http://localhost:5173/colors
298298
</div>
299299
</template>
300300

301-
<script setup>
301+
<script setup lang="ts">
302302
import { onMounted } from 'vue';
303303
304304
// 设置主题
305-
const setTheme = (theme) => {
305+
const setTheme = (theme: string): void => {
306306
document.documentElement.setAttribute('data-theme', theme);
307307
localStorage.setItem('theme', theme);
308308
};
309309
310310
// 跟随系统主题
311-
const setSystemTheme = () => {
311+
const setSystemTheme = (): void => {
312312
localStorage.removeItem('theme');
313313
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
314314
document.documentElement.setAttribute('data-theme', prefersDark ? 'dark' : 'light');
@@ -321,4 +321,10 @@ onMounted(() => {
321321
document.documentElement.setAttribute('data-theme', savedTheme);
322322
}
323323
});
324+
</script>
325+
326+
<script lang="ts">
327+
export default {
328+
name: 'ColorDemo'
329+
}
324330
</script>

frontend/src/router/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createRouter, createWebHistory } from 'vue-router'
22
import ModelManager from '../pages/ModelManager.vue'
33
import PromptManager from '../pages/PromptManager.vue'
4+
// @ts-ignore 由于只在开发环境使用,可以忽略类型检查
45
import ColorDemo from '../pages/ColorDemo.vue'
56

67
// 定义路由配置
@@ -24,16 +25,20 @@ const routes = [
2425
meta: {
2526
title: '提示词管理'
2627
}
27-
},
28-
{
28+
}
29+
]
30+
31+
// 在开发环境中添加ColorDemo路由
32+
if (import.meta.env.DEV) {
33+
routes.push({
2934
path: '/colors',
3035
name: 'ColorDemo',
3136
component: ColorDemo,
3237
meta: {
3338
title: 'FlyonUI 颜色系统示例'
3439
}
35-
}
36-
]
40+
})
41+
}
3742

3843
// 创建路由实例
3944
const router = createRouter({

0 commit comments

Comments
 (0)