/** * Created by ct on 2016/8/13. */ require.config({ baseUrl: 'resources/js', paths: { "formatData": "lib/charts/formatData", "jquery": "lib/bootstrap/js/jquery-2.1.4.min", "bootstrap": "lib/bootstrap/js/bootstrap.min", "jquery-ui": "lib/jquery-ui.min", "lodash": "lib/gridstack/js/lodash.min", "underscore": "lib/underscore/underscore-min", "spectrum": "lib/bootstrap/js/spectrum", "renderMenu" : 'app/renderMenu', "domReady" : 'lib/domReady', "zrender": "lib/zrender/zrender", "zrender/shape/Rectangle": "lib/zrender/zrender", "zrender/shape/Image": "lib/zrender/zrender", "zrender/tool/color": "lib/zrender/zrender", "zrender/Storage" : "lib/zrender/zrender", "CanvasTag" : "customModule/CanvasTag/CanvasTag", "CanvasTagOfImage" : "customModule/CanvasTag/CanvasTagOfImage", "confirmModal": "lib/confirm/confirm-bootstrap", "vue": "lib/vue/vue", "bootstrapFileStyle": "lib/bootstrapFileStyle/fileinput.min", "interact": "lib/interact/interact", "echarts": "lib/charts/echarts", "theme": "lib/charts/theme", "nicescroll": "lib/nicescroll/jquery.nicescroll.min", "tableExport": "lib/tableExport/tableexport.min", "file-saverjs": "lib/tableExport/FileSaver", "blobjs": "lib/tableExport/Blob", "xlsx": "lib/tableExport/xlsx", "jzip": "lib/tableExport/jszip", "tooltipster": "lib/gridly/tooltipster.bundle.min", "generateTableHtml": "app/generateTableHtml", "commonModule" : 'app/commonModule', "thenBy": "lib/thenBy", "jquery-confirm": "lib/confirm/jquery-confirm.min", "jquery-loading": "lib/jqueryLoading/jquery.loading" }, shim : { "bootstrap" : { "deps" :['jquery'] }, "confirmModal" : { "deps" :['jquery'] }, "bootstrapFileStyle" : { "deps" :['bootstrap'] }, "tableExport": { "deps" :['blobjs', 'file-saverjs', 'xlsx', 'jzip'] } }, waitSeconds: 30 }); require(['jquery','domReady','vue','CanvasTagOfImage','renderMenu','echarts','interact','formatData','CanvasTag','zrender','theme','commonModule', 'bootstrapFileStyle','spectrum','confirmModal','nicescroll','tableExport'], function ($,domReady,vue,CanvasTagOfImage,renderMenu,echarts,interact,formatData,CanvasTag,zrender,theme,commonModule) { domReady(function () { //chartsé…ç½®åŒå‘绑定组件 vue.component('chart-option-component',{ template: formatData.tableAndConfigOfBarAndLine(), props: ['chartOption'], data: function(){ return { option: '', myChart: '', optionSetting: { titleContent: '', titleTop: '', titleX: '', titleFontFamily: '', titleFontSize: '', titleFontWeight: '', titleFontStyle: '', titleFontColor: '', subtitleContent: '', subtitleFontFamily: '', subtitleFontSize: '', subtitleFontWeight: '', subtitleFontStyle: '', subtitleFontColor: '', tooltipShow: '', tooltipBorderColor: '', tooltipBorderWidth: '', tooltipBackgroundColor: '', tooltipFontFamily: '', tooltipFontSize: '', tooltipFontWeight: '', tooltipFontColor: '', backgroundOpacity: '' // xRotate: '', // yAxisContent: '' } } }, watch: { chartOption: function(){ var self = this; //颜色选择器åˆå§‹åŒ– $("#titleFontColor").spectrum({ showInput: true, allowEmpty:true, color: this.chartOption.title[0].textStyle.color, change: function(color){ self.optionSetting.titleFontColor = color.toHexString(); } }); $("#subtitleFontColor").spectrum({ showInput: true, allowEmpty:true, color: this.chartOption.title[0].subtextStyle.color, change: function(color) { self.optionSetting.subtitleFontColor = color.toHexString(); } }); $("#tooltipBorderColor").spectrum({ showInput: true, allowEmpty:true, color: this.chartOption.tooltip[0].borderColor, change: function(color) { self.optionSetting.tooltipBorderColor = color.toHexString(); } }); $("#tooltipBackgroundColor").spectrum({ showInput: true, allowEmpty:true, color: this.chartOption.tooltip[0].backgroundColor, change: function(color) { self.optionSetting.tooltipBackgroundColor = color.toHexString(); } }); $("#tooltipFontColor").spectrum({ showInput: true, allowEmpty:true, color: this.chartOption.tooltip[0].textStyle.color, change: function(color) { self.optionSetting.tooltipFontColor = color.toHexString(); } }); if(JSON.stringify(this.chartOption.backgroundColor).split(",").length<4){ this.chartOption.backgroundColor = 'rgba(255,255,255,1)'; } if(this.chartOption.title[0] || this.chartOption.tooltip[0]){ var settings = { titleContent: this.chartOption.title[0].text, titleTop: this.chartOption.title[0].top, titleX: this.chartOption.title[0].left, titleFontFamily: this.chartOption.title[0].textStyle.fontFamily, titleFontSize: this.chartOption.title[0].textStyle.fontSize, titleFontWeight: this.chartOption.title[0].textStyle.fontWeight, titleFontStyle: this.chartOption.title[0].textStyle.fontStyle, titleFontColor: this.chartOption.title[0].textStyle.color, subtitleContent: this.chartOption.title[0].subtext, subtitleFontFamily: this.chartOption.title[0].subtextStyle.fontFamily, subtitleFontSize: this.chartOption.title[0].subtextStyle.fontSize, subtitleFontWeight: this.chartOption.title[0].subtextStyle.fontWeight, subtitleFontStyle: this.chartOption.title[0].subtextStyle.fontStyle, subtitleFontColor: this.chartOption.title[0].subtextStyle.color, tooltipShow: this.chartOption.tooltip[0].show, tooltipBorderColor: this.chartOption.tooltip[0].borderColor, tooltipBorderWidth: this.chartOption.tooltip[0].borderWidth, tooltipBackgroundColor: this.chartOption.tooltip[0].backgroundColor, tooltipFontFamily: this.chartOption.tooltip[0].textStyle.fontFamily, tooltipFontSize: this.chartOption.tooltip[0].textStyle.fontSize, tooltipFontWeight: this.chartOption.tooltip[0].textStyle.fontWeight, tooltipFontColor: this.chartOption.tooltip[0].textStyle.color, backgroundOpacity: JSON.stringify(this.chartOption.backgroundColor).split(",")[3].replace(')"','')*100, // xRotate: this.chartOption.xAxis[0].axisLabel.rotate ? this.chartOption.xAxis[0].axisLabel.rotate : 0, // yAxisContent: '' }; this.optionSetting = settings; } this.option = this.chartOption; $("#optionModal").unbind("shown.bs.modal"); $("#optionModal").on("shown.bs.modal", function (e) { self.myChart = echarts.init(document.getElementById("optionContainer")); self.myChart.setOption(self.option,true); }); }, optionSetting: { handler: function(val, oldVal){ this.chartOption.title[0].text = this.optionSetting.titleContent; this.chartOption.title[0].top = this.optionSetting.titleTop; this.chartOption.title[0].left = this.optionSetting.titleX; this.chartOption.title[0].textStyle.fontFamily = this.optionSetting.titleFontFamily; this.chartOption.title[0].textStyle.fontSize = this.optionSetting.titleFontSize; this.chartOption.title[0].textStyle.fontWeight = this.optionSetting.titleFontWeight; this.chartOption.title[0].textStyle.fontStyle = this.optionSetting.titleFontStyle; this.chartOption.title[0].textStyle.color = this.optionSetting.titleFontColor; this.chartOption.title[0].subtext = this.optionSetting.subtitleContent; this.chartOption.title[0].subtextStyle.fontFamily = this.optionSetting.subtitleFontFamily; this.chartOption.title[0].subtextStyle.fontSize = this.optionSetting.subtitleFontSize; this.chartOption.title[0].subtextStyle.fontWeight = this.optionSetting.subtitleFontWeight; this.chartOption.title[0].subtextStyle.fontStyle = this.optionSetting.subtitleFontStyle; this.chartOption.title[0].subtextStyle.color = this.optionSetting.subtitleFontColor; this.chartOption.tooltip[0].show = 'false' == this.optionSetting.tooltipShow ? false : true; this.chartOption.tooltip[0].borderColor = this.optionSetting.tooltipBorderColor; this.chartOption.tooltip[0].borderWidth = this.optionSetting.tooltipBorderWidth; this.chartOption.tooltip[0].backgroundColor = this.optionSetting.tooltipBackgroundColor; this.chartOption.tooltip[0].textStyle.fontFamily = this.optionSetting.tooltipFontFamily; this.chartOption.tooltip[0].textStyle.fontSize = this.optionSetting.tooltipFontSize; this.chartOption.tooltip[0].textStyle.fontWeight = this.optionSetting.tooltipFontWeight; this.chartOption.tooltip[0].textStyle.color = this.optionSetting.tooltipFontColor; if(JSON.stringify(this.chartOption.backgroundColor).split(",").length == 4){ this.chartOption.backgroundColor = this.chartOption.backgroundColor.split(",")[0]+","+this.chartOption.backgroundColor.split(",")[1]+","+this.chartOption.backgroundColor.split(",")[2]+","+this.optionSetting.backgroundOpacity*0.01+")"; } // this.chartOption.xAxis[0].axisLabel.rotate = this.optionSetting.xRotate; // this.chartOption.yAxis[0].name = this.optionSetting.yAxisContent; if(this.myChart != ''){ this.myChart.setOption(this.option,true); } }, deep: true } } }); //texté…ç½®åŒå‘绑定组件 vue.component('text-option-component',{ template: formatData.tableAndConfigOfText(), props: ['textOption'], data: function(){ return { option: '', optionSetting: { text: '', textColor: '', fontSize: '', color: '', strokeColor: '' } } }, watch: { textOption: function(){ var self = this; $("#textColor").spectrum({ showInput: true, allowEmpty:true, color: self.textOption.textColor, change: function(color) { self.optionSetting.textColor = color.toHexString(); } }); $("#tagColor").spectrum({ showInput: true, allowEmpty:true, color: self.textOption.color, showAlpha: true, change: function(color) { var c = color.toRgb(); self.optionSetting.color = "rgba(" + c.r + ", " + c.g + ", " + c.b + ", " + c.a + ")"; } }); $("#tagStrokeColor").spectrum({ showInput: true, allowEmpty:true, color: self.textOption.strokeColor, showAlpha: true, change: function(color) { var c = color.toRgb(); self.optionSetting.strokeColor = "rgba(" + c.r + ", " + c.g + ", " + c.b + ", " + c.a + ")"; } }); self.optionSetting.text = self.textOption.text; self.optionSetting.textColor = self.textOption.textColor; self.optionSetting.fontSize = self.textOption.textFont.split(" ")[1].replace("px",""); self.optionSetting.color = self.textOption.color; self.optionSetting.strokeColor = self.textOption.strokeColor; self.option = self.textOption; $("#textOptionModal").unbind("shown.bs.modal"); $("#textOptionModal").on("shown.bs.modal", function (e) { CanvasTag().render("textOptionContainer",self.option); }); }, optionSetting: { handler: function(){ this.option.text = this.optionSetting.text; this.option.textColor = this.optionSetting.textColor; this.option.textFont = this.textOption.textFont.split(" ")[0] + " " +this.optionSetting.fontSize + "px " + this.textOption.textFont.split(" ")[2]; this.option.color = this.optionSetting.color; this.option.strokeColor = this.optionSetting.strokeColor; CanvasTag().render("textOptionContainer",this.option); }, deep: true } } }); //imageé…ç½®åŒå‘绑定组件 vue.component('img-option-component',{ template: formatData.tableAndConfigOfSubGroup(), props: ['subGroupOption'], data: function(){ return { option: '', optionSetting: { subGroupText: '', subGroupTextColor: '', subGroupFontSize: '' } } }, watch: { subGroupOption: function(){ var self = this; $("#subGroupTextColor").spectrum({ showInput: true, allowEmpty:true, color: self.subGroupOption.textColor, change: function(color){ self.optionSetting.subGroupTextColor = color.toHexString(); } }); self.optionSetting.subGroupText = self.subGroupOption.text; self.optionSetting.subGroupTextColor = self.subGroupOption.textColor; self.optionSetting.subGroupFontSize = self.subGroupOption.textFont.split(" ")[1].replace("px",""); self.option = self.subGroupOption; $("#textOptionModal").unbind("shown.bs.modal"); $("#textOptionModal").on("shown.bs.modal", function (e) { CanvasTagOfImage().render("textOptionContainer",'',self.option,false); }); }, optionSetting: { handler: function(){ this.option.text = this.optionSetting.subGroupText; this.option.textColor = this.optionSetting.subGroupTextColor; this.option.textFont = this.subGroupOption.textFont.split(" ")[0] + " " +this.optionSetting.subGroupFontSize+ "px " + this.subGroupOption.textFont.split(" ")[2]; CanvasTagOfImage().render("textOptionContainer",'',this.option,false); }, deep: true } } }); var app = new vue({ el: '#app', data: { backgroundClass: 'background-default', isExpanded: false, isLoader: false, isSaveLoader: 'none', currentActiveIndex: -1, currentSelectedIndex: -1, dangerIndex: -1, helpTip: 'è¯·ä¸Šä¼ ç»„ä»¶å›¾ç‰‡.', isImgLoad: 'none', isChartsLoad: 'none', hideImg: '', isShowImgSetting: false, order: 0, //自定义组件option属性 myWidgetOption: '', subGroupText: '', subGroupTextColor: '', subGroupFontSize: '', subGroupImageWidth: '', subGroupImageHeight: '', subGroupFontLocation: '', //“我的图表â€å’Œâ€œæˆ‘çš„ç»„ä»¶â€æ‰€éœ€åŠ¨æ€æ¸²æŸ“çš„æ•°æ® myCharts: [], mySubGroup: [], //坿‹–拽模å—çš„é…ç½® widgets: [], //选䏿¸²æŸ“是å¦å¤±è´¥ // isRenderFail: false, //当å‰é¡µæ˜¯å¦ä¿å˜ isSave:true, //ç»„ä»¶å‚æ•° chartOption: '', textOption: '', subGroupOption: '', //当剿¸²æŸ“组件 currentView: '', //是å¦å…¨å± isAllScreen: false, //自定义组件图片base64ç¼–ç subGroupBase64: '', //获å–从哪一个图表或者组件èœå•è¿›å…¥ç»†èŠ‚è®¾ç½®æ¨¡æ€æ¡† domId: 0, chartType: '', //是å¦åˆ‡æ¢äº†ä¸»é¢˜ currentTheme: '', renderFailList: [], //æ¯ä¸€ä¸ªå›¾è¡¨containerçš„overflow属性 scrollType: 'visible', tableCurrentPage: {}, currentPage: 1, allSubGroupPage: 0 }, methods: { //èƒŒæ™¯æ ·å¼åˆ‡æ¢ saveCurrentBackground: function(event){ var target = $(event.target); var targetClass = event.target.className.replace("img-thumbnail", "").trim(); $.each(target.parent().siblings().find('span'),function (index,obj) { var sibClass = $(obj).attr("class").replace("img-thumbnail", "").trim() || ""; if(app.backgroundClass == sibClass){ app.backgroundClass = ''; } }); app.backgroundClass = targetClass; var deferred = $.ajax({ type: 'POST', dataType: 'json', url: 'myPanel/crud', data : { exportId : $("#exportId").val(), backgroundClass : targetClass }, headers :{ oper : 'update' }, success: function(){ app.isSave = false; } }); }, //ä¾§è¾¹èœå•æ æ˜¾ç¤º/éšè— toggleSideMenu: function(){ if(app.isExpanded == false){ app.isExpanded = true }else { app.isExpanded = false } }, //æ ‡è®°å½“å‰èœå•所选项 toggleSecondMenu: function(index){ this.currentActiveIndex = index; $(".side-menu .nav .dropdown .collapse").collapse('hide'); }, //顶部èœå•划过动画 topMenuMouseEnter: function(index){ app.dangerIndex = index; }, //自定义控件 makeSelfWidget: function(){ if($("[name='imgFile']").val() == ""){ app.helpTip = '请先选择您è¦ä¸Šä¼ 的控件背景图'; }else { app.isImgLoad = 'block'; $.ajax({ type: 'POST', url: 'imgToBase64', data: new FormData($("#imgFile")[0]), async: false, cache: false, contentType: false, processData: false, success: function(data){ if(data.imgBase64 == "noFile"){ app.helpTip = "请先选择您è¦ä¸Šä¼ 的控件背景图"; app.isImgLoad = 'none'; }else if(data.imgBase64 == "noImage"){ app.helpTip = "è¯·ä¸Šä¼ å›¾ç‰‡ç±»åž‹æ–‡ä»¶"; app.isImgLoad = 'none'; }else{ app.hideImg = ['<img src=\'data:image/jpg;base64,'+data.imgBase64+'\' onerror="this.src=\'resources/img/white.jpg\'">'].join(""); setTimeout(function(){ if($("#subGroupContainer").parent().find("img")[0]){ app.isImgLoad = 'none'; var canvasTagOfImage = CanvasTagOfImage().render("subGroupContainer",$("#subGroupContainer").parent().find("img")[0]); app.isShowImgSetting = true; app.myWidgetOption = canvasTagOfImage.getOption(); app.subGroupBase64 = data.imgBase64; //åˆå§‹åŒ– app.subGroupText = app.myWidgetOption.text; app.subGroupTextColor = app.myWidgetOption.textColor; app.subGroupFontSize = app.myWidgetOption.textFont.split(" ")[1].replace('px',''); app.subGroupFontLocation = app.myWidgetOption.textPosition; } }, 0); } }, error: function(){ alert("ä¸Šä¼ å¤±è´¥ï¼Œè¯·é‡è¯•ï¼"); } }); } }, //èŽ·å–æ‰€æœ‰å›¾è¡¨å’ŒæŽ§ä»¶ getAllCharts: function(tag){ app.allSubGroupPage++; //先置空以防æ¢vue就地å¤ç”¨ if(tag == 'init'){ app.myCharts = []; app.mySubGroup = []; app.allSubGroupPage = 1; } this.currentSelectedIndex = -1; this.isChartsLoad = 'block'; $.ajax({ type: 'POST', url: 'selectChartInfo', data: { page: app.allSubGroupPage, pageSize: 10 }, success: function(response){ app.isChartsLoad = 'none'; // var myCharts = []; // var mySubGroup = []; for(var i=0;i<response.data.length;i++){ var dataType; if(parseInt(response.data[i].isRealTime) == 0){ dataType = "å¼•ç”¨å½“å‰æ•°æ®åº“"; }else if(parseInt(response.data[i].isRealTime) == 1){ dataType = "实时获å–"; } if(response.data[i].chartType == 'text:subGroupOfImage'){ app.mySubGroup.push({ chartId: response.data[i].id, base64: "data:image/jpg;base64,"+JSON.parse(response.data[i].jsCode).image}); }else if($.inArray(response.data[i].chartType,['bar','line','pie','table']) != -1){ app.myCharts.push({ chartId: response.data[i].id,chartType: response.data[i].chartType, chartName: response.data[i].chartName, dataType: dataType, imgSrc: "resources/img/"+response.data[i].chartType+"_chart.png" }); } } // app.myCharts = myCharts; // app.mySubGroup = mySubGroup; /** * æ³¨å†Œå›¾è¡¨åˆ é™¤äº‹ä»¶ */ setTimeout(function(){ $('.deleteOneChart').click(function (event) { event.stopPropagation();//å±è”½çˆ¶å…ƒç´ selectæ ·å¼é€‰æ‹© }); $('.deleteOneChart').confirmModal({ confirmTitle : 'æç¤º', confirmMessage : 'ä½ ç¡®å®šåˆ é™¤è¯¥å›¾è¡¨ï¼Ÿ', confirmOk : '是的', confirmCancel : 'å–æ¶ˆ', confirmDirection : 'rtl', confirmStyle : 'primary', confirmCallback : function (target) { var cid = target.parent().attr('data-cid'); $.ajax({ type: 'POST', url: 'authority/checkUserAuthority', data: { chartId: cid }, success: function(data){ if(data.haveAuthority == true){ var deferred = $.ajax({ type: 'POST', dataType: 'json', url: 'myChart/deleteOneChart', data : { "chartId": cid }, headers :{ oper : 'delete' } }); deferred.done(function(data){ if(data.isDelete == true){ target.parent().remove();//当å‰é¢æ¿çš„å›¾è¡¨ç±»åž‹é€‰æ‹©æ¡†åˆ é™¤ $.each($('.draggable'),function (index,target) {//åˆ é™¤panelä¸è¯¥å›¾è¡¨çš„divå…ƒç´ if(cid == $(target).attr("chartid")){ $(target).remove(); } }); }else{ alert("éƒ¨åˆ†è®¾è®¡é¢æ¿ä¸ä½¿ç”¨äº†æœ¬å›¾è¡¨ï¼Œæš‚ä¸å¯åˆ 除!"); } }) }else if(data.haveAuthority == false){ alert("您没有æƒé™ï¼"); } } }); }, confirmDismiss : true, confirmAutoOpen : false }); },0); } }); }, //图表和控件是å¦é€‰ä¸ select: function(index){ if(index == this.currentSelectedIndex){ this.currentSelectedIndex = -1; }else { this.currentSelectedIndex = index; } }, //å›¾è¡¨ï¼Œç»„ä»¶é€‰ä¸æ¸²æŸ“ renderSelected: function(type){ if( this.currentSelectedIndex != -1 ){ var defer = $.ajax({ type: 'POST', url: 'selectOneChartInfo', data: "id=" + this.currentSelectedIndex }); defer.done(function(data){ app.isSave = false; var $targetDiv; if(data.chartType.indexOf("subGroupOfImage") >= 0){ var imgBase64 = JSON.parse(data.jsCode).image; var option = JSON.parse(data.jsCode); app.order = app.order + 1; app.widgets.push({ chartType: 'text:subGroupOfImage',id: app.order,chartId: data.id,width: option.width + 'px',height: option.height + 'px', hideImg: 'data:image/jpg;base64,'+imgBase64, chartName: '' }); setTimeout(function(){ $targetDiv = $("#"+app.order); option.image = $targetDiv.parent().find("img")[0]; CanvasTagOfImage().render(app.order,"",option,false); renderMenu.renderMenu($targetDiv,'',app); }, 0); }else { app.order = app.order + 1; var chartTag; if(data.chartType == 'table'){ chartTag = 'table'; }else { chartTag = 'chart'; } app.widgets.push({ chartType: chartTag,id: app.order,chartId: data.id,width: '400px',height: '400px', chartName: data.chartName }); setTimeout(function(){ if(parseInt(data.isRealTime) == 0){ $targetDiv = $("#"+app.order); if(data.chartType == 'table'){ app.scrollType = 'auto'; // $targetDiv.html(data.jsCode); app.tableCurrentPage[data.id] = 1; renderMenu.renderTableInPanel($targetDiv,data,app); }else { echarts.init($targetDiv[0]).setOption(JSON.parse(data.jsCode)); app.$nextTick(function(){ renderMenu.renderMenu($targetDiv, data.chartName, app); }); } }else if(parseInt(data.isRealTime) == 1){ $.ajax({ async: false, type: 'POST', contentType: "application/json; charset=utf-8", url: 'render', data: JSON.stringify({ 'chartType': data.chartType, 'dataRecordId': data.sqlRecordingId, 'builderModel': JSON.parse(data.buildModel) }), success: function(option){ $targetDiv = $("#"+app.order); var newOption = JSON.parse(data.jsCode); newOption.series[0].data = option.series[0].data; if('legend' in option){ newOption.legend.data = option.legend.data; } if('xAxis' in option){ newOption.xAxis[0].data = option.xAxis[0].data; } echarts.init($targetDiv.get(0)).setOption(newOption); renderMenu.renderMenu($targetDiv, data.chartName, app); }, error: function(){ app.renderFailList.push(app.order); } }); } $(".draggable").niceScroll(); }, 0); } }); } if(type == 'mySubGroup'){ $("#mySubGroup").modal('toggle'); }else if( type == 'myChart' ){ $("#myChart").modal('toggle'); } }, //å…¨å±/å–æ¶ˆå…¨å± allScreen: function(){ this.isAllScreen = this.isAllScreen == false ? true : false; }, //ä¿å˜å¹¶æ¸²æŸ“自定义组件 renderMySubGroup: function(){ if($("#subGroupContainer").attr("zid")){ var pzr = zrender.getInstance($("#subGroupContainer").attr("zid"));//原控件 var option = $.extend(true, {}, pzr.storage.getShapeList()[0].style); //ä¿å˜æ—¶åªèƒ½ä¿å˜å›¾ç‰‡çš„base64ç¼–ç option.image = app.subGroupBase64; var deffer = $.ajax({ type: 'POST', url: 'addCharts', data : { 'chartType': "text:subGroupOfImage", 'sqlRecordingId': "0", 'buildModel': JSON.stringify({}), 'jsCode': JSON.stringify(option), 'chartName': "自定义组件" } }); deffer.done(function(result){ app.order++; app.widgets.push({ id: app.order, chartId: result, chartType: 'text:subGroupOfImage', width: option.width + 'px', height: option.height + 'px', hideImg: 'data:image/jpg;base64,'+app.subGroupBase64 }); app.isSave = false; setTimeout(function(){ var $target = $("#"+app.order); option.image = $target.parent().find("img")[0]; //渲染时 CanvasTagOfImage().render(app.order,"",option,false); renderMenu.renderMenu($target,'',app); //é‡ç½®æ¨¡æ€æ¡† app.isShowImgSetting = false; $(".fileinput-remove").trigger("click"); $('#subGroupContainer').replaceWith('<div id="subGroupContainer" class="thumbnail" style="width:45%;height:410px;float:left;overflow: auto;border:1px dashed rgb(238,238,238);"></div>'); }, 0); }); } $("#subGroupModal").modal('toggle'); }, //主题切æ¢é€’å½’è¿ç®— overloadItemStyle: function(optItem, theme) { for(k in theme) { if(optItem[k] && (typeof theme[k] !== 'object')){ delete optItem[k]; } else if(typeof theme[k] == 'object') { this.overloadItemStyle(optItem, theme[k]); } } }, //修改图表,组件细节åŽä¿å˜ saveOptionChange: function(){ var domOption; if(this.chartType.indexOf('text') >= 0){ //id为domId divçš„zid var domZid = $("#"+this.domId).attr("zid"); var domPzr = zrender.getInstance(domZid);//原控件 domOption = $.extend(true, {}, domPzr.storage.getShapeList()[0].style); //id为textOptionContainer divçš„zid var zid = $("#textOptionContainer").attr("zid"); var pzr = zrender.getInstance(zid);//原控件 var option = $.extend(true, {}, pzr.storage.getShapeList()[0].style); if(this.chartType.indexOf("subGroupOfImage") < 0){ domOption.text = option.text; domOption.textColor = option.textColor; domOption.textFont = option.textFont; domOption.color = option.color; domOption.strokeColor = option.strokeColor; //æ–‡å—组件ä¸å˜åœ¨å¤ç”¨ï¼Œä¸ä¿å˜åˆ°T_MY_CHARTSè¡¨ä¸ var index= this.order - 1; this.widgets[index].option = domOption; // domPzr.storage.getShapeList()[0].style = domOption; CanvasTag().render(this.domId,domOption); renderMenu.renderMenu($("#" + this.domId),'',app); // domPzr.refresh(); }else { domOption.text = option.text; domOption.textColor = option.textColor; domOption.textFont = option.textFont; //ä¸èƒ½ç›´æŽ¥æŠŠoptionç»™domPzr实例,有些属性ä¸èƒ½åŒæ¥ï¼Œä¾‹å¦‚画布宽高 // domPzr.storage.getShapeList()[0].style = domOption; CanvasTagOfImage().render(this.domId,'',domOption,false); renderMenu.renderMenu($("#"+this.domId),'',app); // domPzr.refresh(); // domOption.image = option.image.currentSrc.split(',')[1]; } }else if(this.chartType.indexOf('chart') >= 0){ var instance = echarts.getInstanceByDom(document.getElementById("optionContainer")); echarts.getInstanceByDom(document.getElementById(this.domId)).setOption(instance.getOption()); domOption = instance.getOption(); } if(this.chartType.indexOf('subGroupOfImage') >= 0 || this.chartType.indexOf('chart') >= 0){ $.ajax({ type: 'POST', url: 'updateChartInfo', headers: { imgBase64: domOption.image.currentSrc.split(',')[1] }, data: { 'id': $("#"+this.domId).attr("chartId"), 'jsCode': JSON.stringify(domOption) }, success: function(){ app.isSave = false; }, error: function(){ alert("ä¿å˜æ—¶å¤±è´¥ï¼Œè¯·é‡è¯•!"); } }); } }, //ä¿å˜å½“å‰é¢æ¿å›¾è¡¨ saveCurrentPanel: function(){ this.isLoader = true; this.isSaveLoader = 'block'; var arr = window.location.href.split("/"); var exportId = $("#exportId").val(); var shareHref = arr[0]+"//"+arr[2]+"/"+arr[3]+"/share.page?exportId="+exportId; var widgets = this.widgets; var chartIds = []; //ä¿å˜å›¾è¡¨id var containerIds = []; //ä¿å˜å®¹å™¨id for(var i=0;i<widgets.length;i++) { var chartId = widgets[i].chartId; var containerId = widgets[i].id; if(widgets[i].chartType.indexOf('rectangle') < 0){ chartIds.push(chartId); containerIds.push(containerId); } var target = $('#'+containerId); if(widgets[i].width == 0 && widgets[i].height == 0){ //å¦‚æžœå·²åˆ é™¤ï¼Œheightå’Œwidth为0 this.widgets[i].datax = 0; this.widgets[i].datay = 0 }else { if(target.css('transform').toString() == 'none'){ //如果未拖动,css属性transform属性为none this.widgets[i].datax = 0; this.widgets[i].datay = 0; }else { this.widgets[i].datax = typeof($(target).attr('data-x')) == 'undefined' ? target.css('transform').toString().split(',')[4] : $(target).attr('data-x'); this.widgets[i].datay = typeof($(target).attr('data-y')) == 'undefined' ? target.css('transform').toString().split(',')[5].replace(')','') : $(target).attr('data-y'); } this.widgets[i].width = target.css('width'); this.widgets[i].height = target.css('height'); } if(this.currentTheme != '' && widgets[i].chartType.indexOf('text') < 0 && widgets[i].chartType.indexOf('table') < 0){ this.widgets[i].themeName = this.currentTheme; } } $.ajax({ type: 'POST', url: "panelChartsWrapper/updateWrapper", data: "chartIds="+chartIds+"&containerIds="+containerIds+"&exportId="+exportId }); $.ajax({ type: 'POST', url: "export", data: { "htmlCode": JSON.stringify(this.widgets), "exportId": exportId, "extraMsg": shareHref }, success : function(){ app.isSave = true; //点击导出åŽè¡¨æ˜Žå·²ä¿å˜ app.isLoader = false; app.isSaveLoader = 'none'; // location.reload(); }, error : function(){ app.isLoader = false; app.isSaveLoader = 'none'; alert("ä¿å˜å¤±è´¥ï¼Œè¯·é‡è¯•ï¼"); } }); }, //改å˜å›¾è¡¨ä¸»é¢˜ changeTheme: function(themeName){ this.isSave = false; this.currentTheme = themeName; var widgets = this.widgets; for(var i=0;i<widgets.length;i++) { var target = $("#" + widgets[i].id); var chartName = $(target).find('#chartTitle').text(); if (widgets[i].chartType.indexOf("text") < 0 && widgets[i].chartType.indexOf('table') < 0) { var chartOption = echarts.getInstanceByDom($(target)[0]).getOption(); echarts.dispose($(target)[0]); echarts.registerTheme(themeName, theme[themeName]); var exportChart = echarts.init($(target)[0], themeName); app.overloadItemStyle(chartOption, theme[themeName]); // 主题与图表optionåˆå¹¶ if(chartOption.series[0].type == 'line' || chartOption.series[0].type == 'bar'){ chartOption.xAxis[0].axisLine.lineStyle.color = '#999999'; chartOption.yAxis[0].axisLine.lineStyle.color = '#999999'; chartOption.xAxis[0].axisTick.lineStyle.color = '#999999'; chartOption.yAxis[0].axisTick.lineStyle.color = '#999999'; chartOption.xAxis[0].axisLabel.textStyle.color = '#999999'; chartOption.yAxis[0].axisLabel.textStyle.color = '#999999'; } exportChart.setOption(chartOption); renderMenu.renderMenu($(target), chartName, app); } } } }, mounted: function () { //åˆå§‹åŒ–è®¾è®¡é¢æ¿èƒŒæ™¯ var deferred = $.ajax({ type: 'POST', dataType: 'json', url: 'myPanel/crud', data : { exportId : $("#exportId").val() }, headers :{ oper : 'query' } }); deferred.done(function(data){ if(data.myPanel.backgroundClass){ app.backgroundClass = data.myPanel.backgroundClass; } }); //fileInputåˆå§‹åŒ– $("#input-id").fileinput({ language: 'zh', showUpload: false, allowedFileExtensions : ['jpg', 'png','gif'] }); //颜色选择器åˆå§‹åŒ–(自定义组件) $("#subGroupTextColorMounted").spectrum({ showInput: true, allowEmpty:true, color: 'black', change: function(color){ app.subGroupTextColor = color.toHexString(); } }); //åˆå§‹åŒ–拖拽 interact('.draggable') .draggable({ inertia: true, restrict: { restriction: "#app", endOnly: true, elementRect: { top: 0, left: 0, bottom: 1, right: 1 } }, onmove: function(event){ app.isSave = false; var target = event.target, // keep the dragged position in the data-x/data-y attributes x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx, y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy; // translate the element target.style.webkitTransform = target.style.transform = 'translate(' + x + 'px, ' + y + 'px)'; // update the posiion attributes target.setAttribute('data-x', x); target.setAttribute('data-y', y); } }) .resizable({ preserveAspectRatio: false, edges: { left: true, right: true, bottom: true, top: true } }) .on('resizemove', function (event) { var target = event.target, x = (parseFloat(target.getAttribute('data-x')) || 0), y = (parseFloat(target.getAttribute('data-y')) || 0); // update the element's style target.style.width = event.rect.width + 'px'; target.style.height = event.rect.height + 'px'; // translate when resizing from top or left edges x += event.deltaRect.left; y += event.deltaRect.top; target.style.webkitTransform = target.style.transform = 'translate(' + x + 'px,' + y + 'px)'; target.setAttribute('data-x', x); target.setAttribute('data-y', y); //自适应容器å˜åŒ– app.isSave = false; var chartType = target.getAttribute('charttype'); var id = target.getAttribute('id'); var zid = target.getAttribute('zid'); if(chartType.indexOf("text") >= 0){ var zrInstance = zrender.getInstance(zid); var width = parseInt($(target).css('width').replace('px','')); var height = parseInt($(target).css('height').replace('px','')); if(chartType.indexOf("subGroup") >= 0){ zrInstance.storage.getShapeList()[0].style.height = height; zrInstance.storage.getShapeList()[0].style.width = width; }else { zrInstance.storage.getShapeList()[0].style.height = height - (height / 4); zrInstance.storage.getShapeList()[0].style.width = width - (width / 4); } zrInstance.resize(); }else if( chartType == 'chart' ){ echarts.getInstanceByDom(document.getElementById(id)).resize(); }else if( chartType == 'table' ){ width = parseInt($(target).css('width').replace('px','')); height = parseInt($(target).css('height').replace('px',''))*0.77; $(target).find('table').css('width', width); $(target).find('table').css('height', height); } }); //æ–‡å—组件åˆå§‹åŒ– $('.background-text-pick-block').draggable({ cursor: "move", opacity: 0.7, appendTo :'#app', helper: function (event) { var target = $(this).clone(); target.zIndex( 100000000 ); target.css('position','absolute'); return target; } }); $(".app-container").droppable({ drop : function (event,ui) { //å±è”½é‡å¤æ‹–拽 if(ui.draggable.hasClass("background-text-pick-block")) { app.order ++; app.widgets.push({ chartType: 'text:rectangle',id: app.order,width: '400px',height: '100px',datax: (ui.position.left),datay:(ui.position.top) }); setTimeout(function(){ CanvasTag().render(app.order); renderMenu.renderMenu($("#" + app.order),'',app); $("#"+app.order).css('background-color', 'unset'); }, 0); } } }); //domId,chartTypeåˆå§‹åŒ– $("#optionModal").on("show.bs.modal",function(e){ app.domId = e.relatedTarget.parentNode.parentNode.parentNode.getAttribute('id'); app.chartType = e.relatedTarget.parentNode.parentNode.parentNode.getAttribute('charttype'); }); $("#textOptionModal").on("show.bs.modal",function(e){ app.domId = e.relatedTarget.parentNode.parentNode.parentNode.getAttribute('id'); app.chartType = e.relatedTarget.parentNode.parentNode.parentNode.getAttribute('charttype'); }); //æ˜¾ç¤ºé¢æ¿ var chartIds = []; var containerIds = []; // var textIds = []; var initCharts = $.ajax({ type: 'POST', dataType: 'json', url: 'myPanel/crud', data : { exportId : $("#exportId").val() }, headers :{ oper : 'query' } }); initCharts.done(function(data){ if(data.myPanel.htmlCode){ app.widgets = JSON.parse(data.myPanel.htmlCode); app.$nextTick(function(){ app.order = app.widgets.length; for(item in app.widgets){ if(app.widgets[item].chartId){ chartIds.push(app.widgets[item].chartId); containerIds.push(app.widgets[item].id); }else { // textIds.push(app.widgets[item].id); CanvasTag().render(app.widgets[item].id,app.widgets[item].option); renderMenu.renderMenu($('#'+app.widgets[item].id),'',app); $('#'+app.widgets[item].id).css('background-color', 'unset'); } } //查询所有chartçš„option var defer = $.ajax({ type: 'POST', url: 'getShareOptions', data: 'cids='+chartIds }); defer.done(function(data) { var themeName; var chartNames = []; for (var i = 0; i < chartIds.length; i++) { if(app.widgets[i].themeName){ themeName = app.widgets[i].themeName; } var target = $('#'+containerIds[i]); if (data[i].chartType.indexOf("text") < 0) { var exportChart = echarts.init($(target)[0]); if (parseInt(data[i].isRealTime) == 0) { if(data[i].chartType == 'table'){ app.scrollType = 'auto'; // $("#"+containerIds[i]).html(data[i].jsCode); app.tableCurrentPage[data[i].id] = 1; renderMenu.renderTableInPanel(target,data[i],app); var menuInfo = []; menuInfo.push(target); menuInfo.push(data[i].chartName); chartNames.push(menuInfo); }else { exportChart.setOption(JSON.parse(data[i].jsCode)); renderMenu.renderMenu($(target), data[i].chartName, app); } } else if (parseInt(data[i].isRealTime) == 1) { $.ajax({ async: false, type: 'POST', contentType: "application/json; charset=utf-8", url: 'render', data: JSON.stringify({ 'chartType': data[i].chartType, 'dataRecordId': data[i].sqlRecordingId, 'builderModel': JSON.parse(data[i].buildModel) }), success: function (option) { var newOption = JSON.parse(data[i].jsCode); // 若本图表选择数æ®èŽ·å–æ¨¡å¼ä¸ºå®žæ—¶èŽ·å–, newOption.series[0].data = option.series[0].data; // 在渲染时将数æ®åº“ä¸çš„optionä¸çš„series部分替æ¢ä¸ºæ–°ç”Ÿæˆçš„optionçš„series部分å³å¯ if ('legend' in option) { newOption.legend.data = option.legend.data; } if ('xAxis' in option) { newOption.xAxis[0].data = option.xAxis[0].data; } exportChart.setOption(newOption); renderMenu.renderMenu($(target), data[i].chartName, app); }, error: function () { app.renderFailList.push(app.order); } }); } } else { if (data[i].chartType.indexOf("subGroupOfImage") >= 0) { var option = JSON.parse(data[i].jsCode); option.image = $(target).find("img")[0]; option.width = app.widgets[i].width.replace('px',''); option.height = app.widgets[i].height.replace('px',''); CanvasTagOfImage().render(containerIds[i],"",option,false); renderMenu.renderMenu($(target),'',app); } } } app.$nextTick(function(){ //tableçš„menu渲染 // for(var i=0;i<chartNames.length;i++){ // renderMenu.renderMenu(chartNames[i][0], chartNames[i][1], app); // } $(".draggable").niceScroll(); }); //theme app.changeTheme(themeName); app.isSave = true; }) }); } //ä¿å˜è¿”回图表渲染 if(window.location.href.indexOf("chartId") > 0){ var chartId = window.location.href.split("=")[2].replace("#",""); var defer01 = $.ajax({ type: 'POST', url: 'selectOneChartInfo', data: "id="+chartId }); defer01.done(function(data){ if(data && $('[chartId='+data.id+']').length <= 0) { app.isSave = false; app.order = app.order + 1; var chartTag; if(data.chartType == 'table'){ chartTag = 'table'; }else { chartTag = 'chart'; } app.widgets.push({ chartType: chartTag,id: app.order,chartId: data.id,width: '400px',height: '400px', chartName: data.chartName }); app.$nextTick(function(){ if(parseInt(data.isRealTime) == 0){ if(data.chartType == 'table'){ app.scrollType = 'auto'; // $("#"+app.order).html(data.jsCode); app.tableCurrentPage[data.id] = 1; renderMenu.renderTableInPanel($("#"+app.order),data,app); }else { echarts.init($("#"+app.order)[0]).setOption(JSON.parse(data.jsCode)); setTimeout(function(){ renderMenu.renderMenu($("#"+app.order),data.chartName,app); }, 0); } }else if(parseInt(data.isRealTime) == 1){ $.ajax({ type: 'POST', contentType: "application/json; charset=utf-8", url: 'render', data: JSON.stringify({ 'chartType': data.chartType, 'dataRecordId': data.sqlRecordingId, 'builderModel': JSON.parse(data.buildModel) }), success: function(option){ echarts.init($("#"+app.order)[0]).setOption(option); renderMenu.renderMenu($("#"+app.order),data.chartName,app); }, error: function(){ app.renderFailList.push(app.order); } }); } $(".draggable").niceScroll(); }) } }); } }); //窗å£å…³é—ç›‘å¬ //å…³é—çª—å£æ—¶å¼¹å‡ºç¡®è®¤æç¤º $(window).bind('beforeunload', function(){ // åªæœ‰åœ¨æ ‡è¯†å˜é‡is_confirmä¸ä¸ºfalse时,æ‰å¼¹å‡ºç¡®è®¤æç¤º if(app.isSave == false) return '您å¯èƒ½æœ‰æ•°æ®æ²¡æœ‰ä¿å˜'; }); }, watch: { subGroupText: function(){ this.myWidgetOption.text = this.subGroupText; CanvasTagOfImage().render("subGroupContainer","",this.myWidgetOption); }, subGroupTextColor: function(){ this.myWidgetOption.textColor = this.subGroupTextColor; CanvasTagOfImage().render("subGroupContainer","",this.myWidgetOption); }, subGroupFontSize: function(){ this.myWidgetOption.textFont = this.myWidgetOption.textFont.split(" ")[0] + " " +this.subGroupFontSize+ "px " + this.myWidgetOption.textFont.split(" ")[2]; CanvasTagOfImage().render("subGroupContainer","",this.myWidgetOption); }, subGroupFontLocation: function(){ this.myWidgetOption.textPosition = this.subGroupFontLocation; CanvasTagOfImage().render("subGroupContainer","",this.myWidgetOption); }, isSave: function(){ if(app.isSave == false){ $("title").html("*Infovis-Designer"); }else if(app.isSave == true) { $("title").html("Infovis-Designer"); } } } }); }); });