From 46b93373ced856a1c34d7d6f93701ac1365ff781 Mon Sep 17 00:00:00 2001 From: yezian Date: Thu, 7 Mar 2024 21:08:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E8=87=AA?= =?UTF-8?q?=E5=8A=A9=E8=B4=A6=E5=8F=B7=E6=B3=A8=E9=94=80=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- screeens/Setting/DeleteAccount/index.jsx | 204 +++++++++++++++++++ screeens/Setting/SelectSettingItem/index.jsx | 2 +- screeens/Setting/index.jsx | 19 ++ 3 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 screeens/Setting/DeleteAccount/index.jsx diff --git a/screeens/Setting/DeleteAccount/index.jsx b/screeens/Setting/DeleteAccount/index.jsx new file mode 100644 index 0000000..fbfbaa2 --- /dev/null +++ b/screeens/Setting/DeleteAccount/index.jsx @@ -0,0 +1,204 @@ +import { View, Text, ScrollView } from "react-native"; +import React, { useState, useEffect } from "react"; +import { useTailwind } from "tailwind-rn"; +import { useSafeAreaInsets } from "react-native-safe-area-context"; +import { Button } from "@rneui/themed"; +import MyModal from "../../../components/MyModal"; +import Toast from "react-native-toast-message"; +import baseRequest from "../../../utils/baseRequest"; +import { generateSignature } from "../../../utils/crypto"; + +export default function DeleteAccount({ navigation, route }) { + const tailwind = useTailwind(); + const insets = useSafeAreaInsets(); + + const [isModalVisible, setIsModalVisible] = useState(false); + const [deadline, setDeadline] = useState(); + + const apiUrl = process.env.EXPO_PUBLIC_API_URL; + + //查询用户是否在注销中 + const checkAccountStatus = async () => { + try { + const base = await baseRequest(); + const signature = await generateSignature({ + ...base, + }); + const _response = await fetch( + `${apiUrl}/api/account_cancellation/list_by_mid?signature=${signature}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + ...base, + }), + } + ); + const _data = await _response.json(); + if (_data.ret === -1) { + Toast.show({ + type: "error", + text1: _data.msg, + topOffset: 60, + }); + return; + } + if (_data.data.status === 0) setDeadline(_data.data.due_time); + } catch (error) { + console.error(error); + } + }; + useEffect(() => { + checkAccountStatus(); + }, []); + + //提交注销申请 + const handleDeleteAccount = async () => { + try { + const base = await baseRequest(); + const signature = await generateSignature({ + ...base, + }); + const _response = await fetch( + `${apiUrl}/api/account/cancel?signature=${signature}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + ...base, + }), + } + ); + const _data = await _response.json(); + if (_data.ret === -1) { + Toast.show({ + type: "error", + text1: _data.msg, + topOffset: 60, + }); + return; + } + checkAccountStatus(); + setIsModalVisible(false); + } catch (error) { + console.error(error); + } + }; + + //取消注销 + const undoDeleteAccount = async () => { + try { + const base = await baseRequest(); + const signature = await generateSignature({ + ...base, + }); + const _response = await fetch( + `${apiUrl}/api/account/abort_cancellation?signature=${signature}`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + ...base, + }), + } + ); + const _data = await _response.json(); + if (_data.ret === -1) { + Toast.show({ + type: "error", + text1: _data.msg, + topOffset: 60, + }); + return; + } + setDeadline(); + } catch (error) { + console.error(error); + } + }; + + //格式化时间戳 + function formatDeadline(timestamp) { + const date = new Date(timestamp * 1000); // 时间戳以秒为单位,需要乘以1000转换成毫秒 + const year = date.getFullYear(); + const month = ("0" + (date.getMonth() + 1)).slice(-2); + const day = ("0" + date.getDate()).slice(-2); + const hours = ("0" + date.getHours()).slice(-2); + const minutes = ("0" + date.getMinutes()).slice(-2); + const seconds = ("0" + date.getSeconds()).slice(-2); + + return `${year}年${month}月${day}日 ${hours}:${minutes}:${seconds}`; + } + + return ( + + + + 注销必看须知: + + + + 1、账号个人信息 + + + 账号注销后,您将永远失去该账户的所有内容,且无法恢复。包括但不限于:个人资料信息、访问记录、关注列表、私信聊天记录等。 + + + 2、账号资产与权益 + + + 账号注销后,您将失去所有账号使用期间获得的资产与权益,且无法恢复。包括但不限于您的金币、钻石、会员特权以及其他已付费的订单商品等。 + + + 3、注销时间 + + + 您发起注销账户申请后,我们将在7个自然日后完全清除您的账号信息,在此期间您可以随时在本页面撤销该申请。 + + + 4、其他 + + + 平台入驻创作者请联系运营进行注销。 + + + {deadline && ( + + 您的账号将于{formatDeadline(deadline)} + 注销,如需取消注销,请点击下方“取消注销” + + )} + + + + + ); +} diff --git a/screeens/Setting/SelectSettingItem/index.jsx b/screeens/Setting/SelectSettingItem/index.jsx index b175701..cb07b13 100644 --- a/screeens/Setting/SelectSettingItem/index.jsx +++ b/screeens/Setting/SelectSettingItem/index.jsx @@ -65,7 +65,7 @@ export default function SelectSettingItem({ navigation }) { - + + ({ + headerLeft: () => ( + navigation.goBack()} + /> + ), + title: "账号注销", + headerTitleStyle: { color: "white" }, + headerStyle: { backgroundColor: "#07050A" }, + })} + /> ); }