Vue3项目使用Stimulsoft.Reports.js【项目实战】

Vue3项目使用Stimulsoft.Reports.js【项目实战】

相关阅读:vue-cli使用stimulsoft.reports.js(保姆级教程)_stimulsoft vue-CSDN博客

前言

在BS的项目中我们时常会用到报表打印、标签打印、单据打印,可是BS的通用打印解决方案又很少,小型公司只能依赖第三方打印组件,这无疑是很令人头疼的,这款Stimulsoft.Reports.js是目前我用过比较方便的打印工具,正版价格对于小公司来说也比较合适。

同款的有ActiveReportsJS比这个可能更好用,但是价格也相对高一点。

1.stimulsoft.reports.js下载

官方设计器下载地址:模板设计器

官方项目下载地址:stimulsoft.reports.js测试项目下载 。点击页面底部【Download】下载项目源码里面有我们要的所有文件

注:本插件为付费插件,非付费状态会有水印

2.文件存放

我们把下载的项目存放到项目顶层路径,当然你可以使用自定义名字

工具路径:stimulsoft/*
模板路径:stimulsoft/reports/*
项目文件存放结构

3.项目引入

里的**<%= BASE_URL %>是由于我使用的项目需要加<%= BASE_URL %>**前缀才能访问到具体文件

以这种全局引入的方式会给window下面加一个Stimulsoft的属性后面我们会用到它

<!DOCTYPE html>
<html lang="zh_CN" id="htmlRoot"><head><!-- 其他代码 --></head><body><!-- 其他代码 --><script src="<%= BASE_URL %>stimulsoft/stimulsoft.reports.js"></script><script src="<%= BASE_URL %>stimulsoft/stimulsoft.viewer.js"></script><script src="<%= BASE_URL %>stimulsoft/stimulsoft.designer.js"></script><script src="<%= BASE_URL %>stimulsoft/stimulsoft.blockly.editor.js"></script></body>
</html>

4.创建打印组件

我的打印组件创建路径:src/components/Print/PrintStimulsoftReportV3.vue

<template><span><slot><!-- 可以替换该默认插槽 --><a-button type='primary' @click='printer'>{{ name }}</a-button></slot></span>
</template><script lang="ts" setup>
import {watch, defineExpose} from "vue";// 暴露打印方法供父组件使用
defineExpose({printer
})
/*** 父组件传递打印需要的参数* file 文件名* name 打印按钮显示文本* data 打印的数据* isPrinter 打印更新*/
const props = defineProps(["file", "name", "data", "isPrinter"])
const {data, file, name, isPrinter} = props
// 监听变化,使用isPrinter来更新打印
watch(props, (value, oldValue, onCleanup) => {if (value.isPrinter != oldValue.isPrinter) {printer()}}
);function printer() {console.log('begin')// 获取Stimulsoft工具对象let Stimulsoft = window.Stimulsoft// 绑定激活码Stimulsoft.Base.StiLicense.key = "你的激活码";// 创建报表let report = new Stimulsoft.Report.StiReport()console.log(report.renderAsync)// 绑定报表路径,这里使用了插槽来适应不同的文件report.loadFile('/stimulsoft/reports/' + file + '.mrt')// 清空缓存report.dictionary.databases.clear()// 创建新的DataSet对象let dataSet = new Stimulsoft.System.Data.DataSet('JSON')// 打印数据绑定let json = {}json[file + ""] = data?.valuejson['data'] = data?.valueconsole.log("打印数据", json)dataSet.readJson(JSON.stringify(json))report.regData('JSON', 'JSON', dataSet)// 调用打印数据report.renderAsync(function () {report.print()});}
</script><style scoped>
</style>

5.调用打印组件

5.1基本调用

效果预览

<template><div><PrintStimulsoftReportV3:file="'Report'":name="'打印按钮1'":data="printData1":isPrinter="isPrinter"/><PrintStimulsoftReportV3ref="printV3":file="'Report'":name="'打印按钮2'":data="printData2":isPrinter="isPrinter"><a-button type="primary" @click="print">打印V3</a-button></PrintStimulsoftReportV3></div>
</template><script lang="ts" setup>
import PrintStimulsoftReportV3 from "@/components/Print/PrintStimulsoftReportV3.vue";
import {ref, reactive,onMounted} from "vue"const printData1: any = reactive([])
onMounted(()=>{printData1.value=[{"id": "1709766277226536962","username": "user","title": "阳光小镇的故事","content": "曾经有一个小镇,名叫阳光镇。这个小镇并不大,但它却拥有着一群善良和蔼的居民。","createBy": "admin","createTime": "2023-10-05 11:03:41","updateBy": "admin","updateTime": "2023-10-05 11:06:13","sysOrgCode": "A01"}]
})const isPrinter = ref(false)
const printData2: any = reactive([])
const printV3 =ref()
function print(){printData2.value=[{"id": "1709766277226536962","username": "user","title": "阳光小镇的故事","content": "曾经有一个小镇,名叫阳光镇。这个小镇并不大,但它却拥有着一群善良和蔼的居民。","createBy": "admin","createTime": "2023-10-05 11:03:41","updateBy": "admin","updateTime": "2023-10-05 11:06:13","sysOrgCode": "A01"},{"id": "1709766277226536962","username": "user","title": "阳光小镇的故事","content": "曾经有一个小镇,名叫阳光镇。这个小镇并不大,但它却拥有着一群善良和蔼的居民。","createBy": "admin","createTime": "2023-10-05 11:03:41","updateBy": "admin","updateTime": "2023-10-05 11:06:13","sysOrgCode": "A01"}]// 通过子组件方法打印printV3.value.printer()// 通过修改参数打印// isPrinter.value=!isPrinter.value
}</script><style scoped></style>

5.2实战调用

这里是我实际测试项目中用到的调用方式,操作为【选中打印项目】->【打印数据】

<template><div class="p-2"><BasicTable@register="registerTable":rowSelection="rowSelection"@edit-end="handleEditEnd"@edit-cancel="handleEditCancel":beforeEditSubmit="beforeEditSubmit"@row-click="rowSelectChange"><template #tableTitle><a-button type="primary" preIcon="ant-design:plus" @click="add">新建</a-button><a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button><j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button><PrintJmreport :template-id="'869739541898461184'" :params="printParams" :disabled="!!!selectedRowKeys.length"/><PrintStimulsoftReport ref="Print" :data="printArrV2" :file="'Report'" name="打印Stimulsoft":isPrinter="isPrinter"><a-button type="primary" @click="printDataV2" :disabled="!selectedRowKeys.length">打印Vue2</a-button></PrintStimulsoftReport><PrintStimulsoftReportV3 ref="printV3" :data="printArrV3" :file="'Report'" name="打印V3":isPrinter="isPrinter"><a-button type="primary" @click="printDataV3" :disabled="!selectedRowKeys.length">打印Vue3</a-button></PrintStimulsoftReportV3></template><template #action="{ record }"><TableAction :actions="getActions(record)" :dropDownActions="getDropDownActions(record)"/></template><a-divider/></BasicTable><NodeBootModal @register="registerModel" @success="onSubmit"/></div>
</template><script lang="ts" setup>
import {BasicTable, EditRecordRow, TableAction} from '/@/components/Table';
import type {ActionItem} from '/@/components/Table';
import {useListPage} from '/@/hooks/system/useListPage';
import {useTable} from '/@/components/Table';
import {list, del, getExportUrl, getImportUrl, edit as editData, getById} from './NodeBoot.api';
import {columns, searchFormSchema} from './NoteBoot.data';
import NodeBootModal from './modal/NodeBootModal.vue';
import {useModal} from '/@/components/Modal';
import JUploadButton from '/@/components/Button/src/JUploadButton.vue';
import {ref, reactive, provide} from 'vue';
import PrintJmreport from '@/components/Print/PrintJmreport.vue';
import PrintStimulsoftReport from "@/components/Print/PrintStimulsoftReport.vue";
import PrintStimulsoftReportV3 from "@/components/Print/PrintStimulsoftReportV3.vue";const {prefixCls, tableContext, onImportXls, onExportXls} = useListPage({designScope: 'note-boot-list',tableProps: {size: 'small',api: list,columns: columns,formConfig: {schemas: searchFormSchema,},minHeight: 500,maxHeight: 1000,bordered: true,clickToRowSelect: true,rowSelection: {type: 'radio',},},exportConfig: {name: '记事本',url: getExportUrl,},importConfig: {url: getImportUrl,},
});const [registerTable, {reload, updateTableDataRecord}, {rowSelection, selectedRows, selectedRowKeys}] = tableContext;const [registerModel, {openModal}] = useModal();function add() {openModal(true, {title: '新增', record: [], isUpdate: false});
}function edit(record) {openModal(true, {title: '编辑', record: record, isUpdate: true});
}function info(record) {openModal(true, {title: '详情', record: record, isUpdate: true, disable: true});
}function onSubmit() {reload();
}function getActions(record): ActionItem[] {return [{label: '编辑',onClick: () => edit(record),},];
}function getDropDownActions(record): ActionItem[] {return [{label: '详情',onClick: () => info(record),},{label: '删除',popConfirm: {title: '确认删除',confirm: () => del(record, reload),},},];
}// const [registerTable, {reload, updateTableDataRecord}] = useTable({
//   title: '可编辑单元格示例',
//   api: list,
//   columns: columns,
//   showIndexColumn: true,
//   bordered: true,
// });async function handleEditEnd({record, index, key, value}: Recordable) {console.log('结束', record, index, key, value);const params = {};params['id'] = record.id;params['' + key] = value;return await editData(params);// return false;
}function handleEditCancel() {console.log('取消提交');
}async function beforeEditSubmit({record, index, key, value}) {console.log('单元格数据正在准备提交', {record, index, key, value});return true;
}// 打印
const printParams: any = reactive({});
let printArrV2: any[] = reactive([])
const printArrV3: any = reactive([])
const isPrinter = ref(false)function rowSelectChange(value) {printParams.value = {id: value.id}getById({id: value.id}).then(resp => {console.log("请求的数据", resp)printArrV2 = [resp]printArrV3.value = [resp]})
}async function printDataV2() {await getById({id: selectedRowKeys.value[0]}).then(resp => {console.log(resp)printArrV2 = [resp]console.log(printArrV2)})isPrinter.value = !isPrinter.value
}const printV3 = ref()async function printDataV3() {await getById({id: selectedRowKeys.value[0]}).then(resp => {console.log(resp)printArrV3.value = [resp]console.log(printArrV3)})// isPrinter.value = !isPrinter.valueprintV3.value.printer()
}</script><style scoped></style>

6.其他补充

6.1 vue2打印组件

<template><span><slot><a-button type='primary' icon='printer' @click='printer'>{{ this.name }}</a-button></slot></span>
</template><script>
export default {name: 'statement',props: {data: {type: Array,default: false},file: {type: String,default: false},name: {type: String,default: '打印'},isPrinter: {type: Boolean,default: false}},data() {},methods: {printer() {console.log('begin')Stimulsoft.Base.StiLicense.key = "";let report = new Stimulsoft.Report.StiReport()console.log(report.renderAsync)report.loadFile('/stimulsoft/reports/' + this.file + '.mrt')report.dictionary.databases.clear()// 创建新的DataSet对象let dataSet = new Stimulsoft.System.Data.DataSet('JSON')let json = {}json[this.file] = this.datajson['data'] = this.dataconsole.log(json)dataSet.readJson(JSON.stringify(json))report.regData('JSON', 'JSON', dataSet)report.renderAsync(function () {setTimeout(() => {}, 500)report.print()});// setTimeout(() => {//   report.render()//   report.print()// }, 500)this.isPrinter = false},showPrinter() {this.isPrinter = true}},watch: {isPrinter(val) {console.log("监听到了数据改变")this.printer()}}
}
</script><style scoped>
</style>

6.2 模板数据源

在vue-cli使用stimulsoft.reports.js(保姆级教程)_stimulsoft vue-CSDN博客有详细介绍数据源和报表的使用基础

{"data":[{"id": "1709766277226536962","username": "user","title": "阳光小镇的故事","content": "曾经有一个小镇,名叫阳光镇。","createBy": "admin","createTime": "2023-10-05 11:03:41","updateBy": "admin","updateTime": "2023-10-05 11:06:13","sysOrgCode": "A01"}]
}

6.3 效果预览

在这里插入图片描述
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/150125.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

❓“想创作音乐,但不会编曲?”FL Studio 21 轻松帮你编曲

❓“想创作音乐&#xff0c;但不会编曲&#xff1f;” ❓“不知道如何将各种音乐元素组合起来&#xff1f;” 5个步骤&#xff0c;轻松编曲&#xff01; 想要成为音乐创作高手&#xff0c;编曲是必不可少的技能。今天为大家带来5个编曲的步骤&#xff0c;让你轻松掌握编曲技巧…

JVM-满老师

JVM 前言程序计数器&#xff0c;栈&#xff0c;虚拟机栈&#xff1a;本地方法栈&#xff1a;堆&#xff0c;方法区&#xff1a;堆内存溢出方法区运行时常量池 垃圾回收垃圾回收算法分代回收 前言 JVM 可以理解的代码就叫做字节码&#xff08;即扩展名为 .class 的文件&#xff…

Spring Cloud OpenFeign 性能优化的4个方法

OpenFeign 是 Spring 官方推出的一种声明式服务调用和负载均衡组件。它的出现就是为了替代已经进入停更维护状态的 Netflix Feign&#xff0c;是目前微服务间请求的常用通讯组件。 1.超时设置 OpenFeign 底层依赖Ribbon 框架&#xff0c;并且使用了 Ribbon 的请求连接超时时间…

基于STM32 ZigBee无线远程火灾报警监控系统物联网温度烟雾

实践制作DIY- GC00168---ZigBee无线远程监控系统 一、功能说明&#xff1a; 基于STM32单片机设计---ZigBee无线远程监控系统 二、功能说明&#xff1a; 1个主机&#xff1a;STM32F103C系列单片机LCD1602显示器蜂鸣器 ZigBee无线模块3个按键&#xff08;设置、加、减&#xff0…

图片批量编辑器,轻松拼接多张图片,创意无限!

你是否曾经遇到这样的问题&#xff1a;需要将多张图片拼接成一张完整的画面&#xff0c;却缺乏专业的图片编辑技能&#xff1f;现在&#xff0c;我们为你带来一款强大的图片批量编辑器——让你轻松实现多张图片拼接&#xff0c;创意无限&#xff01; 这款图片批量编辑器可以帮助…

笔训【day3】

目录 选择题 1、二维数组初始化 2、[]优先级高于* ​编辑 3、for初始化只执行一次​编辑 4、大小端 编程题 1、字符串中找出最长连续数字串 2、数组中出现次数超过一半的数 选择题 1、二维数组初始化 C&#xff1a;多初始化了一行 D&#xff1a;不能中间用两个逗号跳过。…

数据结构与算法-(7)---栈的应用-(4)后缀表达式求值

&#x1f308;write in front&#x1f308; &#x1f9f8;大家好&#xff0c;我是Aileen&#x1f9f8;.希望你看完之后&#xff0c;能对你有所帮助&#xff0c;不足请指正&#xff01;共同学习交流. &#x1f194;本文由Aileen_0v0&#x1f9f8; 原创 CSDN首发&#x1f412; 如…

【Java项目推荐之黑马头条】自媒体文章实现异步上下架(使用Kafka中间件实现)

自媒体文章上下架功能完成 需求分析 流程说明 接口定义 说明接口路径/api/v1/news/down_or_up请求方式POST参数DTO响应结果ResponseResult DTO Data public class WmNewsDto {private Integer id;/*** 是否上架 0 下架 1 上架*/private Short enable;}ResponseResult 自媒…

SpringCloud Alibaba - Seata 四种分布式事务解决方案(TCC、Saga)+ 实践部署(下)

目录 一、Seata 分布式解决方案 1.1、TCC 模式 1.1.1、TCC 模式理论 对比 TCC 和 AT 模式的一致性和隔离性 TC 的工作模型 1.2.2、TCC 模式优缺点 1.2.3、TCC 模式注意事项&#xff1a;空回滚 1.2.4、TCC 模式注意事项&#xff1a;业务悬挂 1.2.5、实现 TCC 模式 案例…

VS Code更改软件的语言

刚刚安装好的 vscode 默认是英文&#xff0c;可以安装中文扩展包。如图&#xff1a; 重启即可更换为中文。 如果想切换为英文&#xff0c;可以 Ctrl Shift P&#xff0c;打开命令面板。 输入 Configure DIsplay Language&#xff0c;如图&#xff1a; 可以在中英文之间切换…

如何选择合适的自动化测试工具?

自动化测试是高质量软件交付领域中最重要的实践之一。在今天的敏捷开发方法中&#xff0c;几乎任一软件开发过程都需要在开发阶段的某个时候进行自动化测试&#xff0c;以加速回归测试的工作。自动化测试工具可以帮助测试人员以及整个团队专注于自动化工具无法处理的各自任务&a…

【GSEP202303 C++】1级 长方形面积

[GSEP202303 一级] 长方形面积 题目描述 小明刚刚学习了如何计算长方形面积。他发现&#xff0c;如果一个长方形的长和宽都是整数&#xff0c;它的面积一定也是整数。现在&#xff0c;小明想知道如果给定长方形的面积&#xff0c;有多少种可能的长方形&#xff0c;满足长和宽…

TCP端口崩溃,msg:socket(): Too many open files

一、现象 linux系统中运行了一个TCP服务器&#xff0c;该服务器监听的TCP端口为10000。但是长时间运行时发现该端口会崩溃&#xff0c;TCP客户端连接该端口会失败&#xff1a; 可以看到进行三次握手时&#xff0c;TCP客户端向该TCP服务器的10000端口发送了SYN报文&#xff0c;…

C++面试八股(一)

目录 C和C的区别 1、语言特性 2、内存管理 3、C的库更加丰富 4、对异常的处理 什么是封装继承多态&#xff1f; 封装 继承 多态 new和malloc的区别 STL容器有哪些&#xff1f;容器对应的使用场景&#xff1f;&#xff08;挑一个你认为最熟悉的容器&#xff09; vector、…

前端相关题目随笔

Vh虽然获取到了视口高度&#xff0c;但是vh会随着屏幕的、大小变化&#xff0c;所以当减去一个数字之后&#xff0c;就会显示错误。 生成id 如果没有设置id&#xff0c;则可以通过new Date.getTime()获取一个时间&#xff0c;作为一个单独的id&#xff0c;也可以通过下载uuid生…

Cocos Creator3.8 项目实战(六)Combobox控件的实现和使用

在cocoscreator 中&#xff0c;没有Combobox控件&#xff0c;无奈之下只能自己动手写一个。 ⚠️ 文末附 ComboBox.ts 、ComboBoxItem.ts 完整源码&#xff0c; 可直接拿去使用。 实现原理&#xff1a; 1、Combobox 背景图background 是一个sprite 控件&#xff0c;上面放了一…

【二】spring boot-设计思想

spring boot-设计思想 简介&#xff1a;现在越来越多的人开始分析spring boot源码&#xff0c;拿到项目之后就有点无从下手了&#xff0c;这里介绍一下springboot源码的项目结构 一、项目结构 从上图可以看到&#xff0c;源码分为两个模块&#xff1a; spring-boot-project&a…

Python 无废话-办公自动化Excel修改数据

如何修改Excel 符合条件的数据&#xff1f;用Python 几行代码搞定。 需求&#xff1a;将销售明细表的产品名称为PG手机、HW手机、HW电脑的零售价格分别修改为4500、5500、7500&#xff0c;并保存Excel文件。如下图 Python 修改Excel 数据&#xff0c;常见步骤&#xff1a; 1&…

Go Gin Gorm Casbin权限管理实现 - 2. 使用Gorm存储Casbin权限配置以及`增删改查`

文章目录 0. 背景1. 准备工作2. 权限配置以及增删改查2.1 策略和组使用规范2.2 用户以及组关系的增删改查2.2.1 获取所有用户以及关联的角色2.2.2 角色组中添加用户2.2.3 角色组中删除用户 2.3 角色组权限的增删改查2.3.1 获取所有角色组权限2.3.2 创建角色组权限2.3.3 修改角色…

麻雀搜索算法(SSA)(含MATLAB代码)

先做一个声明&#xff1a;文章是由我的个人公众号中的推送直接复制粘贴而来&#xff0c;因此对智能优化算法感兴趣的朋友&#xff0c;可关注我的个人公众号&#xff1a;启发式算法讨论。我会不定期在公众号里分享不同的智能优化算法&#xff0c;经典的&#xff0c;或者是近几年…