Profile.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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, Switch } from "@tarojs/components";
  5. import Taro, { useDidShow, useShareAppMessage } 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. import TableCell from "@/components/layout/TableCell";
  13. import { useEffect, useState } from "react";
  14. import { jumpPage } from "@/features/trackTimeDuration/hooks/Common";
  15. import Tabbar from "@/components/navigation/TabBar";
  16. let useNavigation;
  17. if (process.env.TARO_ENV == 'rn') {
  18. useNavigation = require("@react-navigation/native").useNavigation
  19. }
  20. export default function Page() {
  21. const dispatch = useDispatch();
  22. const { t } = useTranslation()
  23. const user = useSelector((state: any) => state.user);
  24. const [switchOn, setSwitchOn] = useState(false)
  25. let navigation;
  26. if (useNavigation) {
  27. navigation = useNavigation()
  28. }
  29. useEffect(() => {
  30. if (process.env.TARO_ENV == 'weapp') {
  31. var status = Taro.getStorageSync('isDebug')
  32. setSwitchOn(status)
  33. }
  34. }, [])
  35. if (process.env.TARO_ENV == 'weapp') {
  36. useShareAppMessage((e) => {
  37. return {
  38. title: t('share.title'),
  39. path: 'pages/clock/Clock'
  40. }
  41. })
  42. }
  43. function switchChanged(e) {
  44. setSwitchOn(e.detail.value)
  45. Taro.setStorageSync('isDebug', e.detail.value)
  46. global.isDebug = e.detail.value
  47. }
  48. useDidShow(() => {
  49. // global.updateTab(3)
  50. })
  51. function reset() {
  52. Taro.showModal({
  53. title: t('feature.common.modal.reset_session_title'),
  54. content: t('feature.common.modal.reset_session_content'),
  55. success: res => {
  56. if (res.confirm) {
  57. delSession({ type: 'WX_MP' })
  58. }
  59. }
  60. })
  61. }
  62. function clearF() {
  63. Taro.showModal({
  64. title: t('feature.common.modal.deluser_title'),
  65. content: t('feature.common.modal.deluser_content'),
  66. success: res => {
  67. if (res.confirm) {
  68. dispatch(clear() as any);
  69. }
  70. }
  71. })
  72. }
  73. function tapProfile(e) {
  74. if (process.env.TARO_ENV == 'weapp') {
  75. e.stopPropagation()
  76. }
  77. if (user.isLogin) {
  78. jumpPage('/pages/account/ProfileSetting')
  79. }
  80. else {
  81. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  82. }
  83. }
  84. function tapBalance(e) {
  85. if (user.isLogin) {
  86. }
  87. else {
  88. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  89. if (process.env.TARO_ENV == 'weapp') {
  90. e.stopPropagation()
  91. }
  92. }
  93. }
  94. function goSetting(e) {
  95. jumpPage('/pages/account/Setting')
  96. if (process.env.TARO_ENV == 'weapp') {
  97. e.stopPropagation()
  98. }
  99. }
  100. console.log(user.avatar)
  101. function detail() {
  102. return <View className="container">
  103. <Box>
  104. <View className="profile_card" onClick={tapProfile}>
  105. <View className="avatar" style={{
  106. opacity: user.isLogin ? 1 : 0.4,
  107. background: user.isLogin ? 'transparent' : '#fff'
  108. }}>
  109. {
  110. user.isLogin ? <Image src={user.avatar} className="avatar" mode="aspectFill" style={{
  111. background: user.isLogin ? 'transparent' : '#fff'
  112. }} /> : <Image src={require('@/assets/images/user.png')} className="avatar_placeholder" />
  113. }
  114. </View>
  115. <Text className="nickname">{user.isLogin ? user.nickname : t('page.more.un_login')}</Text>
  116. {/* <Text className="username">{user.isLogin ? '用户名未设置' : ''}</Text> */}
  117. </View>
  118. </Box>
  119. <Box>
  120. <View className="balance" onClick={tapBalance}>
  121. <Text className="title">{t('page.more.stone')}</Text>
  122. <Text className="desc">{t('page.more.stone_desc')}</Text>
  123. </View>
  124. </Box>
  125. {
  126. user.isLogin && <View onClick={goSetting}>
  127. <TableCell title={t('page.more.setting')} showArrow={true} showMarginBottom={true}></TableCell>
  128. </View>
  129. }
  130. {/* {user.isLogin && <Box >
  131. <View onClick={goSetting}>
  132. <Text className="title">设置</Text>
  133. </View>
  134. </Box>
  135. } */}
  136. {
  137. user.isLogin && user.test_user && <TableCell title="user_id" showArrow={true} onClick={clearF}>
  138. <Text style={{ opacity: 0.8 }}>******{user.id.substring(user.id.length - 10, user.id.length)}</Text>
  139. </TableCell>
  140. }
  141. {
  142. user.isLogin && user.test_user && <TableCell title="session" showArrow={true} onClick={reset}>
  143. <Text style={{ opacity: 0.8 }}>{t('page.more.reset_session')}</Text>
  144. </TableCell>
  145. }
  146. {
  147. user.isLogin && user.test_user && <TableCell title={t('page.more.debug_mode')} >
  148. <Switch checked={switchOn} onChange={switchChanged} />
  149. </TableCell>
  150. }
  151. <View style={{ height: 40 }}></View>
  152. {/* <Text>未更改前的1px线</Text>
  153. <View style={{ marginLeft: 100 }}>
  154. <View className="px2Height" />
  155. <View className="px2Width" />
  156. <View className="px2Height" />
  157. <View className="px2Width" />
  158. <View className="px2Height" />
  159. <View className="px2Width" />
  160. <View className="px2Height" />
  161. <View className="px2Width" />
  162. <View className="px2Height" />
  163. <View className="px2Width" />
  164. <View className="px2Height" />
  165. <View className="px2Width" />
  166. </View>
  167. <Text>更改后的1px线</Text>
  168. <View style={{ marginLeft: 100 }}>
  169. <View className="px1Height" />
  170. <View className="px1Width" />
  171. <View className="px1Height" />
  172. <View className="px1Width" />
  173. <View className="px1Height" />
  174. <View className="px1Width" />
  175. <View className="px1Height" />
  176. <View className="px1Width" />
  177. <View className="px1Height" />
  178. <View className="px1Width" />
  179. <View className="px1Height" />
  180. <View className="px1Width" />
  181. </View>
  182. <Text>Svg Demo</Text>
  183. <View style={{ background: 'red', width: 30, height: 30 }}>
  184. <mysvg src='<svg t="1701751531644" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3687" width="200" height="200"><path d="M509.92 843.84C325.504 843.84 176 694.32 176 509.92 176 325.504 325.504 176 509.92 176c184.416 0 333.92 149.504 333.92 333.92 0 184.416-149.504 333.92-333.92 333.92z m0-48c157.904 0 285.92-128.016 285.92-285.92C795.84 352 667.808 224 509.92 224 352 224 224 352 224 509.92c0 157.904 128 285.92 285.92 285.92z" fill="#5A626A" p-id="3548"></path></svg>
  185. ' colors={['blue']} />
  186. </View>
  187. <View style={{ background: 'red', width: 30, height: 30 }}>
  188. <mysvg src='<svg t="1701751531644" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3687" width="200" height="200"><path d="M509.92 843.84C325.504 843.84 176 694.32 176 509.92 176 325.504 325.504 176 509.92 176c184.416 0 333.92 149.504 333.92 333.92 0 184.416-149.504 333.92-333.92 333.92z m0-48c157.904 0 285.92-128.016 285.92-285.92C795.84 352 667.808 224 509.92 224 352 224 224 352 224 509.92c0 157.904 128 285.92 285.92 285.92z" fill="#5A626A" p-id="3548"></path></svg>
  189. ' colors={['yellow']} />
  190. </View>
  191. <View style={{ background: 'red', width: 30, height: 30 }}>
  192. <mysvg src='<svg t="1701751531644" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3687" width="200" height="200"><path d="M509.92 843.84C325.504 843.84 176 694.32 176 509.92 176 325.504 325.504 176 509.92 176c184.416 0 333.92 149.504 333.92 333.92 0 184.416-149.504 333.92-333.92 333.92z m0-48c157.904 0 285.92-128.016 285.92-285.92C795.84 352 667.808 224 509.92 224 352 224 224 352 224 509.92c0 157.904 128 285.92 285.92 285.92z" fill="#5A626A" p-id="3548"></path></svg>
  193. ' colors={['gray']} />
  194. </View>
  195. <View style={{ height: 200,display:'flex',flexShrink:0 }} /> */}
  196. </View>
  197. }
  198. return <View>
  199. <Layout title={t('page.more.title')}
  200. titleShowStyle={NaviBarTitleShowType.scrollToShow} type={TemplateType.flex}>
  201. {
  202. detail()
  203. }
  204. </Layout>
  205. <Tabbar index={3} />
  206. </View>
  207. }