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>",a+='<div class="mark"></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(".tipHtml").remove(),t(".mark").remove()}function a(t,e){var i,n,a;try{n=t.toString().split(".")[1].length}catch(t){n=0}try{a=e.toString().split(".")[1].length}catch(t){a=0}return i=Math.pow(10,Math.max(n,a)),(t*i+e*i)/i}function o(t,e){var i,n,a,o;try{n=t.toString().split(".")[1].length}catch(t){n=0}try{a=e.toString().split(".")[1].length}catch(t){a=0}return i=Math.pow(10,Math.max(n,a)),o=n>=a?n:a,((t*i-e*i)/i).toFixed(o)}function r(t,e){var i=0;try{i+=t.toString().split(".")[1].length}catch(t){}try{i+=e.toString().split(".")[1].length}catch(t){}return Number(t.toString().replace(".",""))*Number(e.toString().replace(".",""))/Math.pow(10,i)}function c(t,e){var i,n,a=0,o=0;try{a=t.toString().split(".")[1].length}catch(t){a=0}try{o=e.toString().split(".")[1].length}catch(t){o=0}return i=Number(t.toString().replace(".","")),n=Number(e.toString().replace(".","")),i/n*Math.pow(10,o-a)}return{tipHtml:e,hideTip:n,loading:i,numAdd:a,numSub:o,numMulti:r,numDiv:c}}(jQuery);t.exports=i},function(t,e,i){var n=i(0),a=i(2);!function(t){function e(){a.getMaterialType(function(e){var i=e.list,n="";e.list.forEach(function(t){n+='<option value="'+t.id+'">'+t.title+"</option>"}),t("#diy_color_select").html(n),o(i[0].id)})}function i(){t("#diy_color_select").change(function(){var e=t(this).val();e&&e!=f.mtid&&o(e),f.mtid=e})}function o(e){a.getMaterial(e,function(e){for(var i="",n=0;n<e.list.length;n++)i+='<div class="box_item" data-imgUrl="'+e.list[n].img_url+'">',i+='<div class="c">',i+='<p><img src="'+e.list[n].img_url+'" /></p>',i+="<p>"+e.list[n].title+"</p>",i+="</div>",i+="</div>";t("#diy_box_content").html(i),t(".do-nicescroll").getNiceScroll().resize(),t(".box_item").each(function(){t(this).unbind("click").click(function(){var e=t(this).data("imgurl");f.addImg(e)})})})}function r(){t(window).resize(function(e){f.mainCanvas&&(f.baseWidth=t(".diy_canvas_wrap").width(),f.baseHeight=t(".diy_canvas_wrap").height(),f.cutArea(f.baseWidth,f.baseHeight,!0),f.resizeCanvasSize())})}function c(){t("#diy_resize").click(function(){f.cutArea(f.baseWidth,f.baseHeight),f.resizeRender()})}function s(){t("#view_ward .click_show_item").each(function(){t(this).click(function(){switch(t(this).data("key")){case 0:var e=f.mainCanvas.getActiveObject();if(!e||"undefined"==e)return!1;f.mainCanvas.bringForward(e),f.mainCanvas.renderAll();break;case 1:var e=f.mainCanvas.getActiveObject();if(!e||"undefined"==e)return!1;f.mainCanvas.sendBackwards(e),f.mainCanvas.renderAll();break;case 2:var e=f.mainCanvas.getActiveObject();if(!e||"undefined"==e)return!1;f.mainCanvas.bringToFront(e),f.mainCanvas.renderAll();break;default:var e=f.mainCanvas.getActiveObject();if(!e||"undefined"==e)return!1;f.mainCanvas.sendToBack(e),f.mainCanvas.renderAll()}})})}function l(){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").each(function(){t(this).click(function(){var e=t(this).data("color");f.setActiveStyle("fill",e),t(".color-span >i").css("background-color",e)})})})}function d(){t("#diy_preview").click(function(){var e=f.returnCanvasImg(200),i=document.createElement("canvas"),n=i.getContext("2d"),a=new Image;a.src=f.bottle.img_url,console.log(f.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*f.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)}}})}function u(){t(".close_modal").click(function(){t(".GlobalModalsWrapper").hide()})}function v(){t("#diy_save_diy_btn").click(function(){if(f.mainCanvas._objects.length<=0)return alert("请添加内容"),!1;n.tipHtml("loading","正在提交");var t={id:f.diyId,img_url:f.returnCanvasImg(200),content:JSON.stringify(f.returnCanvasJson()),type:f.typeId||""};a.saveDiy(t,function(t){alert(t.msg+"请到个人中心-我的定制中查看"),window.location.href="/user/diy"},function(t){alert(t.msg),window.location.href="/login"})}),t("#addCart").click(function(){if(f.mainCanvas._objects.length<=0)return alert("请添加内容"),!1;n.tipHtml("loading","正在提交");var t={id:f.diyId,img_url:f.returnCanvasImg(200),content:JSON.stringify(f.returnCanvasJson()),type:f.typeId||""};a.addCart(t,function(t){alert(t.msg),window.location.href="/shop/cart"},function(t){alert(t.msg)})})}var f=new Object;f.getActiveStyle=function(t,e){var i=this.mainCanvas;return e=e||i.getActiveObject(),e?e.getSelectionStyles&&e.isEditing?e.getSelectionStyles()[t]||"":e[t]||"":""},f.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()}},f.getActiveProp=function(t,e){var i=this.mainCanvas,e=e||i.getActiveObject();return e?e[t]||"":""},f.setActiveProp=function(t,e,i){var n=this.mainCanvas,i=i||n.getActiveObject();i&&(i.set(t,e).setCoords(),n.renderAll())},f.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])},f.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()})},f.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))},f.centerObj=function(t){console.log(t);var e=f.transformViewPoint();t.set("left",e.x-t.width*t.scaleX/2),t.set("top",e.y-t.height*t.scaleY/2),t.setCoords()},f.addText=function(t){var e=this,i=new fabric.IText(t,{fontSize:30,textAlign:"left",cornerStyle:"circle",borderColor:"#000",cornerColor:"#000",fontFamily:"微软雅黑",cornerSize:15,rotatingPointOffset:30,borderDashArray:[3,6]});i.on("editing:entered",function(){f.textFlage=!0}),i.on("editing:exited",function(){f.textFlage=!1}),f.ControlVisibility(i),e.centerObj(i),e.mainCanvas.add(i).setActiveObject(i),e.mainCanvas.renderAll()},f.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()})},f.cloneObject=function(){var e=this;t("#diy_clone_object").click(function(){if(e.mainCanvas.getActiveGroup())return alert("请选择单个对象复制"),!1;var t=e.mainCanvas.getActiveObject();if(!t||"undefined"==t)return!1;e.mainCanvas.getCenter();t.clone(function(t){e.centerObj(t),e.mainCanvas.add(t).setActiveObject(t)},["cornerSize","_controlsVisibility","cornerStyle","rotatingPointOffset","borderDashArray","borderColor","cornerColor","fill"])})},f.dowmCanvas=function(e){e.on("mouse:down",function(e){e.target&&"i-text"==e.target.type?t("#editor-panel").show():(t("#editor-panel").hide(),t(".diy_top_nav_item").removeClass("active"))}),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"})})},f.returnCanvasImg=function(t){var e=this;f.outputWidth=t||500,f.outputHeight=f.outputWidth/f.plateRATIO;var i=n.numDiv(f.outputWidth,f.oldCutWidth),a=e.mainCanvas.getCenter(),o=e.mainCanvas.getZoom();e.mainCanvas.zoomToPoint(new fabric.Point(a.left,a.top),i);var r=e.mainCanvas.toDataURL({format:"png",left:a.left-f.outputWidth/2,top:a.top-f.outputHeight/2,width:f.outputWidth,height:f.outputHeight});return e.mainCanvas.zoomToPoint(new fabric.Point(a.left,a.top),o),r},f.returnCanvasJson=function(){return this.mainCanvas.toJSON(["borderColor","cornerColor","cornerStyle","cornerSize","rotatingPointOffset","borderDashArray","plateRATIO","viewportTransform","oldCutWidth","oldCutHeight","width","height","_controlsVisibility"])},f.cutArea=function(e,i,n){f.cutCanvas&&t("#cutCanvas").remove(),f.cutCanvas=document.createElement("canvas"),f.cutCanvas.width=e,f.cutCanvas.height=i,f.cutCanvas.id="cutCanvas",t(f.cutCanvas).css({position:"absolute",top:0,left:0,width:e,height:i});var a=f.cutCanvas.getContext("2d");a.fillStyle="rgba(173,173,173,0.8)",a.fillRect(0,0,e,i),f.maxWidth=.8*f.baseWidth,f.maxHeight=.8*f.baseHeight,n||(f.maxHeight*f.plateRATIO<f.maxWidth?(f.cutWidth=f.maxHeight*f.plateRATIO,f.cutHeight=f.maxHeight):(f.cutWidth=f.maxWidth,f.cutHeight=f.maxWidth/f.plateRATIO),f.oldCutWidth||(f.oldCutWidth=f.cutWidth,f.oldCutHeight=f.cutHeight,f.mainCanvas.set("oldCutWidth",f.oldCutWidth),f.mainCanvas.set("oldCutHeight",f.oldCutHeight))),a.clearRect((e-f.cutWidth)/2,(i-f.cutHeight)/2,f.cutWidth,f.cutHeight),t("#diy").after(f.cutCanvas)},f.resizeCanvasSize=function(){var t=this.mainCanvas;f.centerLeft=t.getWidth()/2,f.centerTop=t.getHeight()/2,t.setWidth(f.baseWidth),t.setHeight(f.baseHeight);var e=t.getCenter();t.discardActiveGroup(),f.resizeLeft=e.left-f.centerLeft,f.resizeTop=e.top-f.centerTop;var i=t.getZoom(),n=t.getObjects();for(var a in n)n[a].left=n[a].left+f.resizeLeft/i,n[a].top=n[a].top+f.resizeTop/i,n[a].setCoords();t.renderAll(),t.calcOffset()},f.cutRATIO=null,f.resizeRender=function(){var t=this,e=n.numDiv(f.cutWidth,f.oldCutWidth);if(f.cutRATIO==e)return!1;f.cutRATIO=e;var i=t.mainCanvas.getCenter();t.mainCanvas.zoomToPoint(new fabric.Point(i.left,i.top),f.cutRATIO),t.mainCanvas.renderAll(),t.mainCanvas.calcOffset()},f.init=function(i,o){f.baseWidth=t(".diy_canvas_wrap").width(),f.baseHeight=t(".diy_canvas_wrap").height(),f.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}),i?(f.diyId=i,o&&(f.typeId=o),n.tipHtml("loading","正在加载"),a.getDiy({id:f.diyId,type:f.typeId},function(e){var i=JSON.parse(e.diy.content);f.plateRATIO=i.plateRATIO,f.oldCutWidth=i.oldCutWidth,f.oldCutHeight=i.oldCutHeight,f.cutArea(f.baseWidth,f.baseHeight),f.mainCanvas.loadFromJSON(i,function(){n.hideTip(),f.resizeCanvasSize(),f.resizeRender(),f.mainCanvas.renderAll.bind(f.mainCanvas)},function(t,e){e.hasControls=!1,e.lockMovementX=e.lockMovementY=!0,f.mainCanvas.renderAll()}),f.bottle={id:t("#bottle_id").val(),img_url:t("#bottle_img_url").val()}})):alert("diy获取错误"),f.dowmCanvas(f.mainCanvas),e()},f.mtid=null,t(document).ready(function(){var e=t("#diyId").val(),n=t("#diytype").val();if(!e)return alert("获取内容失败"),!1;f.init(e,n),t(".do-nicescroll").niceScroll(),t(".diy_top_nav_item").each(function(){t(this).click(function(){t(this).hasClass("active")?t(".diy_top_nav_item").removeClass("active"):(t(".diy_top_nav_item").removeClass("active"),t(this).addClass("active"))})}),t("#add_text_btn").click(function(){var t=prompt("请输入内容","这是标题");null!=t&&""!=t&&f.addText(t)}),t("#diy_bg_img_file").change(function(){var e=t(this).val();if(!e)return!1;var i=new FormData(t("#diy_bg_img_form")[0]);i.append("image",e),a.uploadImg(i,function(e){f.addImg(e.img_url),t("#diy_bg_img_file").val("")})}),t("#changeFont > li").each(function(){t(this).click(function(){var e=t(this).data("val");f.setActiveStyle("fontFamily",e),t("#showFont").text(e);var i=t(this).find("div")[0].className;t("#showFont").removeClass().addClass(i)})}),i(),r(),c(),s(),f.cloneObject(),f.delObject(),l(),d(),u(),v()})}(jQuery)},function(t,e,i){var n=i(0),a={getMaterialType:function(t){$.ajax({url:"/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:"/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:"/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,i){$.ajax({url:"/api/saveDiy",type:"POST",data:t,dataType:"json",success:function(t){if(n.hideTip(),!t.success)return void("function"==typeof i&&i(t));"function"==typeof e&&e(t)}})},addCart:function(t,e,i){$.ajax({url:"/api/addCart",type:"POST",data:t,dataType:"json",success:function(t){if(n.hideTip(),!t.success)return void("function"==typeof i&&i(t));"function"==typeof e&&e(t)}})},getDiy:function(t,e,i){$.ajax({url:"/api/getDiyById",type:"GET",data:t,dataType:"json",success:function(t){if(n.hideTip(),!t.success)return void alert(t.msg);"function"==typeof e&&e(t)}})}};t.exports=a}]);
|