Profile.tsx 12 KB

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