企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
路径:D:\ireport365\ireport365.war\js\enduser\designer\vs-component-basic.js 第一步添加组件对象 ``` { name: "", type: "clock", coverImage: contextPath + "/images/componenttypes/" + locale + "/basic/zh_b1000.png", coverImageWidth: "50%", tip: "时钟" } ``` 第二步默认大小 ``` case "clock": a.sizeX = 2; a.sizeY = 20; break; ``` 第三步核心代码 ``` vsPluginComponentModule.factory("$vcPlugin_basic_clock", ["$vsPluginRegister", "$timeout", function (a, c) { var b = { showDataCategory: false, showBorderCategory: true, showBasicCategory: true, showFixedCategory: true, showEventCategory: false, showTitleCategory: false, buildDataDescription: function (e, h, g, d, f) { h.$on(event_refreshBindingData, function (k, l) { d.context.orgData = d.context.data; var i = d.config.datasourceConfig.dimensions; var j = d.config.datasourceConfig.measures; if (i && i.length > 0) { if (!j) { j = [] } h.queryModelData({ eventParam: l, dimensions: i, measures: j, tableKey: d.config.datasourceConfig.metadataConfig.metadataTable.key, onQuerySuccess: function (m) { if (m.data.success) { if (d.context.data == null || d.context.data.length == 0) { return } var o = {}; if (d.context.data != null && d.context.data.length > 0) { for (var n = 0; n < i.length; n++) { o[i[n].name] = d.context.data[0][i[n].name] } for (var n = 0; n < j.length; n++) { o[j[n].name] = d.context.data[0][j[n].name] } } c(function () { h.valueMap = o }) } else { toaster.error({ body: m.data.message }) } }, onError: function () { toaster.error({ body: vsLang.connection_failed }) } }) } }) }, buildChartDescription: function (j, h, e, g) { var d = { name: "chart", title: "配置", groups: [] }; e.description.categories.push(d); if (!e.config.is) { e.config.is = true; // 画布宽高 e.config.canvasWidth = 400; e.config.canvasHeight = 400; // 背景渐变色 e.config.backgroundColorOne = "#ff8800"; e.config.backgroundColorTow = "#65ff89"; // 线条的颜色 e.config.lineColor = "#ff8800"; // 线条宽度 e.config.lineWidth = 17; // 线条阴影大小 e.config.shadowBlur = 15; // 线条阴影颜色 e.config.shadowColor = "#ff8800"; // 文字的上下左右位置 e.config.weekLeft = 145; e.config.weekTop = 170; e.config.dataLeft = 125; e.config.dataTop = 200; e.config.timeLeft = 90; e.config.timeTop = 230; // 文字的大小和颜色 e.config.weekFontSize = 25; e.config.weekFontColoe = "rgba(00, 255, 255, 1)"; e.config.dataFontSize = 25; e.config.dataFontColoe = "rgba(00, 255, 255, 1)"; e.config.timeFontSize = 25; e.config.timeFontColoe = "rgba(00, 255, 255, 1)"; } if (j.component.config.showTitle == null) { j.component.config.showTitle = false } j.component = e; var f = []; f.push("<canvas id='canvas'></canvas>"); var i = g(f.join(""))(j); h.append(i); // 时间 function degToRad(degree) { var factor = Math.PI / 180; return degree * factor; } var clearTime; function renderTime() { // console.log('11111') // var domWidth = document.getElementById(e.id).offsetWidth; // var domHeight = document.getElementById(e.id).offsetHeight; j.component.context.canvas = $("#" + e.id + " #canvas")[0] j.component.context.ctx = j.component.context.canvas.getContext("2d"); // console.log(j.component.context.ctx) // 清空画布防止重叠 j.component.context.ctx.clearRect(0, 0, e.config.canvasWidth, e.config.canvasHeight); // 设置宽高 canvas.width = e.config.canvasWidth; canvas.height = e.config.canvasHeight; // 线条颜色 j.component.context.ctx.strokeStyle = e.config.lineColor; // 线条宽度 j.component.context.ctx.lineWidth = e.config.lineWidth; // 线条的阴影大小 j.component.context.ctx.shadowBlur = e.config.shadowBlur; // 线条阴影颜色 j.component.context.ctx.shadowColor = e.config.shadowColor // 时间对象 var now = new Date(); var month = now.getMonth() + 1; var year = now.getFullYear(); var day = now.getDate(); var a = new Array("日", "一", "二", "三", "四", "五", "六"); var week = now.getDay(); var weekStr = "星期" + a[week]; var today = now.toDateString(); var time = now.toLocaleTimeString(); var hrs = now.getHours(); var min = now.getMinutes(); var sec = now.getSeconds(); var mil = now.getMilliseconds(); var smoothsec = sec + (mil / 1000); var smoothmin = min + (smoothsec / 60); //Background gradient = j.component.context.ctx.createRadialGradient((e.config.canvasWidth / 2), (e.config.canvasWidth / 2), 5, (e.config.canvasWidth / 2), (e.config.canvasWidth / 2), (e.config.canvasWidth / 1.333)); gradient.addColorStop(0, e.config.backgroundColorOne); gradient.addColorStop(1, e.config.backgroundColorTow); j.component.context.ctx.fillStyle = gradient; // ctx.fillStyle = 'rgba(00 ,00 , 00, 1)'; // 画布填充 j.component.context.ctx.fillRect(0, 0, e.config.canvasWidth, e.config.canvasHeight); // 下面是开始画圆 x y 直径 //Hours j.component.context.ctx.beginPath(); j.component.context.ctx.arc(e.config.canvasWidth / 2.222, e.config.canvasWidth / 2, e.config.canvasWidth / 2.222, degToRad(270), degToRad((hrs * 30) - 90)); j.component.context.ctx.stroke(); //Minutes j.component.context.ctx.beginPath(); j.component.context.ctx.arc(e.config.canvasWidth / 2.222, e.config.canvasWidth / 2, e.config.canvasWidth / 2.666, degToRad(270), degToRad((smoothmin * 6) - 90)); j.component.context.ctx.stroke(); //Seconds j.component.context.ctx.beginPath(); j.component.context.ctx.arc(e.config.canvasWidth / 2.222, e.config.canvasWidth / 2, e.config.canvasWidth / 3.333, degToRad(270), degToRad((smoothsec * 6) - 90)); j.component.context.ctx.stroke(); // week j.component.context.ctx.font = e.config.weekFontSize + "px Helvetica"; j.component.context.ctx.fillStyle = e.config.weekFontColoe; j.component.context.ctx.fillText(weekStr, e.config.weekLeft, e.config.weekTop); //Date j.component.context.ctx.font = e.config.dataFontSize + "px Helvetica"; j.component.context.ctx.fillStyle = e.config.dataFontColoe; j.component.context.ctx.fillText(year + '-' + month + '-' + day, e.config.dataLeft, e.config.dataTop); //Time j.component.context.ctx.font = e.config.timeFontSize + "px Helvetica Bold"; j.component.context.ctx.fillStyle = e.config.timeFontColoe; j.component.context.ctx.fillText(time + ":" + mil, e.config.timeLeft, e.config.timeTop); // setTimeout('renderTime()', 40) } clearTime = setInterval(renderTime, 40); // 时间end d.groups.push({ name: "width", title: { text: "基本配置" }, elements: [{ title: "宽度", type: "configSlide", bind: "canvasWidth", config: { slideStart: 0, slideEnd: 1000 }, }, { title: "背景色值1", type: "colorpicker", bind: "backgroundColorOne" }, { title: "背景色值2", type: "colorpicker", bind: "backgroundColorTow" }, { title: "条形颜色", type: "colorpicker", bind: "lineColor" }, { title: "条形宽度", type: "configSlide", bind: "lineWidth", config: { slideStart: 0, slideEnd: 100 }, }, { title: "条形阴影颜色", type: "colorpicker", bind: "shadowColor" }, { title: "条形阴影宽度", type: "configSlide", bind: "shadowBlur", config: { slideStart: 0, slideEnd: 100 }, }] }); d.groups.push({ name: "week", title: { text: "星期配置" }, elements: [{ title: "水平位置", type: "configSlide", bind: "weekLeft", config: { slideEnd: 1000 } }, { title: "垂直位置", type: "configSlide", bind: "weekTop", config: { slideEnd: 1000 } }, { title: "字体大小", type: "configSlide", bind: "weekFontSize", config: { slideEnd: 100 } }, { title: "字体颜色", type: "colorpicker", bind: "weekFontColoe" }] }); d.groups.push({ name: "data", title: { text: "日期配置" }, elements: [{ title: "水平位置", type: "configSlide", bind: "dataLeft", config: { slideEnd: 1000 } }, { title: "垂直位置", type: "configSlide", bind: "dataTop", config: { slideEnd: 1000 } }, { title: "字体大小", type: "configSlide", bind: "dataFontSize", config: { slideEnd: 100 } }, { title: "字体颜色", type: "colorpicker", bind: "dataFontColoe" }] }); d.groups.push({ name: "time", title: { text: "时间配置" }, elements: [{ title: "水平位置", type: "configSlide", bind: "timeLeft", config: { slideEnd: 1000 } }, { title: "垂直位置", type: "configSlide", bind: "timeTop", config: { slideEnd: 1000 } }, { title: "字体大小", type: "configSlide", bind: "timeFontSize", config: { slideEnd: 100 } }, { title: "字体颜色", type: "colorpicker", bind: "timeFontColoe" }] }); j.$watch("component.config.canvasWidth", function (w, u) { var p = e.config; console.log(w) p.canvasWidth = w; p.canvasHeight = w; }); j.$watch("component.config.backgroundColorOne", function (w, u) { var p = e.config; p.backgroundColorOne = w; }); j.$watch("component.config.backgroundColorTow", function (w, u) { var p = e.config; p.backgroundColorTow = w; }); j.$watch("component.config.lineColor", function (w, u) { var p = e.config; p.lineColor = w; }); j.$watch("component.config.lineWidth", function (w, u) { var p = e.config; p.lineWidth = w; }); j.$watch("component.config.shadowColor", function (w, u) { var p = e.config; p.shadowColor = w; }); j.$watch("component.config.shadowBlur", function (w, u) { var p = e.config; p.shadowBlur = w; }); // 星期 j.$watch("component.config.weekLeft", function (w, u) { var p = e.config; p.weekLeft = w; }); j.$watch("component.config.weekTop", function (w, u) { var p = e.config; p.weekTop = w; }); j.$watch("component.config.weekFontSize", function (w, u) { var p = e.config; p.weekFontSize = w; }); j.$watch("component.config.weekFontColoe", function (w, u) { var p = e.config; p.weekFontColoe = w; }); // 日期 j.$watch("component.config.dataLeft", function (w, u) { var p = e.config; p.dataLeft = w; }); j.$watch("component.config.dataTop", function (w, u) { var p = e.config; p.dataTop = w; }); j.$watch("component.config.dataFontSize", function (w, u) { var p = e.config; p.dataFontSize = w; }); j.$watch("component.config.dataFontColoe", function (w, u) { var p = e.config; p.dataFontColoe = w; }); // 时间 j.$watch("component.config.timeLeft", function (w, u) { var p = e.config; p.timeLeft = w; }); j.$watch("component.config.timeTop", function (w, u) { var p = e.config; p.timeTop = w; }); j.$watch("component.config.timeFontSize", function (w, u) { var p = e.config; p.timeFontSize = w; }); j.$watch("component.config.timeFontColoe", function (w, u) { var p = e.config; p.timeFontColoe = w; }); } }; a.register("basic", "clock", b); return null } ]); ``` 分享页 路径D:\ireport365\ireport365.war\WEB-INF\classes\report-resource\design.js ``` // 时钟 start case "clock": var html = []; html.push("<canvas id='canvas'></canvas>"); var el = $compile(html.join(""))(scope); element.append(el); var e = scope.component; // 时间 function degToRad(degree){ var factor = Math.PI/180; return degree*factor; } function renderTime(){ var canvas = $("#"+scope.component.id+" #canvas")[0] var ctx = canvas.getContext("2d"); // 清空画布防止重叠 ctx.clearRect(0,0,e.config.canvasWidth,e.config.canvasHeight); // 设置宽高 canvas.width = e.config.canvasWidth; canvas.height = e.config.canvasHeight; // 线条颜色 ctx.strokeStyle = e.config.lineColor; // 线条宽度 ctx.lineWidth = e.config.lineWidth; // 线条的阴影大小 ctx.shadowBlur= e.config.shadowBlur; // 线条阴影颜色 ctx.shadowColor = e.config.shadowColor // 时间对象 var now = new Date(); var month = now.getMonth()+1; var year = now.getFullYear(); var day = now.getDate(); var a = new Array("日", "一", "二", "三", "四", "五", "六"); var week = now.getDay(); var weekStr = "星期"+ a[week]; var today = now.toDateString(); var time = now.toLocaleTimeString(); var hrs = now.getHours(); var min = now.getMinutes(); var sec = now.getSeconds(); var mil = now.getMilliseconds(); var smoothsec = sec+(mil/1000); var smoothmin = min+(smoothsec/60); //Background gradient = ctx.createRadialGradient((e.config.canvasWidth / 2), (e.config.canvasWidth / 2), 5, (e.config.canvasWidth / 2), (e.config.canvasWidth / 2), (e.config.canvasWidth / 1.333)); gradient.addColorStop(0, e.config.backgroundColorOne); gradient.addColorStop(1, e.config.backgroundColorTow); ctx.fillStyle = gradient; // ctx.fillStyle = 'rgba(00 ,00 , 00, 1)'; // 画布填充 ctx.fillRect(0, 0, e.config.canvasWidth, e.config.canvasHeight); // 下面是开始画圆 x y 直径 //Hours ctx.beginPath(); ctx.arc(e.config.canvasWidth / 2.222,e.config.canvasWidth / 2,e.config.canvasWidth / 2.222, degToRad(270), degToRad((hrs*30)-90)); ctx.stroke(); //Minutes ctx.beginPath(); ctx.arc(e.config.canvasWidth / 2.222,e.config.canvasWidth / 2,e.config.canvasWidth / 2.666, degToRad(270), degToRad((smoothmin*6)-90)); ctx.stroke(); //Seconds ctx.beginPath(); ctx.arc(e.config.canvasWidth / 2.222,e.config.canvasWidth / 2,e.config.canvasWidth / 3.333, degToRad(270), degToRad((smoothsec*6)-90)); ctx.stroke(); // week ctx.font = e.config.weekFontSize+"px Helvetica"; ctx.fillStyle = e.config.weekFontColoe; ctx.fillText(weekStr, e.config.weekLeft, e.config.weekTop); //Date ctx.font = e.config.dataFontSize+"px Helvetica"; ctx.fillStyle = e.config.dataFontColoe; ctx.fillText(year+'-'+month+'-'+day, e.config.dataLeft, e.config.dataTop); //Time ctx.font = e.config.timeFontSize+"px Helvetica Bold"; ctx.fillStyle = e.config.timeFontColoe; ctx.fillText(time+":"+mil, e.config.timeLeft, e.config.timeTop); // setTimeout('renderTime()', 40) } setInterval(renderTime, 40); break; // 时钟 end ```