前端集成报表设计器—高效搞定报表设计 | 葡萄城技术团队
前端集成报表设计器---高效搞定报表设计
引言
前端框架Vue.js是当下前端开发非常喜欢的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的。相比于其他库,Vue.js提供了更加简洁、更易于理解的API,使得我们能够快上手并使用Vue.js
Vue这么受大家的喜爱,那么有没有一款好的在 线报表设计器 可以直接跟Vue集成了?现在任何项目报表不部分都是一个不可或缺的模块,以前设计报表都是让研发人员或者专业的报表设计人员进行报表设计,后期项目中要进行 报表编辑、报表添加 都需要专业的人员编辑好报表,然后再上传到服务器上进行发布。整个流程操作流程繁琐,并且时效性不是很好。特别不适合当下的SAAS应用或者是那种报表数量多并且改动频率比较多的系统。那么遇到这种问题,最好的办法就是直接把 设计器 集成到项目中,让最终系统使用者可以在线进行报表的编辑或者设计。俗话说授人以鱼不如授人以渔、现在我提供给你一个系统,系统中还自带了报表设计器,并附带报表设计操作教程,给整个系统使用者进行数据赋能,最终得到一个双赢的效果。
ActiveReportsJS包含两个设计器,桌面端设计器和web端设计器。在实际的报表系统中有报表编辑和创建的需求, 那么就可以根据自己的需求把web端在线设计器集成到报表系统中,实现报表的新增、编辑的需求。
下面我们就来讲解下,如何创建一个web端在线设计器
1、创建Vue引用
创建 Vue 应用的最简单的方法是使用Vue CLI
vue create -p default webonline
2、安装 ActiveReportsJS 相关文件
Web 报表设计器功能是放在@grapecity/activereports-vue NPM 包中,@grapecity/activereports npm 包中存放核心功能。在使用 ActiveReportsJS 时,可以执行以下命令来安装在应用根目录下:
npm install @grapecity/activereports-vue @grapecity/activereports
或者使用yarn命令
yarn add @grapecity/activereports-vue @grapecity/activereports
如果您使用的是 Vue 2.0, 需要安装@vue/composition-api 包:
npm install @vue/composition-api
或
yarn add @vue/composition-api
3、将 ActiveReportsJS报表添加到应用程序
ActiveReportsJS 使用 JSON格式和rdlx-json扩展用于报表模板文件。在应用程序的public文件夹下,创建名为report.rdlx-json的新文件,并在该文件中插入以下JSON内容。
{
"Name": "Report",
"Body": {
"ReportItems": [
{
"Type": "textbox",
"Name": "TextBox1",
"Value": "Hello, ActiveReportsJS Designer",
"Style": {
"FontSize": "18pt"
},
"Width": "8.5in",
"Height": "0.5in"
}
]
}
}
添加设计器宿主元素
打开 src\App.vue 文件,添加代码如下,单文件组件 调用 Vue 报表设计器来加载上一步骤创建的报表模板
<template>
<div id="designer-host">
<JSDesigner v-bind:report="{id: 'report.rdlx-json', displayName: 'my report' }"></JSDesigner>
</div>
</template>
<script>
import { Designer } from "@grapecity/activereports-vue";
export default {
name: "App",
components: {
JSDesigner: Designer,
},
};
</script>
<style src="../node_modules/@grapecity/activereports/styles/ar-js-ui.css"></style>
<style src="../node_modules/@grapecity/activereports/styles/ar-js-designer.css" ></style>
<style>
#designer-host {
width: 100%;
height: 100vh;
}
</style>
4、运行项目
5、给Web端在线设计器添加保存,预览的功能
<template>
<div>
<div id="designer-toolbar" class="container-fluid">
<div class="row mt-3 mb-3">
<button type="button"
class="btn btn-secondary btn-sm col-sm-2 ml-1"
v-on:click="onDesignerOpen()"
:style="{display: designerHidden ? 'block' : 'none'}">
打开设计器
</button>
</div>
</div>
<div id="viewer-host" :style="{display: designerHidden ? 'block' : 'none'}"><ReportViewer ref="reportViewer" /></div>
<div id="designer-host"></div>
<div class="modal" id="dlgOpen" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Open Report</h5>
<button type="button"
class="close"
data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h2>Select Report:</h2>
<div class="list-group">
<button type="button"
class="list-group-item list-group-item-action"
v-for="reportId in reportIds"
v-on:click="onSelectReport(reportId)"
:key="reportId">
{{reportId}}
</button>
</div>
</div>
<div class="modal-footer">
<button type="button"
class="btn btn-secondary"
data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
// 报表设计器包
import { Designer as ReportDesigner } from "@grapecity/activereports/reportdesigner";
import "@grapecity/activereports-localization/dist/designer/zh-locale"; // 中文包
import "@grapecity/activereports-localization";
import "@grapecity/activereports/styles/ar-js-designer.css";
// 报表查看器包
import { Viewer } from "@grapecity/activereports-vue";
import "@grapecity/activereports/styles/ar-js-viewer.css";
// 设计器与查看器公用包
import "@grapecity/activereports/styles/ar-js-ui.css";
import "../../node_modules/bootstrap/dist/css/bootstrap.min.css";
import "../../node_modules/bootstrap/dist/js/bootstrap.min.js";
import $ from "jquery";
let resolveFunc = null;
export default {
name: "Report",
components: {
ReportViewer: Viewer,
},
data() {
return {
reportStorage: new Map(),
reportIds: null,
counter: 0,
designer: null, // 设计器实例
designerHidden: false, // 显示隐藏设计器
disableOpenSaveHotkeys: true,
// 初始化报表查看器参数
reportTemplate: {
Type: "report",
Body: {
Name: "Body",
Type: "section",
ReportItems: [
{
Type: "textbox",
Name: "textbox1",
Style: {
FontSize: "18pt",
},
Value: "Hello, ActiveReportsJS Viewer",
Height: "10in",
},
],
},
Name: "Report",
},
};
},
methods: {
onDesignerOpen() {
this.designerHidden = false;
},
onSelectReport(reportId) {
if (resolveFunc) {
alert("1");
$("#dlgOpen").modal("hide");
resolveFunc({ definition: this.reportStorage.get(reportId), id: reportId, displayName: reportId });
resolveFunc = null;
}
},
},
mounted() {
const _this = this;
this.designer = new ReportDesigner("#designer-host", {
language: "zh", //汉化;
}); // 初始化报表设计器
this.designer.setActionHandlers({
// 添加预览功能
onRender: async (report) => {
this.designerHidden = true;
console.log(report);
this.$refs.reportViewer.Viewer().open(report.definition);
return Promise.resolve();
},
// 添加保存功能
onSave: (info) => {
const reportId = info.id || `NewReport${_this.counter + 1}`;
_this.reportStorage.set(reportId, info.definition);
_this.counter++;
return Promise.resolve({ displayName: reportId });
},
// 添加另存为功能
onSaveAs: function (info) {
const reportId = `NewReport${_this.counter + 1}`;
_this.reportStorage.set(reportId, info.definition);
_this.counter++;
return Promise.resolve({ id: reportId, displayName: reportId });
},
onOpen: function () {
const ret = new Promise(function (resolve) {
resolveFunc = resolve;
_this.reportIds = _this.reportStorage.keys();
$("#dlgOpen").modal("show");
});
return ret;
},
});
},
};
</script>
<style>
#designer-host, #viewer-host {
width: 100%;
height: 800px;
}
</style>
6、预览结果
7、前端报表示例展示
关注公众号
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
最全前端Web报表打印方法汇总 | 葡萄城技术团队
最全前端Web报表打印方法汇总 (一)背景介绍 大家在日常办公过程中经常需要进行文档打印,比如:打印Excel表格、PPT文档、照片。此外,在大家使用的各种应用系统中也都提供了打印功能,而不是让大家必须导出一个Excel或者PDF文件再进行打印,比如:CRM中的合同打印、ERP中的BOM物料清单打印、HIS医疗信息系统中的电子病历打印、WMS中的出库入库单、财务系统中的发票打印等等。这些集成到应用系统中的打印功能的确让用户方便了不少,但是对于软件开发者来说,在为这么多场景的不同打印需要寻求技术方案时就比较头疼了。 本文将汇总大家遇到的各种报表打印需求和实现方案,希望能够对有相关需要的小伙伴们起到一定的帮助作用,让程序猿同学们少些加班、多些生活。 (二)认识打印机类型 在开始介绍打印实现方案之前,我们需要了解一下现在市面是场景的打印类型,以及他们的主要用途。 激光打印机:激光打印机适用于公司、学校、工厂等场景。它使用激光扫描成像技术,通过激光束将数据信号转化为图像,然后将墨粉加热固化到纸张上。激光打印机的打印速度较快,打印质量较高,适合打印大量文档和表格。 喷墨打印机:喷墨打印机适合学生...
-
下一篇
Zadig 全面推出英文版,向全球开发者开放
在全球化协作日益重要的今天,开源项目 Zadig 作为企业级云原生 DevOps 平台,正式推出全英文版本,涵盖官方网站、产品控制台及技术文档,为国际团队提供更加友好的开发体验。这一举措标志着这一原本已在 GitHub 上开源的项目,正式向全球市场拓展。 官方网站:全球焕新登场 全新设计的英文官网,以清晰的架构与国际化的视觉语言,全面展示了 Zadig 的核心特性与技术优势,帮助用户快速洞察其自动化与工程效能价值。 同步构建的英文内容矩阵,将持续输出云原生领域的深度技术解析、行业实践案例,为国际团队提供有价值的学习资源。 产品体验:无缝国际化 Zadig 产品界面现已实现 100% 英文覆盖,确保从导航菜单到操作流程,都严格遵循国际化设计规范。我们注重术语的精准与交互习惯的一致性,为国际团队提供地道的英文使用体验。 在协同层面,Zadig 现已实现从审批流程、消息通知到团队协作的全场景英文覆盖。更进一步,我们原生适配了飞书国际版、Microsoft Teams 等主流协作工具,将系统告警与审批动态实时推送至团队沟通现场,使全球成员能够无视地域差异,实现聚焦高效的实时协作。 此外,平台深...
相关文章
文章评论
共有0条评论来说两句吧...











微信收款码
支付宝收款码