pcDiy.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. var util = require('./util');
  2. var sdzAjax = require('./sdzAjax');
  3. ;(function($){
  4. var app = new Object();
  5. /*获取 当前活动元素或指定元素的样式*/
  6. app.getActiveStyle = function(styleName,object){
  7. var canvas = this.mainCanvas;
  8. object = object || canvas.getActiveObject();
  9. if(!object) return '';
  10. return (object.getSelectionStyles && object.isEditing) ? (object.getSelectionStyles()[styleName] || '') : (object[styleName] || '');
  11. }
  12. /*设置 当前活动元素或指定元素的样式*/
  13. app.setActiveStyle = function(styleName,value,object){
  14. var canvas = this.mainCanvas;
  15. object = object || canvas.getActiveObject();
  16. if (!object) return;
  17. if (object.setSelectionStyles && object.isEditing) {
  18. var style = {};
  19. style[styleName] = value;
  20. object.setSelectionStyles(style);
  21. object.setCoords();
  22. }
  23. else {
  24. object.set(styleName, value);
  25. }
  26. object.setCoords();
  27. canvas.renderAll();
  28. }
  29. /*获取 当前活动或者指定元素的属性值*/
  30. app.getActiveProp = function(name,object){
  31. var canvas = this.mainCanvas;
  32. var object = object || canvas.getActiveObject();
  33. if (!object) return '';
  34. return object[name] || '';
  35. }
  36. /*设置 当前活动或者指定元素的属性值*/
  37. app.setActiveProp = function(name, value,object){
  38. var canvas = this.mainCanvas;
  39. var object = object || canvas.getActiveObject();
  40. if (!object) return;
  41. object.set(name, value).setCoords();
  42. canvas.renderAll();
  43. }
  44. /*调整印花控制器显示的个数*/
  45. app.ControlVisibility = function(canvasItem){
  46. var _controlsVisibility = {
  47. tl: !0,
  48. tr: !0,
  49. br: !0,
  50. bl: !0,
  51. ml: 0,
  52. mt: 0,
  53. mr: 0,
  54. mb: 0,
  55. mtr: !0
  56. }
  57. for(var item in _controlsVisibility){
  58. canvasItem['setControlVisible'](item,_controlsVisibility[item]);
  59. }
  60. }
  61. //添加图片
  62. app.addImg = function(url){
  63. var that = this;
  64. fabric.Image.fromURL(url,function(designImg){
  65. designImg.set({
  66. cornerSize:15,
  67. cornerStyle:'circle',
  68. rotatingPointOffset:30,
  69. borderDashArray:[3,6],
  70. borderColor:'#000',
  71. cornerColor: '#000'
  72. });
  73. //图片宽高比
  74. var imgRATIO = designImg.width / designImg.height;
  75. //图片最大尺寸 app.oldCutWidth
  76. that.maxWidthImg = that.oldCutWidth*0.8;
  77. that.maxHeightImg = that.oldCutHeight*0.8;
  78. var imgWidth,imgHeight
  79. //app.cutWidth
  80. if(that.maxHeightImg*imgRATIO < that.maxWidthImg ){
  81. imgWidth = that.maxHeightImg*imgRATIO;
  82. imgHeight = that.maxHeightImg;
  83. }else{
  84. imgWidth = that.maxWidthImg;
  85. imgHeight = that.maxWidthImg/imgRATIO;
  86. }
  87. designImg.setWidth(imgWidth);
  88. designImg.setHeight(imgHeight);
  89. that.centerObj(designImg);
  90. that.mainCanvas.add(designImg).setActiveObject(designImg);
  91. that.mainCanvas.renderAll();
  92. that.mainCanvas.calcOffset();
  93. })
  94. }
  95. //返回当前中心店坐标
  96. app.transformViewPoint = function(o){
  97. var that = this;
  98. var point = that.mainCanvas.getCenter();
  99. if(o){
  100. var i ={
  101. x:o.x,
  102. y:o.y
  103. }
  104. }else{
  105. var i ={
  106. x:point.left,
  107. y:point.top
  108. }
  109. }
  110. // after 计算出 变换之后 中心点坐标
  111. var after = fabric.util.transformPoint(i, fabric.util.invertTransform(that.mainCanvas.viewportTransform));
  112. return after;
  113. }
  114. //当前元素居中
  115. app.centerObj = function(obj){
  116. var that = this;
  117. console.log(obj)
  118. var afterPoint = app.transformViewPoint();
  119. obj.set('left',afterPoint.x - obj.width*obj.scaleX/2);
  120. obj.set('top',afterPoint.y - obj.height*obj.scaleY/2);
  121. obj.setCoords();
  122. }
  123. //添加文字
  124. app.addText = function(texts){
  125. var that = this;
  126. var text = new fabric.IText(texts, {
  127. fontSize: 30,
  128. textAlign:'left',
  129. cornerStyle:'circle',
  130. borderColor:'#000',
  131. cornerColor: '#000',
  132. fontFamily:'微软雅黑',
  133. cornerSize:15,
  134. rotatingPointOffset:30,
  135. borderDashArray:[3,6]
  136. });
  137. text.on('editing:entered',function(){
  138. app.textFlage = true;
  139. });
  140. text.on('editing:exited',function(){
  141. app.textFlage = false;
  142. });
  143. app.ControlVisibility(text);
  144. that.centerObj(text);
  145. that.mainCanvas.add(text).setActiveObject(text);
  146. that.mainCanvas.renderAll();
  147. }
  148. app.delObject = function(){
  149. var that = this;
  150. $("#diy_del_object").click(function(){
  151. if(that.mainCanvas.getActiveGroup()){
  152. alert('请选择单个对象删除');
  153. return false;
  154. }
  155. var obj = that.mainCanvas.getActiveObject();
  156. if(!obj||obj=='undefined'){return false;}
  157. that.mainCanvas.remove(obj);
  158. that.mainCanvas.renderAll();
  159. });
  160. }
  161. app.cloneObject = function(){
  162. var that = this;
  163. $("#diy_clone_object").click(function(){
  164. if(that.mainCanvas.getActiveGroup()){
  165. alert('请选择单个对象复制');
  166. return false;
  167. }
  168. var obj = that.mainCanvas.getActiveObject();
  169. if(!obj||obj=='undefined'){return false;}
  170. var point = that.mainCanvas.getCenter();
  171. obj.clone(function(obj){
  172. that.centerObj(obj);
  173. that.mainCanvas.add(obj).setActiveObject(obj);
  174. },["cornerSize","_controlsVisibility","cornerStyle","rotatingPointOffset","borderDashArray","borderColor","cornerColor","fill"]);
  175. });
  176. }
  177. //canvas 检测按下
  178. app.dowmCanvas = function(canvas){
  179. canvas.on('mouse:down',function(options){
  180. if(options.target && options.target.type=='i-text'){
  181. $("#editor-panel").show();
  182. }else{
  183. $("#editor-panel").hide();
  184. $(".diy_top_nav_item").removeClass('active');
  185. }
  186. });
  187. canvas.on('mouse:up',function(options){
  188. if(options.target){
  189. }
  190. });
  191. canvas.on('object:selected',function(options){
  192. var group = canvas.getActiveGroup();
  193. if(group){
  194. group.set({
  195. cornerSize:15,
  196. cornerStyle:'circle',
  197. rotatingPointOffset:30,
  198. borderDashArray:[3,6],
  199. borderColor:'#000',
  200. cornerColor: '#000'
  201. })
  202. }
  203. })
  204. }
  205. //把当前画布保存成图片
  206. app.returnCanvasImg = function(width){
  207. var that= this;
  208. app.outputWidth = width || 500 ;
  209. app.outputHeight = app.outputWidth/app.plateRATIO;
  210. //新的缩放比例
  211. var afterCutRATIO = util.numDiv(app.outputWidth,app.oldCutWidth);
  212. //中心点坐标
  213. var point = that.mainCanvas.getCenter();
  214. //之前缩放比例
  215. var zoomNum = that.mainCanvas.getZoom();
  216. //执行新的缩放
  217. that.mainCanvas.zoomToPoint(new fabric.Point(point.left,point.top),afterCutRATIO);
  218. //生成剪切图片
  219. var dataURL = that.mainCanvas.toDataURL({
  220. format: 'png',
  221. left: point.left -app.outputWidth/2 ,
  222. top: point.top - app.outputHeight/2,
  223. width: app.outputWidth,
  224. height: app.outputHeight
  225. });
  226. //缩放回原来大小
  227. that.mainCanvas.zoomToPoint(new fabric.Point(point.left,point.top),zoomNum);
  228. return dataURL;
  229. }
  230. app.returnCanvasJson = function(){
  231. var that = this;
  232. return that.mainCanvas.toJSON([
  233. 'borderColor',
  234. 'cornerColor',
  235. 'cornerStyle',
  236. 'cornerSize',
  237. 'rotatingPointOffset',
  238. 'borderDashArray',
  239. 'plateRATIO',
  240. 'viewportTransform',
  241. 'oldCutWidth',
  242. 'oldCutHeight',
  243. 'width',
  244. 'height',
  245. '_controlsVisibility'
  246. ]);
  247. }
  248. //绘制剪切区域
  249. app.cutArea = function(width,height,win){
  250. if(app.cutCanvas){
  251. $("#cutCanvas").remove();
  252. }
  253. app.cutCanvas = document.createElement('canvas');
  254. app.cutCanvas.width = width;
  255. app.cutCanvas.height= height;
  256. app.cutCanvas.id = 'cutCanvas';
  257. $(app.cutCanvas).css({
  258. position:'absolute',
  259. top:0,
  260. left:0,
  261. width:width,
  262. height:height
  263. });
  264. var cutCtx = app.cutCanvas.getContext('2d');
  265. cutCtx.fillStyle = 'rgba(173,173,173,0.8)';
  266. cutCtx.fillRect(0,0,width,height);
  267. //剪切区域的最大高度 和宽度
  268. app.maxWidth = app.baseWidth*0.8;
  269. app.maxHeight = app.baseHeight*0.8;
  270. if(!win){
  271. if(app.maxHeight*app.plateRATIO < app.maxWidth){
  272. app.cutWidth = app.maxHeight*app.plateRATIO;
  273. app.cutHeight = app.maxHeight;
  274. }else {
  275. app.cutWidth = app.maxWidth;
  276. app.cutHeight = app.maxWidth/app.plateRATIO;
  277. }
  278. if(!app.oldCutWidth){
  279. //存储之前剪切大小
  280. app.oldCutWidth = app.cutWidth;
  281. app.oldCutHeight = app.cutHeight;
  282. app.mainCanvas.set('oldCutWidth',app.oldCutWidth);
  283. app.mainCanvas.set('oldCutHeight',app.oldCutHeight);
  284. }
  285. }
  286. cutCtx.clearRect((width-app.cutWidth)/2,(height-app.cutHeight)/2, app.cutWidth, app.cutHeight);
  287. $("#diy").after(app.cutCanvas);
  288. }
  289. //变换屏幕变换时,让canvas 元素居中
  290. app.resizeCanvasSize = function(){
  291. var canvas = this.mainCanvas;
  292. app.centerLeft = canvas.getWidth()/2;
  293. app.centerTop = canvas.getHeight()/2;
  294. canvas.setWidth(app.baseWidth);
  295. canvas.setHeight(app.baseHeight);
  296. var point = canvas.getCenter();
  297. //抛弃选择中的组
  298. canvas.discardActiveGroup();
  299. app.resizeLeft = point.left - app.centerLeft,
  300. app.resizeTop = point.top - app.centerTop;
  301. var zoomNum = canvas.getZoom();
  302. //console.log(zoomNum)
  303. var objects = canvas.getObjects();
  304. //console.log(objects[0])
  305. for (var i in objects) {
  306. objects[i].left = objects[i].left + app.resizeLeft/zoomNum;
  307. objects[i].top = objects[i].top + app.resizeTop/zoomNum;
  308. objects[i].setCoords();
  309. }
  310. canvas.renderAll();
  311. canvas.calcOffset();
  312. }
  313. app.cutRATIO = null;
  314. //自适应屏幕 缩放
  315. app.resizeRender = function(){
  316. var that = this;
  317. //缩放比例
  318. var afterCutRATIO = util.numDiv(app.cutWidth,app.oldCutWidth);
  319. if(app.cutRATIO == afterCutRATIO){
  320. return false;
  321. }else{
  322. app.cutRATIO = afterCutRATIO;
  323. }
  324. var point = that.mainCanvas.getCenter();
  325. that.mainCanvas.zoomToPoint(new fabric.Point(point.left,point.top),app.cutRATIO);
  326. that.mainCanvas.renderAll();
  327. that.mainCanvas.calcOffset();
  328. }
  329. app.init = function(did,typeId){
  330. //diy 基础宽度
  331. app.baseWidth = $(".diy_canvas_wrap").width();
  332. app.baseHeight = $(".diy_canvas_wrap").height();
  333. app.mainCanvas = new fabric.Canvas('diy',{
  334. selectionColor: 'rgba(0,0,0,0.1)',
  335. controlsAboveOverlay:true,
  336. preserveObjectStacking:true,
  337. backgroundColor:'rgba(255,255,255,0)',
  338. selctionBorderColor:'#000',
  339. selectionDashArray:[3,6],
  340. selectionLineWidth: 1
  341. });
  342. if(did){
  343. app.diyId = did;
  344. if(typeId){
  345. app.typeId = typeId;
  346. }
  347. util.tipHtml('loading','正在加载');
  348. sdzAjax.getDiy({id:app.diyId,type:app.typeId},function(data){
  349. //console.log(data);
  350. var json = JSON.parse(data.diy.content);
  351. app.plateRATIO = json.plateRATIO;
  352. app.oldCutWidth = json.oldCutWidth;
  353. app.oldCutHeight = json.oldCutHeight;
  354. app.cutArea(app.baseWidth,app.baseHeight);
  355. app.mainCanvas.loadFromJSON(json,function(){
  356. util.hideTip();
  357. app.resizeCanvasSize();
  358. app.resizeRender();
  359. app.mainCanvas.renderAll.bind(app.mainCanvas)
  360. },function(o,obj){
  361. obj.hasControls = false;
  362. obj.lockMovementX = obj.lockMovementY = true;
  363. app.mainCanvas.renderAll();
  364. });
  365. app.bottle = {
  366. id:$("#bottle_id").val(),
  367. img_url:$("#bottle_img_url").val()
  368. }
  369. });
  370. }else{
  371. alert('diy获取错误')
  372. }
  373. app.dowmCanvas(app.mainCanvas);
  374. //获取产品分类
  375. getMaterialType();
  376. }
  377. //获取分类 sdzAjax
  378. function getMaterialType(){
  379. sdzAjax.getMaterialType(function(res){
  380. var list = res.list;
  381. var html = '';
  382. res.list.forEach(function(item){
  383. html+='<option value="'+ item.id +'">'+ item.title +'</option>';
  384. })
  385. $("#diy_color_select").html(html);
  386. //
  387. getMaterial(list[0].id);
  388. });
  389. }
  390. //素材分类 ID
  391. app.mtid = null;
  392. //change select
  393. function changeSelectMaterialType(){
  394. $("#diy_color_select").change(function(){
  395. var id = $(this).val();
  396. id && id != app.mtid && getMaterial(id);
  397. app.mtid = id;
  398. })
  399. }
  400. //获取分类下面内容
  401. function getMaterial(id){
  402. sdzAjax.getMaterial(id,function(res){
  403. var html ='';
  404. for(var i=0;i<res.list.length;i++){
  405. html+='<div class="box_item" data-imgUrl="'+ res.list[i].img_url +'">';
  406. html+='<div class="c">';
  407. html+='<p><img src="'+res.list[i].img_url+'" /></p>';
  408. html+='<p>'+res.list[i].title+'</p>';
  409. html+='</div>';
  410. html+='</div>';
  411. }
  412. $("#diy_box_content").html(html);
  413. $(".do-nicescroll").getNiceScroll().resize();
  414. $(".box_item").each(function(){
  415. $(this).unbind('click').click(function(){
  416. //添加设计图
  417. var imgUrl = $(this).data('imgurl');
  418. app.addImg(imgUrl);
  419. })
  420. })
  421. })
  422. }
  423. //屏幕变化的时候
  424. function windowResize(){
  425. $(window).resize(function(e){
  426. if(app.mainCanvas){
  427. app.baseWidth = $(".diy_canvas_wrap").width();
  428. app.baseHeight = $(".diy_canvas_wrap").height();
  429. //变换剪切区域
  430. app.cutArea(app.baseWidth,app.baseHeight,true);
  431. app.resizeCanvasSize();
  432. }
  433. })
  434. }
  435. //适应屏幕
  436. function niceWindow(){
  437. $("#diy_resize").click(function(){
  438. app.cutArea(app.baseWidth,app.baseHeight);
  439. app.resizeRender();
  440. })
  441. }
  442. //层级修改
  443. function changeHierarchy(){
  444. $("#view_ward .click_show_item").each(function(){
  445. $(this).click(function(){
  446. var key = $(this).data('key');
  447. switch(key)
  448. {
  449. case 0://上一层
  450. var obj = app.mainCanvas.getActiveObject();
  451. if(!obj||obj=='undefined'){return false;};
  452. app.mainCanvas.bringForward(obj);
  453. app.mainCanvas.renderAll();
  454. break;
  455. case 1: //下一层
  456. var obj = app.mainCanvas.getActiveObject();
  457. if(!obj||obj=='undefined'){return false;};
  458. app.mainCanvas.sendBackwards(obj);
  459. app.mainCanvas.renderAll();
  460. break;
  461. case 2: //置顶
  462. var obj = app.mainCanvas.getActiveObject();
  463. if(!obj||obj=='undefined'){return false;};
  464. app.mainCanvas.bringToFront(obj);
  465. app.mainCanvas.renderAll();
  466. break;
  467. default: //置底
  468. var obj = app.mainCanvas.getActiveObject();
  469. if(!obj||obj=='undefined'){return false;};
  470. app.mainCanvas.sendToBack(obj);
  471. app.mainCanvas.renderAll();
  472. }
  473. })
  474. })
  475. }
  476. //颜色遍历
  477. function getColor(){
  478. sdzAjax.getColor(function(data){
  479. var html = ''
  480. var divContent = '<div class="djsy-color-panel-item">{span}</div>'
  481. var spanContent = '<span data-color="{color}" style="background-color:{color}"></span>'
  482. for( var item in data.colorPanel){
  483. var span = ''
  484. for(var i=0;i<data.colorPanel[item].length;i++){
  485. span+=spanContent.replace(/{color}/g,data.colorPanel[item][i]);
  486. }
  487. html+=divContent.replace("{span}",span);
  488. }
  489. $("#djsy_text_color_panel_content").html(html);
  490. $("#djsy_text_color_panel_content .djsy-color-panel-item > span").each(function(){
  491. $(this).click(function(){
  492. var color = $(this).data('color');
  493. app.setActiveStyle('fill',color);
  494. $(".color-span >i").css('background-color',color);
  495. })
  496. })
  497. });
  498. }
  499. //预览效果
  500. function previewCanvas(){
  501. $("#diy_preview").click(function(){
  502. var imgUrl = app.returnCanvasImg(200);
  503. var previewCanvas = document.createElement('canvas');
  504. var ctx = previewCanvas.getContext("2d");
  505. var img = new Image();
  506. img.src = app.bottle.img_url;
  507. console.log(app.bottle);
  508. img.onload = function(){
  509. console.log(img.onload);
  510. previewCanvas.width = img.width;
  511. previewCanvas.height = img.height;
  512. ctx.drawImage(img,0,0,img.width,img.height);
  513. var imgBotte = new Image();
  514. imgBotte.src = imgUrl;
  515. imgBotte.onload = function(){
  516. imgBotte.height = img.height*0.54;
  517. imgBotte.width = imgBotte.height*app.plateRATIO;
  518. ctx.drawImage(imgBotte,(img.width-imgBotte.width)/2,img.height*0.3,imgBotte.width,imgBotte.height);
  519. var imgBotteUrl = previewCanvas.toDataURL();
  520. $("#previewCanvas").show();
  521. var imgEle = '<img class="previewImg" src="'+ imgBotteUrl +'"/>';
  522. $("#previewImgWrap").html(imgEle);
  523. }
  524. }
  525. });
  526. }
  527. //关闭弹窗
  528. function close_modal(){
  529. $(".close_modal").click(function(){
  530. $(".GlobalModalsWrapper").hide();
  531. })
  532. }
  533. //保存diy
  534. function saveCanvas(){
  535. $("#diy_save_diy_btn").click(function(){
  536. var obj = app.mainCanvas._objects;
  537. if(obj.length<=0){
  538. alert("请添加内容");
  539. return false;
  540. }
  541. util.tipHtml('loading','正在提交');
  542. var data = {
  543. id :app.diyId,
  544. img_url:app.returnCanvasImg(200),
  545. content:JSON.stringify(app.returnCanvasJson()),
  546. type:app.typeId || ''
  547. }
  548. sdzAjax.saveDiy(data,function(data){
  549. alert(data.msg +'请到个人中心-我的定制中查看');
  550. window.location.href = '/user/diy';
  551. },function(err){
  552. alert(err.msg);
  553. window.location.href = '/login';
  554. });
  555. });
  556. $("#addCart").click(function(){
  557. //
  558. var obj = app.mainCanvas._objects;
  559. if(obj.length<=0){
  560. alert("请添加内容");
  561. return false;
  562. }
  563. util.tipHtml('loading','正在提交');
  564. var data = {
  565. id :app.diyId,
  566. img_url:app.returnCanvasImg(200),
  567. content:JSON.stringify(app.returnCanvasJson()),
  568. type:app.typeId || ''
  569. }
  570. sdzAjax.addCart(data,function(data){
  571. alert(data.msg);
  572. window.location.href = '/shop/cart';
  573. },function(err){
  574. alert(err.msg);
  575. //window.location.href = '/login';
  576. });
  577. })
  578. }
  579. $(document).ready(function(){
  580. var did = $("#diyId").val();
  581. var typeId = $("#diytype").val();
  582. if(!did){
  583. alert("获取内容失败")
  584. return false;
  585. }
  586. app.init(did,typeId);
  587. $(".do-nicescroll").niceScroll();
  588. //文字显示下拉
  589. $(".diy_top_nav_item").each(function(){
  590. $(this).click(function(){
  591. if($(this).hasClass('active')){
  592. $(".diy_top_nav_item").removeClass('active');
  593. }else{
  594. $(".diy_top_nav_item").removeClass('active');
  595. $(this).addClass('active');
  596. }
  597. })
  598. });
  599. //添加文字
  600. $("#add_text_btn").click(function(){
  601. var title=prompt("请输入内容","这是标题");
  602. if (title!=null && title!=""){
  603. app.addText(title);
  604. }
  605. })
  606. //上传图片
  607. $("#diy_bg_img_file").change(function(){
  608. var imgVal = $(this).val();
  609. if(!imgVal){
  610. return false;
  611. }
  612. var formData = new FormData($("#diy_bg_img_form")[0]);
  613. formData.append("image", imgVal);
  614. sdzAjax.uploadImg(formData,function(data){
  615. app.addImg(data.img_url);
  616. $("#diy_bg_img_file").val('');
  617. });
  618. });
  619. //设置字体
  620. $("#changeFont > li").each(function(){
  621. $(this).click(function(){
  622. var fontVal = $(this).data('val');
  623. app.setActiveStyle('fontFamily',fontVal);
  624. $("#showFont").text(fontVal);
  625. var className = $(this).find('div')[0].className;
  626. $("#showFont").removeClass().addClass(className);
  627. });
  628. });
  629. //改变分类
  630. changeSelectMaterialType();
  631. //屏幕变化的时候
  632. windowResize();
  633. //自适应屏幕
  634. niceWindow();
  635. //改变元素的层级
  636. changeHierarchy();
  637. //复制
  638. app.cloneObject();
  639. //删除
  640. app.delObject();
  641. //设置颜色
  642. getColor()
  643. // 返回预览图
  644. previewCanvas();
  645. //关闭弹窗
  646. close_modal();
  647. //保存
  648. saveCanvas();
  649. });
  650. })(jQuery)