Profile.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. import Buttons from "@/components/basic/Buttons";
  2. import { delSession } from "@/services/common";
  3. import { clear, getInfo, getPerm, logout, uploadPerm } 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, updateDebug } 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. import dayjs from "dayjs";
  21. let useNavigation, SwitchRN;
  22. if (process.env.TARO_ENV == 'rn') {
  23. useNavigation = require("@react-navigation/native").useNavigation
  24. SwitchRN = require('react-native').Switch
  25. }
  26. export default function Page() {
  27. const dispatch = useDispatch();
  28. const { t } = useTranslation()
  29. const user = useSelector((state: any) => state.user);
  30. const [switchOn, setSwitchOn] = useState(false)
  31. const [triggered, setTriggered] = useState(true)
  32. const [memberAlert, setMemberAlert] = useState(global.memberAlert)
  33. const [baseDeviceTime, setBaseDeviceTime] = useState(false)
  34. const accessObj = useSelector((state: any) => state.access);
  35. let navigation;
  36. if (useNavigation) {
  37. navigation = useNavigation()
  38. }
  39. useEffect(() => {
  40. if (process.env.TARO_ENV == 'weapp') {
  41. var status = Taro.getStorageSync('isDebug')
  42. setSwitchOn(status)
  43. }
  44. getPermissions()
  45. }, [])
  46. if (process.env.TARO_ENV == 'weapp') {
  47. useShareAppMessage((e) => {
  48. return {
  49. title: t('share.title'),
  50. path: 'pages/clock/Clock'
  51. }
  52. })
  53. }
  54. function switchChanged(e) {
  55. setSwitchOn(e.detail.value)
  56. Taro.setStorageSync('isDebug', e.detail.value)
  57. global.isDebug = e.detail.value
  58. dispatch(updateDebug({ is_debug: e.detail.value }))
  59. }
  60. function alertChanged(e) {
  61. setMemberAlert(e.detail.value)
  62. global.memberAlert = e.detail.value
  63. Taro.setStorage({
  64. key: 'memberAlert',
  65. data: e.detail.value
  66. })
  67. }
  68. function baseDeviceChanged(e) {
  69. setBaseDeviceTime(e)
  70. global.baseDeviceTime = e
  71. uploadPerm({ expire_based_on_device_time: e }).then(res => {
  72. if (global.indexPageRefresh) {
  73. global.indexPageRefresh()
  74. }
  75. })
  76. }
  77. function getPermissions() {
  78. getPerm().then(res => {
  79. setBaseDeviceTime((res as any).expire_based_on_device_time)
  80. })
  81. }
  82. useDidShow(() => {
  83. // global.updateTab(3)
  84. })
  85. function reset() {
  86. showAlert({
  87. title: t('feature.common.modal.reset_session_title'),
  88. content: t('feature.common.modal.reset_session_content'),
  89. showCancel: false,
  90. confirm: () => {
  91. delSession({ type: 'WX_MP' })
  92. }
  93. })
  94. }
  95. function clearF() {
  96. showAlert({
  97. title: t('feature.common.modal.deluser_title'),
  98. content: t('feature.common.modal.deluser_content'),
  99. showCancel: true,
  100. confirm: () => {
  101. dispatch(clear() as any);
  102. }
  103. })
  104. }
  105. function tapProfile(e) {
  106. if (process.env.TARO_ENV == 'weapp') {
  107. e.stopPropagation()
  108. }
  109. if (user.isLogin) {
  110. jumpPage('/pages/account/ProfileSetting', 'ProfileSetting', navigation)
  111. }
  112. else {
  113. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  114. }
  115. }
  116. function tapBalance(e) {
  117. if (user.isLogin) {
  118. jumpPage('/pages/store/product_list', 'ProductList', navigation)
  119. }
  120. else {
  121. jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
  122. if (process.env.TARO_ENV == 'weapp') {
  123. e.stopPropagation()
  124. }
  125. }
  126. }
  127. function goSetting(e) {
  128. console.log('apple')
  129. jumpPage('/pages/account/Setting', 'Setting', navigation)
  130. if (process.env.TARO_ENV == 'weapp' && e) {
  131. e.stopPropagation()
  132. }
  133. }
  134. usePullDownRefresh(() => {
  135. refresh()
  136. })
  137. function refresh() {
  138. setTriggered(true)
  139. getInfo().then(res => {
  140. console.log(res)
  141. Taro.stopPullDownRefresh()
  142. dispatch(getInfoSuccess(res))
  143. setTriggered(false)
  144. }).catch(e => {
  145. Taro.stopPullDownRefresh()
  146. setTriggered(false)
  147. })
  148. }
  149. function headerView() {
  150. return <TitleView title={t('page.more.title')} showAddBtn={false}>
  151. </TitleView>
  152. }
  153. function memberdesc() {
  154. if (!accessObj.access) {
  155. return ''
  156. }
  157. if (accessObj.access.member.type == 'NON_CONSUMABLE') {
  158. return 'Unlimited premium access to Pro features forever.'
  159. }
  160. if (accessObj.access.member.type == 'AUTO_RENEW') {
  161. return 'Premium access to Pro features during membership.'
  162. }
  163. return t('page.more.member_desc', { time: member_expire() })
  164. }
  165. function member_expire() {
  166. if (global.language == 'en') {
  167. return dayjs(accessObj.access.member.expire).format('MMM D HH:mm')
  168. }
  169. return dayjs(accessObj.access.member.expire).format('YYYY年MM月DD日 HH:mm')
  170. }
  171. function detail() {
  172. return <View className="container">
  173. <Box>
  174. <View className="profile_card" onClick={tapProfile}>
  175. <View className="avatar" style={{
  176. opacity: user.isLogin ? 1 : 0.4,
  177. background: user.isLogin ? 'transparent' : '#fff'
  178. }}>
  179. {
  180. user.isLogin ? <Image src={user.avatar} className="avatar" mode="aspectFill" style={{
  181. background: user.isLogin ? 'transparent' : '#fff'
  182. }} /> : <Image src={require('@/assets/images/user.png')} className="avatar_placeholder" />
  183. }
  184. </View>
  185. <Text className="nickname">{user.isLogin ? user.nickname : t('page.more.un_login')}</Text>
  186. {/* <Text className="username">{user.isLogin ? '用户名未设置' : ''}</Text> */}
  187. </View>
  188. </Box>
  189. <Box>
  190. {
  191. (!user.isLogin || (accessObj && accessObj.access && accessObj.access.member.status == 'NON_MEMBER')) ? <View className="balance" onClick={tapBalance}>
  192. <Text className="title">{t('page.more.stone')}</Text>
  193. <Text className="desc" style={{ height: process.env.TARO_ENV == 'weapp' ? rpxToPx(32) : rpxToPx(64) }}>{t('page.more.stone_desc')}</Text>
  194. </View> :
  195. <View className="balance" onClick={tapBalance}>
  196. <Text className="title">{t('page.more.pro_member')}</Text>
  197. <Text className="desc">{memberdesc()}</Text>
  198. {/* <Text className="desc">{t('page.more.member_desc', { time: member_expire() })}</Text> */}
  199. </View>
  200. }
  201. </Box>
  202. {
  203. user.isLogin && process.env.TARO_ENV == 'rn' && <View onClick={goSetting}>
  204. <TableCell title={t('page.more.setting')} showArrow={true} showMarginBottom={true} onClick={goSetting}></TableCell>
  205. </View>
  206. }
  207. {
  208. user.isLogin && process.env.TARO_ENV == 'weapp' && <TableCell title={t('page.more.setting')} showArrow={true} showMarginBottom={true} onClick={goSetting}></TableCell>
  209. }
  210. {/* {user.isLogin && <Box >
  211. <View onClick={goSetting}>
  212. <Text className="title">设置</Text>
  213. </View>
  214. </Box>
  215. } */}
  216. {
  217. user.isLogin && user.test_user && <View>
  218. <View className="cell_top" onClick={clearF}>
  219. <Text className="cell_title">user_id</Text>
  220. <Text className="cell_value">{user.id.substring(0, 6)}***{user.id.substring(user.id.length - 10, user.id.length)}</Text>
  221. <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
  222. </View>
  223. <View className="cell_line" style={{ marginLeft: rpxToPx(46), marginRight: rpxToPx(46) }}></View>
  224. <View className="cell_center" onClick={reset}>
  225. <Text className="cell_title">session</Text>
  226. <Text className="cell_value">{t('page.more.reset_session')}</Text>
  227. <Image className="cell_arrow" src={require('@/assets/images/arrow3.png')} />
  228. </View>
  229. <View className="cell_line" style={{ marginLeft: rpxToPx(46), marginRight: rpxToPx(46) }}></View>
  230. <View className="cell_center">
  231. <Text className="cell_title">member alert</Text>
  232. <Switch checked={memberAlert} onChange={alertChanged} />
  233. </View>
  234. <View className="cell_line" style={{ marginLeft: rpxToPx(46), marginRight: rpxToPx(46) }}></View>
  235. <View className="cell_center">
  236. <Text className="cell_title">expire based on device time</Text>
  237. {
  238. process.env.TARO_ENV == 'rn' ? <SwitchRN value={baseDeviceTime} onChange={(e) => { baseDeviceChanged(e.nativeEvent.value) }} /> : <Switch checked={baseDeviceTime} onChange={(e) => { baseDeviceChanged(e.detail.value) }} />
  239. }
  240. </View>
  241. <View className="cell_line" style={{ marginLeft: rpxToPx(46), marginRight: rpxToPx(46) }}></View>
  242. <View className="cell_bottom">
  243. <Text className="cell_title">{t('page.more.debug_mode')}</Text>
  244. <Switch checked={switchOn} onChange={switchChanged} />
  245. </View>
  246. </View>
  247. }
  248. {/* {
  249. user.isLogin && user.test_user && <TableCell title="user_id" showArrow={true} onClick={clearF}>
  250. <Text style={{ opacity: 0.8 }}>{user.id.substring(0, 6)}***{user.id.substring(user.id.length - 10, user.id.length)}</Text>
  251. </TableCell>
  252. }
  253. {
  254. user.isLogin && user.test_user && <TableCell title="session" showArrow={true} onClick={reset}>
  255. <Text style={{ opacity: 0.8 }}>{t('page.more.reset_session')}</Text>
  256. </TableCell>
  257. }
  258. {
  259. user.isLogin && user.test_user && <TableCell title={t('page.more.debug_mode')} >
  260. <Switch checked={switchOn} onChange={switchChanged} />
  261. </TableCell>
  262. } */}
  263. <View style={{ height: 40 }}></View>
  264. {/* <Text>未更改前的1px线</Text>
  265. <View style={{ marginLeft: 100 }}>
  266. <View className="px2Height" />
  267. <View className="px2Width" />
  268. <View className="px2Height" />
  269. <View className="px2Width" />
  270. <View className="px2Height" />
  271. <View className="px2Width" />
  272. <View className="px2Height" />
  273. <View className="px2Width" />
  274. <View className="px2Height" />
  275. <View className="px2Width" />
  276. <View className="px2Height" />
  277. <View className="px2Width" />
  278. </View>
  279. <Text>更改后的1px线</Text>
  280. <View style={{ marginLeft: 100 }}>
  281. <View className="px1Height" />
  282. <View className="px1Width" />
  283. <View className="px1Height" />
  284. <View className="px1Width" />
  285. <View className="px1Height" />
  286. <View className="px1Width" />
  287. <View className="px1Height" />
  288. <View className="px1Width" />
  289. <View className="px1Height" />
  290. <View className="px1Width" />
  291. <View className="px1Height" />
  292. <View className="px1Width" />
  293. </View>
  294. <Text>Svg Demo</Text>
  295. <View style={{ background: 'red', width: 30, height: 30 }}>
  296. <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>
  297. ' colors={['blue']} />
  298. </View>
  299. <View style={{ background: 'red', width: 30, height: 30 }}>
  300. <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>
  301. ' colors={['yellow']} />
  302. </View>
  303. <View style={{ background: 'red', width: 30, height: 30 }}>
  304. <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>
  305. ' colors={['gray']} />
  306. </View>
  307. <View style={{ height: 200,display:'flex',flexShrink:0 }} /> */}
  308. </View>
  309. }
  310. return <View>
  311. <Layout title={t('page.more.title')}
  312. titleShowStyle={NaviBarTitleShowType.scrollToShow}
  313. type={TemplateType.customHeader}
  314. header={headerView()}
  315. triggered={triggered}
  316. refresh={refresh}
  317. >
  318. {
  319. detail()
  320. }
  321. </Layout>
  322. <Tabbar index={3} />
  323. </View>
  324. }