sign-in.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <view class="sign-in-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-btn" @click="goBack">
  6. <text class="back-icon">‹</text>
  7. </view>
  8. <text class="header-title">签到</text>
  9. <view class="placeholder"></view>
  10. </view>
  11. <scroll-view scroll-y class="content">
  12. <!-- 签到日历标题 -->
  13. <view class="calendar-header">
  14. <text class="calendar-title">11月签到日历</text>
  15. <text class="calendar-subtitle">红线相系,良缘成就一生欢喜。</text>
  16. </view>
  17. <!-- 月份选择 -->
  18. <view class="month-selector">
  19. <text class="month-text">2025年 11月</text>
  20. <view class="streak-badge">
  21. <text class="streak-text">红线季良缘</text>
  22. </view>
  23. <view class="calendar-icon">📅</view>
  24. </view>
  25. <!-- 日历 -->
  26. <view class="calendar">
  27. <view class="weekdays">
  28. <text class="weekday">日</text>
  29. <text class="weekday">一</text>
  30. <text class="weekday">二</text>
  31. <text class="weekday">三</text>
  32. <text class="weekday">四</text>
  33. <text class="weekday">五</text>
  34. <text class="weekday">六</text>
  35. </view>
  36. <view class="days">
  37. <view
  38. v-for="(day, index) in calendarDays"
  39. :key="index"
  40. class="day-item"
  41. :class="{
  42. 'other-month': day.isOtherMonth,
  43. 'signed': day.isSigned,
  44. 'today': day.isToday
  45. }"
  46. >
  47. <text class="day-number">{{ day.day }}</text>
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 签到统计 -->
  52. <view class="sign-stats">
  53. <view class="stat-item">
  54. <text class="stat-icon">📊</text>
  55. <text class="stat-text">累计签到: {{ totalSignDays }}天</text>
  56. </view>
  57. <view class="stat-item">
  58. <text class="stat-icon">💗</text>
  59. <text class="stat-text">可用积分: {{ availablePoints }}</text>
  60. </view>
  61. <view class="gift-icon">🎁</view>
  62. </view>
  63. <!-- 连续签到进度 -->
  64. <view class="streak-progress">
  65. <text class="progress-label">连续签到奖励</text>
  66. <text class="progress-days">连续{{ consecutiveDays }}天</text>
  67. </view>
  68. <view class="progress-bar">
  69. <view class="progress-fill" :style="{ width: progressWidth }"></view>
  70. </view>
  71. <!-- 签到按钮 -->
  72. <view class="sign-button" :class="{ disabled: isSigned }" @click="handleSignIn">
  73. <text class="button-text">{{ isSigned ? '今日已签到' : '今日签到 +10积分' }}</text>
  74. </view>
  75. <!-- 提示文字 -->
  76. <view class="tips">
  77. <text class="tips-text">坚持签到,缘分更近一步</text>
  78. <text class="tips-sub">品牌出品 | 青鸟之恋1跟平台</text>
  79. </view>
  80. </scroll-view>
  81. </view>
  82. </template>
  83. <script>
  84. import api from '@/utils/api.js'
  85. export default {
  86. data() {
  87. return {
  88. currentYear: new Date().getFullYear(),
  89. currentMonth: new Date().getMonth() + 1,
  90. totalSignDays: 0,
  91. availablePoints: 0,
  92. consecutiveDays: 0,
  93. makerId: null,
  94. isSigned: false,
  95. calendarDays: [],
  96. signedDates: [] // 已签到的日期
  97. }
  98. },
  99. computed: {
  100. progressWidth() {
  101. // 假设7天为一个周期
  102. const progress = (this.consecutiveDays % 7) / 7 * 100
  103. return progress + '%'
  104. }
  105. },
  106. onLoad() {
  107. this.initData()
  108. },
  109. onShow() {
  110. // 每次显示页面时刷新数据
  111. if (this.makerId) {
  112. this.loadSignInData()
  113. }
  114. },
  115. methods: {
  116. goBack() {
  117. uni.navigateBack()
  118. },
  119. async initData() {
  120. // 获取红娘ID
  121. const userInfo = uni.getStorageSync('userInfo')
  122. if (userInfo && userInfo.matchmakerId) {
  123. this.makerId = userInfo.matchmakerId
  124. } else if (userInfo && userInfo.userId) {
  125. // 如果没有matchmakerId,通过API获取
  126. try {
  127. const res = await api.matchmaker.getByUserId(userInfo.userId)
  128. let matchmaker = res
  129. if (res && res.data) {
  130. matchmaker = res.data
  131. }
  132. if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
  133. this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
  134. userInfo.matchmakerId = this.makerId
  135. uni.setStorageSync('userInfo', userInfo)
  136. }
  137. } catch (e) {
  138. console.error('获取红娘信息失败:', e)
  139. }
  140. }
  141. await this.loadSignInData()
  142. this.generateCalendar()
  143. },
  144. async loadSignInData() {
  145. if (!this.makerId) return
  146. try {
  147. // 获取签到统计数据
  148. const statsRes = await api.matchmaker.checkinStats(this.makerId)
  149. let stats = statsRes
  150. if (statsRes && statsRes.data) {
  151. stats = statsRes.data
  152. }
  153. this.totalSignDays = stats.totalDays || 0
  154. this.consecutiveDays = stats.continuousDays || 0
  155. // 获取积分余额
  156. const balanceRes = await api.pointsMall.getBalance(this.makerId)
  157. this.availablePoints = balanceRes.balance || 0
  158. // 检查今日签到状态
  159. const statusRes = await api.matchmaker.checkinStatus(this.makerId)
  160. let statusData = statusRes
  161. if (statusRes && statusRes.data !== undefined) {
  162. statusData = statusRes.data
  163. }
  164. this.isSigned = statusData === true || statusData?.isCheckedIn === true || statusData?.checked === true
  165. // 如果今日已签到,添加到已签到日期
  166. if (this.isSigned) {
  167. const today = new Date().getDate()
  168. if (!this.signedDates.includes(today)) {
  169. this.signedDates.push(today)
  170. }
  171. }
  172. } catch (e) {
  173. console.error('加载签到数据失败:', e)
  174. }
  175. },
  176. generateCalendar() {
  177. const year = this.currentYear
  178. const month = this.currentMonth
  179. // 获取当月第一天是星期几
  180. const firstDay = new Date(year, month - 1, 1).getDay()
  181. // 获取当月天数
  182. const daysInMonth = new Date(year, month, 0).getDate()
  183. // 获取上月天数
  184. const prevMonthDays = new Date(year, month - 1, 0).getDate()
  185. const days = []
  186. // 添加上月日期
  187. for (let i = firstDay - 1; i >= 0; i--) {
  188. days.push({
  189. day: prevMonthDays - i,
  190. isOtherMonth: true,
  191. isSigned: false,
  192. isToday: false
  193. })
  194. }
  195. // 添加当月日期
  196. const today = new Date().getDate()
  197. const currentMonthNow = new Date().getMonth() + 1
  198. for (let i = 1; i <= daysInMonth; i++) {
  199. days.push({
  200. day: i,
  201. isOtherMonth: false,
  202. isSigned: this.signedDates.includes(i),
  203. isToday: i === today && month === currentMonthNow
  204. })
  205. }
  206. // 添加下月日期补齐
  207. const remainingDays = 42 - days.length // 6行7列
  208. for (let i = 1; i <= remainingDays; i++) {
  209. days.push({
  210. day: i,
  211. isOtherMonth: true,
  212. isSigned: false,
  213. isToday: false
  214. })
  215. }
  216. this.calendarDays = days
  217. },
  218. async handleSignIn() {
  219. if (this.isSigned) {
  220. uni.showToast({
  221. title: '今日已签到',
  222. icon: 'none'
  223. })
  224. return
  225. }
  226. if (!this.makerId) {
  227. uni.showToast({ title: '请先登录', icon: 'none' })
  228. return
  229. }
  230. try {
  231. // 调用后端签到接口
  232. await api.matchmaker.doCheckin(this.makerId)
  233. // 签到成功后更新状态
  234. this.isSigned = true
  235. this.totalSignDays++
  236. this.consecutiveDays++
  237. // 更新今天的签到状态
  238. const today = new Date().getDate()
  239. if (!this.signedDates.includes(today)) {
  240. this.signedDates.push(today)
  241. }
  242. this.generateCalendar()
  243. // 刷新积分余额
  244. const balanceRes = await api.pointsMall.getBalance(this.makerId)
  245. this.availablePoints = balanceRes.balance || 0
  246. uni.showToast({
  247. title: '签到成功 +5积分',
  248. icon: 'success'
  249. })
  250. } catch (e) {
  251. console.error('签到失败:', e)
  252. // 如果是已签到的错误,更新状态
  253. if (e.message && e.message.includes('已签到')) {
  254. this.isSigned = true
  255. }
  256. uni.showToast({
  257. title: e.message || '签到失败',
  258. icon: 'none'
  259. })
  260. }
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss" scoped>
  266. .sign-in-page {
  267. min-height: 100vh;
  268. background: linear-gradient(180deg, #F3E5F5 0%, #FFF9F9 40%);
  269. display: flex;
  270. flex-direction: column;
  271. }
  272. /* 顶部导航栏 */
  273. .header {
  274. display: flex;
  275. align-items: center;
  276. justify-content: space-between;
  277. padding: 20rpx 30rpx;
  278. padding-top: calc(20rpx + env(safe-area-inset-top));
  279. background: transparent;
  280. .back-btn {
  281. width: 50rpx;
  282. height: 50rpx;
  283. display: flex;
  284. align-items: center;
  285. justify-content: center;
  286. .back-icon {
  287. font-size: 40rpx;
  288. color: #333;
  289. }
  290. }
  291. .header-title {
  292. font-size: 32rpx;
  293. font-weight: bold;
  294. color: #333;
  295. }
  296. .placeholder {
  297. width: 50rpx;
  298. }
  299. }
  300. .content {
  301. flex: 1;
  302. padding: 10rpx 20rpx 20rpx;
  303. }
  304. /* 日历标题 */
  305. .calendar-header {
  306. margin-bottom: 20rpx;
  307. .calendar-title {
  308. display: block;
  309. font-size: 32rpx;
  310. font-weight: bold;
  311. color: #333;
  312. margin-bottom: 8rpx;
  313. }
  314. .calendar-subtitle {
  315. display: block;
  316. font-size: 24rpx;
  317. color: #FF6B9D;
  318. }
  319. }
  320. /* 月份选择 */
  321. .month-selector {
  322. display: flex;
  323. align-items: center;
  324. justify-content: space-between;
  325. margin-bottom: 20rpx;
  326. .month-text {
  327. font-size: 28rpx;
  328. font-weight: bold;
  329. color: #7B1FA2;
  330. }
  331. .streak-badge {
  332. background: linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%);
  333. color: #FFFFFF;
  334. font-size: 22rpx;
  335. font-weight: bold;
  336. padding: 6rpx 14rpx;
  337. border-radius: 12rpx;
  338. }
  339. .calendar-icon {
  340. font-size: 32rpx;
  341. }
  342. }
  343. /* 日历 */
  344. .calendar {
  345. background: #FFFFFF;
  346. border-radius: 16rpx;
  347. padding: 20rpx;
  348. margin-bottom: 20rpx;
  349. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  350. .weekdays {
  351. display: grid;
  352. grid-template-columns: repeat(7, 1fr);
  353. margin-bottom: 15rpx;
  354. .weekday {
  355. text-align: center;
  356. font-size: 24rpx;
  357. color: #666;
  358. font-weight: bold;
  359. }
  360. }
  361. .days {
  362. display: grid;
  363. grid-template-columns: repeat(7, 1fr);
  364. gap: 8rpx;
  365. .day-item {
  366. aspect-ratio: 1;
  367. display: flex;
  368. align-items: center;
  369. justify-content: center;
  370. border-radius: 12rpx;
  371. background: #F5F5F5;
  372. &.other-month {
  373. background: transparent;
  374. .day-number {
  375. color: #CCC;
  376. }
  377. }
  378. &.signed {
  379. background: linear-gradient(135deg, #CE93D8 0%, #BA68C8 100%);
  380. .day-number {
  381. color: #FFFFFF;
  382. font-weight: bold;
  383. }
  384. }
  385. &.today {
  386. border: 2rpx solid #9C27B0;
  387. }
  388. .day-number {
  389. font-size: 24rpx;
  390. color: #333;
  391. }
  392. }
  393. }
  394. }
  395. /* 签到统计 */
  396. .sign-stats {
  397. display: flex;
  398. align-items: center;
  399. justify-content: space-between;
  400. background: #FFFFFF;
  401. border-radius: 16rpx;
  402. padding: 15rpx 20rpx;
  403. margin-bottom: 15rpx;
  404. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  405. .stat-item {
  406. display: flex;
  407. align-items: center;
  408. gap: 8rpx;
  409. flex: 1;
  410. .stat-icon {
  411. font-size: 24rpx;
  412. }
  413. .stat-text {
  414. font-size: 24rpx;
  415. color: #666;
  416. }
  417. }
  418. .gift-icon {
  419. font-size: 32rpx;
  420. }
  421. }
  422. /* 连续签到进度 */
  423. .streak-progress {
  424. display: flex;
  425. align-items: center;
  426. justify-content: space-between;
  427. margin-bottom: 10rpx;
  428. .progress-label {
  429. font-size: 24rpx;
  430. color: #666;
  431. }
  432. .progress-days {
  433. font-size: 24rpx;
  434. color: #9C27B0;
  435. font-weight: bold;
  436. }
  437. }
  438. .progress-bar {
  439. width: 100%;
  440. height: 12rpx;
  441. background: #E0E0E0;
  442. border-radius: 6rpx;
  443. margin-bottom: 25rpx;
  444. overflow: hidden;
  445. .progress-fill {
  446. height: 100%;
  447. background: linear-gradient(90deg, #9C27B0 0%, #BA68C8 100%);
  448. border-radius: 6rpx;
  449. transition: width 0.3s ease;
  450. }
  451. }
  452. /* 签到按钮 */
  453. .sign-button {
  454. background: linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%);
  455. border-radius: 16rpx;
  456. padding: 20rpx;
  457. margin-bottom: 20rpx;
  458. box-shadow: 0 4rpx 12rpx rgba(156, 39, 176, 0.3);
  459. &.disabled {
  460. background: #E0E0E0;
  461. box-shadow: none;
  462. }
  463. .button-text {
  464. display: block;
  465. text-align: center;
  466. font-size: 28rpx;
  467. font-weight: bold;
  468. color: #FFFFFF;
  469. }
  470. }
  471. /* 提示文字 */
  472. .tips {
  473. text-align: center;
  474. .tips-text {
  475. display: block;
  476. font-size: 26rpx;
  477. color: #666;
  478. margin-bottom: 8rpx;
  479. }
  480. .tips-sub {
  481. display: block;
  482. font-size: 22rpx;
  483. color: #999;
  484. }
  485. }
  486. </style>