fix(web): 积分商品保存 — 去掉 image_url 中的临时 token 参数

MediaPicker 返回含 ?token= 的 URL 用于预览认证,但保存到数据库时应只存纯路径,
避免 JWT token 持久化。同时改进错误提示显示后端返回的具体消息。
This commit is contained in:
iven
2026-05-26 10:38:30 +08:00
parent 9d6a92e1d7
commit 3972db4f98

View File

@@ -128,10 +128,12 @@ export default function PointsProductList() {
description?: string; description?: string;
sort_order?: number; sort_order?: number;
}; };
// 保存时去掉 URL 中的 ?token= 参数token 是临时的,不应持久化)
const cleanImageUrl = imageUrl ? imageUrl.replace(/\?token=.*$/, '') : undefined;
if (editing) { if (editing) {
await pointsApi.updateProduct(editing.id, { await pointsApi.updateProduct(editing.id, {
...typed, ...typed,
image_url: imageUrl || undefined, image_url: cleanImageUrl,
version: editing.version, version: editing.version,
}); });
} else { } else {
@@ -141,7 +143,7 @@ export default function PointsProductList() {
points_cost: typed.points_cost, points_cost: typed.points_cost,
stock: typed.stock, stock: typed.stock,
description: typed.description, description: typed.description,
image_url: imageUrl || undefined, image_url: cleanImageUrl,
sort_order: typed.sort_order, sort_order: typed.sort_order,
}; };
await pointsApi.createProduct(req); await pointsApi.createProduct(req);
@@ -149,8 +151,9 @@ export default function PointsProductList() {
message.success(editing ? '更新成功' : '创建成功'); message.success(editing ? '更新成功' : '创建成功');
handleCloseDrawer(); handleCloseDrawer();
refresh(page); refresh(page);
} catch { } catch (err: unknown) {
message.error(editing ? '更新失败' : '创建失败'); const apiMsg = (err as { response?: { data?: { message?: string } } })?.response?.data?.message;
message.error(apiMsg || (editing ? '更新失败' : '创建失败'));
} }
}; };