fix(store): persist package imageUrls on audit approve

Ensure multi-image packages are written on approval and always returned as arrays from store detail.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-07 20:46:26 +08:00
parent 34a1897c09
commit 21d44026d9
3 changed files with 40 additions and 11 deletions
+20 -3
View File
@@ -34,7 +34,7 @@ export const STORE_PACKAGE_IMAGE_MAX_COUNT = 20;
/** 门店环境照最多张数(总部/合伙人上传) */
export const STORE_ENV_PHOTO_MAX_COUNT = 20;
/** 归一化套餐图片:兼容 imageUrl / imageUrls,去重后截断上限 */
/** 归一化套餐图片:兼容 imageUrl / imageUrls(含 JSON 字符串),去重后截断上限 */
export function normalizeStorePackageImageUrls(input: {
imageUrl?: string | null;
imageUrls?: unknown;
@@ -47,8 +47,25 @@ export function normalizeStorePackageImageUrls(input: {
seen.add(url);
out.push(url);
};
if (Array.isArray(input.imageUrls)) {
for (const item of input.imageUrls) push(item);
let list: unknown = input.imageUrls;
if (typeof list === 'string') {
const trimmed = list.trim();
if (trimmed.startsWith('[')) {
try {
list = JSON.parse(trimmed);
} catch {
list = trimmed ? [trimmed] : [];
}
} else if (trimmed) {
list = [trimmed];
} else {
list = [];
}
}
if (Array.isArray(list)) {
for (const item of list) push(item);
}
if (out.length === 0) push(input.imageUrl);
return out.slice(0, STORE_PACKAGE_IMAGE_MAX_COUNT);