Profile.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import Buttons from "@/components/basic/Buttons";
  2. import { delSession } from "@/services/common";
  3. import { clear, logout } from "@/services/user";
  4. import { View, Text, Image } from "@tarojs/components";
  5. import Taro, { useDidShow } from "@tarojs/taro";
  6. import { useDispatch, useSelector } from "react-redux";
  7. import './Profile.scss'
  8. import Box from "@/components/layout/Box";
  9. import { BoxType, NaviBarTitleShowType, TemplateType } from "@/utils/types";
  10. import Layout from "@/components/layout/layout";
  11. import { useTranslation } from "react-i18next";
  12. export default function Page() {
  13. const dispatch = useDispatch();
  14. const { t } = useTranslation()
  15. const user = useSelector((state: any) => state.user);
  16. function tapLogin() {
  17. Taro.navigateTo({
  18. url: '/pages/account/ChooseAuth'
  19. })
  20. }
  21. useDidShow(() => {
  22. global.updateTab(3)
  23. })
  24. function reset() {
  25. Taro.showModal({
  26. title: '重置session',
  27. content: '确认重置session吗?',
  28. success: res => {
  29. if (res.confirm) {
  30. delSession({ type: 'WX_MP' })
  31. }
  32. }
  33. })
  34. }
  35. function tapProfile(e) {
  36. e.stopPropagation()
  37. if (user.isLogin) {
  38. Taro.navigateTo({
  39. url: '/pages/account/ProfileSetting'
  40. })
  41. }
  42. else {
  43. Taro.navigateTo({
  44. url: '/pages/account/ChooseAuth'
  45. })
  46. }
  47. }
  48. function tapBalance(e) {
  49. if (user.isLogin) {
  50. }
  51. else {
  52. Taro.navigateTo({
  53. url: '/pages/account/ChooseAuth'
  54. })
  55. e.stopPropagation()
  56. }
  57. }
  58. function goSetting(e) {
  59. Taro.navigateTo({
  60. url: '/pages/account/Setting'
  61. })
  62. e.stopPropagation()
  63. }
  64. function detail() {
  65. return <View className="container">
  66. <View style={{ height: 20 }} />
  67. <Box type={BoxType.outline}>
  68. <View className="profile_card" onClick={tapProfile}>
  69. <View className="avatar" style={{ opacity: user.isLogin ? 1 : 0.4 }}>
  70. {
  71. user.isLogin ? <Image src={user.avatar} className="avatar" /> : <Image src={require('@/assets/images/user.png')} className="avatar_placeholder" />
  72. }
  73. </View>
  74. <Text className="nickname">{user.isLogin ? user.nickname : '未登录'}</Text>
  75. <Text className="username">{user.isLogin ? '用户名未设置' : ''}</Text>
  76. </View>
  77. </Box>
  78. <Box type={BoxType.outline}>
  79. <View className="balance" onClick={tapBalance}>
  80. <Text className="title">逆龄石</Text>
  81. <Text className="desc">{'会员体系升级中,期间指标记录限时免逆龄石记录\n敬请期待'}</Text>
  82. </View>
  83. </Box>
  84. {user.isLogin && <Box type={BoxType.outline}>
  85. <View onClick={goSetting}>
  86. <Text className="title">设置</Text>
  87. </View>
  88. </Box>
  89. }
  90. {
  91. user.isLogin && user.test_user && <Text>用户名:{user.nickname}</Text>
  92. }
  93. {
  94. user.isLogin && user.test_user && <Text>id:{user.id}</Text>
  95. }
  96. {
  97. user.isLogin && user.test_user && <Buttons title='重置session' onClick={reset} btnStyle={{ width: 289, marginBottom: 30 }} />
  98. }
  99. </View>
  100. }
  101. return <Layout title={t('page.more.title')}
  102. titleShowStyle={NaviBarTitleShowType.scrollToShow} type={TemplateType.flex}>
  103. {
  104. detail()
  105. }
  106. </Layout>;
  107. }