1 |
- !function(t){function e(n){if(i[n])return i[n].exports;var a=i[n]={i:n,l:!1,exports:{}};return t[n].call(a.exports,a,a.exports,e),a.l=!0,a.exports}var i={};e.m=t,e.c=i,e.d=function(t,i,n){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=1)}([function(t,e){var i=function(t){function e(e,i,n){var a='<div class="tipHtml">';e&&(a+="loading"==e?'<div class="icon weui-icon_toast weui-icon-'+e+'"></div>':'<div class="icon weui-icon-'+e+'"></div>'),a+="<div>"+i+"</div>",a+="</div>",t("body").append(a),n&&"number"==typeof n&&setTimeout(function(){t(".tipHtml").remove()},n)}function i(t){html='<div class="loader-inner ball-clip-rotate">',html+='<div class="weui-icon-loading"></div>',html+="</div>",t.append(html)}function n(){t(".loader-inner").remove()}function a(){t(".tipHtml").remove()}function o(t,e){var i=t.toDataURL(e),n=i.split(","),a=void 0;a=n[0].indexOf("base64")>=0?atob(n[1]):decodeURIComponent(n[1]);for(var o=new ArrayBuffer(a.length),r=new Uint8Array(o),s=0;s<a.length;s+=1)r[s]=a.charCodeAt(s);var d=n[0].split(":")[1].split(";")[0],u=null;if(c)u=new Blob([l?r:o],{type:d});else{var f=new BlobBuilder;f.append(o),u=f.getBlob(d)}return u}function r(t,e,i){if("undefined"==typeof URL){var n=new FileReader;n.onload=function(e){t.src=e.target.result,i&&i()},n.readAsDataURL(e)}else t.src=URL.createObjectURL(e),i&&i()}function s(){return Date.parse(new Date)/1e3}var c="undefined"!=typeof Blob&&function(){try{return Boolean(new Blob)}catch(t){return!1}}(),l=c&&"undefined"!=typeof Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(t){return!1}}();return{tipHtml:e,hideTip:a,toBlob:o,loadImage:r,returnDataTime:s,loading:i,hideLoading:n}}(jQuery);t.exports=i},function(t,e,i){var n=i(0),a=i(2);!function(t){function e(){t("#view_ward .djys-align-item").each(function(){t(this).click(function(){switch(t(this).data("key")){case 0:var e=u.mainCanvas.getActiveObject();if(!e||"undefined"==e)return!1;u.mainCanvas.bringForward(e),u.mainCanvas.renderAll();break;case 1:var e=u.mainCanvas.getActiveObject();if(!e||"undefined"==e)return!1;u.mainCanvas.sendBackwards(e),u.mainCanvas.renderAll();break;case 2:var e=u.mainCanvas.getActiveObject();if(!e||"undefined"==e)return!1;u.mainCanvas.bringToFront(e),u.mainCanvas.renderAll();break;default:var e=u.mainCanvas.getActiveObject();if(!e||"undefined"==e)return!1;u.mainCanvas.sendToBack(e),u.mainCanvas.renderAll()}})})}function i(){a.getColor(function(e){var i="";for(var n in e.colorPanel){for(var a="",o=0;o<e.colorPanel[n].length;o++)a+='<span data-color="{color}" style="background-color:{color}"></span>'.replace(/{color}/g,e.colorPanel[n][o]);i+='<div class="djsy-color-panel-item">{span}</div>'.replace("{span}",a)}t("#djsy_text_color_panel_content").html(i),t("#djsy_text_color_panel_content .djsy-color-panel-item > span,#djsy_color_default > span").each(function(){t(this).click(function(){var e=t(this).data("color");u.setActiveStyle("fill",e),mui("#djsy_text_color_panel").popover("hide")})})})}function o(){t("#diy_preview").click(function(){var e=u.returnCanvasImg(200),i=document.createElement("canvas"),n=i.getContext("2d"),a=new Image;a.src=u.bottle.img_url,console.log(u.bottle),a.onload=function(){console.log(a.onload),i.width=a.width,i.height=a.height,n.drawImage(a,0,0,a.width,a.height);var o=new Image;o.src=e,o.onload=function(){o.height=.54*a.height,o.width=o.height*u.plateRATIO,n.drawImage(o,(a.width-o.width)/2,.3*a.height,o.width,o.height);var e=i.toDataURL();t("#previewCanvas").show();var r='<img class="previewImg" src="'+e+'"/>';t("#previewImgWrap").html(r)}}}),t(".close_preview").click(function(){t("#previewCanvas").hide()})}function r(t){var e=prompt("请输入内容",t);null!=e&&""!=e&&u.addText(e)}function s(){u.mtid||(n.tipHtml("loading","正在加载"),a.getMaterialType(function(e){var i=e.list,n="",a=0;e.list.forEach(function(t){n+=0==a?'<span class="active" data-id="'+t.id+'">'+t.title+"</span>":'<span data-id="'+t.id+'">'+t.title+"</span>",a++}),t("#djsy-source-list-left").html(n),u.mtid=i[0].id,l(u.mtid),c()}))}function c(){t("#djsy-source-list-left >span").each(function(){t(this).unbind("click").click(function(){t(this).addClass("active").siblings("span").removeClass("active");var e=t(this).data("id");e&&e!=u.mtid&&(l(e),u.mtid=e)})})}function l(e){a.getMaterial(e,function(e){for(var i="",a=0;a<e.list.length;a++)i+='<li class="box_item" data-imgUrl="'+e.list[a].img_url+'">',i+='<div class="dsjy_trend_wrap">',i+='<img src="'+e.list[a].img_url+'" />',i+="<span>"+e.list[a].title+"</span>",i+="</div>",i+="</li>";n.hideTip(),t("#djsy_source_contant_ul").html(i),t(".box_item").each(function(){t(this).unbind("click").click(function(){var e=t(this).data("imgurl");u.addImg(e),t(".djsy-pop-wrap").hide()})})})}function d(){t("#diy_save_diy_btn").click(function(){if(u.mainCanvas._objects.length<=0)return alert("请添加内容"),!1;n.tipHtml("loading","正在提交");var t={id:u.diyId,img_url:u.returnCanvasImg(100),content:JSON.stringify(u.returnCanvasJson()),type:u.typeId};a.saveDiy(t,function(t){alert(t.msg+"请到个人中心-我的定制查看"),window.location.href="/wap/user/diy"})}),t("#diy_cart_diy_btn").click(function(){if(u.mainCanvas._objects.length<=0)return alert("请添加内容"),!1;n.tipHtml("loading","正在提交");var t={id:u.diyId,img_url:u.returnCanvasImg(100),content:JSON.stringify(u.returnCanvasJson()),type:u.typeId};a.addCart(t,function(t){alert(t.msg),window.location.href="/wap/shop/cart"})})}var u=new Object;u.setActiveStyle=function(t,e,i){var n=this.mainCanvas;if(i=i||n.getActiveObject()){if(i.setSelectionStyles&&i.isEditing){var a={};a[t]=e,i.setSelectionStyles(a),i.setCoords()}else i.set(t,e);i.setCoords(),n.renderAll()}},u.ControlVisibility=function(t){var e={tl:!0,tr:!0,br:!0,bl:!0,ml:0,mt:0,mr:0,mb:0,mtr:!0};for(var i in e)t.setControlVisible(i,e[i])},u.addImg=function(t){var e=this;fabric.Image.fromURL(t,function(t){t.set({cornerSize:15,cornerStyle:"circle",rotatingPointOffset:30,borderDashArray:[3,6],borderColor:"#000",cornerColor:"#000"});var i=t.width/t.height;e.maxWidthImg=.8*e.oldCutWidth,e.maxHeightImg=.8*e.oldCutHeight;var n,a;e.maxHeightImg*i<e.maxWidthImg?(n=e.maxHeightImg*i,a=e.maxHeightImg):(n=e.maxWidthImg,a=e.maxWidthImg/i),t.setWidth(n),t.setHeight(a),e.centerObj(t),e.mainCanvas.add(t).setActiveObject(t),e.mainCanvas.renderAll(),e.mainCanvas.calcOffset()})},u.transformViewPoint=function(t){var e=this,i=e.mainCanvas.getCenter();if(t)var n={x:t.x,y:t.y};else var n={x:i.left,y:i.top};return fabric.util.transformPoint(n,fabric.util.invertTransform(e.mainCanvas.viewportTransform))},u.centerObj=function(t){console.log(t);var e=u.transformViewPoint();t.set("left",e.x-t.width*t.scaleX/2),t.set("top",e.y-t.height*t.scaleY/2),t.setCoords()},u.returnCanvasJson=function(){return this.mainCanvas.toJSON(["borderColor","cornerColor","cornerStyle","cornerSize","rotatingPointOffset","borderDashArray","plateRATIO","viewportTransform","oldCutWidth","oldCutHeight","width","height","_controlsVisibility"])},u.returnCanvasImg=function(t){var e=this;u.outputWidth=t||500,u.outputHeight=u.outputWidth/u.plateRATIO;var i=u.outputWidth/u.oldCutWidth,n=e.mainCanvas.getCenter(),a=e.mainCanvas.getZoom();e.mainCanvas.zoomToPoint(new fabric.Point(n.left,n.top),i);var o=e.mainCanvas.toDataURL({format:"png",left:n.left-u.outputWidth/2,top:n.top-u.outputHeight/2,width:u.outputWidth,height:u.outputHeight});return e.mainCanvas.zoomToPoint(new fabric.Point(n.left,n.top),a),o},u.cutArea=function(e,i,n){u.cutCanvas&&t("#cutCanvas").remove(),u.cutCanvas=document.createElement("canvas"),u.cutCanvas.width=e,u.cutCanvas.height=i,u.cutCanvas.id="cutCanvas",t(u.cutCanvas).css({position:"absolute",top:0,left:0,width:e,height:i});var a=u.cutCanvas.getContext("2d");a.fillStyle="rgba(173,173,173,0.8)",a.fillRect(0,0,e,i),u.maxWidth=.8*u.baseWidth,u.maxHeight=.8*u.baseHeight,n||(u.maxHeight*u.plateRATIO<u.maxWidth?(u.cutWidth=u.maxHeight*u.plateRATIO,u.cutHeight=u.maxHeight):(u.cutWidth=u.maxWidth,u.cutHeight=u.maxWidth/u.plateRATIO)),a.clearRect((e-u.cutWidth)/2,(i-u.cutHeight)/2,u.cutWidth,u.cutHeight),t("#diy").after(u.cutCanvas)},u.resizeCanvasSize=function(){var t=this.mainCanvas;u.centerLeft=t.getWidth()/2,u.centerTop=t.getHeight()/2,t.setWidth(u.baseWidth),t.setHeight(u.baseHeight);var e=t.getCenter();t.discardActiveGroup(),u.resizeLeft=e.left-u.centerLeft,u.resizeTop=e.top-u.centerTop;var i=t.getZoom(),n=t.getObjects();for(var a in n)n[a].left=n[a].left+u.resizeLeft/i,n[a].top=n[a].top+u.resizeTop/i,n[a].setCoords();t.renderAll(),t.calcOffset()},u.cutRATIO=null,u.resizeRender=function(){var t=this,e=u.cutWidth/u.oldCutWidth;if(u.cutRATIO==e)return!1;u.cutRATIO=e;var i=t.mainCanvas.getCenter();t.mainCanvas.zoomToPoint(new fabric.Point(i.left,i.top),u.cutRATIO),t.mainCanvas.renderAll(),t.mainCanvas.calcOffset()},u.dowmCanvas=function(){var e=this.mainCanvas;e.on("mouse:down",function(e){e.target&&"i-text"==e.target.type?t(".djsy-text-edit-wrap").addClass("djsy-text-edit-ani"):t(".djsy-text-edit-wrap").removeClass("djsy-text-edit-ani"),e.target?t(".djys-align-wrap").removeClass("djys-align-ani"):t(".djys-align-wrap").addClass("djys-align-ani")}),e.on("mouse:up",function(t){t.target}),e.on("object:selected",function(t){var i=e.getActiveGroup();i&&i.set({cornerSize:15,cornerStyle:"circle",rotatingPointOffset:30,borderDashArray:[3,6],borderColor:"#000",cornerColor:"#000"})})},u.addText=function(t){var e=this,i=new fabric.IText(t,{fontSize:30,textAlign:"left",cornerStyle:"circle",borderColor:"#000",cornerColor:"#000",fontFamily:"Microsoft YaHei",cornerSize:15,rotatingPointOffset:30,borderDashArray:[3,6]});i.on("editing:entered",function(){u.textFlage=!0}),i.on("editing:exited",function(){u.textFlage=!1}),u.ControlVisibility(i),e.centerObj(i),e.mainCanvas.add(i).setActiveObject(i),e.mainCanvas.renderAll()},u.delObject=function(){var e=this;t("#diy_del_object").click(function(){if(e.mainCanvas.getActiveGroup())return alert("请选择对象删除"),!1;var t=e.mainCanvas.getActiveObject();if(!t||"undefined"==t)return!1;e.mainCanvas.remove(t),e.mainCanvas.renderAll()})},u.init=function(e,i){u.baseWidth=t(".diy_canvas_wrap").width(),u.baseHeight=t(".diy_canvas_wrap").height(),u.mainCanvas=new fabric.Canvas("diy",{selectionColor:"rgba(0,0,0,0.1)",controlsAboveOverlay:!0,preserveObjectStacking:!0,backgroundColor:"rgba(255,255,255,0)",selctionBorderColor:"#000",selectionDashArray:[3,6],selectionLineWidth:1}),e?(u.diyId=e,i&&(u.typeId=i),n.tipHtml("loading","正在加载"),a.getDiy({id:u.diyId,type:u.typeId},function(e){n.hideTip();var i=JSON.parse(e.diy.content);u.plateRATIO=i.plateRATIO,u.oldCutWidth=i.oldCutWidth,u.oldCutHeight=i.oldCutHeight,u.cutArea(u.baseWidth,u.baseHeight),u.mainCanvas.loadFromJSON(i,function(){u.resizeCanvasSize(),u.resizeRender(),u.mainCanvas.renderAll.bind(u.mainCanvas)},function(t,e){e.hasControls=!1,e.lockMovementX=e.lockMovementY=!0,u.mainCanvas.renderAll()}),u.bottle={id:t("#bottle_id").val(),img_url:t("#bottle_img_url").val()}})):alert("diy获取错误"),u.dowmCanvas(),u.delObject()},u.mtid=null,t(document).ready(function(){var n=t("#diyId").val(),c=t("#diytype").val();t(".add_icon").click(function(){t(".func_add").toggleClass("func_add_click"),t(".djsy-position-view-wrap").addClass("djsy-position-view-ani"),t("#djsy_full_sceen").fadeOut()}),t("#diy_bg_img_file").change(function(){if(!t(this).val())return!1;var e=new FormData(t("#diy_bg_img_form")[0]);a.uploadImg(e,function(e){u.addImg(e.img_url),t("#diy_bg_img_file").val("")})}),t("#djsy_add_text_btn").click(function(){r("输入内容")}),t("#changeFont > li").each(function(){t(this).click(function(){var e=t(this).data("val");u.setActiveStyle("fontFamily",e),t("#showFont").text(e);var i=t(this).find("div")[0].className;t("#showFont").removeClass().addClass(i),mui("#djsy_text_edit_popover").popover("toggle")})}),t("#djsy_add_source_btn").click(function(){t(".djsy-pop-wrap").show(),s()}),t("#close_pop").click(function(){t(".djsy-pop-wrap").hide()}),u.init(n,c),e(),i(),o(),d()})}(jQuery)},function(t,e,i){var n=i(0),a={getMaterialType:function(t){$.ajax({url:"/wap/api/getMaterialType",type:"GET",dataType:"json",success:function(e){if(!e.success)return void alert(e.msg);"function"==typeof t&&t(e)}})},getMaterial:function(t,e){$.ajax({url:"/wap/api/getMaterial",type:"GET",data:{tid:t},dataType:"json",success:function(t){if(!t.success)return void alert(t.msg);"function"==typeof e&&e(t)}})},getColor:function(t){$.ajax({url:"/admin/js/color.json",type:"GET",dataType:"json",success:function(e){"function"==typeof t&&t(e)}})},uploadImg:function(t,e){$.ajax({url:"/wap/api/uploadImg",type:"POST",data:t,dataType:"json",cache:!1,processData:!1,contentType:!1,success:function(t){if(!t.success)return void alert(t.msg);"function"==typeof e&&e(t)}})},saveDiy:function(t,e){$.ajax({url:"/wap/api/saveDiy",type:"POST",data:t,dataType:"json",success:function(t){if(n.hideTip(),!t.success)return void alert(t.msg);"function"==typeof e&&e(t)}})},addCart:function(t,e){$.ajax({url:"/wap/api/addCart",type:"POST",data:t,dataType:"json",success:function(t){if(n.hideTip(),!t.success)return void alert(t.msg);"function"==typeof e&&e(t)}})},getDiy:function(t,e){$.ajax({url:"/wap/api/getDiyById",type:"GET",data:t,dataType:"json",success:function(t){if(!t.success)return void alert(t.msg);"function"==typeof e&&e(t)}})}};t.exports=a}]);
|