Setting.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import showActionSheet from "@/components/basic/ActionSheet";
  2. import showAlert from "@/components/basic/Alert";
  3. import Buttons from "@/components/basic/Buttons";
  4. import Footer from "@/components/layout/Footer";
  5. import TableCell from "@/components/layout/TableCell";
  6. import { ColorType } from "@/context/themes/color";
  7. import { ChooseScenarioBtn } from "@/features/common/SpecBtns";
  8. import { APP_VERSION, WX_VERSION } from "@/services/http/api";
  9. import { clear, logout } from "@/services/user";
  10. import { logoutSuccess } from "@/store/user";
  11. import { kIsAndroid } from "@/utils/tools";
  12. import { View, Text, Button } from "@tarojs/components";
  13. import Taro from "@tarojs/taro";
  14. import { useEffect } from "react";
  15. import { useTranslation } from "react-i18next";
  16. import { useDispatch, useSelector } from "react-redux";
  17. let useNavigation,useActionSheet;
  18. if (process.env.TARO_ENV == 'rn') {
  19. useNavigation = require("@react-navigation/native").useNavigation
  20. useActionSheet = require('@expo/react-native-action-sheet').useActionSheet
  21. }
  22. let hasCache = false;
  23. export default function Page() {
  24. const dispatch = useDispatch();
  25. const { t } = useTranslation()
  26. const user = useSelector((state: any) => state.user);
  27. let showActionSheetWithOptions;
  28. if (process.env.TARO_ENV == 'rn') {
  29. showActionSheetWithOptions = useActionSheet()
  30. }
  31. let navigation;
  32. if (useNavigation) {
  33. navigation = useNavigation()
  34. }
  35. useEffect(() => {
  36. Taro.setNavigationBarTitle({
  37. title: t('page.setting.title')
  38. })
  39. if (process.env.TARO_ENV == 'rn') {
  40. navigation.setOptions({ title: t('page.setting.title') ?? '' });
  41. }
  42. Taro.getStorage({ key: 'notification' }).then(res => {
  43. hasCache = true;
  44. })
  45. }, [])
  46. async function getStorage(key: string) {
  47. try {
  48. const res = await Taro.getStorage({ key });
  49. return res.data;
  50. } catch {
  51. return '';
  52. }
  53. }
  54. async function logoutF() {
  55. // var showDayRing = await getStorage('showedDisqualifiedAlert') || false;
  56. showAlert({
  57. title: t('feature.common.modal.logout_title'),
  58. content: t('feature.common.modal.logout_content'),
  59. showCancel: true,
  60. confirm: () => {
  61. logout().then(res => {
  62. dispatch(logoutSuccess())
  63. if (hasCache) {
  64. Taro.setStorage({
  65. key: 'notification',
  66. data: true
  67. })
  68. }
  69. if (process.env.TARO_ENV == 'rn') {
  70. var Jto = require('react-native').NativeModules.NativeBridge;
  71. Jto.clearNotification()
  72. }
  73. // if (showDayRing) {
  74. // Taro.setStorage({
  75. // key: 'showedDisqualifiedAlert',
  76. // data: true
  77. // })
  78. // }
  79. if (process.env.TARO_ENV == 'weapp') {
  80. Taro.switchTab({
  81. url: '/pages/clock/Clock'
  82. })
  83. //check
  84. //退出到首页后,点击登录,会再次执行naviback函数
  85. // Taro.navigateBack();
  86. console.log('setting navi back')
  87. }
  88. else {
  89. navigation.goBack()
  90. }
  91. }).catch((e) => {
  92. })
  93. }
  94. })
  95. }
  96. function del(){
  97. showActionSheet({
  98. title:t('feature.common.modal.deluser_action_title'),
  99. showActionSheetWithOptions: showActionSheetWithOptions,
  100. itemList: [t('feature.common.modal.deluser_action_confirm')],
  101. success: (res) => {
  102. switch (res) {
  103. case 0:
  104. {
  105. showAlert({
  106. title: t('feature.common.modal.deluser_title'),
  107. content: t('feature.common.modal.deluser_content'),
  108. showCancel: true,
  109. cancelText:t('feature.common.modal.deluser_cancel'),
  110. confirmText:t('feature.common.modal.deluser_confirm'),
  111. redConfirm:true,
  112. confirm: () => {
  113. delUser()
  114. }
  115. })
  116. }
  117. break;
  118. }
  119. }
  120. })
  121. }
  122. function delUser(){
  123. dispatch(clear() as any);
  124. setTimeout(()=>{
  125. navigation.goBack()
  126. },1500)
  127. }
  128. return <View style={{ color: '#fff', display: 'flex', flexDirection: 'column', flex: 1 }}>
  129. <View style={{ height: 20 }} />
  130. <TableCell title={t('page.setting.version')} ><Text style={{ opacity: 0.8, color: '#fff' }}>{process.env.TARO_ENV == 'weapp' ? WX_VERSION : APP_VERSION}</Text></TableCell>
  131. {/* <Text style={{color:'#9E9E9E',textAlign:'center',fontSize:14}}>v1.2.2</Text> */}
  132. {
  133. process.env.TARO_ENV == 'rn' && <View style={{ flex: 1 }} />
  134. }
  135. <Footer>
  136. <View>
  137. <ChooseScenarioBtn title={t('page.setting.logout')} onClick={logoutF} background={ColorType.fast} />
  138. <View style={{display:'flex',alignItems:'center',justifyContent:'center',marginTop:20}}>
  139. <Text onClick={del} style={{color:'#fff',opacity:0.4}}>{t('feature.common.modal.del')}</Text>
  140. </View>
  141. </View>
  142. </Footer>
  143. {
  144. process.env.TARO_ENV == 'rn' && <View style={{ height: 50 }} />
  145. }
  146. {/* <Buttons title='退出登录' onClick={logoutF} btnStyle={{ width: 289, marginBottom: 30 }} /> */}
  147. {/* {
  148. user.test_user && <Buttons title='注销账号' onClick={clearF} btnStyle={{ width: 289, marginBottom: 30 }} />
  149. } */}
  150. </View>
  151. }