Browse Source

新增图片压缩功能,修复已知bug

dev-xx
马远东 8 months ago
parent
commit
a3a9303627
  1. 25
      src/api/storagecost/index.js
  2. 46
      src/components/IMGcompressor/imgcompressor.js
  3. 817
      src/views/cost/Deliverycostmanagement/Deliverymaintenancecosts.vue
  4. 14
      src/views/distribution/signfor/distributionSignfortreat.vue

25
src/api/storagecost/index.js

@ -261,3 +261,28 @@ export const $_expenseDispatchPricedetail = params => {
params,
});
};
// 配送-模板-车型计费配置-修改
export const $_expenseDispatchPriceupdate = data => {
return request({
url: '/api/logpm-statisticsdata/expenseDispatchPrice/update',
method: 'post',
data,
});
};
// 配送-模板-车型计费配置-删除
export const $_expenseDispatchPriceremove = params => {
return request({
url: '/api/logpm-statisticsdata/expenseDispatchPrice/remove',
method: 'post',
params,
});
};
// 配送-模板-超区删除
export const $_expenseDispatchPriceOverZoneremove = params => {
return request({
url: '/api/logpm-statisticsdata/expenseDispatchPriceOverZone/remove',
method: 'post',
params,
});
};

46
src/components/IMGcompressor/imgcompressor.js

@ -0,0 +1,46 @@
export async function compressImageBlob(blob) {
return new Promise((resolve, reject) => {
const img = new Image();
const reader = new FileReader();
reader.onload = e => {
img.src = e.target.result;
};
img.onload = () => {
const width = img.width;
const height = img.height;
const maxWidth = 800; // 最大宽度
const maxHeight = 800; // 最大高度
let newWidth = width;
let newHeight = height;
// 计算缩放比例
if (width > height) {
if (width > maxWidth) {
newHeight *= maxWidth / newWidth;
newWidth = maxWidth;
}
} else {
if (height > maxHeight) {
newWidth *= maxHeight / newHeight;
newHeight = maxHeight;
}
}
// 创建离屏 canvas
const offScreenCanvas = new OffscreenCanvas(newWidth, newHeight);
const ctx = offScreenCanvas.getContext('2d');
ctx.drawImage(img, 0, 0, newWidth, newHeight);
// 压缩图片
offScreenCanvas
.convertToBlob({ type: 'image/jpeg', quality: 0.8 })
.then(resolve)
.catch(reject);
};
reader.onerror = reject;
reader.readAsDataURL(blob);
});
}

817
src/views/cost/Deliverycostmanagement/Deliverymaintenancecosts.vue

File diff suppressed because it is too large Load Diff

14
src/views/distribution/signfor/distributionSignfortreat.vue

@ -294,6 +294,7 @@
v-model:file-list="DoorstepPhoto"
:action="doubledCount"
list-type="picture-card"
:before-upload="beforeUpload"
:on-preview="EnlargeTheTmageA"
:on-remove="handleRemove"
:on-success="ImgSuccessA"
@ -315,6 +316,7 @@
v-model:file-list="StackingPhoto"
:action="doubledCount"
list-type="picture-card"
:before-upload="beforeUpload"
:on-preview="EnlargeTheTmageB"
:on-remove="handleRemove"
:on-success="ImgSuccessB"
@ -337,6 +339,7 @@
:action="doubledCount"
list-type="picture-card"
:on-preview="EnlargeTheTmageC"
:before-upload="beforeUpload"
:on-remove="handleRemove"
:on-success="ImgSuccessC"
:headers="headers"
@ -357,6 +360,7 @@
v-model:file-list="HomePhotos"
:action="doubledCount"
list-type="picture-card"
:before-upload="beforeUpload"
:on-preview="EnlargeTheTmageD"
:on-remove="handleRemove"
:on-success="ImgSuccessD"
@ -379,6 +383,7 @@
:action="doubledCount"
list-type="picture-card"
:on-preview="EnlargeTheTmageE"
:before-upload="beforeUpload"
:on-remove="handleRemove"
:on-success="ImgSuccessE"
:headers="headers"
@ -521,6 +526,7 @@ import {
$_retentionScan,
} from '@/api/distribution/distributionSignfor';
import { update as updatesign } from '@/api/distribution/distributionSignfor';
import{compressImageBlob } from '@/components/IMGcompressor/imgcompressor.js'
import option from '@/option/distribution/distributionSignfor';
import { mapGetters } from 'vuex';
import { getDictionaryBiz } from '@/api/system/dict';
@ -1856,6 +1862,9 @@ export default {
},
//
submitForm() {
console.log(this.DoorstepPhoto,'img最新');
return
// this.isDis = true;
// console.log(this.$refs.signform.validate, 'this.$refs.signform');
// let row = {};
@ -1955,6 +1964,11 @@ export default {
EnlargeTheTmageA(uploadFile) {
this.dialogImageUrlA = uploadFile.url;
this.dialogVisibleA = true;
},
async beforeUpload(file){
const compressedBlob = await compressImageBlob(file);
return compressedBlob;
},
EnlargeTheTmageB(uploadFile) {
this.dialogImageUrlB = uploadFile.url;

Loading…
Cancel
Save