index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <wrapper
  3. fill
  4. margin
  5. padding
  6. background
  7. >
  8. <schema-table
  9. ref="table"
  10. :schema="schema"
  11. @row-click="onToggle"
  12. />
  13. <program-dialog ref="programDialog" />
  14. <schedule-dialog ref="scheduleDialog" />
  15. </wrapper>
  16. </template>
  17. <script>
  18. import {
  19. getPublishHistory,
  20. cancelPublish
  21. } from '@/api/platform'
  22. import {
  23. State,
  24. EventPriority,
  25. EventTarget,
  26. PublishType
  27. } from '@/constant'
  28. import { getEventDescription } from '@/utils/event'
  29. export default {
  30. name: 'ScheduleDeployHistory',
  31. data () {
  32. return {
  33. schema: {
  34. list: getPublishHistory,
  35. transform: this.transform,
  36. cols: [
  37. { type: 'expand', render (data, h) {
  38. return h('div', {
  39. staticClass: 'o-info'
  40. }, [
  41. h('div', null, data.desc),
  42. h('div', null, `设备:${data.device}`)
  43. ])
  44. } },
  45. { prop: 'type', label: '类型', width: 100 },
  46. { prop: 'name', label: '名称', 'min-width': 100 },
  47. { prop: 'createBy', label: '发布人' },
  48. { prop: 'createTime', label: '发布时间' },
  49. { label: '状态', type: 'tag', render ({ status }) {
  50. if (status === State.CANCEL) {
  51. return {
  52. type: 'danger',
  53. label: '已下架'
  54. }
  55. }
  56. return {
  57. type: 'success',
  58. label: '正常'
  59. }
  60. } },
  61. { type: 'invoke', render: [
  62. { label: '下架', render: ({ status }) => status === State.RESOLVED, on: this.onCancel },
  63. { label: '查看', on: this.onView }
  64. ] }
  65. ]
  66. }
  67. }
  68. },
  69. methods: {
  70. transform (item) {
  71. const same = this.getSame(item)
  72. const diff = this.getDiff(item)
  73. return { ...same, ...diff }
  74. },
  75. getSame ({ id, status, programCalendarName, resolutionRatio, createBy, createByUsername, createTime, calendarReleaseDeviceList }) {
  76. return {
  77. id,
  78. status,
  79. name: programCalendarName,
  80. resolutionRatio,
  81. createBy: createByUsername || createBy,
  82. createTime,
  83. device: calendarReleaseDeviceList?.map(item => item.deviceName).join(',')
  84. }
  85. },
  86. getDiff (item) {
  87. const target = JSON.parse(item.target)
  88. let type = ''
  89. switch (target.type) {
  90. case PublishType.CALENDAR:
  91. type = '排期'
  92. break
  93. case PublishType.EVENT:
  94. type = ['', '默认播放', '单播', '插播'][target.detail.priority]
  95. break
  96. default:
  97. break
  98. }
  99. return {
  100. type,
  101. target,
  102. desc: this.getDesc(target)
  103. }
  104. },
  105. getDesc (target) {
  106. if (target.type === PublishType.EVENT && target.detail.priority === EventPriority.INSERTED) {
  107. return getEventDescription(target.detail)
  108. }
  109. return ''
  110. },
  111. onToggle (row) {
  112. this.$refs.table.getInst().toggleRowExpansion(row)
  113. },
  114. onView ({ target: { type, detail } }) {
  115. switch (type) {
  116. case PublishType.CALENDAR:
  117. this.viewSchedule(detail)
  118. break
  119. case PublishType.EVENT:
  120. if (detail.target.type === EventTarget.RECUR) {
  121. this.viewSchedule(detail.target.id)
  122. } else {
  123. this.$refs.programDialog.show(detail.target.id)
  124. }
  125. break
  126. default:
  127. break
  128. }
  129. },
  130. viewSchedule (id) {
  131. this.$refs.scheduleDialog.show(id)
  132. },
  133. onCancel (publishItem) {
  134. cancelPublish(publishItem.id, publishItem.name).then(() => {
  135. publishItem.status = State.CANCEL
  136. })
  137. }
  138. }
  139. }
  140. </script>