index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view>
  3. <Calendar
  4. class="uni-calendar--hook"
  5. :selected="selected"
  6. :lunar="true"
  7. :range="false"
  8. :showMonth="true"
  9. @change="handleChange"
  10. />
  11. <uni-popup ref="popupRef" type="dialog">
  12. <view class="popupContent">
  13. <view class="">上上签</view>
  14. <view class="ss-m-y-10">今日运势:上</view>
  15. <view class="d-flex align-center justify-center">
  16. 幸运色:
  17. <view class="luckyColor" :style="{ 'background-color': currentColor }"></view>
  18. </view>
  19. <view class="color-666 font-size-13 ss-m-t-30" style="text-align: left;">
  20. <view>宜:炼丹悟道 结善缘 精心修养</view>
  21. <view>忌:远行 投资 冲动决策</view>
  22. <view>今日贵人相助,修行精进</view>
  23. </view>
  24. </view>
  25. </uni-popup>
  26. </view>
  27. </template>
  28. <script setup>
  29. import { onLoad } from '@dcloudio/uni-app'
  30. import { ref } from 'vue'
  31. import Calendar from '@/components/uni-calendar/components/uni-calendar/uni-calendar.vue'
  32. /**
  33. * 获取任意时间
  34. */
  35. function getDate(date, AddDayCount = 0) {
  36. if (!date) {
  37. date = new Date()
  38. }
  39. if (typeof date !== 'object') {
  40. date = date.replace(/-/g, '/')
  41. }
  42. const dd = new Date(date)
  43. dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
  44. const y = dd.getFullYear()
  45. const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
  46. const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
  47. return {
  48. fullDate: y + '-' + m + '-' + d,
  49. year: y,
  50. month: m,
  51. date: d,
  52. day: dd.getDay()
  53. }
  54. }
  55. const selected = ref([])
  56. onLoad(() => {
  57. setTimeout(() => {
  58. selected.value = [
  59. {
  60. date: getDate(new Date(),-3).fullDate,
  61. color: '#2196F3',
  62. url: 'https://menduner.citupro.com:3443/dev/2dbc20a5db2122e399b491638889ba9f8aea4e1c7a44463ee0df40b25f85b8cc.png'
  63. },
  64. {
  65. date: getDate(new Date(),-2).fullDate,
  66. color: '#ff5252',
  67. url: 'https://menduner.citupro.com:3443/dev/2dbc20a5db2122e399b491638889ba9f8aea4e1c7a44463ee0df40b25f85b8cc.png'
  68. },
  69. {
  70. date: getDate(new Date(),-1).fullDate,
  71. color: '#26A69A',
  72. url: 'https://menduner.citupro.com:3443/dev/2dbc20a5db2122e399b491638889ba9f8aea4e1c7a44463ee0df40b25f85b8cc.png'
  73. }
  74. ]
  75. }, 2000)
  76. })
  77. const popupRef = ref()
  78. const currentColor = ref(null)
  79. const handleChange = (e) => {
  80. // console.log('change 返回:', e)
  81. if (e.isBackToday) return
  82. if (e.extraInfo) {
  83. popupRef.value.open()
  84. currentColor.value = e.extraInfo?.color || '#2979ff'
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .popupContent {
  90. background-color: #fff;
  91. border-radius: 6px;
  92. width: 400rpx;
  93. height: 400rpx;
  94. text-align: center;
  95. padding: 30rpx;
  96. .luckyColor {
  97. width: 60rpx;
  98. height: 60rpx;
  99. border-radius: 50%;
  100. }
  101. }
  102. </style>