Commit e97f31e9 by 岑成威

fix: gengxin

1 parent 084e35e7
Pipeline #210 for e97f31e9 failed in 0 seconds
...@@ -225,17 +225,55 @@ function isKeyedSelectInteractionType(interactionType: string | undefined): bool ...@@ -225,17 +225,55 @@ 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 时为年月日,否则年月 */ /** 读取叶子节点 validationRules.datePattern */
function getDatePickerFormat(node: InspectionNode): "year-month" | "year-month-day" { export function getInspectionNodeDatePattern(node: { validationRules?: string }): string {
try { try {
const rules = JSON.parse(node.validationRules || "{}") as { datePattern?: string }; return (
if (rules.datePattern && rules.datePattern.length > 8) { (JSON.parse(node.validationRules || "{}") as { datePattern?: string }).datePattern?.trim() ??
return "year-month-day"; ""
} );
} catch { } catch {
/* ignore */ return "";
}
}
/** 是否需要选「日」:pattern 含 dd,或长度 > 8(如 yyyy-MM-dd);无 pattern 时默认完整日期 */
export function requiresDatePickerDayColumn(datePattern?: string): boolean {
const p = String(datePattern ?? "").trim();
if (!p) return true;
if (/dd/i.test(p)) return true;
return p.length > 8;
}
/** date_picker 展示/提交格式:年月日 yyyy-MM-dd 或年月 yyyy-MM */
export function getDatePickerFormat(node: InspectionNode): "year-month" | "year-month-day" {
return requiresDatePickerDayColumn(getInspectionNodeDatePattern(node))
? "year-month-day"
: "year-month";
}
/** van-date-picker columns-type */
export function getDatePickerColumnsType(node: { validationRules?: string }): ("year" | "month" | "day")[] {
return requiresDatePickerDayColumn(getInspectionNodeDatePattern(node))
? ["year", "month", "day"]
: ["year", "month"];
}
/** 保存前将 date_picker 值规范为接口要求的格式 */
export function formatInspectionDateSubmitValue(
value: string | number | undefined,
node: InspectionNode
): string {
const raw = String(value ?? "").trim();
if (!raw) return "";
if (!requiresDatePickerDayColumn(getInspectionNodeDatePattern(node))) {
const parts = raw.split("-").filter(Boolean);
if (parts.length >= 2) {
return `${parts[0]}-${String(parts[1]).padStart(2, "0")}`;
}
return raw;
} }
return "year-month"; return normalizeInspectionDateDefault(raw, node);
} }
/** 将模板/接口日期(含 ISO、斜杠、紧凑数字)规范为 date_picker 展示格式 */ /** 将模板/接口日期(含 ISO、斜杠、紧凑数字)规范为 date_picker 展示格式 */
......
<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 {
formatInspectionDateSubmitValue,
getInspectionLeafInputInitial, getInspectionLeafInputInitial,
getInspectionLeafSelectInitial, getInspectionLeafSelectInitial,
type InspectionNode, type InspectionNode,
...@@ -99,9 +100,13 @@ function setSubmitData() { ...@@ -99,9 +100,13 @@ function setSubmitData() {
const inputList = ["text_input", "textarea_input", "number_input", "date_picker"]; const inputList = ["text_input", "textarea_input", "number_input", "date_picker"];
const dropdownList = ["dropdown", "radio_button_select"]; const dropdownList = ["dropdown", "radio_button_select"];
if (inputList.includes(item.interactionType) && item.value != null && item.value !== "") { if (inputList.includes(item.interactionType) && item.value != null && item.value !== "") {
const valueText =
item.interactionType === "date_picker"
? formatInspectionDateSubmitValue(item.value, item as InspectionNode)
: String(item.value ?? "");
const pushData = { const pushData = {
id: item.id, id: item.id,
valueText: item.value || "", valueText,
valueKey: "", valueKey: "",
interactionType: item.interactionType, interactionType: item.interactionType,
}; };
......
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, ref } from "vue"; import { formatInspectionDateSubmitValue, getDatePickerColumnsType } from "@api";
import { computed, onMounted, ref, watch } from "vue";
const props = defineProps({ const props = defineProps({
item: { item: {
...@@ -17,24 +18,24 @@ const displayValue = computed({ ...@@ -17,24 +18,24 @@ const displayValue = computed({
get: () => String(props.item.value ?? ""), get: () => String(props.item.value ?? ""),
set: (v: string) => emit("update", v), set: (v: string) => emit("update", v),
}); });
const columnsType = ref(["year", "month", "day"]); const columnsType = ref<("year" | "month" | "day")[]>(["year", "month", "day"]);
const showPicker = ref(false); const showPicker = ref(false);
const pickerValue = ref([]); const pickerValue = ref([]);
// 页面加载时初始化数据 function syncColumnsType() {
columnsType.value = getDatePickerColumnsType(props.item);
}
onMounted(() => { onMounted(() => {
initData(); syncColumnsType();
}); });
// 初始化数据 watch(
function initData() { () => props.item?.validationRules,
const validationRules = JSON.parse(props.item.validationRules || "{}"); () => {
if (validationRules.datePattern && validationRules.datePattern.length > 8) { syncColumnsType();
columnsType.value = ["year", "month", "day"];
} else {
columnsType.value = ["year", "month"];
} }
} );
function clampPickerParts(parts: (number | string)[]): (number | string)[] { function clampPickerParts(parts: (number | string)[]): (number | string)[] {
const year = Number(parts[0]); const year = Number(parts[0]);
...@@ -76,7 +77,7 @@ function onConfirm() { ...@@ -76,7 +77,7 @@ function onConfirm() {
if (pickerValue.value.length > 0) { if (pickerValue.value.length > 0) {
const clamped = clampPickerParts(pickerValue.value); const clamped = clampPickerParts(pickerValue.value);
pickerValue.value = clamped; pickerValue.value = clamped;
picker = clamped.join("-"); picker = formatInspectionDateSubmitValue(clamped.join("-"), props.item);
} }
showPicker.value = false; showPicker.value = false;
emit("update", picker); emit("update", picker);
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
class="inspect-card inspect-card--subtabs"> class="inspect-card inspect-card--subtabs">
<!-- 二级项 Tab:仅当子节点为分组(nodeType=2)等多级结构时展示;叶子直挂大项时不展示 --> <!-- 二级项 Tab:仅当子节点为分组(nodeType=2)等多级结构时展示;叶子直挂大项时不展示 -->
<div v-if="activeBigModule?.hasSecondaryTabs === true" <div v-if="activeBigModule?.hasSecondaryTabs === true"
ref="subtabRowRef"
class="subtab-row"> class="subtab-row">
<div v-for="subTab in activeBigModule?.subTabs" <div v-for="subTab in activeBigModule?.subTabs"
:key="subTab.key" :key="subTab.key"
...@@ -180,7 +181,7 @@ ...@@ -180,7 +181,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { BigModule } from "@/types/views/car-detail"; import type { BigModule } from "@/types/views/car-detail";
import { onMounted, ref, watch } from "vue"; import { nextTick, onMounted, ref, watch } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import customizeForm from "@/components/CustomizeForm/Index.vue"; import customizeForm from "@/components/CustomizeForm/Index.vue";
...@@ -224,6 +225,39 @@ const { ...@@ -224,6 +225,39 @@ const {
onOpenModulePicker, onOpenModulePicker,
} = modules; } = modules;
const subtabRowRef = ref<HTMLElement | null>(null);
/** 下一步 / 上一步 / 检测评分返回等程序切换二级 Tab 时,将当前项滚入横向可视区 */
function scrollActiveSubTabIntoView() {
void nextTick(() => {
void nextTick(() => {
const row = subtabRowRef.value;
if (!row || activeBigModule.value?.hasSecondaryTabs !== true) return;
const activeEl = row.querySelector<HTMLElement>(".subtab-item.active");
activeEl?.scrollIntoView({
behavior: "smooth",
block: "nearest",
inline: "center",
});
});
});
}
watch(
[activeSubKey, activeBigKey],
() => {
if (loading.value || activeBigKey.value === SCORE_BIG_KEY) return;
scrollActiveSubTabIntoView();
},
{ flush: "post" }
);
watch(loading, (isLoading) => {
if (!isLoading) {
scrollActiveSubTabIntoView();
}
});
/** 弹窗内待确认的模块 key,打开时与当前 active 同步 */ /** 弹窗内待确认的模块 key,打开时与当前 active 同步 */
const pendingModuleKey = ref<number | string>(""); const pendingModuleKey = ref<number | string>("");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!