signIn.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!-- 签到 -->
  2. <template>
  3. <div>
  4. <integralShow ref="integralRef"></integralShow>
  5. <div class="d-flex justify-center mt-10">
  6. <div v-for="(item, index) in configList" :key="'signInKey' + index" >
  7. <div
  8. class="borderRadius-5 mx-5 py-3 px-4"
  9. style="text-align: center;"
  10. :style="{'background-color': index < continuousDay ? '#10897ba8' : 'var(--color-f2f4f7)'}"
  11. >
  12. <!-- 图标 -->
  13. <div class="mt-1">
  14. <svg-icon v-if="index < continuousDay" name="tick" size="36"></svg-icon>
  15. <svg-icon v-else name="integral" size="38"></svg-icon>
  16. </div>
  17. <div class="mt-2" :style="{'color': index < continuousDay ? '#fff' : 'var(--color-333)'}">
  18. <span class="font-12">+</span>
  19. <span>{{ item.point }}</span>
  20. </div>
  21. </div>
  22. <div class="mt-2 font-13" style="text-align: center;" :style="{'color': index < continuousDay ? '#10897b' : 'var(--color-333)'}">
  23. {{ `${index === todayNumber ? '今天' : '第' + item.day + '天'}` }}
  24. </div>
  25. </div>
  26. </div>
  27. <div class="mt-8" style="text-align: right;">
  28. <span v-if="continuousDay > 0" class="font-13 color-777 mr-3">
  29. 您已经连续签到
  30. <span class="mx-1" style="color: var(--v-primary-base); font-weight: 600;"> {{ continuousDay }} </span>
  31. 天,明天再来吧
  32. </span>
  33. <v-btn class="half-button" color="primary" size="small" :loading="signLoading" :disabled="todaySignIn" @click="handleSignIn">{{ todaySignIn ? '已签到' : '签到' }}</v-btn>
  34. </div>
  35. </div>
  36. </template>
  37. <script setup>
  38. defineOptions({name: 'personal-taskCenter-signIn'})
  39. import { ref } from 'vue'
  40. import { useUserStore } from '@/store/user'
  41. import { useI18n } from '@/hooks/web/useI18n'
  42. import { getRewardSignInRecordSummary, getRewardSignInConfigList, createRewardSignInRecord } from '@/api/sign'
  43. import integralShow from '@/views/integral/pointsManagement/components/integralShow.vue'
  44. import Snackbar from '@/plugins/snackbar'
  45. const { t } = useI18n()
  46. const userStore = useUserStore()
  47. const integralRef = ref()
  48. // 连续签到天数
  49. const continuousDay = ref(0)
  50. // 今天有无签到
  51. const todaySignIn = ref(false)
  52. // 规则列表
  53. const configList = ref([])
  54. const todayNumber = ref()
  55. const signLoading = ref(false)
  56. // 获取签到规则列表
  57. const getConfigList = async () => {
  58. const data = await getRewardSignInConfigList()
  59. configList.value = data
  60. }
  61. getConfigList()
  62. // 获取个人签到统计
  63. const getSummary = async () => {
  64. const data = await getRewardSignInRecordSummary()
  65. if (!data) return
  66. continuousDay.value = data.continuousDay // 连续签到第n天
  67. todaySignIn.value = data.todaySignIn // 今天有无签到
  68. todayNumber.value = todaySignIn.value ? continuousDay.value - 1 : continuousDay.value
  69. }
  70. getSummary()
  71. // 签到
  72. const handleSignIn = async () => {
  73. signLoading.value = true
  74. await createRewardSignInRecord()
  75. setTimeout(async () => {
  76. await getSummary()
  77. Snackbar.success(t('taskCenter.signInSuccess'))
  78. signLoading.value = false
  79. // 更新积分数
  80. await userStore.getUserAccountInfo()
  81. }, 1000)
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .color-333 { color: var(--color-333); }
  86. .color-fff { color: #fff; }
  87. .color-777 { color: var(--color-666); }
  88. .font-12 { font-size: 12px; }
  89. .font-13 { font-size: 13px; }
  90. .font-14 { font-size: 14; }
  91. .font-16 { font-size: 16px; }
  92. .borderRadius-5 { border-radius: 5px; }
  93. .signInRecord {
  94. font-size: 14px;
  95. color: var(--v-primary-base);
  96. cursor: pointer;
  97. }
  98. </style>