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

news2024/10/5 14:25:10

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.项目引入

引入文件 index.html
里的<%= 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?.value
  json['data'] = data?.value
  console.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"/>

    <PrintStimulsoftReportV3
        ref="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.value
  printV3.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.data
      json['data'] = this.data
      console.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.coloradmin.cn/o/1066587.html

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

相关文章

【JavaEE初阶】 多线程(初阶)——壹

文章目录 &#x1f332;线程的概念&#x1f6a9;线程是什么&#x1f6a9;为啥要有线程&#x1f6a9;进程和线程的区别&#x1f6a9;Java 的线程 和 操作系统线程 的关系 &#x1f60e;第一个多线程程序&#x1f6a9;使用 jconsole 命令观察线程 &#x1f38d;创建线程&#x1f…

字段位置顺序对值的影响

Unity中验证AB加载场景时报错&#xff1a; Cannot load scene: Invalid scene name (empty string) and invalid build index -1 报错原因是因为把字段放在了Start函数后面(图一)改成(图二)就好了。图一中协程使用的sceneBName字段值为null。 图一&#xff1a; 图二&#xff1a…

【C++】List -- 详解

一、list的介绍及使用 https://cplusplus.com/reference/list/list/?kwlist list 是可以在常数范围内在任意位置进行插入和删除的序列式容器&#xff0c;并且该容器可以前后双向迭代。 list 的底层是双向链表结构&#xff0c;双向链表中每个元素存储在互不相关的独立节点中&…

Windows10点击开始菜单没反应的四种解决方法

在Windows10电脑中&#xff0c;用户点击开始菜单却出现了没反映的情况&#xff0c;这样用户就无法通过开始菜单来展开操作哦&#xff0c;会给用户的正常操作带来一定程序的影响&#xff0c;下面小编给大家带来四种简单的解决方法&#xff0c;帮助大家轻松恢复Windows10电脑开始…

Selenium 高级定位 CSS

一、CSS选择器概念 CSS拥有自己的语法规则和表达式 CSS通常分为相对定位和绝对定位 CSS常和XPATH一起用于UI自动化测试 二、CSS相对定位使用场景 支持web场景支持app端的webview 三、CSS语法实战 3.1、CSS相对定位的优点 可维护性强语法简洁可以解决各种复杂的定位场景 # …

ARMv7-A 那些事 - 6.常用汇编指令

By: Ailson Jack Date: 2023.10.07 个人博客&#xff1a;http://www.only2fire.com/ 本文在我博客的地址是&#xff1a;http://www.only2fire.com/archives/158.html&#xff0c;排版更好&#xff0c;便于学习&#xff0c;也可以去我博客逛逛&#xff0c;兴许有你想要的内容呢。…

【二叉树练习题】

欢迎来到我的&#xff1a;世界 希望作者的文章对你有所帮助&#xff0c;有不足的地方还请指正&#xff0c;大家一起学习交流 ! 目录 前言初阶题二叉树的节点个数二叉树的叶子节点个数二叉树第k层节点个数二叉树查找值为x的节点 进阶题完全二叉树的节点个数翻转二叉树检验两个树…

修炼k8s+flink+hdfs+dlink(一:安装dlink)

一&#xff1a;mysql初始化。 mysql -uroot -p123456 create database dinky; grant all privileges on dinky.* to dinky% identified by dinky with grant option; flush privileges;二&#xff1a;上传dinky。 上传至目录/opt/app/dlink tar -zxvf dlink-release-0.7.4.t…

医学访问学者面试技巧

医学访问学者面试是一个非常重要的环节&#xff0c;它决定了你是否能够获得这个宝贵的机会去国外的大学或研究机构学习和研究。在这篇文章中&#xff0c;知识人网小编将分享一些关于医学访问学者面试的技巧&#xff0c;帮助你在面试中表现出色。 1. 准备充分 在参加医学访问学…

Multisim:JFET混频器设计(含完整程序)

目录 前言实验内容一、先看作业题目要求二、作业正文IntroductionPre-lab work3.13.2 Experiment Work4.1(2)circuit setup4.1(3)add 12V DC4.1(4)set input x1 and x24.1(5)4.1(6)4.1(7)4.2(1)(2)4.2(3)4.2(4)4.3(1)(2)4.3(3) Conclusion 三、资源包内容 前言 花了好大心血完成…

【线性代数及其应用 —— 第一章 线性代数中的线性方程组】-1.线性方程组

所有笔记请看&#xff1a; 博客学习目录_Howe_xixi的博客-CSDN博客https://blog.csdn.net/weixin_44362628/article/details/126020573?spm1001.2014.3001.5502思维导图如下&#xff1a; 内容笔记如下&#xff1a;

中国高清行政、地形、旅游、人文地图全集(地理干货,覆盖34个省市自治区)

中国高清行政、地形、旅游、人文地图全集&#xff08;地理干货&#xff0c;覆盖34个省市自治区&#xff09;&#xff1a; 中国的高原、平原、盆地和丘陵 四大高原&#xff1a;青藏高原位于中国西南部&#xff0c;平均海拔在4000米以上&#xff0c;是中国最大、世界最高的大高原…

安卓手机如何下载谷歌应用商店(play.google.com)里的app,无需下载google play

不需要梯子&#xff01; 不需要下载google play&#xff01; 不需要考虑机型&#xff01; 1、首先使用电脑打开网站 https://apps.evozi.com/ 点击 apk downloader 进入一个新的界面 2、电脑打开谷歌商店 https://play.google.com/store/apps 搜索任意软件&#xff0c;比如 …

300元开放式耳机推荐哪款好用一点、最便宜的开放式耳机

对于音乐爱好者来说&#xff0c;一款出色的耳机是必不可少的&#xff0c;开放式耳机以其独特的音场表现和舒适的佩戴感受&#xff0c;成为许多人钟爱的选择。如果你正在寻找一个300元价位好用的开放式耳机&#xff0c;今天就给大家推荐几款&#xff0c;希望能帮助到你~ 1、西圣…

python入门篇07-数据容器(序列 集合 字典,json初识)基础(下)

全文目录,一步到位 1.前言简介1.1 专栏传送门1.1.1 上文传送门 2. python基础使用2.1 序列2.1.1 序列定义2.1.2 序列参数解释2.1.3 列表list切片2.1.4 元组tuple切片2.1.5 字符串str切片 2.2 集合定义2.2.1 set集合-基本语法2.2.2 set集合-添加元素.add()2.2.3 set集合- 移除元…

bochs 对 Linux0.11 进行调试 (TODO: 后面可以考虑集成 vscode+gdb+qemu)

我在阅读 Linux0.11 源码时&#xff0c;对一个指令 LDS 感到困惑。 看了下 intel 指令集手册&#xff0c;能猜到 LDS 的功能&#xff0c;但不确定。 于是决定搭建调试环境&#xff0c;看看 LDS 的功能是否真如自己猜测。 首先 make debug 运行 qemu-Linux0.11&#xff0c;命…

死磕CMS垃圾回收器

为什么会有这篇文章&#xff1f; **校招垃圾回收面试重灾区。**本人秋招面试过大大小小的公司&#xff0c;发现几乎所有公司在面试的时候&#xff0c;一旦涉及到JVM只是&#xff0c;CMS和G1是常问点&#xff0c;而且CMS问的尤其多。所以本文会对根据网上常见的资料做一个整合并…

Qt扫盲-QTreeView 理论总结

QTreeView 理论使用总结 一、概述二、快捷键绑定三、提高性能四、简单实例1. 设计与概念2. TreeItem类定义3. TreeItem类的实现4. TreeModel类定义5. TreeModel类实现6. 在模型中设置数据 一、概述 QTreeView实现了 model 中item的树形表示。这个类用于提供标准的层次列表&…

Python3.x安装Pandas教程

python3.x 安装pandas总是会出现一些乱七八糟的问题&#xff0c;那现在就给你们讲述一种超级简单的安装方法&#xff0c;非常简单。 1&#xff0c;检查自己的python版本&#xff0c;我的是python3.4 32位的 2&#xff0c;https://www.lfd.uci.edu/~gohlke/pythonlibs/ 进入此网…

IIS部署Flask

启用 CGI 安装wfastcgi pip install wfastcgi 启用 wfastcgi 首先以管理员身份运行wfastcgi-enable来在IIS上启用wfastcgi&#xff0c;这个命令位于c:\python_dir\scripts&#xff0c;也就是你需要确保此目录在系统的PATH里&#xff0c;或者你需要cd到这个目录后再执行。 #…