From 286f7fa538a6d255b947d234e895cba1f692dd88 Mon Sep 17 00:00:00 2001 From: weizhiqiang <598748873@qq.com> Date: Sun, 21 Apr 2024 20:48:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8A=A5=E8=A1=A8=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E7=BB=84=E4=BB=B6=EF=BC=8C=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9C=AA=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../template/assets/report/css/ruler.css | 8 +- .../assets/report/js/skyeyeReportDesigner.js | 205 +++++++++++++++-- .../assets/report/json/skyeyeEditor.json | 7 + .../js/pageReportDesign/pageReportDesign.js | 5 +- .../js/pageReportDesign/simpleTableDesign.js | 215 ++++++++++++++++++ .../js/reportDataFrom/reportDataFromWrite.js | 33 +-- .../template/js/reportPage/reportPageShow.js | 86 +++++++ .../pageReportDesign/pageReportDesign.html | 14 +- .../pageReportDesign/simpleTableDesign.html | 59 +++++ .../template/assets/lib/layui/custom.js | 2 +- .../lib/layui/customer/skyeye/dsFormUtil.js | 6 +- 11 files changed, 579 insertions(+), 61 deletions(-) create mode 100644 report/src/main/resources/template/js/pageReportDesign/simpleTableDesign.js create mode 100644 report/src/main/resources/template/tpl/pageReportDesign/simpleTableDesign.html diff --git a/report/src/main/resources/template/assets/report/css/ruler.css b/report/src/main/resources/template/assets/report/css/ruler.css index 48f7de45e..7e3e81fa6 100644 --- a/report/src/main/resources/template/assets/report/css/ruler.css +++ b/report/src/main/resources/template/assets/report/css/ruler.css @@ -304,11 +304,17 @@ body { cursor: e-resize; } -.echarts-box{ +.echarts-box { width: 100%; height: 100%; } +.table-box { + width: 100%; + height: 100%; + position: absolute; +} + .word-box{ width: 100%; height: 100%; diff --git a/report/src/main/resources/template/assets/report/js/skyeyeReportDesigner.js b/report/src/main/resources/template/assets/report/js/skyeyeReportDesigner.js index 81a28dde1..d90e48642 100644 --- a/report/src/main/resources/template/assets/report/js/skyeyeReportDesigner.js +++ b/report/src/main/resources/template/assets/report/js/skyeyeReportDesigner.js @@ -4,6 +4,9 @@ var form; var inPageEcharts = {}; var inPageEchartsObject = {}; +// 已经添加上的echarts图表 +var inPageTable = {}; + // 已经添加上的文字模型 var inPageWordMation = {}; @@ -127,6 +130,9 @@ layui.define(["jquery", 'form', 'element'], function(exports) { str = f.getBgImageHtml(item, str); } else if(item.id == 'wordModel') { str = f.getWordModelHtml(item, str); + } else if(item.id == 'tableModel') { + // todo 待定 + str = f.getTableModelHtml(item, str); } else { str = f.getEchartsHtml(item, str); } @@ -204,6 +210,21 @@ layui.define(["jquery", 'form', 'element'], function(exports) { return str; }, + // 标题按钮--表格模型获取html + getTableModelHtml: function(item, str) { + str = f.getCommonParentHeader(str, item); + $.each(item.children, function (j, bean) { + str += '' + + '' + + '' + bean.name + '' + + ''; + }); + str += '' + + '' + + ''; + return str; + }, + // 标题按钮--背景图片模型获取html getBgImageHtml: function(item, str) { str = f.getCommonParentHeader(str, item); @@ -245,10 +266,66 @@ layui.define(["jquery", 'form', 'element'], function(exports) { f.addNewWordModel(modelId, wordStyleMation); }); + // 表格模型点击事件 + skyeyeHeader.find(".tableModel").click(function () { + var modelId = $(this).attr("rowId"); + f.addNewTableModel(modelId, null); + }); + + }, + + // 加载表格模型 + addNewTableModel: function(modelId, tableMation) { + // 获取boxId + var boxId = modelId + getRandomValueToString(); + // 获取表格图表id + var tableId = f.getTableBox(boxId, modelId); + // 加入页面属性 + var table = !isNull(tableMation) ? tableMation : { + attr: { + "custom.dataBaseMation": { "value": "", "edit": 1, "remark": "数据来源", "name": "数据来源", "editorType": "99", "editorChooseValue": "", "typeName": "数据源"}, + "custom.move.x": { "value": "0", "edit": 1, "remark": "鼠标拖动距离左侧的像素", "name": "X坐标", "editorType": "98", "editorChooseValue": "", "typeName": "坐标"}, + "custom.move.y": { "value": "0", "edit": 1, "remark": "鼠标拖动距离顶部的像素", "name": "Y坐标", "editorType": "98", "editorChooseValue": "", "typeName": "坐标"}, + "custom.tableColumn": { "defaultValue": [], "edit": 1, "remark": "数据表格的信息", "name": "表格配置", "editorType": "101", "editorChooseValue": "", "typeName": "数据源"}, + }, + tableColumnList: [], + isPage: 1 + } + + table["tableId"] = tableId + + // 加载表格 + dsFormTableUtil.initDynamicTable(tableId, table); + + inPageTable[boxId] = $.extend(true, {}, table); + return boxId; + }, + + getTableBox: function (boxId, modelId) { + var box = f.createBox(boxId, modelId, null); + + var tableBoxId = "table" + boxId; + var tableBox = document.createElement("div"); + // 为div设置类名 + tableBox.className = "table-box"; + tableBox.id = "label-" + tableBoxId; + tableBox.onmousedown = ee => { + var id = $("#" + tableBoxId).parent().attr("id"); + f.setMoveEvent(ee, $("#" + id)); + // 阻止事件冒泡(针对父元素的move) + ee.stopPropagation(); + }; + box.appendChild(tableBox); + + var table = document.createElement("table"); + table.id = tableBoxId; + box.appendChild(table); + + return tableBoxId; }, // 加载echarts模型 - addNewModel: function(modelId, echartsMation){ + addNewModel: function(modelId, echartsMation) { if (!f.isNull(echartsMation)) { var option = getEchartsOptions(echartsMation); // 获取boxId @@ -285,7 +362,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { }, // 根据id获取echarts信息 - getEchartsMationById: function(id){ + getEchartsMationById: function(id) { var echartsMation; $.each(params.headerMenuJson, function(i, item) { if (!f.isNull(item.children) && item.id == 'echartsModel') { @@ -297,7 +374,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { }, // 根据id获取文字模型的style信息 - getWordStyleMationById: function(id){ + getWordStyleMationById: function(id) { var wordMation; $.each(params.headerMenuJson, function(i, item) { if (!f.isNull(item.children) && item.id == 'wordModel') { @@ -308,7 +385,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { return wordMation; }, - getEchartsBox: function (boxId, modelId){ + getEchartsBox: function (boxId, modelId) { var echartsId = "echarts" + boxId; var echartsBox = document.createElement("div"); // 为div设置类名 @@ -325,7 +402,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { return echartsId; }, - getWordBox: function (boxId, modelId, styleStr, wordStyleMation){ + getWordBox: function (boxId, modelId, styleStr, wordStyleMation) { var wordId = "word" + boxId; var wordBox = document.createElement("font"); // 为div设置类名 @@ -344,7 +421,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { return wordId; }, - setDesignAttr: function(wordStyleMation){ + setDesignAttr: function(wordStyleMation) { var otherStyle = { width: wordStyleMation.defaultWidth + 'px', height: wordStyleMation.defaultHeight + 'px' @@ -352,7 +429,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { return otherStyle; }, - createBox: function(id, modelId, otherStyle){ + createBox: function(id, modelId, otherStyle) { f.removeEchartsEditMation(); // 创建一个div var div = document.createElement("div"); @@ -364,7 +441,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { div.style.top = "0px"; div.style.left = "0px"; if (!f.isNull(otherStyle)) { - $.each(otherStyle, function (key, value){ + $.each(otherStyle, function (key, value) { div.style[key] = value; }); } @@ -456,7 +533,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { return div; }, - setMoveEvent: function (ee, box){ + setMoveEvent: function (ee, box) { // 获取事件对象 var ee = ee || window.event; var maxLeft = skyeyeReportContent.width() - box.width(); @@ -489,7 +566,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { * @param y 鼠标按下时,鼠标相对于元素的y坐标 * @returns {number|number} */ - getTop: function (e, y){ + getTop: function (e, y) { var top = e.clientY - y - 104; top = top < 0 ? 0 : top; var chooseEcharts = skyeyeReportContent.find(".active").eq(0); @@ -508,7 +585,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { * @param maxLeft 允许的最大左边距 * @returns {number|number} */ - getLeft: function (e, x, maxLeft){ + getLeft: function (e, x, maxLeft) { var left = e.clientX - x - 44; left = left < 0 ? 0 : left; left = left > maxLeft ? maxLeft : left; @@ -569,7 +646,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { // 不触发‘移除所有图表的编辑信息’的事件的对象的class--颜色选择器 var notTriggerRemove = ["layui-colorpicker-main"]; // 图表点击事件 - $("body").on('click', ".echarts-box, .word-box", function (e) { + $("body").on('click', ".echarts-box, .word-box, .table-box", function (e) { f.setChooseReportItem($(this)); e.stopPropagation(); }); @@ -578,11 +655,12 @@ layui.define(["jquery", 'form', 'element'], function(exports) { $("body").on('click', skyeyeReportContent, function (e) { var pass = true; $.each(notTriggerRemove, function (i, item) { - if ($(e.target).parents("." + item).length > 0 || $(e.target).attr('class').indexOf(item) != -1) { + if ($(e.target).parents("." + item).length > 0 + || (!isNull($(e.target).attr('class')) && $(e.target).attr('class').indexOf(item) != -1)) { pass = false; } }); - if(pass){ + if (pass) { f.removeEchartsEditMation(); } }); @@ -606,6 +684,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { $("body").on('click', "#save", function (e) { var eachartsList = f.getEchartsListToSave(); var wordMationList = f.getWordMationListToSave(); + var tableMationList = f.getTableListToSave(); var bgImage = skyeyeReportContent.css("backgroundImage").replace('url(', '').replace(')', ''); if (isNull(bgImage) || bgImage == 'none' || bgImage.indexOf('none') > -1) { @@ -616,15 +695,18 @@ layui.define(["jquery", 'form', 'element'], function(exports) { contentHeight: skyeyeReportContent.height(), bgImage: bgImage, modelList: eachartsList, - wordMationList: wordMationList + wordMationList: wordMationList, + tableMationList: tableMationList }; AjaxPostUtil.request({url: sysMainMation.reportBasePath + "editReportPageContentById", params: {id: id, content: encodeURIComponent(JSON.stringify(params))}, type: 'json', method: "POST", callback: function(json) { winui.window.msg(systemLanguage["com.skyeye.successfulOperation"][languageType], {icon: 1, time: 2000}); }}); }); + + f.loadHandlebar(); }, - getEchartsListToSave: function (){ + getEchartsListToSave: function () { var eachartsList = new Array(); $.each(skyeyeReportContent.find(".kuang"), function(i, item) { if ($(item).find(".echarts-box").length > 0) { @@ -641,7 +723,24 @@ layui.define(["jquery", 'form', 'element'], function(exports) { return eachartsList; }, - getWordMationListToSave: function (){ + getTableListToSave: function () { + var tableList = new Array(); + $.each(skyeyeReportContent.find(".kuang"), function(i, item) { + if ($(item).find(".table-box").length > 0) { + var boxId = $(item).data("boxId"); + var etableMation = inPageTable[boxId]; + tableList.push({ + modelId: $(item).data("modelId"), + attrMation: etableMation, + width: $(item).width(), + height: $(item).height() + }); + } + }); + return tableList; + }, + + getWordMationListToSave: function () { var wordMationList = new Array(); $.each(skyeyeReportContent.find(".kuang"), function(i, item) { if ($(item).find(".word-box").length > 0) { @@ -659,7 +758,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { }, // 设置选中项 - setChooseReportItem: function(_this){ + setChooseReportItem: function(_this) { if (!_this.parent().hasClass("active")) { f.removeEchartsEditMation(); // 被选中项 @@ -670,14 +769,14 @@ layui.define(["jquery", 'form', 'element'], function(exports) { }, // 移除所有图表的编辑信息 - removeEchartsEditMation: function(){ + removeEchartsEditMation: function() { $(".dian").hide(); $(".kuang").removeClass("active"); $("#showForm").parent().remove(); }, // 加载echarts报表编辑器 - loadEchartsEditor: function (){ + loadEchartsEditor: function () { var chooseObject = skyeyeReportContent.find(".active").eq(0); var boxId = chooseObject.data("boxId"); var objectMation = getDataChooseMation(boxId); @@ -737,8 +836,22 @@ layui.define(["jquery", 'form', 'element'], function(exports) { } }, + loadHandlebar: function () { + // 加载json对象 + Handlebars.registerHelper('json', function(context, type) { + if (!isNull(context)) { + return JSON.stringify(context); + } + if (type == 'array') { + return JSON.stringify([]); + } else { + return JSON.stringify({}); + } + }); + }, + // 加载编辑器‘详情’类型的展示 - loadEchartsEditorISDetail: function (key, val, boxId, indexNumber, typeName){ + loadEchartsEditorISDetail: function (key, val, boxId, indexNumber, typeName) { var formItem = editorType["100"]; var data = f.getFormItemData(key, val, boxId, indexNumber); var html = getDataUseHandlebars('{{#bean}}' + formItem.html + '{{/bean}}', data); @@ -795,6 +908,9 @@ layui.define(["jquery", 'form', 'element'], function(exports) { value = JSON.stringify(value); } } + if (val.editorType == '101') { + value = JSON.stringify(value); + } return { "bean": { modelKey: key, @@ -811,7 +927,7 @@ layui.define(["jquery", 'form', 'element'], function(exports) { }, // 添加一个新的form表单 - addNewFormBox: function(){ + addNewFormBox: function() { var editForm = '