feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面
This commit is contained in:
@@ -18,34 +18,21 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Button, Input, Radio, RadioGroup, Tag } from '@douyinfe/semi-ui';
|
||||
import { Image, Palette, Sparkles, Type, Wand2 } from 'lucide-react';
|
||||
import { Input as AntInput, Segmented } from 'antd';
|
||||
import { Button, Input } from '@/components/ui';
|
||||
import { Check } from 'lucide-react';
|
||||
import {
|
||||
CARTOON_AVATAR_PRESETS,
|
||||
USER_AVATAR_TYPES,
|
||||
getCartoonAvatarDataUrl,
|
||||
getInitialAvatarDataUrl,
|
||||
} from '../../../../helpers';
|
||||
import SectionHeader from '../components/SectionHeader';
|
||||
|
||||
const AVATAR_TYPE_OPTIONS = [
|
||||
{
|
||||
value: USER_AVATAR_TYPES.PRESET,
|
||||
label: '卡通形象',
|
||||
desc: '从系统内置卡通头像中选择,适合默认展示',
|
||||
icon: Palette,
|
||||
},
|
||||
{
|
||||
value: USER_AVATAR_TYPES.INITIAL,
|
||||
label: '姓名首字',
|
||||
desc: '根据用户名自动生成简洁文字头像',
|
||||
icon: Type,
|
||||
},
|
||||
{
|
||||
value: USER_AVATAR_TYPES.CUSTOM,
|
||||
label: '图片链接',
|
||||
desc: '填写公网图片 URL,使用自己的头像',
|
||||
icon: Image,
|
||||
},
|
||||
{ value: USER_AVATAR_TYPES.PRESET, label: '卡通形象' },
|
||||
{ value: USER_AVATAR_TYPES.INITIAL, label: '姓名首字' },
|
||||
{ value: USER_AVATAR_TYPES.CUSTOM, label: '图片链接' },
|
||||
];
|
||||
|
||||
const AvatarSection = ({
|
||||
@@ -71,108 +58,58 @@ const AvatarSection = ({
|
||||
avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM &&
|
||||
!avatarSettings.customAvatarUrl?.trim();
|
||||
|
||||
// 与 getInitialAvatarDataUrl 相同的首字取法,仅用于展示,不进入保存载荷
|
||||
const initialText = username ? username[0].toUpperCase() : '';
|
||||
|
||||
return (
|
||||
<div className='space-y-6'>
|
||||
<div className='flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 rounded-3xl border border-white/70 dark:border-white/10 bg-white/50 dark:bg-white/[0.045] backdrop-blur-xl px-5 py-4'>
|
||||
<div className='flex items-center gap-3'>
|
||||
<div className='w-11 h-11 rounded-2xl bg-gradient-to-br from-rose-500 to-orange-400 flex items-center justify-center shadow-lg shadow-rose-500/20'>
|
||||
<Wand2 className='w-5 h-5 text-white' />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className='text-xl font-bold text-gray-900 dark:text-white'>
|
||||
{t('头像设置')}
|
||||
</h2>
|
||||
<p className='text-sm text-gray-500 dark:text-gray-400'>
|
||||
{t('选择你在平台内展示的头像样式')}
|
||||
</p>
|
||||
</div>
|
||||
<section className='ui-avatar-section'>
|
||||
<SectionHeader
|
||||
title={t('头像设置')}
|
||||
description={t('选择你在平台内展示的头像样式')}
|
||||
extra={
|
||||
<Button
|
||||
theme='solid'
|
||||
loading={savingAvatarSettings}
|
||||
disabled={customAvatarInvalid}
|
||||
onClick={saveAvatarSettings}
|
||||
>
|
||||
{t('保存头像')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
<div className='ui-avatar-layout'>
|
||||
<div className='ui-avatar-preview'>
|
||||
<span className='ui-avatar-preview-frame'>
|
||||
<img src={previewUrl} alt={t('头像预览')} />
|
||||
</span>
|
||||
<strong>{username}</strong>
|
||||
<span className='ui-avatar-preview-live'>{t('实时预览')}</span>
|
||||
<p>{t('头像将同步显示在用户入口和体验中心对话中')}</p>
|
||||
</div>
|
||||
<Button
|
||||
theme='solid'
|
||||
loading={savingAvatarSettings}
|
||||
disabled={customAvatarInvalid}
|
||||
onClick={saveAvatarSettings}
|
||||
className='!bg-gradient-to-r !from-rose-500 !to-orange-400 !border-0 !rounded-xl !shadow-lg !shadow-rose-500/20'
|
||||
>
|
||||
{t('保存头像')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-1 xl:grid-cols-[280px_1fr] gap-5'>
|
||||
<div className='relative overflow-hidden rounded-[28px] border border-white/70 dark:border-white/10 bg-white/[0.54] dark:bg-white/[0.045] p-5 shadow-[0_20px_55px_rgba(244,63,94,0.10)]'>
|
||||
<div className='absolute inset-0 bg-[radial-gradient(circle_at_25%_20%,rgba(251,113,133,0.22),transparent_32%),radial-gradient(circle_at_90%_85%,rgba(251,146,60,0.16),transparent_34%)] pointer-events-none' />
|
||||
<div className='relative flex flex-col items-center text-center'>
|
||||
<div className='relative mb-4'>
|
||||
<div className='absolute inset-0 rounded-[32px] bg-gradient-to-br from-rose-500 to-orange-400 blur-lg opacity-30' />
|
||||
<img
|
||||
src={previewUrl}
|
||||
alt={t('头像预览')}
|
||||
className='relative w-28 h-28 rounded-[32px] object-cover ring-4 ring-white/90 dark:ring-slate-950 shadow-xl'
|
||||
/>
|
||||
<span className='absolute -bottom-1 -right-1 w-6 h-6 rounded-full bg-emerald-500 border-4 border-white dark:border-slate-950' />
|
||||
</div>
|
||||
<div className='text-base font-semibold text-gray-900 dark:text-white'>
|
||||
{username}
|
||||
</div>
|
||||
<div className='mt-2 text-xs text-gray-500 dark:text-gray-400 leading-relaxed'>
|
||||
{t('该头像会同步展示在右上角用户入口和体验中心文本对话中。')}
|
||||
</div>
|
||||
<Tag
|
||||
color='pink'
|
||||
shape='circle'
|
||||
className='mt-4 !bg-white/70 dark:!bg-white/[0.08]'
|
||||
>
|
||||
{t('实时预览')}
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='rounded-[28px] border border-white/70 dark:border-white/10 bg-white/50 dark:bg-white/[0.045] backdrop-blur-xl p-5'>
|
||||
<div className='mb-5'>
|
||||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3'>
|
||||
{t('头像类型')}
|
||||
</label>
|
||||
<RadioGroup
|
||||
type='button'
|
||||
value={avatarSettings.avatarType}
|
||||
onChange={(e) =>
|
||||
handleAvatarSettingChange('avatarType', e.target.value)
|
||||
}
|
||||
className='!flex !flex-wrap !gap-2'
|
||||
>
|
||||
{AVATAR_TYPE_OPTIONS.map((option) => {
|
||||
const Icon = option.icon;
|
||||
return (
|
||||
<Radio key={option.value} value={option.value}>
|
||||
<span className='inline-flex items-center gap-1.5'>
|
||||
<Icon size={14} />
|
||||
{t(option.label)}
|
||||
</span>
|
||||
</Radio>
|
||||
);
|
||||
})}
|
||||
</RadioGroup>
|
||||
<p className='mt-2 text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t(
|
||||
AVATAR_TYPE_OPTIONS.find(
|
||||
(item) => item.value === avatarSettings.avatarType,
|
||||
)?.desc || '',
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className='ui-avatar-editor'>
|
||||
<div className='ui-avatar-field-label'>{t('头像类型')}</div>
|
||||
<Segmented
|
||||
block
|
||||
value={avatarSettings.avatarType}
|
||||
onChange={(value) => handleAvatarSettingChange('avatarType', value)}
|
||||
options={AVATAR_TYPE_OPTIONS.map((option) => ({
|
||||
value: option.value,
|
||||
label: t(option.label),
|
||||
}))}
|
||||
/>
|
||||
{avatarSettings.avatarType === USER_AVATAR_TYPES.PRESET && (
|
||||
<div>
|
||||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-3'>
|
||||
<div className='ui-avatar-field'>
|
||||
<div className='ui-avatar-field-label ui-avatar-field-label-muted'>
|
||||
{t('选择卡通形象')}
|
||||
</label>
|
||||
<div className='grid grid-cols-2 sm:grid-cols-4 gap-3'>
|
||||
</div>
|
||||
<div className='ui-avatar-grid'>
|
||||
{CARTOON_AVATAR_PRESETS.map((preset) => {
|
||||
const selected = avatarSettings.avatarPreset === preset.id;
|
||||
return (
|
||||
<button
|
||||
key={preset.id}
|
||||
type='button'
|
||||
aria-pressed={selected}
|
||||
onClick={() => {
|
||||
handleAvatarSettingChange(
|
||||
'avatarType',
|
||||
@@ -180,25 +117,15 @@ const AvatarSection = ({
|
||||
);
|
||||
handleAvatarSettingChange('avatarPreset', preset.id);
|
||||
}}
|
||||
className={`group relative rounded-2xl border p-3 transition-all duration-200 ${
|
||||
selected
|
||||
? 'border-rose-300 bg-white/[0.82] dark:bg-white/[0.08] shadow-lg shadow-rose-500/10'
|
||||
: 'border-white/70 dark:border-white/10 bg-white/[0.46] dark:bg-white/[0.035] hover:border-rose-200 dark:hover:border-rose-400/25'
|
||||
}`}
|
||||
className={`ui-avatar-option ${selected ? 'selected' : ''}`}
|
||||
>
|
||||
<img
|
||||
src={getCartoonAvatarDataUrl(preset.id, 96)}
|
||||
alt={preset.label}
|
||||
className='mx-auto w-14 h-14 rounded-2xl object-cover transition-transform group-hover:scale-105'
|
||||
/>
|
||||
<div className='mt-2 text-xs font-medium text-gray-700 dark:text-gray-200 truncate'>
|
||||
{t(preset.label)}
|
||||
</div>
|
||||
<span>{t(preset.label)}</span>
|
||||
{selected && (
|
||||
<Sparkles
|
||||
size={16}
|
||||
className='absolute top-2 right-2 text-rose-500'
|
||||
/>
|
||||
<Check size={14} className='ui-avatar-check' />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
@@ -206,28 +133,37 @@ const AvatarSection = ({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{avatarSettings.avatarType === USER_AVATAR_TYPES.INITIAL && (
|
||||
<div className='ui-avatar-field'>
|
||||
<div className='ui-avatar-field-label'>{t('显示文字')}</div>
|
||||
<AntInput
|
||||
readOnly
|
||||
value={initialText}
|
||||
className='ui-avatar-text-input'
|
||||
aria-label={t('显示文字')}
|
||||
/>
|
||||
<p className='ui-avatar-help'>
|
||||
{t('根据用户名自动生成简洁文字头像')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM && (
|
||||
<div className='rounded-2xl border border-sky-100 dark:border-sky-400/20 bg-sky-50/[0.55] dark:bg-sky-400/[0.06] p-4'>
|
||||
<div className='ui-avatar-field'>
|
||||
<div className='ui-avatar-field-label'>{t('图片链接')}</div>
|
||||
<Input
|
||||
className='ui-avatar-text-input'
|
||||
value={avatarSettings.customAvatarUrl}
|
||||
onChange={(value) =>
|
||||
handleAvatarSettingChange('customAvatarUrl', value)
|
||||
}
|
||||
placeholder={t(
|
||||
'请输入图片 URL,例如 https://example.com/avatar.png',
|
||||
)}
|
||||
prefix={<Image size={15} className='text-sky-500' />}
|
||||
placeholder='https://example.com/avatar.png'
|
||||
showClear
|
||||
/>
|
||||
<p className='mt-2 text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t('支持公网图片链接。若图片加载失败,会回退到默认卡通头像。')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user