From b1cbf6f89389a6c5f185e1aa8daf0d4d18b7c686 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 22 Apr 2022 07:43:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=B4=E5=83=8F=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/SystemController.php | 20 ++++++++++++++----- app/Module/Base.php | 4 ++-- resources/assets/js/components/ImgUpload.vue | 19 +++++++++--------- .../js/pages/manage/setting/personal.vue | 2 +- .../assets/sass/components/user-avatar.scss | 5 +++++ 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index afca635bd..e1e5fbacf 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -368,8 +368,15 @@ class SystemController extends AbstractController * @apiGroup system * @apiName imgupload * - * @apiParam {String} image64 图片base64 - * @apiParam {String} filename 文件名 + * @apiParam {File} image post-图片对象 + * @apiParam {String} [image64] post-图片base64(与'image'二选一) + * @apiParam {String} filename post-文件名 + * @apiParam {Number} [width] 压缩图片宽(默认0) + * @apiParam {Number} [height] 压缩图片高(默认0) + * @apiParam {String} [whcut] 压缩方式 + * - 1:裁切(默认,宽、高非0有效) + * - 0:缩放 + * - -1或'auto':保持等比裁切 * * @apiSuccess {Number} ret 返回状态码(1正确、0错误) * @apiSuccess {String} msg 返回信息(错误描述) @@ -380,9 +387,12 @@ class SystemController extends AbstractController if (User::userid() === 0) { return Base::retError('身份失效,等重新登录'); } - $scale = [intval(Request::input('width')), intval(Request::input('height'))]; - if (!$scale[0] && !$scale[1]) { - $scale = [2160, 4160, -1]; + $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]; } $path = "uploads/user/picture/" . User::userid() . "/" . date("Ym") . "/"; $image64 = trim(Base::getPostValue('image64')); diff --git a/app/Module/Base.php b/app/Module/Base.php index 52a873808..baab10657 100755 --- a/app/Module/Base.php +++ b/app/Module/Base.php @@ -2196,7 +2196,7 @@ class Base if ($width > 0 || $height > 0) { $scaleName = "_{WIDTH}x{HEIGHT}"; if (isset($param['scale'][2])) { - $scaleName .= $param['scale'][2]; + $scaleName .= "_c{$param['scale'][2]}"; } } } @@ -2370,7 +2370,7 @@ class Base if ($width > 0 || $height > 0) { $scaleName = "_{WIDTH}x{HEIGHT}"; if (isset($param['scale'][2])) { - $scaleName .= $param['scale'][2]; + $scaleName .= "_c{$param['scale'][2]}"; } } } diff --git a/resources/assets/js/components/ImgUpload.vue b/resources/assets/js/components/ImgUpload.vue index 88736f471..568500895 100755 --- a/resources/assets/js/components/ImgUpload.vue +++ b/resources/assets/js/components/ImgUpload.vue @@ -90,6 +90,8 @@ }, height: { }, + whcut: { + }, type: { }, http: { @@ -110,10 +112,6 @@ data () { return { actionUrl: $A.apiUrl('system/imgupload'), - params: { - width: this.width, - height: this.height - }, multiple: this.num > 1, visible: false, browseVisible: false, @@ -176,10 +174,15 @@ }, uploadParams() { + let params = { + width: this.width, + height: this.height, + whcut: this.whcut, + }; if (Object.keys(this.otherParams).length > 0) { - return Object.assign(this.params, this.otherParams); + return Object.assign(params, this.otherParams); } else { - return this.params; + return params; } } }, @@ -277,10 +280,6 @@ if (!check) { $A.noticeWarning(this.$L('最多只能上传 ' + this.maxNum + ' 张图片。')); } - this.params = { - width: this.width, - height: this.height - }; return check; }, handleClick() { diff --git a/resources/assets/js/pages/manage/setting/personal.vue b/resources/assets/js/pages/manage/setting/personal.vue index 3fc780cc6..76b0762ab 100644 --- a/resources/assets/js/pages/manage/setting/personal.vue +++ b/resources/assets/js/pages/manage/setting/personal.vue @@ -2,7 +2,7 @@
- + {{$L('建议尺寸:200x200')}} diff --git a/resources/assets/sass/components/user-avatar.scss b/resources/assets/sass/components/user-avatar.scss index 640bf42e3..d43a30993 100755 --- a/resources/assets/sass/components/user-avatar.scss +++ b/resources/assets/sass/components/user-avatar.scss @@ -19,6 +19,11 @@ font-size: 15px; line-height: inherit; } + .el-avatar { + > img { + margin: 0 auto; + } + } > em { position: absolute; right: 0;