EventItem.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <el-popover
  3. trigger="hover"
  4. placement="right"
  5. :close-delay="0"
  6. >
  7. <div class="c-event-detail">
  8. <div class="c-event-detail__time">{{ time }}</div>
  9. <div
  10. v-if="desc"
  11. class="c-event-detail__desc"
  12. >{{ desc }}</div>
  13. </div>
  14. <template #reference>
  15. <div
  16. class="c-event u-ellipsis u-pointer"
  17. :class="{ fill, editable }"
  18. @click="onClick"
  19. >
  20. {{ event.origin.target.name }}
  21. <i
  22. class="c-event__icon el-icon-close"
  23. @click.stop="onRemove"
  24. />
  25. </div>
  26. </template>
  27. </el-popover>
  28. </template>
  29. <script>
  30. import { EventFreq } from '@/constant'
  31. export default {
  32. name: 'EventItem',
  33. props: {
  34. event: {
  35. type: Object,
  36. default: null
  37. },
  38. fill: {
  39. type: [Boolean, String],
  40. default: false
  41. },
  42. editable: {
  43. type: [Boolean, String],
  44. default: false
  45. }
  46. },
  47. computed: {
  48. time () {
  49. const { start, until } = this.event.origin
  50. return until ? `${start} - ${until}` : `自${start}开始`
  51. },
  52. desc () {
  53. const { freq, byDay, startTime, endTime } = this.event.origin
  54. switch (freq) {
  55. case EventFreq.WEEKLY:
  56. return `每周${byDay.split(',').map(val => ['日', '一', '二', '三', '四', '五', '六'][val]).join('、')},${startTime} - ${endTime}`
  57. default:
  58. return null
  59. }
  60. }
  61. },
  62. methods: {
  63. onClick () {
  64. this.$emit('edit', this.event)
  65. },
  66. onRemove () {
  67. this.$emit('remove', this.event)
  68. }
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .c-event-detail {
  74. display: inline-block;
  75. color: $black;
  76. text-align: center;
  77. &__time {
  78. font-size: 14px;
  79. font-weight: bold;
  80. }
  81. &__desc {
  82. margin-top: 6px;
  83. color: $black;
  84. font-size: 12px;
  85. }
  86. }
  87. .c-event {
  88. display: inline-block;
  89. position: relative;
  90. max-width: 100%;
  91. padding: 6px 8px;
  92. color: #fff;
  93. font-size: 14px;
  94. line-height: 1;
  95. border-radius: $radius--mini;
  96. background-color: $blue;
  97. &.fill {
  98. width: 100%;
  99. }
  100. &.editable:hover {
  101. padding-right: 30px;
  102. i {
  103. display: inline-flex;
  104. }
  105. }
  106. &__icon {
  107. display: none;
  108. position: absolute;
  109. justify-content: center;
  110. align-items: center;
  111. top: 50%;
  112. right: 0;
  113. width: 30px;
  114. height: 100%;
  115. transform: translateY(-50%);
  116. }
  117. }
  118. </style>