yh-hiprint 2.5.1 → 2.5.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/HiprintDesigner.vue +1 -0
- package/README.md +1 -1
- package/hiprintPreview.vue +80 -70
- package/hooks/useHiprint.js +40 -41
- package/index.d.ts +313 -3
- package/index.js +74 -11
- package/libs/es62es5.js +42 -0
- package/libs/etypes/default-etyps-provider.js +69 -69
- package/libs/hiprint.bundle.js +1744 -1758
- package/libs/index.js +13 -0
- package/package.json +13 -3
package/HiprintDesigner.vue
CHANGED
package/README.md
CHANGED
package/hiprintPreview.vue
CHANGED
|
@@ -16,6 +16,7 @@ import {onMounted, ref} from 'vue';
|
|
|
16
16
|
import {useRoute} from 'vue-router';
|
|
17
17
|
import axios from '@/libs/api.request.js';
|
|
18
18
|
import {hiprint} from 'yh-hiprint';
|
|
19
|
+
import {getPrintTemplate} from 'yh-hiprint/libs/index.js';
|
|
19
20
|
|
|
20
21
|
function getQuery() {
|
|
21
22
|
let query = {};
|
|
@@ -27,6 +28,14 @@ function getQuery() {
|
|
|
27
28
|
let index = str.indexOf('=');
|
|
28
29
|
let key = str.substring(0, index);
|
|
29
30
|
let value = decodeURIComponent(str.substring(index + 1));
|
|
31
|
+
switch (key) {
|
|
32
|
+
case 'returnHtml':
|
|
33
|
+
value = value === '1';
|
|
34
|
+
break;
|
|
35
|
+
case 'isCustom':
|
|
36
|
+
value = value === '1';
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
30
39
|
query[key] = value;
|
|
31
40
|
});
|
|
32
41
|
} catch (error) {
|
|
@@ -62,77 +71,79 @@ let loading = ElLoading.service({
|
|
|
62
71
|
text: '正在加载数据……',
|
|
63
72
|
});
|
|
64
73
|
|
|
65
|
-
function getData(query) {
|
|
66
|
-
let {code, params, data, isCustom} = query;
|
|
74
|
+
async function getData(query) {
|
|
75
|
+
let {code, params, data, isCustom, returnHtml} = query;
|
|
67
76
|
loading.setText('获取打印配置和数据');
|
|
68
77
|
let reqParams = params ? JSON.parse(params) : [];
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
let datas = Object.entries(item);
|
|
86
|
-
datas.forEach((arr) => {
|
|
87
|
-
if (Array.isArray(arr[1])) {
|
|
88
|
-
hasData = arr[1].length > 0;
|
|
89
|
-
printData[arr[0]] = arr[1];
|
|
90
|
-
} else {
|
|
91
|
-
if (arr[1] !== null) {
|
|
92
|
-
hasData = true;
|
|
93
|
-
let itemsEntries = Object.entries(arr[1]);
|
|
94
|
-
itemsEntries.forEach((cArr) => {
|
|
95
|
-
printData[`$${arr[0]}[${cArr[0]}]`] = cArr[1];
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return printData;
|
|
101
|
-
});
|
|
102
|
-
} else {
|
|
103
|
-
list = [];
|
|
104
|
-
}
|
|
105
|
-
let hiprintTemplate = new hiprint.PrintTemplate({template: JSON.parse(json)});
|
|
106
|
-
// 如若有本地数据,那么将本地数据替换远端数据。传入预览中。
|
|
107
|
-
if (isCustom === '1') {
|
|
108
|
-
await ElMessageBox.prompt('在下面输入框中输入您给的自定义数据', '自定义数据', {
|
|
109
|
-
inputType: 'textarea',
|
|
110
|
-
inputValue: localStorage.hiprintCustomValue || null,
|
|
111
|
-
}).then((e) => {
|
|
112
|
-
try {
|
|
113
|
-
hasData = true;
|
|
114
|
-
localStorage.hiprintCustomValue = e.value;
|
|
115
|
-
list = JSON.parse(e.value);
|
|
116
|
-
} catch (error) {
|
|
117
|
-
try {
|
|
78
|
+
try {
|
|
79
|
+
let res = await getPrintTemplate(code, reqParams);
|
|
80
|
+
loading.setText('格式化数据,初始化打印插件');
|
|
81
|
+
let {list, json} = res.data;
|
|
82
|
+
if (json) {
|
|
83
|
+
let hasData = false;
|
|
84
|
+
if (Array.isArray(list) && list.length > 0) {
|
|
85
|
+
list = list.map((item, index) => {
|
|
86
|
+
let printData = {};
|
|
87
|
+
let datas = Object.entries(item);
|
|
88
|
+
datas.forEach((arr) => {
|
|
89
|
+
if (Array.isArray(arr[1])) {
|
|
90
|
+
hasData = arr[1].length > 0;
|
|
91
|
+
printData[arr[0]] = arr[1];
|
|
92
|
+
} else {
|
|
93
|
+
if (arr[1] !== null) {
|
|
118
94
|
hasData = true;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
95
|
+
let itemsEntries = Object.entries(arr[1]);
|
|
96
|
+
itemsEntries.forEach((cArr) => {
|
|
97
|
+
printData[`$${arr[0]}[${cArr[0]}]`] = cArr[1];
|
|
98
|
+
});
|
|
123
99
|
}
|
|
124
100
|
}
|
|
125
101
|
});
|
|
126
|
-
|
|
102
|
+
return printData;
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
list = [];
|
|
106
|
+
}
|
|
107
|
+
let hiprintTemplate = new hiprint.PrintTemplate({template: JSON.parse(json)});
|
|
108
|
+
// 如若有本地数据,那么将本地数据替换远端数据。传入预览中。
|
|
109
|
+
if (isCustom === '1') {
|
|
110
|
+
await ElMessageBox.prompt('在下面输入框中输入您给的自定义数据', '自定义数据', {
|
|
111
|
+
inputType: 'textarea',
|
|
112
|
+
inputValue: localStorage.hiprintCustomValue || null,
|
|
113
|
+
}).then((e) => {
|
|
127
114
|
try {
|
|
128
115
|
hasData = true;
|
|
129
|
-
|
|
116
|
+
localStorage.hiprintCustomValue = e.value;
|
|
117
|
+
list = JSON.parse(e.value);
|
|
130
118
|
} catch (error) {
|
|
131
|
-
|
|
132
|
-
|
|
119
|
+
try {
|
|
120
|
+
hasData = true;
|
|
121
|
+
list = JSON.parse(data);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
hasData = false;
|
|
124
|
+
list = [];
|
|
125
|
+
}
|
|
133
126
|
}
|
|
127
|
+
});
|
|
128
|
+
} else if (data) {
|
|
129
|
+
try {
|
|
130
|
+
hasData = true;
|
|
131
|
+
list = JSON.parse(data);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
hasData = false;
|
|
134
|
+
list = [];
|
|
134
135
|
}
|
|
135
|
-
|
|
136
|
+
}
|
|
137
|
+
let html = hiprintTemplate.getHtml(list);
|
|
138
|
+
if (opener && returnHtml && html[0]) {
|
|
139
|
+
opener.postMessage({
|
|
140
|
+
type: 'sendPrintHTML',
|
|
141
|
+
data: html[0].innerHTML,
|
|
142
|
+
});
|
|
143
|
+
ElMessageBox.alert('渲染完成!确认后返回系统').then(() => {
|
|
144
|
+
window.close();
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
136
147
|
document.body.innerHTML = '';
|
|
137
148
|
document.body.appendChild(html[0]);
|
|
138
149
|
if (hasData) {
|
|
@@ -144,18 +155,17 @@ function getData(query) {
|
|
|
144
155
|
window.close();
|
|
145
156
|
});
|
|
146
157
|
}
|
|
147
|
-
success.value = false;
|
|
148
|
-
} else {
|
|
149
|
-
error.value = true;
|
|
150
158
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
console.error(err);
|
|
159
|
+
success.value = false;
|
|
160
|
+
} else {
|
|
154
161
|
error.value = true;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
}
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error(error);
|
|
165
|
+
error.value = true;
|
|
166
|
+
} finally {
|
|
167
|
+
loading.close();
|
|
168
|
+
}
|
|
159
169
|
}
|
|
160
170
|
</script>
|
|
161
171
|
<style lang="scss"></style>
|
package/hooks/useHiprint.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {hiprint as h, defaultElementTypeProvider as p} from '../libs/hiprint.bundle.js';
|
|
2
2
|
// 调用浏览器打印js
|
|
3
|
-
import
|
|
3
|
+
import '../libs/plugins/jquery.hiwprint.js';
|
|
4
4
|
// 默认配置
|
|
5
|
-
import
|
|
5
|
+
import '../libs/hiprint.config.js';
|
|
6
6
|
// 样式
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { ref, computed, watch, reactive, nextTick } from "vue";
|
|
7
|
+
import '../libs/css/hiprint.css';
|
|
8
|
+
import {ref, computed, watch, reactive, nextTick} from 'vue';
|
|
10
9
|
|
|
11
10
|
export const hiprint = h;
|
|
12
11
|
export const defaultElementTypeProvider = p;
|
|
13
12
|
|
|
14
|
-
export function print
|
|
13
|
+
export function print(provider = defaultElementTypeProvider, template, ...args) {
|
|
15
14
|
hiprint.init({
|
|
16
15
|
providers: [new provider()],
|
|
17
16
|
});
|
|
@@ -22,7 +21,7 @@ export function print (provider = defaultElementTypeProvider, template, ...args)
|
|
|
22
21
|
return hiprintTemplate;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
export function print2
|
|
24
|
+
export function print2(provider = defaultElementTypeProvider, template, ...args) {
|
|
26
25
|
hiprint.init({
|
|
27
26
|
providers: [new provider()],
|
|
28
27
|
});
|
|
@@ -33,26 +32,26 @@ export function print2 (provider = defaultElementTypeProvider, template, ...args
|
|
|
33
32
|
return hiprintTemplate;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
export function usePaper
|
|
37
|
-
const paperType = ref(
|
|
35
|
+
export function usePaper() {
|
|
36
|
+
const paperType = ref('A4');
|
|
38
37
|
const paperTypeName = computed(() => {
|
|
39
38
|
const paperTypeObj = paperTypesObj.find((item) => item.value === paperType.value);
|
|
40
39
|
if (paperTypeObj) {
|
|
41
40
|
return paperTypeObj.label;
|
|
42
41
|
} else {
|
|
43
|
-
return
|
|
42
|
+
return '自定义';
|
|
44
43
|
}
|
|
45
44
|
});
|
|
46
45
|
const paperWidth = ref(210);
|
|
47
46
|
const paperHeight = ref(296.6);
|
|
48
47
|
|
|
49
48
|
const paperTypesObj = reactive([
|
|
50
|
-
{
|
|
51
|
-
{
|
|
52
|
-
{
|
|
53
|
-
{
|
|
54
|
-
{
|
|
55
|
-
{
|
|
49
|
+
{label: 'A3', value: 'A3'},
|
|
50
|
+
{label: 'A4', value: 'A4'},
|
|
51
|
+
{label: 'A5', value: 'A5'},
|
|
52
|
+
{label: 'B3', value: 'B3'},
|
|
53
|
+
{label: 'B4', value: 'B4'},
|
|
54
|
+
{label: 'B5', value: 'B5'},
|
|
56
55
|
]);
|
|
57
56
|
|
|
58
57
|
const paperTypes = {
|
|
@@ -82,9 +81,9 @@ export function usePaper () {
|
|
|
82
81
|
},
|
|
83
82
|
};
|
|
84
83
|
|
|
85
|
-
function setPaper
|
|
86
|
-
if (type !==
|
|
87
|
-
let {
|
|
84
|
+
function setPaper(type, callback) {
|
|
85
|
+
if (type !== 'other') {
|
|
86
|
+
let {width, height} = paperTypes[type];
|
|
88
87
|
paperWidth.value = width;
|
|
89
88
|
paperHeight.value = height;
|
|
90
89
|
}
|
|
@@ -94,19 +93,19 @@ export function usePaper () {
|
|
|
94
93
|
watch([paperWidth, paperHeight], ([width, height], [oldW, oldH]) => {
|
|
95
94
|
nextTick(() => {
|
|
96
95
|
if (width === 420 && height === 297) {
|
|
97
|
-
paperType.value =
|
|
96
|
+
paperType.value = 'A3';
|
|
98
97
|
} else if (width === 210 && height === 297) {
|
|
99
|
-
paperType.value =
|
|
98
|
+
paperType.value = 'A4';
|
|
100
99
|
} else if (width === 210 && height === 148) {
|
|
101
|
-
paperType.value =
|
|
100
|
+
paperType.value = 'A5';
|
|
102
101
|
} else if (width === 500 && height === 353) {
|
|
103
|
-
paperType.value =
|
|
102
|
+
paperType.value = 'B3';
|
|
104
103
|
} else if (width === 250 && height === 353) {
|
|
105
|
-
paperType.value =
|
|
104
|
+
paperType.value = 'B4';
|
|
106
105
|
} else if (width === 250 && height === 176) {
|
|
107
|
-
paperType.value =
|
|
106
|
+
paperType.value = 'B5';
|
|
108
107
|
} else {
|
|
109
|
-
paperType.value =
|
|
108
|
+
paperType.value = 'other';
|
|
110
109
|
}
|
|
111
110
|
});
|
|
112
111
|
});
|
|
@@ -121,7 +120,7 @@ export function usePaper () {
|
|
|
121
120
|
};
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
export function useScale
|
|
123
|
+
export function useScale(callback) {
|
|
125
124
|
const scaleValue = ref(1);
|
|
126
125
|
const scalePercentage = computed(() => {
|
|
127
126
|
return `${(scaleValue.value * 100).toFixed(0)}%`;
|
|
@@ -132,11 +131,11 @@ export function useScale (callback) {
|
|
|
132
131
|
const canZoomOut = computed(() => {
|
|
133
132
|
return scaleValue.value < 4;
|
|
134
133
|
});
|
|
135
|
-
function zoomIn
|
|
134
|
+
function zoomIn() {
|
|
136
135
|
scaleValue.value = scaleValue.value - 0.1;
|
|
137
136
|
callback();
|
|
138
137
|
}
|
|
139
|
-
function zoomOut
|
|
138
|
+
function zoomOut() {
|
|
140
139
|
scaleValue.value = scaleValue.value + 0.1;
|
|
141
140
|
callback();
|
|
142
141
|
}
|
|
@@ -150,22 +149,22 @@ export function useScale (callback) {
|
|
|
150
149
|
};
|
|
151
150
|
}
|
|
152
151
|
|
|
153
|
-
export function useDataSource
|
|
152
|
+
export function useDataSource(axios) {
|
|
154
153
|
const detailData = ref();
|
|
155
|
-
function getDetail
|
|
154
|
+
function getDetail(id) {
|
|
156
155
|
return axios
|
|
157
156
|
.request({
|
|
158
157
|
url: `/printTemplate/get/${id}`,
|
|
159
|
-
method:
|
|
158
|
+
method: 'post',
|
|
160
159
|
})
|
|
161
160
|
.then((res) => {
|
|
162
161
|
if (res.data.data && res.data.data.sourceCodes) {
|
|
163
|
-
let codes = res.data.data.sourceCodes.split(
|
|
162
|
+
let codes = res.data.data.sourceCodes.split(',');
|
|
164
163
|
let formListCode = dataSourceForm.value.map((item) => item.value);
|
|
165
164
|
codes = codes.filter((item) => formListCode.includes(item));
|
|
166
165
|
formCode.value = codes;
|
|
167
166
|
} else {
|
|
168
|
-
formCode.value =
|
|
167
|
+
formCode.value = '';
|
|
169
168
|
}
|
|
170
169
|
detailData.value = res.data.data;
|
|
171
170
|
return Promise.resolve(res.data.data);
|
|
@@ -175,7 +174,7 @@ export function useDataSource (axios) {
|
|
|
175
174
|
const dataSourceList = ref([]);
|
|
176
175
|
const listColumns = computed(() => {
|
|
177
176
|
return codeMapDataSource.value[listCode.value].map((item) => {
|
|
178
|
-
let index = item.indexOf(
|
|
177
|
+
let index = item.indexOf('[');
|
|
179
178
|
return item.substring(index + 1, item.length - 1);
|
|
180
179
|
});
|
|
181
180
|
});
|
|
@@ -192,18 +191,18 @@ export function useDataSource (axios) {
|
|
|
192
191
|
});
|
|
193
192
|
const dataSourceForm = ref([]);
|
|
194
193
|
const codeMapDataSource = ref({});
|
|
195
|
-
function getDataSourceList
|
|
194
|
+
function getDataSourceList() {
|
|
196
195
|
return axios
|
|
197
196
|
.request({
|
|
198
|
-
url:
|
|
199
|
-
method:
|
|
197
|
+
url: '/printTemplate/getDsList',
|
|
198
|
+
method: 'post',
|
|
200
199
|
})
|
|
201
200
|
.then((res) => {
|
|
202
201
|
res.data.list.forEach((item) => {
|
|
203
202
|
if (item.columns) {
|
|
204
|
-
codeMapDataSource.value[item.code] = item?.columns?.split(
|
|
203
|
+
codeMapDataSource.value[item.code] = item?.columns?.split(',')?.map((col) => `$${item.code}[${col.toUpperCase()}]`) || [];
|
|
205
204
|
}
|
|
206
|
-
if (item.type ===
|
|
205
|
+
if (item.type === 'LIST') {
|
|
207
206
|
dataSourceList.value.push({
|
|
208
207
|
label: item.name,
|
|
209
208
|
value: item.code,
|