WarningDisposalTimeline.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div v-if="groups.length" class="warning-history">
  3. <div class="history-hint">按时间倒序分组,滚动即可回溯</div>
  4. <section v-for="group in groups" :key="group.day" class="history-group">
  5. <div class="history-day">{{ dayLabel(group.day) }}</div>
  6. <div
  7. v-for="(item, index) in group.items"
  8. :key="recordKey(item, index)"
  9. class="history-row"
  10. :class="{ 'last-record': index === group.items.length - 1 }"
  11. >
  12. <span class="history-time">{{ timeLabel(recordTime(item)) }}</span>
  13. <div class="history-body">
  14. <div class="history-title">
  15. <b>{{ recordUser(item) }}</b>
  16. <span class="history-separator">·</span>
  17. {{ typeLabel(item) }}
  18. </div>
  19. <div v-if="levelChange(item)" class="history-content">预警级别:{{ levelChange(item) }}</div>
  20. <div v-if="recordContent(item)" class="history-content">{{ recordContent(item) }}</div>
  21. <WarningDisposalReasons :record="item" />
  22. <WarningAttachments :attachments="attachmentsForDisposal(item, attachments)" image-thumbnails />
  23. </div>
  24. </div>
  25. </section>
  26. </div>
  27. <el-empty v-else :description="emptyText" />
  28. </template>
  29. <script setup>
  30. import { computed } from 'vue'
  31. import WarningAttachments from './WarningAttachments.vue'
  32. import WarningDisposalReasons from './WarningDisposalReasons.vue'
  33. import { attachmentsForDisposal } from '../warningAttachments'
  34. const props = defineProps({
  35. records: { type: Array, default: () => [] },
  36. attachments: { type: Array, default: () => [] },
  37. levelLabels: { type: Object, default: () => ({}) },
  38. emptyText: { type: String, default: '暂无处置记录' }
  39. })
  40. const typeLabels = {
  41. RELEASE: '发布预警',
  42. UPGRADE: '升级预警',
  43. RESOLVE: '解除预警',
  44. AUTO_CLEAR: '系统自动解除',
  45. CLEAR: '核查解除',
  46. RECEIVE: '接收预警',
  47. START: '开始处置',
  48. HANDLE: '提交处置结果',
  49. RETURN: '退回重办',
  50. SUPERVISION: '预警督办',
  51. INSTRUCTION: '领导批示'
  52. }
  53. const groups = computed(() => {
  54. const byDay = new Map()
  55. ;(props.records || []).forEach((item) => {
  56. const time = normalizeDate(recordTime(item))
  57. const day = time ? localDateKey(time) : '-'
  58. if (!byDay.has(day)) byDay.set(day, [])
  59. byDay.get(day).push(item)
  60. })
  61. return Array.from(byDay.entries())
  62. .sort(([left], [right]) => right.localeCompare(left))
  63. .map(([day, items]) => ({
  64. day,
  65. items: items.slice().sort((left, right) => timestamp(recordTime(right)) - timestamp(recordTime(left)))
  66. }))
  67. })
  68. function valueOf(item, camel, snake) {
  69. return item?.[camel] ?? item?.[snake]
  70. }
  71. function recordKey(item, index) {
  72. return valueOf(item, 'disposalId', 'disposal_id') || `${recordTime(item)}-${index}`
  73. }
  74. function recordTime(item) {
  75. return valueOf(item, 'createTime', 'create_time') || valueOf(item, 'disposalTime', 'disposal_time') || ''
  76. }
  77. function recordUser(item) {
  78. return valueOf(item, 'disposalUserName', 'disposal_user_name')
  79. || valueOf(item, 'disposalUser', 'disposal_user')
  80. || '-'
  81. }
  82. function recordContent(item) {
  83. return valueOf(item, 'disposalContent', 'disposal_content') || item?.content || ''
  84. }
  85. function typeLabel(item) {
  86. const type = valueOf(item, 'disposalType', 'disposal_type')
  87. return valueOf(item, 'disposalTypeName', 'disposal_type_name') || typeLabels[type] || type || '处置记录'
  88. }
  89. function levelChange(item) {
  90. const oldLevel = valueOf(item, 'oldLevel', 'old_level')
  91. const newLevel = valueOf(item, 'newLevel', 'new_level')
  92. if (oldLevel == null && newLevel == null) return ''
  93. const label = value => props.levelLabels[value] || value || '-'
  94. return `${label(oldLevel)} -> ${label(newLevel)}`
  95. }
  96. function normalizeDate(value) {
  97. if (!value) return null
  98. if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value
  99. const text = String(value).trim().replace(' ', 'T')
  100. const date = new Date(text)
  101. return Number.isNaN(date.getTime()) ? null : date
  102. }
  103. function timestamp(value) {
  104. return normalizeDate(value)?.getTime() || 0
  105. }
  106. function localDateKey(date) {
  107. const pad = value => String(value).padStart(2, '0')
  108. return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
  109. }
  110. function timeLabel(value) {
  111. const date = normalizeDate(value)
  112. if (!date) return '--:--'
  113. return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
  114. }
  115. function dayLabel(day) {
  116. if (day === '-') return '时间未知'
  117. const date = normalizeDate(`${day}T00:00:00`)
  118. if (!date) return day
  119. const today = new Date()
  120. const yesterday = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1)
  121. const prefix = day === localDateKey(today) ? '今天 · ' : day === localDateKey(yesterday) ? '昨天 · ' : ''
  122. const year = date.getFullYear() === today.getFullYear() ? '' : `${date.getFullYear()}年`
  123. return `${prefix}${year}${date.getMonth() + 1}月${date.getDate()}日`
  124. }
  125. </script>
  126. <style scoped>
  127. .history-hint {
  128. padding-bottom: 10px;
  129. margin-bottom: 14px;
  130. border-bottom: 1px solid #f0f2f4;
  131. color: #909399;
  132. font-size: 12px;
  133. }
  134. .history-day {
  135. margin: 16px 0 4px;
  136. color: #303133;
  137. font-size: 13px;
  138. font-weight: 500;
  139. }
  140. .history-row {
  141. display: flex;
  142. gap: 12px;
  143. padding: 8px 0 8px 4px;
  144. }
  145. .history-time {
  146. position: relative;
  147. box-sizing: border-box;
  148. width: 62px;
  149. flex: none;
  150. align-self: stretch;
  151. padding-top: 1px;
  152. padding-right: 22px;
  153. color: #909399;
  154. font-family: ui-monospace, Consolas, "Courier New", monospace;
  155. font-size: 12px;
  156. }
  157. .history-time::before {
  158. position: absolute;
  159. top: 5px;
  160. right: 8px;
  161. z-index: 1;
  162. width: 7px;
  163. height: 7px;
  164. border: 2px solid #fff;
  165. border-radius: 50%;
  166. background: #3b5bdb;
  167. box-shadow: 0 0 0 1px #9bb3d9;
  168. content: '';
  169. transform: translateX(50%);
  170. }
  171. .history-time::after {
  172. position: absolute;
  173. top: 10px;
  174. right: 8px;
  175. bottom: -27px;
  176. width: 1px;
  177. background: repeating-linear-gradient(to bottom, #3b5bdb 0 4px, transparent 4px 8px);
  178. content: '';
  179. transform: translateX(50%);
  180. }
  181. .last-record .history-time::after {
  182. display: none;
  183. }
  184. .history-body {
  185. min-width: 0;
  186. flex: 1;
  187. }
  188. .history-title {
  189. color: #303133;
  190. font-size: 13px;
  191. }
  192. .history-title b {
  193. font-weight: 700;
  194. }
  195. .history-separator {
  196. margin: 0 4px;
  197. color: #909399;
  198. }
  199. .history-content {
  200. margin-top: 3px;
  201. color: #606266;
  202. font-size: 12.5px;
  203. line-height: 1.6;
  204. white-space: pre-wrap;
  205. overflow-wrap: anywhere;
  206. }
  207. </style>