Profile.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. export default function Page() {
  15. const dispatch = useDispatch();
  16. const { t } = useTranslation()
  17. const user = useSelector((state: any) => state.user);
  18. const [switchOn, setSwitchOn] = useState(false)
  19. useEffect(() => {
  20. var status = Taro.getStorageSync('isDebug')
  21. setSwitchOn(status)
  22. }, [])
  23. useShareAppMessage((e)=>{
  24. return {
  25. title:t('share.title'),
  26. path:'pages/clock/Clock'
  27. }
  28. })
  29. function switchChanged(e) {
  30. setSwitchOn(e.detail.value)
  31. Taro.setStorageSync('isDebug', e.detail.value)
  32. global.isDebug = e.detail.value
  33. }
  34. function tapLogin() {
  35. Taro.navigateTo({
  36. url: '/pages/account/ChooseAuth'
  37. })
  38. }
  39. useDidShow(() => {
  40. global.updateTab(3)
  41. })
  42. function reset() {
  43. Taro.showModal({
  44. title: '重置session',
  45. content: '确认重置session吗?',
  46. success: res => {
  47. if (res.confirm) {
  48. delSession({ type: 'WX_MP' })
  49. }
  50. }
  51. })
  52. }
  53. function clear() {
  54. Taro.showModal({
  55. title: '注销账号',
  56. content: '确定注销此账号吗?',
  57. success: res => {
  58. if (res.confirm) {
  59. dispatch(clear() as any);
  60. }
  61. }
  62. })
  63. }
  64. function tapProfile(e) {
  65. e.stopPropagation()
  66. if (user.isLogin) {
  67. Taro.navigateTo({
  68. url: '/pages/account/ProfileSetting'
  69. })
  70. }
  71. else {
  72. Taro.navigateTo({
  73. url: '/pages/account/ChooseAuth'
  74. })
  75. }
  76. }
  77. function tapBalance(e) {
  78. if (user.isLogin) {
  79. }
  80. else {
  81. Taro.navigateTo({
  82. url: '/pages/account/ChooseAuth'
  83. })
  84. e.stopPropagation()
  85. }
  86. }
  87. function goSetting(e) {
  88. Taro.navigateTo({
  89. url: '/pages/account/Setting'
  90. })
  91. e.stopPropagation()
  92. }
  93. console.log(user.avatar)
  94. function detail() {
  95. return <View className="container">
  96. <Box>
  97. <View className="profile_card" onClick={tapProfile}>
  98. <View className="avatar" style={{
  99. opacity: user.isLogin ? 1 : 0.4,
  100. background: user.isLogin ? 'transparent' : '#fff'
  101. }}>
  102. {
  103. user.isLogin ? <Image src={user.avatar} className="avatar" mode="aspectFill" style={{
  104. background: user.isLogin ? 'transparent' : '#fff'
  105. }} /> : <Image src={require('@/assets/images/user.png')} className="avatar_placeholder" />
  106. }
  107. </View>
  108. <Text className="nickname">{user.isLogin ? user.nickname : '未登录'}</Text>
  109. {/* <Text className="username">{user.isLogin ? '用户名未设置' : ''}</Text> */}
  110. </View>
  111. </Box>
  112. <Box>
  113. <View className="balance" onClick={tapBalance}>
  114. <Text className="title">逆龄石</Text>
  115. <Text className="desc">{'会员体系升级中,期间指标记录限时免逆龄石记录\n敬请期待'}</Text>
  116. </View>
  117. </Box>
  118. {
  119. user.isLogin && <View onClick={goSetting}>
  120. <TableCell title="设置" showArrow={true} showMarginBottom={true}></TableCell>
  121. </View>
  122. }
  123. {/* {user.isLogin && <Box >
  124. <View onClick={goSetting}>
  125. <Text className="title">设置</Text>
  126. </View>
  127. </Box>
  128. } */}
  129. {
  130. user.isLogin && user.test_user && <TableCell title="user_id" showArrow={true} onClick={clear}>
  131. <Text style={{ opacity: 0.8 }}>******{user.id.substring(user.id.length - 10, user.id.length)}</Text>
  132. </TableCell>
  133. }
  134. {
  135. user.isLogin && user.test_user && <TableCell title="session" showArrow={true} onClick={reset}>
  136. <Text style={{ opacity: 0.8 }}>重置session</Text>
  137. </TableCell>
  138. }
  139. {
  140. user.isLogin && user.test_user && <TableCell title="走查模式" >
  141. <Switch checked={switchOn} onChange={switchChanged} />
  142. </TableCell>
  143. }
  144. {/* <Text>未更改前的1px线</Text>
  145. <View style={{ marginLeft: 100 }}>
  146. <View className="px2Height" />
  147. <View className="px2Width" />
  148. <View className="px2Height" />
  149. <View className="px2Width" />
  150. <View className="px2Height" />
  151. <View className="px2Width" />
  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>
  159. <Text>更改后的1px线</Text>
  160. <View style={{ marginLeft: 100 }}>
  161. <View className="px1Height" />
  162. <View className="px1Width" />
  163. <View className="px1Height" />
  164. <View className="px1Width" />
  165. <View className="px1Height" />
  166. <View className="px1Width" />
  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>
  174. <Text>Svg Demo</Text>
  175. <View style={{ background: 'red', width: 30, height: 30 }}>
  176. <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>
  177. ' colors={['blue']} />
  178. </View>
  179. <View style={{ background: 'red', width: 30, height: 30 }}>
  180. <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>
  181. ' colors={['yellow']} />
  182. </View>
  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={['gray']} />
  186. </View>
  187. <View style={{ height: 200,display:'flex',flexShrink:0 }} /> */}
  188. </View>
  189. }
  190. return <Layout title={t('page.more.title')}
  191. titleShowStyle={NaviBarTitleShowType.scrollToShow} type={TemplateType.flex}>
  192. {
  193. detail()
  194. }
  195. </Layout>;
  196. }