Commit 168328df by chenwq1

feat: 增强检测报告与文件上传功能

- 新增 InspectionValueItem 接口,支持检测结果单项值的结构定义
- 更新 InspectionResultVO 接口,允许 completedFlag 为字符串或数字
- 重构 resolveInspectionNodeInitialValue 函数,支持多值返回并优化逻辑
- 新增 buildInspectionResultVOFromDefaults 函数,简化默认值构建过程
- 在 InspectSubModuleContent 组件中优化初始值展示逻辑
- 新增 OSS 文件上传示例页面,支持文件选择与上传功能
- 更新路由配置,添加上传示例页面路由
- 调整样式与布局,提升用户体验
1 parent a29d2d96
Pipeline #79 for 168328df failed in 0 seconds
...@@ -102,9 +102,27 @@ export function getInspectReportPage(params: InspectReportPageParams) { ...@@ -102,9 +102,27 @@ export function getInspectReportPage(params: InspectReportPageParams) {
// 检测模板相关接口 // 检测模板相关接口
/** 检测结果单项值(与落库结构对齐) */
export interface InspectionValueItem {
id?: number;
resultId?: number;
valueKey?: string;
valueText?: string;
interactionType?: string;
valueSeq?: number;
remark?: string;
}
export interface InspectionResultVO { export interface InspectionResultVO {
/** 完成标志:0 未完成,1 已完成 */ id?: number;
completedFlag: 0 | 1; recordId?: number;
nodeId?: number;
nodeName?: string;
resultStatus?: number;
/** 完成标志:0 未完成,1 已完成(接口也可能给空字符串) */
completedFlag?: 0 | 1 | string;
remark?: string;
inspectionValueList?: InspectionValueItem[];
[key: string]: unknown; [key: string]: unknown;
} }
...@@ -213,46 +231,99 @@ function hasDefaultValueFlag(node: InspectionNode): boolean { ...@@ -213,46 +231,99 @@ function hasDefaultValueFlag(node: InspectionNode): boolean {
} }
/** /**
* 解析单个叶子节点的初始值 * 解析叶子节点默认值对应的文案列表(可多值,与 inspectionValueList 一一对应)
* - defaultType 1:固定值,取 defaultValue * - defaultType 1:固定值,取 defaultValue
* - defaultType 2:接口值,用 nodeCode 从 templateDefaultData 取字段 * - defaultType 2:接口值;若字段为数组则每项一条,否则单条
* - defaultType 3:表达式(暂未约定,返回 undefined) * - defaultType 3:表达式(暂未约定,返回空)
*/ */
export function resolveInspectionNodeInitialValue( export function resolveInspectionNodeInitialValueTexts(
node: InspectionNode, node: InspectionNode,
templateDefaultData: InspectionTemplateDefaultData | null | undefined templateDefaultData: InspectionTemplateDefaultData | null | undefined
): string | undefined { ): string[] {
if (!hasDefaultValueFlag(node)) return undefined; if (!hasDefaultValueFlag(node)) return [];
const type = node.defaultType; const type = node.defaultType;
if (type === 1) { if (type === 1) {
return node.defaultValue ?? ""; return [node.defaultValue ?? ""];
} }
if (type === 2) { if (type === 2) {
const code = node.nodeCode; const code = node.nodeCode;
if (!code || !templateDefaultData) return undefined; if (!code || !templateDefaultData) return [];
const raw = (templateDefaultData as Record<string, unknown>)[code]; const raw = (templateDefaultData as Record<string, unknown>)[code];
if (raw === undefined || raw === null) return undefined; if (raw === undefined || raw === null) return [];
return String(raw); if (Array.isArray(raw)) {
return raw.map((item) => (item === undefined || item === null ? "" : String(item)));
}
return [String(raw)];
} }
if (type === 3) { if (type === 3) {
// 表达式:待后端约定格式后再实现 return [];
return undefined; }
if (node.defaultValue !== undefined && node.defaultValue !== null) {
return [String(node.defaultValue)];
} }
// 未带 defaultType 时兜底用 defaultValue return [];
return node.defaultValue ?? undefined; }
function buildInspectionResultVOFromDefaults(node: InspectionNode, valueTexts: string[]): InspectionResultVO {
const inspectionValueList: InspectionValueItem[] = valueTexts.map((valueText, index) => ({
id: 0,
resultId: 0,
valueKey: "",
valueText,
interactionType: node.interactionType ?? "",
valueSeq: index,
remark: "",
}));
return {
id: 0,
recordId: 0,
nodeId: node.id,
nodeName: node.nodeName,
resultStatus: 0,
completedFlag: 0,
remark: "",
inspectionValueList,
};
} }
/** 为二级项下的叶子节点列表写入 resolvedInitialValue */ /**
* 解析单个叶子节点的初始值(展示用;多值时以 ", " 拼接)
*/
export function resolveInspectionNodeInitialValue(
node: InspectionNode,
templateDefaultData: InspectionTemplateDefaultData | null | undefined
): string | undefined {
const texts = resolveInspectionNodeInitialValueTexts(node, templateDefaultData);
if (texts.length === 0) return undefined;
return texts.length === 1 ? texts[0] : texts.join(", ");
}
/**
* 为二级项下的叶子节点写入解析默认值:
* - 已有 inspectionResultVO 的叶子不覆盖
* - 否则将默认值写入新建的 inspectionResultVO.inspectionValueList[].valueText(多值多条)
*/
export function applyResolvedInitialValuesToLeafNodes( export function applyResolvedInitialValuesToLeafNodes(
leafNodes: InspectionNode[] | undefined, leafNodes: InspectionNode[] | undefined,
templateDefaultData: InspectionTemplateDefaultData | null | undefined templateDefaultData: InspectionTemplateDefaultData | null | undefined
): InspectionNode[] { ): InspectionNode[] {
if (!leafNodes?.length) return []; if (!leafNodes?.length) return [];
return leafNodes.map((node) => ({ return leafNodes.map((node) => {
...node, if (node.inspectionResultVO != null) {
resolvedInitialValue: resolveInspectionNodeInitialValue(node, templateDefaultData), return { ...node };
})); }
const valueTexts = resolveInspectionNodeInitialValueTexts(node, templateDefaultData);
if (valueTexts.length === 0) {
return { ...node };
}
const resolvedInitialValue = valueTexts.length === 1 ? valueTexts[0] : valueTexts.join(", ");
return {
...node,
resolvedInitialValue,
inspectionResultVO: buildInspectionResultVOFromDefaults(node, valueTexts),
};
});
} }
// ===== 检测记录保存 ===== // ===== 检测记录保存 =====
......
...@@ -59,6 +59,16 @@ const routes: RouteRecordRaw[] = [ ...@@ -59,6 +59,16 @@ const routes: RouteRecordRaw[] = [
showTabBar: false, showTabBar: false,
}, },
}, },
/** 开发自测:OSS 分片上传 */
{
path: "/upload-demo",
name: "UploadDemo",
component: () => import("@views/upload-demo/index.vue"),
meta: {
title: "OSS 上传 Demo",
showTabBar: false,
},
},
{ {
path: "/:pathMatch(.*)*", path: "/:pathMatch(.*)*",
name: "NotFound", name: "NotFound",
......
...@@ -66,12 +66,26 @@ const props = withDefaults( ...@@ -66,12 +66,26 @@ const props = withDefaults(
/** 模拟表单值(nodeId -> 文本) */ /** 模拟表单值(nodeId -> 文本) */
const fieldValues = ref<Record<number, string>>({}); const fieldValues = ref<Record<number, string>>({});
function initialFieldText(n: InspectionNode): string {
if (n.resolvedInitialValue !== undefined) {
return n.resolvedInitialValue;
}
const list = n.inspectionResultVO?.inspectionValueList;
if (list?.length) {
return list
.map((item) => String(item.valueText ?? "").trim())
.filter(Boolean)
.join(", ");
}
return n.defaultValue ?? "";
}
watch( watch(
() => props.leafNodes, () => props.leafNodes,
(nodes: InspectionNode[] | undefined) => { (nodes: InspectionNode[] | undefined) => {
const next: Record<number, string> = {}; const next: Record<number, string> = {};
for (const n of nodes ?? []) { for (const n of nodes ?? []) {
next[n.id] = n.resolvedInitialValue ?? n.defaultValue ?? ""; next[n.id] = initialFieldText(n);
} }
fieldValues.value = next; fieldValues.value = next;
}, },
......
<script setup lang="ts">
import { ref } from "vue";
import PageTop from "@/components/PageTop.vue";
import { OSS_CONFIG } from "@/config/oss";
import { uploadFile } from "@/utils/upload.js";
import { showToast } from "vant";
const fileInputRef = ref<HTMLInputElement | null>(null);
const uploading = ref(false);
const lastResult = ref<Record<string, unknown> | null>(null);
const lastError = ref<string>("");
function pickFile() {
lastError.value = "";
lastResult.value = null;
fileInputRef.value?.click();
}
async function onFileChange(ev: Event) {
const input = ev.target as HTMLInputElement;
const file = input.files?.[0];
input.value = "";
if (!file) return;
uploading.value = true;
lastError.value = "";
lastResult.value = null;
try {
const res = (await uploadFile(file)) as Record<string, unknown>;
lastResult.value = res;
const url =
(typeof res.aliyunAddress === "string" && res.aliyunAddress) ||
(typeof res.url === "string" && res.url) ||
"";
showToast(url ? "上传成功" : "上传完成(无 URL 字段)");
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : String(e);
lastError.value = msg;
showToast(`上传失败:${msg}`);
} finally {
uploading.value = false;
}
}
</script>
<template>
<div class="upload-demo">
<PageTop title="OSS 上传 Demo" />
<div class="card">
<p class="hint">
使用 <code>utils/upload.js</code> 的 <code>uploadFile</code>,桶 <code>{{ OSS_CONFIG.BUCKET_NAME }}</code>,目录
<code>{{ OSS_CONFIG.FOLDER }}</code>
</p>
<input ref="fileInputRef"
accept="image/*"
class="hidden-input"
type="file"
@change="onFileChange">
<van-button :loading="uploading"
block
type="primary"
@click="pickFile">
{{ uploading ? "上传中…" : "选择图片并上传" }}
</van-button>
<div v-if="lastError" class="block error">
<div class="label">错误</div>
<pre>{{ lastError }}</pre>
</div>
<div v-if="lastResult" class="block ok">
<div class="label">返回(JSON)</div>
<pre>{{ JSON.stringify(lastResult, null, 2) }}</pre>
</div>
</div>
</div>
</template>
<style scoped lang="scss">
.upload-demo {
min-height: 100vh;
background: #f5f6f7;
}
.card {
margin: 12px;
padding: 16px;
background: #fff;
border-radius: 8px;
}
.hint {
margin: 0 0 16px;
font-size: 12px;
color: #646566;
line-height: 1.5;
code {
padding: 0 4px;
font-size: 11px;
background: #f2f3f5;
border-radius: 2px;
}
}
.hidden-input {
position: absolute;
width: 0;
height: 0;
opacity: 0;
pointer-events: none;
}
.block {
margin-top: 16px;
padding: 12px;
border-radius: 6px;
font-size: 12px;
.label {
margin-bottom: 8px;
font-weight: 600;
color: #323233;
}
pre {
margin: 0;
white-space: pre-wrap;
word-break: break-all;
font-size: 11px;
line-height: 1.4;
}
}
.block.error {
background: #fff1f0;
color: #cf1322;
}
.block.ok {
background: #f6ffed;
color: #389e0d;
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!