From 84e12639811d78c7dc05f13ac5c72b0c522a38e7 Mon Sep 17 00:00:00 2001 From: jinyaqiu Date: Mon, 4 Aug 2025 15:26:39 +0800 Subject: [PATCH] feat: settingmodal --- app/(tabs)/owner.tsx | 12 +------ app/(tabs)/reset-password.tsx | 4 +-- app/(tabs)/setting.tsx | 60 ++++++++++++++++++---------------- components/login/forgetPwd.tsx | 2 +- components/login/login.tsx | 2 +- components/owner/delete.tsx | 5 ++- components/owner/setting.tsx | 5 +-- components/owner/userInfo.tsx | 16 ++++----- i18n/locales/en/login.json | 8 +++-- i18n/locales/zh/login.json | 8 +++-- 10 files changed, 58 insertions(+), 64 deletions(-) diff --git a/app/(tabs)/owner.tsx b/app/(tabs)/owner.tsx index 0e92e2f..b3fa3a0 100644 --- a/app/(tabs)/owner.tsx +++ b/app/(tabs)/owner.tsx @@ -5,13 +5,12 @@ import CarouselComponent from '@/components/owner/carousel'; import CreateCountComponent from '@/components/owner/createCount'; import Ranking from '@/components/owner/ranking'; import MemberCard from '@/components/owner/rights/memberCard'; -import SettingModal from '@/components/owner/setting'; import SkeletonOwner from '@/components/owner/SkeletonOwner'; import UserInfo from '@/components/owner/userName'; import { checkAuthStatus } from '@/lib/auth'; import { fetchApi } from '@/lib/server-api-util'; import { CountData, UserInfoDetails } from '@/types/user'; -import { useFocusEffect, usePathname, useRouter } from 'expo-router'; +import { useFocusEffect, useRouter } from 'expo-router'; import { useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { FlatList, StyleSheet, View } from 'react-native'; @@ -21,7 +20,6 @@ export default function OwnerPage() { const insets = useSafeAreaInsets(); const { t } = useTranslation(); const router = useRouter(); - const pathname = usePathname(); // 添加页面挂载状态 const [isMounted, setIsMounted] = useState(false); @@ -36,10 +34,6 @@ export default function OwnerPage() { checkAuth(); }, [router]); - // 设置弹窗 - const [modalVisible, setModalVisible] = useState(false); - - // 数据统计 const [countData, setCountData] = useState({} as CountData); @@ -147,10 +141,6 @@ export default function OwnerPage() { { length: 1000, offset: 1000 * index, index } )} /> - {/* 设置弹窗 - 使用条件渲染避免层级冲突 */} - {modalVisible && ( - - )} ); } diff --git a/app/(tabs)/reset-password.tsx b/app/(tabs)/reset-password.tsx index 598ad10..63e8a3a 100644 --- a/app/(tabs)/reset-password.tsx +++ b/app/(tabs)/reset-password.tsx @@ -34,12 +34,12 @@ const ResetPassword = () => { } if (password !== confirmPassword) { - setError(t('auth.signup.passwordNotMatch', { ns: 'login' })); + setError(t('auth.forgetPwd.passwordNotMatch', { ns: 'login' })); return; } if (password?.length < 6) { - setError(t('auth.signup.pwdLengthError', { ns: 'login' })); + setError(t('auth.forgetPwd.pwdLengthError', { ns: 'login' })); return; } diff --git a/app/(tabs)/setting.tsx b/app/(tabs)/setting.tsx index 5c679fc..eda0964 100644 --- a/app/(tabs)/setting.tsx +++ b/app/(tabs)/setting.tsx @@ -11,17 +11,17 @@ import { checkNotificationPermission, getLocationPermission, getPermissions, req import { ThemedText } from '@/components/ThemedText'; import { useAuth } from '@/contexts/auth-context'; import { fetchApi } from '@/lib/server-api-util'; -import { Address, User } from '@/types/user'; +import { Address } from '@/types/user'; import * as Location from 'expo-location'; -import { useRouter } from 'expo-router'; +import { useFocusEffect, useRouter } from 'expo-router'; import * as SecureStore from 'expo-secure-store'; -import React, { useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Linking, Platform, Pressable, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; import { useSafeAreaInsets } from "react-native-safe-area-context"; -const Setting = (props: { modalVisible: boolean, setModalVisible: (visible: boolean) => void, userInfo: User }) => { - const { modalVisible, setModalVisible, userInfo } = props; +const Setting = (props: { userInfo: any }) => { + const { userInfo } = props; const insets = useSafeAreaInsets(); const { t } = useTranslation(); // 判断当前语言环境 @@ -59,7 +59,6 @@ const Setting = (props: { modalVisible: boolean, setModalVisible: (visible: bool .then((granted: boolean | ((prevState: boolean) => boolean)) => { setNotificationsEnabled(granted); }); - setModalVisible(false); } }; @@ -74,7 +73,6 @@ const Setting = (props: { modalVisible: boolean, setModalVisible: (visible: bool .then((granted: boolean | ((prevState: boolean) => boolean)) => { setAlbumEnabled(granted); }); - setModalVisible(false); } } @@ -90,7 +88,6 @@ const Setting = (props: { modalVisible: boolean, setModalVisible: (visible: bool .then((granted: boolean | ((prevState: boolean) => boolean)) => { setLocationEnabled(granted); }); - setModalVisible(false); } }; // 正在获取位置信息 @@ -166,7 +163,6 @@ const Setting = (props: { modalVisible: boolean, setModalVisible: (visible: bool }) .then(async (res) => { await logout(); - setModalVisible(false); router.replace('/login'); }) .catch(() => { @@ -174,22 +170,32 @@ const Setting = (props: { modalVisible: boolean, setModalVisible: (visible: bool }); }; // 检查是否有权限 - useEffect(() => { - if (modalVisible) { - // 位置权限 - getLocationPermission().then((res: boolean | ((prevState: boolean) => boolean)) => { - setLocationEnabled(res); - }) - // 媒体库权限 - getPermissions().then((res: boolean | ((prevState: boolean) => boolean)) => { - setAlbumEnabled(res); - }) - // 通知权限 - checkNotificationPermission().then((res: boolean | ((prevState: boolean) => boolean)) => { - setNotificationsEnabled(res); - }) - } - }, [modalVisible]) + useFocusEffect( + useCallback(() => { + let isActive = true; + + const checkPermissions = async () => { + // 位置权限 + const locationRes = await getLocationPermission(); + // 媒体库权限 + const albumRes = await getPermissions(); + // 通知权限 + const notificationRes = await checkNotificationPermission(); + + if (isActive) { + setLocationEnabled(locationRes); + setAlbumEnabled(albumRes); + setNotificationsEnabled(notificationRes); + } + }; + + checkPermissions(); + + return () => { + isActive = false; + }; + }, []) + ); // 获取语言环境 useEffect(() => { @@ -215,8 +221,6 @@ const Setting = (props: { modalVisible: boolean, setModalVisible: (visible: bool {/* 用户信息 */} - + ); }; diff --git a/components/login/forgetPwd.tsx b/components/login/forgetPwd.tsx index 4bebfbb..da377d2 100644 --- a/components/login/forgetPwd.tsx +++ b/components/login/forgetPwd.tsx @@ -51,7 +51,7 @@ const ForgetPwd = ({ setIsSignUp, updateUrlParam, setError }: LoginProps) => { setCountdown(60); }) .catch((error) => { - setError(t('auth.forgetPwd.sendEmailError', { ns: 'login' })); + setError(error.message || t('auth.forgetPwd.sendEmailError', { ns: 'login' })); }) .finally(() => { setLocading(false); diff --git a/components/login/login.tsx b/components/login/login.tsx index 4a97015..84017c4 100644 --- a/components/login/login.tsx +++ b/components/login/login.tsx @@ -52,7 +52,7 @@ const Login = ({ updateUrlParam, setError, setShowPassword, showPassword }: Logi router.replace('/user-message'); } } catch (error) { - // Handle error + setError(error.message || t('auth.login.loginError', { ns: 'login' })); } finally { setIsLoading(false); } diff --git a/components/owner/delete.tsx b/components/owner/delete.tsx index 977f5fb..4b56770 100644 --- a/components/owner/delete.tsx +++ b/components/owner/delete.tsx @@ -6,8 +6,8 @@ import { useTranslation } from 'react-i18next'; import { Modal, Pressable, StyleSheet, View } from 'react-native'; import { ThemedText } from '../ThemedText'; -const DeleteModal = (props: { modalVisible: boolean, setModalVisible: (visible: boolean) => void, setSettingModalVisible: (visible: boolean) => void }) => { - const { modalVisible, setModalVisible, setSettingModalVisible } = props; +const DeleteModal = (props: { modalVisible: boolean, setModalVisible: (visible: boolean) => void }) => { + const { modalVisible, setModalVisible } = props; const { logout } = useAuth(); const { t } = useTranslation(); const router = useRouter(); @@ -22,7 +22,6 @@ const DeleteModal = (props: { modalVisible: boolean, setModalVisible: (visible: .then(async (res) => { await logout(); setModalVisible(false); - setSettingModalVisible(false); router.replace('/login'); }) .catch(() => { diff --git a/components/owner/setting.tsx b/components/owner/setting.tsx index 1a11077..9f83dfb 100644 --- a/components/owner/setting.tsx +++ b/components/owner/setting.tsx @@ -19,6 +19,9 @@ import { checkNotificationPermission, getLocationPermission, getPermissions, req const SettingModal = (props: { modalVisible: boolean, setModalVisible: (visible: boolean) => void, userInfo: User }) => { const { modalVisible, setModalVisible, userInfo } = props; + console.log(111111111111111111111111); + + console.log("hjhkkkkkkkkkkkkkkkkkkkkkkkkkkk111111111", setModalVisible); const { t } = useTranslation(); const [modalType, setModalType] = useState<'ai' | 'terms' | 'privacy' | 'user'>('ai'); @@ -213,8 +216,6 @@ const SettingModal = (props: { modalVisible: boolean, setModalVisible: (visible: {/* 用户信息 */} void; - modalVisible: boolean; getCurrentLocation: () => void; isLoading: boolean; isRefreshing: boolean; @@ -21,7 +19,8 @@ interface UserInfoProps { setCurrentLocation: (location: Address) => void; } const UserInfo = (props: UserInfoProps) => { - const { userInfo, setModalVisible, modalVisible, getCurrentLocation, isLoading, isRefreshing, currentLocation, setCurrentLocation } = props; + const { userInfo, getCurrentLocation, isLoading, isRefreshing, currentLocation, setCurrentLocation } = props; + const router = useRouter(); const { t } = useTranslation(); // 获取本地存储的location @@ -71,13 +70,11 @@ const UserInfo = (props: UserInfoProps) => { // 在组件挂载时自动获取位置(可选) useEffect(() => { - if (modalVisible) { - getLocation(); - if (currentLocation && Object?.keys(currentLocation)?.length === 0) { - getCurrentLocation(); - } + getLocation(); + if (currentLocation && Object?.keys(currentLocation)?.length === 0) { + getCurrentLocation(); } - }, [modalVisible]) + }, []) return ( @@ -124,7 +121,6 @@ const UserInfo = (props: UserInfoProps) => { } { - setModalVisible(false); // 携带参数跳转 router.push({ pathname: '/user-message', diff --git a/i18n/locales/en/login.json b/i18n/locales/en/login.json index 157d090..b0ad62d 100644 --- a/i18n/locales/en/login.json +++ b/i18n/locales/en/login.json @@ -66,8 +66,7 @@ "accountPlaceholder": "Enter your account or email", "signUpMessage": "Don’t have an account?", "signUp": "Sign up", - "phoneLogin": "Phone Login", - "passwordNotMatch": "Passwords do not match" + "phoneLogin": "Phone Login" }, "agree": { "logintext": "By logging in, you agree to our", @@ -87,7 +86,10 @@ "sendEmailBtn": "Send email", "goback": "Go back", "success": "Email sent successfully, please check your email", - "sendEmailBtnDisabled": "Email sent" + "sendEmailBtnDisabled": "Email sent", + "sendEmailError": "Failed to send email, please try again", + "passwordNotMatch": "Passwords do not match", + "pwdLengthError": "Password length must be at least 6 characters" }, "resetPwd": { "title": "Reset password", diff --git a/i18n/locales/zh/login.json b/i18n/locales/zh/login.json index 3ebd163..c0a04b0 100644 --- a/i18n/locales/zh/login.json +++ b/i18n/locales/zh/login.json @@ -66,8 +66,7 @@ "accountPlaceholder": "请输入您的账号或邮箱", "signUpMessage": "还没有账号?", "signUp": "注册", - "phoneLogin": "手机号登录", - "passwordNotMatch": "密码不一致" + "phoneLogin": "手机号登录" }, "agree": { "logintext": "登录即表示您同意我们的", @@ -87,7 +86,10 @@ "sendEmailBtn": "发送邮件", "signupButton": "注册", "goback": "返回登录", - "sendEmailBtnDisabled": "已发送" + "sendEmailBtnDisabled": "已发送", + "sendEmailError": "发送失败,请重试", + "passwordNotMatch": "密码不一致", + "pwdLengthError": "密码长度至少为6位" }, "resetPwd": { "title": "重置密码",