yh-hiprint 2.2.7 → 2.2.9
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 +6 -2
- package/hiprintPreview.vue +32 -28
- package/package.json +1 -1
package/HiprintDesigner.vue
CHANGED
|
@@ -222,7 +222,7 @@
|
|
|
222
222
|
label-position="top"
|
|
223
223
|
size="small">
|
|
224
224
|
<el-form-item label="表数据选择">
|
|
225
|
-
<template v-if="
|
|
225
|
+
<template v-if="hasDataSource">
|
|
226
226
|
<el-select
|
|
227
227
|
v-model="listCode"
|
|
228
228
|
@change="tableFieldChange">
|
|
@@ -243,7 +243,7 @@
|
|
|
243
243
|
:span="12"
|
|
244
244
|
v-for="col in currentElementObjColumns">
|
|
245
245
|
<el-form-item :label="col.title">
|
|
246
|
-
<template v-if="
|
|
246
|
+
<template v-if="hasDataSource">
|
|
247
247
|
<el-select v-model="col.field">
|
|
248
248
|
<el-option
|
|
249
249
|
v-for="d in listColumns"
|
|
@@ -601,6 +601,10 @@ async function updateTemplate(code) {
|
|
|
601
601
|
}
|
|
602
602
|
updateing = false;
|
|
603
603
|
}
|
|
604
|
+
|
|
605
|
+
const hasDataSource = computed(() => {
|
|
606
|
+
return Array.isArray(formCode.value) ? formCode.value.length > 0 : formCode.value;
|
|
607
|
+
});
|
|
604
608
|
onActivated(() => {
|
|
605
609
|
updateTemplate(route.query.code);
|
|
606
610
|
});
|
package/hiprintPreview.vue
CHANGED
|
@@ -11,28 +11,32 @@
|
|
|
11
11
|
sub-title="请求参数或者返回数据错误"></el-result>
|
|
12
12
|
</template>
|
|
13
13
|
<script setup>
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import axios from
|
|
18
|
-
import {
|
|
14
|
+
import {ElLoading, ElResult, ElMessageBox} from 'element-plus';
|
|
15
|
+
import {onMounted, ref} from 'vue';
|
|
16
|
+
import {useRoute} from 'vue-router';
|
|
17
|
+
import axios from '@/libs/api.request.js';
|
|
18
|
+
import {hiprint} from 'yh-hiprint';
|
|
19
19
|
|
|
20
|
-
function getQuery(){
|
|
21
|
-
let query = {}
|
|
20
|
+
function getQuery() {
|
|
21
|
+
let query = {};
|
|
22
22
|
try {
|
|
23
|
-
decodeURIComponent(location.hash)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
decodeURIComponent(location.hash)
|
|
24
|
+
.split('?')[1]
|
|
25
|
+
.split('&')
|
|
26
|
+
.forEach((str) => {
|
|
27
|
+
let index = str.indexOf('=');
|
|
28
|
+
let key = str.substring(0, index);
|
|
29
|
+
let value = str.substring(index + 1);
|
|
30
|
+
query[key] = value;
|
|
31
|
+
});
|
|
27
32
|
} catch (error) {
|
|
28
|
-
console.error(
|
|
33
|
+
console.error('hiprint Preview getQuery on error:', error);
|
|
29
34
|
}
|
|
30
|
-
return query
|
|
35
|
+
return query;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
onMounted(() => {
|
|
34
39
|
let query = getQuery();
|
|
35
|
-
debugger;
|
|
36
40
|
if (query.code) {
|
|
37
41
|
sessionStorage.printQuery = JSON.stringify(query);
|
|
38
42
|
getData(query);
|
|
@@ -45,7 +49,7 @@ onMounted(() => {
|
|
|
45
49
|
error.value = true;
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
|
-
window.addEventListener(
|
|
52
|
+
window.addEventListener('afterprint', () => {
|
|
49
53
|
self.close();
|
|
50
54
|
});
|
|
51
55
|
});
|
|
@@ -55,24 +59,24 @@ const success = ref(false);
|
|
|
55
59
|
const error = ref(false);
|
|
56
60
|
|
|
57
61
|
let loading = ElLoading.service({
|
|
58
|
-
text:
|
|
62
|
+
text: '正在加载数据……',
|
|
59
63
|
});
|
|
60
64
|
|
|
61
65
|
function getData(query) {
|
|
62
|
-
let {
|
|
63
|
-
loading.setText(
|
|
66
|
+
let {code, params, data, isCustom} = query;
|
|
67
|
+
loading.setText('获取打印配置和数据');
|
|
64
68
|
let reqParams = params ? JSON.parse(params) : [];
|
|
65
69
|
|
|
66
70
|
axios
|
|
67
71
|
.request({
|
|
68
72
|
url: `/printTemplate/data/${code}`,
|
|
69
|
-
method:
|
|
70
|
-
type:
|
|
73
|
+
method: 'post',
|
|
74
|
+
type: 'json',
|
|
71
75
|
data: reqParams,
|
|
72
76
|
})
|
|
73
77
|
.then(async (res) => {
|
|
74
|
-
loading.setText(
|
|
75
|
-
let {
|
|
78
|
+
loading.setText('格式化数据,初始化打印插件');
|
|
79
|
+
let {list, json} = res.data;
|
|
76
80
|
if (json) {
|
|
77
81
|
let hasData = false;
|
|
78
82
|
if (Array.isArray(list) && list.length > 0) {
|
|
@@ -98,11 +102,11 @@ function getData(query) {
|
|
|
98
102
|
} else {
|
|
99
103
|
list = [];
|
|
100
104
|
}
|
|
101
|
-
let hiprintTemplate = new hiprint.PrintTemplate({
|
|
105
|
+
let hiprintTemplate = new hiprint.PrintTemplate({template: JSON.parse(json)});
|
|
102
106
|
// 如若有本地数据,那么将本地数据替换远端数据。传入预览中。
|
|
103
|
-
if (isCustom ===
|
|
104
|
-
await ElMessageBox.prompt(
|
|
105
|
-
inputType:
|
|
107
|
+
if (isCustom === '1') {
|
|
108
|
+
await ElMessageBox.prompt('在下面输入框中输入您给的自定义数据', '自定义数据', {
|
|
109
|
+
inputType: 'textarea',
|
|
106
110
|
inputValue: localStorage.hiprintCustomValue || null,
|
|
107
111
|
}).then((e) => {
|
|
108
112
|
try {
|
|
@@ -129,14 +133,14 @@ function getData(query) {
|
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
let html = hiprintTemplate.getHtml(list);
|
|
132
|
-
document.body.innerHTML =
|
|
136
|
+
document.body.innerHTML = '';
|
|
133
137
|
document.body.appendChild(html[0]);
|
|
134
138
|
if (hasData) {
|
|
135
139
|
setTimeout(() => {
|
|
136
140
|
window.print();
|
|
137
141
|
}, 1000);
|
|
138
142
|
} else {
|
|
139
|
-
ElMessageBox.alert(
|
|
143
|
+
ElMessageBox.alert('数据源没有数据,打印将取消').then(() => {
|
|
140
144
|
window.close();
|
|
141
145
|
});
|
|
142
146
|
}
|