From ad3e773f27c00af38c850acd0504128a18b2acfb Mon Sep 17 00:00:00 2001 From: kuaifan Date: Mon, 18 Nov 2024 14:33:31 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/SystemController.php | 22 +++++++++++-------- app/Module/Base.php | 4 ++-- resources/assets/js/components/ImgUpload.vue | 12 +++++----- resources/assets/js/components/TEditor.vue | 5 ++++- .../js/components/VMEditor/engine/editor.vue | 5 ++++- resources/assets/js/pages/manage.vue | 2 +- .../js/pages/manage/approve/details.vue | 2 +- .../assets/js/pages/manage/approve/index.vue | 2 +- .../manage/components/DialogComplaint.vue | 2 +- .../pages/manage/components/DialogWrapper.vue | 2 +- .../manage/components/TeamManagement.vue | 2 +- .../js/pages/manage/setting/checkin.vue | 2 +- .../js/pages/manage/setting/personal.vue | 2 +- 13 files changed, 38 insertions(+), 26 deletions(-) diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 5c56c5d71..311a4d086 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -892,10 +892,10 @@ class SystemController extends AbstractController * @apiParam {String} filename post-文件名 * @apiParam {Number} [width] 压缩图片宽(默认0) * @apiParam {Number} [height] 压缩图片高(默认0) - * @apiParam {String} [whcut] 压缩方式 - * - 1:裁切(默认,宽、高非0有效) - * - 0:缩放 - * - -1或'auto':保持等比裁切 + * @apiParam {String} [whcut] 压缩方式(等比缩放) + * - cover:完全覆盖容器,可能图片部分不可见(width、height必须大于0) + * - contain:完全装入容器,可能容器部分显示空白(width、height必须大于0) + * - percentage:完全装入容器,可能容器有一边尺寸不足(默认,假如:width=200、height=0,则宽度最大不超过200、高度自动) * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -908,11 +908,15 @@ class SystemController extends AbstractController } $width = intval(Request::input('width')); $height = intval(Request::input('height')); - $whcut = intval(Request::input('whcut', 1)); - $scale = [2160, 4160, -1]; - if ($width > 0 || $height > 0) { - $scale = [$width, $height, $whcut]; - } + $whcut = Request::input('whcut'); + $whcut = match (strval($whcut)) { + '1' => 'cover', + '0' => 'contain', + 'cover', + 'contain' => $whcut, + default => 'percentage', + }; + $scale = [$width ?: 2160, $height ?: 4160, $whcut]; $path = "uploads/user/picture/" . User::userid() . "/" . date("Ym") . "/"; $image64 = trim(Request::input('image64')); $fileName = trim(Request::input('filename')); diff --git a/app/Module/Base.php b/app/Module/Base.php index 9c61499bb..e691c20b6 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2027,7 +2027,7 @@ class Base if ($width > 0 || $height > 0) { $scaleName = "_{WIDTH}x{HEIGHT}"; if (isset($param['scale'][2])) { - $scaleName .= "_c{$param['scale'][2]}"; + $scaleName .= "_{$param['scale'][2]}"; } } } @@ -2065,7 +2065,7 @@ class Base $data = match ($exif['Orientation']) { 2 => imageflip($data, IMG_FLIP_HORIZONTAL), 3 => imagerotate($data, 180, 0), - 4 => imageflip($data, IMG_FLIP_VERTICAL), + 4 => imageflip($data, IMG_FLIP_VERTICAL), 5 => imageflip(imagerotate($data, -90, 0), IMG_FLIP_HORIZONTAL), 6 => imagerotate($data, -90, 0), 7 => imageflip(imagerotate($data, 90, 0), IMG_FLIP_HORIZONTAL), diff --git a/resources/assets/js/components/ImgUpload.vue b/resources/assets/js/components/ImgUpload.vue index f55855ab1..d05f3aab7 100755 --- a/resources/assets/js/components/ImgUpload.vue +++ b/resources/assets/js/components/ImgUpload.vue @@ -29,7 +29,7 @@ :headers="uploadHeaders" :data="uploadParams" :show-upload-list="false" - :max-size="maxSize" + :max-size="maxImageSize" :format="['jpg', 'jpeg', 'webp', 'gif', 'png']" :default-file-list="defaultList" :on-progress="handleProgress" @@ -77,8 +77,6 @@