Commit 31bdc10b authored by 罗超's avatar 罗超

处理图片压缩

parent bf46523b
...@@ -138,6 +138,7 @@ export default { ...@@ -138,6 +138,7 @@ export default {
// debugger; // debugger;
console.log('filein...') console.log('filein...')
if (fileObj.type == "image/png" || fileObj.type == "image/jpeg") { if (fileObj.type == "image/png" || fileObj.type == "image/jpeg") {
let that = this
lrz(fileObj, { lrz(fileObj, {
width: 750, width: 750,
quality: 0.8 quality: 0.8
...@@ -145,8 +146,20 @@ export default { ...@@ -145,8 +146,20 @@ export default {
.then(function(rst) { .then(function(rst) {
//成功时执行 //成功时执行
console.log(rst) console.log(rst)
var arr = rst.base64.split(',');
var mime = arr[0].match(/:(.*?);/)[1];
var bstr = atob(arr[1]);
var n = bstr.length;
var u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
var newFile = new File([u8arr], fileObj.name, { type: mime });
debugger;
console.log(newFile);
that.uploadStart(path, newFile, callback)
}).catch(function(error) { }).catch(function(error) {
this.uploadStart(path, fileObj, callback) that.uploadStart(path, fileObj, callback)
}).always(function() { }).always(function() {
//不管成功或失败,都会执行 //不管成功或失败,都会执行
}) })
...@@ -154,6 +167,8 @@ export default { ...@@ -154,6 +167,8 @@ export default {
}, },
Vue.prototype.uploadStart = function(path, fileObj, callback) { Vue.prototype.uploadStart = function(path, fileObj, callback) {
console.log(fileObj)
debugger;
//获取文件扩展名 //获取文件扩展名
var filename = fileObj.name; var filename = fileObj.name;
var index = filename.lastIndexOf("."); var index = filename.lastIndexOf(".");
...@@ -185,6 +200,7 @@ export default { ...@@ -185,6 +200,7 @@ export default {
Body: fileObj, // 上传文件对象 Body: fileObj, // 上传文件对象
onProgress: function(progressData) {} onProgress: function(progressData) {}
}, function(err, data) { }, function(err, data) {
debugger;
if (data && data.statusCode == 200) { if (data && data.statusCode == 200) {
var uploadResult = { var uploadResult = {
resultCode: 1, resultCode: 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment