Commit 36f81cbd by chenwq1

feat: 增强检测报告功能与用户交互

- 更新 InspectionNode 接口,支持 existsDefaultValue 为字符串或数字
- 新增 resolvedInitialValue 字段,便于前端解析初始值
- 引入 InspectionTemplateDefaultData 接口,定义检测模板默认值结构
- 实现 resolveInspectionNodeInitialValue 函数,解析叶子节点初始值
- 新增 applyResolvedInitialValuesToLeafNodes 函数,批量处理叶子节点的初始值
- 在 car-detail 页面中引入 InspectSubModuleContent 组件,优化二级项内容展示
- 更新 ScoreForm 组件引用,提升代码可读性
- 调整样式与布局,改善用户体验
1 parent 8122807c
Pipeline #76 for 36f81cbd failed in 0 seconds
......@@ -127,7 +127,7 @@ export interface InspectionNode {
options?: string;
validationRules?: string;
allowNoStructure?: number;
existsDefaultValue?: string;
existsDefaultValue?: string | number;
defaultValue?: string;
defaultType?: number;
nodeLevel: number;
......@@ -139,6 +139,11 @@ export interface InspectionNode {
inspectionResultVO?: InspectionResultVO;
/** 子节点列表(nodeType=2 的节点下挂 nodeType=3 的叶子节点) */
childrenNodes?: InspectionNode[];
/**
* 前端根据 existsDefaultValue / defaultType 解析后的初始值
* (defaultType=2 时从 getInspectionTemplateDefault 的 data[nodeCode] 映射)
*/
resolvedInitialValue?: string;
[key: string]: unknown;
}
......@@ -168,16 +173,88 @@ export function getInspectionChildren(rootNodeId: string | number, taskId: strin
});
}
/** getInspectionTemplateDefault 返回的 data 结构(字段与 nodeCode 对应,可扩展) */
export interface InspectionTemplateDefaultData {
keyCount?: string;
carBrand?: string;
exteriorColor?: string;
compulsoryInsuranceExpiry?: string;
engineNumber?: string;
handoverAddress?: string;
sourceNo?: string;
seat?: string;
licensePlate?: string;
carSeriesId?: string;
productionDate?: string;
annualInspectionExpiry?: string;
registrationDate?: string;
vin?: string;
displacement?: string;
emissionStandard?: string;
carSeriesName?: string;
mileage?: string;
usageType?: string;
[key: string]: unknown;
}
/**
* 获取检测模板默认值
* 获取检测模板默认值(业务层已解包为 data 对象)
* @param taskId 检测工单ID
*/
export function getInspectionTemplateDefault(taskId: string | number) {
return post(`/rest/inspectionTemplate/default`, {
return post<InspectionTemplateDefaultData>(`/rest/inspectionTemplate/default`, {
taskId,
});
}
/** 是否存在默认值:1-存在 0-不存在 */
function hasDefaultValueFlag(node: InspectionNode): boolean {
return String(node.existsDefaultValue ?? "") === "1";
}
/**
* 解析单个叶子节点的初始值
* - defaultType 1:固定值,取 defaultValue
* - defaultType 2:接口值,用 nodeCode 从 templateDefaultData 取字段
* - defaultType 3:表达式(暂未约定,返回 undefined)
*/
export function resolveInspectionNodeInitialValue(
node: InspectionNode,
templateDefaultData: InspectionTemplateDefaultData | null | undefined
): string | undefined {
if (!hasDefaultValueFlag(node)) return undefined;
const type = node.defaultType;
if (type === 1) {
return node.defaultValue ?? "";
}
if (type === 2) {
const code = node.nodeCode;
if (!code || !templateDefaultData) return undefined;
const raw = (templateDefaultData as Record<string, unknown>)[code];
if (raw === undefined || raw === null) return undefined;
return String(raw);
}
if (type === 3) {
// 表达式:待后端约定格式后再实现
return undefined;
}
// 未带 defaultType 时兜底用 defaultValue
return node.defaultValue ?? undefined;
}
/** 为二级项下的叶子节点列表写入 resolvedInitialValue */
export function applyResolvedInitialValuesToLeafNodes(
leafNodes: InspectionNode[] | undefined,
templateDefaultData: InspectionTemplateDefaultData | null | undefined
): InspectionNode[] {
if (!leafNodes?.length) return [];
return leafNodes.map((node) => ({
...node,
resolvedInitialValue: resolveInspectionNodeInitialValue(node, templateDefaultData),
}));
}
// ===== 检测记录保存 =====
export interface LeafNodeValue {
......
<template>
<div class="inspect-sub-content inspect-sub-content--mock">
<div v-if="!leafNodes?.length"
class="sub-empty">
<van-icon color="#c8c9cc"
name="notes-o"
size="40" />
<p>当前二级项暂无检测项(childrenNodes 为空)</p>
</div>
<template v-else>
<div v-if="bigModuleLabel || subTabLabel"
class="sub-header">
<span v-if="bigModuleLabel">{{ bigModuleLabel }}</span>
<span v-if="bigModuleLabel && subTabLabel"> · </span>
<span v-if="subTabLabel">{{ subTabLabel }}</span>
<span class="sub-header-tag">模拟</span>
</div>
<div v-for="node in leafNodes"
:key="node.id"
class="mock-field-card">
<div class="mock-field-title">
{{ node.nodeName }}
<span v-if="node.required === 1"
class="req">*</span>
</div>
<div class="mock-field-meta">
<span>nodeCode: {{ node.nodeCode || "—" }}</span>
<span>interaction: {{ node.interactionType || "—" }}</span>
</div>
<div v-if="showResolvedDefault(node)"
class="mock-resolved">
解析默认: {{ node.resolvedInitialValue ?? node.defaultValue ?? "—" }}
</div>
<van-field class="mock-input"
:model-value="fieldValues[node.id] ?? ''"
:placeholder="node.placeholder || '模拟输入'"
@update:model-value="(v) => onFieldInput(node.id, v)" />
</div>
</template>
</div>
</template>
<script setup lang="ts">
import type { InspectionNode, LeafNodeRecord } from "@api";
import { ref, watch } from "vue";
import { showToast } from "vant";
const props = withDefaults(
defineProps<{
/** 当前二级项下已处理默认值的 childrenNodes(叶子节点) */
leafNodes?: InspectionNode[];
bigModuleLabel?: string;
subTabLabel?: string;
}>(),
{
leafNodes: () => [],
bigModuleLabel: "",
subTabLabel: "",
}
);
/** 模拟表单值(nodeId -> 文本) */
const fieldValues = ref<Record<number, string>>({});
watch(
() => props.leafNodes,
(nodes: InspectionNode[] | undefined) => {
const next: Record<number, string> = {};
for (const n of nodes ?? []) {
next[n.id] = n.resolvedInitialValue ?? n.defaultValue ?? "";
}
fieldValues.value = next;
},
{ immediate: true, deep: true }
);
function showResolvedDefault(node: InspectionNode) {
return (
node.existsDefaultValue === "1" ||
node.existsDefaultValue === 1 ||
node.resolvedInitialValue !== undefined ||
!!node.defaultValue
);
}
function onFieldInput(nodeId: number, v: string) {
fieldValues.value = { ...fieldValues.value, [nodeId]: v };
}
/**
* 与父页 InspectSubContentExpose 对齐;正式组件实现后替换逻辑即可。
*/
async function collectData(validate: boolean): Promise<LeafNodeRecord[] | null> {
const list = props.leafNodes ?? [];
if (validate) {
for (const n of list) {
if (n.required === 1 && !String(fieldValues.value[n.id] ?? "").trim()) {
showToast(`请填写:${n.nodeName}`);
return null;
}
}
}
return list.map((leaf) => ({
nodeId: leaf.id,
nodeName: leaf.nodeName,
resultStatus: 0,
remark: "",
data: [
{
id: leaf.id,
valueText: String(fieldValues.value[leaf.id] ?? ""),
valueKey: "",
interactionType: leaf.interactionType ?? "",
valueSeq: 0,
remark: "",
},
],
}));
}
defineExpose({ collectData });
</script>
<style lang="scss" scoped>
.inspect-sub-content--mock {
padding-bottom: 8px;
}
.sub-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 220px;
gap: 12px;
padding: 24px;
font-size: 13px;
color: #969799;
text-align: center;
}
.sub-header {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
margin-bottom: 12px;
font-size: 13px;
font-weight: 600;
color: #323233;
.sub-header-tag {
padding: 0 6px;
font-size: 11px;
font-weight: 500;
color: #185efe;
background: #185efe1a;
border-radius: 4px;
}
}
.mock-field-card {
margin-bottom: 14px;
padding: 12px;
background: #f7f8fa;
border-radius: 8px;
}
.mock-field-title {
margin-bottom: 6px;
font-size: 15px;
font-weight: 600;
color: #323233;
.req {
margin-left: 2px;
color: #ee0a24;
}
}
.mock-field-meta {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 6px;
font-size: 11px;
color: #969799;
}
.mock-resolved {
margin-bottom: 8px;
padding: 6px 8px;
font-size: 12px;
line-height: 1.4;
color: #185efe;
word-break: break-all;
background: #185efe14;
border-radius: 4px;
}
.mock-input {
padding: 8px 10px;
margin-top: 4px;
overflow: hidden;
background: #fff;
border-radius: 6px;
:deep(.van-field__body) {
padding: 0;
}
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!