yh-hiprint 2.0.0 → 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.
- package/HiprintDesigner.vue +2 -2
- package/README.md +102 -1
- package/hiprint.js +1 -1
- package/hiprintPreview.vue +8 -1
- package/index.js +15 -2
- package/package.json +1 -1
package/HiprintDesigner.vue
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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 "
|
|
6
|
+
import App from "yh-hiprint/hiprint.vue";
|
|
7
7
|
const router = createRouter({
|
|
8
8
|
history: createWebHashHistory(),
|
|
9
9
|
routes: [
|
package/hiprintPreview.vue
CHANGED
|
@@ -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
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { install } from "vant";
|
|
2
|
-
|
|
3
1
|
export { hiprint, defaultElementTypeProvider, print, print2, usePaper, useScale, useDataSource } from "./hooks/useHiprint";
|
|
4
2
|
|
|
5
3
|
export { default as jquery } from "jquery";
|
|
@@ -16,8 +14,23 @@ export function cLog(string, isError = false) {
|
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
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 + "¶ms=" + 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
|
+
};
|
|
19
31
|
export default {
|
|
20
32
|
install(app, { router, pinia, isAdmin }) {
|
|
33
|
+
app.provide("$hiprint", hiprint);
|
|
21
34
|
if (router) {
|
|
22
35
|
router.addRoute("Index", {
|
|
23
36
|
path: "hiprint/designer",
|