mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 19:23:26 +00:00
优化头像上传
This commit is contained in:
parent
0b0e6951e5
commit
b1cbf6f893
@ -368,8 +368,15 @@ class SystemController extends AbstractController
|
|||||||
* @apiGroup system
|
* @apiGroup system
|
||||||
* @apiName imgupload
|
* @apiName imgupload
|
||||||
*
|
*
|
||||||
* @apiParam {String} image64 图片base64
|
* @apiParam {File} image post-图片对象
|
||||||
* @apiParam {String} filename 文件名
|
* @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 {Number} ret 返回状态码(1正确、0错误)
|
||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
@ -380,9 +387,12 @@ class SystemController extends AbstractController
|
|||||||
if (User::userid() === 0) {
|
if (User::userid() === 0) {
|
||||||
return Base::retError('身份失效,等重新登录');
|
return Base::retError('身份失效,等重新登录');
|
||||||
}
|
}
|
||||||
$scale = [intval(Request::input('width')), intval(Request::input('height'))];
|
$width = intval(Request::input('width'));
|
||||||
if (!$scale[0] && !$scale[1]) {
|
$height = intval(Request::input('height'));
|
||||||
|
$whcut = intval(Request::input('whcut', 1));
|
||||||
$scale = [2160, 4160, -1];
|
$scale = [2160, 4160, -1];
|
||||||
|
if ($width > 0 || $height > 0) {
|
||||||
|
$scale = [$width, $height, $whcut];
|
||||||
}
|
}
|
||||||
$path = "uploads/user/picture/" . User::userid() . "/" . date("Ym") . "/";
|
$path = "uploads/user/picture/" . User::userid() . "/" . date("Ym") . "/";
|
||||||
$image64 = trim(Base::getPostValue('image64'));
|
$image64 = trim(Base::getPostValue('image64'));
|
||||||
|
|||||||
@ -2196,7 +2196,7 @@ class Base
|
|||||||
if ($width > 0 || $height > 0) {
|
if ($width > 0 || $height > 0) {
|
||||||
$scaleName = "_{WIDTH}x{HEIGHT}";
|
$scaleName = "_{WIDTH}x{HEIGHT}";
|
||||||
if (isset($param['scale'][2])) {
|
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) {
|
if ($width > 0 || $height > 0) {
|
||||||
$scaleName = "_{WIDTH}x{HEIGHT}";
|
$scaleName = "_{WIDTH}x{HEIGHT}";
|
||||||
if (isset($param['scale'][2])) {
|
if (isset($param['scale'][2])) {
|
||||||
$scaleName .= $param['scale'][2];
|
$scaleName .= "_c{$param['scale'][2]}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,6 +90,8 @@
|
|||||||
},
|
},
|
||||||
height: {
|
height: {
|
||||||
},
|
},
|
||||||
|
whcut: {
|
||||||
|
},
|
||||||
type: {
|
type: {
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
@ -110,10 +112,6 @@
|
|||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
actionUrl: $A.apiUrl('system/imgupload'),
|
actionUrl: $A.apiUrl('system/imgupload'),
|
||||||
params: {
|
|
||||||
width: this.width,
|
|
||||||
height: this.height
|
|
||||||
},
|
|
||||||
multiple: this.num > 1,
|
multiple: this.num > 1,
|
||||||
visible: false,
|
visible: false,
|
||||||
browseVisible: false,
|
browseVisible: false,
|
||||||
@ -176,10 +174,15 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
uploadParams() {
|
uploadParams() {
|
||||||
|
let params = {
|
||||||
|
width: this.width,
|
||||||
|
height: this.height,
|
||||||
|
whcut: this.whcut,
|
||||||
|
};
|
||||||
if (Object.keys(this.otherParams).length > 0) {
|
if (Object.keys(this.otherParams).length > 0) {
|
||||||
return Object.assign(this.params, this.otherParams);
|
return Object.assign(params, this.otherParams);
|
||||||
} else {
|
} else {
|
||||||
return this.params;
|
return params;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -277,10 +280,6 @@
|
|||||||
if (!check) {
|
if (!check) {
|
||||||
$A.noticeWarning(this.$L('最多只能上传 ' + this.maxNum + ' 张图片。'));
|
$A.noticeWarning(this.$L('最多只能上传 ' + this.maxNum + ' 张图片。'));
|
||||||
}
|
}
|
||||||
this.params = {
|
|
||||||
width: this.width,
|
|
||||||
height: this.height
|
|
||||||
};
|
|
||||||
return check;
|
return check;
|
||||||
},
|
},
|
||||||
handleClick() {
|
handleClick() {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
<div class="setting-item submit">
|
<div class="setting-item submit">
|
||||||
<Form ref="formData" :model="formData" :rules="ruleData" label-width="auto" @submit.native.prevent>
|
<Form ref="formData" :model="formData" :rules="ruleData" label-width="auto" @submit.native.prevent>
|
||||||
<FormItem :label="$L('头像')" prop="userimg">
|
<FormItem :label="$L('头像')" prop="userimg">
|
||||||
<ImgUpload v-model="formData.userimg" :num="1"></ImgUpload>
|
<ImgUpload v-model="formData.userimg" :num="1" :width="512" :height="512" :whcut="1"></ImgUpload>
|
||||||
<span class="form-tip">{{$L('建议尺寸:200x200')}}</span>
|
<span class="form-tip">{{$L('建议尺寸:200x200')}}</span>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem :label="$L('邮箱')">
|
<FormItem :label="$L('邮箱')">
|
||||||
|
|||||||
@ -19,6 +19,11 @@
|
|||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
}
|
}
|
||||||
|
.el-avatar {
|
||||||
|
> img {
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
> em {
|
> em {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user