This commit is contained in:
theluyuan 2024-10-16 15:31:00 +08:00
parent 6a15bbb2e0
commit c0e40bee86
4 changed files with 27 additions and 12 deletions

View File

@ -74,7 +74,7 @@ const _sfc_main = defineComponent({
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var options = { var options = {
file, file,
quality: 0.6, quality: props.quality,
mimeType: "image/jpeg", mimeType: "image/jpeg",
maxWidth: 2e3, maxWidth: 2e3,
maxHeight: 2e3, maxHeight: 2e3,
@ -194,7 +194,12 @@ const _sfc_main = defineComponent({
if (Array.isArray(files) && files.length > 0) { if (Array.isArray(files) && files.length > 0) {
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
let _file = files[i]; let _file = files[i];
let f = await imgcomp(_file); let f;
if (props.quality) {
f = await imgcomp(_file);
} else {
f = _file;
}
formData.append(props.field + "[" + i + "]", f); formData.append(props.field + "[" + i + "]", f);
} }
} }

View File

@ -48982,7 +48982,7 @@ const _sfc_main$7 = defineComponent({
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var options = { var options = {
file, file,
quality: 0.6, quality: props.quality,
mimeType: "image/jpeg", mimeType: "image/jpeg",
maxWidth: 2e3, maxWidth: 2e3,
maxHeight: 2e3, maxHeight: 2e3,
@ -49102,7 +49102,12 @@ const _sfc_main$7 = defineComponent({
if (Array.isArray(files) && files.length > 0) { if (Array.isArray(files) && files.length > 0) {
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
let _file = files[i]; let _file = files[i];
let f = await imgcomp(_file); let f;
if (props.quality) {
f = await imgcomp(_file);
} else {
f = _file;
}
formData.append(props.field + "[" + i + "]", f); formData.append(props.field + "[" + i + "]", f);
} }
} }

View File

@ -79,11 +79,11 @@ export interface UploadProps {
quality?: number; quality?: number;
} }
function imgcomp(file: any) { function imgcomp(file: any): Promise<Blob> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var options = { var options = {
file: file, file: file,
quality: 0.6, quality: props.quality,
mimeType: "image/jpeg", mimeType: "image/jpeg",
maxWidth: 2000, maxWidth: 2000,
maxHeight: 2000, maxHeight: 2000,
@ -252,7 +252,12 @@ const localUploadTransaction = async (option: localUploadTransaction) => {
if (Array.isArray(files) && files.length > 0) { if (Array.isArray(files) && files.length > 0) {
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
let _file = files[i]; let _file = files[i];
let f = await imgcomp(_file); let f: File | Blob;
if (props.quality) {
f = await imgcomp(_file);
} else {
f = _file;
}
formData.append(props.field + "[" + i + "]", f); formData.append(props.field + "[" + i + "]", f);
} }
} }
@ -482,10 +487,10 @@ onUnmounted(() => {
</div> </div>
</div> </div>
<div v-else ref="dragRef" class="layui-upload-drag" :class="disabled <div v-else ref="dragRef" class="layui-upload-drag" :class="disabled
? 'layui-upload-drag-disable' ? 'layui-upload-drag-disable'
: isDragEnter : isDragEnter
? 'layui-upload-drag-draging' ? 'layui-upload-drag-draging'
: '' : ''
" @click.stop="chooseFile"> " @click.stop="chooseFile">
<i class="layui-icon"></i> <i class="layui-icon"></i>
<p>{{ dragText }}</p> <p>{{ dragText }}</p>

File diff suppressed because one or more lines are too long