| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <template>
- <div v-if="groups.length" class="warning-history">
- <div class="history-hint">按时间倒序分组,滚动即可回溯</div>
- <section v-for="group in groups" :key="group.day" class="history-group">
- <div class="history-day">{{ dayLabel(group.day) }}</div>
- <div
- v-for="(item, index) in group.items"
- :key="recordKey(item, index)"
- class="history-row"
- :class="{ 'last-record': index === group.items.length - 1 }"
- >
- <span class="history-time">{{ timeLabel(recordTime(item)) }}</span>
- <div class="history-body">
- <div class="history-title">
- <b>{{ recordUser(item) }}</b>
- <span class="history-separator">·</span>
- {{ typeLabel(item) }}
- </div>
- <div v-if="levelChange(item)" class="history-content">预警级别:{{ levelChange(item) }}</div>
- <div v-if="recordContent(item)" class="history-content">{{ recordContent(item) }}</div>
- <WarningDisposalReasons :record="item" />
- <WarningAttachments :attachments="attachmentsForDisposal(item, attachments)" image-thumbnails />
- </div>
- </div>
- </section>
- </div>
- <el-empty v-else :description="emptyText" />
- </template>
- <script setup>
- import { computed } from 'vue'
- import WarningAttachments from './WarningAttachments.vue'
- import WarningDisposalReasons from './WarningDisposalReasons.vue'
- import { attachmentsForDisposal } from '../warningAttachments'
- const props = defineProps({
- records: { type: Array, default: () => [] },
- attachments: { type: Array, default: () => [] },
- levelLabels: { type: Object, default: () => ({}) },
- emptyText: { type: String, default: '暂无处置记录' }
- })
- const typeLabels = {
- RELEASE: '发布预警',
- UPGRADE: '升级预警',
- RESOLVE: '解除预警',
- AUTO_CLEAR: '系统自动解除',
- CLEAR: '核查解除',
- RECEIVE: '接收预警',
- START: '开始处置',
- HANDLE: '提交处置结果',
- RETURN: '退回重办',
- SUPERVISION: '预警督办',
- INSTRUCTION: '领导批示'
- }
- const groups = computed(() => {
- const byDay = new Map()
- ;(props.records || []).forEach((item) => {
- const time = normalizeDate(recordTime(item))
- const day = time ? localDateKey(time) : '-'
- if (!byDay.has(day)) byDay.set(day, [])
- byDay.get(day).push(item)
- })
- return Array.from(byDay.entries())
- .sort(([left], [right]) => right.localeCompare(left))
- .map(([day, items]) => ({
- day,
- items: items.slice().sort((left, right) => timestamp(recordTime(right)) - timestamp(recordTime(left)))
- }))
- })
- function valueOf(item, camel, snake) {
- return item?.[camel] ?? item?.[snake]
- }
- function recordKey(item, index) {
- return valueOf(item, 'disposalId', 'disposal_id') || `${recordTime(item)}-${index}`
- }
- function recordTime(item) {
- return valueOf(item, 'createTime', 'create_time') || valueOf(item, 'disposalTime', 'disposal_time') || ''
- }
- function recordUser(item) {
- return valueOf(item, 'disposalUserName', 'disposal_user_name')
- || valueOf(item, 'disposalUser', 'disposal_user')
- || '-'
- }
- function recordContent(item) {
- return valueOf(item, 'disposalContent', 'disposal_content') || item?.content || ''
- }
- function typeLabel(item) {
- const type = valueOf(item, 'disposalType', 'disposal_type')
- return valueOf(item, 'disposalTypeName', 'disposal_type_name') || typeLabels[type] || type || '处置记录'
- }
- function levelChange(item) {
- const oldLevel = valueOf(item, 'oldLevel', 'old_level')
- const newLevel = valueOf(item, 'newLevel', 'new_level')
- if (oldLevel == null && newLevel == null) return ''
- const label = value => props.levelLabels[value] || value || '-'
- return `${label(oldLevel)} -> ${label(newLevel)}`
- }
- function normalizeDate(value) {
- if (!value) return null
- if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value
- const text = String(value).trim().replace(' ', 'T')
- const date = new Date(text)
- return Number.isNaN(date.getTime()) ? null : date
- }
- function timestamp(value) {
- return normalizeDate(value)?.getTime() || 0
- }
- function localDateKey(date) {
- const pad = value => String(value).padStart(2, '0')
- return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
- }
- function timeLabel(value) {
- const date = normalizeDate(value)
- if (!date) return '--:--'
- return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
- }
- function dayLabel(day) {
- if (day === '-') return '时间未知'
- const date = normalizeDate(`${day}T00:00:00`)
- if (!date) return day
- const today = new Date()
- const yesterday = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1)
- const prefix = day === localDateKey(today) ? '今天 · ' : day === localDateKey(yesterday) ? '昨天 · ' : ''
- const year = date.getFullYear() === today.getFullYear() ? '' : `${date.getFullYear()}年`
- return `${prefix}${year}${date.getMonth() + 1}月${date.getDate()}日`
- }
- </script>
- <style scoped>
- .history-hint {
- padding-bottom: 10px;
- margin-bottom: 14px;
- border-bottom: 1px solid #f0f2f4;
- color: #909399;
- font-size: 12px;
- }
- .history-day {
- margin: 16px 0 4px;
- color: #303133;
- font-size: 13px;
- font-weight: 500;
- }
- .history-row {
- display: flex;
- gap: 12px;
- padding: 8px 0 8px 4px;
- }
- .history-time {
- position: relative;
- box-sizing: border-box;
- width: 62px;
- flex: none;
- align-self: stretch;
- padding-top: 1px;
- padding-right: 22px;
- color: #909399;
- font-family: ui-monospace, Consolas, "Courier New", monospace;
- font-size: 12px;
- }
- .history-time::before {
- position: absolute;
- top: 5px;
- right: 8px;
- z-index: 1;
- width: 7px;
- height: 7px;
- border: 2px solid #fff;
- border-radius: 50%;
- background: #3b5bdb;
- box-shadow: 0 0 0 1px #9bb3d9;
- content: '';
- transform: translateX(50%);
- }
- .history-time::after {
- position: absolute;
- top: 10px;
- right: 8px;
- bottom: -27px;
- width: 1px;
- background: repeating-linear-gradient(to bottom, #3b5bdb 0 4px, transparent 4px 8px);
- content: '';
- transform: translateX(50%);
- }
- .last-record .history-time::after {
- display: none;
- }
- .history-body {
- min-width: 0;
- flex: 1;
- }
- .history-title {
- color: #303133;
- font-size: 13px;
- }
- .history-title b {
- font-weight: 700;
- }
- .history-separator {
- margin: 0 4px;
- color: #909399;
- }
- .history-content {
- margin-top: 3px;
- color: #606266;
- font-size: 12.5px;
- line-height: 1.6;
- white-space: pre-wrap;
- overflow-wrap: anywhere;
- }
- </style>
|