index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <schedule-wrapper
  3. class="c-schedule-calendar"
  4. :name="name"
  5. :hide-header="hideHeader"
  6. :editable="editable"
  7. :dirty="dirty"
  8. @add="onAdd"
  9. @submit="submit"
  10. @save="onSave"
  11. >
  12. <div class="l-flex__none l-flex--row">
  13. <button
  14. class="l-flex__none o-button c-schedule-calendar__toggle"
  15. :class="{ show: canToToday }"
  16. @click="onToday"
  17. >
  18. 今日
  19. </button>
  20. <div class="l-flex__fill l-flex--row center">
  21. <i
  22. class="c-schedule-calendar__toggle c-schedule-calendar__btn el-icon-arrow-left c-sibling-item u-pointer"
  23. :class="{ show: canToPrevious }"
  24. @click="onPrevious"
  25. />
  26. <span class="c-schedule-calendar__time u-readonly">{{ date }}</span>
  27. <i
  28. class="c-schedule-calendar__toggle c-schedule-calendar__btn el-icon-arrow-right u-pointer"
  29. :class="{ show: canToNext }"
  30. @click="onNext"
  31. />
  32. </div>
  33. <div class="l-flex__none l-flex--row c-schedule-calendar__mode u-pointer">
  34. <div
  35. class="c-schedule-calendar__type"
  36. :class="{ active: mode === 0 }"
  37. @click="onChangeToWeek"
  38. >
  39. </div>
  40. <div
  41. class="c-schedule-calendar__type"
  42. :class="{ active: mode === 1 }"
  43. @click="onChangeToMonth"
  44. >
  45. </div>
  46. </div>
  47. </div>
  48. <component
  49. :is="activeComponent"
  50. class="c-schedule-calendar__main"
  51. :editable="editable"
  52. :weeks="weeks"
  53. :cursor="weekIndex"
  54. @add="onAdd"
  55. @edit="onEditProxy"
  56. @remove="onRemove"
  57. @switch="toDay"
  58. />
  59. <confirm-dialog
  60. ref="editDialog"
  61. title="事件设置"
  62. @confirm="onSaveEvent"
  63. >
  64. <event-edit
  65. v-if="event"
  66. ref="editor"
  67. class="u-align-self--center"
  68. :event="event"
  69. :ratio="ratio"
  70. />
  71. </confirm-dialog>
  72. <confirm-dialog
  73. ref="conflictDialog"
  74. title="冲突提醒"
  75. append-to-body
  76. @confirm="onCover"
  77. >
  78. <div
  79. v-for="conflict in conflicts"
  80. :key="conflict.key"
  81. class="o-conflict"
  82. >
  83. {{ conflict.info }}
  84. <div class="o-conflict__desc">{{ conflict.desc }}</div>
  85. </div>
  86. </confirm-dialog>
  87. <el-dialog
  88. :visible.sync="isPreviewing"
  89. custom-class="c-preview schedule"
  90. :before-close="onClosePreviewDialog"
  91. append-to-body
  92. >
  93. <schedule
  94. v-if="scheduleId"
  95. class="l-flex__auto has-padding"
  96. :schedule="scheduleId"
  97. />
  98. </el-dialog>
  99. </schedule-wrapper>
  100. </template>
  101. <script>
  102. import { ScheduleType } from '@/constant'
  103. import {
  104. toEvent,
  105. toDate
  106. } from '@/utils/event'
  107. import calendarMixin from '../mixins/calendar'
  108. import ScheduleWrapper from '../components/ScheduleWrapper'
  109. import ScheduleCalendarWeek from './ScheduleCalendarWeek'
  110. import ScheduleCalendarMonth from './ScheduleCalendarMonth'
  111. import EventEdit from './EventEdit'
  112. export default {
  113. name: 'ScheduleComplex',
  114. components: {
  115. ScheduleWrapper,
  116. ScheduleCalendarWeek,
  117. ScheduleCalendarMonth,
  118. EventEdit
  119. },
  120. mixins: [calendarMixin],
  121. methods: {
  122. transformEvents (events, type) {
  123. switch (type) {
  124. case ScheduleType.CALENDAR:
  125. return events.map(event => this.createEventProxy(toEvent(event))).sort((a, b) => toDate(a.origin.start) - toDate(b.origin.start))
  126. default:
  127. return events.sort((a, b) => toDate(a.start) - toDate(b.start)).map(this.createEventProxy)
  128. }
  129. },
  130. getEvents () {
  131. switch (this.scheduleOptions.type) {
  132. case ScheduleType.CALENDAR:
  133. return this.events.map(({ origin: event }) => {
  134. const { start, until, target: { id, name } } = event
  135. return {
  136. programId: id,
  137. programName: name,
  138. startDateTime: start,
  139. endDateTime: until
  140. }
  141. })
  142. default:
  143. return this.events.map(({ origin }) => origin)
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .c-schedule-calendar {
  151. min-height: 200px;
  152. &__time {
  153. box-sizing: content-box;
  154. min-width: 100px;
  155. padding: $spacing;
  156. color: $black;
  157. font-size: 24px;
  158. font-weight: bold;
  159. line-height: 1;
  160. text-align: center;
  161. }
  162. &__toggle {
  163. visibility: hidden;
  164. &.show {
  165. visibility: visible;
  166. }
  167. }
  168. &__btn {
  169. color: $blue;
  170. font-size: 18px;
  171. font-weight: bold;
  172. }
  173. &__main {
  174. flex: 0 1 auto;
  175. min-height: 0;
  176. }
  177. &__mode {
  178. border-radius: 4px;
  179. background-color: #f4f7f8;
  180. overflow: hidden;
  181. }
  182. &__type {
  183. padding: 8px 12px;
  184. color: $info--dark;
  185. &.active {
  186. color: #fff;
  187. background-color: $blue;
  188. }
  189. }
  190. }
  191. .o-conflict {
  192. &__desc {
  193. padding: 4px 0;
  194. color: $info;
  195. font-size: 12px;
  196. }
  197. }
  198. </style>