DeviceCalender.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 {
  48. isHit,
  49. toDate,
  50. getEventDescription
  51. } from '@/utils/event'
  52. import VueSeamlessScroll from 'vue-seamless-scroll'
  53. import Box from './Box'
  54. export default {
  55. name: 'DeviceCalender',
  56. components: {
  57. VueSeamlessScroll,
  58. Box
  59. },
  60. props: {
  61. deviceList: {
  62. type: Array,
  63. required: true
  64. }
  65. },
  66. data () {
  67. return {
  68. classOption: {
  69. step: 0.5,
  70. hoverStop: false
  71. },
  72. programMap: null
  73. }
  74. },
  75. computed: {
  76. tableData () {
  77. const map = this.programMap
  78. return this.deviceList.map(({ id, name, onlineStatus }) => {
  79. const data = map ? map[id] : null
  80. return {
  81. id, name,
  82. updateTime: data ? data.updateTime : '-',
  83. programName: map
  84. ? data?.event?.target.name || '暂无节目'
  85. : '查询中...',
  86. programDesc: map && data?.event ? getEventDescription(data.event) : '-',
  87. status: onlineStatus === 1 && map && data?.event ? '在播' : ''
  88. }
  89. })
  90. }
  91. },
  92. watch: {
  93. deviceList: {
  94. handler () {
  95. if (this.deviceList.length) {
  96. this.getTimelines()
  97. }
  98. },
  99. immediate: true
  100. }
  101. },
  102. methods: {
  103. getTimelines () {
  104. getTimelines(this.deviceList.map(i => i.id), { custom: true }).then(
  105. data => {
  106. const map = {}
  107. data.forEach(({ deviceId, updateTime, eventDetail }) => {
  108. map[deviceId] = {
  109. updateTime,
  110. event: this.getCurrentEvent(eventDetail)
  111. }
  112. })
  113. this.programMap = map
  114. }
  115. )
  116. },
  117. getCurrentEvent (events) {
  118. if (events.length) {
  119. const now = new Date()
  120. const timeline = events.filter(({ until }) => !until || now < new Date(until)).sort((a, b) => {
  121. if (b.priority === a.priority) {
  122. return toDate(a.start) - toDate(b.start)
  123. }
  124. return b.priority - a.priority
  125. })
  126. for (let i = 0; i < timeline.length; i++) {
  127. const event = timeline[i]
  128. if (isHit(event, now)) {
  129. return event
  130. }
  131. }
  132. }
  133. return null
  134. }
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .c-calendar {
  140. &__header {
  141. color: #9ea9cd;
  142. background-color: #313a5a;
  143. }
  144. &__list {
  145. position: absolute;
  146. top: 0;
  147. left: 0;
  148. width: 100%;
  149. height: 100%;
  150. overflow: hidden;
  151. }
  152. &__item {
  153. color: #ffffff;
  154. border-bottom: 1px solid #313a5a;
  155. }
  156. &__header,
  157. &__item {
  158. font-size: 18px;
  159. line-height: 60px;
  160. text-align: center;
  161. }
  162. .alarm__icon {
  163. width: 19px;
  164. height: 19px;
  165. transform: translateY(-2px);
  166. }
  167. .col {
  168. &__deviceName {
  169. flex: 1;
  170. min-width: 0;
  171. }
  172. &__programName {
  173. flex: 1;
  174. min-width: 0;
  175. }
  176. &__calender {
  177. flex: 2;
  178. min-width: 0;
  179. }
  180. &__createTime {
  181. flex: 1;
  182. min-width: 0;
  183. }
  184. &__status {
  185. width: 50px;
  186. &.o-red {
  187. color: #f40645;
  188. }
  189. }
  190. }
  191. }
  192. </style>