print-center-vue2 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,161 @@
1
+ ## 宝威打印中心
2
+
3
+ ### 快速开始
4
+
5
+ 1. 安装
6
+ vue3版本 npm install --save print-center
7
+ vue2版本 npm install --save print-center-vue2
8
+ 2. 使用
9
+
10
+ ```js
11
+ // vue3
12
+ import 'print-center/style.css'
13
+ import PrintCenter from 'print-center'
14
+ app.use(PrintCenter)
15
+ ```
16
+
17
+ ```js
18
+ // vue2
19
+ import PrintCenter from 'print-center-vue2'
20
+ app.use(PrintCenter)
21
+ ```
22
+
23
+ 3. vite.config.js配置(vue3)
24
+
25
+ 最新版本vue不支持运行时编译。需要将bundler配置为别名“vue”为“vue/dist/vue.esm-bundler.js”。
26
+
27
+ ```js
28
+ // vite.config.js
29
+ import { defineConfig } from 'vite'
30
+ import vue from '@vitejs/plugin-vue'
31
+
32
+ // https://vitejs.dev/config/
33
+ export default defineConfig({
34
+ plugins: [vue()],
35
+ resolve: {
36
+ alias: {
37
+ vue: 'vue/dist/vue.esm-bundler.js'
38
+ }
39
+ },
40
+ ...
41
+ })
42
+ ```
43
+
44
+ 4. 使用案例
45
+ src\components\Print\index.vue
46
+
47
+ ```vue
48
+ <!-- 浏览器打印--预览界面(组件化) -->
49
+ <template>
50
+ <PrintCenter ref="previewRef" :previewConfig="previewConfig"></PrintCenter>
51
+ </template>
52
+ <script>
53
+ export default {
54
+ props: {
55
+ templateConfig: Object // 模板配置数据
56
+ },
57
+ data() {
58
+ return {
59
+ // 预览配置数据
60
+ previewConfig: {
61
+ exportPdf: false, // 是否使用导出pdf功能(默认false)
62
+ exportImg: false, // 是否使用导出图片功能(默认false)
63
+ close: false, // 是否可关闭预览界面
64
+ // 模板配置数据来源 interface:接口获取 json:json导入
65
+ dataSources: 'interface',
66
+ // 模板id (dataSources==interface)时使用
67
+ templateId: '',
68
+ // 接口请求路径 (dataSources==interface)时使用
69
+ interfaceUrl: 'http://localhost:9001/print/details',
70
+ // 模板配置数据 (dataSources==json)时使用
71
+ templateConfig: {},
72
+ // 预览标题
73
+ title: '',
74
+ // 页面参数
75
+ pageParams: {
76
+ key2: ` [{"rqCode": "我是页面参数" }]`
77
+ }
78
+ }
79
+ }
80
+ },
81
+ mounted() {},
82
+ methods: {
83
+ // 打印预览
84
+ preview({ templateConfig, pageParams, templateId }) {
85
+ this.init({ templateConfig, pageParams, templateId })
86
+ this.$refs['previewRef'].init()
87
+ },
88
+ // 打印
89
+ print({ templateConfig, pageParams, templateId }) {
90
+ this.init({ templateConfig, pageParams, templateId })
91
+ this.$refs['previewRef'].initPrint()
92
+ },
93
+ // 初始化
94
+ init({ templateConfig, pageParams, templateId }) {
95
+ this.previewConfig.dataSources = templateId ? 'interface' : 'json'
96
+ if (templateId) {
97
+ this.previewConfig.templateId = templateId
98
+ } else {
99
+ this.previewConfig.templateConfig = templateConfig
100
+ }
101
+ this.previewConfig.pageParams = pageParams
102
+ }
103
+ }
104
+ }
105
+ </script>
106
+ ```
107
+
108
+ ### 预览界面导出图片、pdf功能使用
109
+
110
+ 1. main.js中引入导出插件
111
+ **vue3+vite**
112
+
113
+ ```js
114
+ // 打印中心导出pdf、图片
115
+ import html2canvas from 'print-center/js/html2canvas/html2canvas.min.js'
116
+ app.config.globalProperties.html2canvas = html2canvas
117
+ import jspdf from 'print-center/js/jspdf/jspdf.umd.min.js'
118
+ app.config.globalProperties.jspdf = jspdf
119
+ ```
120
+
121
+ **vue2+webpack**
122
+
123
+ ```js
124
+ // 打印中心导出pdf、图片
125
+ import html2canvas from 'print-center-vue2/js/html2canvas/html2canvas.min.js'
126
+ Vue.prototype.html2canvas = jspdhtml2canvasf
127
+ import jspdf from 'print-center-vue2/js/jspdf/jspdf.umd.min.js'
128
+ Vue.prototype.jspdf = jspdf
129
+ ```
130
+
131
+ 2. 配置数据中使用导出功能
132
+
133
+ ```js
134
+ ...
135
+ // 预览配置数据
136
+ previewConfig: {
137
+ exportPdf: true, // 是否使用导出pdf功能(默认false)
138
+ exportImg: true, // 是否使用导出图片功能(默认false)
139
+ ...
140
+ }
141
+ ...
142
+ ```
143
+
144
+ ### v1.0.0(vue3)
145
+
146
+ 1. 初始化打印中心项目,npm部署。
147
+ 2. 包含文本、表格、描述列表、栅格四个组件。
148
+
149
+ ### v1.1.0(vue3)
150
+
151
+ 1. 当前版本基础功能已基本完善,后续会继续优化功能,欢迎大家提建议。
152
+
153
+ ### v1.1.2(vue3)
154
+
155
+ 1. 预览界面多模版切换标题显示bug修改。
156
+ 2. 文档补全。
157
+
158
+ ### v1.1.3(vue2,vue3)
159
+
160
+ 1. 自定义组件bug修复。
161
+ 2. vue2版本兼容处理。