Profile.tsx 9.2 KB

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