| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <template>
- <view class="theme-picker">
- <view class="current-theme" @click="showSelector = !showSelector">
- <text>{{ themeStore.getThemeLabel(themeStore.currentTheme) }}</text>
- <uni-icons :type="showSelector ? 'arrowup' : 'arrowdown'" size="16"></uni-icons>
- </view>
-
- <view v-if="showSelector" class="theme-selector">
- <view
- v-for="theme in themeStore.themeOptions"
- :key="theme.name"
- class="theme-item"
- :class="{ active: theme.name === themeStore.currentTheme }"
- @click="changeTheme(theme.name)"
- >
- <view class="color-preview">
- <view
- v-for="(color, key) in theme.colors"
- v-if="key.includes('color')"
- :key="key"
- class="color-block"
- :style="{ backgroundColor: color }"
- ></view>
- </view>
- <text class="theme-label">{{ theme.label }}</text>
- </view>
- </view>
- </view>
- </template>
-
- <script setup>
- import { ref } from 'vue'
- import { useThemeStore } from '@/stores/theme'
-
- const themeStore = useThemeStore()
- const showSelector = ref(false)
-
- // 切换主题
- const changeTheme = (themeName) => {
- themeStore.setTheme(themeName)
- showSelector.value = false
- }
- </script>
-
- <style scoped>
- .theme-picker {
- position: relative;
- z-index: 100;
- }
-
- .current-theme {
- display: flex;
- align-items: center;
- padding: 8px 12px;
- background-color: var(--card-bg);
- border-radius: 20px;
- font-size: 14px;
- cursor: pointer;
- }
-
- .theme-selector {
- position: absolute;
- top: 40px;
- right: 0;
- width: 180px;
- background-color: var(--card-bg);
- border-radius: 12px;
- box-shadow: 0 4px 12px rgba(0,0,0,0.1);
- padding: 10px;
- z-index: 200;
- }
-
- .theme-item {
- padding: 10px;
- border-radius: 8px;
- margin-bottom: 8px;
- cursor: pointer;
- transition: all 0.3s;
- }
-
- .theme-item.active {
- background-color: rgba(42, 92, 170, 0.1);
- }
-
- .theme-item:hover {
- background-color: rgba(0,0,0,0.05);
- }
-
- .color-preview {
- display: flex;
- height: 20px;
- border-radius: 4px;
- overflow: hidden;
- margin-bottom: 6px;
- }
-
- .color-block {
- flex: 1;
- height: 100%;
- }
-
- .theme-label {
- font-size: 13px;
- text-align: center;
- display: block;
- }
- </style>
|