yh-hiprint 2.0.1 → 2.0.2

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.
@@ -265,10 +265,10 @@
265
265
  </el-dialog>
266
266
  </template>
267
267
  <script setup lang="ts">
268
- import { onMounted, ref, onActivated, onDeactivated, computed, watch, nextTick } from "vue";
268
+ import { onMounted, ref, onActivated, onDeactivated, computed, watch } from "vue";
269
269
  import { hiprint, defaultElementTypeProvider, fontSize, scale, zIndex, panel, usePaper, useScale, useDataSource, jquery as $ } from "yh-hiprint";
270
270
  import { useRoute, onBeforeRouteUpdate } from "vue-router";
271
- import { ElMessageBox } from "element-plus";
271
+ import { ElMessageBox, ElMessage } from "element-plus";
272
272
  import axios from "@/libs/api.request";
273
273
 
274
274
  const route = useRoute();
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  力控远海技术中心封装的 hiprint
4
4
 
5
+ 当前教程匹配 2+ 版本
6
+
5
7
  ## 安装
6
8
 
7
9
  配置好[云效NPM私有仓库](https://packages.aliyun.com/npm/npm-registry/guide)后,直接执行如下命令安装
@@ -11,4 +13,103 @@ npm install yh-hiprint
11
13
 
12
14
  ## 使用
13
15
 
14
- 参考[中控项目](https://codeup.aliyun.com/60765e0161a945067837bb5f/Core/Core-Service) `中控系统/02-Src/web/src/view/hiprint/designer.vue`
16
+ ### 安装并引入设计器
17
+
18
+ `main.js(main.ts)` 中
19
+
20
+ ```javascript
21
+ import yhHiprint from "yh-hiprint";
22
+ // ……
23
+ const app = createApp(App);
24
+ //……
25
+ app.use(yhHiprint, {
26
+ router,
27
+ pinia,
28
+ isAdmin,
29
+ });
30
+ //……
31
+ app.use(pinia);
32
+ app.use(router);
33
+ app.use(ElementPlus);
34
+ ```
35
+
36
+ ### 预览页面配置
37
+
38
+ ###### 新增预览页入口html
39
+ `hiprint/index.html`
40
+ ```html
41
+ <!DOCTYPE html>
42
+ <html lang="en">
43
+ <head>
44
+ <meta charset="UTF-8" />
45
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
46
+ <link rel="icon" type="image/svg+xml" href="/favicon.ico" />
47
+ <link rel="stylesheet" href="/iconfont/iconfont.css">
48
+ <title>力控元海</title>
49
+ </head>
50
+ <body>
51
+ <div id="app"></div>
52
+ <script type="module" src="/src/layout/hiprint/hiprint.js"></script>
53
+ </body>
54
+ </html>
55
+ ```
56
+
57
+ ###### 新增预览页入口js
58
+ `src/layout/hiprint/hiprint.js`
59
+ ```js
60
+ import { createApp } from "vue";
61
+ import { createRouter, createWebHashHistory } from "vue-router";
62
+ import { setTitle } from "@/libs/util";
63
+ import "element-plus/dist/index.css";
64
+
65
+ import App from "yh-hiprint/hiprint.vue";
66
+ const router = createRouter({
67
+ history: createWebHashHistory(),
68
+ routes: [
69
+ {
70
+ path: "/",
71
+ redirect: "/preview",
72
+ },
73
+ {
74
+ path: "/preview",
75
+ name: "printView",
76
+ meta: {
77
+ title: "打印",
78
+ },
79
+ component: () => import("yh-hiprint/hiprintPreview.vue"),
80
+ },
81
+ ],
82
+ });
83
+
84
+ router.beforeEach((to, from, next) => {
85
+ next();
86
+ });
87
+
88
+ router.afterEach((to) => {
89
+ setTitle(to);
90
+ window.scrollTo(0, 0);
91
+ });
92
+ const app = createApp(App);
93
+ app.use(router);
94
+ app.mount("#app");
95
+ ```
96
+
97
+ ###### 配置对应 的vite 入口
98
+ `vite-.config.js`
99
+ ```javascript
100
+ // ……
101
+ export default defineConfig({
102
+ // ……
103
+ build: {
104
+ // ……
105
+ rollupOptions: {
106
+ // ……
107
+ input: {
108
+ // ……
109
+ hiprint: path.resolve(__dirname, "hiprint/index.html"),
110
+ },
111
+ },
112
+ },
113
+ });
114
+
115
+ ```
package/hiprint.js CHANGED
@@ -3,7 +3,7 @@ import { createRouter, createWebHashHistory } from "vue-router";
3
3
  import { setTitle } from "@/libs/util";
4
4
  import "element-plus/dist/index.css";
5
5
 
6
- import App from "./hiprint.vue";
6
+ import App from "yh-hiprint/hiprint.vue";
7
7
  const router = createRouter({
8
8
  history: createWebHashHistory(),
9
9
  routes: [
@@ -11,7 +11,7 @@
11
11
  sub-title="请求参数或者返回数据错误"></el-result>
12
12
  </template>
13
13
  <script setup>
14
- import { ElLoading, ElResult } from "element-plus";
14
+ import { ElLoading, ElResult, ElMessageBox } from "element-plus";
15
15
  import { onMounted, ref } from "vue";
16
16
  import { useRoute } from "vue-router";
17
17
  import axios from "@/libs/api.request.js";
@@ -31,6 +31,9 @@ onMounted(() => {
31
31
  error.value = true;
32
32
  }
33
33
  }
34
+ window.addEventListener("afterprint", () => {
35
+ self.close();
36
+ });
34
37
  });
35
38
 
36
39
  const route = useRoute();
@@ -90,6 +93,10 @@ function getData(query) {
90
93
  setTimeout(() => {
91
94
  window.print();
92
95
  }, 1000);
96
+ } else {
97
+ ElMessageBox.alert("数据源没有数据,打印将取消").then(() => {
98
+ window.close();
99
+ });
93
100
  }
94
101
  success.value = false;
95
102
  } else {
package/index.js CHANGED
@@ -14,8 +14,23 @@ export function cLog(string, isError = false) {
14
14
  }
15
15
  }
16
16
 
17
+ const hiprint = (code, params) => {
18
+ let height = document.documentElement.clientHeight;
19
+ let width = (document.documentElement.clientWidth - 1200) / 2;
20
+ // 转换数组
21
+ let data = params;
22
+ if (typeof params !== "Array") {
23
+ data = [params];
24
+ }
25
+
26
+ let windowOpen = window.open("/hiprint/#/preview?code=" + code + "&params=" + JSON.stringify(data), "windowOpen", "height=" + height + ", width=1200, top=20, left=" + width + ", toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
27
+ // window.setTimeout(() => {
28
+ // windowOpen.close();
29
+ // }, 5000);
30
+ };
17
31
  export default {
18
32
  install(app, { router, pinia, isAdmin }) {
33
+ app.provide("$hiprint", hiprint);
19
34
  if (router) {
20
35
  router.addRoute("Index", {
21
36
  path: "hiprint/designer",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yh-hiprint",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Hiprint for Vue3 by NoahLiu in ForceCon in Hunan Changesha",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",