fix(系统设置): 仓库设置自动出库规则不再丢失「出库当天订单」的时间字段

normalizeWarehouseSubjectConfig 原先按「值是否为 boolean」过滤 auto_outbound_rules 子项,
字符串子项 same_day_outbound_deadline_time / same_day_outbound_release_time(HH:mm)
在读取(getSettings)与保存(saveSettings)时都被静默丢弃;改为按 flag 与 HH:mm 时间
白名单逐项归一化,并补全页面兜底字段与输入长度限制。
This commit is contained in:
liufumingren 2026-09-23 02:22:42 +08:00
parent b370cfd706
commit b32bc4ec7e
2 changed files with 59 additions and 12 deletions

View File

@ -2,6 +2,9 @@ import request from '@/utils/request'
const v = '1.0'
/** HH:mm(24 小时制、两位补零) */
const HH_MM_PATTERN = /^([01]\d|2[0-3]):[0-5]\d$/
/** 自动出库规则配置(subject_config.auto_outbound_rules) */
export type SettingWarehouseAutoOutboundRules = {
enabled?: boolean
@ -11,8 +14,32 @@ export type SettingWarehouseAutoOutboundRules = {
require_sync?: boolean
require_print?: boolean
require_pick?: boolean
/** 是否允许当天复核的订单当天自动出库,默认 false */
allow_same_day_outbound?: boolean
/** 允许当天出库最后时间,格式 HH:mm,默认 06:00;复核时间早于该时间的订单不受「出库当天订单」关闭的影响 */
same_day_outbound_deadline_time?: string
/** 当天放开时间,格式 HH:mm,默认 22:00;未开启「出库当天订单」时,当天到达该时间后不再限制当天复核订单的自动出库 */
same_day_outbound_release_time?: string
}
/** auto_outbound_rules 中的布尔(flag)子项 */
export const AUTO_OUTBOUND_RULE_FLAG_KEYS = [
'enabled',
'require_recheck',
'require_pack',
'require_weigh',
'require_sync',
'require_print',
'require_pick',
'allow_same_day_outbound'
] as const
/** auto_outbound_rules 中的 HH:mm 时间子项(缺省/空值回退默认,非空值原样保留交由后端校验) */
export const AUTO_OUTBOUND_RULE_TIME_KEYS = [
'same_day_outbound_deadline_time',
'same_day_outbound_release_time'
] as const
/** 文档默认:auto_outbound_rules 各子项默认值 */
export const DEFAULT_AUTO_OUTBOUND_RULES: Required<SettingWarehouseAutoOutboundRules> = {
enabled: false,
@ -21,7 +48,10 @@ export const DEFAULT_AUTO_OUTBOUND_RULES: Required<SettingWarehouseAutoOutboundR
require_weigh: true,
require_sync: true,
require_print: true,
require_pick: true
require_pick: true,
allow_same_day_outbound: false,
same_day_outbound_deadline_time: '06:00',
same_day_outbound_release_time: '22:00'
}
/** 收货未入库提醒配置(subject_config.receiving_pending_inbound_notice) */
@ -167,12 +197,25 @@ export function normalizeWarehouseSubjectConfig(
? { ...(rulesRaw as Record<string, unknown>) }
: ({} as Record<string, unknown>)
base.auto_outbound_rules = {
...DEFAULT_AUTO_OUTBOUND_RULES,
...Object.fromEntries(
Object.entries(rules).filter(([, v]) => typeof v === 'boolean')
)
} as SettingWarehouseAutoOutboundRules
// 按白名单保留 flag 与 HH:mm 时间子项:不能只按「值是否为 boolean」过滤,
// 否则 same_day_outbound_deadline_time / same_day_outbound_release_time(字符串)
// 会在读取与保存时被静默丢弃。
const normalizedRules: Record<string, unknown> = { ...DEFAULT_AUTO_OUTBOUND_RULES }
for (const key of AUTO_OUTBOUND_RULE_FLAG_KEYS) {
const value = rules[key]
normalizedRules[key] =
value === true || value === 1 || value === '1'
? true
: value === false || value === 0 || value === '0'
? false
: DEFAULT_AUTO_OUTBOUND_RULES[key]
}
for (const key of AUTO_OUTBOUND_RULE_TIME_KEYS) {
const value = rules[key]
const text = value === undefined || value === null ? '' : String(value).trim()
normalizedRules[key] = text !== '' ? text : DEFAULT_AUTO_OUTBOUND_RULES[key]
}
base.auto_outbound_rules = normalizedRules as SettingWarehouseAutoOutboundRules
for (const key of WAREHOUSE_SENDER_FIELD_KEYS) {
if (typeof base[key] !== 'string') {
@ -220,11 +263,10 @@ export function normalizeWarehouseSubjectConfig(
}
// 开始自动分配时间 / 截单时间(HH:mm,非法回退默认 08:00 / 18:00)
const HHmmPattern = /^([01]\d|2[0-3]):[0-5]\d$/
const allocTime = String(base.allocate_start_time ?? '')
base.allocate_start_time = HHmmPattern.test(allocTime) ? allocTime : '08:00'
base.allocate_start_time = HH_MM_PATTERN.test(allocTime) ? allocTime : '08:00'
const cutoffTime = String(base.cutoff_order_time ?? '')
base.cutoff_order_time = HHmmPattern.test(cutoffTime) ? cutoffTime : '18:00'
base.cutoff_order_time = HH_MM_PATTERN.test(cutoffTime) ? cutoffTime : '18:00'
// 收货未入库提醒(enabled flag 兼容 boolean / 数字 / 字符串;notice_time 非法回退 08:30;
// min_hours 默认 24;max_hours 默认 48 且必须大于 min_hours)
@ -239,7 +281,7 @@ export function normalizeWarehouseSubjectConfig(
noticeEnabled === true || noticeEnabled === 1 || noticeEnabled === '1'
const noticeTime = String(notice.notice_time ?? '')
notice.notice_time = HHmmPattern.test(noticeTime)
notice.notice_time = HH_MM_PATTERN.test(noticeTime)
? noticeTime
: DEFAULT_RECEIVING_PENDING_INBOUND_NOTICE.notice_time

View File

@ -209,6 +209,8 @@
: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>
@ -318,7 +320,10 @@ const FALLBACK_FIELDS: NormalizedField[] = [
{ key: 'require_weigh', label: '要求已称重', type: 'boolean', description: 'weighing_weight>0,默认开启' },
{ key: 'require_sync', label: '要求已同步', type: 'boolean', description: 'sync_status=fin,默认开启' },
{ key: 'require_print', label: '要求已打印', type: 'boolean', description: 'print_status=fin,默认开启' },
{ key: 'require_pick', label: '要求已拣货', type: 'boolean', description: 'pick_status=fin,默认开启' }
{ key: 'require_pick', label: '要求已拣货', type: 'boolean', description: 'pick_status=fin,默认开启' },
{ key: 'allow_same_day_outbound', label: '出库当天订单', type: 'boolean', description: '允许当天复核的订单当天自动出库,默认关闭' },
{ key: 'same_day_outbound_deadline_time', label: '允许当天出库最后时间', type: 'string', maxLength: 5, defaultValue: '06:00', description: '格式 HH:mm,默认 06:00;复核时间早于该时间的订单不受「出库当天订单」关闭的影响' },
{ key: 'same_day_outbound_release_time', label: '当天放开时间', type: 'string', maxLength: 5, defaultValue: '22:00', description: '格式 HH:mm,默认 22:00;未开启「出库当天订单」时,当天到达该时间后不再限制当天复核订单的自动出库' }
]
},
{