From 2159041f3acb35e7fab1bc30639b21bb60e29697 Mon Sep 17 00:00:00 2001 From: zhangdi <15053473693@163.com> Date: Fri, 24 Jan 2025 09:23:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=97=AE=E9=A2=98=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 7 +- src/views/components/requestSub.vue | 96 ++++++++++++---------- src/views/goodsManagement/reciviceList.vue | 32 ++++---- vue.config.js | 4 +- 4 files changed, 72 insertions(+), 67 deletions(-) diff --git a/package.json b/package.json index b30d349..5fc03d5 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,10 @@ "element-ui": "^2.15.6", "file-saver": "^2.0.5", "html2canvas": "^1.4.1", - "html2canvas": "^1.4.1", "js-base64": "^2.5.1", "js-cookie": "^2.2.0", "js-md5": "^0.7.3", "jspdf": "^2.5.2", - "jspdf": "^2.5.2", "jszip": "^3.10.1", "mockjs": "^1.0.1-beta3", "moment": "^2.30.1", @@ -45,12 +43,11 @@ "vue-i18n": "^8.7.0", "vue-print-nb": "^1.7.5", "vue-printjs": "^1.0.0", - "vue-printjs": "^1.0.0", "vue-router": "^3.0.1", "vue-seamless-scroll": "^1.1.23", "vuex": "^3.1.1", - "xlsx": "^0.18.5", - "vxe-table": "^4.6.25" + "vxe-table": "^4.6.25", + "xlsx": "^0.18.5" }, "devDependencies": { "@vue/cli-plugin-babel": "^3.1.1", diff --git a/src/views/components/requestSub.vue b/src/views/components/requestSub.vue index c1ac3dc..71b5878 100644 --- a/src/views/components/requestSub.vue +++ b/src/views/components/requestSub.vue @@ -653,48 +653,46 @@ export default { }, beforeAvatarUpload(index){ return (file) =>{ - console.log('file------>',file) if(this.addForm[index].form.videoAttaches && this.addForm[index].form.picAttaches && this.addForm[index].form.videoAttaches.length + this.addForm[index].form.picAttaches.length < 3){ const isLt3M = file.size - if(isLt3M > 1024 * 1024 * 5){ + + // if(isLt3M > 1024 * 1024 * 2){ // const r = confirm( // // `您上传的图片大小超过5Mb,是否进行压缩上传?(此操作会降低图片质量)` // `您上传的图片大小超过5Mb,请压缩后再次上传` // ) - // console.log('r=========>',r) // if(r){ - // // const _this = this - // // return new Promise((resolve, reject) => { - // // const image = new Image() - // // let resultBlob = '' - // // image.src = URL.createObjectURL(file) - // // image.onload = () => { - // // // 调用方法获取blob格式,方法写在下边 - // // resultBlob = _this.compressUpload(image, file) - // // const fs = new File([resultBlob], file.name, { - // // type: file.type, - // // width:200, - // // height:200 - // // }) - // // console.log('fs============>',fs) - // // if (fs.size > 1024 * 1024 * 3) { - // // // this.commonZipPic(fs) - // // this.$message.warning('压缩后图片仍大于3Mb,请您手动压缩') - // // reject() - // // } - // // resolve(fs) - // // } - // // image.onerror = () => { - // // reject() - // // } - // // }) + const _this = this + return new Promise((resolve, reject) => { + const image = new Image() + let resultBlob = '' + image.src = URL.createObjectURL(file) + image.onload = () => { + // 调用方法获取blob格式,方法写在下边 + resultBlob = _this.compressUpload(image, file) + const fs = new File([resultBlob], file.name, { + type: file.type, + width:200, + height:200 + }) + if (fs.size > 1024 * 1024 * 3) { + // this.commonZipPic(fs) + this.$message.warning('压缩后图片仍大于3Mb,请您手动压缩') + reject() + } + resolve(fs) + } + image.onerror = () => { + reject() + } + }) // }else{ - this.$message.warning('您上传的图片大小超过5Mb,请手动压缩后在上传') - return false + // this.$message.warning('您上传的图片大小超过5Mb,请手动压缩后在上传') + // return false // } - }else{ - return true - } + // }else{ + // return true + // } }else{ this.$message.error('故障视频与故障图片最多可上传3个') return false @@ -706,17 +704,28 @@ export default { const canvas = document.createElement('canvas') const ctx = canvas.getContext('2d') // const initSize = image.src.length - const { width } = image - const { height } = image - canvas.width = width - canvas.height = height + const width = image.width * 0.1 // 图片宽度 * 压缩比例 + + const height = image.height * 0.1 // 图片高度 * 压缩比例 + + canvas.width = width // 画布宽度 + + canvas.height = height // 画布宽度 + // const { width } = image + // const { height } = image + // canvas.width = width + // canvas.height = height ctx.fillRect(0, 0, canvas.width, canvas.height) - ctx.drawImage(image, 0, 0, width / 10, height / 10) - // 进行最小压缩0.1 - const compressData = canvas.toDataURL(file.type || 'image/jpeg', 0.1) + // ctx.drawImage(image, 0, 0, width / 10, height / 10) + ctx.drawImage(image, 0, 0, width, height) + const dataUrl = canvas.toDataURL(file.type) //图片转路径 + + const blobData = this.dataURItoBlob(dataUrl, file.type) //图片转二进制 + // // 进行最小压缩0.1 + // const compressData = canvas.toDataURL(file.type || 'image/jpeg', 0.1) // 压缩后调用方法进行base64转Blob,方法写在下边 - const blobImg = this.dataURItoBlob(compressData) - return blobImg + // const blobImg = this.dataURItoBlob(blobData) + return blobData }, /* base64转Blob对象 */ dataURItoBlob(data) { @@ -735,7 +744,6 @@ export default { }, // 上传视频文件压缩后再上传 uploadCompressVideo(file) { - console.log('file===================>',file) if (file) { let filename = file.name; let filetype = file.type; @@ -758,7 +766,7 @@ export default { this.fileList.push({ name: item.name, link: item.response ? item.response.data.link : item.url }) this.imgList.push({ name: item.name, url: item.response ? item.response.data.link : item.url }) }) - this.addForm[index].form.picAttaches = fileList + this.addForm[index].form.picAttaches = this.fileList } }, changeDescribe(event, index) { diff --git a/src/views/goodsManagement/reciviceList.vue b/src/views/goodsManagement/reciviceList.vue index c756dc5..cab8a2b 100644 --- a/src/views/goodsManagement/reciviceList.vue +++ b/src/views/goodsManagement/reciviceList.vue @@ -262,22 +262,22 @@ export default { searchValue: dateFormat(new Date(), "yyyy-MM-dd"), searchClearable: false, }, - { - label: "仓库编号", - labelWidth: 120, - prop: "applyUser", - search: true, - hide: true, - viewDisplay: false, - }, - { - label: "物料名称", - labelWidth: 120, - prop: "applyUser", - search: true, - hide: true, - viewDisplay: false, - }, + // { + // label: "仓库编号", + // labelWidth: 120, + // prop: "applyUser", + // search: true, + // hide: true, + // viewDisplay: false, + // }, + // { + // label: "物料名称", + // labelWidth: 120, + // prop: "applyUser", + // search: true, + // hide: true, + // viewDisplay: false, + // }, { label: "是否需要归还", labelWidth: 150, diff --git a/vue.config.js b/vue.config.js index 4b794d1..c759086 100644 --- a/vue.config.js +++ b/vue.config.js @@ -28,8 +28,8 @@ module.exports = { //本地服务接口地址 // target: 'http://localhost', // target:'http://192.168.0.111:80', - target:'http://192.168.1.12:10001', - // target:'http://192.168.1.4:10001', + // target:'http://192.168.1.12:10001', + target:'http://192.168.1.4:10001', // target:'http://192.168.0.116:80', // target:'http://192.168.0.108:80', //远程演示服务地址,可用于直接启动项目