| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634 |
- import { useEffect, useState, useCallback, useRef } from 'react';
- import { useNavigate } from 'react-router-dom';
- import { useTranslation } from 'react-i18next';
- import { px2vmin, px2vmax, px2vw } from '@/utils/viewport';
- import {
- getUserInfo,
- updateUsername,
- updateBotName,
- getUserUIState,
- updateUserUIState,
- // 统一的 API 工具:包含 userId/token 头部和与 ws 一致的 base URL 推导
- getApiBaseUrl,
- getApiHeaders,
- } from '@/utils/api';
- import {
- getUserId,
- getStorage,
- setStorage,
- STORAGE_KEYS,
- setCurrentAvatarId as setAvatarIdToStorage,
- setCurrentBackgroundImageId as setBackgroundImageIdToStorage,
- getCurrentBackgroundImageId,
- clearUserSessionAndRedirectToBegin,
- } from '@/utils/storage';
- import { getOssUrl } from '@/utils/oss';
- import { MissionEnergyStoneModal } from '@/components/MissionEnergyStoneModal';
- import { UserAgreementModal } from '@/components/UserAgreementModal';
- import { PrivacyPolicyModal } from '@/components/PrivacyPolicyModal';
- const closeBtn = getOssUrl('close-btn.png');
- const editIcon = getOssUrl('mode_edit_outline.png');
- const conversationEnergyStoneCount = getOssUrl('conversion-energy-stone-count.png');
- const lumiNoCap = getOssUrl('Lumi-no-cap.png');
- const lumiCap = getOssUrl('Lumi-cap.png');
- const arrowRight = getOssUrl('arrow_right.png');
- const headCap = getOssUrl('head-cap.png');
- const bgHappyNewYear = getOssUrl('bg-happynewyear-s.png');
- const starBg = getOssUrl('star-bg.png');
- const rocketIcon = getOssUrl('Rocket.gif');
- const XIconImage = getOssUrl('x-icon.png');
- const primaryDefaultButton = getOssUrl('primary-default.png');
- const secondaryDefaultButton = getOssUrl('secondary-default.png');
- export const ProfilePage = () => {
- const { t } = useTranslation('profile');
- const { t: tCommon } = useTranslation('common');
- const navigate = useNavigate();
- const [username, setUsername] = useState<string>('');
- const [botName, setBotName] = useState<string>('');
- const [, setMissionStoneCount] = useState<number>(0);
- const [conversationStoneCount, setConversationStoneCount] = useState<number>(0);
- const [hasCap, setHasCap] = useState<boolean>(false);
- const [hasBackgroundReward, setHasBackgroundReward] = useState<boolean>(false);
- const [currentAvatarId, setCurrentAvatarId] = useState<string | null>(null);
- const [currentBackgroundImageId, setCurrentBackgroundImageId] = useState<string | null>(null);
- const [loading, setLoading] = useState<boolean>(true);
- const [userLevel, setUserLevel] = useState<number>(0);
- const [totalSpeechDurationMs, setTotalSpeechDurationMs] = useState<number>(0);
- const [showUsernameModal, setShowUsernameModal] = useState<boolean>(false);
- const [showBotNameModal, setShowBotNameModal] = useState<boolean>(false);
- const [tempUsername, setTempUsername] = useState<string>('');
- const [tempBotName, setTempBotName] = useState<string>('');
- const [isUsernameFocused, setIsUsernameFocused] = useState<boolean>(false);
- const [isBotNameFocused, setIsBotNameFocused] = useState<boolean>(false);
- const usernameInputRef = useRef<HTMLInputElement>(null);
- const botNameInputRef = useRef<HTMLInputElement>(null);
- const [showEnergyStoneModal, setShowEnergyStoneModal] = useState<boolean>(false);
- const [energyStoneModalType, setEnergyStoneModalType] = useState<'mission' | 'conversation'>('mission');
- const [showFeedbackModal, setShowFeedbackModal] = useState<boolean>(false);
- const [feedbackText, setFeedbackText] = useState<string>('');
- const [isSubmittingFeedback, setIsSubmittingFeedback] = useState<boolean>(false);
- const [showAgreementModal, setShowAgreementModal] = useState<boolean>(false);
- const [showPrivacyPolicyModal, setShowPrivacyPolicyModal] = useState<boolean>(false);
-
- // const cancelBtnImage = getOssUrl('cancel.png'); // Unused - replaced by primary buttons
- // const changeBtnImage = getOssUrl('change.png'); // Unused - replaced by primary buttons
- // const changeBtnActiveImage = getOssUrl('change-a.png'); // Unused - replaced by primary buttons
- // const sendBtnImage = getOssUrl('send.png'); // Unused - replaced by primary buttons
- // const sendBtnActiveImage = getOssUrl('send-a.png'); // Unused - replaced by primary buttons
- // 获取能量石数量
- const fetchEnergyStoneCounts = useCallback(
- async (userId: string) => {
- try {
- const apiBaseUrl = getApiBaseUrl();
- const request = async () =>
- fetch(`${apiBaseUrl}/api/users/${userId}/energy-stones/count`, {
- method: 'GET',
- headers: getApiHeaders(),
- });
- let response = await request();
- if (response.status === 401) {
- // 会话失效:清空本地状态并统一跳转到 /begin
- console.warn(
- '[ProfilePage] 请求能量石数量接口返回 401,认为会话失效,准备清空本地并跳转 /begin',
- {
- userId,
- }
- );
- clearUserSessionAndRedirectToBegin();
- return;
- }
- if (response.ok) {
- const data = await response.json();
- if (data.success && data.data) {
- setMissionStoneCount(data.data.mission_count || 0);
- setConversationStoneCount(data.data.conversation_count || 0);
- }
- }
- } catch (error) {
- console.error('[ProfilePage] 获取能量石数量失败:', error);
- }
- },
- []
- );
- // 获取用户头像信息
- const fetchUserAvatars = useCallback(
- async (userId: string) => {
- try {
- const apiBaseUrl = getApiBaseUrl();
- const request = async () =>
- fetch(`${apiBaseUrl}/api/users/${userId}/avatars`, {
- method: 'GET',
- headers: getApiHeaders(),
- });
- let response = await request();
- if (response.status === 401) {
- clearUserSessionAndRedirectToBegin();
- return;
- }
- if (response.ok) {
- const data = await response.json();
- if (data.success && data.data) {
- const avatarIds = data.data.avatar_ids || [];
- // 检查是否有注册赠送的形象(带帽子)
- const hasRegisteredCap = avatarIds.includes('avatar_registered_cap');
- setHasCap(hasRegisteredCap);
- }
- }
- } catch (error) {
- console.error('[ProfilePage] 获取用户头像信息失败:', error);
- }
- },
- []
- );
- // 获取用户背景图片信息
- const fetchUserBackgroundImages = useCallback(
- async (userId: string) => {
- try {
- const apiBaseUrl = getApiBaseUrl();
- const request = async () =>
- fetch(`${apiBaseUrl}/api/users/${userId}/background-images`, {
- method: 'GET',
- headers: getApiHeaders(),
- });
- let response = await request();
- if (response.status === 401) {
- clearUserSessionAndRedirectToBegin();
- return;
- }
- if (response.ok) {
- const data = await response.json();
- if (data.success && data.data) {
- const imageIds = data.data.image_ids || [];
- const hasNewYearBackground = imageIds.some((id: string) =>
- id.toLowerCase().includes('newyear') ||
- id.toLowerCase().includes('happynewyear') ||
- id.toLowerCase().includes('new_year')
- );
- setHasBackgroundReward(hasNewYearBackground);
- }
- }
- } catch (error) {
- console.error('[ProfilePage] 获取用户背景图片信息失败:', error);
- }
- },
- []
- );
- // 加载用户信息
- useEffect(() => {
- const loadUserData = async () => {
- const userId = getUserId();
- if (!userId) {
- navigate('/email-login');
- return;
- }
- try {
- // 获取用户基本信息(401 时由各接口内部的 401 分支负责处理会话失效)
- const userInfo = await getUserInfo(userId);
- if (userInfo.success && userInfo.data) {
- setUsername(userInfo.data.username || '');
- setBotName(userInfo.data.bot_name || getStorage(STORAGE_KEYS.LUMI_NAME) || 'Lumi');
- setUserLevel(userInfo.data.user_level || 0);
- // 同步当前背景图片状态(用于正确展示选中边框)
- const backgroundIdFromUser = userInfo.data.current_background_image_id || getCurrentBackgroundImageId();
- if (backgroundIdFromUser) {
- setCurrentBackgroundImageId(backgroundIdFromUser);
- // 存一份到 localStorage,保持与后端一致
- setBackgroundImageIdToStorage(backgroundIdFromUser);
- }
- setTotalSpeechDurationMs(userInfo.data.total_speech_duration_ms || 0);
- }
- // 获取用户 UI 状态(包含 current_avatar_id)
- const uiState = await getUserUIState(userId);
- if (uiState.success && uiState.data) {
- setCurrentAvatarId(uiState.data.current_avatar_id || null);
- }
- // 获取能量石数量
- await fetchEnergyStoneCounts(userId);
- // 获取用户头像信息
- await fetchUserAvatars(userId);
- // 获取用户背景图片信息
- await fetchUserBackgroundImages(userId);
- } catch (error) {
- console.error('加载用户数据失败:', error);
- } finally {
- setLoading(false);
- }
- };
- loadUserData();
- }, [navigate, fetchEnergyStoneCounts, fetchUserAvatars, fetchUserBackgroundImages]);
- // 防止弹窗打开时背景滚动
- useEffect(() => {
- if (showUsernameModal || showBotNameModal || showEnergyStoneModal || showFeedbackModal || showAgreementModal || showPrivacyPolicyModal) {
- document.body.style.overflow = 'hidden';
- } else {
- document.body.style.overflow = '';
- }
- return () => {
- document.body.style.overflow = '';
- };
- }, [showUsernameModal, showBotNameModal, showEnergyStoneModal, showFeedbackModal, showAgreementModal, showPrivacyPolicyModal]);
- const handleClose = useCallback(() => {
- navigate(-1);
- }, [navigate]);
- const handleHeadClick = useCallback(async () => {
- const userId = getUserId();
- if (!userId) return;
- if (!hasCap) {
- navigate('/first-login');
- return;
- }
- // 已拥有情况下,切换头像
- const newAvatarId = currentAvatarId === 'avatar_registered_cap'
- ? 'avatar_default'
- : 'avatar_registered_cap';
-
- try {
- const result = await updateUserUIState(userId, { current_avatar_id: newAvatarId });
- if (result.success) {
- setCurrentAvatarId(newAvatarId); // 更新 React state
- setAvatarIdToStorage(newAvatarId); // 同步到 localStorage
- }
- } catch (error) {
- console.error('切换头像失败:', error);
- }
- }, [hasCap, currentAvatarId, navigate]);
- // 打开编辑用户名弹窗
- const handleEditUsername = useCallback(() => {
- setTempUsername(username);
- setShowUsernameModal(true);
- setTimeout(() => {
- usernameInputRef.current?.focus();
- }, 0);
- }, [username]);
- // 检查用户名是否改变(且非空)
- const isUsernameChanged = tempUsername.trim() !== username.trim();
- // 保存用户名
- const handleSaveUsername = useCallback(async () => {
- const userId = getUserId();
- if (!userId || !tempUsername.trim()) {
- setShowUsernameModal(false);
- return;
- }
- try {
- const result = await updateUsername(userId, tempUsername.trim());
- if (result.success) {
- setUsername(tempUsername.trim());
- setShowUsernameModal(false);
- }
- } catch (error) {
- console.error('保存用户名失败:', error);
- setShowUsernameModal(false);
- }
- }, [tempUsername]);
- // 关闭编辑用户名弹窗
- const handleCloseUsernameModal = useCallback(() => {
- setShowUsernameModal(false);
- setTempUsername('');
- }, []);
- // 打开编辑 Lumi 名字弹窗
- const handleEditBotName = useCallback(() => {
- setTempBotName(botName);
- setShowBotNameModal(true);
- setTimeout(() => {
- botNameInputRef.current?.focus();
- }, 0);
- }, [botName]);
- // 检查 Lumi 名字是否改变(且非空)
- const isBotNameChanged = tempBotName.trim() !== botName.trim();
- // 保存 Lumi 名字
- const handleSaveBotName = useCallback(async () => {
- const userId = getUserId();
- if (!userId || !tempBotName.trim()) {
- setShowBotNameModal(false);
- return;
- }
- try {
- const result = await updateBotName(userId, tempBotName.trim());
- if (result.success) {
- setBotName(tempBotName.trim());
- setShowBotNameModal(false);
- // 同时更新 localStorage
- setStorage(STORAGE_KEYS.LUMI_NAME, tempBotName.trim());
- }
- } catch (error) {
- console.error('保存 Lumi 名字失败:', error);
- setShowBotNameModal(false);
- }
- }, [tempBotName]);
- // 关闭编辑 Lumi 名字弹窗
- const handleCloseBotNameModal = useCallback(() => {
- setShowBotNameModal(false);
- setTempBotName('');
- }, []);
- // 处理能量石点击
- const handleEnergyStoneClick = useCallback((stoneType: 'mission' | 'conversation') => {
- setEnergyStoneModalType(stoneType);
- setShowEnergyStoneModal(true);
- }, []);
- // 关闭能量石弹窗
- const handleCloseEnergyStoneModal = useCallback(() => {
- setShowEnergyStoneModal(false);
- }, []);
- // 打开反馈弹窗
- const handleOpenFeedbackModal = useCallback(() => {
- setShowFeedbackModal(true);
- setFeedbackText('');
- }, []);
- // 关闭反馈弹窗
- const handleCloseFeedbackModal = useCallback(() => {
- setShowFeedbackModal(false);
- setFeedbackText('');
- }, []);
- // 提交反馈
- const handleSubmitFeedback = useCallback(async () => {
- const userId = getUserId();
- if (!userId || !feedbackText.trim()) {
- return;
- }
- setIsSubmittingFeedback(true);
- try {
- const apiBaseUrl = getApiBaseUrl();
- const response = await fetch(`${apiBaseUrl}/api/users/${userId}/feedback`, {
- method: 'POST',
- headers: getApiHeaders(),
- body: JSON.stringify({ content: feedbackText.trim() }),
- });
- if (response.ok) {
- setShowFeedbackModal(false);
- setFeedbackText('');
- // 可以添加成功提示
- } else {
- console.error('提交反馈失败:', response.statusText);
- }
- } catch (error) {
- console.error('提交反馈异常:', error);
- } finally {
- setIsSubmittingFeedback(false);
- }
- }, [feedbackText]);
- // 计算升级所需时间和当前进度
- const getLevelProgress = useCallback(() => {
- const level = userLevel;
- const totalSeconds = Math.floor(totalSpeechDurationMs / 1000);
- // 定义各等级升级需要的时长(秒)
- const requiredTimesByLevel = [10, 30, 60, 120, 240, 240];
-
- // 获取当前等级升级需要的时长
- const requiredTime = requiredTimesByLevel[level] || 240;
-
- // 当前已沟通的时长(秒)= 总时长
- const currentTime = Math.max(0, totalSeconds);
-
- // 进度百分比 = 当前已沟通时长 / 升级需要的时长
- const progress = Math.min(100, (currentTime / requiredTime) * 100);
- return {
- currentTime,
- requiredTime,
- progress,
- displayText: `${currentTime}/${requiredTime}`,
- };
- }, [userLevel, totalSpeechDurationMs]);
- if (loading) {
- return (
- <div
- style={{
- width: '100vw',
- height: '100vh',
- backgroundColor: '#1A1821',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- color: '#fff',
- }}
- >
- {tCommon('message.loading')}
- </div>
- );
- }
- return (
- <>
- <style>{`
- @keyframes fadeIn {
- from {
- opacity: 0;
- }
- to {
- opacity: 1;
- }
- }
- .profile-modal-input::placeholder {
- color: rgba(245, 243, 240, 0.45);
- }
- .feedback-textarea::placeholder {
- color: rgba(245, 243, 240, 0.45);
- }
- `}</style>
- <div
- style={{
- height: '100vh',
- position: 'relative',
- overflow: 'hidden',
- }}
- >
- {/* 关闭按钮 */}
- <img
- src={closeBtn}
- alt="Close"
- onClick={handleClose}
- style={{
- width: px2vmin(30),
- height: px2vmin(30),
- position: 'absolute',
- top: px2vmin(62),
- right: px2vmin(27),
- cursor: 'pointer',
- zIndex: 100,
- }}
- />
- {/* 用户名字和编辑图标 */}
- <div
- style={{
- position: 'absolute',
- top: px2vmin(90),
- left: '50%',
- transform: 'translateX(-50%)',
- display: 'flex',
- alignItems: 'center',
- gap: px2vmin(8),
- zIndex: 10,
- }}
- >
- <span
- style={{
- fontSize: px2vmin(18),
- color: '#fff',
- fontWeight: 500,
- }}
- >
- {username || tCommon('userDefault')}
- </span>
- <img
- src={editIcon}
- alt="Edit"
- onClick={handleEditUsername}
- style={{
- width: px2vmin(20),
- height: px2vmin(20),
- cursor: 'pointer',
- }}
- />
- </div>
- {/* 用户等级显示区域 */}
- <div
- style={{
- position: 'absolute',
- top: px2vmin(166),
- left: '50%',
- transform: 'translateX(-50%)',
- width: px2vmin(343),
- height: px2vmin(38),
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'flex-start',
- zIndex: 10,
- }}
- >
- {/* 对话能量石:放在等级行左侧 */}
- <div
- onClick={() => handleEnergyStoneClick('conversation')}
- style={{
- position: 'relative',
- width: px2vmin(70),
- height: px2vmin(32),
- cursor: 'pointer',
- flexShrink: 0,
- }}
- >
- <img
- src={conversationEnergyStoneCount}
- alt="Conversation Energy Stone"
- style={{
- width: '100%',
- height: '100%',
- }}
- />
- <span
- style={{
- position: 'absolute',
- top: '50%',
- left: '60%',
- transform: 'translate(-50%, -50%)',
- fontSize: px2vmin(10),
- color: '#000',
- fontWeight: 500,
- }}
- >
- {conversationStoneCount}
- </span>
- </div>
- {/* 等级和进度内容区域,与对话能量石间隔 16 */}
- <div
- style={{
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'space-between',
- flex: 1,
- marginLeft: px2vmin(16),
- }}
- >
- {/* 第一个五角星 - 当前等级 */}
- <div
- style={{
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- }}
- >
- <img
- src={starBg}
- alt="Star"
- style={{
- width: px2vmin(32),
- height: px2vmin(32),
- }}
- />
- <span
- style={{
- position: 'absolute',
- top: '50%',
- left: '50%',
- transform: 'translate(-50%, -50%)',
- fontSize: px2vmin(10),
- color: '#000',
- fontWeight: 600,
- }}
- >
- {userLevel}
- </span>
- </div>
- {/* 进度条区域 */}
- <div
- style={{
- position: 'relative',
- flex: 1,
- marginLeft: px2vmin(8),
- marginRight: px2vmin(8),
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- }}
- >
- {/* 进度条 - 与五角星居中对齐 */}
- <div
- style={{
- width: px2vmin(166),
- height: px2vmin(12),
- backgroundColor: 'rgba(255, 255, 255, 0.2)',
- borderRadius: px2vmin(6),
- overflow: 'hidden',
- position: 'relative',
- }}
- >
- <div
- style={{
- width: `${getLevelProgress().progress}%`,
- height: '100%',
- backgroundColor: '#BF9DF8',
- borderRadius: px2vmin(6),
- transition: 'width 0.3s ease',
- }}
- />
- </div>
- {/* 进度文字 - 绝对定位在进度条上方 */}
- <span
- style={{
- position: 'absolute',
- top: px2vmin(-16),
- left: '50%',
- transform: 'translateX(-50%)',
- fontSize: px2vmin(10),
- color: '#fff',
- lineHeight: 1,
- whiteSpace: 'nowrap',
- }}
- >
- {getLevelProgress().displayText}
- </span>
- </div>
- {/* 第三个元素 - 下一等级或火箭 */}
- <div
- style={{
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- }}
- >
- {userLevel >= 5 ? (
- <img
- src={rocketIcon}
- alt="Rocket"
- style={{
- width: px2vmin(32),
- height: px2vmin(32),
- }}
- />
- ) : (
- <>
- <img
- src={starBg}
- alt="Star"
- style={{
- width: px2vmin(32),
- height: px2vmin(32),
- }}
- />
- <span
- style={{
- position: 'absolute',
- top: '50%',
- left: '50%',
- transform: 'translate(-50%, -50%)',
- fontSize: px2vmin(10),
- color: '#000',
- fontWeight: 600,
- }}
- >
- {userLevel + 1}
- </span>
- </>
- )}
- </div>
- </div>
- </div>
- {/* 区域A */}
- <div
- style={{
- position: 'absolute',
- top: px2vmin(256),
- left: '50%',
- transform: 'translateX(-50%)',
- width: px2vmin(343),
- height: px2vmin(240),
- backgroundColor: '#4A4459',
- borderRadius: px2vmin(28),
- zIndex: 10,
- }}
- >
- {/* Lumi 头像 */}
- <img
- src={currentAvatarId === 'avatar_registered_cap' ? lumiCap : lumiNoCap}
- alt="Lumi"
- style={{
- width: px2vmin(180),
- height: px2vmin(180),
- position: 'absolute',
- left: 0,
- top: px2vmax(-56),
- }}
- />
- {/* Lumi名字和编辑图标 */}
- <div
- style={{
- position: 'absolute',
- left: px2vmin(200),
- marginRight: px2vmin(10),
- top: px2vmin(36),
- display: 'flex',
- alignItems: 'center',
- gap: px2vmin(8),
- }}
- >
- <span
- style={{
- fontSize: px2vmin(18),
- color: '#fff',
- fontWeight: 500,
- }}
- >
- {botName}
- </span>
- <img
- src={editIcon}
- alt="Edit"
- onClick={handleEditBotName}
- style={{
- width: px2vmin(20),
- height: px2vmin(20),
- cursor: 'pointer',
- }}
- />
- </div>
- {/* 区域B */}
- <div
- style={{
- position: 'absolute',
- left: '50%',
- transform: 'translateX(-50%)',
- top: px2vmin(108),
- width: px2vmin(311),
- height: px2vmin(116),
- display: 'flex',
- gap: px2vmin(15),
- }}
- >
- {/* 区域C */}
- <div
- style={{
- width: px2vmin(148),
- height: px2vmin(116),
- backgroundColor: 'rgba(245,243,240, 0.1)',
- borderRadius: px2vmin(15),
- position: 'relative',
- }}
- >
- {/* 112*92 容器 */}
- <div
- style={{
- position: 'absolute',
- top: px2vmin(12),
- left: '50%',
- transform: 'translateX(-50%)',
- width: px2vmin(112),
- height: px2vmin(92),
- }}
- >
- {/* 108*70 边框区域 */}
- <div
- onClick={handleHeadClick}
- style={{
- width: px2vmin(108),
- height: px2vmin(70),
- border: `2px solid ${
- hasCap && currentAvatarId === 'avatar_registered_cap'
- ? '#BF9DF8'
- : 'rgba(245,243,240, 0.3)'
- }`,
- borderRadius: px2vmin(12),
- marginLeft: '50%',
- transform: 'translateX(-50%)',
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- cursor: hasCap ? 'pointer' : 'pointer',
- }}
- >
- <img
- src={headCap}
- alt="Head Cap"
- style={{
- width: px2vmin(70),
- height: px2vmin(70),
- }}
- />
- </div>
- {/* Head 文字 */}
- <div
- style={{
- marginTop: px2vmin(8),
- textAlign: 'center',
- fontSize: px2vmin(14),
- color: '#fff',
- }}
- >
- {t('head')}
- </div>
- </div>
- </div>
- {/* 区域D */}
- <div
- style={{
- width: px2vmin(148),
- height: px2vmin(116),
- backgroundColor: 'rgba(245,243,240, 0.1)',
- borderRadius: px2vmin(15),
- position: 'relative',
- }}
- >
- {/* 112*92 容器 */}
- <div
- style={{
- position: 'absolute',
- top: px2vmin(12),
- left: '50%',
- transform: 'translateX(-50%)',
- width: px2vmin(112),
- height: px2vmin(92),
- }}
- >
- {/* 108*70 边框区域(暂不支持点击/分享,仅展示) */}
- <div
- style={{
- width: px2vmin(108),
- height: px2vmin(70),
- border: `2px solid ${
- hasBackgroundReward && currentBackgroundImageId === 'happynewyear'
- ? '#BF9DF8'
- : 'rgba(245,243,240, 0.3)'
- }`,
- borderRadius: px2vmin(12),
- marginLeft: '50%',
- transform: 'translateX(-50%)',
- position: 'relative',
- overflow: 'hidden',
- cursor: 'default',
- }}
- >
- <img
- src={bgHappyNewYear}
- alt="Background"
- style={{
- width: '100%',
- height: '100%',
- objectFit: 'cover',
- }}
- />
- {/* 暂不支持分享:不再显示礼物图标和可点击蒙层 */}
- </div>
- {/* Background 文字 */}
- <div
- style={{
- marginTop: px2vmin(8),
- textAlign: 'center',
- fontSize: px2vmin(14),
- color: '#fff',
- }}
- >
- {t('background')}
- </div>
- </div>
- </div>
- </div>
- </div>
- {/* 区域E */}
- <div
- style={{
- position: 'absolute',
- top: px2vmin(534),
- left: '50%',
- transform: 'translateX(-50%)',
- width: px2vmin(343),
- height: px2vmin(178),
- zIndex: 10,
- }}
- >
- {/* 意见反馈 & 帮助 */}
- <div
- onClick={handleOpenFeedbackModal}
- style={{
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'space-between',
- height: px2vmin(59),
- borderTop: '1px solid #34313D',
- // marginLeft: px2vmin(10),
- // marginRight: px2vmin(10),
- cursor: 'pointer',
- }}
- >
- <span
- style={{
- fontSize: px2vmin(16),
- color: '#fff',
- marginLeft: px2vmin(10),
- }}
- >
- {t('feedbackAndHelp')}
- </span>
- <img
- src={arrowRight}
- alt="Arrow"
- style={{
- width: px2vmin(24),
- height: px2vmin(24),
- marginRight: '10px',
- }}
- />
- </div>
- {/* 使用协议 */}
- <div
- onClick={() => setShowAgreementModal(true)}
- style={{
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'space-between',
- height: px2vmin(59),
- borderTop: '1px solid #34313D',
- // marginLeft: px2vmin(10),
- // marginRight: px2vmin(10),
- cursor: 'pointer',
- }}
- >
- <span
- style={{
- fontSize: px2vmin(16),
- color: '#fff',
- marginLeft: px2vmin(10),
- }}
- >
- {t('userAgreement')}
- </span>
- <img
- src={arrowRight}
- alt="Arrow"
- style={{
- width: px2vmin(24),
- height: px2vmin(24),
- marginRight: '10px',
- }}
- />
- </div>
- {/* 隐私政策 */}
- <div
- onClick={() => setShowPrivacyPolicyModal(true)}
- style={{
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'space-between',
- height: px2vmin(59),
- borderTop: '1px solid #34313D',
- // marginLeft: px2vmin(10),
- // marginRight: px2vmin(10),
- cursor: 'pointer',
- }}
- >
- <span
- style={{
- fontSize: px2vmin(16),
- color: '#fff',
- marginLeft: px2vmin(10),
- }}
- >
- {t('privacyPolicy')}
- </span>
- <img
- src={arrowRight}
- alt="Arrow"
- style={{
- width: px2vmin(24),
- height: px2vmin(24),
- marginRight: '10px',
- }}
- />
- </div>
- </div>
- {/* 编辑用户名弹窗 */}
- {showUsernameModal && (
- <>
- {/* 遮罩层 */}
- <div
- onClick={handleCloseUsernameModal}
- style={{
- position: 'fixed',
- top: 0,
- left: 0,
- right: 0,
- bottom: 0,
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
- zIndex: 9998,
- animation: 'fadeIn 0.3s ease-out',
- }}
- />
- {/* 弹窗内容 */}
- <div
- style={{
- position: 'fixed',
- bottom: 0,
- left: '50%',
- transform: 'translateX(-50%)',
- width: px2vw(375),
- backgroundColor: '#34313D',
- borderTopLeftRadius: px2vmin(32),
- borderTopRightRadius: px2vmin(32),
- zIndex: 9999,
- display: 'flex',
- flexDirection: 'column',
- alignItems: 'center',
- paddingTop: px2vmin(12),
- paddingBottom: px2vmin(32),
- paddingLeft: px2vmin(32),
- paddingRight: px2vmin(32),
- }}
- >
- {/* 顶部拖拽指示条 */}
- <div
- style={{
- width: px2vmin(32),
- height: px2vmin(4),
- backgroundColor: '#79747E',
- borderRadius: px2vmin(4),
- }}
- />
- {/* 文字标签 */}
- <div
- style={{
- width: '100%',
- fontSize: px2vmin(14),
- color: '#fff',
- fontWeight: 'bold',
- marginTop: px2vmin(24),
- marginBottom: px2vmin(16),
- textAlign: 'left',
- }}
- >
- {t('changeMyName')}
- </div>
- {/* 输入框容器(与 email-login 一致:12PX 圆角 + 聚焦边框 #BF9DF8) */}
- <div
- style={{
- width: '100%',
- height: px2vmin(56),
- position: 'relative',
- marginBottom: px2vmin(32),
- }}
- >
- <div
- className="relative overflow-visible"
- style={{
- height: '100%',
- background: 'rgba(0,0,0,0.1)',
- borderRadius: '12PX',
- border: isUsernameFocused ? '1PX solid #BF9DF8' : '1PX solid transparent',
- boxShadow: isUsernameFocused
- ? 'none'
- : 'rgba(255, 255, 255, 0.18) 0px 1px 0px 0px, rgba(0, 0, 0, 0.65) 0px 0px 0px 1px inset, rgba(0, 0, 0, 0.25) 0px 4px 8px inset',
- }}
- >
- <input
- ref={usernameInputRef}
- type="text"
- value={tempUsername}
- onChange={(e) => setTempUsername(e.target.value)}
- onFocus={() => setIsUsernameFocused(true)}
- onBlur={() => setIsUsernameFocused(false)}
- onKeyDown={(e) => {
- if (e.key === 'Enter') {
- handleSaveUsername();
- } else if (e.key === 'Escape') {
- handleCloseUsernameModal();
- }
- }}
- placeholder={t('placeholderUsername')}
- className="w-full h-full font-normal leading-normal tracking-[0.5px] text-[rgba(245,243,240,0.7)] bg-transparent border-none outline-none placeholder:text-[rgba(245,243,240,0.45)]"
- style={{
- fontSize: px2vmin(16),
- paddingLeft: px2vmin(24),
- paddingRight: px2vmin(24),
- }}
- />
- {tempUsername ? (
- <button
- type="button"
- className="absolute top-1/2 -translate-y-1/2 flex items-center justify-center transition-opacity touch-manipulation"
- style={{
- right: px2vmin(12),
- width: px2vmin(24),
- height: px2vmin(24),
- background: 'transparent',
- border: 'none',
- cursor: 'pointer',
- opacity: isUsernameFocused ? 1 : 0.6,
- zIndex: 1,
- }}
- onClick={() => setTempUsername('')}
- onMouseDown={(e) => e.preventDefault()}
- aria-label={tCommon('a11y.clear')}
- >
- <img
- src={XIconImage}
- alt={tCommon('a11y.clear')}
- style={{
- width: px2vmin(24),
- height: px2vmin(24),
- objectFit: 'contain',
- }}
- draggable={false}
- />
- </button>
- ) : null}
- </div>
- </div>
- {/* 按钮组 */}
- <div
- style={{
- display: 'flex',
- gap: px2vmin(43),
- justifyContent: 'center',
- width: '100%',
- }}
- >
- <button
- onClick={handleCloseUsernameModal}
- style={{
- width: px2vmin(80),
- height: px2vmin(42),
- backgroundImage: `url(${secondaryDefaultButton})`,
- backgroundRepeat: 'no-repeat',
- backgroundPosition: 'center',
- border: 'none',
- cursor: 'pointer',
- padding: 0,
- borderRadius: px2vmin(20),
- }}
- >
- <span
- style={{
- display: 'inline-block',
- fontSize: px2vmin(16),
- color: '#FFFFFF',
- fontWeight: 500,
- }}
- >
- {tCommon('button.cancel')}
- </span>
- </button>
- <button
- onClick={handleSaveUsername}
- style={{
- width: px2vmin(84),
- height: px2vmin(42),
- backgroundImage: `url(${primaryDefaultButton})`,
- backgroundRepeat: 'no-repeat',
- backgroundPosition: 'center',
- border: 'none',
- cursor: isUsernameChanged && tempUsername.trim() ? 'pointer' : 'default',
- padding: 0,
- opacity: isUsernameChanged && tempUsername.trim() ? 1 : 0.6,
- borderRadius: px2vmin(20),
- }}
- disabled={!isUsernameChanged || !tempUsername.trim()}
- >
- <span
- style={{
- display: 'inline-block',
- fontSize: px2vmin(16),
- color: '#FFFFFF',
- fontWeight: 500,
- }}
- >
- {t('change')}
- </span>
- </button>
- </div>
- </div>
- </>
- )}
- {/* 编辑 Lumi 名字弹窗 */}
- {showBotNameModal && (
- <>
- {/* 遮罩层 */}
- <div
- onClick={handleCloseBotNameModal}
- style={{
- position: 'fixed',
- top: 0,
- left: 0,
- right: 0,
- bottom: 0,
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
- zIndex: 9998,
- animation: 'fadeIn 0.3s ease-out',
- }}
- />
- {/* 弹窗内容 */}
- <div
- style={{
- position: 'fixed',
- bottom: 0,
- left: '50%',
- transform: 'translateX(-50%)',
- width: px2vw(375),
- backgroundColor: '#34313D',
- borderTopLeftRadius: px2vmin(32),
- borderTopRightRadius: px2vmin(32),
- zIndex: 9999,
- display: 'flex',
- flexDirection: 'column',
- alignItems: 'center',
- paddingTop: px2vmin(12),
- paddingBottom: px2vmin(32),
- paddingLeft: px2vmin(32),
- paddingRight: px2vmin(32),
- }}
- >
- {/* 顶部拖拽指示条 */}
- <div
- style={{
- width: px2vmin(32),
- height: px2vmin(4),
- backgroundColor: '#79747E',
- borderRadius: px2vmin(4),
- }}
- />
- {/* 文字标签 */}
- <div
- style={{
- width: '100%',
- fontSize: px2vmin(14),
- color: '#fff',
- marginTop: px2vmin(24),
- marginBottom: px2vmin(16),
- textAlign: 'left',
- }}
- >
- {t('changeLumiName')}
- </div>
- {/* 输入框容器(与 email-login 一致:12PX 圆角 + 聚焦边框 #BF9DF8) */}
- <div
- style={{
- width: '100%',
- height: px2vmin(56),
- position: 'relative',
- marginBottom: px2vmin(32),
- }}
- >
- <div
- className="relative overflow-visible"
- style={{
- height: '100%',
- background: 'rgba(0,0,0,0.1)',
- borderRadius: '12PX',
- border: isBotNameFocused ? '1PX solid #BF9DF8' : '1PX solid transparent',
- boxShadow: isBotNameFocused
- ? 'none'
- : 'rgba(255, 255, 255, 0.18) 0px 1px 0px 0px, rgba(0, 0, 0, 0.65) 0px 0px 0px 1px inset, rgba(0, 0, 0, 0.25) 0px 4px 8px inset',
- }}
- >
- <input
- ref={botNameInputRef}
- type="text"
- value={tempBotName}
- onChange={(e) => setTempBotName(e.target.value)}
- onFocus={() => setIsBotNameFocused(true)}
- onBlur={() => setIsBotNameFocused(false)}
- onKeyDown={(e) => {
- if (e.key === 'Enter') {
- handleSaveBotName();
- } else if (e.key === 'Escape') {
- handleCloseBotNameModal();
- }
- }}
- placeholder={t('placeholderLumiName')}
- className="w-full h-full font-normal leading-normal tracking-[0.5px] text-[rgba(245,243,240,0.7)] bg-transparent border-none outline-none placeholder:text-[rgba(245,243,240,0.45)]"
- style={{
- fontSize: px2vmin(16),
- paddingLeft: px2vmin(24),
- paddingRight: px2vmin(24),
- }}
- />
- {tempBotName ? (
- <button
- type="button"
- className="absolute top-1/2 -translate-y-1/2 flex items-center justify-center transition-opacity touch-manipulation"
- style={{
- right: px2vmin(12),
- width: px2vmin(24),
- height: px2vmin(24),
- background: 'transparent',
- border: 'none',
- cursor: 'pointer',
- opacity: isBotNameFocused ? 1 : 0.6,
- zIndex: 1,
- }}
- onClick={() => setTempBotName('')}
- onMouseDown={(e) => e.preventDefault()}
- aria-label={tCommon('a11y.clear')}
- >
- <img
- src={XIconImage}
- alt={tCommon('a11y.clear')}
- style={{
- width: px2vmin(24),
- height: px2vmin(24),
- objectFit: 'contain',
- }}
- draggable={false}
- />
- </button>
- ) : null}
- </div>
- </div>
- {/* 按钮组 */}
- <div
- style={{
- display: 'flex',
- gap: px2vmin(43),
- justifyContent: 'center',
- width: '100%',
- }}
- >
- <button
- onClick={handleCloseBotNameModal}
- style={{
- width: px2vmin(80),
- height: px2vmin(42),
- backgroundImage: `url(${secondaryDefaultButton})`,
- backgroundRepeat: 'no-repeat',
- backgroundPosition: 'center',
- border: 'none',
- cursor: 'pointer',
- padding: 0,
- borderRadius: px2vmin(20),
- }}
- >
- <span
- style={{
- display: 'inline-block',
- fontSize: px2vmin(16),
- color: '#FFFFFF',
- fontWeight: 500,
- }}
- >
- {tCommon('button.cancel')}
- </span>
- </button>
- <button
- onClick={handleSaveBotName}
- style={{
- width: px2vmin(84),
- height: px2vmin(42),
- backgroundImage: `url(${primaryDefaultButton})`,
- backgroundRepeat: 'no-repeat',
- backgroundPosition: 'center',
- border: 'none',
- cursor: isBotNameChanged && tempBotName.trim() ? 'pointer' : 'default',
- padding: 0,
- opacity: isBotNameChanged && tempBotName.trim() ? 1 : 0.6,
- borderRadius: px2vmin(20),
- }}
- disabled={!isBotNameChanged || !tempBotName.trim()}
- >
- <span
- style={{
- display: 'inline-block',
- fontSize: px2vmin(16),
- color: '#FFFFFF',
- fontWeight: 500,
- }}
- >
- {t('change')}
- </span>
- </button>
- </div>
- </div>
- </>
- )}
- {/* 能量石弹窗 */}
- <MissionEnergyStoneModal
- visible={showEnergyStoneModal}
- onClose={handleCloseEnergyStoneModal}
- stoneType={energyStoneModalType}
- />
- {/* 意见反馈弹窗 */}
- {showFeedbackModal && (
- <>
- {/* 遮罩层 */}
- <div
- onClick={handleCloseFeedbackModal}
- style={{
- position: 'fixed',
- top: 0,
- left: 0,
- right: 0,
- bottom: 0,
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
- zIndex: 9998,
- animation: 'fadeIn 0.3s ease-out',
- }}
- />
- {/* 弹窗内容 */}
- <div
- style={{
- position: 'fixed',
- bottom: 0,
- left: '50%',
- transform: 'translateX(-50%)',
- width: px2vw(375),
- height: px2vmin(420),
- backgroundColor: '#34313D',
- borderTopLeftRadius: px2vmin(32),
- borderTopRightRadius: px2vmin(32),
- zIndex: 9999,
- display: 'flex',
- flexDirection: 'column',
- alignItems: 'center',
- paddingTop: px2vmin(12),
- paddingBottom: px2vmin(32),
- paddingLeft: px2vmin(32),
- paddingRight: px2vmin(32),
- }}
- >
- {/* 顶部拖拽指示条 */}
- <div
- style={{
- width: px2vmin(32),
- height: px2vmin(4),
- backgroundColor: '#79747E',
- borderRadius: px2vmin(4),
- }}
- />
- {/* 文字标签 */}
- <div
- style={{
- width: px2vmin(311),
- fontSize: px2vmin(14),
- color: '#fff',
- fontWeight: 'bold',
- marginTop: px2vmin(24),
- marginBottom: px2vmin(16),
- textAlign: 'left',
- alignSelf: 'center',
- }}
- >
- {t('feedbackAndHelp')}
- </div>
- {/* 输入区域 */}
- <div
- style={{
- width: px2vmin(311),
- height: px2vmin(224),
- marginBottom: px2vmin(32),
- alignSelf: 'center',
- }}
- >
- <textarea
- value={feedbackText}
- onChange={(e) => setFeedbackText(e.target.value)}
- placeholder={tCommon('feedbackPlaceholder')}
- className="feedback-textarea"
- style={{
- width: '100%',
- height: '100%',
- backgroundColor: 'rgba(245, 243, 240, 0.1)',
- border: 'none',
- borderRadius: px2vmin(12),
- padding: px2vmin(16),
- fontSize: px2vmin(14),
- color: 'rgba(245, 243, 240, 0.7)',
- fontFamily: 'inherit',
- resize: 'none',
- outline: 'none',
- }}
- />
- </div>
- {/* 按钮组 */}
- <div
- style={{
- display: 'flex',
- gap: px2vmin(43),
- justifyContent: 'center',
- width: '100%',
- }}
- >
- <button
- onClick={handleCloseFeedbackModal}
- disabled={isSubmittingFeedback}
- style={{
- width: px2vmin(85),
- height: px2vmin(44),
- backgroundImage: `url(${secondaryDefaultButton})`,
- backgroundRepeat: 'no-repeat',
- backgroundPosition: 'center',
- border: 'none',
- cursor: isSubmittingFeedback ? 'default' : 'pointer',
- padding: 0,
- opacity: isSubmittingFeedback ? 0.6 : 1,
- borderRadius: px2vmin(20),
- }}
- >
- <span
- style={{
- display: 'inline-block',
- fontSize: px2vmin(16),
- color: '#FFFFFF',
- fontWeight: 500,
- }}
- >
- {tCommon('button.cancel')}
- </span>
- </button>
- <button
- onClick={handleSubmitFeedback}
- disabled={!feedbackText.trim() || isSubmittingFeedback}
- style={{
- width: px2vmin(72),
- height: px2vmin(44),
- backgroundImage: `url(${primaryDefaultButton})`,
- backgroundRepeat: 'no-repeat',
- backgroundPosition: 'center',
- border: 'none',
- cursor: feedbackText.trim() && !isSubmittingFeedback ? 'pointer' : 'default',
- padding: 0,
- opacity: feedbackText.trim() && !isSubmittingFeedback ? 1 : 0.6,
- borderRadius: px2vmin(20),
- }}
- >
- <span
- style={{
- display: 'inline-block',
- fontSize: px2vmin(16),
- color: '#FFFFFF',
- fontWeight: 500,
- }}
- >
- {tCommon('button.send')}
- </span>
- </button>
- </div>
- </div>
- </>
- )}
- {/* 用户协议弹窗 */}
- <UserAgreementModal
- visible={showAgreementModal}
- onClose={() => setShowAgreementModal(false)}
- />
- {/* 隐私政策弹窗 */}
- <PrivacyPolicyModal
- visible={showPrivacyPolicyModal}
- onClose={() => setShowPrivacyPolicyModal(false)}
- />
- </div>
- </>
- );
- };
|