Profile.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import Buttons from "@/components/basic/Buttons";
  2. import { delSession } from "@/services/common";
  3. import { clear, getInfo, logout } from "@/services/user";
  4. import { View, Text, Image, Switch } from "@tarojs/components";
  5. import Taro, { useDidShow, usePullDownRefresh, 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. import { getInfoSuccess } from "@/store/user";
  17. import TitleView from "@/features/trackTimeDuration/components/TitleView";
  18. import showAlert from "@/components/basic/Alert";
  19. import { rpxToPx } from "@/utils/tools";
  20. let useNavigation;
  21. if (process.env.TARO_ENV == 'rn') {
  22. useNavigation = require("@react-navigation/native").useNavigation
  23. }
  24. export default function Page() {
  25. const dispatch = useDispatch();
  26. const { t } = useTranslation()
  27. const user = useSelector((state: any) => state.user);
  28. const [switchOn, setSwitchOn] = useState(false)
  29. const [triggered, setTriggered] = useState(true)
  30. const [memberAlert, setMemberAlert] = useState(global.memberAlert)
  31. let navigation;
  32. if (useNavigation) {
  33. navigation = useNavigation()
  34. }
  35. useEffect(() => {
  36. if (process.env.TARO_ENV == 'weapp') {
  37. var status = Taro.getStorageSync('isDebug')
  38. setSwitchOn(status)
  39. }
  40. }, [])
  41. if (process.env.TARO_ENV == 'weapp') {
  42. useShareAppMessage((e) => {
  43. return {
  44. title: t('share.title'),
  45. path: 'pages/clock/Clock'
  46. }
  47. })
  48. }
  49. function switchChanged(e) {
  50. setSwitchOn(e.detail.value)
  51. Taro.setStorageSync('isDebug', e.detail.value)
  52. global.isDebug = e.detail.value
  53. }
  54. function alertChanged(e) {
  55. setMemberAlert(e.detail.value)
  56. global.memberAlert = e.detail.value
  57. Taro.setStorage({
  58. key: 'memberAlert',
  59. data: e.detail.value
  60. })
  61. }
  62. useDidShow(() => {
  63. // global.updateTab(3)
  64. })
  65. function reset() {
  66. showAlert({
  67. title: t('feature.common.modal.reset_session_title'),
  68. content: t('feature.common.modal.reset_session_content'),
  69. showCancel: false,
  70. confirm: () => {
  71. delSession({ type: 'WX_MP' })
  72. }
  73. })
  74. }
  75. function clearF() {
  76. showAlert({
  77. title: t('feature.common.modal.deluser_title'),
  78. content: t('feature.common.modal.deluser_content'),
  79. showCancel: true,
  80. confirm: () => {
  81. dispatch(clear() as any);
  82. }
  83. })
  84. }
  85. function tapProfile(e) {
  86. if (process.env.TARO_ENV == 'weapp') {
  87. e.stopPropagation()
  88. }
  89. if (user.isLogin) {
  90. jumpPage('/pages/account/ProfileSetting', 'ProfileSetting', navigation)
  91. }
  92. else {
  93. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  94. }
  95. }
  96. function tapBalance(e) {
  97. if (user.isLogin) {
  98. }
  99. else {
  100. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  101. if (process.env.TARO_ENV == 'weapp') {
  102. e.stopPropagation()
  103. }
  104. }
  105. }
  106. function goSetting(e) {
  107. console.log('apple')
  108. jumpPage('/pages/account/Setting', 'Setting', navigation)
  109. if (process.env.TARO_ENV == 'weapp' && e) {
  110. e.stopPropagation()
  111. }
  112. }
  113. usePullDownRefresh(() => {
  114. refresh()
  115. })
  116. function refresh() {
  117. setTriggered(true)
  118. getInfo().then(res => {
  119. console.log(res)
  120. Taro.stopPullDownRefresh()
  121. dispatch(getInfoSuccess(res))
  122. setTriggered(false)
  123. }).catch(e => {
  124. Taro.stopPullDownRefresh()
  125. setTriggered(false)
  126. })
  127. }
  128. function headerView() {
  129. return <TitleView title={t('page.more.title')} showAddBtn={false}>
  130. </TitleView>
  131. }
  132. function detail() {
  133. return <View className="container">
  134. <Box>
  135. <View className="profile_card" onClick={tapProfile}>
  136. <View className="avatar" style={{
  137. opacity: user.isLogin ? 1 : 0.4,
  138. background: user.isLogin ? 'transparent' : '#fff'
  139. }}>
  140. {
  141. user.isLogin ? <Image src={user.avatar} className="avatar" mode="aspectFill" style={{
  142. background: user.isLogin ? 'transparent' : '#fff'
  143. }} /> : <Image src={require('@/assets/images/user.png')} className="avatar_placeholder" />
  144. }
  145. </View>
  146. <Text className="nickname">{user.isLogin ? user.nickname : t('page.more.un_login')}</Text>
  147. {/* <Text className="username">{user.isLogin ? '用户名未设置' : ''}</Text> */}
  148. </View>
  149. </Box>
  150. <Box>
  151. <View className="balance" onClick={tapBalance}>
  152. <Text className="title">{t('page.more.stone')}</Text>
  153. <Text className="desc">{t('page.more.stone_desc')}</Text>
  154. </View>
  155. </Box>
  156. {
  157. user.isLogin && process.env.TARO_ENV == 'rn' && <View onClick={goSetting}>
  158. <TableCell title={t('page.more.setting')} showArrow={true} showMarginBottom={true} onClick={goSetting}></TableCell>
  159. </View>
  160. }
  161. {
  162. user.isLogin && process.env.TARO_ENV == 'weapp' && <TableCell title={t('page.more.setting')} showArrow={true} showMarginBottom={true} onClick={goSetting}></TableCell>
  163. }
  164. {/* {user.isLogin && <Box >
  165. <View onClick={goSetting}>
  166. <Text className="title">设置</Text>
  167. </View>
  168. </Box>
  169. } */}
  170. {
  171. user.isLogin && user.test_user && <View>
  172. <View className="cell_top" onClick={clearF}>
  173. <Text className="cell_title">user_id</Text>
  174. <Text className="cell_value">{user.id.substring(0, 6)}***{user.id.substring(user.id.length - 10, user.id.length)}</Text>
  175. <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
  176. </View>
  177. <View className="cell_line" style={{ marginLeft: rpxToPx(46), marginRight: rpxToPx(46) }}></View>
  178. <View className="cell_center" onClick={reset}>
  179. <Text className="cell_title">session</Text>
  180. <Text className="cell_value">{t('page.more.reset_session')}</Text>
  181. <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
  182. </View>
  183. <View className="cell_line" style={{ marginLeft: rpxToPx(46), marginRight: rpxToPx(46) }}></View>
  184. <View className="cell_bottom">
  185. <Text className="cell_title">{t('page.more.debug_mode')}</Text>
  186. <Switch checked={switchOn} onChange={switchChanged} />
  187. </View>
  188. </View>
  189. }
  190. {/* {
  191. user.isLogin && user.test_user && <TableCell title="user_id" showArrow={true} onClick={clearF}>
  192. <Text style={{ opacity: 0.8 }}>{user.id.substring(0, 6)}***{user.id.substring(user.id.length - 10, user.id.length)}</Text>
  193. </TableCell>
  194. }
  195. {
  196. user.isLogin && user.test_user && <TableCell title="session" showArrow={true} onClick={reset}>
  197. <Text style={{ opacity: 0.8 }}>{t('page.more.reset_session')}</Text>
  198. </TableCell>
  199. }
  200. {
  201. user.isLogin && user.test_user && <TableCell title={t('page.more.debug_mode')} >
  202. <Switch checked={switchOn} onChange={switchChanged} />
  203. </TableCell>
  204. } */}
  205. <View style={{ height: 40 }}></View>
  206. {/* <Text>未更改前的1px线</Text>
  207. <View style={{ marginLeft: 100 }}>
  208. <View className="px2Height" />
  209. <View className="px2Width" />
  210. <View className="px2Height" />
  211. <View className="px2Width" />
  212. <View className="px2Height" />
  213. <View className="px2Width" />
  214. <View className="px2Height" />
  215. <View className="px2Width" />
  216. <View className="px2Height" />
  217. <View className="px2Width" />
  218. <View className="px2Height" />
  219. <View className="px2Width" />
  220. </View>
  221. <Text>更改后的1px线</Text>
  222. <View style={{ marginLeft: 100 }}>
  223. <View className="px1Height" />
  224. <View className="px1Width" />
  225. <View className="px1Height" />
  226. <View className="px1Width" />
  227. <View className="px1Height" />
  228. <View className="px1Width" />
  229. <View className="px1Height" />
  230. <View className="px1Width" />
  231. <View className="px1Height" />
  232. <View className="px1Width" />
  233. <View className="px1Height" />
  234. <View className="px1Width" />
  235. </View>
  236. <Text>Svg Demo</Text>
  237. <View style={{ background: 'red', width: 30, height: 30 }}>
  238. <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>
  239. ' colors={['blue']} />
  240. </View>
  241. <View style={{ background: 'red', width: 30, height: 30 }}>
  242. <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>
  243. ' colors={['yellow']} />
  244. </View>
  245. <View style={{ background: 'red', width: 30, height: 30 }}>
  246. <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>
  247. ' colors={['gray']} />
  248. </View>
  249. <View style={{ height: 200,display:'flex',flexShrink:0 }} /> */}
  250. </View>
  251. }
  252. return <View>
  253. <Layout title={t('page.more.title')}
  254. titleShowStyle={NaviBarTitleShowType.scrollToShow}
  255. type={TemplateType.customHeader}
  256. header={headerView()}
  257. triggered={triggered}
  258. refresh={refresh}
  259. >
  260. {
  261. detail()
  262. }
  263. </Layout>
  264. <Tabbar index={3} />
  265. </View>
  266. }