daily-fortune.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="daily-fortune-page">
  3. <view class="nav-bar">
  4. <text class="nav-back" @click="goBack">←</text>
  5. <text class="nav-title">每日宜忌</text>
  6. <view class="nav-right"></view>
  7. </view>
  8. <view v-if="loading" class="loading-state"><text>加载中...</text></view>
  9. <view v-else-if="error" class="error-state"><text class="error-text">{{ error }}</text></view>
  10. <view v-else-if="fortune" class="content">
  11. <view class="date-banner">
  12. <text class="date-text">{{ fortune.date || todayStr }}</text>
  13. <text class="date-lunar" v-if="fortune.lunarDate">{{ fortune.lunarDate }}</text>
  14. </view>
  15. <view class="info-card" v-if="fortune.fiveElements">
  16. <view class="card-title-bar"><text class="card-title">今日五行</text></view>
  17. <view class="five-elements-display">
  18. <text class="fe-main">{{ fortune.fiveElements.main || '' }}</text>
  19. <text class="fe-detail" v-if="fortune.fiveElements.detail">{{ fortune.fiveElements.detail }}</text>
  20. </view>
  21. </view>
  22. <view class="info-card" v-if="fortune.auspicious && fortune.auspicious.length > 0">
  23. <view class="card-title-bar auspicious-bar"><text class="card-title">宜</text></view>
  24. <view class="item-tags">
  25. <view v-for="(item, idx) in fortune.auspicious" :key="idx" class="tag-item good">
  26. <text class="tag-text">{{ item }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="info-card" v-if="fortune.inauspicious && fortune.inauspicious.length > 0">
  31. <view class="card-title-bar inauspicious-bar"><text class="card-title">忌</text></view>
  32. <view class="item-tags">
  33. <view v-for="(item, idx) in fortune.inauspicious" :key="idx" class="tag-item bad">
  34. <text class="tag-text">{{ item }}</text>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="info-card" v-if="fortune.familyAdvice">
  39. <view class="card-title-bar"><text class="card-title">家庭建议</text></view>
  40. <view class="advice-content"><text class="advice-text">{{ fortune.familyAdvice }}</text></view>
  41. </view>
  42. <view class="info-card" v-if="fortune.focusMember">
  43. <view class="card-title-bar"><text class="card-title">今日关注</text></view>
  44. <view class="focus-member-card">
  45. <text class="focus-name">{{ fortune.focusMember.name }}</text>
  46. <text class="focus-tip">{{ fortune.focusMember.tip }}</text>
  47. <view v-if="fortune.focusMember.wuxingTip" class="focus-wuxing">
  48. <text class="wuxing-tip-text">{{ fortune.focusMember.wuxingTip }}</text>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. export default {
  57. data: function() { return { fortune: null, loading: false, error: null, todayStr: '' } },
  58. onLoad: function() {
  59. var now = new Date()
  60. this.todayStr = now.getFullYear() + '-' + String(now.getMonth() + 1).padStart(2, '0') + '-' + String(now.getDate()).padStart(2, '0')
  61. this.loadDailyFortune()
  62. },
  63. methods: {
  64. loadDailyFortune: function() {
  65. var self = this
  66. self.loading = true; self.error = null
  67. self.$store.dispatch('tianpan/loadDailyFortune', { date: self.todayStr })
  68. .then(function(data) { self.fortune = data })
  69. .catch(function(e) { self.error = e.message || '加载失败' })
  70. .finally(function() { self.loading = false })
  71. },
  72. goBack: function() { uni.navigateBack() }
  73. }
  74. }
  75. </script>
  76. <style scoped>
  77. .daily-fortune-page { min-height: 100vh; background: #F3F4F6; }
  78. .nav-bar { display: flex; align-items: center; justify-content: space-between; padding: 20px 16px 10px; background: #F97316; }
  79. .nav-back { font-size: 18px; color: #FFF; }
  80. .nav-title { font-size: 17px; font-weight: bold; color: #FFF; }
  81. .nav-right { width: 40px; }
  82. .loading-state, .error-state { padding: 60px 20px; display: flex; justify-content: center; align-items: center; }
  83. .error-text { color: #EF4444; font-size: 14px; }
  84. .content { padding: 12px; }
  85. .date-banner { background: linear-gradient(135deg, #F97316, #FB923C); border-radius: 12px; padding: 20px; margin-bottom: 12px; text-align: center; }
  86. .date-text { font-size: 22px; font-weight: bold; color: #FFF; display: block; }
  87. .date-lunar { font-size: 13px; color: rgba(255,255,255,0.8); display: block; margin-top: 4px; }
  88. .info-card { background: #FFF; border-radius: 12px; padding: 16px; margin-bottom: 12px; }
  89. .card-title-bar { margin-bottom: 12px; border-bottom: 1px solid #F3F4F6; padding-bottom: 8px; display: flex; align-items: center; }
  90. .auspicious-bar .card-title { color: #10B981; font-size: 15px; font-weight: bold; }
  91. .inauspicious-bar .card-title { color: #EF4444; font-size: 15px; font-weight: bold; }
  92. .card-title { font-size: 15px; font-weight: bold; color: #1F2937; }
  93. .five-elements-display { text-align: center; padding: 8px 0; }
  94. .fe-main { font-size: 28px; font-weight: bold; color: #F97316; display: block; }
  95. .fe-detail { font-size: 13px; color: #9CA3AF; display: block; margin-top: 4px; }
  96. .item-tags { display: flex; flex-wrap: wrap; gap: 8px; }
  97. .tag-item { padding: 6px 14px; border-radius: 16px; }
  98. .tag-item.good { background: #DCFCE7; }
  99. .tag-item.bad { background: #FEE2E2; }
  100. .tag-text { font-size: 13px; }
  101. .tag-item.good .tag-text { color: #166534; }
  102. .tag-item.bad .tag-text { color: #991B1B; }
  103. .advice-content { padding: 4px 0; }
  104. .advice-text { font-size: 14px; color: #374151; line-height: 1.7; }
  105. .focus-member-card { display: flex; flex-direction: column; }
  106. .focus-name { font-size: 16px; font-weight: bold; color: #F97316; margin-bottom: 4px; }
  107. .focus-tip { font-size: 13px; color: #374151; line-height: 1.5; }
  108. .focus-wuxing { margin-top: 8px; background: #FFF7ED; border-radius: 8px; padding: 8px; }
  109. .wuxing-tip-text { font-size: 12px; color: #9CA3AF; }
  110. </style>