DeleteAccount.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * 删除账号页面
  3. * @邠心vbe on 2025/06/27
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, ScrollView } from 'react-native';
  7. import CheckBoxText from '../../components/CheckBoxText';
  8. import Button from '../../components/Button';
  9. import apiUser from '../../api/apiUser';
  10. import Dialog from '../../components/Dialog';
  11. import { PageList } from '../Router';
  12. import TextView from '../../components/TextView';
  13. import { getStorageJsonSync, setStorage, setStorageJson } from '../../utils/storage';
  14. import { setAccessToken } from '../../api/http';
  15. export default class DeleteAccount extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. checkValue1: false,
  20. checkValue2: false,
  21. checkValue3: false
  22. };
  23. }
  24. deleteAccount() {
  25. Dialog.showDialog({
  26. title: $t('profile.deleteAccount'),
  27. message: $t('profile.confirmDeleteAccount'),
  28. ok: $t('nav.confirm'),
  29. callback: button => {
  30. if (button == Dialog.BUTTON_OK) {
  31. this.deleteMyAccount();
  32. }
  33. }
  34. })
  35. }
  36. deleteMyAccount(again=false) {
  37. Dialog.showProgressDialog();
  38. apiUser.deleteAccount({
  39. secondConfirm: again
  40. }).then(res => {
  41. toastShort($t('profile.deleteAccountSuccess'))
  42. Dialog.dismissLoading();
  43. this.requestLogout();
  44. /*setTimeout(() => {
  45. startPage(PageList.login);
  46. }, 500);*/
  47. }).catch(err => {
  48. Dialog.dismissLoading();
  49. //toastShort(err)
  50. setTimeout(() => {
  51. if (err.code == 5334) {
  52. Dialog.showDialog({
  53. title: $t('profile.deleteAccount'),
  54. message: err.msg,
  55. ok: $t("nav.confirm"),
  56. callback: button => {
  57. if (button == Dialog.BUTTON_OK) {
  58. setTimeout(() => {
  59. this.deleteMyAccount(true);
  60. }, 500)
  61. }
  62. }
  63. })
  64. } else {
  65. Dialog.showResultDialog(err.msg);
  66. }
  67. }, 500);
  68. })
  69. }
  70. async requestLogout() {
  71. const data = await getStorageJsonSync('loginData');
  72. if (data && data.email) {
  73. delete data.password
  74. setStorageJson('loginData', data);
  75. setStorage('RegisterTokenDate', "");
  76. }
  77. global.userInfo = {}
  78. /*this.setState({
  79. isLogin: false,
  80. userInfo: {}
  81. });*/
  82. Dialog.dismissLoading();
  83. setAccessToken('');
  84. startPage(PageList.home);
  85. }
  86. render() {
  87. const styles = delStyle();
  88. return (
  89. <ScrollView
  90. style={styles.container}
  91. contentContainerStyle={$padding(16)}>
  92. <View style={styles.cardView}>
  93. <TextView style={styles.textTitle}>We’re sorry to see you go.</TextView>
  94. <TextView style={styles.textMessage}>Please be aware that any remaining credits in your account will be forfeited and are non-refundable if you choose to delete your account.</TextView>
  95. <TextView style={styles.textMessage}>To proceed with account deletion, please confirm your decision by pressing the "Delete Account" button.</TextView>
  96. <TextView style={styles.textMessage}>Once confirmed, your account and all associated data will be permanently deleted and can not be recovered.</TextView>
  97. <TextView style={styles.textMessage}>This action is irreversible.</TextView>
  98. <View style={styles.confirmView}>
  99. <TextView style={styles.textConfirm}>Please Confirm The Following</TextView>
  100. <View>
  101. <CheckBoxText
  102. value={this.state.checkValue1}
  103. onValueChange={(newValue) => this.setState({checkValue1: newValue})}
  104. flexText={true}
  105. text={"I understand that my remaining credits will be forfeited and are non-refundable."}
  106. disabled={false}
  107. textStyle={{fontSize: 12}}/>
  108. </View>
  109. <View>
  110. <CheckBoxText
  111. value={this.state.checkValue2}
  112. onValueChange={(newValue) => this.setState({checkValue2: newValue})}
  113. flexText={true}
  114. text={"I confirm that my account and all associated data will be permanently deleted."}
  115. disabled={false}
  116. textStyle={{fontSize: 12}}/>
  117. </View>
  118. <View>
  119. <CheckBoxText
  120. value={this.state.checkValue3}
  121. onValueChange={(newValue) => this.setState({checkValue3: newValue})}
  122. flexText={true}
  123. text={"I acknowledge that this action is irreversible and can not be undone."}
  124. disabled={false}
  125. textStyle={{fontSize: 12}}/>
  126. </View>
  127. </View>
  128. </View>
  129. <Button
  130. style={styles.btnDelete}
  131. text="DELETE ACCOUNT"
  132. textColor="#FF0F2B"
  133. disabled={!(this.state.checkValue1 && this.state.checkValue2 && this.state.checkValue3)}
  134. onClick={() => this.deleteAccount()}/>
  135. </ScrollView>
  136. );
  137. }
  138. }
  139. const delStyle = () => StyleSheet.create({
  140. container: {
  141. flex: 1,
  142. backgroundColor: pageBackground
  143. },
  144. cardView: {
  145. padding: 16,
  146. borderRadius: 6,
  147. backgroundColor: colorLight
  148. },
  149. btnDelete: {
  150. backgroundColor: colorLight,
  151. ...$margin(24, 0, 16)
  152. },
  153. textTitle: {
  154. color: textPrimary,
  155. fontSize: 16,
  156. paddingBottom: 8
  157. },
  158. textMessage: {
  159. color: textSecondary,
  160. fontSize: 14,
  161. paddingBottom: 16
  162. },
  163. confirmView: {
  164. paddingTop: 16,
  165. borderTopWidth: 1,
  166. borderColor: "#ededed"
  167. },
  168. textConfirm: {
  169. color: textPrimary,
  170. fontSize: 14,
  171. fontWeight: "500",
  172. paddingBottom: 16
  173. }
  174. })