- <template>
- <div id="designer-toolbar" class="container-fluid">
- <div class="row mt-3 mb-3">
- <button
- type="button"
- class="btn btn-primary btn-sm col-sm-2 ml-1"
- v-on:click="onPdfPreview()"
- :style="{display: designerHidden ? 'none' : 'block'}"
- >
- PDF 预览
- </button>
- <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="host" style="height:100%;width:100%;margin:10px">
- <ReportDesigner ref='reportDesigner'></ReportDesigner>
- </div>
- </template>
- <script>
- import {ref, onMounted, watch} from 'vue';
- import {Designer as ReportDesigner} from '@grapecity/activereports-vue';
- import "@grapecity/activereports-localization/dist/designer/zh-locale";
- import "@grapecity/activereports/styles/ar-js-ui.css";
- import "@grapecity/activereports/styles/ar-js-designer.css";
- import {PdfExport} from "@grapecity/activereports";
- export default {
- name: 'ActiveReportsDesigner',
- // props: {
- // reportFile: {
- // type: String,
- // default: ''
- // },
- // reportOrientation: {
- // type: String,
- // default: "Landscape"
- // }
- // },
- components: {ReportDesigner},
- setup(context) {
- let reportDesigner = ref();
- let resolveFunc = ref(null);
- let reportStorage = new Map();
- let counter = 0;
- let designerHidden = ref(false);
- const onPdfPreview = () => {
- // 在这里定义 onPdfPreview 方法的逻辑
- // 例如,在 PDF 预览按钮点击时执行的操作
- const reportInfo = reportDesigner.getReport();
- console.log('PDF 预览按钮被点击');
- const report = new PageReport()
- report.load(reportInfo.definition);
- const doc = report.run();
- const result = PdfExport(doc);
- result.download("exportedreport.pdf");
- // 可以在这里添加具体的逻辑
- };
- const onDesignerOpen = () => {
- // 在这里定义 onDesignerOpen 方法的逻辑
- // 例如,在打开设计器按钮点击时执行的操作
- this.designerHidden = false;
- console.log('打开设计器按钮被点击');
- // 可以在这里添加具体的逻辑
- };
- onMounted(() => {
- reportDesigner = new ReportDesigner("#host", {language: "zh"});
- reportDesigner.setActionHandlers({
- onRender: async (report)=>{
- this.designerHidden = true;
- this.$refs.reportViewer.Viewer().open(report.definition);
- },
- onCreate: () => {
- const reportId = `NewReport${counter + 1}`;
- counter++;
- return Promise.resolve({definition: templates.CPL, id: reportId, displayName: reportId});
- },
- onOpen: function () {
- const ret = new Promise((resolve) => {
- resolveFunc.value = resolve;
- return ret;
- })
- },
- onSave: (info) => {
- const reportId = info.id || `NewReport${counter + 1}`;
- this.reportStorage.set(reportId, info.definition);
- counter++;
- return Promise.resolve({displayName: reportId});
- },
- onSaveAs: (info) => {
- const reportId = `NewReport${counter + 1}`;
- this.reportStorage.set(reportId, info.definition);
- counter++;
- return Promise.resolve({id: reportId, displayName: reportId});
- }
- });
- reportDesigner.setReport({ id: "reports/company-template.rdlx-json" });
- })
- return {
- reportDesigner,
- reportStorage,
- resolveFunc,
- counter,
- onPdfPreview,
- onDesignerOpen,
- designerHidden,
- }
- },
- }
- </script>
- <style>
- #host, #viewer-host {
- width: 100%;
- height: 500px;
- }
- </style>
复制代码 现在目前的代码是这样 然后报 |