yh-hiprint 2.5.3 → 3.0.0
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/HiprintDesigner.vue +21 -197
- package/config.json +399 -0
- package/doc.md +265 -0
- package/hooks/useHipirntCanvas.ts +3 -0
- package/hooks/{useHiprint.js → useHiprint.ts} +92 -41
- package/{index.js → index.ts} +67 -21
- package/libs/hiprint.bundle.js +1 -2
- package/libs/previewHiprint.ts +55 -0
- package/package.json +3 -13
- package/store/defaultPrintElement.ts +152 -0
- package/store/useHiprintStore.ts +75 -0
- package/types.ts +756 -0
- package/index.d.ts +0 -377
package/libs/hiprint.bundle.js
CHANGED
|
@@ -2291,7 +2291,6 @@ var hiprint = (function (t) {
|
|
|
2291
2291
|
useSVG: !0,
|
|
2292
2292
|
correctLevel: t.tableQRCodeLevel || 0,
|
|
2293
2293
|
typeNumber,
|
|
2294
|
-
mode: 4,
|
|
2295
2294
|
}).makeCode(p);
|
|
2296
2295
|
r.html(qrcodebox);
|
|
2297
2296
|
}
|
|
@@ -10188,7 +10187,7 @@ var hiprint = (function (t) {
|
|
|
10188
10187
|
QRCode({
|
|
10189
10188
|
level: this.options.getQRcodeLevel(),
|
|
10190
10189
|
fnc1: 'None',
|
|
10191
|
-
mode:
|
|
10190
|
+
mode: 'Auto',
|
|
10192
10191
|
moduleSize: 8,
|
|
10193
10192
|
quietZone: 0,
|
|
10194
10193
|
aimIndicator: 0,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import axios from '@/libs/api.request';
|
|
3
|
+
import {ElMessage, ElMessageBox} from 'element-plus';
|
|
4
|
+
import {hiprint} from 'yh-hiprint';
|
|
5
|
+
|
|
6
|
+
export default async function (code) {
|
|
7
|
+
let {
|
|
8
|
+
data: {list, json},
|
|
9
|
+
} = await axios.request({
|
|
10
|
+
url: `/printTemplate/data/${code}`,
|
|
11
|
+
method: 'post',
|
|
12
|
+
type: 'json',
|
|
13
|
+
data: [
|
|
14
|
+
{
|
|
15
|
+
code: '50101820',
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
if (json) {
|
|
20
|
+
if (Array.isArray(list) && list.length > 0) {
|
|
21
|
+
list = list.map((item) => {
|
|
22
|
+
let printData = {};
|
|
23
|
+
let datas = Object.entries(item);
|
|
24
|
+
datas.forEach((arr) => {
|
|
25
|
+
if (Array.isArray(arr[1])) {
|
|
26
|
+
printData[arr[0]] = arr[1];
|
|
27
|
+
} else {
|
|
28
|
+
if (arr[1] !== null && arr[1] !== undefined) {
|
|
29
|
+
let itemsEntries = Object.entries(arr[1]);
|
|
30
|
+
itemsEntries.forEach((cArr) => {
|
|
31
|
+
printData[`$${arr[0]}[${cArr[0]}]`] = cArr[1];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return printData;
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
list = [];
|
|
40
|
+
}
|
|
41
|
+
const htmlStr = new hiprint.PrintTemplate({template: JSON.parse(json)}).getHtml(list)[0].innerHTML;
|
|
42
|
+
ElMessageBox.alert(htmlStr, '打印预览', {
|
|
43
|
+
customClass: 'print-preview-dialog',
|
|
44
|
+
dangerouslyUseHTMLString: true,
|
|
45
|
+
closeOnClickModal: true,
|
|
46
|
+
closeOnPressEscape: true,
|
|
47
|
+
closeOnHashChange: true,
|
|
48
|
+
showConfirmButton: false,
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
ElMessage.warning({
|
|
52
|
+
message: '模板配置不存在,请检查',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yh-hiprint",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Hiprint for Vue3
|
|
5
|
-
"main": "index.
|
|
6
|
-
"types": "index.d.ts",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "Hiprint for Vue3",
|
|
5
|
+
"main": "index.ts",
|
|
7
6
|
"scripts": {
|
|
8
7
|
"start": "npm run pub:aliyun && npm run pub:npm",
|
|
9
8
|
"pub:aliyun": "npm publish --registry https://packages.aliyun.com/60765e0161a945067837bb5f/npm/npm-registry/ --no-git-checks",
|
|
10
9
|
"pub:npm": "npm publish --registry https://registry.npmjs.org/ --no-git-checks"
|
|
11
10
|
},
|
|
12
11
|
"dependencies": {
|
|
13
|
-
"@babel/core": "7.28.4",
|
|
14
|
-
"@babel/generator": "7.28.3",
|
|
15
|
-
"@babel/parser": "7.28.4",
|
|
16
|
-
"@babel/plugin-transform-arrow-functions": "^7.27.1",
|
|
17
|
-
"@babel/plugin-transform-block-scoping": "^7.28.4",
|
|
18
|
-
"@babel/plugin-transform-computed-properties": "^7.27.1",
|
|
19
|
-
"@babel/plugin-transform-shorthand-properties": "^7.27.1",
|
|
20
|
-
"@babel/plugin-transform-template-literals": "^7.27.1",
|
|
21
|
-
"@babel/traverse": "7.28.4",
|
|
22
12
|
"@nuintun/qrcode": "^5.0.1",
|
|
23
13
|
"canvg": "4.0.1",
|
|
24
14
|
"html2canvas": "1.4.1",
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {HlinePrintElementType, ImagePrintElementType, PrintElementTypes, TextPrintElementType, VlinePrintElementType, RectPrintElementType, OvalPrintElementType, TablePrintElementType, LongTextPrintElementType, BarcodePrintElementType, QRCodePrintElementType, HTMLPrintElementType} from '../types';
|
|
2
|
+
|
|
3
|
+
export const defaultTextElement: TextPrintElementType = {
|
|
4
|
+
printElementType: {
|
|
5
|
+
title: '文本',
|
|
6
|
+
type: PrintElementTypes.TEXT,
|
|
7
|
+
},
|
|
8
|
+
options: {
|
|
9
|
+
textType: 'text',
|
|
10
|
+
title: '文本',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const defaultTextValElement: TextPrintElementType = {
|
|
15
|
+
printElementType: {
|
|
16
|
+
title: '值(文本)',
|
|
17
|
+
type: PrintElementTypes.TEXT,
|
|
18
|
+
},
|
|
19
|
+
options: {
|
|
20
|
+
textType: 'text',
|
|
21
|
+
title: '值(文本)',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const defaultImageElement: ImagePrintElementType = {
|
|
26
|
+
printElementType: {
|
|
27
|
+
title: '图片',
|
|
28
|
+
type: PrintElementTypes.IMAGE,
|
|
29
|
+
},
|
|
30
|
+
options: {
|
|
31
|
+
title: '图片',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const defaultHlineElement: HlinePrintElementType = {
|
|
36
|
+
printElementType: {
|
|
37
|
+
title: '横线',
|
|
38
|
+
type: PrintElementTypes.HLINE,
|
|
39
|
+
},
|
|
40
|
+
options: {
|
|
41
|
+
title: '横线',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const defaultVlineElement: VlinePrintElementType = {
|
|
46
|
+
printElementType: {
|
|
47
|
+
title: '竖线',
|
|
48
|
+
type: PrintElementTypes.VLINE,
|
|
49
|
+
},
|
|
50
|
+
options: {
|
|
51
|
+
title: '竖线',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const defaultReactElement: RectPrintElementType = {
|
|
56
|
+
printElementType: {
|
|
57
|
+
title: '矩形',
|
|
58
|
+
type: PrintElementTypes.RECT,
|
|
59
|
+
},
|
|
60
|
+
options: {
|
|
61
|
+
title: '矩形',
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const defaultOvalElement: OvalPrintElementType = {
|
|
66
|
+
printElementType: {
|
|
67
|
+
title: '圆形',
|
|
68
|
+
type: PrintElementTypes.OVAL,
|
|
69
|
+
},
|
|
70
|
+
options: {
|
|
71
|
+
title: '圆形',
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const defaultTableElement: TablePrintElementType = {
|
|
76
|
+
printElementType: {
|
|
77
|
+
title: '表格',
|
|
78
|
+
type: PrintElementTypes.TABLE,
|
|
79
|
+
columns: [
|
|
80
|
+
[
|
|
81
|
+
{
|
|
82
|
+
title: '列1',
|
|
83
|
+
width: 100,
|
|
84
|
+
rowspan: 1,
|
|
85
|
+
colspan: 1,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
title: '列2',
|
|
89
|
+
width: 100,
|
|
90
|
+
rowspan: 1,
|
|
91
|
+
colspan: 1,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
options: {
|
|
97
|
+
title: '表格',
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const defaultemptyTableElement: TablePrintElementType = {
|
|
102
|
+
printElementType: {
|
|
103
|
+
title: '空白表格',
|
|
104
|
+
type: PrintElementTypes.TABLE,
|
|
105
|
+
columns: [],
|
|
106
|
+
},
|
|
107
|
+
options: {
|
|
108
|
+
title: '空白表格',
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const defaultLongTextElement: LongTextPrintElementType = {
|
|
113
|
+
printElementType: {
|
|
114
|
+
title: '长文本',
|
|
115
|
+
type: PrintElementTypes.LONGTEXT,
|
|
116
|
+
},
|
|
117
|
+
options: {
|
|
118
|
+
title: '长文本',
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const defaultHTMLElement: HTMLPrintElementType = {
|
|
123
|
+
printElementType: {
|
|
124
|
+
title: 'HTML',
|
|
125
|
+
type: PrintElementTypes.HTML,
|
|
126
|
+
},
|
|
127
|
+
options: {
|
|
128
|
+
title: 'HTML',
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const defaultQRCodeElement: QRCodePrintElementType = {
|
|
133
|
+
printElementType: {
|
|
134
|
+
title: '二维码',
|
|
135
|
+
type: PrintElementTypes.TEXT,
|
|
136
|
+
},
|
|
137
|
+
options: {
|
|
138
|
+
title: '二维码',
|
|
139
|
+
textType: 'qrcode',
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const defaultBarcodeElement: BarcodePrintElementType = {
|
|
144
|
+
printElementType: {
|
|
145
|
+
title: '条形码',
|
|
146
|
+
type: PrintElementTypes.TEXT,
|
|
147
|
+
},
|
|
148
|
+
options: {
|
|
149
|
+
title: '条形码',
|
|
150
|
+
textType: 'barcode',
|
|
151
|
+
},
|
|
152
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {computed, ref} from 'vue';
|
|
2
|
+
import {HiprintPrintOption, PrintElementType, PrintElementTypes, PrintPanelOptions, TextPrintElementType} from 'yh-hiprint/types';
|
|
3
|
+
import {defineStore} from 'pinia';
|
|
4
|
+
|
|
5
|
+
export default defineStore('useHiprintStore', () => {
|
|
6
|
+
const printElements = ref<PrintElementType[]>([]);
|
|
7
|
+
const panelOption = ref<PrintPanelOptions>();
|
|
8
|
+
|
|
9
|
+
const activeElements = ref<PrintElementType[]>([]);
|
|
10
|
+
|
|
11
|
+
const activeElement = computed<PrintElementType | null>(() => {
|
|
12
|
+
if (activeElements.value.length && activeElements.value.length === 1) {
|
|
13
|
+
return activeElements.value[0];
|
|
14
|
+
} else {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const panelType = computed<PrintElementTypes>(() => {
|
|
20
|
+
if (activeElement.value === null) {
|
|
21
|
+
return PrintElementTypes.PANEL;
|
|
22
|
+
} else {
|
|
23
|
+
if (activeElement.value.printElementType.type === PrintElementTypes.TEXT) {
|
|
24
|
+
if ((activeElement.value as TextPrintElementType).options.textType === 'qrcode') {
|
|
25
|
+
return PrintElementTypes.QRCODE;
|
|
26
|
+
} else if ((activeElement.value as TextPrintElementType).options.textType === 'barcode') {
|
|
27
|
+
return PrintElementTypes.BARCODE;
|
|
28
|
+
} else {
|
|
29
|
+
return PrintElementTypes.TEXT;
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
switch (activeElement.value.printElementType.type) {
|
|
33
|
+
case PrintElementTypes.IMAGE:
|
|
34
|
+
return PrintElementTypes.IMAGE;
|
|
35
|
+
case PrintElementTypes.TABLE:
|
|
36
|
+
return PrintElementTypes.TABLE;
|
|
37
|
+
case PrintElementTypes.HLINE:
|
|
38
|
+
return PrintElementTypes.HLINE;
|
|
39
|
+
case PrintElementTypes.VLINE:
|
|
40
|
+
return PrintElementTypes.VLINE;
|
|
41
|
+
case PrintElementTypes.RECT:
|
|
42
|
+
return PrintElementTypes.RECT;
|
|
43
|
+
case PrintElementTypes.OVAL:
|
|
44
|
+
return PrintElementTypes.OVAL;
|
|
45
|
+
case PrintElementTypes.LONGTEXT:
|
|
46
|
+
return PrintElementTypes.LONGTEXT;
|
|
47
|
+
case PrintElementTypes.HTML:
|
|
48
|
+
return PrintElementTypes.HTML;
|
|
49
|
+
default:
|
|
50
|
+
return PrintElementTypes.PANEL;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const hiprontPrintOption = computed<string>(() => {
|
|
57
|
+
return JSON.stringify({
|
|
58
|
+
panels: [
|
|
59
|
+
{
|
|
60
|
+
...panelOption.value,
|
|
61
|
+
printElements: printElements.value,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
hiprontPrintOption,
|
|
69
|
+
panelType,
|
|
70
|
+
panelOption,
|
|
71
|
+
printElements,
|
|
72
|
+
activeElement,
|
|
73
|
+
activeElements,
|
|
74
|
+
};
|
|
75
|
+
});
|