Skip to content

Commit 3951dca

Browse files
author
oyjt
committed
refactor: 简化主题设置
1 parent 176d2d2 commit 3951dca

File tree

13 files changed

+88
-500
lines changed

13 files changed

+88
-500
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<view class="mb-20rpx flex items-center gap-2">
3+
<view>
4+
请选择主题颜色:
5+
</view>
6+
<view
7+
v-for="color in colors"
8+
:key="color"
9+
class="h-32rpx w-32rpx cursor-pointer border border-gray-200 rounded-full"
10+
:style="{ backgroundColor: color }"
11+
@click="changeTheme(color)"
12+
/>
13+
</view>
14+
</template>
15+
16+
<script setup lang="ts">
17+
import { useAppStore } from '@/store';
18+
19+
const appStore = useAppStore();
20+
21+
const colors = ['#409EFF', '#67C23A', '#E6A23C', '#F56C6C', '#909399'];
22+
23+
function changeTheme(color: string) {
24+
appStore.setTheme(color);
25+
}
26+
</script>

src/components/theme-switcher/index.vue

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/hooks/use-theme/index.ts

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ThemeMode } from '@/utils/theme/types';
21
import { computed } from 'vue';
32
import { useAppStore } from '@/store';
43

@@ -8,42 +7,18 @@ import { useAppStore } from '@/store';
87
export default function useTheme() {
98
const appStore = useAppStore();
109

11-
// 当前主题模式
12-
const themeMode = computed(() => appStore.getThemeMode);
13-
14-
// 是否为深色主题
15-
const isDark = computed(() => appStore.getIsDark);
16-
17-
// 当前主题颜色
18-
const themeColors = computed(() => appStore.getThemeColors);
10+
// 当前主题
11+
const themeColor = computed(() => appStore.getTheme);
1912

2013
/**
2114
* 设置主题模式
2215
*/
23-
const setThemeMode = (mode: ThemeMode) => {
24-
appStore.setThemeMode(mode);
25-
};
26-
27-
/**
28-
* 切换主题
29-
*/
30-
const toggleTheme = () => {
31-
appStore.toggleTheme();
32-
};
33-
34-
/**
35-
* 获取主题颜色值
36-
*/
37-
const getThemeColor = (key: keyof typeof themeColors.value) => {
38-
return themeColors.value[key];
16+
const setTheme = (color: string) => {
17+
appStore.setTheme(color);
3918
};
4019

4120
return {
42-
themeMode,
43-
isDark,
44-
themeColors,
45-
setThemeMode,
46-
toggleTheme,
47-
getThemeColor,
21+
setTheme,
22+
themeColor,
4823
};
4924
}

src/pages/common/theme/index.vue

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/pages/tab/home/index.vue

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
<template>
22
<view class="min-h-screen flex flex-col items-center">
3-
<image
4-
class="mb-50rpx mt-200rpx h-200rpx w-200rpx"
5-
src="@/static/images/logo.png"
6-
width="200rpx"
7-
height="200rpx"
8-
/>
3+
<image class="mb-50rpx mt-200rpx h-200rpx w-200rpx" src="@/static/images/logo.png" width="200rpx" height="200rpx" />
94
<view class="flex justify-center">
105
<text class="font-size-36rpx">
116
{{ $t('home.intro') }}
127
</text>
138
</view>
149
<view class="mt-100rpx flex gap-30rpx">
1510
<lang-select />
16-
<view cursor-pointer @click="toGithub">
11+
<view class="cursor-pointer" @click="toGithub">
1712
<view class="i-mdi-github text-40rpx" />
1813
</view>
19-
<!-- #ifdef H5 -->
20-
<theme-switcher />
21-
<!-- #endif -->
2214
</view>
15+
16+
<!-- 主题预览 -->
17+
<view class="mt-100rpx">
18+
<view class="rounded-12rpx bg-#f8f9fa p-30rpx shadow-md">
19+
<theme-picker />
20+
<view class="u-border-top pt-20rpx">
21+
主题预览
22+
</view>
23+
<view class="flex flex-col gap-10rpx py-20rpx">
24+
<view class="flex items-center">
25+
图标:<text class="i-mdi-yin-yang text-36rpx color-primary" />
26+
</view>
27+
<view class="flex items-center">
28+
文字:<up-text type="primary" text="主要文字" size="18" />
29+
</view>
30+
<view class="flex items-center">
31+
按钮:<view><u-button type="primary" text="主要按钮" shape="circle" /></view>
32+
</view>
33+
</view>
34+
</view>
35+
</view>
36+
2337
<!-- #ifdef MP-WEIXIN -->
2438
<!-- 隐私协议组件 -->
2539
<agree-privacy v-model="showAgreePrivacy" :disable-check-privacy="false" @agree="handleAgree" />

src/static/styles/theme.scss

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -16,98 +16,7 @@
1616

1717
// 背景颜色
1818
--theme-bg-color: #ffffff;
19-
--theme-bg-color-secondary: #f8f9fa;
20-
--theme-bg-color-tertiary: #f1f7f7;
2119

2220
// 边框颜色
2321
--theme-border-color: #e9ecef;
24-
--theme-border-color-light: #f2f7f7;
25-
26-
// 阴影
27-
--theme-shadow-color: rgba(0, 0, 0, 0.1);
28-
--theme-shadow-color-light: rgba(0, 0, 0, 0.05);
29-
}
30-
31-
// 深色主题
32-
[data-theme="dark"] {
33-
// 主色调保持不变
34-
--theme-primary: #21d59d;
35-
--theme-primary-dark: #76a3fd;
36-
--theme-success: #3ed268;
37-
--theme-warning: #fe9831;
38-
--theme-error: #fa4e62;
39-
40-
// 文字颜色
41-
--theme-main-color: #ffffff;
42-
--theme-content-color: #b0b8c1;
43-
--theme-tips-color: #8a8f95;
44-
--theme-light-color: #6c757d;
45-
--theme-disabled-color: #495057;
46-
47-
// 背景颜色
48-
--theme-bg-color: #1a1a1a;
49-
--theme-bg-color-secondary: #2d2d2d;
50-
--theme-bg-color-tertiary: #3a3a3a;
51-
52-
// 边框颜色
53-
--theme-border-color: #404040;
54-
--theme-border-color-light: #4a4a4a;
55-
56-
// 阴影
57-
--theme-shadow-color: rgba(0, 0, 0, 0.3);
58-
--theme-shadow-color-light: rgba(0, 0, 0, 0.2);
59-
}
60-
61-
// 主题切换动画
62-
// * {
63-
// transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
64-
// }
65-
66-
// 主题工具类
67-
.theme-bg {
68-
background-color: var(--theme-bg-color);
69-
}
70-
71-
.theme-bg-secondary {
72-
background-color: var(--theme-bg-color-secondary);
73-
}
74-
75-
.theme-bg-tertiary {
76-
background-color: var(--theme-bg-color-tertiary);
77-
}
78-
79-
.theme-text {
80-
color: var(--theme-main-color);
81-
}
82-
83-
.theme-text-content {
84-
color: var(--theme-content-color);
85-
}
86-
87-
.theme-text-tips {
88-
color: var(--theme-tips-color);
89-
}
90-
91-
.theme-text-light {
92-
color: var(--theme-light-color);
93-
}
94-
95-
.theme-text-disabled {
96-
color: var(--theme-disabled-color);
97-
}
98-
99-
.theme-border {
100-
border-color: var(--theme-border-color);
101-
}
102-
103-
.theme-border-light {
104-
border-color: var(--theme-border-color-light);
105-
}
106-
107-
.theme-shadow {
108-
box-shadow: 0 2px 8px var(--theme-shadow-color);
109-
}
110-
111-
.theme-shadow-light {
112-
box-shadow: 0 1px 4px var(--theme-shadow-color-light);
11322
}

0 commit comments

Comments
 (0)