Files
template-10584/src/components/GradientThemeSelector.tsx
赵忠林 9d9762ef17 feat(theme): 实现主题切换系统并优化经销商相关页面
- 新增主题切换系统,支持智能主题和手动选择
- 更新经销商首页、团队、订单、提现等页面样式
- 添加主题相关的Hook和样式工具函数
- 优化部分组件样式以适配新主题
2025-08-19 00:08:26 +08:00

114 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useState } from 'react'
import { View, Text } from '@tarojs/components'
import { Popup, Button } from '@nutui/nutui-react-taro'
import { gradientThemes, GradientTheme } from '@/styles/gradients'
interface GradientThemeSelectorProps {
visible: boolean
onClose: () => void
onSelect: (theme: GradientTheme) => void
currentTheme?: GradientTheme
}
const GradientThemeSelector: React.FC<GradientThemeSelectorProps> = ({
visible,
onClose,
onSelect,
currentTheme
}) => {
const [selectedTheme, setSelectedTheme] = useState<GradientTheme | null>(currentTheme || null)
const handleThemeSelect = (theme: GradientTheme) => {
setSelectedTheme(theme)
}
const handleConfirm = () => {
if (selectedTheme) {
onSelect(selectedTheme)
onClose()
}
}
const renderThemeItem = (theme: GradientTheme) => {
const isSelected = selectedTheme?.name === theme.name
return (
<View
key={theme.name}
className={`p-3 rounded-lg border-2 ${isSelected ? 'border-blue-500' : 'border-gray-200'}`}
onClick={() => handleThemeSelect(theme)}
>
{/* 渐变预览 */}
<View
className="w-full h-16 rounded-lg mb-2"
style={{
background: theme.background
}}
>
<View className="w-full h-full flex items-center justify-center">
<Text className="text-white text-xs font-bold">
</Text>
</View>
</View>
{/* 主题信息 */}
<View className="text-center">
<Text className="text-sm font-semibold text-gray-800 mb-1">
{theme.description.split(' - ')[0]}
</Text>
<Text className="text-xs text-gray-500">
{theme.description.split(' - ')[1]}
</Text>
</View>
{/* 选中标识 */}
{isSelected && (
<View className="absolute top-1 right-1 w-6 h-6 bg-blue-500 rounded-full flex items-center justify-center">
<Text className="text-white text-xs"></Text>
</View>
)}
</View>
)
}
return (
<Popup
visible={visible}
position="bottom"
onClose={onClose}
style={{ height: '70vh' }}
>
<View className="p-4">
<View className="flex items-center justify-between mb-4">
<Text className="text-lg font-bold"></Text>
<Button size="small" fill="outline" onClick={onClose}>
</Button>
</View>
<Text className="text-sm text-gray-600 mb-4">
</Text>
{/* 主题网格 */}
<View className="grid grid-cols-2 gap-3 mb-6">
{gradientThemes.map(renderThemeItem)}
</View>
{/* 确认按钮 */}
<Button
type="primary"
block
disabled={!selectedTheme}
onClick={handleConfirm}
>
</Button>
</View>
</Popup>
)
}
export default GradientThemeSelector