Commit 084e35e7 by 岑成威

fix: 修复bug

1 parent 81238a41
Pipeline #209 for 084e35e7 failed in 0 seconds
...@@ -225,6 +225,101 @@ function isKeyedSelectInteractionType(interactionType: string | undefined): bool ...@@ -225,6 +225,101 @@ function isKeyedSelectInteractionType(interactionType: string | undefined): bool
return KEYED_SELECT_INTERACTION_TYPES.has(interactionType); return KEYED_SELECT_INTERACTION_TYPES.has(interactionType);
} }
/** date_picker:validationRules.datePattern 长度 > 8 时为年月日,否则年月 */
function getDatePickerFormat(node: InspectionNode): "year-month" | "year-month-day" {
try {
const rules = JSON.parse(node.validationRules || "{}") as { datePattern?: string };
if (rules.datePattern && rules.datePattern.length > 8) {
return "year-month-day";
}
} catch {
/* ignore */
}
return "year-month";
}
/** 将模板/接口日期(含 ISO、斜杠、紧凑数字)规范为 date_picker 展示格式 */
export function normalizeInspectionDateDefault(raw: string, node: InspectionNode): string {
const trimmed = String(raw ?? "").trim();
if (!trimmed) return "";
let normalized = trimmed.replace(/\//g, "-");
const isoPrefix = normalized.match(/^(\d{4}-\d{2}-\d{2})/);
if (isoPrefix) {
normalized = isoPrefix[1];
}
const compact = normalized.replace(/\D/g, "");
const format = getDatePickerFormat(node);
if (format === "year-month") {
const dashParts = normalized.split("-").filter(Boolean);
if (dashParts.length >= 2) {
const y = dashParts[0];
const m = dashParts[1].padStart(2, "0");
return `${y}-${m}`;
}
if (compact.length >= 6) {
return `${compact.slice(0, 4)}-${compact.slice(4, 6)}`;
}
return normalized;
}
const dashParts = normalized.split("-").filter(Boolean);
if (dashParts.length >= 3) {
return `${dashParts[0]}-${dashParts[1].padStart(2, "0")}-${dashParts[2].padStart(2, "0")}`;
}
if (dashParts.length === 2) {
return `${dashParts[0]}-${dashParts[1].padStart(2, "0")}-01`;
}
if (compact.length >= 8) {
return `${compact.slice(0, 4)}-${compact.slice(4, 6)}-${compact.slice(6, 8)}`;
}
if (compact.length >= 6) {
return `${compact.slice(0, 4)}-${compact.slice(4, 6)}-01`;
}
return normalized;
}
function normalizeInitialValueText(node: InspectionNode, raw: string): string {
if (node.interactionType === "date_picker") {
return normalizeInspectionDateDefault(raw, node);
}
return raw;
}
/** 叶子是否已有保存过的检测结果(空 VO / 空 valueList 仍视为未保存,可写默认值) */
function hasInspectionResultSavedValues(node: InspectionNode): boolean {
const vo = node.inspectionResultVO;
if (vo === null || vo === undefined) return false;
const list = vo.inspectionValueList;
if (!list?.length) return false;
return list.some((item) => {
const text = String(item?.valueText ?? "").trim();
const key = String(item?.valueKey ?? "").trim();
return text !== "" || key !== "";
});
}
/** seat 默认值:未知 / null / 空 视为无默认值,不回显 */
function isIgnoredSeatDefaultValue(raw: unknown): boolean {
if (raw === undefined || raw === null) return true;
const s = String(raw).trim();
if (s === "" || s.toLowerCase() === "null") return true;
if (s === "未知") return true;
const { valueKey, valueText } = parseKeyedSelectDefault(s);
if (valueText.trim() === "未知") return true;
if (!valueKey && !valueText.trim()) return true;
return false;
}
function filterTemplateDefaultRaw(node: InspectionNode, raw: unknown): unknown {
if (node.nodeCode === "seat" && isIgnoredSeatDefaultValue(raw)) {
return null;
}
return raw;
}
/** 将模板默认值如 `2-私户` 按首个 `-` 拆成 key / 展示文案 */ /** 将模板默认值如 `2-私户` 按首个 `-` 拆成 key / 展示文案 */
export function parseKeyedSelectDefault(raw: string): { valueKey: string; valueText: string } { export function parseKeyedSelectDefault(raw: string): { valueKey: string; valueText: string } {
const i = raw.indexOf("-"); const i = raw.indexOf("-");
...@@ -251,15 +346,19 @@ export function resolveInspectionNodeInitialValueTexts( ...@@ -251,15 +346,19 @@ export function resolveInspectionNodeInitialValueTexts(
const type = Number(node.defaultType); const type = Number(node.defaultType);
if (type === 1) { if (type === 1) {
return [node.defaultValue ?? ""]; const raw = filterTemplateDefaultRaw(node, node.defaultValue ?? "");
if (raw === null || raw === undefined) return [];
return [String(raw)];
} }
if (type === 2) { if (type === 2) {
const code = node.nodeCode; const code = node.nodeCode;
if (!code || !templateDefaultData) return []; if (!code || !templateDefaultData) return [];
const raw = (templateDefaultData as Record<string, unknown>)[code]; const raw = filterTemplateDefaultRaw(node, (templateDefaultData as Record<string, unknown>)[code]);
if (raw === undefined || raw === null) return []; if (raw === undefined || raw === null) return [];
if (Array.isArray(raw)) { if (Array.isArray(raw)) {
return raw.map((item) => (item === undefined || item === null ? "" : String(item))); return raw
.map((item) => (item === undefined || item === null ? "" : String(item)))
.filter((item) => !(node.nodeCode === "seat" && isIgnoredSeatDefaultValue(item)));
} }
return [String(raw)]; return [String(raw)];
} }
...@@ -267,7 +366,9 @@ export function resolveInspectionNodeInitialValueTexts( ...@@ -267,7 +366,9 @@ export function resolveInspectionNodeInitialValueTexts(
return []; return [];
} }
if (node.defaultValue !== undefined && node.defaultValue !== null) { if (node.defaultValue !== undefined && node.defaultValue !== null) {
return [String(node.defaultValue)]; const raw = filterTemplateDefaultRaw(node, node.defaultValue);
if (raw === null || raw === undefined) return [];
return [String(raw)];
} }
return []; return [];
} }
...@@ -337,6 +438,24 @@ export function getInspectionLeafSelectInitial(node: InspectionNode): { ...@@ -337,6 +438,24 @@ export function getInspectionLeafSelectInitial(node: InspectionNode): {
return empty; return empty;
} }
/**
* 文本/数字/日期类叶子控件初始 value(检测结果 → resolvedInitialValue)
*/
export function getInspectionLeafInputInitial(node: InspectionNode): string {
const list = node.inspectionResultVO?.inspectionValueList;
if (list?.length) {
const text = String(list[0]?.valueText ?? "").trim();
if (text) {
return normalizeInitialValueText(node, text);
}
}
const raw = node.resolvedInitialValue;
if (raw) {
return normalizeInitialValueText(node, String(raw));
}
return "";
}
function buildInspectionResultVOFromDefaults(node: InspectionNode, valueTexts: string[]): InspectionResultVO { function buildInspectionResultVOFromDefaults(node: InspectionNode, valueTexts: string[]): InspectionResultVO {
const keyed = isKeyedSelectInteractionType(node.interactionType); const keyed = isKeyedSelectInteractionType(node.interactionType);
const inspectionValueList: InspectionValueItem[] = valueTexts.map((raw, index) => { const inspectionValueList: InspectionValueItem[] = valueTexts.map((raw, index) => {
...@@ -388,11 +507,13 @@ export function applyResolvedInitialValuesToLeafNodes( ...@@ -388,11 +507,13 @@ export function applyResolvedInitialValuesToLeafNodes(
): InspectionNode[] { ): InspectionNode[] {
if (!leafNodes?.length) return []; if (!leafNodes?.length) return [];
return leafNodes.map((node) => { return leafNodes.map((node) => {
if (node.inspectionResultVO !== null && node.inspectionResultVO !== undefined) { if (hasInspectionResultSavedValues(node)) {
return { ...node }; return { ...node };
} }
const valueTexts = resolveInspectionNodeInitialValueTexts(node, templateDefaultData); const valueTexts = resolveInspectionNodeInitialValueTexts(node, templateDefaultData).map((raw) =>
if (valueTexts.length === 0) { normalizeInitialValueText(node, raw)
);
if (valueTexts.length === 0 || valueTexts.every((t) => !String(t).trim())) {
return { ...node }; return { ...node };
} }
const resolvedInitialValue = valueTexts.length === 1 ? valueTexts[0] : valueTexts.join(", "); const resolvedInitialValue = valueTexts.length === 1 ? valueTexts[0] : valueTexts.join(", ");
......
<script setup lang="ts"> <script setup lang="ts">
import type { CustomizeFormValidateResult } from "@/types/views/car-detail"; import type { CustomizeFormValidateResult } from "@/types/views/car-detail";
import { import {
getInspectionLeafInputInitial,
getInspectionLeafSelectInitial, getInspectionLeafSelectInitial,
type InspectionNode, type InspectionNode,
type InspectionTemplateDefaultData, type InspectionTemplateDefaultData,
...@@ -49,20 +50,6 @@ const pageLoading = ref(false); ...@@ -49,20 +50,6 @@ const pageLoading = ref(false);
const SELECT_INTERACTION_TYPES = new Set(["dropdown", "radio_button_select"]); const SELECT_INTERACTION_TYPES = new Set(["dropdown", "radio_button_select"]);
function getValueText(item: InspectionNode) {
let valueText = "";
if (item?.inspectionResultVO) {
const inspectionValueList = item?.inspectionResultVO?.inspectionValueList || [];
if (inspectionValueList && inspectionValueList.length > 0) {
const inputList = ["text_input", "textarea_input", "number_input", "date_picker"];
if (inputList.includes(String(item.interactionType ?? ""))) {
valueText = inspectionValueList[0]?.valueText || "";
}
}
}
return valueText;
}
function mapLeafNodeToColumnRow(item: InspectionNode): InspectionColumnRow { function mapLeafNodeToColumnRow(item: InspectionNode): InspectionColumnRow {
const row: InspectionColumnRow = { const row: InspectionColumnRow = {
...item, ...item,
...@@ -76,7 +63,7 @@ function mapLeafNodeToColumnRow(item: InspectionNode): InspectionColumnRow { ...@@ -76,7 +63,7 @@ function mapLeafNodeToColumnRow(item: InspectionNode): InspectionColumnRow {
row.valueText = valueText; row.valueText = valueText;
return row; return row;
} }
row.value = getValueText(item); row.value = getInspectionLeafInputInitial(item);
return row; return row;
} }
......
...@@ -13,6 +13,7 @@ const keywordInput = ref(""); ...@@ -13,6 +13,7 @@ const keywordInput = ref("");
/** 点击「搜索」后生效的查询词 */ /** 点击「搜索」后生效的查询词 */
const searchKeyword = ref(""); const searchKeyword = ref("");
const refreshing = ref(false); const refreshing = ref(false);
const searchLoading = ref(false);
const loading = ref(false); const loading = ref(false);
const finished = ref(false); const finished = ref(false);
const pageSize = 10; const pageSize = 10;
...@@ -100,23 +101,41 @@ async function fillMore() { ...@@ -100,23 +101,41 @@ async function fillMore() {
} }
function onLoad() { function onLoad() {
if (refreshing.value) {
loading.value = false;
return;
}
void fillMore(); void fillMore();
} }
let refreshTask: Promise<void> | null = null;
async function onRefresh() { async function onRefresh() {
// 勿在开头判断 refreshing:PullRefresh 触发 @refresh 时 v-model 已为 true,会误 return 且无法执行 finally,下拉一直转圈 if (refreshTask) {
return refreshTask;
}
refreshing.value = true; refreshing.value = true;
refreshTask = (async () => {
try { try {
resetList(); resetList();
await fillMore(); await fillMore();
} finally { } finally {
refreshing.value = false; refreshing.value = false;
refreshTask = null;
} }
})();
return refreshTask;
} }
function onSearch() { async function onSearch() {
if (refreshTask) return;
searchLoading.value = true;
searchKeyword.value = keywordInput.value.trim(); searchKeyword.value = keywordInput.value.trim();
void onRefresh(); try {
await onRefresh();
} finally {
searchLoading.value = false;
}
} }
function onClearKeyword() { function onClearKeyword() {
...@@ -167,11 +186,15 @@ onActivated(() => { ...@@ -167,11 +186,15 @@ onActivated(() => {
size="18" /> size="18" />
</button> </button>
</div> </div>
<button class="round-search__submit" <van-button class="round-search__submit"
type="button" color="#185efe"
:disabled="searchLoading || refreshing"
:loading="searchLoading"
round
size="small"
@click="onSearch"> @click="onSearch">
搜索 搜索
</button> </van-button>
</div> </div>
</div> </div>
</PageTop> </PageTop>
...@@ -325,14 +348,15 @@ onActivated(() => { ...@@ -325,14 +348,15 @@ onActivated(() => {
flex-shrink: 0; flex-shrink: 0;
height: 34px; height: 34px;
padding: 0 14px; padding: 0 14px;
border: 0;
}
:deep(.round-search__submit.van-button) {
height: 34px;
padding: 0 14px;
font-size: 14px; font-size: 14px;
font-weight: 500; font-weight: 500;
line-height: 34px; line-height: 34px;
color: #fff;
cursor: pointer;
background: #185efe;
border: 0;
border-radius: 999px;
} }
.list-wrap { .list-wrap {
......
...@@ -15,6 +15,7 @@ const keywordInput = ref(""); ...@@ -15,6 +15,7 @@ const keywordInput = ref("");
const searchKeyword = ref(""); const searchKeyword = ref("");
const activeStatus = ref<WorkOrderStatus>(1); const activeStatus = ref<WorkOrderStatus>(1);
const refreshing = ref(false); const refreshing = ref(false);
const searchLoading = ref(false);
const loading = ref(false); const loading = ref(false);
const finished = ref(false); const finished = ref(false);
const pageSize = 20; const pageSize = 20;
...@@ -139,19 +140,34 @@ async function onLoad() { ...@@ -139,19 +140,34 @@ async function onLoad() {
} }
} }
let refreshTask: Promise<void> | null = null;
async function onRefresh() { async function onRefresh() {
if (refreshTask) {
return refreshTask;
}
refreshing.value = true; refreshing.value = true;
refreshTask = (async () => {
try { try {
resetList(); resetList();
await Promise.all([fetchTabCounts(), fillMore()]); await Promise.all([fetchTabCounts(), fillMore()]);
} finally { } finally {
refreshing.value = false; refreshing.value = false;
refreshTask = null;
} }
})();
return refreshTask;
} }
function onSearch() { async function onSearch() {
if (refreshTask) return;
searchLoading.value = true;
searchKeyword.value = keywordInput.value.trim(); searchKeyword.value = keywordInput.value.trim();
void onRefresh(); try {
await onRefresh();
} finally {
searchLoading.value = false;
}
} }
function onClearKeyword() { function onClearKeyword() {
...@@ -316,11 +332,15 @@ void onRefresh(); ...@@ -316,11 +332,15 @@ void onRefresh();
size="18" /> size="18" />
</button> </button>
</div> </div>
<button class="round-search__submit" <van-button class="round-search__submit"
type="button" color="#185efe"
:disabled="searchLoading || refreshing"
:loading="searchLoading"
round
size="small"
@click="onSearch"> @click="onSearch">
搜索 搜索
</button> </van-button>
</div> </div>
</div> </div>
</PageTop> </PageTop>
...@@ -549,14 +569,15 @@ void onRefresh(); ...@@ -549,14 +569,15 @@ void onRefresh();
flex-shrink: 0; flex-shrink: 0;
height: 34px; height: 34px;
padding: 0 14px; padding: 0 14px;
border: 0;
}
:deep(.round-search__submit.van-button) {
height: 34px;
padding: 0 14px;
font-size: 14px; font-size: 14px;
font-weight: 500; font-weight: 500;
line-height: 34px; line-height: 34px;
color: #fff;
cursor: pointer;
background: #185efe;
border: 0;
border-radius: 999px;
} }
.list-wrap { .list-wrap {
......
...@@ -377,7 +377,7 @@ onMounted(() => { ...@@ -377,7 +377,7 @@ onMounted(() => {
:src="CDN.certification" /> :src="CDN.certification" />
</div> </div>
<div class="cert-info"> <div class="cert-info">
<span class="cert-title">广联认证检测</span> <span class="cert-title">优加认证检测</span>
<span class="cert-sub">官方认证</span> <span class="cert-sub">官方认证</span>
</div> </div>
</div> </div>
...@@ -642,7 +642,7 @@ onMounted(() => { ...@@ -642,7 +642,7 @@ onMounted(() => {
<span class="video-info__mark">*</span> <span class="video-info__mark">*</span>
<span class="video-info__label">检测机构:</span> <span class="video-info__label">检测机构:</span>
</div> </div>
<span class="video-info__value">广联认证</span> <span class="video-info__value">优加认证</span>
</div> </div>
<div class="video-info__item"> <div class="video-info__item">
<div class="video-info__lead"> <div class="video-info__lead">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!