/** 店铺编辑表单模型(任务 92):由店铺行预填可编辑字段(分组/名称/账号),纯逻辑。 */ import type { ShopSummary } from './shop-dto.ts' import type { ShopManageFormValues } from './shop-manage-form-model.ts' function finiteId(value: unknown): number | null { return typeof value === 'number' && Number.isFinite(value) && value >= 1 ? Math.floor(value) : null } function groupIdOr(item: ShopSummary): number | null { return typeof item.groupId === 'number' && Number.isFinite(item.groupId) && item.groupId >= 1 ? Math.floor(item.groupId) : null } function textField(value: unknown): string { return typeof value === 'string' ? value : '' } /** 由店铺行预填编辑表单:密码掩码不回填明文,需保存时重新录入(后端更新要求必填)。 */ export function buildShopManageEditForm(item: ShopSummary | null | undefined): ShopManageFormValues | null { if (!item || typeof item !== 'object') return null if (finiteId(item.id) === null) return null return { groupId: groupIdOr(item), shopName: textField(item.shopName), mallName: textField(item.mallName), znUsername: textField(item.znUsername), account: textField(item.account), password: '', } }