fix(系统设置): 仓库设置支持嵌套 object 子项,售后跟进时间不再渲染为 [object Object]
- 新增 ObjectFieldEditor.vue:object 字段按 meta itemFields 递归渲染(bool/select/color/number/string),
嵌套 object 不再退化成文本框 String(对象);留空表示「跟随服务端默认」,提交时不写入该键
- WarehouseSettingsForm.vue:object 字段改用递归编辑器并整体回写;ensureFieldDefaults 不再为嵌套 object 预填二级值;
顺带修掉模板 `as number | undefined` 触发的 vue/no-deprecated-filter 与 v-loading 属性顺序告警
- settingwarehouse.ts normalizeSchemaValue 增加 depth(顶层=1):
* 扁平标量(如 order: "24")归一为 { _default: 24 },不再被内层默认值覆盖丢值
* 嵌套 object 无实际值或归一化后为空则不写入该键
* 嵌套层叶子缺省不注入 meta 默认(留空 = 跟随服务端默认)
This commit is contained in:
parent
c926beb226
commit
2fe9a2c844
@ -211,12 +211,31 @@ function schemaFlagValue(value: unknown, fallback: unknown): boolean {
|
|||||||
|
|
||||||
const SCHEMA_FLAG_TYPES = new Set(['flag', 'boolean', 'bool', 'switch'])
|
const SCHEMA_FLAG_TYPES = new Set(['flag', 'boolean', 'bool', 'switch'])
|
||||||
const SCHEMA_NUMBER_TYPES = new Set(['number', 'integer', 'int', 'float', 'decimal'])
|
const SCHEMA_NUMBER_TYPES = new Set(['number', 'integer', 'int', 'float', 'decimal'])
|
||||||
|
/** 嵌套 object(如售后跟进时间)里代表「该类型默认值」的子键 */
|
||||||
|
const SCHEMA_DEFAULT_SUB_KEY = '_default'
|
||||||
|
/** 嵌套 object 叶子所在层级:缺省视作「未覆盖」,不注入 meta 默认值(留空 = 跟随服务端默认) */
|
||||||
|
const NESTED_LEAF_DEPTH = 3
|
||||||
|
|
||||||
/** 按字段 schema 归一化单个值;返回 undefined 表示该键不写入 */
|
function isPlainObjectValue(value: unknown): value is Record<string, unknown> {
|
||||||
|
return !!value && typeof value === 'object' && !Array.isArray(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 是否为「扁平标量」配置值(数字或非空字符串) */
|
||||||
|
function isScalarConfigValue(value: unknown): boolean {
|
||||||
|
if (typeof value === 'number') return Number.isFinite(value)
|
||||||
|
if (typeof value === 'string') return value.trim() !== ''
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字段 schema 归一化单个值;返回 undefined 表示该键不写入。
|
||||||
|
* depth 为当前字段在配置树中的层级(顶层字段 depth=1),用于区分「一级 object」与「嵌套 object」。
|
||||||
|
*/
|
||||||
function normalizeSchemaValue(
|
function normalizeSchemaValue(
|
||||||
value: unknown,
|
value: unknown,
|
||||||
field: WarehouseSubjectFieldSchema,
|
field: WarehouseSubjectFieldSchema,
|
||||||
present: boolean
|
present: boolean,
|
||||||
|
depth = 1
|
||||||
): unknown {
|
): unknown {
|
||||||
const type = String(field.type ?? '').toLowerCase()
|
const type = String(field.type ?? '').toLowerCase()
|
||||||
const fallback = field.defaultValue !== undefined ? field.defaultValue : field.default
|
const fallback = field.defaultValue !== undefined ? field.defaultValue : field.default
|
||||||
@ -224,12 +243,14 @@ function normalizeSchemaValue(
|
|||||||
|
|
||||||
// flag / boolean:兼容 true|false、1|0、'1'|'0',非法或缺省回退默认
|
// flag / boolean:兼容 true|false、1|0、'1'|'0',非法或缺省回退默认
|
||||||
if (SCHEMA_FLAG_TYPES.has(type)) {
|
if (SCHEMA_FLAG_TYPES.has(type)) {
|
||||||
if (!present && fallback === undefined) return undefined
|
if (!present && (fallback === undefined || depth >= NESTED_LEAF_DEPTH)) return undefined
|
||||||
return schemaFlagValue(present ? value : fallback, fallback)
|
return schemaFlagValue(present ? value : fallback, fallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
// number / integer:非法或缺省回退默认(无默认则不写入)
|
// number / integer:非法或缺省回退默认(无默认则不写入)
|
||||||
if (SCHEMA_NUMBER_TYPES.has(type)) {
|
if (SCHEMA_NUMBER_TYPES.has(type)) {
|
||||||
|
// 嵌套 object 的叶子(如售后跟进时间的各子类型)缺省时视为「未覆盖」:不写入、不注入默认值
|
||||||
|
if (!present && depth >= NESTED_LEAF_DEPTH) return undefined
|
||||||
const num = Number(present ? value : fallback)
|
const num = Number(present ? value : fallback)
|
||||||
if (Number.isFinite(num)) return num
|
if (Number.isFinite(num)) return num
|
||||||
return fallback === undefined ? undefined : fallback
|
return fallback === undefined ? undefined : fallback
|
||||||
@ -238,13 +259,22 @@ function normalizeSchemaValue(
|
|||||||
// object:只保留 schema(meta item_keys)里声明的子项,逐项递归
|
// object:只保留 schema(meta item_keys)里声明的子项,逐项递归
|
||||||
if (type === 'object') {
|
if (type === 'object') {
|
||||||
if (!children.length) return present ? value : fallback
|
if (!children.length) return present ? value : fallback
|
||||||
const source =
|
// 后端可能用「扁平标量」表示该类型下所有子类型同值(等价于只设置 _default),
|
||||||
value && typeof value === 'object' && !Array.isArray(value)
|
// 例如 after_sale_followup_hours.order = "24";必须优先识别,否则会被内层默认值覆盖。
|
||||||
? (value as Record<string, unknown>)
|
if (present && isScalarConfigValue(value)) {
|
||||||
: fallback && typeof fallback === 'object' && !Array.isArray(fallback)
|
const defaultChild = children.find((child) => child.key === SCHEMA_DEFAULT_SUB_KEY)
|
||||||
? (fallback as Record<string, unknown>)
|
if (!defaultChild) return value
|
||||||
: {}
|
const normalized = normalizeSchemaValue(value, defaultChild, true, depth + 1)
|
||||||
return normalizeSchemaObject(source, children)
|
return normalized === undefined ? value : { [SCHEMA_DEFAULT_SUB_KEY]: normalized }
|
||||||
|
}
|
||||||
|
const source = isPlainObjectValue(value) ? value : isPlainObjectValue(fallback) ? fallback : null
|
||||||
|
// 嵌套 object(depth>=2)没有任何实际值时视为「未覆盖」:既不写入,也不注入内层默认值,
|
||||||
|
// 交给服务端按 meta 默认处理(页面据此显示为留空)。
|
||||||
|
if (!source) return depth >= 2 ? undefined : normalizeSchemaObject({}, children, depth + 1)
|
||||||
|
const normalized = normalizeSchemaObject(source, children, depth + 1)
|
||||||
|
// 嵌套 object 归一化后为空(子项均未覆盖)→ 不写入该键
|
||||||
|
if (depth >= 2 && Object.keys(normalized).length === 0) return undefined
|
||||||
|
return normalized
|
||||||
}
|
}
|
||||||
|
|
||||||
// array:逐项按子项 schema 归一化
|
// array:逐项按子项 schema 归一化
|
||||||
@ -252,9 +282,7 @@ function normalizeSchemaValue(
|
|||||||
const list = Array.isArray(value) ? value : Array.isArray(fallback) ? fallback : []
|
const list = Array.isArray(value) ? value : Array.isArray(fallback) ? fallback : []
|
||||||
if (!children.length) return list
|
if (!children.length) return list
|
||||||
return list.map((item) =>
|
return list.map((item) =>
|
||||||
item && typeof item === 'object' && !Array.isArray(item)
|
isPlainObjectValue(item) ? normalizeSchemaObject(item, children, depth + 1) : item
|
||||||
? normalizeSchemaObject(item as Record<string, unknown>, children)
|
|
||||||
: item
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,19 +295,20 @@ function normalizeSchemaValue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// string / color / select / location:有值原样保留,缺省用默认
|
// string / color / select / location:有值原样保留,缺省用默认
|
||||||
if (!present) return fallback
|
if (!present) return depth >= NESTED_LEAF_DEPTH ? undefined : fallback
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 按子项 schema 递归归一化对象(只保留 schema 中声明的子项) */
|
/** 按子项 schema 递归归一化对象(只保留 schema 中声明的子项);depth 为子项所在层级 */
|
||||||
function normalizeSchemaObject(
|
function normalizeSchemaObject(
|
||||||
source: Record<string, unknown>,
|
source: Record<string, unknown>,
|
||||||
children: WarehouseSubjectFieldSchema[]
|
children: WarehouseSubjectFieldSchema[],
|
||||||
|
depth = 1
|
||||||
): Record<string, unknown> {
|
): Record<string, unknown> {
|
||||||
const out: Record<string, unknown> = {}
|
const out: Record<string, unknown> = {}
|
||||||
for (const child of children) {
|
for (const child of children) {
|
||||||
if (!child?.key) continue
|
if (!child?.key) continue
|
||||||
const normalized = normalizeSchemaValue(source[child.key], child, child.key in source)
|
const normalized = normalizeSchemaValue(source[child.key], child, child.key in source, depth)
|
||||||
if (normalized !== undefined) out[child.key] = normalized
|
if (normalized !== undefined) out[child.key] = normalized
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|||||||
@ -0,0 +1,197 @@
|
|||||||
|
<!--
|
||||||
|
ObjectFieldEditor — 仓库设置 object 字段编辑器(支持任意层级嵌套 object)
|
||||||
|
|
||||||
|
用于 WarehouseSettingsForm.vue:「售后跟进时间(h)」这类 object 里还套 object 的字段。
|
||||||
|
- 子项集合完全来自 getFieldMeta 的 item_keys(由 normalizeFieldMetaItem 递归解析),不硬编码 key;
|
||||||
|
- 子项类型是 object 且带 itemFields 时递归渲染自己(不再退化成 el-input 显示 [object Object]);
|
||||||
|
- 数值 / 文本子项留空表示「未覆盖,跟随服务端默认」,提交时该键不写入。
|
||||||
|
-->
|
||||||
|
<template>
|
||||||
|
<div class="object-field-editor">
|
||||||
|
<div v-for="sub in fields" :key="sub.key" class="object-field-editor__item">
|
||||||
|
<div class="object-field-editor__row">
|
||||||
|
<span class="object-field-editor__label" :title="sub.description">{{ sub.label }}</span>
|
||||||
|
|
||||||
|
<el-switch
|
||||||
|
v-if="sub.type === 'boolean'"
|
||||||
|
:model-value="Boolean(value[sub.key])"
|
||||||
|
:active-value="true"
|
||||||
|
:inactive-value="false"
|
||||||
|
@update:model-value="onChange(sub.key, $event)"
|
||||||
|
/>
|
||||||
|
<el-select
|
||||||
|
v-else-if="sub.type === 'select'"
|
||||||
|
:model-value="selectValue(sub.key)"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
placeholder="请选择"
|
||||||
|
class="object-field-editor__control"
|
||||||
|
@update:model-value="onChange(sub.key, $event)"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="opt in sub.options || []"
|
||||||
|
:key="`${sub.key}-${String(opt.value)}`"
|
||||||
|
:label="opt.label"
|
||||||
|
:value="opt.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
<el-color-picker
|
||||||
|
v-else-if="sub.type === 'color'"
|
||||||
|
:model-value="String(value[sub.key] ?? '')"
|
||||||
|
show-alpha
|
||||||
|
:predefine="PREDEFINED_COLORS"
|
||||||
|
@update:model-value="onChange(sub.key, $event)"
|
||||||
|
/>
|
||||||
|
<el-input-number
|
||||||
|
v-else-if="sub.type === 'number'"
|
||||||
|
:model-value="numberValue(sub.key)"
|
||||||
|
:min="sub.min"
|
||||||
|
:max="sub.max"
|
||||||
|
:step="sub.step ?? 1"
|
||||||
|
:precision="sub.precision"
|
||||||
|
controls-position="right"
|
||||||
|
:placeholder="placeholderOf(sub)"
|
||||||
|
class="object-field-editor__control"
|
||||||
|
@update:model-value="onChange(sub.key, $event)"
|
||||||
|
/>
|
||||||
|
<ObjectFieldEditor
|
||||||
|
v-else-if="sub.type === 'object' && sub.itemFields && sub.itemFields.length"
|
||||||
|
:fields="sub.itemFields"
|
||||||
|
:model-value="objectValue(sub.key)"
|
||||||
|
class="object-field-editor__nested"
|
||||||
|
@update:model-value="onChange(sub.key, $event)"
|
||||||
|
/>
|
||||||
|
<el-input
|
||||||
|
v-else
|
||||||
|
:model-value="String(value[sub.key] ?? '')"
|
||||||
|
size="small"
|
||||||
|
clearable
|
||||||
|
:maxlength="sub.maxLength"
|
||||||
|
:placeholder="placeholderOf(sub)"
|
||||||
|
class="object-field-editor__control"
|
||||||
|
@update:model-value="onChange(sub.key, $event)"
|
||||||
|
/>
|
||||||
|
<span v-if="sub.description" class="object-field-editor__desc">{{ sub.description }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed } from 'vue'
|
||||||
|
|
||||||
|
defineOptions({ name: 'ObjectFieldEditor' })
|
||||||
|
|
||||||
|
/** 与 WarehouseSettingsForm 的 NormalizedField 结构一致(子集),便于父页直接传入 itemFields */
|
||||||
|
type ObjectEditorField = {
|
||||||
|
key: string
|
||||||
|
label: string
|
||||||
|
type: 'number' | 'string' | 'boolean' | 'select' | 'array' | 'string_array' | 'color' | 'object' | 'location'
|
||||||
|
description?: string
|
||||||
|
min?: number
|
||||||
|
max?: number
|
||||||
|
step?: number
|
||||||
|
precision?: number
|
||||||
|
maxLength?: number
|
||||||
|
defaultValue?: unknown
|
||||||
|
itemFields?: ObjectEditorField[]
|
||||||
|
options?: { label: string; value: string | number | boolean }[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const PREDEFINED_COLORS = ['#ff4d4f', '#ff7a45', '#faad14', '#fadb14', '#95de64', '#52c41a']
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
fields: ObjectEditorField[]
|
||||||
|
modelValue?: Record<string, unknown> | null
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'update:modelValue', value: Record<string, unknown>): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const value = computed<Record<string, unknown>>(() =>
|
||||||
|
props.modelValue && typeof props.modelValue === 'object' ? props.modelValue : {}
|
||||||
|
)
|
||||||
|
|
||||||
|
function numberValue(key: string): number | undefined {
|
||||||
|
const raw = value.value[key]
|
||||||
|
if (raw === undefined || raw === null || raw === '') return undefined
|
||||||
|
const num = Number(raw)
|
||||||
|
return Number.isFinite(num) ? num : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function objectValue(key: string): Record<string, unknown> {
|
||||||
|
const raw = value.value[key]
|
||||||
|
return raw && typeof raw === 'object' && !Array.isArray(raw)
|
||||||
|
? (raw as Record<string, unknown>)
|
||||||
|
: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** select 当前值(避免在模板里写 `as string | number`——`|` 会被当作已废弃的 filter 语法) */
|
||||||
|
function selectValue(key: string): string | number | boolean | undefined {
|
||||||
|
const raw = value.value[key]
|
||||||
|
if (raw === undefined || raw === null) return undefined
|
||||||
|
if (typeof raw === 'string' || typeof raw === 'number' || typeof raw === 'boolean') return raw
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function placeholderOf(sub: ObjectEditorField): string {
|
||||||
|
const def = sub.defaultValue
|
||||||
|
if (def === undefined || def === null || def === '') return '留空'
|
||||||
|
return `默认 ${String(def)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单层更新:只改当前这一层的一个子键,返回新对象(嵌套层由子组件自己维护,最终整体冒泡到页面)。
|
||||||
|
* 清空(undefined / null / '')时删除该键,表示「未覆盖」,避免把空值提交给后端。
|
||||||
|
*/
|
||||||
|
function onChange(key: string, next: unknown) {
|
||||||
|
const out: Record<string, unknown> = { ...value.value }
|
||||||
|
if (next === undefined || next === null || next === '') delete out[key]
|
||||||
|
else out[key] = next
|
||||||
|
emit('update:modelValue', out)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.object-field-editor {
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
&__item {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__label {
|
||||||
|
flex: 0 0 120px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #606266;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__control {
|
||||||
|
width: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 嵌套 object:换行后整块缩进,用左侧细线体现层级 */
|
||||||
|
&__nested {
|
||||||
|
flex: 1 1 100%;
|
||||||
|
width: auto;
|
||||||
|
max-width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 4px 0 4px 120px;
|
||||||
|
padding-left: 12px;
|
||||||
|
border-left: 2px solid #ebeef5;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__desc {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -7,7 +7,7 @@
|
|||||||
viewType='form' 渲染替换默认的列表结构。
|
viewType='form' 渲染替换默认的列表结构。
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<div class="warehouse-settings-form" v-loading="pageLoading">
|
<div v-loading="pageLoading" class="warehouse-settings-form">
|
||||||
<!-- 顶部固定区:仅标题(操作按钮统一放在底部固定条,避免头尾重复) -->
|
<!-- 顶部固定区:仅标题(操作按钮统一放在底部固定条,避免头尾重复) -->
|
||||||
<div class="settings-header">
|
<div class="settings-header">
|
||||||
<div class="header-text">
|
<div class="header-text">
|
||||||
@ -111,7 +111,7 @@
|
|||||||
/>
|
/>
|
||||||
<el-input-number
|
<el-input-number
|
||||||
v-else-if="itemField.type === 'number'"
|
v-else-if="itemField.type === 'number'"
|
||||||
:model-value="getArrayObjectFieldValue(item, itemField.key) as number | undefined"
|
:model-value="numberCellValue(item, itemField.key)"
|
||||||
:min="itemField.min"
|
:min="itemField.min"
|
||||||
:max="itemField.max"
|
:max="itemField.max"
|
||||||
:step="itemField.step ?? 1"
|
:step="itemField.step ?? 1"
|
||||||
@ -188,31 +188,12 @@
|
|||||||
controls-position="right"
|
controls-position="right"
|
||||||
placeholder="未设置则留空"
|
placeholder="未设置则留空"
|
||||||
/>
|
/>
|
||||||
<div v-else-if="field.type === 'object' && field.itemFields && field.itemFields.length" class="object-editor">
|
<div v-else-if="field.type === 'object' && field.itemFields && field.itemFields.length" class="object-field-block">
|
||||||
<div
|
<ObjectFieldEditor
|
||||||
v-for="itemKey in field.itemFields"
|
:fields="field.itemFields"
|
||||||
:key="`${field.key}-${itemKey.key}`"
|
:model-value="getObjectFieldValue(field.key)"
|
||||||
class="object-editor__row"
|
@update:model-value="onObjectFieldChange(field.key, $event)"
|
||||||
>
|
/>
|
||||||
<span class="object-editor__label">{{ itemKey.label }}</span>
|
|
||||||
<el-switch
|
|
||||||
v-if="itemKey.type === 'boolean'"
|
|
||||||
:model-value="getObjectFieldValue(field.key, itemKey.key) as boolean"
|
|
||||||
:active-value="true"
|
|
||||||
:inactive-value="false"
|
|
||||||
@update:model-value="onObjectFieldChange(field.key, itemKey.key, $event)"
|
|
||||||
/>
|
|
||||||
<el-input
|
|
||||||
v-else
|
|
||||||
:model-value="String(getObjectFieldValue(field.key, itemKey.key) ?? '')"
|
|
||||||
size="small"
|
|
||||||
style="width:200px"
|
|
||||||
:maxlength="itemKey.maxLength"
|
|
||||||
placeholder="请输入"
|
|
||||||
@update:model-value="onObjectFieldChange(field.key, itemKey.key, $event)"
|
|
||||||
/>
|
|
||||||
<span v-if="itemKey.description" class="object-editor__desc">{{ itemKey.description }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<SpacePicker
|
<SpacePicker
|
||||||
v-else-if="field.type === 'location'"
|
v-else-if="field.type === 'location'"
|
||||||
@ -250,6 +231,7 @@
|
|||||||
import { computed, reactive, ref } from 'vue'
|
import { computed, reactive, ref } from 'vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import SpacePicker from '@/components/SpacePicker/index.vue'
|
import SpacePicker from '@/components/SpacePicker/index.vue'
|
||||||
|
import ObjectFieldEditor from '../components/ObjectFieldEditor.vue'
|
||||||
import {
|
import {
|
||||||
settingWarehouseGetSettings,
|
settingWarehouseGetSettings,
|
||||||
settingWarehouseGetFieldMeta,
|
settingWarehouseGetFieldMeta,
|
||||||
@ -465,6 +447,15 @@ function ensureFieldDefaults(target: Record<string, unknown>, fields: Normalized
|
|||||||
const obj = current && typeof current === 'object' && !Array.isArray(current)
|
const obj = current && typeof current === 'object' && !Array.isArray(current)
|
||||||
? { ...(current as Record<string, unknown>) } : ({} as Record<string, unknown>)
|
? { ...(current as Record<string, unknown>) } : ({} as Record<string, unknown>)
|
||||||
for (const sub of f.itemFields) {
|
for (const sub of f.itemFields) {
|
||||||
|
// 嵌套 object(如售后跟进时间的 订单/收货单/入库单/出库单):只保证容器存在,
|
||||||
|
// 二级子项不预填默认值 —— 留空即表示「跟随服务端默认」,避免把 24/4/4… 全部写成显式值
|
||||||
|
if (sub.type === 'object' && sub.itemFields?.length) {
|
||||||
|
const nested = obj[sub.key]
|
||||||
|
obj[sub.key] = nested && typeof nested === 'object' && !Array.isArray(nested)
|
||||||
|
? { ...(nested as Record<string, unknown>) }
|
||||||
|
: {}
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (!(sub.key in obj)) {
|
if (!(sub.key in obj)) {
|
||||||
if (sub.type === 'boolean') obj[sub.key] = sub.defaultValue === true
|
if (sub.type === 'boolean') obj[sub.key] = sub.defaultValue === true
|
||||||
else if (sub.defaultValue !== undefined) obj[sub.key] = cloneValue(sub.defaultValue)
|
else if (sub.defaultValue !== undefined) obj[sub.key] = cloneValue(sub.defaultValue)
|
||||||
@ -572,6 +563,14 @@ function getArrayObjectFieldValue(item: unknown, childKey: string): unknown {
|
|||||||
return (item as Record<string, unknown>)[childKey]
|
return (item as Record<string, unknown>)[childKey]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 数组项里的数字列值(避免在模板里写 `as number | undefined`——`|` 会被当作已废弃的 filter 语法) */
|
||||||
|
function numberCellValue(item: unknown, childKey: string): number | undefined {
|
||||||
|
const raw = getArrayObjectFieldValue(item, childKey)
|
||||||
|
if (raw === undefined || raw === null || raw === '') return undefined
|
||||||
|
const num = Number(raw)
|
||||||
|
return Number.isFinite(num) ? num : undefined
|
||||||
|
}
|
||||||
|
|
||||||
function onArrayObjectItemInput(field: NormalizedField, index: number, childKey: string, value: string | number | boolean | null | undefined) {
|
function onArrayObjectItemInput(field: NormalizedField, index: number, childKey: string, value: string | number | boolean | null | undefined) {
|
||||||
const list = [...getArrayFieldItems(field.key)]
|
const list = [...getArrayFieldItems(field.key)]
|
||||||
const current = list[index]
|
const current = list[index]
|
||||||
@ -581,17 +580,16 @@ function onArrayObjectItemInput(field: NormalizedField, index: number, childKey:
|
|||||||
subjectConfig[field.key] = list
|
subjectConfig[field.key] = list
|
||||||
}
|
}
|
||||||
|
|
||||||
function getObjectFieldValue(fieldKey: string, subKey: string): unknown {
|
function getObjectFieldValue(fieldKey: string): Record<string, unknown> {
|
||||||
const obj = subjectConfig[fieldKey]
|
const obj = subjectConfig[fieldKey]
|
||||||
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return undefined
|
return obj && typeof obj === 'object' && !Array.isArray(obj)
|
||||||
return (obj as Record<string, unknown>)[subKey]
|
? (obj as Record<string, unknown>)
|
||||||
|
: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onObjectFieldChange(fieldKey: string, subKey: string, value: unknown) {
|
/** object 编辑器整体回写(嵌套层由 ObjectFieldEditor 递归维护,这里只落顶层键) */
|
||||||
const current = subjectConfig[fieldKey]
|
function onObjectFieldChange(fieldKey: string, value: Record<string, unknown>) {
|
||||||
const obj: Record<string, unknown> = current && typeof current === 'object' && !Array.isArray(current) ? { ...(current as Record<string, unknown>) } : {}
|
subjectConfig[fieldKey] = value
|
||||||
obj[subKey] = value
|
|
||||||
subjectConfig[fieldKey] = obj
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function locationFieldValue(key: string): number | string | null {
|
function locationFieldValue(key: string): number | string | null {
|
||||||
@ -867,28 +865,10 @@ loadAll()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.object-editor {
|
/* object 字段容器:内部由 ObjectFieldEditor 递归渲染(嵌套层级由组件自带缩进) */
|
||||||
|
.object-field-block {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 560px;
|
max-width: 560px;
|
||||||
|
|
||||||
&__row {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
margin-bottom: 8px;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__label {
|
|
||||||
flex: 0 0 120px;
|
|
||||||
font-size: 13px;
|
|
||||||
color: #606266;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__desc {
|
|
||||||
font-size: 12px;
|
|
||||||
color: #909399;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.field-control {
|
.field-control {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user