Compare commits

..
Author SHA1 Message Date
cykj 5ec997228d Merge pull request 'feat(qc): 修改记录同次提交合并节点并附件化展示 (#153)' (#154) from codex/issue-153-chg-group-fc14c4ae0ee7 into V2.0
continuous-integration/drone/tag Build is passing
feat(qc): 修改记录同次提交合并节点并附件化展示 (#153)\n\nMerge pull request #154
2026-11-20 05:25:22 +00:00
zlwu fb4bceb6b0 merge(V2.0): 同步集成分支后再合入 #153 2026-11-20 13:24:46 +08:00
zlwuandCursor cc17ac2425 feat(qc): 修改记录同次提交合并节点并附件化展示
批量保存写入 operateBatchId;弹窗按批次合并时间线,检测材料复用附件只读组件。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-20 13:23:26 +08:00
zlwuandCursor 70ebd4eff7 feat(web-admin): 市场侧栏新增器械销售菜单与施工中占位页
在市场模块末位注册器械销售目录及三类/二类医疗器械、化妆品子路由,同步后端静态菜单与 SQL 迁移写入 sys_menu 并向已有市场权限角色授权;子页面暂用统一施工中占位。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-20 13:17:02 +08:00
cykj 4d4856d4c2 Merge pull request 'fix(qc): 修改记录图标、空列表与弹窗尺寸 (#151)' (#152) from codex/issue-151-qc-hist-icon-7be0e4fa7247 into V2.0
fix(qc): 修改记录图标、空列表与弹窗尺寸 (#151)

Merge pull request #152
2026-11-20 03:57:14 +00:00
12 changed files with 612 additions and 29 deletions

No files matched your search

+50 -2
View File
@@ -7,7 +7,7 @@ from app.core.response import success_response
router = APIRouter(prefix="/web/menu", tags=["菜单管理"])
# 与 web-admin/src/router/modules/sqxp.ts 一致:6 个一级菜单分组
# 市场二级顺序:存储服务、科研捐赠、市场基础信息、中试服务、基础实验
# 市场二级顺序:存储服务、科研捐赠、市场基础信息、中试服务、基础实验、器械销售
STATIC_MENU_TREE = [
{
"id": "TOP00000000000000000000000000006",
@@ -375,7 +375,55 @@ STATIC_MENU_TREE = [
},
},
],
}
},
# 器械销售(市场侧栏末位)
{
"id": "DEV00000000000000000000000000001",
"name": "DeviceSales",
"path": "device-sales",
"component": "",
"meta": {
"title": "器械销售",
"icon": "ri:shopping-bag-3-line",
"keepAlive": False,
"roles": ["admin"],
},
"children": [
{
"id": "DEV00000000000000000000000000002",
"name": "DeviceSalesClassIii",
"path": "class-iii",
"component": "/device-sales/under-construction/index",
"meta": {
"title": "三类医疗器械",
"keepAlive": False,
"menuCode": "device-sales:class-iii:list",
},
},
{
"id": "DEV00000000000000000000000000003",
"name": "DeviceSalesClassIi",
"path": "class-ii",
"component": "/device-sales/under-construction/index",
"meta": {
"title": "二类医疗器械",
"keepAlive": False,
"menuCode": "device-sales:class-ii:list",
},
},
{
"id": "DEV00000000000000000000000000004",
"name": "DeviceSalesCosmetics",
"path": "cosmetics",
"component": "/device-sales/under-construction/index",
"meta": {
"title": "化妆品产品",
"keepAlive": False,
"menuCode": "device-sales:cosmetics:list",
},
},
],
},
],
},
+2
View File
@@ -449,6 +449,7 @@ class TaskCompleteWithResultBody(BaseModel):
third_party_attachments: Optional[str] = Field(None, alias="thirdPartyAttachments")
material_usages: Optional[List[Dict[str, Any]]] = Field(None, alias="materialUsages")
task_status: Optional[str] = Field(None, alias="taskStatus")
operate_batch_id: Optional[str] = Field(None, alias="operateBatchId")
@router.get("/qc-lab-test-items")
@@ -1438,6 +1439,7 @@ async def complete_task_with_result(
operator_user_name=str(user.get("nickName") or user.get("nick_name") or ""),
before=before,
after=after,
operate_batch_id=body.operate_batch_id,
)
db.commit()
db.refresh(obj)
@@ -144,12 +144,14 @@ def append_task_result_change_log(
before: Dict[str, Any],
after: Dict[str, Any],
operate_time: Optional[datetime] = None,
operate_batch_id: Optional[str] = None,
) -> BizQcTaskResultChangeLog:
"""追加一条检测结果保存留痕(不 commit)。无字段差异也写入。"""
now = operate_time or datetime.now()
changes = build_result_changes(before, after)
has_change = "1" if changes else "0"
name = _resolve_operator_name(db, user_id, operator_user_name)
batch_id = _norm_text(operate_batch_id) or None
obj = BizQcTaskResultChangeLog(
id=generate_uuid(),
task_id=task.id,
@@ -159,6 +161,7 @@ def append_task_result_change_log(
operate_time=now,
operator_user_id=user_id,
operator_user_name=name or None,
operate_batch_id=batch_id,
has_field_change=has_change,
changes_json=json.dumps(changes, ensure_ascii=False),
tenant_no=tenant_no,
@@ -194,6 +197,7 @@ def _row_to_dict(row: BizQcTaskResultChangeLog) -> Dict[str, Any]:
"operateTime": _fmt_dt(row.operate_time),
"operatorUserId": row.operator_user_id or "",
"operatorUserName": row.operator_user_name or "",
"operateBatchId": row.operate_batch_id or "",
"hasFieldChange": row.has_field_change == "1",
"changes": changes,
"createTime": _fmt_dt(row.create_time),
+1
View File
@@ -2407,6 +2407,7 @@ class BizQcTaskResultChangeLog(Base):
operate_time = Column(DateTime, nullable=False, comment="业务操作时间")
operator_user_id = Column(String(64), nullable=True, comment="操作人用户ID")
operator_user_name = Column(String(64), nullable=True, comment="操作人姓名快照")
operate_batch_id = Column(String(64), nullable=True, comment="同一次保存批次ID(多任务共用)")
has_field_change = Column(CHAR(1), nullable=False, default="0", comment="1有字段变更 0仅保存无变更")
changes_json = Column(Text, nullable=True, comment="变更明细JSON")
tenant_no = Column(String(64), nullable=False, default="zkxw", comment="租户编号")
@@ -0,0 +1,164 @@
-- 市场模块新增「器械销售」及三个子菜单;授权给已有 menu:market 的角色。
-- 不新建角色/用户;用户经现有 sys_user_role 自动带上菜单。
-- MySQL 5.7,可重复执行。目标库:测试库(如 zkxw-sc)。
-- 1) 二级目录:器械销售(挂在市场下,order_num=6 末位)
INSERT INTO sys_menu (
id, menu_name, parent_id, menu_type, path, component, perms,
is_frame, visible, status, tenant_no, order_num, remark,
create_by, create_dept_id, create_time, update_by, update_time, del_flag
)
SELECT
'DEV00000000000000000000000000001',
'器械销售',
m.id,
'M',
'device-sales',
NULL,
'menu:device-sales',
1, '1', '1', m.tenant_no, 6,
'市场-器械销售',
'migration', '', NOW(), 'migration', NOW(), 0
FROM sys_menu m
WHERE m.del_flag = 0 AND m.perms = 'menu:market'
AND NOT EXISTS (
SELECT 1 FROM sys_menu e
WHERE e.id = 'DEV00000000000000000000000000001' AND e.del_flag = 0
);
-- 2) 子菜单:三类 / 二类 / 化妆品
INSERT INTO sys_menu (
id, menu_name, parent_id, menu_type, path, component, perms,
is_frame, visible, status, tenant_no, order_num, remark,
create_by, create_dept_id, create_time, update_by, update_time, del_flag
)
SELECT
x.id, x.menu_name, 'DEV00000000000000000000000000001', 'C', x.path,
'device-sales/under-construction/index', x.perms,
1, '1', '1', p.tenant_no, x.order_num, x.remark,
'migration', '', NOW(), 'migration', NOW(), 0
FROM sys_menu p
JOIN (
SELECT 'DEV00000000000000000000000000002' AS id, '三类医疗器械' AS menu_name,
'class-iii' AS path, 'device-sales:class-iii:list' AS perms, 1 AS order_num,
'市场-器械销售-三类医疗器械' AS remark
UNION ALL
SELECT 'DEV00000000000000000000000000003', '二类医疗器械',
'class-ii', 'device-sales:class-ii:list', 2,
'市场-器械销售-二类医疗器械'
UNION ALL
SELECT 'DEV00000000000000000000000000004', '化妆品产品',
'cosmetics', 'device-sales:cosmetics:list', 3,
'市场-器械销售-化妆品产品'
) x ON 1 = 1
WHERE p.del_flag = 0 AND p.id = 'DEV00000000000000000000000000001'
AND NOT EXISTS (
SELECT 1 FROM sys_menu e WHERE e.id = x.id AND e.del_flag = 0
);
-- 3) 给已有「市场」顶级菜单授权的角色,授予器械销售目录+三个子菜单
-- (含祖先目录,满足选中子菜单须含祖先)
INSERT INTO sys_role_menu (
id, role_id, menu_id, tenant_no, order_num, remark,
create_by, create_dept_id, create_time, update_by, update_time, del_flag
)
SELECT
INSERT(INSERT(MD5(CONCAT('device-sales-rm:', r.tenant_no, ':', r.id, ':', m.id)), 13, 1, '3'), 17, 1, '8'),
r.id, m.id, r.tenant_no, NULL,
'grant device-sales from menu:market',
'migration', '', NOW(), 'migration', NOW(), 0
FROM sys_role r
JOIN sys_role_menu src
ON src.role_id = r.id AND src.tenant_no = r.tenant_no AND src.del_flag = 0
JOIN sys_menu top
ON top.id = src.menu_id AND top.tenant_no = src.tenant_no AND top.del_flag = 0
AND top.perms = 'menu:market'
JOIN sys_menu m
ON m.tenant_no = r.tenant_no AND m.del_flag = 0 AND m.status = '1'
AND m.id IN (
'DEV00000000000000000000000000001',
'DEV00000000000000000000000000002',
'DEV00000000000000000000000000003',
'DEV00000000000000000000000000004'
)
WHERE r.del_flag = 0
AND NOT EXISTS (
SELECT 1 FROM sys_role_menu existing
WHERE existing.role_id = r.id
AND existing.menu_id = m.id
AND existing.tenant_no = r.tenant_no
AND existing.del_flag = 0
);
-- 3b) 超级管理员同步授予(角色管理勾选与超管侧栏数据一致)
INSERT INTO sys_role_menu (
id, role_id, menu_id, tenant_no, order_num, remark,
create_by, create_dept_id, create_time, update_by, update_time, del_flag
)
SELECT
INSERT(INSERT(MD5(CONCAT('device-sales-sa:', r.tenant_no, ':', r.id, ':', m.id)), 13, 1, '3'), 17, 1, '8'),
r.id, m.id, r.tenant_no, NULL,
'grant device-sales to super admin',
'migration', '', NOW(), 'migration', NOW(), 0
FROM sys_role r
JOIN sys_menu m
ON m.del_flag = 0 AND m.status = '1'
AND m.id IN (
'DEV00000000000000000000000000001',
'DEV00000000000000000000000000002',
'DEV00000000000000000000000000003',
'DEV00000000000000000000000000004'
)
WHERE r.del_flag = 0 AND r.role_name = '超级管理员'
AND NOT EXISTS (
SELECT 1 FROM sys_role_menu existing
WHERE existing.role_id = r.id
AND existing.menu_id = m.id
AND existing.tenant_no = r.tenant_no
AND existing.del_flag = 0
);
-- 3c) 恢复已挂到上述角色、但被软删的用户-角色关联(打通 用户→角色→菜单)
UPDATE sys_user_role ur
JOIN sys_role r ON r.id = ur.role_id AND r.del_flag = 0
JOIN sys_role_menu rm
ON rm.role_id = r.id AND rm.del_flag = 0
AND rm.menu_id = 'DEV00000000000000000000000000001'
JOIN sys_user u ON u.id = ur.user_id AND u.del_flag = 0
SET ur.del_flag = 0,
ur.update_by = 'migration',
ur.update_time = NOW()
WHERE ur.del_flag = 1;
-- 4) 核对
SELECT id, menu_name, parent_id, path, perms, order_num, visible, del_flag
FROM sys_menu
WHERE id LIKE 'DEV0000000000000000000000000000%'
ORDER BY order_num, menu_name;
SELECT COUNT(DISTINCT rm.role_id) AS roles_granted,
COUNT(*) AS role_menu_rows
FROM sys_role_menu rm
WHERE rm.del_flag = 0
AND rm.menu_id IN (
'DEV00000000000000000000000000001',
'DEV00000000000000000000000000002',
'DEV00000000000000000000000000003',
'DEV00000000000000000000000000004'
);
-- 抽样:有市场权限的用户是否能通过角色落到器械销售菜单
SELECT u.nick_name, u.phone_no, r.role_name, m.menu_name, m.perms
FROM sys_user u
JOIN sys_user_role ur ON ur.user_id = u.id AND ur.del_flag = 0
JOIN sys_role r ON r.id = ur.role_id AND r.del_flag = 0
JOIN sys_role_menu rm ON rm.role_id = r.id AND rm.del_flag = 0
JOIN sys_menu m ON m.id = rm.menu_id AND m.del_flag = 0
WHERE u.del_flag = 0
AND m.id IN (
'DEV00000000000000000000000000002',
'DEV00000000000000000000000000003',
'DEV00000000000000000000000000004'
)
ORDER BY u.nick_name, m.order_num
LIMIT 30;
@@ -0,0 +1,8 @@
-- 质检检测结果留痕:同一次批量保存共用 operate_batch_id(Issue #153)
-- 历史行可为空;前端对无批次号的旧数据做短时窗口合并兜底。
ALTER TABLE `biz_qc_task_result_change_log`
ADD COLUMN `operate_batch_id` varchar(64) DEFAULT NULL COMMENT '同一次保存批次ID(多任务共用)' AFTER `operator_user_name`;
ALTER TABLE `biz_qc_task_result_change_log`
ADD KEY `idx_qc_result_chg_batch` (`tenant_no`, `operate_batch_id`, `del_flag`);
+2
View File
@@ -51,6 +51,7 @@ export function fetchCompleteTaskWithResult(
remark?: string
thirdPartyAttachments?: string
taskStatus?: 'dzx' | 'jxz' | 'ywc'
operateBatchId?: string
materialUsages?: Array<{
requisitionUsageId: string
qty: number
@@ -83,6 +84,7 @@ export type QcTaskResultChangeLog = {
operateTime: string
operatorUserId?: string
operatorUserName?: string
operateBatchId?: string
hasFieldChange: boolean
changes: QcTaskResultChangeItem[]
createTime?: string
Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

+51 -2
View File
@@ -60,8 +60,8 @@ export const sqxpAdminRoutes: AppRouteRecord[] = [
},
// ═══════════════════════════════════════════════════════════════════════════
// 1. 市场 (menu:market)
// 二级菜单:存储服务、科研捐赠、市场基础信息、中试服务、基础实验
// (主推存储/捐赠在前;中试/基础实验及关联基础信息后置)
// 二级菜单:存储服务、科研捐赠、市场基础信息、中试服务、基础实验、器械销售
// (主推存储/捐赠在前;中试/基础实验及关联基础信息后置;器械销售在末位)
// ═══════════════════════════════════════════════════════════════════════════
{
id: 'TOP00000000000000000000000000001',
@@ -669,6 +669,55 @@ export const sqxpAdminRoutes: AppRouteRecord[] = [
props: { bizType: 'basic_experiment' }
}
]
},
// ── 器械销售(市场侧栏末位;占位页待完善)────────────────────────────
{
id: 'DEV00000000000000000000000000001',
name: 'DeviceSales',
path: 'device-sales',
component: '',
meta: {
title: '器械销售',
icon: 'ri:shopping-bag-3-line',
keepAlive: false,
roles: ['admin']
},
children: [
{
id: 'DEV00000000000000000000000000002',
name: 'DeviceSalesClassIii',
path: 'class-iii',
component: '/device-sales/under-construction/index',
meta: {
title: '三类医疗器械',
keepAlive: false,
menuCode: 'device-sales:class-iii:list'
}
},
{
id: 'DEV00000000000000000000000000003',
name: 'DeviceSalesClassIi',
path: 'class-ii',
component: '/device-sales/under-construction/index',
meta: {
title: '二类医疗器械',
keepAlive: false,
menuCode: 'device-sales:class-ii:list'
}
},
{
id: 'DEV00000000000000000000000000004',
name: 'DeviceSalesCosmetics',
path: 'cosmetics',
component: '/device-sales/under-construction/index',
meta: {
title: '化妆品产品',
keepAlive: false,
menuCode: 'device-sales:cosmetics:list'
}
}
]
}
]
},
@@ -0,0 +1,63 @@
<!-- 器械销售占位页:施工中 -->
<template>
<div class="page-container under-construction-page">
<section class="panel under-construction-panel">
<img
class="under-construction-img"
src="@/assets/images/common/under-construction.jpg"
alt="正在施工"
/>
<p class="under-construction-title">{{ pageTitle }}</p>
<p class="under-construction-hint">待完善</p>
</section>
</div>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { useRoute } from 'vue-router'
defineOptions({ name: 'DeviceSalesUnderConstruction' })
const route = useRoute()
const pageTitle = computed(() => String(route.meta?.title || '器械销售'))
</script>
<style scoped lang="scss">
.under-construction-page {
min-height: calc(100vh - 140px);
display: flex;
}
.under-construction-panel {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
padding: 48px 24px;
text-align: center;
}
.under-construction-img {
width: min(420px, 70vw);
max-height: 280px;
object-fit: contain;
border-radius: 12px;
}
.under-construction-title {
margin: 8px 0 0;
font-size: 16px;
font-weight: 600;
color: #111827;
}
.under-construction-hint {
margin: 0;
font-size: 18px;
font-weight: 600;
color: #10b981;
}
</style>
@@ -380,6 +380,11 @@
const thirdPartyAttachments = financeAttachmentsToUrlString(attachments.value)
const remarkVal = remark.value
// 同一次批量保存共用批次号,修改记录弹窗合并为一个时间线节点
const operateBatchId =
typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function'
? crypto.randomUUID().replace(/-/g, '').toUpperCase()
: `BATCH${Date.now()}${Math.random().toString(16).slice(2, 10)}`.toUpperCase()
saving.value = true
const failures: string[] = []
let successCount = 0
@@ -399,7 +404,8 @@
})),
remark: remarkVal,
thirdPartyAttachments,
taskStatus: item.saveStatus
taskStatus: item.saveStatus,
operateBatchId
},
props.operateScope
)
@@ -14,39 +14,112 @@
>
<DialogFormBody :loading="loading" body-class="qc-result-chg-body">
<el-empty
v-if="!loading && !entries.length"
v-if="!loading && !timelineNodes.length"
description="暂无修改记录"
:image-size="72"
/>
<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
v-for="(node, idx) in timelineNodes"
:key="node.key"
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" />
<span v-if="idx < timelineNodes.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 }}
{{ node.operateTime || '—' }} · {{ node.operatorUserName || '—' }}
<template v-if="node.entries.length > 1">
· 共 {{ node.entries.length }} 项
</template>
</div>
<template v-if="entry.hasFieldChange && entry.changes?.length">
<div v-if="node.sharedAttachment" class="qc-result-chg-tl__change">
<div class="qc-result-chg-tl__line-text">
{{ node.sharedAttachment.fieldLabel }}:
<template
v-if="
node.sharedAttachment.oldValue &&
node.sharedAttachment.oldValue !== node.sharedAttachment.newValue
"
>
已更新
</template>
<template v-else-if="!node.sharedAttachment.newValue">已清空</template>
</div>
<ProtocolAttachmentReadonly
v-if="attachmentFilesFromValue(node.sharedAttachment.newValue).length"
size="compact"
:files="attachmentFilesFromValue(node.sharedAttachment.newValue)"
@preview="onAttachmentPreview"
@download="onAttachmentDownload"
/>
<span
v-else-if="!node.sharedAttachment.newValue"
class="qc-result-chg-tl__line-text"
>—</span>
</div>
<div
v-for="entry in node.entries"
:key="entry.id"
class="qc-result-chg-tl__entry"
>
<div
v-for="(chg, cIdx) in entry.changes"
:key="`${entry.id}-${cIdx}`"
v-if="showItemName && entry.itemName"
class="qc-result-chg-tl__item-name"
>
{{ entry.itemName }}
</div>
<template v-if="visibleChanges(entry, node).length">
<div
v-for="(chg, cIdx) in visibleChanges(entry, node)"
:key="`${entry.id}-${cIdx}`"
class="qc-result-chg-tl__change"
>
<template v-if="isAttachmentChange(chg)">
<div class="qc-result-chg-tl__line-text">
{{ chg.fieldLabel }}:
<template v-if="chg.oldValue && chg.oldValue !== chg.newValue">
已更新
</template>
<template v-else-if="!chg.newValue">已清空</template>
</div>
<ProtocolAttachmentReadonly
v-if="attachmentFilesFromValue(chg.newValue).length"
size="compact"
:files="attachmentFilesFromValue(chg.newValue)"
@preview="onAttachmentPreview"
@download="onAttachmentDownload"
/>
<span
v-else-if="!chg.newValue"
class="qc-result-chg-tl__line-text"
>—</span>
</template>
<div v-else 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>
</div>
</template>
<div
v-else-if="!entry.hasFieldChange || !entry.changes?.length"
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 v-if="node.allNoFieldChange" class="qc-result-chg-tl__note">
即使未改值,点击保存也会记一条操作留痕
</div>
</div>
@@ -66,13 +139,33 @@
import { ElMessage } from 'element-plus'
import { Close } from '@element-plus/icons-vue'
import DialogFormBody from '@/components/business/dialog-form-body/index.vue'
import ProtocolAttachmentReadonly from '@/views/cell-storage/protocol/ProtocolAttachmentReadonly.vue'
import { downloadAttachmentFile } from '@/utils/download-attachment'
import {
qcAttachmentFullUrl,
qcPreviewAttachment
} from './composables/useQcViewAttachmentHelpers'
import {
fetchQcTaskResultChangeLogsBatch,
type QcTaskResultChangeItem,
type QcTaskResultChangeLog
} from '@/api/qc-task-result'
defineOptions({ name: 'QcTaskResultChangeLogDialog' })
type TimelineNode = {
key: string
operateTime: string
operatorUserName: string
entries: QcTaskResultChangeLog[]
allNoFieldChange: boolean
/** 多任务同次提交且检测材料一致时,提到节点级只展示一次 */
sharedAttachment: QcTaskResultChangeItem | null
}
/** 无批次号的旧数据:同操作人且时间差 ≤15s 合并为一次提交 */
const LEGACY_GROUP_WINDOW_MS = 15_000
const props = withDefaults(
defineProps<{
visible: boolean
@@ -99,6 +192,8 @@
return suffix ? `修改记录 · ${suffix}` : '修改记录'
})
const timelineNodes = computed(() => groupChangeLogs(entries.value))
function onVisibleChange(v: boolean) {
emit('update:visible', v)
}
@@ -107,16 +202,138 @@
emit('update:visible', false)
}
function isAttachmentChange(chg: QcTaskResultChangeItem) {
return (chg.fieldKey || '') === 'attachments'
}
function pickSharedAttachment(rows: QcTaskResultChangeLog[]) {
if (rows.length < 2) return null
const attChanges = rows
.map((r) => (r.changes || []).find((c) => isAttachmentChange(c)))
.filter(Boolean) as QcTaskResultChangeItem[]
if (!attChanges.length || attChanges.length !== rows.length) return null
const first = attChanges[0]
const same = attChanges.every(
(c) => c.newValue === first.newValue && c.oldValue === first.oldValue
)
return same ? first : null
}
function visibleChanges(entry: QcTaskResultChangeLog, node: TimelineNode) {
const list = entry.changes || []
if (!node.sharedAttachment) return list
return list.filter((c) => !isAttachmentChange(c))
}
function attachmentFilesFromValue(raw: string | undefined) {
const text = String(raw || '').trim()
if (!text) return [] as Array<Record<string, unknown>>
return text
.split(',')
.map((u, i) => {
const url = u.trim()
if (!url) return null
const name = url.includes('/') ? url.split('/').pop() || `附件${i + 1}` : url
return {
id: `chg_att_${i}_${name}`,
fileUrl: url,
fileName: name
}
})
.filter(Boolean) as Array<Record<string, unknown>>
}
function onAttachmentPreview(file: Record<string, unknown>) {
qcPreviewAttachment(file)
}
function onAttachmentDownload(file: Record<string, unknown>) {
downloadAttachmentFile(file, { fullFileUrl: qcAttachmentFullUrl })
}
function parseOperateTimeMs(text: string | undefined) {
const s = String(text || '').trim()
if (!s) return NaN
const t = Date.parse(s.replace(/-/g, '/'))
return Number.isFinite(t) ? t : NaN
}
function groupChangeLogs(list: QcTaskResultChangeLog[]): TimelineNode[] {
const sorted = [...(list || [])].sort((a, b) => {
const tb = parseOperateTimeMs(b.operateTime)
const ta = parseOperateTimeMs(a.operateTime)
if (Number.isFinite(tb) && Number.isFinite(ta) && tb !== ta) return tb - ta
return String(b.id || '').localeCompare(String(a.id || ''))
})
const batchBuckets = new Map<string, QcTaskResultChangeLog[]>()
const orphans: QcTaskResultChangeLog[] = []
for (const row of sorted) {
const batch = String(row.operateBatchId || '').trim()
if (batch) {
const arr = batchBuckets.get(batch) || []
arr.push(row)
batchBuckets.set(batch, arr)
} else {
orphans.push(row)
}
}
const nodes: TimelineNode[] = []
for (const [batch, rows] of batchBuckets) {
nodes.push(toNode(`batch:${batch}`, rows))
}
// 旧数据兜底:按时间序贪心合并同操作人短窗口
const used = new Set<string>()
for (let i = 0; i < orphans.length; i++) {
const head = orphans[i]
if (used.has(head.id)) continue
const group = [head]
used.add(head.id)
const headTs = parseOperateTimeMs(head.operateTime)
const headOp = String(head.operatorUserId || head.operatorUserName || '')
for (let j = i + 1; j < orphans.length; j++) {
const cur = orphans[j]
if (used.has(cur.id)) continue
const curOp = String(cur.operatorUserId || cur.operatorUserName || '')
if (curOp !== headOp) continue
const curTs = parseOperateTimeMs(cur.operateTime)
if (!Number.isFinite(headTs) || !Number.isFinite(curTs)) continue
if (Math.abs(curTs - headTs) > LEGACY_GROUP_WINDOW_MS) continue
group.push(cur)
used.add(cur.id)
}
nodes.push(toNode(`legacy:${head.id}`, group))
}
return nodes.sort((a, b) => {
const tb = parseOperateTimeMs(b.operateTime)
const ta = parseOperateTimeMs(a.operateTime)
if (Number.isFinite(tb) && Number.isFinite(ta) && tb !== ta) return tb - ta
return a.key.localeCompare(b.key)
})
}
function toNode(key: string, rows: QcTaskResultChangeLog[]): TimelineNode {
const first = rows[0]
return {
key,
operateTime: first?.operateTime || '',
operatorUserName: first?.operatorUserName || '',
entries: rows,
allNoFieldChange: rows.every((r) => !r.hasFieldChange),
sharedAttachment: pickSharedAttachment(rows)
}
}
async function loadLogs() {
const seq = ++loadSeq
const ids = (props.taskIds || []).map((x) => (x || '').trim()).filter(Boolean)
loading.value = true
entries.value = []
try {
// 多任务统一走批量接口,避免路径被 /qc-tasks/{id} 误匹配
const list = ids.length
? await fetchQcTaskResultChangeLogsBatch(ids)
: []
const list = ids.length ? await fetchQcTaskResultChangeLogsBatch(ids) : []
if (seq !== loadSeq) return
entries.value = Array.isArray(list) ? list : []
} catch {
@@ -191,7 +408,26 @@
font-size: 12px;
font-weight: 600;
color: var(--mint-primary-dark, #059669);
margin-bottom: 6px;
margin-bottom: 8px;
}
.qc-result-chg-tl__entry {
margin-bottom: 10px;
&:last-child {
margin-bottom: 0;
}
}
.qc-result-chg-tl__item-name {
font-size: 13px;
font-weight: 600;
color: var(--mint-text, #1e293b);
margin-bottom: 4px;
}
.qc-result-chg-tl__change {
margin: 4px 0;
}
.qc-result-chg-tl__line-text {
@@ -202,7 +438,7 @@
}
.qc-result-chg-tl__note {
margin-top: 4px;
margin-top: 6px;
font-size: 12px;
color: var(--mint-text-muted, #334155);
}