my.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <script lang="ts" setup>
  2. import { useRequest } from 'alova/client'
  3. import { storeToRefs } from 'pinia'
  4. import { computed, ref } from 'vue'
  5. import { getCouponSituation } from '@/api/home'
  6. import { getCouponIssuerApplyById, getShareState } from '@/api/me'
  7. import { useShare } from '@/hooks/useShare'
  8. import { useUserStore } from '@/store'
  9. import { useInviterStore } from '@/store/inviter'
  10. import { useTokenStore } from '@/store/token'
  11. import { changtime } from '@/utils'
  12. import { getImageUrl } from '@/utils/imageUtil'
  13. definePage({
  14. style: {
  15. navigationBarTitleText: '我的',
  16. navigationStyle: 'custom',
  17. },
  18. })
  19. const userStore = useUserStore()
  20. const tokenStore = useTokenStore()
  21. const inviterStore = useInviterStore()
  22. // 使用storeToRefs解构userInfo
  23. const { userInfo } = storeToRefs(userStore)
  24. const { hasLogin } = storeToRefs(tokenStore)
  25. const deadline = ref(Date.now())
  26. // 用户优惠券统计数据
  27. const { send: getCouponSituationRequest, data: couponSituationData, loading: couponSituationLoading } = useRequest(getCouponSituation, {
  28. immediate: false,
  29. })
  30. const { send: getShareStateRequest, data: shareStateData, loading: shareStateLoading } = useRequest(getShareState, {
  31. immediate: false,
  32. })
  33. // 昵称输入值
  34. const nicknameInput = ref('')
  35. onShow(async () => {
  36. console.log('登录判断:', hasLogin.value)
  37. // 登录后查询收益数据
  38. if (hasLogin.value) {
  39. await getCouponSituationRequest({ queryType: 'time' })
  40. await getShareStateRequest()
  41. deadline.value = Date.now()
  42. }
  43. })
  44. function handleLogout() {
  45. uni.showModal({
  46. title: '提示',
  47. content: '确定要退出登录吗?',
  48. success: async (res) => {
  49. if (res.confirm) {
  50. // 清空用户信息
  51. await useTokenStore().logout()
  52. // 执行退出登录逻辑
  53. uni.showToast({
  54. title: '退出登录成功',
  55. icon: 'success',
  56. mask: true,
  57. duration: 2000,
  58. complete: () => {
  59. // #ifdef MP-WEIXIN
  60. // 微信小程序,去首页
  61. uni.reLaunch({ url: '/pages/home/home' })
  62. // #endif
  63. // #ifndef MP-WEIXIN
  64. // 非微信小程序,去登录页
  65. // uni.navigateTo({ url: LOGIN_PAGE })
  66. // #endif
  67. }
  68. })
  69. }
  70. },
  71. })
  72. }
  73. // 顶部导航栏高度,设置banner位置
  74. const navigationBarHeight = ref(0)
  75. // 头像默认图片
  76. const defaultAvatar = '../../static/images/me/me-bg.png'
  77. // 计算头像显示
  78. const avatarDisplay = computed(() => {
  79. return userInfo.value?.avatar || defaultAvatar
  80. })
  81. // #ifdef MP-WEIXIN
  82. function getNavigationBarHeight() {
  83. uni.getSystemInfo({
  84. success: (res) => {
  85. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  86. console.log('顶部导航栏高度:', res.statusBarHeight, menuButtonInfo)
  87. // 顶部导航栏高度 = 状态栏高度 + 胶囊的高度
  88. navigationBarHeight.value = res.statusBarHeight + menuButtonInfo.height
  89. },
  90. })
  91. }
  92. getNavigationBarHeight()
  93. // #endif
  94. const show = ref(false)
  95. const refreshing = ref(false)
  96. function close() {
  97. show.value = false
  98. }
  99. function open() {
  100. show.value = true
  101. }
  102. async function menuClick(page, otherJs?: () => Promise<boolean>) {
  103. if (otherJs && typeof otherJs === 'function') {
  104. const execRes = await otherJs(page)
  105. if (execRes === false) {
  106. return
  107. }
  108. }
  109. uni.navigateTo({
  110. url: `/pages-A/${page}/index?couponSituation=${JSON.stringify(couponSituationData.value)}`,
  111. })
  112. }
  113. // 判断是否是发券人
  114. function isCouponIssuer(currentPage?: string) {
  115. // 发券人相关页面
  116. const validPages = ['myInviter', 'shareFriend', 'invitePage']
  117. console.log('111111111111')
  118. // 判断跳转页面是否是发券人相关页面
  119. if (!validPages.includes(currentPage)) {
  120. return Promise.resolve(true)
  121. }
  122. // 是否已经成为发券人
  123. if (userStore.isPassIssuer()) {
  124. return Promise.resolve(true)
  125. }
  126. else {
  127. uni.showModal({
  128. title: '提示',
  129. content: '您还不是发券人,请先申请成为发券人',
  130. showCancel: false,
  131. })
  132. return Promise.resolve(false)
  133. }
  134. }
  135. //展开弹窗
  136. function watchUserStatus() {
  137. if (userInfo.value.status === '0') {
  138. open();
  139. return Promise.resolve(false)
  140. }
  141. return Promise.resolve(true)
  142. }
  143. async function getInviteInfo(currentPage?: string) {
  144. const isCouponIssuerRes = await isCouponIssuer(currentPage)
  145. if (!isCouponIssuerRes) {
  146. return isCouponIssuerRes
  147. }
  148. const isInviter = await inviterStore.fetchInviterInfo()
  149. if (!isInviter) {
  150. uni.showModal({
  151. title: '提示',
  152. content: '您没有上级邀请人,无法查看邀请信息',
  153. showCancel: false,
  154. })
  155. }
  156. return isInviter
  157. }
  158. async function onRefresh() {
  159. refreshing.value = true
  160. await userStore.fetchUserInfo()
  161. await getCouponSituationRequest({ queryType: 'time' })
  162. await getShareStateRequest()
  163. deadline.value = Date.now()
  164. refreshing.value = false
  165. }
  166. // 创建分享hook实例
  167. const { getShareConfig, getTimelineShareConfig } = useShare()
  168. // #ifdef MP-WEIXIN
  169. // 分享给好友生命周期函数
  170. onShareAppMessage(async (options) => {
  171. return await getShareConfig()
  172. })
  173. // 分享到朋友圈生命周期函数
  174. onShareTimeline(async () => {
  175. return await getTimelineShareConfig()
  176. })
  177. // #endif
  178. </script>
  179. <template>
  180. <view class="profile-container">
  181. <up-pull-refresh :refreshing="refreshing" :threshold="60" @refresh="onRefresh">
  182. <!-- 顶部区域 -->
  183. <view class="me-header"
  184. :style="{ background: `url(${getImageUrl('@img/me/me-bg.png')})`, backgroundSize: 'cover', backgroundRepeat: 'no-repeat', backgroundPosition: 'center center' }">
  185. <view class="me-header-avatar-info" :style="{ paddingTop: `23rpx` }">
  186. <up-image :src="avatarDisplay" width="128rpx" height="128rpx" shape="circle" />
  187. <view class="me-header-info">
  188. <view class="me-header-name">
  189. <!-- #ifdef MP-WEIXIN -->
  190. <!-- <input v-model="userInfo.value.nickname" type="nickname" :disabled="true" placeholder="用户昵称"
  191. placeholder-style="color: #fff; opacity: 0.7;" class="nickname-input"> -->
  192. <text class="nickname-input">{{ userInfo.nickname || '用户' }}</text>
  193. <!-- #endif -->
  194. <!-- #ifndef MP-WEIXIN -->
  195. {{ userInfo.value?.nickname || '用户' }}
  196. <!-- #endif -->
  197. </view>
  198. </view>
  199. </view>
  200. <view class="me-header-tips">
  201. <view class="me-header-tips-row header-data-time">
  202. <view class="desc-time">
  203. <up-loading-icon v-if="couponSituationLoading || shareStateLoading" size="23rpx"
  204. :loading="couponSituationLoading || shareStateLoading" color="#fff" />
  205. <up-icon v-else name="info-circle" size="23rpx" color="#fff" />
  206. <view v-if="couponSituationLoading || shareStateLoading" class="desc-text">
  207. 数据加载中...
  208. </view>
  209. <view v-else class="desc-text">
  210. 数据截止到&nbsp;&nbsp;{{ changtime(deadline, 'YYYY-MM-DD HH:mm:ss') }}
  211. </view>
  212. </view>
  213. </view>
  214. <view class="me-header-tips-row header-data-info">
  215. <view class="me-header-tips-item">
  216. <view class="me-header-tips-item-num">
  217. {{ shareStateData?.todayShareCount || 0 }}
  218. </view>
  219. <view class="me-header-tips-item-des">
  220. 今日邀请
  221. </view>
  222. </view>
  223. <view class="me-header-tips-item">
  224. <view class="me-header-tips-item-num">
  225. {{ shareStateData?.totalShareCount || 0 }}
  226. </view>
  227. <view class="me-header-tips-item-des">
  228. 累计邀请
  229. </view>
  230. </view>
  231. <view class="me-header-tips-item" @click="menuClick('invitePage')">
  232. <view class="me-header-tips-item-num">
  233. {{ shareStateData?.totalTeamMemberCount || 0 }}
  234. </view>
  235. <view class="me-header-tips-item-des">
  236. 累计团员
  237. </view>
  238. <view class="me-header-tips-item-icon">
  239. <up-icon name="arrow-right" size="21rpx" color="#FFFFFF" />
  240. </view>
  241. </view>
  242. </view>
  243. <view class="me-header-tips-row header-data-info">
  244. <view class="me-header-tips-item">
  245. <view class="me-header-tips-item-num">
  246. {{ couponSituationData?.quantityForComplimentary || 0 }}
  247. </view>
  248. <view class="me-header-tips-item-des">
  249. 今日发券
  250. </view>
  251. </view>
  252. <view class="me-header-tips-item">
  253. <view class="me-header-tips-item-num">
  254. {{ couponSituationData?.quantityToBeUsed || 0 }}
  255. </view>
  256. <view class="me-header-tips-item-des">
  257. 今日领取
  258. </view>
  259. </view>
  260. <view class="me-header-tips-item" @click="menuClick('incomePage')">
  261. <view class="me-header-tips-item-num">
  262. {{ couponSituationData?.usedQuantity || 0 }}
  263. </view>
  264. <view class="me-header-tips-item-des">
  265. 今日使用
  266. </view>
  267. <view class="me-header-tips-item-icon">
  268. <up-icon name="arrow-right" size="21rpx" color="#FFFFFF" />
  269. </view>
  270. </view>
  271. </view>
  272. </view>
  273. </view>
  274. <!-- 菜单 -->
  275. <view class="me-header-menu">
  276. <view class="me-header-menu-item" @click="menuClick('applyForm',watchUserStatus)">
  277. <view class="me-header-menu-icon">
  278. <image :src="getImageUrl('@img/me/coupon-need.png')" mode="aspectFill" />
  279. <view class="me-header-menu-text">
  280. 申请发券人
  281. </view>
  282. </view>
  283. <view class="me-header-menu-left">
  284. <up-icon name="arrow-right" color="#979797" size="12" />
  285. </view>
  286. </view>
  287. <view class="me-header-menu-item" @click="menuClick('invitePage', isCouponIssuer)">
  288. <view class="me-header-menu-icon">
  289. <image :src="getImageUrl('@img/me/invite.png')" mode="aspectFill" />
  290. <view class="me-header-menu-text">
  291. 我的邀请
  292. </view>
  293. </view>
  294. <view class="me-header-menu-left">
  295. <up-icon name="arrow-right" color="#979797" size="12" />
  296. </view>
  297. </view>
  298. <view class="me-header-menu-item" @click="menuClick('myInviter', getInviteInfo)">
  299. <view class="me-header-menu-icon">
  300. <image :src="getImageUrl('@img/me/inviter.png')" mode="aspectFill" />
  301. <view class="me-header-menu-text">
  302. 我的邀请人
  303. </view>
  304. </view>
  305. <view class="me-header-menu-left">
  306. <up-icon name="arrow-right" color="#979797" size="12" />
  307. </view>
  308. </view>
  309. <view class="me-header-menu-item" @click="menuClick('shareFriend', isCouponIssuer)">
  310. <view class="me-header-menu-icon">
  311. <image :src="getImageUrl('@img/me/share.png')" mode="aspectFill" />
  312. <view class="me-header-menu-text">
  313. 邀请好友
  314. </view>
  315. </view>
  316. <view class="me-header-menu-left">
  317. <up-icon name="arrow-right" color="#979797" size="12" />
  318. </view>
  319. </view>
  320. <view class="me-header-menu-item" @click="menuClick('settingPage')">
  321. <view class="me-header-menu-icon">
  322. <image :src="getImageUrl('@img/me/setting.png')" mode="aspectFill" />
  323. <view class="me-header-menu-text">
  324. 设置
  325. </view>
  326. </view>
  327. <view class="me-header-menu-left">
  328. <up-icon name="arrow-right" color="#979797" size="12" />
  329. </view>
  330. </view>
  331. <view class="me-header-menu-item" @click="handleLogout">
  332. <view class="me-header-menu-icon">
  333. <image :src="getImageUrl('@img/me/loginOut.png')" mode="aspectFill" />
  334. <view class="me-header-menu-text">
  335. 退出登录
  336. </view>
  337. </view>
  338. <view class="me-header-menu-left">
  339. <up-icon name="arrow-right" color="#979797" size="12" />
  340. </view>
  341. </view>
  342. </view>
  343. </up-pull-refresh>
  344. <!-- 申请中的提示框 -->
  345. <up-modal content="您已提交申请,请耐心等待!" title="提示" :show="show">
  346. <template #confirmButton>
  347. <view class="rounded" style="margin-top: 20rpx;" @click="show = false">
  348. 我知道了
  349. </view>
  350. </template>
  351. </up-modal>
  352. </view>
  353. </template>
  354. <style lang="scss" scoped>
  355. // 提示框
  356. ::v-deep .u-modal {
  357. width: 580rpx !important;
  358. // height: 376rpx !important;
  359. border-radius: 20rpx !important;
  360. }
  361. ::v-deep .u-modal__title {
  362. font-weight: 500 !important;
  363. font-size: 34rpx !important;
  364. color: #333333 !important;
  365. padding-top: 29rpx !important;
  366. padding-bottom: 28rpx !important;
  367. }
  368. ::v-deep .u-modal__content {
  369. border-top: 1px solid #eeeeee;
  370. border-bottom: 1px solid #eeeeee;
  371. padding-top: 82rpx !important;
  372. padding-bottom: 64rpx !important;
  373. }
  374. ::v-deep .u-modal__content__text {
  375. font-weight: 500 !important;
  376. font-size: 32rpx !important;
  377. color: #333333 !important;
  378. text-align: center !important;
  379. }
  380. .rounded {
  381. width: 300rpx;
  382. line-height: 69rpx;
  383. background: linear-gradient(90deg, #ee6b67 0%, #ff7d78 100%);
  384. border-radius: 35rpx;
  385. font-weight: 400;
  386. font-size: 30rpx;
  387. color: #ffffff;
  388. text-align: center;
  389. margin: 0 auto;
  390. }
  391. .profile-container {
  392. height: calc(100vh - 100rpx);
  393. background-color: #f8f8fa;
  394. .me-header {
  395. height: 746rpx;
  396. display: flex;
  397. flex-direction: column;
  398. justify-content: center;
  399. align-items: center;
  400. .me-header-avatar-info {
  401. display: flex;
  402. flex-direction: column;
  403. justify-content: center;
  404. align-items: center;
  405. gap: 24rpx;
  406. .me-header-info {
  407. .me-header-name {
  408. font-weight: 500;
  409. font-size: 30rpx;
  410. color: #ffffff;
  411. }
  412. }
  413. }
  414. .me-header-tips {
  415. margin-top: 46rpx;
  416. height: 317rpx;
  417. width: 702rpx;
  418. display: flex;
  419. flex-direction: column;
  420. justify-content: center;
  421. align-items: center;
  422. gap: 20rpx;
  423. background: linear-gradient(90deg, #ff7671, #ff8e8a, #ff7671);
  424. border-radius: 8rpx;
  425. .me-header-tips-row {
  426. display: flex;
  427. .desc-time {
  428. width: 100%;
  429. display: flex;
  430. flex-direction: row;
  431. flex-wrap: nowrap;
  432. gap: 6rpx;
  433. justify-content: flex-end;
  434. padding-right: 21rpx;
  435. font-weight: 400;
  436. font-size: 20rpx;
  437. color: #ffffff;
  438. line-height: 20rpx;
  439. }
  440. .me-header-tips-item {
  441. flex: 1;
  442. display: flex;
  443. flex-direction: column;
  444. justify-content: center;
  445. align-items: center;
  446. gap: 15rpx;
  447. font-weight: 500;
  448. font-size: 34rpx;
  449. color: #ffffff;
  450. line-height: 1;
  451. .me-header-tips-item-num {
  452. font-weight: bold;
  453. }
  454. .me-header-tips-item-des {
  455. font-weight: 400;
  456. font-size: 24rpx;
  457. color: #ffffff;
  458. }
  459. }
  460. }
  461. .header-data-time {
  462. align-self: flex-end;
  463. }
  464. .me-header-tips-row.header-data-info {
  465. align-self: center;
  466. width: 642rpx;
  467. height: 96rpx;
  468. background: rgba($color: #851b17, $alpha: 0.1);
  469. border-radius: 10rpx;
  470. .me-header-tips-item {
  471. font-weight: 400;
  472. font-size: 23rpx;
  473. color: #ffffff;
  474. position: relative;
  475. &:not(:last-child):after {
  476. content: '';
  477. position: absolute;
  478. top: 50%;
  479. right: 0;
  480. transform: translateY(-50%);
  481. width: 2px;
  482. height: 40rpx;
  483. background: #ffffff;
  484. }
  485. .me-header-tips-item-icon {
  486. position: absolute;
  487. top: 50%;
  488. right: 21rpx;
  489. width: 21rpx;
  490. height: 21rpx;
  491. font-weight: bolder;
  492. transform: translateY(-50%);
  493. }
  494. }
  495. }
  496. }
  497. }
  498. .me-header-menu {
  499. background: #ffffff;
  500. border-radius: 10rpx;
  501. margin: -50rpx 24rpx 0;
  502. padding: 0 20rpx;
  503. .me-header-menu-item {
  504. height: 88rpx;
  505. display: flex;
  506. justify-content: space-between;
  507. align-items: center;
  508. border-bottom: 1px solid #eeeeee;
  509. &:last-child {
  510. border-bottom: none;
  511. }
  512. .me-header-menu-icon {
  513. display: flex;
  514. justify-content: center;
  515. align-items: center;
  516. gap: 13rpx;
  517. image {
  518. width: 40rpx;
  519. height: 40rpx;
  520. }
  521. .me-header-menu-text {
  522. font-weight: 400;
  523. font-size: 26rpx;
  524. color: #333333;
  525. }
  526. }
  527. .me-header-menu-left {}
  528. }
  529. }
  530. }
  531. /* 昵称输入框样式 */
  532. .nickname-input {
  533. width: 100%;
  534. height: 100%;
  535. font-weight: 500;
  536. font-size: 30rpx;
  537. color: #ffffff;
  538. background: transparent;
  539. border: none;
  540. outline: none;
  541. text-align: center;
  542. }
  543. </style>