diff --git a/src/utils/goodsImageCompressor.ts b/src/utils/goodsImageCompressor.ts index 9948e0d..156e87e 100644 --- a/src/utils/goodsImageCompressor.ts +++ b/src/utils/goodsImageCompressor.ts @@ -58,7 +58,8 @@ const uploadImage = async (file: File): Promise => { } const result = await response.json(); - if (result.code !== 200) { + console.log('上传图片结果', result); + if (result.code !== 0) { throw new Error(result.msg || "上传失败"); } @@ -103,6 +104,9 @@ const compressGoodsImage = async ( }); // 上传压缩后的图片 + console.log('压缩图片名称', compressedFile.name); + console.log('压缩前图片大小', file.size); + console.log('压缩后图片大小', compressedFile.size); const newImageUrl = await uploadImage(compressedFile); // 更新商品信息 @@ -114,6 +118,8 @@ const compressGoodsImage = async ( delete (updateData as any).createTime; delete (updateData as any).updateTime; + console.log('压缩图片信息', compressed); + await updateGoodsApi(goods.goodsId!, updateData); return { @@ -124,6 +130,7 @@ const compressGoodsImage = async ( newImageUrl }; } catch (error) { + console.error('压缩商品图片失败', error); return { goodsId: goods.goodsId!, goodsName: goods.goodsName, @@ -183,7 +190,7 @@ export const compressAllGoodsImages = async ( } = {} ): Promise => { const wxStore = useWxStore(); - const corpid = wxStore.corpid; + const corpid = wxStore.corpid || 'wpZ1ZrEgAA2QTxIRcB4cMtY7hQbTcPAw'; if (!corpid) { throw new Error("未获取到企业微信ID"); diff --git a/src/views/shop/goods/index.vue b/src/views/shop/goods/index.vue index f290f68..47cb738 100644 --- a/src/views/shop/goods/index.vue +++ b/src/views/shop/goods/index.vue @@ -296,7 +296,7 @@ const handleCompressAllImages = async () => { -
+