yh-hiprint 2.2.9 → 2.2.10

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/hiprint.js CHANGED
@@ -1,35 +1,35 @@
1
- import { createApp } from "vue";
2
- import { createRouter, createWebHashHistory } from "vue-router";
3
- import { setTitle } from "@/libs/util";
4
- import "element-plus/dist/index.css";
5
-
6
- import App from "yh-hiprint/hiprint.vue";
7
- const router = createRouter({
8
- history: createWebHashHistory(),
9
- routes: [
10
- {
11
- path: "/",
12
- redirect: "/preview",
13
- },
14
- {
15
- path: "/preview",
16
- name: "printView",
17
- meta: {
18
- title: "打印",
19
- },
20
- component: () => import("yh-hiprint/hiprintPreview.vue"),
21
- },
22
- ],
23
- });
24
-
25
- router.beforeEach((to, from, next) => {
26
- next();
27
- });
28
-
29
- router.afterEach((to) => {
30
- setTitle(to);
31
- window.scrollTo(0, 0);
32
- });
33
- const app = createApp(App);
34
- app.use(router);
35
- app.mount("#app");
1
+ import { createApp } from "vue";
2
+ import { createRouter, createWebHashHistory } from "vue-router";
3
+ import { setTitle } from "@/libs/util";
4
+ import "element-plus/dist/index.css";
5
+
6
+ import App from "yh-hiprint/hiprint.vue";
7
+ const router = createRouter({
8
+ history: createWebHashHistory(),
9
+ routes: [
10
+ {
11
+ path: "/",
12
+ redirect: "/preview",
13
+ },
14
+ {
15
+ path: "/preview",
16
+ name: "printView",
17
+ meta: {
18
+ title: "打印",
19
+ },
20
+ component: () => import("yh-hiprint/hiprintPreview.vue"),
21
+ },
22
+ ],
23
+ });
24
+
25
+ router.beforeEach((to, from, next) => {
26
+ next();
27
+ });
28
+
29
+ router.afterEach((to) => {
30
+ setTitle(to);
31
+ window.scrollTo(0, 0);
32
+ });
33
+ const app = createApp(App);
34
+ app.use(router);
35
+ app.mount("#app");
package/hiprint.vue CHANGED
@@ -1,13 +1,13 @@
1
- <template>
2
- <router-view></router-view>
3
- </template>
4
- <script setup></script>
5
- <style lang="scss">
6
- html,
7
- body,
8
- #app {
9
- width: 100%;
10
- height: 100%;
11
- margin: 0;
12
- }
13
- </style>
1
+ <template>
2
+ <router-view></router-view>
3
+ </template>
4
+ <script setup></script>
5
+ <style lang="scss">
6
+ html,
7
+ body,
8
+ #app {
9
+ width: 100%;
10
+ height: 100%;
11
+ margin: 0;
12
+ }
13
+ </style>
@@ -1,161 +1,161 @@
1
- <template>
2
- <el-result
3
- v-if="success"
4
- icon="success"
5
- title="成功"
6
- sub-title="已成功调用系统打印"></el-result>
7
- <el-result
8
- v-if="error"
9
- icon="error"
10
- title="错误"
11
- sub-title="请求参数或者返回数据错误"></el-result>
12
- </template>
13
- <script setup>
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
-
20
- function getQuery() {
21
- let query = {};
22
- try {
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
- });
32
- } catch (error) {
33
- console.error('hiprint Preview getQuery on error:', error);
34
- }
35
- return query;
36
- }
37
-
38
- onMounted(() => {
39
- let query = getQuery();
40
- if (query.code) {
41
- sessionStorage.printQuery = JSON.stringify(query);
42
- getData(query);
43
- } else {
44
- if (sessionStorage.printQuery) {
45
- query = JSON.parse(sessionStorage.printQuery);
46
- getData(query);
47
- } else {
48
- loading.close();
49
- error.value = true;
50
- }
51
- }
52
- window.addEventListener('afterprint', () => {
53
- self.close();
54
- });
55
- });
56
-
57
- const route = useRoute();
58
- const success = ref(false);
59
- const error = ref(false);
60
-
61
- let loading = ElLoading.service({
62
- text: '正在加载数据……',
63
- });
64
-
65
- function getData(query) {
66
- let {code, params, data, isCustom} = query;
67
- loading.setText('获取打印配置和数据');
68
- let reqParams = params ? JSON.parse(params) : [];
69
-
70
- axios
71
- .request({
72
- url: `/printTemplate/data/${code}`,
73
- method: 'post',
74
- type: 'json',
75
- data: reqParams,
76
- })
77
- .then(async (res) => {
78
- loading.setText('格式化数据,初始化打印插件');
79
- let {list, json} = res.data;
80
- if (json) {
81
- let hasData = false;
82
- if (Array.isArray(list) && list.length > 0) {
83
- list = list.map((item, index) => {
84
- let printData = {};
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 {
118
- hasData = true;
119
- list = JSON.parse(data);
120
- } catch (error) {
121
- hasData = false;
122
- list = [];
123
- }
124
- }
125
- });
126
- } else if (data) {
127
- try {
128
- hasData = true;
129
- list = JSON.parse(data);
130
- } catch (error) {
131
- hasData = false;
132
- list = [];
133
- }
134
- }
135
- let html = hiprintTemplate.getHtml(list);
136
- document.body.innerHTML = '';
137
- document.body.appendChild(html[0]);
138
- if (hasData) {
139
- setTimeout(() => {
140
- window.print();
141
- }, 1000);
142
- } else {
143
- ElMessageBox.alert('数据源没有数据,打印将取消').then(() => {
144
- window.close();
145
- });
146
- }
147
- success.value = false;
148
- } else {
149
- error.value = true;
150
- }
151
- })
152
- .catch((err) => {
153
- console.error(err);
154
- error.value = true;
155
- })
156
- .finally(() => {
157
- loading.close();
158
- });
159
- }
160
- </script>
161
- <style lang="scss"></style>
1
+ <template>
2
+ <el-result
3
+ v-if="success"
4
+ icon="success"
5
+ title="成功"
6
+ sub-title="已成功调用系统打印"></el-result>
7
+ <el-result
8
+ v-if="error"
9
+ icon="error"
10
+ title="错误"
11
+ sub-title="请求参数或者返回数据错误"></el-result>
12
+ </template>
13
+ <script setup>
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
+
20
+ function getQuery() {
21
+ let query = {};
22
+ try {
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
+ });
32
+ } catch (error) {
33
+ console.error('hiprint Preview getQuery on error:', error);
34
+ }
35
+ return query;
36
+ }
37
+
38
+ onMounted(() => {
39
+ let query = getQuery();
40
+ if (query.code) {
41
+ sessionStorage.printQuery = JSON.stringify(query);
42
+ getData(query);
43
+ } else {
44
+ if (sessionStorage.printQuery) {
45
+ query = JSON.parse(sessionStorage.printQuery);
46
+ getData(query);
47
+ } else {
48
+ loading.close();
49
+ error.value = true;
50
+ }
51
+ }
52
+ window.addEventListener('afterprint', () => {
53
+ self.close();
54
+ });
55
+ });
56
+
57
+ const route = useRoute();
58
+ const success = ref(false);
59
+ const error = ref(false);
60
+
61
+ let loading = ElLoading.service({
62
+ text: '正在加载数据……',
63
+ });
64
+
65
+ function getData(query) {
66
+ let {code, params, data, isCustom} = query;
67
+ loading.setText('获取打印配置和数据');
68
+ let reqParams = params ? JSON.parse(params) : [];
69
+
70
+ axios
71
+ .request({
72
+ url: `/printTemplate/data/${code}`,
73
+ method: 'post',
74
+ type: 'json',
75
+ data: reqParams,
76
+ })
77
+ .then(async (res) => {
78
+ loading.setText('格式化数据,初始化打印插件');
79
+ let {list, json} = res.data;
80
+ if (json) {
81
+ let hasData = false;
82
+ if (Array.isArray(list) && list.length > 0) {
83
+ list = list.map((item, index) => {
84
+ let printData = {};
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 {
118
+ hasData = true;
119
+ list = JSON.parse(data);
120
+ } catch (error) {
121
+ hasData = false;
122
+ list = [];
123
+ }
124
+ }
125
+ });
126
+ } else if (data) {
127
+ try {
128
+ hasData = true;
129
+ list = JSON.parse(data);
130
+ } catch (error) {
131
+ hasData = false;
132
+ list = [];
133
+ }
134
+ }
135
+ let html = hiprintTemplate.getHtml(list);
136
+ document.body.innerHTML = '';
137
+ document.body.appendChild(html[0]);
138
+ if (hasData) {
139
+ setTimeout(() => {
140
+ window.print();
141
+ }, 1000);
142
+ } else {
143
+ ElMessageBox.alert('数据源没有数据,打印将取消').then(() => {
144
+ window.close();
145
+ });
146
+ }
147
+ success.value = false;
148
+ } else {
149
+ error.value = true;
150
+ }
151
+ })
152
+ .catch((err) => {
153
+ console.error(err);
154
+ error.value = true;
155
+ })
156
+ .finally(() => {
157
+ loading.close();
158
+ });
159
+ }
160
+ </script>
161
+ <style lang="scss"></style>