feat: settingmodal

This commit is contained in:
jinyaqiu 2025-08-04 15:26:39 +08:00
parent b266b6646d
commit 84e1263981
10 changed files with 58 additions and 64 deletions

View File

@ -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<CountData>({} as CountData);
@ -147,10 +141,6 @@ export default function OwnerPage() {
{ length: 1000, offset: 1000 * index, index }
)}
/>
{/* 设置弹窗 - 使用条件渲染避免层级冲突 */}
{modalVisible && (
<SettingModal modalVisible={modalVisible} setModalVisible={setModalVisible} userInfo={userInfoDetails.user_info} />
)}
</View>
);
}

View File

@ -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;
}

View File

@ -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
{/* 用户信息 */}
<UserInfo
userInfo={userInfo}
setModalVisible={setModalVisible}
modalVisible={modalVisible}
setCurrentLocation={setCurrentLocation}
getCurrentLocation={getCurrentLocation}
isLoading={isLoading}
@ -387,7 +391,7 @@ const Setting = (props: { modalVisible: boolean, setModalVisible: (visible: bool
</Pressable>
<PrivacyModal modalVisible={privacyModalVisible} setModalVisible={setPrivacyModalVisible} type={modalType} />
<LcensesModal modalVisible={lcensesModalVisible} setModalVisible={setLcensesModalVisible} />
<DeleteModal modalVisible={deleteModalVisible} setModalVisible={setDeleteModalVisible} setSettingModalVisible={setModalVisible} />
<DeleteModal modalVisible={deleteModalVisible} setModalVisible={setDeleteModalVisible} />
</View>
);
};

View File

@ -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);

View File

@ -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);
}

View File

@ -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(() => {

View File

@ -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:
{/* 用户信息 */}
<UserInfo
userInfo={userInfo}
setModalVisible={setModalVisible}
modalVisible={modalVisible}
setCurrentLocation={setCurrentLocation}
getCurrentLocation={getCurrentLocation}
isLoading={isLoading}

View File

@ -12,8 +12,6 @@ import { ThemedText } from "../ThemedText";
interface UserInfoProps {
userInfo: User;
setModalVisible: (visible: boolean) => 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 (
<View style={styles.container}>
@ -124,7 +121,6 @@ const UserInfo = (props: UserInfoProps) => {
<UserSvg width={80} height={80} />
}
<TouchableOpacity style={styles.edit} onPress={() => {
setModalVisible(false);
// 携带参数跳转
router.push({
pathname: '/user-message',

View File

@ -66,8 +66,7 @@
"accountPlaceholder": "Enter your account or email",
"signUpMessage": "Dont 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",

View File

@ -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": "重置密码",