yh-hiprint 1.0.10 → 2.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/hiprint.js ADDED
@@ -0,0 +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 "./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 ADDED
@@ -0,0 +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>
@@ -0,0 +1,108 @@
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 } 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
+ onMounted(() => {
21
+ let query = route.query;
22
+ if (query.code) {
23
+ sessionStorage.printQuery = JSON.stringify(query);
24
+ getData(query);
25
+ } else {
26
+ if (sessionStorage.printQuery) {
27
+ query = JSON.parse(sessionStorage.printQuery);
28
+ getData(query);
29
+ } else {
30
+ loading.close();
31
+ error.value = true;
32
+ }
33
+ }
34
+ });
35
+
36
+ const route = useRoute();
37
+ const success = ref(false);
38
+ const error = ref(false);
39
+
40
+ let loading = ElLoading.service({
41
+ text: "正在加载数据……",
42
+ });
43
+
44
+ function getData(query) {
45
+ let { code, params } = query;
46
+ loading.setText("获取打印配置和数据");
47
+ let reqParams = JSON.parse(params);
48
+
49
+ axios
50
+ .request({
51
+ url: `/printTemplate/data/${code}`,
52
+ method: "post",
53
+ type: "json",
54
+ data: reqParams,
55
+ })
56
+ .then((res) => {
57
+ loading.setText("格式化数据,初始化打印插件");
58
+ let { list, json } = res.data;
59
+ if (json) {
60
+ let hasData = false;
61
+ if (Array.isArray(list) && list.length > 0) {
62
+ list = list.map((item, index) => {
63
+ let printData = {};
64
+ let reqData = reqParams[index];
65
+ let datas = Object.entries(item);
66
+ datas.forEach((arr) => {
67
+ if (Array.isArray(arr[1])) {
68
+ hasData = arr[1].length > 0;
69
+ printData[arr[0]] = arr[1];
70
+ } else {
71
+ if (arr[1] !== null) {
72
+ hasData = true;
73
+ let itemsEntries = Object.entries(arr[1]);
74
+ itemsEntries.forEach((cArr) => {
75
+ printData[`$${arr[0]}[${cArr[0]}]`] = cArr[1];
76
+ });
77
+ }
78
+ }
79
+ });
80
+ return printData;
81
+ });
82
+ } else {
83
+ list = [];
84
+ }
85
+ let hiprintTemplate = new hiprint.PrintTemplate({ template: JSON.parse(json) });
86
+ let html = hiprintTemplate.getHtml(list);
87
+ document.body.innerHTML = "";
88
+ document.body.appendChild(html[0]);
89
+ if (hasData) {
90
+ setTimeout(() => {
91
+ window.print();
92
+ }, 1000);
93
+ }
94
+ success.value = false;
95
+ } else {
96
+ error.value = true;
97
+ }
98
+ })
99
+ .catch((err) => {
100
+ console.error(err);
101
+ error.value = true;
102
+ })
103
+ .finally(() => {
104
+ loading.close();
105
+ });
106
+ }
107
+ </script>
108
+ <style lang="scss"></style>
@@ -6,7 +6,7 @@ import "../libs/hiprint.config.js";
6
6
  // 样式
7
7
  import "../libs/css/hiprint.css";
8
8
  import "../libs/css/print-lock.css";
9
- import { ref, computed } from "vue";
9
+ import { ref, computed, watch } from "vue";
10
10
 
11
11
  export const hiprint = h;
12
12
  export const defaultElementTypeProvider = p;
@@ -41,27 +41,27 @@ export function usePaper() {
41
41
  const paperTypes = {
42
42
  A3: {
43
43
  width: 420,
44
- height: 296.6,
44
+ height: 297,
45
45
  },
46
46
  A4: {
47
47
  width: 210,
48
- height: 296.6,
48
+ height: 297,
49
49
  },
50
50
  A5: {
51
51
  width: 210,
52
- height: 147.6,
52
+ height: 148,
53
53
  },
54
54
  B3: {
55
55
  width: 500,
56
- height: 352.6,
56
+ height: 353,
57
57
  },
58
58
  B4: {
59
59
  width: 250,
60
- height: 352.6,
60
+ height: 353,
61
61
  },
62
62
  B5: {
63
63
  width: 250,
64
- height: 175.6,
64
+ height: 176,
65
65
  },
66
66
  };
67
67
 
@@ -74,6 +74,24 @@ export function usePaper() {
74
74
  callback();
75
75
  }
76
76
 
77
+ watch([paperWidth, paperHeight], (width, height) => {
78
+ if (width === 420 && height === 297) {
79
+ paperType.value = "A3";
80
+ } else if (width === 210 && height === 297) {
81
+ paperType.value = "A4";
82
+ } else if (width === 210 && height === 148) {
83
+ paperType.value = "A5";
84
+ } else if (width === 500 && height === 353) {
85
+ paperType.value = "B3";
86
+ } else if (width === 250 && height === 353) {
87
+ paperType.value = "B4";
88
+ } else if (width === 250 && height === 176) {
89
+ paperType.value = "B5";
90
+ } else {
91
+ paperType.value = "other";
92
+ }
93
+ });
94
+
77
95
  return {
78
96
  paperType,
79
97
  paperWidth,
package/index.js CHANGED
@@ -1,15 +1,46 @@
1
- export {
2
- hiprint,
3
- defaultElementTypeProvider,
4
- print,
5
- print2,
6
- usePaper,
7
- useScale,
8
- useDataSource,
9
- } from "./hooks/useHiprint";
1
+ import { install } from "vant";
2
+
3
+ export { hiprint, defaultElementTypeProvider, print, print2, usePaper, useScale, useDataSource } from "./hooks/useHiprint";
10
4
 
11
5
  export { default as jquery } from "jquery";
12
6
  export { default as fontSize } from "./font-size";
13
7
  export { default as scale } from "./scale";
14
8
  export { default as zIndex } from "./z-index";
15
9
  export { default as panel } from "./panel";
10
+
11
+ export function cLog(string, isError = false) {
12
+ if (isError) {
13
+ console.error("%cyhHiprint:%c", "font-size: 16px;font-weight: bold;color: #00ffff", "font-size: 16px;font-weight: bold;color: #ccccc", string);
14
+ } else {
15
+ console.log("%cyhHiprint%c " + string, "font-size: 18px;font-weight: bold;color: #61AFEF", "font-size: 12px;color: #999");
16
+ }
17
+ }
18
+
19
+ export default {
20
+ install(app, { router, pinia, isAdmin }) {
21
+ if (router) {
22
+ router.addRoute("Index", {
23
+ path: "hiprint/designer",
24
+ name: "打印设计器",
25
+ meta: {
26
+ icon: "md-planet",
27
+ title: "打印设计器",
28
+ },
29
+ component: () => import("yh-hiprint/HiprintDesigner.vue"),
30
+ });
31
+ router.addRoute({
32
+ path: "/preview",
33
+ name: "printView",
34
+ meta: {
35
+ icon: "md-planet",
36
+ title: "printView",
37
+ },
38
+ component: () => import("yh-hiprint/hiprintPreview.vue"),
39
+ });
40
+ } else {
41
+ if (!router) {
42
+ cLog("没有传递 router 对象,所以无法将路由添加到应用中", true);
43
+ }
44
+ }
45
+ },
46
+ };