index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { useState } from 'react'
  2. import Taro, { useDidHide, useShareAppMessage } from '@tarojs/taro'
  3. import { View, Text, Image, Navigator } from '@tarojs/components'
  4. import { observer, inject } from 'mobx-react'
  5. import './index.less'
  6. import { Store } from '@src/app'
  7. import ModalStore from '@src/store/modalStore'
  8. import IosShowPay from '@src/components/pay/IosShowPay'
  9. import GlobalModal from '@src/components/bottomModal'
  10. import { share } from '@src/utils'
  11. import { setClipboardData, showToast } from '@src/utils/compatibility'
  12. interface Props {
  13. store: Store;
  14. }
  15. function My(props: Props) {
  16. let { userInfoStore, indexStore } = props.store
  17. const [payType, setPayType] = useState<"shubi" | "vip">("shubi")
  18. //支付弹窗
  19. const payBtn = (e, type) => {
  20. e.stopPropagation()
  21. setPayType(type)
  22. ModalStore.showModal()
  23. }
  24. // 使用 useDidHide 如果需要在页面隐藏时做一些处理
  25. useDidHide(() => {
  26. ModalStore.hideModal()
  27. });
  28. // 分享
  29. useShareAppMessage(async () => {
  30. // 获取当前页面栈
  31. const pages = Taro.getCurrentPages()
  32. // 获取栈顶的页面,即当前页面
  33. const currentPage = pages[pages.length - 1]
  34. // 获取页面的路径和参数
  35. const route = currentPage.route // 页面路径
  36. if (route) {
  37. let shareInfo: any = await share({ pagePath: route })
  38. let { sharePicUrl, shareTitles, pageName, pagePath } = shareInfo
  39. return {
  40. title: shareTitles || app.appInfo?.appName + '-' + pageName,
  41. path: pagePath || undefined,
  42. imageUrl: sharePicUrl || undefined
  43. }
  44. }
  45. return {}
  46. })
  47. const copy = () => {
  48. setClipboardData({
  49. data: userInfoStore?.userInfo?.openId || "",
  50. success: function (res) {
  51. setClipboardData({
  52. data: userInfoStore?.userInfo?.openId || "",
  53. success: function (res) {
  54. showToast({
  55. title: "复制成功",
  56. icon: "success"
  57. })
  58. }
  59. })
  60. }
  61. })
  62. }
  63. return <View className='my'>
  64. <View className="userInfo">
  65. <View className="userInfo_box">
  66. {/* 个人信息 */}
  67. <View className="top" >
  68. <View className="left" >
  69. <View className="avtai">
  70. {/* || (userInfoStore.userInfo?.avatarUrl ? userInfoStore.userInfo?.avatarUrl : require('../../icon/avatar.jpg')) */}
  71. <Image mode="widthFix" lazy-load src={"https://test-book-content.oss-cn-hangzhou.aliyuncs.com/bookImageFE90FDA493CE46C694B423F4F4EA7BCB.jpg"} />
  72. </View>
  73. <View className="name" style={userInfoStore.isAuth ? { width: Taro.pxTransform(120) } : {}}>
  74. <View className='name_id'>
  75. <Text className="ID">ID:{userInfoStore?.userInfo?.nickname || userInfoStore?.userInfo?.openId}</Text>
  76. <Image onClick={copy} className='copy' lazy-load src={require('../../icon/copy.png')} />
  77. </View>
  78. {
  79. userInfoStore.isVip && <View className="grade">
  80. <Image lazy-load src={require('../../icon/grade.png')} />
  81. <Text>V1</Text>
  82. </View>
  83. }
  84. </View>
  85. </View>
  86. </View>
  87. {/* 付费功能 */}
  88. <IosShowPay>
  89. {/* vip续费 模板存在才显示*/}
  90. {!!indexStore?.rechargeTemplate?.find(item => item.templateType === 2) && <View className="bottom">
  91. <View>
  92. <View className="left">
  93. <Image lazy-load src={require('../../icon/VIP.png')} />
  94. <View className="txt">
  95. <Text>会员尊享免费解锁权益</Text>
  96. {
  97. userInfoStore.isVip && <Text className="tfv">有效期至:{userInfoStore?.userInfo?.vipExpireTime}</Text>
  98. }
  99. </View>
  100. </View>
  101. <View className="right" onClick={(e) => {
  102. payBtn(e, "vip")
  103. }}>{userInfoStore.isVip ? '立即续费' : '立即开通'}</View>
  104. </View>
  105. <Image lazy-load src={require('../../icon/vipBack.png')} />
  106. </View>}
  107. {/*我的账户 模板存在才显示*/}
  108. {!!indexStore?.rechargeTemplate?.find(item => item.templateType === 1) && <View className='account_info'>
  109. <View className='account_info_title'>我的账户</View>
  110. <View className='account_info_content'>
  111. <View className='account_info_content_left'>
  112. <View className='account_info_content_text'>
  113. <Text>{userInfoStore.userInfo?.coinNum || 0}</Text>
  114. <Text>书币</Text>
  115. </View>
  116. {/* <View className='account_info_content_text' onClick={() => { }}>
  117. <Text>0</Text>
  118. <Text>赠币</Text>
  119. </View> */}
  120. </View>
  121. <View className='account_info_content_btn' onClick={(e) => {
  122. payBtn(e, "shubi")
  123. }}>充值</View>
  124. </View>
  125. </View>}
  126. {/* 支付弹窗 */}
  127. <GlobalModal type={payType} isBook={false} />
  128. </IosShowPay>
  129. {/* 底部功能入口 */}
  130. <View className="list_bt" >
  131. <Navigator className="item" url="/pages/my/contactService/index">
  132. <View className="left">
  133. <Image lazy-load src={require('../../icon/phone.png')} mode="widthFix" />
  134. <Text>联系客服</Text>
  135. </View>
  136. <View className="right">
  137. <Image lazy-load src={require('../../icon/jtRight.png')} mode="widthFix" />
  138. </View>
  139. </Navigator>
  140. <View className="line"></View>
  141. <Navigator className="item" url="/pages/my/aboutUs/index">
  142. <View className="left">
  143. <Image lazy-load src={require('../../icon/we.png')} mode="widthFix" />
  144. <Text>关于我们</Text>
  145. </View>
  146. <View className="right">
  147. <Image lazy-load src={require('../../icon/jtRight.png')} mode="widthFix" />
  148. </View>
  149. </Navigator>
  150. </View>
  151. </View>
  152. </View>
  153. </View>
  154. }
  155. export default inject('store')(observer(My));