DeviceCalender.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <box title="各大屏当前播放节目">
  3. <div class="l-flex__fill l-flex--col c-calendar u-text--center">
  4. <div class="l-flex__none l-flex--row c-calendar__header">
  5. <div class="col__deviceName">设备名称</div>
  6. <div class="col__programName">节目名称</div>
  7. <div class="col__calender">时间排期</div>
  8. <div class="col__createTime">更新时间</div>
  9. <div class="col__status">状态</div>
  10. </div>
  11. <div class="l-flex__fill u-relative">
  12. <div class="c-calendar__list">
  13. <vue-seamless-scroll
  14. :data="tableData"
  15. :class-option="classOption"
  16. >
  17. <div
  18. v-for="item in tableData"
  19. :key="item.id"
  20. class="l-flex--row c-calendar__item"
  21. >
  22. <div class="col__deviceName">
  23. <auto-text
  24. class="u-text--center"
  25. :text="item.name"
  26. />
  27. </div>
  28. <div class="col__programName">
  29. <auto-text :text="item.programName" />
  30. </div>
  31. <div class="col__calender">
  32. <auto-text :text="item.programDesc" />
  33. </div>
  34. <div class="col__createTime">
  35. <auto-text :text="item.updateTime" />
  36. </div>
  37. <div class="col__status o-red">{{ item.status }}</div>
  38. </div>
  39. </vue-seamless-scroll>
  40. </div>
  41. </div>
  42. </div>
  43. </box>
  44. </template>
  45. <script>
  46. import { getTimelines } from './api'
  47. import { EventPriorityInfo } from '@/constant'
  48. import {
  49. isHit,
  50. toDate,
  51. getEventDescription
  52. } from '@/utils/event'
  53. import VueSeamlessScroll from 'vue-seamless-scroll'
  54. import Box from './Box'
  55. export default {
  56. name: 'DeviceCalender',
  57. components: {
  58. VueSeamlessScroll,
  59. Box
  60. },
  61. props: {
  62. deviceList: {
  63. type: Array,
  64. required: true
  65. }
  66. },
  67. data () {
  68. return {
  69. classOption: {
  70. step: 0.5,
  71. hoverStop: false
  72. },
  73. programMap: null
  74. }
  75. },
  76. computed: {
  77. tableData () {
  78. const map = this.programMap
  79. return this.deviceList.map(({ id, name, onlineStatus }) => {
  80. const data = map ? map[id] : null
  81. return {
  82. id, name,
  83. updateTime: data ? data.updateTime : '-',
  84. programName: map
  85. ? data?.event
  86. ? data.event.target.name || EventPriorityInfo[data.event.priority]
  87. : '暂无节目'
  88. : '查询中...',
  89. programDesc: map && data?.event ? getEventDescription(data.event) : '-',
  90. status: onlineStatus === 1 && map && data?.event ? '在播' : ''
  91. }
  92. })
  93. }
  94. },
  95. watch: {
  96. deviceList: {
  97. handler () {
  98. if (this.deviceList.length) {
  99. this.getTimelines()
  100. }
  101. },
  102. immediate: true
  103. }
  104. },
  105. methods: {
  106. getTimelines () {
  107. getTimelines(this.deviceList.map(i => i.id), { custom: true }).then(
  108. data => {
  109. const map = {}
  110. data.forEach(({ deviceId, updateTime, eventDetail }) => {
  111. map[deviceId] = {
  112. updateTime,
  113. event: this.getCurrentEvent(eventDetail)
  114. }
  115. })
  116. this.programMap = map
  117. }
  118. )
  119. },
  120. getCurrentEvent (events) {
  121. if (events.length) {
  122. const now = new Date()
  123. const timeline = events.filter(({ until }) => !until || now < new Date(until)).sort((a, b) => {
  124. if (b.priority === a.priority) {
  125. return toDate(a.start) - toDate(b.start)
  126. }
  127. return b.priority - a.priority
  128. })
  129. for (let i = 0; i < timeline.length; i++) {
  130. const event = timeline[i]
  131. if (isHit(event, now)) {
  132. return event
  133. }
  134. }
  135. }
  136. return null
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .c-calendar {
  143. &__header {
  144. color: #9ea9cd;
  145. background-color: #313a5a;
  146. }
  147. &__list {
  148. position: absolute;
  149. top: 0;
  150. left: 0;
  151. width: 100%;
  152. height: 100%;
  153. overflow: hidden;
  154. }
  155. &__item {
  156. color: #ffffff;
  157. border-bottom: 1px solid #313a5a;
  158. }
  159. &__header,
  160. &__item {
  161. font-size: 18px;
  162. line-height: 60px;
  163. text-align: center;
  164. }
  165. .alarm__icon {
  166. width: 19px;
  167. height: 19px;
  168. transform: translateY(-2px);
  169. }
  170. .col {
  171. &__deviceName {
  172. flex: 1;
  173. min-width: 0;
  174. }
  175. &__programName {
  176. flex: 1;
  177. min-width: 0;
  178. }
  179. &__calender {
  180. flex: 2;
  181. min-width: 0;
  182. }
  183. &__createTime {
  184. flex: 1;
  185. min-width: 0;
  186. }
  187. &__status {
  188. width: 50px;
  189. &.o-red {
  190. color: #f40645;
  191. }
  192. }
  193. }
  194. }
  195. </style>