Files
zkxw/web-admin/src/views/quality-inspection/qc-work-order/QcTaskResultChangeLogDialog.vue
T
zlwuandCursor 9b6228860f feat(qc): 检测结果默认已完成/通过并记录修改历史
填写弹窗未落结论时默认任务状态已完成、结论通过(实验室与第三方);
每次保存追加操作留痕,卡片可查看修改时间线。关联 #148 #149。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-20 11:34:18 +08:00

206 lines
5.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- 质检任务 · 检测结果修改记录 -->
<template>
<el-dialog
:model-value="visible"
:title="dialogTitle"
width="560px"
class="dialog-form-layout qc-task-result-change-log-dialog"
align-center
modal-class="protocol-dialog-mask"
append-to-body
destroy-on-close
:close-on-click-modal="false"
@update:model-value="onVisibleChange"
>
<DialogFormBody :loading="loading">
<el-empty
v-if="!loading && !entries.length"
description="暂无修改记录"
:image-size="56"
/>
<div v-else class="qc-result-chg-tl">
<div v-for="(entry, idx) in entries" :key="entry.id" class="qc-result-chg-tl__item">
<div class="qc-result-chg-tl__rail">
<span class="qc-result-chg-tl__dot" />
<span v-if="idx < entries.length - 1" class="qc-result-chg-tl__line" />
</div>
<div class="qc-result-chg-tl__content">
<div class="qc-result-chg-tl__meta">
{{ entry.operateTime || '—' }} · {{ entry.operatorUserName || '—' }}
<template v-if="showItemName && entry.itemName">
· {{ entry.itemName }}
</template>
</div>
<template v-if="entry.hasFieldChange && entry.changes?.length">
<div
v-for="(chg, cIdx) in entry.changes"
:key="`${entry.id}-${cIdx}`"
class="qc-result-chg-tl__line-text"
>
<template v-if="chg.oldValue">
{{ chg.fieldLabel }}:{{ chg.oldValue || '—' }} → {{ chg.newValue || '—' }}
</template>
<template v-else>
{{ chg.fieldLabel }}:{{ chg.newValue || '—' }}
</template>
</div>
</template>
<div v-else class="qc-result-chg-tl__line-text">保存操作(字段无变更)</div>
<div v-if="!entry.hasFieldChange" class="qc-result-chg-tl__note">
即使未改值,点击保存也会记一条操作留痕
</div>
</div>
</div>
</div>
</DialogFormBody>
<template #footer>
<el-button class="btn-ghost" @click="close">
<el-icon><Close /></el-icon>关闭
</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { Close } from '@element-plus/icons-vue'
import DialogFormBody from '@/components/business/dialog-form-body/index.vue'
import {
fetchQcTaskResultChangeLogs,
fetchQcTaskResultChangeLogsBatch,
type QcTaskResultChangeLog
} from '@/api/qc-task-result'
defineOptions({ name: 'QcTaskResultChangeLogDialog' })
const props = withDefaults(
defineProps<{
visible: boolean
taskIds: string[]
titleSuffix?: string
}>(),
{
titleSuffix: ''
}
)
const emit = defineEmits<{
'update:visible': [value: boolean]
}>()
const loading = ref(false)
const entries = ref<QcTaskResultChangeLog[]>([])
let loadSeq = 0
const showItemName = computed(() => (props.taskIds || []).length > 1)
const dialogTitle = computed(() => {
const suffix = (props.titleSuffix || '').trim()
return suffix ? `修改记录 · ${suffix}` : '修改记录'
})
function onVisibleChange(v: boolean) {
emit('update:visible', v)
}
function close() {
emit('update:visible', false)
}
async function loadLogs() {
const seq = ++loadSeq
const ids = (props.taskIds || []).map((x) => (x || '').trim()).filter(Boolean)
loading.value = true
entries.value = []
try {
const list =
ids.length > 1
? await fetchQcTaskResultChangeLogsBatch(ids)
: ids.length === 1
? await fetchQcTaskResultChangeLogs(ids[0])
: []
if (seq !== loadSeq) return
entries.value = list || []
} catch {
if (seq !== loadSeq) return
entries.value = []
ElMessage.error('加载修改记录失败')
} finally {
if (seq === loadSeq) loading.value = false
}
}
watch(
() => [props.visible, (props.taskIds || []).join(',')] as const,
([vis]) => {
if (vis) void loadLogs()
}
)
</script>
<style scoped lang="scss">
.qc-result-chg-tl {
display: flex;
flex-direction: column;
gap: 4px;
padding: 4px 0 8px;
}
.qc-result-chg-tl__item {
display: flex;
gap: 12px;
}
.qc-result-chg-tl__rail {
display: flex;
flex-direction: column;
align-items: center;
width: 12px;
flex-shrink: 0;
}
.qc-result-chg-tl__dot {
width: 10px;
height: 10px;
margin-top: 4px;
border-radius: 50%;
background: var(--mint-primary, #10b981);
flex-shrink: 0;
}
.qc-result-chg-tl__line {
width: 2px;
flex: 1;
min-height: 36px;
margin-top: 4px;
background: var(--mint-primary-bg, #ecfdf5);
}
.qc-result-chg-tl__content {
flex: 1;
min-width: 0;
padding-bottom: 14px;
}
.qc-result-chg-tl__meta {
font-size: 12px;
font-weight: 600;
color: var(--mint-primary-dark, #059669);
margin-bottom: 6px;
}
.qc-result-chg-tl__line-text {
font-size: 13px;
color: var(--mint-text, #1e293b);
margin: 2px 0;
word-break: break-word;
}
.qc-result-chg-tl__note {
margin-top: 4px;
font-size: 12px;
color: var(--mint-text-muted, #334155);
}
</style>