|
@@ -761,7 +761,7 @@
|
|
|
success: function(res){
|
|
|
res = JSON.parse(res);
|
|
|
if(200!=res.code){
|
|
|
- //alert(res.msg);
|
|
|
+ alert(res.msg);
|
|
|
}else{
|
|
|
const data = res.data;
|
|
|
const list = data.list;
|
|
@@ -779,46 +779,96 @@
|
|
|
$.each(this.imglist,function(index,term){
|
|
|
const id = index+1;
|
|
|
//"background-position": "center",
|
|
|
- that.bgload(term.url,'.image_div #img'+id,id)
|
|
|
- //$('.image_div #img'+id).css({'background-image':"url("+term.url+")","background-size":"100% 100%"});
|
|
|
+ //that.bgload(term.url,'.image_div #img'+id,id)
|
|
|
+ $('.image_div #img'+id).css({'background-image':"url("+term.url+")","background-size":"100% 100%"});
|
|
|
+ that.setimgloading(id,false)
|
|
|
});
|
|
|
},
|
|
|
uploadimg(e){
|
|
|
let index = $(e.target).data('index');
|
|
|
- console.log(index);
|
|
|
let id = this.imglist[index-1].id;
|
|
|
-
|
|
|
let that = this
|
|
|
myFile = $('#uploadfile');
|
|
|
myFile.click()
|
|
|
myFile.unbind().change(function (e) {
|
|
|
that.setimgloading(index,true)
|
|
|
- url = "/index.php/index/fileoper/uploadfilebydir";
|
|
|
- var formData = new window.FormData()
|
|
|
- //formData.append('userid', this.userid);
|
|
|
- //formData.append('partyid', this.partyid);
|
|
|
- //formData.append('id', id);
|
|
|
- formData.set('dir', "party");
|
|
|
- formData.set('file', document.querySelector('input[type=file]').files[0])
|
|
|
+ //url = "/index.php/index/fileoper/uploadfilebydir";
|
|
|
+ //var formData = new window.FormData()
|
|
|
+ //formData.set('dir', "party");
|
|
|
+ var file = document.querySelector('input[type=file]').files[0];
|
|
|
+ if (file.size > 1024 * 1024 * 1){
|
|
|
+ // 图片大于1M进行压缩
|
|
|
+ that.canvasDataURL(file, function (blob) {
|
|
|
+ console.log(blob);
|
|
|
+ var newFile = new File([blob], file.name, {
|
|
|
+ type: file.type
|
|
|
+ }
|
|
|
+ )
|
|
|
+ var isLt1M;
|
|
|
+ if (file.size < newFile.size) {
|
|
|
+ isLt1M = file.size
|
|
|
+ } else {
|
|
|
+ isLt1M = newFile.size
|
|
|
+ }
|
|
|
+ console.log(file.size)
|
|
|
+ console.log(newFile.size)
|
|
|
+ if (isLt1M / 1024 / 1024 > 1) {
|
|
|
+ alert('图片压缩之后还是大于1M,请压缩之后上传!');
|
|
|
+ that.setimgloading(index,false);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ file = newFile
|
|
|
+ that.douploadimg(file,index,myFile)
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ that.douploadimg(file,index,myFile)
|
|
|
+ }
|
|
|
+ /*formData.set('file', file)
|
|
|
var xhr=new XMLHttpRequest();
|
|
|
xhr.open("post",url);
|
|
|
xhr.send(formData);
|
|
|
xhr.onload=function(){
|
|
|
res = JSON.parse(xhr.response);
|
|
|
if(200!=res.code){
|
|
|
- alert(res.resultData);
|
|
|
+ alert(res.msg);
|
|
|
+ that.setimgloading(index,false)
|
|
|
}else{
|
|
|
myFile.val('')
|
|
|
formData.delete('dir')
|
|
|
formData.delete('file')
|
|
|
var pictureurl = res.resultData;
|
|
|
that.imglist[index-1].url = pictureurl;
|
|
|
- that.sethtmlimglist()
|
|
|
- that.saveimg(index)
|
|
|
+ that.saveimg(index)
|
|
|
+ that.sethtmlimglist()
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
});
|
|
|
},
|
|
|
+ douploadimg(file,index,myFile){
|
|
|
+ let that = this
|
|
|
+ url = "/index.php/index/fileoper/uploadfilebydir";
|
|
|
+ var formData = new window.FormData()
|
|
|
+ formData.set('dir', "party");
|
|
|
+ formData.set('file', file)
|
|
|
+ var xhr=new XMLHttpRequest();
|
|
|
+ xhr.open("post",url);
|
|
|
+ xhr.send(formData);
|
|
|
+ xhr.onload=function(){
|
|
|
+ res = JSON.parse(xhr.response);
|
|
|
+ if(200!=res.code){
|
|
|
+ alert(res.msg);
|
|
|
+ that.setimgloading(index,false)
|
|
|
+ }else{
|
|
|
+ myFile.val('')
|
|
|
+ formData.delete('dir')
|
|
|
+ formData.delete('file')
|
|
|
+ var pictureurl = res.resultData;
|
|
|
+ that.imglist[index-1].url = pictureurl;
|
|
|
+ that.saveimg(index)
|
|
|
+ that.sethtmlimglist()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
saveimg(index){
|
|
|
var that = this
|
|
|
let id = this.imglist[index-1].id;
|
|
@@ -915,11 +965,11 @@
|
|
|
success: function(res){
|
|
|
res = JSON.parse(res);
|
|
|
if(200!=res.code){
|
|
|
- console.log(res.msg);
|
|
|
+ alert(res.msg);
|
|
|
}else{
|
|
|
$('html ,body').animate({ scrollTop: -10 }, 500);
|
|
|
//alert(location.href+"&showinfo=1");
|
|
|
- window.location.href = location.href+"&showinfo=1";
|
|
|
+ //window.location.href = location.href+"&showinfo=1";
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -958,6 +1008,38 @@
|
|
|
this.isloadingimg6=isloading
|
|
|
break;
|
|
|
}
|
|
|
+ },
|
|
|
+ canvasDataURL(file, callback) {
|
|
|
+ var that=this
|
|
|
+ var reader = new FileReader()
|
|
|
+ reader.readAsDataURL(file)
|
|
|
+ reader.onload = function (e) {
|
|
|
+ const img = new Image()
|
|
|
+ const quality = 0.1 // 图像质量
|
|
|
+ const canvas = document.createElement('canvas')
|
|
|
+ const drawer = canvas.getContext('2d')
|
|
|
+ img.src = this.result
|
|
|
+ img.onload = function () {
|
|
|
+ canvas.width = img.width
|
|
|
+ canvas.height = img.height
|
|
|
+ drawer.drawImage(img, 0, 0, canvas.width, canvas.height)
|
|
|
+ // convertBase64UrlToBlob(canvas.toDataURL(file.type, quality), callback);
|
|
|
+ var blob =that.convertBase64UrlToBlob(canvas.toDataURL("image/jpeg", quality) );
|
|
|
+ callback(blob)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ convertBase64UrlToBlob(urlData) {
|
|
|
+ var bytes = window.atob(urlData.split(',')[1]); //去掉url的头,并转换为byte
|
|
|
+ //处理异常,将ascii码小于0的转换为大于0
|
|
|
+ var ab = new ArrayBuffer(bytes.length);
|
|
|
+ var ia = new Uint8Array(ab);
|
|
|
+ for (var i = 0; i < bytes.length; i++) {
|
|
|
+ ia[i] = bytes.charCodeAt(i);
|
|
|
+ }
|
|
|
+ return new Blob([ab], {
|
|
|
+ type: 'image/jpg'
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|