|
@@ -103,16 +103,22 @@ var app = new Vue({
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (_this.picList.length <= 0) {
|
|
|
|
|
+ $.toast('请先选择图片', 'text');
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
console.log('提交处理');
|
|
console.log('提交处理');
|
|
|
var total = $(".print-pic").length;
|
|
var total = $(".print-pic").length;
|
|
|
|
|
+ // $each(_this.picList,function (k, item) {
|
|
|
$(".print-pic").each(function (k, item) {
|
|
$(".print-pic").each(function (k, item) {
|
|
|
var _img = $(this).find('.pic-img');
|
|
var _img = $(this).find('.pic-img');
|
|
|
var name = $.trim(_img.attr('alt'));
|
|
var name = $.trim(_img.attr('alt'));
|
|
|
var num = parseInt($(this).find('.pic-num').val());
|
|
var num = parseInt($(this).find('.pic-num').val());
|
|
|
var colorType = $(this).find('.color').attr('data-color');
|
|
var colorType = $(this).find('.color').attr('data-color');
|
|
|
var $previewImg = document.getElementById("pic_preview_" + k);
|
|
var $previewImg = document.getElementById("pic_preview_" + k);
|
|
|
- var id = $(this).attr('data-id');
|
|
|
|
|
-
|
|
|
|
|
|
|
+ var picId = $(this).attr('data-id');
|
|
|
|
|
+ var fileData = typeof(_this.picList[k]) != 'undefined' ? _this.picList[k] : '';
|
|
|
// var canvas = document.createElement("canvas");
|
|
// var canvas = document.createElement("canvas");
|
|
|
var scale = 12;
|
|
var scale = 12;
|
|
|
var opts = {
|
|
var opts = {
|
|
@@ -122,71 +128,71 @@ var app = new Vue({
|
|
|
background: '#fff',
|
|
background: '#fff',
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- html2canvas($previewImg, opts).then(function (canvas) {
|
|
|
|
|
- const context = canvas.getContext('2d');
|
|
|
|
|
- context.translate(0.5, 0.5);
|
|
|
|
|
- context.mozImageSmoothingEnabled = false;
|
|
|
|
|
- context.webkitImageSmoothingEnabled = false;
|
|
|
|
|
- context.msImageSmoothingEnabled = false;
|
|
|
|
|
- context.imageSmoothingEnabled = false;
|
|
|
|
|
-
|
|
|
|
|
- var src = canvas.toDataURL('image/jpeg');
|
|
|
|
|
- var file = _this.dataURLtoFile(src, name ? name : '图片打印.jpeg');
|
|
|
|
|
- formData.append('type', 1);
|
|
|
|
|
- formData.append('taskKey', _this.taskKey);
|
|
|
|
|
- formData.append('image[]', file);
|
|
|
|
|
- formData.append('nums[]', num);
|
|
|
|
|
- formData.append('ids[]', id);
|
|
|
|
|
- formData.append('colors[]', colorType);
|
|
|
|
|
- count++;
|
|
|
|
|
|
|
+ // html2canvas($previewImg, opts).then(function (canvas) {
|
|
|
|
|
+ // const context = canvas.getContext('2d');
|
|
|
|
|
+ // context.translate(0.5, 0.5);
|
|
|
|
|
+ // context.mozImageSmoothingEnabled = false;
|
|
|
|
|
+ // context.webkitImageSmoothingEnabled = false;
|
|
|
|
|
+ // context.msImageSmoothingEnabled = false;
|
|
|
|
|
+ // context.imageSmoothingEnabled = false;
|
|
|
|
|
+ //
|
|
|
|
|
+ // var src = canvas.toDataURL('image/jpeg');
|
|
|
|
|
+ // var file = _this.dataURLtoFile(src, name ? name : '图片打印.jpeg');
|
|
|
|
|
+ formData.append('type', 1);
|
|
|
|
|
+ formData.append('taskKey', _this.taskKey);
|
|
|
|
|
+ if (fileData) {
|
|
|
|
|
+ formData.append('image[]', fileData);
|
|
|
|
|
+ formData.append('nums[]', num);
|
|
|
|
|
+ formData.append('ids[]', id);
|
|
|
|
|
+ formData.append('colors[]', colorType);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (total <= (k + 1)) {
|
|
|
|
|
- if (count <= 0) {
|
|
|
|
|
- $.toast('请选择打印的图片');
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- _this.submitting = true;
|
|
|
|
|
|
|
+ count++;
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- // 上传
|
|
|
|
|
- $.showLoading('文件上传处理中...');
|
|
|
|
|
- var ajax = $.ajax({
|
|
|
|
|
- url: '/weixin/upload/image',
|
|
|
|
|
- data: formData,
|
|
|
|
|
- type: "post",
|
|
|
|
|
- dataType: 'json',
|
|
|
|
|
- cache: false,
|
|
|
|
|
- contentType: false,
|
|
|
|
|
- processData: false,
|
|
|
|
|
- timeout: 30000,
|
|
|
|
|
- success: function (res) {
|
|
|
|
|
- $.hideLoading();
|
|
|
|
|
- _this.submitting = false;
|
|
|
|
|
- if (res.code == 'success') {
|
|
|
|
|
- _this.showModal();
|
|
|
|
|
- } else if (res.code == 'login') {
|
|
|
|
|
- login(res.data.url);
|
|
|
|
|
- } else {
|
|
|
|
|
- $.toast(res.message);
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- error: function (res) {
|
|
|
|
|
- _this.submitting = false;
|
|
|
|
|
- $.toast('服务器错误');
|
|
|
|
|
- },
|
|
|
|
|
- complete: function (XMLHttpRequest, status) {
|
|
|
|
|
- if (status == 'timeout') {
|
|
|
|
|
- ajax.abort();
|
|
|
|
|
- $.toast('请求超时,请重新提交');
|
|
|
|
|
- location.reload();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ if (count <= 0) {
|
|
|
|
|
+ $.toast('请选择打印的图片');
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 上传
|
|
|
|
|
+ $.showLoading('文件上传处理中...');
|
|
|
|
|
+ _this.submitting = true;
|
|
|
|
|
+ var ajax = $.ajax({
|
|
|
|
|
+ url: '/weixin/upload/image',
|
|
|
|
|
+ data: formData,
|
|
|
|
|
+ type: "post",
|
|
|
|
|
+ dataType: 'json',
|
|
|
|
|
+ cache: false,
|
|
|
|
|
+ contentType: false,
|
|
|
|
|
+ processData: false,
|
|
|
|
|
+ timeout: 30000,
|
|
|
|
|
+ success: function (res) {
|
|
|
|
|
+ $.hideLoading();
|
|
|
|
|
+ _this.submitting = false;
|
|
|
|
|
+ if (res.code == 'success') {
|
|
|
|
|
+ _this.showModal();
|
|
|
|
|
+ } else if (res.code == 'login') {
|
|
|
|
|
+ login(res.data.url);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $.toast(res.message);
|
|
|
}
|
|
}
|
|
|
- );
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ error: function (res) {
|
|
|
|
|
+ _this.submitting = false;
|
|
|
|
|
+ $.toast('服务器错误');
|
|
|
|
|
+ },
|
|
|
|
|
+ complete: function (XMLHttpRequest, status) {
|
|
|
|
|
+ if (status == 'timeout') {
|
|
|
|
|
+ ajax.abort();
|
|
|
|
|
+ $.toast('请求超时,请重新提交');
|
|
|
|
|
+ location.reload();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // });
|
|
|
},
|
|
},
|
|
|
// 显示填写窗口
|
|
// 显示填写窗口
|
|
|
showModal: function () {
|
|
showModal: function () {
|
|
@@ -419,6 +425,10 @@ var app = new Vue({
|
|
|
}
|
|
}
|
|
|
return new File([u8arr], filename, {type: mime});
|
|
return new File([u8arr], filename, {type: mime});
|
|
|
},
|
|
},
|
|
|
|
|
+ // base转文件
|
|
|
|
|
+ dataBlobtoFile: function (dataurl, filename) {//将base64转换为文件
|
|
|
|
|
+ return new File([u8arr], filename, {type: 'image/jpeg'});
|
|
|
|
|
+ },
|
|
|
// 删除图片
|
|
// 删除图片
|
|
|
picDel: function (id) {
|
|
picDel: function (id) {
|
|
|
var fileId = $("#pic_" + id).attr('data-id');
|
|
var fileId = $("#pic_" + id).attr('data-id');
|
|
@@ -468,16 +478,35 @@ var app = new Vue({
|
|
|
|
|
|
|
|
$("#cropBox").popup();
|
|
$("#cropBox").popup();
|
|
|
var options = {
|
|
var options = {
|
|
|
- aspectRatio: rate,
|
|
|
|
|
|
|
+ aspectRatio: 0,
|
|
|
center: true,
|
|
center: true,
|
|
|
- zoomOnTouch: false,
|
|
|
|
|
|
|
+ movable: true,
|
|
|
|
|
+ zoomable: true,
|
|
|
|
|
+ zoomOnTouch: true,
|
|
|
zoomOnWheel: false,
|
|
zoomOnWheel: false,
|
|
|
- scalable: false,
|
|
|
|
|
- touchDragZoom: false,
|
|
|
|
|
- responsive: false,
|
|
|
|
|
- // autoCropArea: 0.8,
|
|
|
|
|
- minCropBoxWidth: 80,
|
|
|
|
|
- minCropBoxHeight: 80,
|
|
|
|
|
|
|
+ scalable: true,
|
|
|
|
|
+ // cropBoxMovable: false,
|
|
|
|
|
+ wheelZoomRatio: 0.1,
|
|
|
|
|
+ background: false,
|
|
|
|
|
+ responsive: true,
|
|
|
|
|
+ guides: false,
|
|
|
|
|
+ strict: false,
|
|
|
|
|
+ width: width,
|
|
|
|
|
+ dragMode: 'move',
|
|
|
|
|
+ height: height,
|
|
|
|
|
+ autoCropArea: 0,
|
|
|
|
|
+ cropBoxMovable: false,
|
|
|
|
|
+ cropBoxResizable: false,
|
|
|
|
|
+ minContainerWidth: iWidth,
|
|
|
|
|
+ minContainerHeight: iHeight,
|
|
|
|
|
+ minCropBoxWidth: iWidth,
|
|
|
|
|
+ maxCropBoxWidth: iWidth,
|
|
|
|
|
+ minCropBoxHeight: iHeight,
|
|
|
|
|
+ maxCropBoxHeight: iHeight,
|
|
|
|
|
+ minCanvasWeight: iWidth,
|
|
|
|
|
+ maxCanvasWeight: iWidth,
|
|
|
|
|
+ minCanvasHeight: iHeight,
|
|
|
|
|
+ maxCanvasHeight: iHeight,
|
|
|
// preview: '.preview-img',
|
|
// preview: '.preview-img',
|
|
|
viewMode: 1,
|
|
viewMode: 1,
|
|
|
crop: function (data) {
|
|
crop: function (data) {
|
|
@@ -489,22 +518,7 @@ var app = new Vue({
|
|
|
rotate: Math.round(data.rotate),
|
|
rotate: Math.round(data.rotate),
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- var canvas = $image.cropper('getCroppedCanvas', {
|
|
|
|
|
- width: data.height * 15,
|
|
|
|
|
- height: data.width * 15,
|
|
|
|
|
- rotate: data.rotate
|
|
|
|
|
- });
|
|
|
|
|
- var url = canvas.toBlob(function (e) {
|
|
|
|
|
- console.log(e); //生成Blob的图片格式
|
|
|
|
|
- if(e != null){
|
|
|
|
|
- var timestamp = Date.parse(new Date());
|
|
|
|
|
- e.name = timestamp + ".png";
|
|
|
|
|
- url = URL.createObjectURL(e);
|
|
|
|
|
- _this.picList[id].url = url;
|
|
|
|
|
- _this.picList[id].preview = url;
|
|
|
|
|
- _this.cropParams.preview = url;
|
|
|
|
|
- }
|
|
|
|
|
- }, "image/jpeg");
|
|
|
|
|
|
|
+
|
|
|
/* _this.picList[id].preview = canvas.toDataURL("image/jpeg", 1);
|
|
/* _this.picList[id].preview = canvas.toDataURL("image/jpeg", 1);
|
|
|
_this.cropParams.preview = canvas.toDataURL("image/jpeg", 1);*/
|
|
_this.cropParams.preview = canvas.toDataURL("image/jpeg", 1);*/
|
|
|
_this.cropParams.cropData = cropData;
|
|
_this.cropParams.cropData = cropData;
|
|
@@ -572,6 +586,7 @@ var app = new Vue({
|
|
|
},
|
|
},
|
|
|
// 确定剪切
|
|
// 确定剪切
|
|
|
cropConfirm: function () {
|
|
cropConfirm: function () {
|
|
|
|
|
+ var _this = this;
|
|
|
$.closePopup();
|
|
$.closePopup();
|
|
|
$("#previewBox").hide();
|
|
$("#previewBox").hide();
|
|
|
$(".crop-img").show();
|
|
$(".crop-img").show();
|
|
@@ -579,12 +594,31 @@ var app = new Vue({
|
|
|
this.cropPreviewStatus = false;
|
|
this.cropPreviewStatus = false;
|
|
|
if (this.jc != null) {
|
|
if (this.jc != null) {
|
|
|
$.showLoading('图片处理中...');
|
|
$.showLoading('图片处理中...');
|
|
|
- setTimeout(function() {
|
|
|
|
|
- $.hideLoading();
|
|
|
|
|
- $("#cropImg").cropper('destroy');
|
|
|
|
|
- this.jc = null;
|
|
|
|
|
- $("#cropImg").remove();
|
|
|
|
|
- }, 200);
|
|
|
|
|
|
|
+ var canvas = $image.cropper('getCroppedCanvas', {
|
|
|
|
|
+ width: data.height * 15,
|
|
|
|
|
+ height: data.width * 15,
|
|
|
|
|
+ rotate: data.rotate
|
|
|
|
|
+ });
|
|
|
|
|
+ var url = canvas.toBlob(function (e) {
|
|
|
|
|
+ console.log(e); //生成Blob的图片格式
|
|
|
|
|
+ if (e != null) {
|
|
|
|
|
+ var timestamp = Date.parse(new Date());
|
|
|
|
|
+ e.name = timestamp + ".png";
|
|
|
|
|
+ url = URL.createObjectURL(e);
|
|
|
|
|
+ _this.picList[id].url = url;
|
|
|
|
|
+ _this.picList[id].preview = url;
|
|
|
|
|
+ _this.picList[id].fileData = _this.dataBlobtoFile(e, e.name);
|
|
|
|
|
+ _this.cropParams.preview = url;
|
|
|
|
|
+
|
|
|
|
|
+ setTimeout(function () {
|
|
|
|
|
+ $.hideLoading();
|
|
|
|
|
+ $("#cropImg").cropper('destroy');
|
|
|
|
|
+ this.jc = null;
|
|
|
|
|
+ $("#cropImg").remove();
|
|
|
|
|
+ }, 200);
|
|
|
|
|
+ }
|
|
|
|
|
+ }, "image/jpeg");
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
},
|
|
},
|