Setting.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import Buttons from "@/components/basic/Buttons";
  2. import Footer from "@/components/layout/Footer";
  3. import TableCell from "@/components/layout/TableCell";
  4. import { ColorType } from "@/context/themes/color";
  5. import { ChooseScenarioBtn } from "@/features/common/SpecBtns";
  6. import { clear, logout } from "@/services/user";
  7. import { logoutSuccess } from "@/store/user";
  8. import { View, Text, Button } from "@tarojs/components";
  9. import Taro from "@tarojs/taro";
  10. import { useEffect } from "react";
  11. import { useTranslation } from "react-i18next";
  12. import { useDispatch, useSelector } from "react-redux";
  13. let useNavigation;
  14. if (process.env.TARO_ENV == 'rn') {
  15. useNavigation = require("@react-navigation/native").useNavigation
  16. }
  17. export default function Page() {
  18. const dispatch = useDispatch();
  19. const { t } = useTranslation()
  20. const user = useSelector((state: any) => state.user);
  21. let navigation;
  22. if (useNavigation) {
  23. navigation = useNavigation()
  24. }
  25. useEffect(() => {
  26. Taro.setNavigationBarTitle({
  27. title: t('page.setting.title')
  28. })
  29. }, [])
  30. function logoutF() {
  31. Taro.showModal({
  32. title: t('feature.common.modal.logout_title'),
  33. content: t('feature.common.modal.logout_content'),
  34. success: res => {
  35. if (res.confirm) {
  36. logout().then(res => {
  37. dispatch(logoutSuccess())
  38. if (process.env.TARO_ENV == 'weapp') {
  39. Taro.switchTab({
  40. url: '/pages/clock/Clock'
  41. })
  42. Taro.navigateBack();
  43. console.log('setting navi back')
  44. }
  45. else {
  46. navigation.goBack()
  47. }
  48. })
  49. // dispatch(logout() as any);
  50. }
  51. // if (process.env.TARO_ENV == 'rn'){
  52. // setTimeout(()=>{
  53. // navigation.goBack()
  54. // },1000)
  55. // }
  56. }
  57. })
  58. }
  59. return <View style={{ color: '#fff', display: 'flex', flexDirection: 'column', flex: 1 }}>
  60. <View style={{ height: 20 }} />
  61. <TableCell title={t('page.setting.version')} ><Text style={{ opacity: 0.8, color: '#fff' }}>{process.env.TARO_ENV == 'weapp'?'1.3.9':'1.3.3'}</Text></TableCell>
  62. {/* <Text style={{color:'#9E9E9E',textAlign:'center',fontSize:14}}>v1.2.2</Text> */}
  63. {
  64. process.env.TARO_ENV == 'rn' && <View style={{ flex: 1 }} />
  65. }
  66. <Footer>
  67. <ChooseScenarioBtn title={t('page.setting.logout')} onClick={logoutF} background={ColorType.fast} />
  68. </Footer>
  69. {
  70. process.env.TARO_ENV == 'rn' && <View style={{ height: 50 }} />
  71. }
  72. {/* <Buttons title='退出登录' onClick={logoutF} btnStyle={{ width: 289, marginBottom: 30 }} /> */}
  73. {/* {
  74. user.test_user && <Buttons title='注销账号' onClick={clearF} btnStyle={{ width: 289, marginBottom: 30 }} />
  75. } */}
  76. </View>
  77. }