组件参数props
2025/5/28...大约 6 分钟sv-print可视化打印打印组件模板
基础参数
参数键名 | 数据类型 | 默认值 | 说明 | 备注 |
---|---|---|---|---|
template | object | {} | 模板json数据 | 也可传整个模板对象支持的参数 |
printData | object | {} | 打印数据(设计时打印预览) | |
templateKey | string | default-template | 缓存键(设计保存存入localStorage的键) | |
title | string | 默认模板 | 导出文件默认名称:模板模板.json | |
designOptions | object | { grid: true } | 设计参数,显示网格线 | |
boolean | `` | 是否自动连接打印客户端 | 即将废弃 设计页面可无需考虑 | |
paperList | string[] | 默认纸张列表 | 可选纸张列表,见下方参数说明 | |
plugins | object[] | 插件 | 插件机制,扩展参数,扩展打印元素 见下方参数说明 | |
authKey | string | `` | 授权key | 没有则有体验版水印 |
参数说明:
paperList
// vue3 为例
const paperList = ref([
{ type: 'A1', width: 594, height: 841 },
{ type: 'A2', width: 420, height: 594 },
{ type: 'A3', width: 297, height: 420 },
{ type: 'A4', width: 210, height: 297 },
{ type: 'A5', width: 148, height: 210 },
{ type: 'A6', width: 105, height: 148 },
{ type: 'A7', width: 74, height: 105 },
{ type: 'B1', width: 728, height: 1030 },
{ type: 'B2', width: 515, height: 728 },
{ type: 'B3', width: 364, height: 515 },
{ type: 'B4', width: 257, height: 364 },
{ type: 'B5', width: 182, height: 257 },
{ type: 'B6', width: 91, height: 182 },
{ type: 'B7', width: 64, height: 91 },
]);
构建可拖拽元素相关
参数键名 | 数据类型 | 默认值 | 说明 | 备注 |
---|---|---|---|---|
providers | object[] | [] | 可拖拽元素 provider | |
providerMap | object|object[] | { container: ".hiprintEpContainer", value: "defaultModule" } | 构建可拖拽元素的容器,provider的键 | |
clearProviderContainer | boolean | true | 构建provider时 是否先清空容器 | |
tags | string[] | [".draggable-ele"] | 可拖拽元素 选择器 |
参数说明:
provider.js
import { hiprint } from 'sv-print';
export default function (options) {
var addElementTypes = function (context) {
context.removePrintElementTypes('ibujianModule'); // 避免重复添加
context.addPrintElementTypes('ibujianModule', [
new hiprint.PrintElementTypeGroup('i不简', [
{
tid: 'ibujianModule.text', // 唯一 key
type: 'text', // 元素类型
title: '文本', // 这里和 options 中的 title 一样。"拖拽时就显示" 优先级高于 options 的, "无法彻底删除"
options: {
// 参数同 模板json数据格式 中的 options, 可以不用指定 left, top
title: '文本2', // 标题
field: 'text', // 字段名
testData: '123', // 测试数据
},
},
]),
]);
};
return {
addElementTypes: addElementTypes,
};
}
providers参数
// vue3 为例
import provider from './provider.js';
// 注意留意, addPrintElementTypes("ibujianModule", []) 中的 "ibujianModule"
const providers = ref([provider]);
providerMap参数
// vue3 为例
// 默认值, 指定 ".hiprintEpContainer" 容器, 构建 "defaultModule" 的 provider
const providerMap = ref({
container: '.hiprintEpContainer',
value: 'defaultModule',
});
// 构建前先清空容器
const clearProviderContainer = ref(true);
// 也可以指定多个容器, 构建多个 provider
const providerMapList = ref([
{
container: '.hiprintEpContainer',
value: 'defaultModule',
},
{
container: '.hiprintEpContainer2',
value: 'defaultModule2',
},
]);
tags参数
// vue3 为例
<template>
<Designer :tags="tags">
<template #other>
<div class="draggable-ele" tid="defaultModule.text">这个元素可拖拽</div>
<div class="ibujian" tid="defaultModule.text">这个元素可拖拽</div>
<div class="xxxx" tid="defaultModule.text">不可以,不可拖拽</div>
</template>
</Designer>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { Designer } from '@sv-print/vue3';
const tags = ref(['.draggable-ele', '.ibujian']);
</script>
设计器函数重写
参数键名 | 数据类型 | 默认值 | 说明 | 备注 |
---|---|---|---|---|
events | object | {} | 保存,编辑模板,编辑打印数据,快捷键 | |
onPreviewClick | function(e: MouseEvent):boolean | 预览 点击事件 | 返回 "true|false" 是否阻止冒泡 | |
onImageChooseClick | function(target: any) | 图片选择点击事件 | ||
onPanelAddClick | function(panel, createPanel) | 多面板点击 "+" 事件 | ||
onFunctionClick | function(option, printElement, event) | 函数/textarea点击事件 |
参数说明:
events事件
// vue3 为例
<template>
<Designer :events="events"></Designer>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { Designer } from '@sv-print/vue3';
const events = ref({
// 保存模板
onSave: (key: string, data: unknown) => {
console.log('保存模板');
return true; // 返回 true 阻止冒泡
},
// 编辑模板
onEdit: (data: unknown) => {
console.log('编辑模板');
return true; // 返回 true 阻止冒泡
},
// 编辑打印数据
onEditData: (data: unknown) => {
console.log('编辑打印数据');
return true; // 返回 true 阻止冒泡
},
// 快捷键
onKeyDownEvent: (e: KeyboardEvent, designerUtils: unknown) => {
console.log('快捷键');
return true; // 返回 true 阻止冒泡
},
});
</script>
onPreviewClick事件
// vue3 为例
<template>
<Designer :onPreviewClick="onPreviewClick"></Designer>
</template>
<script setup lang="ts">
const onPreviewClick = (e: MouseEvent) => {
console.log('预览点击事件');
console.log(e);
return true; // 返回 true 阻止冒泡
};
</script>
onImageChooseClick事件
// vue3 为例
<template>
<Designer :onImageChooseClick="onImageChooseClick"></Designer>
</template>
<script setup lang="ts">
const onImageChooseClick = (target: unknown) => {
console.log('图片 选择点击事件');
console.log(target);
target.refresh('https://www.ibujian.cn/logo.png');
};
</script>
onPanelAddClick事件
// vue3 为例
<template>
<Designer :onPanelAddClick="onPanelAddClick"></Designer>
</template>
<script setup lang="ts">
const onPanelAddClick = (panel, createPanel) => {
console.log('多面板 新增 点击事件');
console.log(panel);
panel.name = '新面板' + (panel.index + 1);
createPanel(panel);
};
</script>
设计器回调
参数键名 | 数据类型 | 默认值 | 说明 | 备注 |
---|---|---|---|---|
onDesigned | function | 组件初始化完成回调 | 见参数说明 |
参数说明:
回调示例
// vue3 为例
<template>
<Designer @onDesigned="onDesigned"></Designer>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { Designer } from '@sv-print/vue3';
const utils = ref();
const onDesigned = (e) => {
console.log('注意看 onDesigned 回调参数: ');
console.log(e);
const { hiprint, designerUtils } = e.detail;
console.log(hiprint);
// 核心工具类, 单例对象
utils.value = designerUtils;
console.log(designerUtils);
// 设计器的 模板对象
console.log(designerUtils.printTemplate);
// 示例: 更新模板json数据
designerUtils.printTemplate.update({});
// 示例: 导出模板json文件
designerUtils.export();
};
</script>
UI样式参数
参数键名 | 数据类型 | 默认值 | 说明 | 备注 |
---|---|---|---|---|
theme | string | light | 默认主题 | |
themeList | string[] | 支持的所有主题 | 可选主题列表,见下方参数说明 | |
showPanels | boolean | true | 是显示多面板操作区域 | |
headerLogoHtml | string | <i class="svp-header-logo svicon sv-print"></i> | 默认 Header 左侧logo样式 | 需authKey |
headerTitle | string | sv-print | 默认 Header title | 需authKey |
miniMapOriginMode | boolean | false | 概览图原始模式 | |
previewOptions | object | {} | 预览参数 | |
styleOption | object | {} | 默认小组件样式,位置 | |
showOption | object | {} | Header,Toolbar,Footer显示控制 |
参数说明:
themeList
// vue3 为例
const themeList = ref([
'light',
'dark',
'cupcake',
'bumblebee',
'emerald',
'corporate',
'synthwave',
'retro',
'cyberpunk',
'valentine',
'halloween',
'garden',
'forest',
'aqua',
'lofi',
'pastel',
'fantasy',
'wireframe',
'black',
'luxury',
'dracula',
'cmyk',
'autumn',
'business',
'acid',
'lemonade',
'night',
'coffee',
'winter',
]);
previewOptions
// vue3 为例
const previewOptions = ref({
showPdf: true, // 是否显示 导出pdf按钮
showImg: true, // 是否显示 导出图片按钮
});
styleOption
// vue3 为例
const styleOption = ref({
panels: {
// 多面板
mode: 'left',
style: 'left:calc(28%);top:100px;',
},
draggableEls: {
// 可拖拽元素
mode: 'default', // 拖拽模式: default(默认), top(上), bottom(下), left(左), right(右), fixed(固定)
show: true, // 是否显示 默认: true
html: '<i class="svicon sv-element"></i><span>拖拽元素</span>', // 缩放 左侧的 按钮/icon (一般不用)
style: 'left:20px;top:95px;width:200px;height:calc(100% - 340px);', // 样式
},
options: {
// 属性
mode: 'default',
html: '<i class="svicon sv-options"></i><span>属性</span>',
style: 'right:0;top:95px;width:200px;',
},
pageStructure: {
// 页面结构
mode: 'default',
html: '<i class="svicon sv-structure"></i><span>页面结构</span>',
style: 'right:210px;top:95px;width:200px;',
},
locationExchange: {
// 位置交换
mode: 'default',
show: false,
html: '<i class="svicon sv-switch"></i><span>位置交换</span>',
style: 'right:490px;top:95px;width:300px;height:400px',
},
miniMap: {
// 小地图
mode: 'default',
html: '<i class="svicon sv-flow"></i><span>概览图</span>',
style: 'left:20px;bottom:30px;width:240px;min-height:200px;height:200px',
},
editableTools: {
// 编辑工具
mode: 'top',
style: 'left:280px;top:180px;',
},
zIndexTools: {
// 层级工具
mode: 'top',
style: 'left:280px;top:300px;',
},
fontTools: {
// 字体工具
mode: 'top',
style: 'left:280px;top:420px;',
},
zoomTools: {
// 缩放工具
mode: 'left',
style: 'left:240px;top:100px;',
},
rotateTools: {
// 旋转工具
mode: 'bottom',
style: 'left:440px;top:180px;',
},
});
showOption
// vue3 为例
const showOption = ref({
showHeader: true, // 是否显示 顶部 Header
showToolbar: true, // 是否显示 工具栏 Toolbar
showFooter: true, // 是否显示 底部 Footer
// 即将废弃移除
showPower: true, // 是否显示 "powered by sv-print" 需要 authKey 支持
});