yh-hiprint 1.0.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/README.md ADDED
@@ -0,0 +1,14 @@
1
+ ## yh-hiprint
2
+
3
+ 力控远海技术中心封装的 hiprint
4
+
5
+ ## 安装
6
+
7
+ 配置好[云效NPM私有仓库](https://packages.aliyun.com/npm/npm-registry/guide)后,直接执行如下命令安装
8
+ ```shell
9
+ npm install yh-hiprint
10
+ ```
11
+
12
+ ## 使用
13
+
14
+ 参考[中控项目](https://codeup.aliyun.com/60765e0161a945067837bb5f/Core/Core-Service) `中控系统/02-Src/web/src/view/hiprint/designer.vue`
@@ -0,0 +1,40 @@
1
+ import $ from "jquery";
2
+
3
+ export default function (tableFields) {
4
+ function t() {
5
+ this.name = "field";
6
+ }
7
+
8
+ return (
9
+ (t.prototype.createTarget = function (t, i, e) {
10
+ // t: 元素对象,i: 元素options, e: 元素printElementType
11
+ return (
12
+ (this.target = $(
13
+ `<div class="hiprint-option-item">
14
+ <div class="hiprint-option-item-label">字段选择</div>
15
+ <div class="hiprint-option-item-field">
16
+ <select class="auto-submit">${tableFields.value.map((item) => {
17
+ return `<option value="${item}">${item}</option>`;
18
+ })}</select>
19
+ </div>
20
+ </div>`
21
+ )),
22
+ this.target
23
+ );
24
+ }),
25
+ // 获取值
26
+ (t.prototype.getValue = function () {
27
+ var t = this.target.find("select").val();
28
+ if (t) return t;
29
+ }),
30
+ // 设置值
31
+ (t.prototype.setValue = function (t) {
32
+ this.target.find("select").val(t);
33
+ }),
34
+ // 销毁 DOM
35
+ (t.prototype.destroy = function () {
36
+ this.target.remove();
37
+ }),
38
+ t
39
+ );
40
+ }
package/font-size.js ADDED
@@ -0,0 +1,46 @@
1
+ import $ from "jquery";
2
+ export default (function () {
3
+ function t() {
4
+ this.name = "fontSize"; // 重写的参数 key
5
+ }
6
+ // 涉及修改元素样式, 添加一个 css 方法
7
+ return (
8
+ (t.prototype.css = function (t, e) {
9
+ if (t && t.length) {
10
+ if (e) return t.css("font-size", e + "pt"), "font-size:" + e + "pt";
11
+ t[0].style.fontSize = "";
12
+ }
13
+ return null;
14
+ }),
15
+ // 创建 DOM
16
+ (t.prototype.createTarget = function () {
17
+ let list = [8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72];
18
+ let fontSizeList = '\n <option value="" >默认</option>';
19
+ list.forEach(function (e) {
20
+ fontSizeList += '\n <option value="' + e + '">' + e + "pt</option>";
21
+ });
22
+ this.target = $(
23
+ ' <div class="hiprint-option-item">\n <div class="hiprint-option-item-label">\n 字体大小\n </div>\n <div class="hiprint-option-item-field">\n <select class="auto-submit"> </select>\n </div>\n </div>'
24
+ );
25
+ this.target.find(".auto-submit").append($(fontSizeList));
26
+ return this.target;
27
+ }),
28
+ // 获取值
29
+ (t.prototype.getValue = function () {
30
+ var t = this.target.find("select").val();
31
+ if (t) return parseFloat(t.toString());
32
+ }),
33
+ // 设置值
34
+ (t.prototype.setValue = function (t) {
35
+ t &&
36
+ (this.target.find('option[value="' + t + '"]').length ||
37
+ this.target.find("select").prepend('<option value="' + t + '" >' + t + "</option>"));
38
+ this.target.find("select").val(t);
39
+ }),
40
+ // 销毁 DOM
41
+ (t.prototype.destroy = function () {
42
+ this.target.remove();
43
+ }),
44
+ t
45
+ );
46
+ })();
@@ -0,0 +1,210 @@
1
+ import {
2
+ hiprint as h,
3
+ defaultElementTypeProvider as p,
4
+ } from "../libs/hiprint.bundle.js";
5
+ // 调用浏览器打印js
6
+ import "../libs/plugins/jquery.hiwprint.js";
7
+ // 默认配置
8
+ import "../libs/hiprint.config.js";
9
+ // 样式
10
+ import "../libs/css/hiprint.css";
11
+ import "../libs/css/print-lock.css";
12
+ import { ref, computed } from "vue";
13
+
14
+ export const hiprint = h;
15
+ export const defaultElementTypeProvider = p;
16
+
17
+ export function print(
18
+ provider = defaultElementTypeProvider,
19
+ template,
20
+ ...args
21
+ ) {
22
+ hiprint.init({
23
+ providers: [new provider()],
24
+ });
25
+ const hiprintTemplate = new hiprint.PrintTemplate({
26
+ template: template,
27
+ });
28
+ hiprintTemplate.print(...args);
29
+ return hiprintTemplate;
30
+ }
31
+
32
+ export function print2(
33
+ provider = defaultElementTypeProvider,
34
+ template,
35
+ ...args
36
+ ) {
37
+ hiprint.init({
38
+ providers: [new provider()],
39
+ });
40
+ const hiprintTemplate = new hiprint.PrintTemplate({
41
+ template: template,
42
+ });
43
+ hiprintTemplate.print2(...args);
44
+ return hiprintTemplate;
45
+ }
46
+
47
+ export function usePaper() {
48
+ const paperType = ref("A4");
49
+ const paperWidth = ref(210);
50
+ const paperHeight = ref(296.6);
51
+
52
+ const paperTypes = {
53
+ A3: {
54
+ width: 420,
55
+ height: 296.6,
56
+ },
57
+ A4: {
58
+ width: 210,
59
+ height: 296.6,
60
+ },
61
+ A5: {
62
+ width: 210,
63
+ height: 147.6,
64
+ },
65
+ B3: {
66
+ width: 500,
67
+ height: 352.6,
68
+ },
69
+ B4: {
70
+ width: 250,
71
+ height: 352.6,
72
+ },
73
+ B5: {
74
+ width: 250,
75
+ height: 175.6,
76
+ },
77
+ };
78
+
79
+ function setPaper(type, callback) {
80
+ if (type !== "other") {
81
+ let { width, height } = paperTypes[type];
82
+ paperWidth.value = width;
83
+ paperHeight.value = height;
84
+ }
85
+ callback();
86
+ }
87
+
88
+ return {
89
+ paperType,
90
+ paperWidth,
91
+ paperHeight,
92
+ setPaper,
93
+ };
94
+ }
95
+
96
+ export function useScale(callback) {
97
+ const scaleValue = ref(1);
98
+ const scalePercentage = computed(() => {
99
+ return `${(scaleValue.value * 100).toFixed(0)}%`;
100
+ });
101
+ const canZoomIn = computed(() => {
102
+ return scaleValue.value > 0.5;
103
+ });
104
+ const canZoomOut = computed(() => {
105
+ return scaleValue.value < 1.5;
106
+ });
107
+ function zoomIn() {
108
+ scaleValue.value = scaleValue.value - 0.1;
109
+ callback();
110
+ }
111
+ function zoomOut() {
112
+ scaleValue.value = scaleValue.value + 0.1;
113
+ callback();
114
+ }
115
+ return {
116
+ scaleValue,
117
+ scalePercentage,
118
+ canZoomIn,
119
+ canZoomOut,
120
+ zoomIn,
121
+ zoomOut,
122
+ };
123
+ }
124
+
125
+ export function useDataSource(axios) {
126
+ const detailData = ref();
127
+ function getDetail(id) {
128
+ return axios
129
+ .request({
130
+ url: `/printTemplate/get/${id}`,
131
+ method: "post",
132
+ })
133
+ .then((res) => {
134
+ if (res.data.data && res.data.data.sourceCodes) {
135
+ let codes = res.data.data.sourceCodes.split(",");
136
+ let formListCode = dataSourceForm.value.map((item) => item.value);
137
+ codes = codes.filter((item) => formListCode.includes(item));
138
+ formCode.value = codes;
139
+ } else {
140
+ formCode.value = "";
141
+ }
142
+ detailData.value = res.data.data;
143
+ });
144
+ }
145
+ const listCode = ref([]);
146
+ const dataSourceList = ref([]);
147
+ const listColumns = computed(() => {
148
+ return codeMapDataSource.value[listCode.value].map((item) => {
149
+ let index = item.indexOf("[");
150
+ return item.substring(index + 1, item.length - 1);
151
+ });
152
+ });
153
+
154
+ const formCode = ref([]);
155
+ const formColumns = computed(() => {
156
+ let arr = [];
157
+ if (formCode.value && formCode.value.length) {
158
+ formCode.value.forEach((item) => {
159
+ arr = arr.concat(codeMapDataSource.value[item]);
160
+ });
161
+ }
162
+ return arr;
163
+ });
164
+ const dataSourceForm = ref([]);
165
+ const codeMapDataSource = ref({});
166
+ function getDataSourceList() {
167
+ return axios
168
+ .request({
169
+ url: "/printTemplate/getDsList",
170
+ method: "post",
171
+ })
172
+ .then((res) => {
173
+ res.data.list.forEach((item) => {
174
+ if (item.columns) {
175
+ codeMapDataSource.value[item.code] = item?.columns
176
+ ?.split(",")
177
+ ?.map((col) => `$${item.code}[${col.toUpperCase()}]`) || [];
178
+ }
179
+ if (item.type === "LIST") {
180
+ dataSourceList.value.push({
181
+ label: item.name,
182
+ value: item.code,
183
+ });
184
+ } else {
185
+ dataSourceForm.value.push({
186
+ label: item.name,
187
+ value: item.code,
188
+ });
189
+ }
190
+ });
191
+ });
192
+ }
193
+
194
+ const dataSource = ref([]);
195
+ return {
196
+ detailData,
197
+ getDetail,
198
+ listCode,
199
+ dataSourceList,
200
+ listColumns,
201
+ formCode,
202
+ formColumns,
203
+ dataSourceForm,
204
+ codeMapDataSource,
205
+ getDataSourceList,
206
+ dataSource,
207
+ };
208
+ }
209
+
210
+ window.hiprint = hiprint;
package/index.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ declare module "yh-hiprint";
2
+
3
+ /** JQuery 简化dom操作的库 */
4
+ export declare const jquery: JQuery;
5
+
6
+ /** hiprint 字体大小配置 */
7
+ export declare const fontSize;
8
+ /** hiprint 缩放配置 */
9
+ export declare const scale;
10
+ /** hiprint 层级配置 */
11
+ export declare const zIndex;
12
+ /** hiprint 侧边栏配置 */
13
+ export declare const panel;
14
+
15
+ export declare const hiprint;
16
+ export declare const defaultElementTypeProvider: (options: any) => {
17
+ addElementTypes: (context) => void;
18
+ };
19
+ export declare const print;
20
+ export declare const print2;
21
+ export declare const usePaper;
22
+
23
+ /**
24
+ * 打印组件的缩放
25
+ * @param callback 每次缩放后都会执行的回调函数
26
+ */
27
+ export declare const useScale: (callback: () => void) => {
28
+ /** 当前缩放值 */
29
+ scaleValue: Ref<number>;
30
+ /** 当前百分比展示字符串 */
31
+ scalePercentage: ComputedRef<string>;
32
+ /** 当前是否能缩小 */
33
+ canZoomIn: ComputedRef<boolean>;
34
+ /** 当前是否能放大 */
35
+ canZoomOut: ComputedRef<boolean>;
36
+ /** 缩小 */
37
+ zoomIn: () => void;
38
+ /** 放大 */
39
+ zoomOut: () => void;
40
+ };
41
+
42
+ /**
43
+ * 打印组件数据源
44
+ * @param axios 系统中的请求实体 `src/libs/api.request.js`
45
+ */
46
+ export declare const useDataSource: (axios) => {
47
+ detailData: Ref<any>;
48
+ getDetail: (id) => void;
49
+ listCode: Ref<any[]>;
50
+ dataSourceList: Ref<any[]>;
51
+ listColumns: ComputedRef<string[]>;
52
+ formCode: Ref<any[]>;
53
+ formColumns: ComputedRef<string[]>;
54
+ dataSourceForm: Ref<any[]>;
55
+ codeMapDataSource: Ref<any>;
56
+ getDataSourceList: () => void;
57
+ dataSource: Ref<string[]>;
58
+ };
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ export {
2
+ hiprint,
3
+ defaultElementTypeProvider,
4
+ print,
5
+ print2,
6
+ usePaper,
7
+ useScale,
8
+ useDataSource,
9
+ } from "./hooks/useHiprint";
10
+
11
+ export { default as jquery } from "jquery";
12
+ export { default as fontSize } from "./font-size";
13
+ export { default as scale } from "./scale";
14
+ export { default as zIndex } from "./z-index";
15
+ export { default as panel } from "./panel";