Commit b181f954 by chenwq1

fix:osss

1 parent 8e2a1493
...@@ -6,8 +6,8 @@ PUBLISH_PATH = '/' ...@@ -6,8 +6,8 @@ PUBLISH_PATH = '/'
BASE_URL = '/ BASE_URL = '/
# 开发环境 # 开发环境
# VITE_API_BASE_URL = 'http://aus.test.glsx.com.cn/admin/rest' VITE_API_BASE_URL = 'http://aus.test.glsx.com.cn/admin/rest'
VITE_API_BASE_URL = 'http://192.168.1.69:6903/admin/rest' # VITE_API_BASE_URL = 'http://192.168.1.69:6903/admin/rest'
#VITE_TOKEN= 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbmlzdHJhdG9yIiwicmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJwYXNzd29yZCI6IiQyYSQxMCRlQ21jWmxPaFltVUxrNklibjR3RVgudjNpa0dzcnBpYjh0SlBlcGJ6NVl1SXFWbUpCVER4eSIsImlzcyI6ImF1c0FwcCIsImV4cCI6MTg0NTI4NTU3NiwiaWF0IjoxNzczMjg1NTc2LCJqdGkiOiIzMCIsImF1dGhvcml0aWVzIjpbIlJPTEVfU1VQRVIiXX0.q0Ou_W9goNWUgasZTULp4IDWlZhVHWbQ0jn49qdZeSw' #VITE_TOKEN= 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbmlzdHJhdG9yIiwicmVhbE5hbWUiOiLotoXnuqfnrqHnkIblkZgiLCJwYXNzd29yZCI6IiQyYSQxMCRlQ21jWmxPaFltVUxrNklibjR3RVgudjNpa0dzcnBpYjh0SlBlcGJ6NVl1SXFWbUpCVER4eSIsImlzcyI6ImF1c0FwcCIsImV4cCI6MTg0NTI4NTU3NiwiaWF0IjoxNzczMjg1NTc2LCJqdGkiOiIzMCIsImF1dGhvcml0aWVzIjpbIlJPTEVfU1VQRVIiXX0.q0Ou_W9goNWUgasZTULp4IDWlZhVHWbQ0jn49qdZeSw'
......
export const OSS_CONFIG = { export const OSS_CONFIG = {
BUCKET_NAME: "glsk-oss", BUCKET_NAME: "glsk-oss",
OSS_DOMAIN: "https://glsk-oss.oss-cn-shenzhen.aliyuncs.com", OSS_DOMAIN: "https://glsk-oss.oss-cn-shenzhen.aliyuncs.com",
FOLDER: "usedCarH5/", FOLDER: "usedCarH5/",
/** /**
* glsk-oss-jssdk 需要的 systemSource(会传给 STS 凭证接口) * glsk-oss-jssdk 需要的 systemSource(会传给 STS 凭证接口)
* H5 默认用 h5,按你们接口约定调整 * H5 默认用 h5,按你们接口约定调整
*/ */
SYSTEM_SOURCE: "h5", SYSTEM_SOURCE: "web",
} as const; } as const;
...@@ -53,13 +53,28 @@ export function uploadFile(file, options = {}) { ...@@ -53,13 +53,28 @@ export function uploadFile(file, options = {}) {
* @param {File[]} files * @param {File[]} files
* @param {Parameters<typeof uploadFile>[1]} [options] * @param {Parameters<typeof uploadFile>[1]} [options]
*/ */
export function uploadFiles(files, options = {}) { const IMAGE_EXT = /\.(jpe?g|png|gif|webp|bmp|svg|ico|heic|heif)$/i;
if (!Array.isArray(files) || files.length === 0) { const VIDEO_EXT = /\.(mp4|webm|ogg|mov|mpe?g|avi|wmv|flv|mkv)$/i;
return Promise.reject(new Error("files 不能为空"));
} /** 是否为图片(MIME 优先;无 MIME 时按扩展名兜底,常见于部分移动端) */
return Promise.all(files.map((f) => uploadFile(f, options))); export function isLikelyImageFile(file) {
if (!file) return false;
const t = (file.type || "").toLowerCase();
if (t.startsWith("image/")) return true;
if (!t && IMAGE_EXT.test(file.name || "")) return true;
return false;
} }
/** 是否为视频 */
export function isLikelyVideoFile(file) {
if (!file) return false;
const t = (file.type || "").toLowerCase();
if (t.startsWith("video/")) return true;
if (!t && VIDEO_EXT.test(file.name || "")) return true;
return false;
}
// 将图片进行格式转换。 // 将图片进行格式转换。
async function format() { async function format() {
try { try {
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<CustomizeForm ref="customizeFormRef" @submitSuccess="getTemplateData('0')" /> <CustomizeForm ref="customizeFormRef" @submitSuccess="getTemplateData('0')" />
</div> </div>
<div class="customizeFormBox" v-if="activeNodeId == -1"> <div class="customizeFormBox" v-if="activeNodeId == -1">
<TestingScore ref="testingScoreRef" /> <TestingScore ref="testingScoreRef" @submitSuccess="getTemplateData('0')" />
</div> </div>
</div> </div>
</template> </template>
...@@ -32,6 +32,7 @@ import { DetectionController } from "@/api/DetectionController"; ...@@ -32,6 +32,7 @@ import { DetectionController } from "@/api/DetectionController";
import { CheckCircleFilled } from '@ant-design/icons-vue' import { CheckCircleFilled } from '@ant-design/icons-vue'
import { TrackHelper } from "@/common/TrackHelper"; import { TrackHelper } from "@/common/TrackHelper";
import { Modal } from "ant-design-vue"; import { Modal } from "ant-design-vue";
import { applyResolvedInitialValuesToLeafNodes } from "@/views/detection/order/utils/inspectInitialValues";
@Component({ @Component({
...@@ -132,7 +133,10 @@ export default class DetectionOrderEdit extends PaginationComponent<Vehicle> { ...@@ -132,7 +133,10 @@ export default class DetectionOrderEdit extends PaginationComponent<Vehicle> {
} else { } else {
this.inspectionNodeList = nodeList; this.inspectionNodeList = nodeList;
} }
this.inspectionNodeList = this.inspectionNodeList.map(item => ({ ...item, childrenNodes: this.setDefaultData(item.childrenNodes || []) })); this.inspectionNodeList = this.inspectionNodeList.map(item => ({
...item,
childrenNodes: this.applyLeafDefaults(item.childrenNodes || []),
}));
this.$refs.customizeFormRef.init({ this.$refs.customizeFormRef.init({
customizeFormList: this.inspectionNodeList, customizeFormList: this.inspectionNodeList,
carTypeList: this.carTypeList, carTypeList: this.carTypeList,
...@@ -142,89 +146,39 @@ export default class DetectionOrderEdit extends PaginationComponent<Vehicle> { ...@@ -142,89 +146,39 @@ export default class DetectionOrderEdit extends PaginationComponent<Vehicle> {
}); });
} }
setDefaultData(list: any[] = []) { applyLeafDefaults(list: any[] = []) {
const typeToKeyMap = { const withDefaults = applyResolvedInitialValuesToLeafNodes(
text_input: 'valueText', list,
textarea_input: 'valueText', this.defaultData || {},
number_input: 'valueText', this.carTypeList || [],
date_picker: 'valueText', );
dropdown: 'valueKey', return this.mapNodeResultStatus(withDefaults);
radio_button_select: 'valueKey' }
};
// 节点名称 -> /inspectionTemplate/default 字段,按包含关系匹配
const matchers: { match: (n: string) => boolean; key: string }[] = [
{ match: n => n === '品牌', key: 'carBrand' },
{ match: n => n === '车系', key: 'carSeriesName' },
{ match: n => n === '车型', key: 'carTypeId' },
{ match: n => /车源/.test(n), key: 'sourceNo' },
{ match: n => /VIN|车架号/i.test(n), key: 'vin' },
{ match: n => /车牌/.test(n), key: 'licensePlate' },
{ match: n => /注册|登记/.test(n), key: 'registrationDate' },
{ match: n => /出厂|生产/.test(n), key: 'productionDate' },
{ match: n => /年检/.test(n), key: 'annualInspectionExpiry' },
{ match: n => /交强险/.test(n), key: 'compulsoryInsuranceExpiry' },
{ match: n => /排量/.test(n), key: 'displacement' },
{ match: n => /排放/.test(n), key: 'emissionStandard' },
{ match: n => /发动机/.test(n), key: 'engineNumber' },
{ match: n => /颜色/.test(n), key: 'exteriorColor' },
{ match: n => /钥匙/.test(n), key: 'keyCount' },
{ match: n => /里程/.test(n), key: 'mileage' },
{ match: n => /使用性质|营运/.test(n), key: 'usageType' },
];
const defaultList = list.map(item => {
const inspectionValueList = item?.inspectionResultVO?.inspectionValueList || [];
let value = null;
if (inspectionValueList.length > 0) {
const key = typeToKeyMap[item.interactionType];
if (key) value = inspectionValueList[0][key] || '';
}
if (value == null || value === '') { mapNodeResultStatus(nodes: any[] = []): any[] {
const hit = matchers.find(m => m.match(String(item.nodeName || ''))); return (nodes || []).map((item) => {
if (hit) { const mapped = {
const dv = this.defaultData?.[hit.key]; ...item,
if (dv != null && dv !== '') { resultStatus: item?.inspectionResultVO?.resultStatus == 3 ? true : false,
value = String(dv); };
// 下拉/单选:default 返回的是名称,需要换成 options 里的 id if (mapped.childrenNodes?.length) {
if (item.interactionType === 'dropdown' || item.interactionType === 'radio_button_select') { mapped.childrenNodes = this.mapNodeResultStatus(mapped.childrenNodes);
const optionsList = item.nodeName === '车型'
? this.carTypeList
: JSON.parse(item.options || '[]').map((s: string) => {
const parts = (s || '').split('-');
return { text: parts[1] || '', value: parts[0] || '' };
});
const opt = optionsList.find((o: any) => String(o.value) === value)
|| optionsList.find((o: any) => String(o.text) === value);
value = opt ? String(opt.value) : '';
}
}
}
} }
return { ...item, resultStatus: item?.inspectionResultVO?.resultStatus == 3 ? true : false, value }; return mapped;
}); });
return defaultList;
} }
handleNodeList(item: any) { handleNodeList(item: any) {
if (item.id == this.activeNodeId) return; if (item.id == this.activeNodeId) return;
if (this.hasCurrentTabRequiredUnfilled()) { Modal.confirm({
Modal.confirm({ title: '提示',
title: '提示', content: '当前一级类目下,存在必填检测项未完成,强制离开将丢失数据,请完成检查后切换tab或离开标签页。',
content: '当前一级类目下,存在必填检测项未完成,强制离开将丢失数据,请完成检查后切换tab或离开标签页。', okText: '强制离开',
okText: '强制离开', cancelText: '继续填写',
cancelText: '继续填写', onOk: () => {
onOk: () => { this.switchNode(item);
this.switchNode(item); },
}, });
});
return;
}
this.switchNode(item);
}
hasCurrentTabRequiredUnfilled(): boolean {
const ref: any = Number(this.activeNodeId) === -1 ? this.$refs.testingScoreRef : this.$refs.customizeFormRef;
return !!ref?.hasRequiredUnfilled?.();
} }
switchNode(item: any) { switchNode(item: any) {
......
...@@ -106,7 +106,8 @@ ...@@ -106,7 +106,8 @@
<a-button type="link" size="small">检测报告</a-button> <a-button type="link" size="small">检测报告</a-button>
</router-link> </router-link>
<router-link v-if="record.status != 3" <router-link
v-if="!((record.status == 3 && record.auditStatus == 3) || record.status == 4)"
:to="{ path: '/detection/order/edit', query: { id: record.id, page: 'order', action: 'EDIT' } }"> :to="{ path: '/detection/order/edit', query: { id: record.id, page: 'order', action: 'EDIT' } }">
<a-button type="link" size="small" @click="trackEnterEditMode(record)">编辑报告</a-button> <a-button type="link" size="small" @click="trackEnterEditMode(record)">编辑报告</a-button>
</router-link> </router-link>
......
...@@ -58,10 +58,12 @@ ...@@ -58,10 +58,12 @@
v-if="getValidationRules(item).datePattern && getValidationRules(item).datePattern.length > 8" v-if="getValidationRules(item).datePattern && getValidationRules(item).datePattern.length > 8"
format="YYYY-MM-DD" value-format="YYYY-MM-DD" style="width: 100%;" format="YYYY-MM-DD" value-format="YYYY-MM-DD" style="width: 100%;"
v-model:value="item.value" :placeholder="item.placeholder" v-model:value="item.value" :placeholder="item.placeholder"
:disabled="item.editPermission == '0'" allow-clear /> :disabled="item.editPermission == '0'" :disabled-date="disabledDateBefore1990"
allow-clear />
<a-date-picker v-else style="width: 100%;" v-model:value="item.value" format="YYYY-MM" <a-date-picker v-else style="width: 100%;" v-model:value="item.value" format="YYYY-MM"
value-format="YYYY-MM" picker="month" :placeholder="item.placeholder" value-format="YYYY-MM" picker="month" :placeholder="item.placeholder"
:disabled="item.editPermission == '0'" allow-clear /> :disabled="item.editPermission == '0'" :disabled-date="disabledMonthBefore1990"
allow-clear />
</div> </div>
<!-- 下拉选择器 --> <!-- 下拉选择器 -->
<div v-if="item.interactionType == 'dropdown'"> <div v-if="item.interactionType == 'dropdown'">
...@@ -88,7 +90,7 @@ ...@@ -88,7 +90,7 @@
<div v-if="item.interactionType == 'image_upload_and_button_select'"> <div v-if="item.interactionType == 'image_upload_and_button_select'">
<CustomizeFormButtonSelect :columnsList="getOptionList(item)" :item="item" <CustomizeFormButtonSelect :columnsList="getOptionList(item)" :item="item"
:value="item.value" @update="item.value = $event" /> :value="item.value" @update="item.value = $event" />
<CustomizeFormButtonSelectUploadFile v-if="item.value" :item="item" :value="item.value" <CustomizeFormButtonSelectUploadFile :item="item"
@update="item.uploadValue = $event" /> @update="item.uploadValue = $event" />
</div> </div>
</a-form-item> </a-form-item>
...@@ -113,6 +115,9 @@ import { CheckCircleFilled } from "@ant-design/icons-vue"; ...@@ -113,6 +115,9 @@ import { CheckCircleFilled } from "@ant-design/icons-vue";
import { DetectionController } from "@/api/DetectionController"; import { DetectionController } from "@/api/DetectionController";
import { message } from "ant-design-vue"; import { message } from "ant-design-vue";
import { TrackHelper } from "@/common/TrackHelper"; import { TrackHelper } from "@/common/TrackHelper";
import dayjs, { Dayjs } from "dayjs";
const DATE_PICKER_MIN = dayjs("1990-01-01");
@Component({ components: { TitleDivider, CustomizeFormButtonSelect, CustomizeFormUploadFile, CustomizeFormButtonSelectUploadFile, CheckCircleFilled } }) @Component({ components: { TitleDivider, CustomizeFormButtonSelect, CustomizeFormUploadFile, CustomizeFormButtonSelectUploadFile, CheckCircleFilled } })
...@@ -139,7 +144,6 @@ export default class CustomizeForm extends Vue { ...@@ -139,7 +144,6 @@ export default class CustomizeForm extends Vue {
this.activeNodeId = data.activeNodeId || ''; this.activeNodeId = data.activeNodeId || '';
this.taskId = data.taskId || ''; this.taskId = data.taskId || '';
this.snapshotInitialValues(); this.snapshotInitialValues();
console.log('111111111111111111initData', this.columnsList);
} }
snapshotInitialValues() { snapshotInitialValues() {
...@@ -254,6 +258,16 @@ export default class CustomizeForm extends Vue { ...@@ -254,6 +258,16 @@ export default class CustomizeForm extends Vue {
return JSON.parse(item.validationRules || "{}"); return JSON.parse(item.validationRules || "{}");
} }
/** date_picker:1990-01-01 之前不可选 */
disabledDateBefore1990(current: Dayjs) {
return !!current && current.isBefore(DATE_PICKER_MIN, "day");
}
/** date_picker(按月):1990-01 之前不可选 */
disabledMonthBefore1990(current: Dayjs) {
return !!current && current.isBefore(DATE_PICKER_MIN, "month");
}
getOptionList(item: any) { getOptionList(item: any) {
const optionsList = JSON.parse(item.options || "[]").map(item => { const optionsList = JSON.parse(item.options || "[]").map(item => {
const valueList = (item || "").split("-"); const valueList = (item || "").split("-");
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-facing-decorator"; import { Component, Prop, Vue, Watch } from "vue-facing-decorator";
import { uploadFile } from "@/utils/upload.js"; import { uploadFile, isLikelyImageFile } from "@/utils/upload.js";
import { PlusOutlined, CloseCircleOutlined } from "@ant-design/icons-vue"; import { PlusOutlined, CloseCircleOutlined } from "@ant-design/icons-vue";
import { message } from "ant-design-vue"; import { message } from "ant-design-vue";
...@@ -89,10 +89,14 @@ export default class CustomizeFormButtonSelectUploadFile extends Vue { ...@@ -89,10 +89,14 @@ export default class CustomizeFormButtonSelectUploadFile extends Vue {
const file = input.files?.[0]; const file = input.files?.[0];
input.value = ""; input.value = "";
if (!file) return; if (!file) return;
if (!isLikelyImageFile(file)) {
return message.error("仅支持上传图片文件");
}
const maxSize10MB = 10 * 1024 * 1024; const maxSize10MB = 10 * 1024 * 1024;
const maxSize100MB = 100 * 1024 * 1024; const maxSize100MB = 100 * 1024 * 1024;
if ( if (
this.item.interactionType == "image_upload" && (this.item.interactionType == "image_upload" ||
this.item.interactionType == "image_upload_and_button_select") &&
file.size > maxSize10MB file.size > maxSize10MB
) { ) {
return message.error("文件大小不能超过10MB"); return message.error("文件大小不能超过10MB");
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Prop, Vue } from "vue-facing-decorator"; import { Component, Prop, Vue } from "vue-facing-decorator";
import { uploadFile } from "@/utils/upload.js"; import { uploadFile, isLikelyImageFile, isLikelyVideoFile } from "@/utils/upload.js";
import { PlusOutlined, CloseCircleOutlined } from "@ant-design/icons-vue"; import { PlusOutlined, CloseCircleOutlined } from "@ant-design/icons-vue";
import { message } from "ant-design-vue"; import { message } from "ant-design-vue";
...@@ -122,6 +122,15 @@ export default class CustomizeFormUploadFile extends Vue { ...@@ -122,6 +122,15 @@ export default class CustomizeFormUploadFile extends Vue {
const file = input.files?.[0]; const file = input.files?.[0];
input.value = ""; input.value = "";
if (!file) return; if (!file) return;
if (this.item.interactionType == "image_upload") {
if (!isLikelyImageFile(file)) {
return message.error("仅支持上传图片文件");
}
} else if (this.item.interactionType == "video_upload") {
if (!isLikelyVideoFile(file)) {
return message.error("仅支持上传视频文件");
}
}
const maxSize10MB = 10 * 1024 * 1024; const maxSize10MB = 10 * 1024 * 1024;
const maxSize100MB = 100 * 1024 * 1024; const maxSize100MB = 100 * 1024 * 1024;
if ( if (
......
...@@ -196,7 +196,7 @@ export default class OperationLog extends Vue { ...@@ -196,7 +196,7 @@ export default class OperationLog extends Vue {
.logBox-content { .logBox-content {
float: left; float: left;
width: 100%; max-width: 100%;
font-size: 14px; font-size: 14px;
font-weight: 400; font-weight: 400;
line-height: 20px; line-height: 20px;
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
v-model:value="postData.exteriorScore" v-model:value="postData.exteriorScore"
:min="0" :min="0"
:max="100" :max="100"
:step="0.01"
:precision="2"
:controls="false" :controls="false"
class="score-value-input" class="score-value-input"
placeholder="请输入" placeholder="请输入"
...@@ -26,6 +28,7 @@ ...@@ -26,6 +28,7 @@
v-model:value="postData.exteriorScore" v-model:value="postData.exteriorScore"
:min="0" :min="0"
:max="100" :max="100"
:step="0.01"
/> />
</div> </div>
</div> </div>
...@@ -222,6 +225,8 @@ ...@@ -222,6 +225,8 @@
v-model:value="postData.overallScore" v-model:value="postData.overallScore"
:min="0" :min="0"
:max="200" :max="200"
:step="0.01"
:precision="2"
:controls="false" :controls="false"
class="score-value-input" class="score-value-input"
placeholder="请对车况做整体总结,如:车况良好,仅有正常使痕迹,无重大事故..." placeholder="请对车况做整体总结,如:车况良好,仅有正常使痕迹,无重大事故..."
...@@ -236,6 +241,7 @@ ...@@ -236,6 +241,7 @@
v-model:value="postData.overallScore" v-model:value="postData.overallScore"
:min="0" :min="0"
:max="100" :max="100"
:step="0.01"
/> />
</div> </div>
</div> </div>
...@@ -497,6 +503,7 @@ export default class TestingScore extends Vue { ...@@ -497,6 +503,7 @@ export default class TestingScore extends Vue {
message.success(res.message || "保存成功"); message.success(res.message || "保存成功");
this.sendSaveTrack(modifiedFields); this.sendSaveTrack(modifiedFields);
this.snapshotInitialPostData(); this.snapshotInitialPostData();
this.$emit("submitSuccess", res);
} else { } else {
message.error(res.message || "保存失败"); message.error(res.message || "保存失败");
} }
......
import dayjs from "dayjs";
/** /inspectionTemplate/default 返回的模板默认值 */
export type TemplateDefaultData = Record<string, string | string[] | null | undefined>;
const SELECT_INTERACTION_TYPES = new Set([
"dropdown",
"radio_button_select",
"button_select",
]);
function isSelectInteractionType(interactionType: string): boolean {
return SELECT_INTERACTION_TYPES.has(interactionType);
}
function isLeafNode(node: Record<string, unknown>): boolean {
const children = node.childrenNodes as unknown[] | undefined;
return !children?.length;
}
/** 是否已有保存过的检测结果 */
export function hasSavedInspectionResult(node: Record<string, unknown>): boolean {
const list = (node.inspectionResultVO as { inspectionValueList?: unknown[] } | undefined)
?.inspectionValueList;
return Array.isArray(list) && list.length > 0;
}
/** 解析单条默认值字符串为 valueKey / valueText */
export function parseDefaultValueParts(
interactionType: string,
raw: string,
): { valueKey: string; valueText: string } {
if (isSelectInteractionType(interactionType) && raw.includes("-")) {
const idx = raw.indexOf("-");
return {
valueKey: raw.slice(0, idx),
valueText: raw.slice(idx + 1),
};
}
return { valueKey: "", valueText: raw };
}
function resolveApiDefaultKey(node: Record<string, unknown>): string {
return String(node.defaultField || node.nodeCode || "").trim();
}
function readTemplateDefaultRaw(
templateDefaultData: TemplateDefaultData,
apiKey: string,
): string | string[] | null | undefined {
if (!apiKey || !templateDefaultData) {
return undefined;
}
if (templateDefaultData[apiKey] != null) {
return templateDefaultData[apiKey];
}
return undefined;
}
function rawToValueTexts(raw: string | string[] | null | undefined): string[] {
if (raw == null) {
return [];
}
if (Array.isArray(raw)) {
return raw.map((item) => String(item)).filter((s) => s !== "");
}
const s = String(raw);
return s !== "" ? [s] : [];
}
/**
* 按节点配置与 templateDefaultData 解析默认值字符串列表(未写入 inspectionResultVO)
*/
export function resolveDefaultValueTexts(
node: Record<string, unknown>,
templateDefaultData: TemplateDefaultData,
): string[] {
if (String(node.existsDefaultValue ?? "") !== "1") {
return [];
}
const defaultType =
node.defaultType != null && node.defaultType !== ""
? Number(node.defaultType)
: null;
if (defaultType === 3) {
return [];
}
if (
defaultType === 1 &&
node.defaultValue != null &&
node.defaultValue !== ""
) {
return [String(node.defaultValue)];
}
// defaultType=2,或未配置 type、或 type=1 但无固定值:从接口 Map 按 nodeCode/defaultField 取值
const apiKey = resolveApiDefaultKey(node);
const apiTexts = rawToValueTexts(
readTemplateDefaultRaw(templateDefaultData, apiKey),
);
if (apiTexts.length) {
return apiTexts;
}
if (node.defaultValue != null && node.defaultValue !== "") {
return [String(node.defaultValue)];
}
return [];
}
function normalizeDatePickerValue(
node: Record<string, unknown>,
raw: string,
): string {
if (String(node.interactionType ?? "") !== "date_picker" || !raw) {
return raw;
}
const parsed = dayjs(raw);
if (!parsed.isValid()) {
return raw;
}
try {
const rules = JSON.parse(String(node.validationRules || "{}"));
const pattern = String(rules.datePattern || "");
if (pattern.length > 8) {
return parsed.format("YYYY-MM-DD");
}
return parsed.format("YYYY-MM");
} catch {
return parsed.format("YYYY-MM-DD");
}
}
function buildInspectionValueEntry(
node: Record<string, unknown>,
raw: string,
valueSeq: number,
): Record<string, unknown> {
const normalized = normalizeDatePickerValue(node, raw);
const { valueKey, valueText } = parseDefaultValueParts(
String(node.interactionType ?? ""),
normalized,
);
return {
valueKey,
valueText,
interactionType: node.interactionType,
valueSeq,
};
}
function resolveDropdownFormValue(
node: Record<string, unknown>,
valueKey: string,
valueText: string,
carTypeList: { text: string; value: string }[],
): string {
if (valueKey) {
return valueKey;
}
const options =
node.nodeName === "车型"
? carTypeList
: JSON.parse(String(node.options || "[]")).map((s: string) => {
const parts = (s || "").split("-");
return { text: parts[1] || "", value: parts[0] || "" };
});
const opt =
options.find((o: { value: string }) => String(o.value) === valueText) ||
options.find((o: { text: string }) => String(o.text) === valueText);
return opt ? String(opt.value) : "";
}
/** 将 inspectionResultVO 同步到表单字段 item.value 等 */
export function syncLeafNodeFormValue(
node: Record<string, unknown>,
carTypeList: { text: string; value: string }[] = [],
): void {
const list =
((node.inspectionResultVO as { inspectionValueList?: Record<string, unknown>[] } | undefined)
?.inspectionValueList) || [];
if (!list.length) {
return;
}
const interactionType = String(node.interactionType ?? "");
if (interactionType === "dropdown" || interactionType === "radio_button_select") {
const first = list[0];
const valueKey = String(first.valueKey ?? "");
const valueText = String(first.valueText ?? "");
node.valueKey = valueKey;
node.valueText = valueText;
node.value = valueKey || resolveDropdownFormValue(node, valueKey, valueText, carTypeList);
return;
}
if (interactionType === "button_select") {
const entries = list.map((entry) => ({
valueKey: String(entry.valueKey ?? ""),
valueText: String(entry.valueText ?? ""),
}));
node.value = entries.length > 0 ? JSON.stringify(entries) : "";
return;
}
const text = normalizeDatePickerValue(node, String(list[0].valueText ?? ""));
if (text !== "") {
node.value = text;
}
}
function applyDefaultsToSingleLeaf(
node: Record<string, unknown>,
templateDefaultData: TemplateDefaultData,
carTypeList: { text: string; value: string }[] = [],
): Record<string, unknown> {
const next = { ...node };
if (hasSavedInspectionResult(next)) {
syncLeafNodeFormValue(next, carTypeList);
return next;
}
const valueTexts = resolveDefaultValueTexts(next, templateDefaultData);
if (!valueTexts.length) {
syncLeafNodeFormValue(next, carTypeList);
return next;
}
const inspectionValueList = valueTexts.map((raw, index) =>
buildInspectionValueEntry(next, raw, index + 1),
);
const resolvedInitialValue = inspectionValueList
.map((entry) => String(entry.valueText ?? ""))
.filter((text) => text !== "")
.join(", ");
next.inspectionResultVO = {
...(typeof next.inspectionResultVO === "object" && next.inspectionResultVO
? next.inspectionResultVO
: {}),
inspectionValueList,
};
next.resolvedInitialValue = resolvedInitialValue;
const interactionType = String(next.interactionType ?? "");
if (interactionType === "dropdown" || interactionType === "radio_button_select") {
const first = inspectionValueList[0];
const valueKey = String(first.valueKey ?? "");
const valueText = String(first.valueText ?? "");
next.valueKey = valueKey;
next.valueText = valueText;
next.value =
valueKey || resolveDropdownFormValue(next, valueKey, valueText, carTypeList);
} else if (interactionType === "button_select") {
const entries = inspectionValueList.map((entry) => ({
valueKey: String(entry.valueKey ?? ""),
valueText: String(entry.valueText ?? ""),
}));
next.value = JSON.stringify(entries);
} else {
next.value = normalizeDatePickerValue(
next,
String(inspectionValueList[0].valueText ?? ""),
);
}
return next;
}
/**
* 递归对叶子节点应用解析后的默认值(分组节点会向下遍历 childrenNodes)
*/
export function applyResolvedInitialValuesToLeafNodes(
nodes: Record<string, unknown>[],
templateDefaultData: TemplateDefaultData,
carTypeList: { text: string; value: string }[] = [],
): Record<string, unknown>[] {
return (nodes || []).map((node) => {
if (!isLeafNode(node)) {
const children = (node.childrenNodes as Record<string, unknown>[]) || [];
return {
...node,
childrenNodes: applyResolvedInitialValuesToLeafNodes(
children,
templateDefaultData,
carTypeList,
),
};
}
return applyDefaultsToSingleLeaf(node, templateDefaultData, carTypeList);
});
}
...@@ -66,6 +66,12 @@ export default class DetectionTemplatePage extends PaginationComponent<Inspectio ...@@ -66,6 +66,12 @@ export default class DetectionTemplatePage extends PaginationComponent<Inspectio
}, },
}, },
{ {
title: "模板ID",
dataIndex: "templateCode",
key: "templateCode",
align: "center",
},
{
title: "模板名称", title: "模板名称",
dataIndex: "templateName", dataIndex: "templateName",
key: "templateName", key: "templateName",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!