Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qianjiangb2b
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AI-甘富林
qianjiangb2b
Commits
03567c07
Commit
03567c07
authored
Jun 16, 2026
by
AI-甘富林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片上传bug
parent
70905178
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
8 deletions
+16
-8
package-lock.json
package-lock.json
+3
-3
ProductImageUpload.tsx
src/components/admin/product-edit/ProductImageUpload.tsx
+10
-0
imageCompression.ts
src/utils/imageCompression.ts
+3
-5
No files found.
package-lock.json
View file @
03567c07
...
@@ -7171,9 +7171,9 @@
...
@@ -7171,9 +7171,9 @@
}
}
},
},
"node_modules/semver"
:
{
"node_modules/semver"
:
{
"version"
:
"7.
7.2
"
,
"version"
:
"7.
8.4
"
,
"resolved"
:
"https://registry.npm
js.org/semver/-/semver-7.7.2
.tgz"
,
"resolved"
:
"https://registry.npm
mirror.com/semver/-/semver-7.8.4
.tgz"
,
"integrity"
:
"sha512-
RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJem
A=="
,
"integrity"
:
"sha512-
rUCObTnP32Q08R2uuIrt7r9PlEonuTmtuXYcW6s5kjdlj3xbnwe+21yXptAUYcMAABLkYYTtnmzb3w3EDZfue
A=="
,
"dev"
:
true
,
"dev"
:
true
,
"license"
:
"ISC"
,
"license"
:
"ISC"
,
"bin"
:
{
"bin"
:
{
...
...
src/components/admin/product-edit/ProductImageUpload.tsx
View file @
03567c07
...
@@ -179,6 +179,16 @@ export function ProductImageUpload({
...
@@ -179,6 +179,16 @@ export function ProductImageUpload({
processedFile = await compressImage(file, 1);
processedFile = await compressImage(file, 1);
}
}
// 压缩后二次校验:Canvas 重新编码无损格式(PNG 等)可能反而变大
if (processedFile.size > 5 * 1024 * 1024) {
toast({
title: "错误",
description: `
图片
$
{
file
.
name
}
压缩后仍超过
5
MB
,请尝试缩小图片尺寸
`,
variant: "destructive",
});
continue;
}
const fileExt = processedFile.name.split(".").pop();
const fileExt = processedFile.name.split(".").pop();
const fileName = `
product_$
{
Date
.
now
()}
_$
{
i
}.
$
{
fileExt
}
`;
const fileName = `
product_$
{
Date
.
now
()}
_$
{
i
}.
$
{
fileExt
}
`;
const filePath = `
products
/
$
{
fileName
}
`;
const filePath = `
products
/
$
{
fileName
}
`;
...
...
src/utils/imageCompression.ts
View file @
03567c07
...
@@ -43,11 +43,9 @@ export const compressImage = async (
...
@@ -43,11 +43,9 @@ export const compressImage = async (
// 绘制图片
// 绘制图片
ctx
.
drawImage
(
img
,
0
,
0
,
canvas
.
width
,
canvas
.
height
);
ctx
.
drawImage
(
img
,
0
,
0
,
canvas
.
width
,
canvas
.
height
);
// 对于 AVIF 或 WebP 等格式,转换为 JPEG 以确保兼容性
// 统一输出 JPEG:canvas.toBlob 的 quality 参数仅对 image/jpeg 有效
// canvas.toBlob 在某些浏览器中可能不支持 AVIF 编码
// PNG 等无损格式通过 Canvas 重新编码后可能反而变大,导致突破 bucket 大小限制
const
outputType
=
(
file
.
type
===
'image/avif'
||
file
.
type
===
'image/webp'
)
const
outputType
=
'image/jpeg'
;
?
'image/jpeg'
:
file
.
type
;
// 生成新的文件名(如果格式改变)
// 生成新的文件名(如果格式改变)
const
getNewFileName
=
(
originalName
:
string
,
newType
:
string
)
=>
{
const
getNewFileName
=
(
originalName
:
string
,
newType
:
string
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment