Calendar.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :md="20">
  5. <el-row>
  6. <h2>我的日历</h2>
  7. </el-row>
  8. <el-row>
  9. <calendar-heatmap :max="10" :values="values" :end-date="endDate" />
  10. </el-row>
  11. </el-col>
  12. </el-row>
  13. </div>
  14. </template>
  15. <script>
  16. import Vue from 'vue'
  17. import { CalendarHeatmap } from 'vue-calendar-heatmap'
  18. import { getHeatmap } from '@/api/im'
  19. Vue.component('calendarHeatmap', CalendarHeatmap)
  20. export default {
  21. name: 'Calendar',
  22. data() {
  23. return {
  24. values: [
  25. { date: '2018-9-22', count: 6 },
  26. { date: '2018-9-23', count: 5 },
  27. { date: '2018-9-24', count: 4 },
  28. { date: '2018-9-25', count: 3 },
  29. { date: '2018-9-26', count: 2 },
  30. { date: '2018-9-27', count: 1 },
  31. { date: '2018-9-28', count: 7 },
  32. { date: '2018-9-29', count: 8 },
  33. { date: '2018-9-30', count: 9 }
  34. ],
  35. endDate: '2019-10-22'
  36. }
  37. },
  38. created() {
  39. const path = this.$route.path
  40. var title = '我的消息'
  41. if (path.endsWith('/send')) {
  42. title = '发出的消息'
  43. } else if (path.endsWith('/receive')) {
  44. title = '收到的消息'
  45. } else if (path.endsWith('/private')) {
  46. title = '私信'
  47. }
  48. document.title = title
  49. console.log(new Date())
  50. getHeatmap().then(resp => {
  51. if (resp.code === 0) {
  52. this.values = resp.data
  53. this.endDate = this.getYearMonthDay()
  54. }
  55. })
  56. },
  57. methods: {
  58. getYearMonthDay() {
  59. const date = new Date()
  60. const year = date.getFullYear().toString().padStart(4, '0')
  61. const month = (date.getMonth() + 1).toString().padStart(2, '0')
  62. const day = date.getDate().toString().padStart(2, '0')
  63. return year + '-' + month + '-' + day
  64. }
  65. }
  66. }
  67. </script>