yh-hiprint 2.0.2 → 2.1.1

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.
@@ -378,6 +378,8 @@ watch(
378
378
  };
379
379
  })
380
380
  );
381
+ } else {
382
+ hiprintTemplate.value?.setFields("");
381
383
  }
382
384
  },
383
385
  {
@@ -492,12 +494,12 @@ function init() {
492
494
  paginationContainer: ".hiprint-printPagination",
493
495
  });
494
496
 
495
- hiprintTemplate.value.design("#hiprint-printTemplate", { grid: true });
497
+ hiprintTemplate.value?.design("#hiprint-printTemplate", { grid: true });
496
498
  scaleValue.value = hiprintTemplate.value.editingPanel.scale || 1;
497
499
  window.ht = hiprintTemplate.value;
498
500
 
499
501
  if (formColumns.value) {
500
- hiprintTemplate.value.setFields(
502
+ hiprintTemplate.value?.setFields(
501
503
  formColumns.value.map((item) => {
502
504
  return {
503
505
  field: item,
@@ -508,7 +510,7 @@ function init() {
508
510
  }
509
511
  $(".hiprint-designer").on("mousedown", ".hiprint-printElement", (e) => {
510
512
  let t = e.currentTarget;
511
- let pes = hiprintTemplate.value.editingPanel.printElements;
513
+ let pes = hiprintTemplate.value?.editingPanel.printElements;
512
514
  let index = pes.map((item) => item.designTarget[0]).indexOf(t);
513
515
  let pe = pes[index];
514
516
  currentElementObj.value = pe;
@@ -516,6 +518,15 @@ function init() {
516
518
  listCode.value = pe.options.field;
517
519
  }
518
520
  });
521
+ $("#PrintElementOptionSetting").on("input", "input[type=number]", ($el) => {
522
+ let val = parseInt($el.target.value);
523
+ if (val < 1) {
524
+ $el.target.value = 1;
525
+ }
526
+ if (val > 2000) {
527
+ $el.target.value = 2000;
528
+ }
529
+ });
519
530
  } catch (error) {
520
531
  console.log(error.message);
521
532
  clearPrint();
@@ -536,14 +547,14 @@ async function updateTemplate(code) {
536
547
  await getDetail(code);
537
548
  if (detailData.value && detailData.value.json) {
538
549
  let jsonObj = JSON.parse(detailData.value.json);
539
- hiprintTemplate.value.update(jsonObj);
550
+ hiprintTemplate.value?.update(jsonObj);
540
551
  let { width, height } = jsonObj.panels[0];
541
552
  paperWidth.value = width;
542
553
  paperHeight.value = height;
543
- hiprintTemplate.value.setPaper(width, height);
554
+ hiprintTemplate.value?.setPaper(width, height);
544
555
  scaleValue.value = 1;
545
556
  } else {
546
- hiprintTemplate.value.update({
557
+ hiprintTemplate.value?.update({
547
558
  panels: [
548
559
  {
549
560
  index: 0,
@@ -561,7 +572,7 @@ async function updateTemplate(code) {
561
572
  });
562
573
  paperWidth.value = 210;
563
574
  paperHeight.value = 297;
564
- hiprintTemplate.value.setPaper(210, 297);
575
+ hiprintTemplate.value?.setPaper(210, 297);
565
576
  scaleValue.value = 1;
566
577
  }
567
578
  } else {
package/README.md CHANGED
@@ -113,3 +113,15 @@ export default defineConfig({
113
113
  });
114
114
 
115
115
  ```
116
+
117
+ ## 更新日志
118
+
119
+ ###### 2.1.1
120
+ - 升级 hiprint 方法,兼容打印预览的 data、isCustom 参数
121
+
122
+ ###### 2.1.0
123
+ - 打印预览增加 data、isCustom 参数,并提供 isCustom 参数的GUI部分
124
+ - 修复部分设计器的bug
125
+
126
+ ###### 2.0.0
127
+ - 插件内聚,将能够内聚的代码都提取到包中。
@@ -45,9 +45,9 @@ let loading = ElLoading.service({
45
45
  });
46
46
 
47
47
  function getData(query) {
48
- let { code, params } = query;
48
+ let { code, params, data, isCustom } = query;
49
49
  loading.setText("获取打印配置和数据");
50
- let reqParams = JSON.parse(params);
50
+ let reqParams = JSON.parse(params) || [];
51
51
 
52
52
  axios
53
53
  .request({
@@ -56,7 +56,7 @@ function getData(query) {
56
56
  type: "json",
57
57
  data: reqParams,
58
58
  })
59
- .then((res) => {
59
+ .then(async (res) => {
60
60
  loading.setText("格式化数据,初始化打印插件");
61
61
  let { list, json } = res.data;
62
62
  if (json) {
@@ -64,7 +64,6 @@ function getData(query) {
64
64
  if (Array.isArray(list) && list.length > 0) {
65
65
  list = list.map((item, index) => {
66
66
  let printData = {};
67
- let reqData = reqParams[index];
68
67
  let datas = Object.entries(item);
69
68
  datas.forEach((arr) => {
70
69
  if (Array.isArray(arr[1])) {
@@ -86,6 +85,33 @@ function getData(query) {
86
85
  list = [];
87
86
  }
88
87
  let hiprintTemplate = new hiprint.PrintTemplate({ template: JSON.parse(json) });
88
+ // 如若有本地数据,那么将本地数据替换远端数据。传入预览中。
89
+ if (isCustom === "1") {
90
+ await ElMessageBox.prompt("在下面输入框中输入您给的自定义数据", "自定义数据", {
91
+ inputType: "textarea",
92
+ }).then((e) => {
93
+ try {
94
+ hasData = true;
95
+ list = JSON.parse(e.value);
96
+ } catch (error) {
97
+ try {
98
+ hasData = true;
99
+ list = JSON.parse(data);
100
+ } catch (error) {
101
+ hasData = false;
102
+ list = [];
103
+ }
104
+ }
105
+ });
106
+ } else if (data) {
107
+ try {
108
+ hasData = true;
109
+ list = JSON.parse(data);
110
+ } catch (error) {
111
+ hasData = false;
112
+ list = [];
113
+ }
114
+ }
89
115
  let html = hiprintTemplate.getHtml(list);
90
116
  document.body.innerHTML = "";
91
117
  document.body.appendChild(html[0]);
package/index.d.ts CHANGED
@@ -56,3 +56,12 @@ export declare const useDataSource: (axios) => {
56
56
  getDataSourceList: () => void;
57
57
  dataSource: Ref<string[]>;
58
58
  };
59
+
60
+ export declare interface HiprintOption {
61
+ code: string;
62
+ params: Object;
63
+ data: Record<string, any> | Record<string, any>[];
64
+ isCustom: boolean;
65
+ }
66
+
67
+ export declare const hiprint: (HiprintOption) => void;
package/index.js CHANGED
@@ -14,19 +14,25 @@ export function cLog(string, isError = false) {
14
14
  }
15
15
  }
16
16
 
17
- const hiprint = (code, params) => {
17
+ export const hiprint = ({ code, params, data, isCustom }) => {
18
18
  let height = document.documentElement.clientHeight;
19
19
  let width = (document.documentElement.clientWidth - 1200) / 2;
20
20
  // 转换数组
21
- let data = params;
21
+ let paramData = params;
22
22
  if (typeof params !== "Array") {
23
- data = [params];
23
+ paramData = [params];
24
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);
25
+ url = "/hiprint/#/preview?code=" + code;
26
+ if (paramData) {
27
+ url += `&params=${JSON.stringify(paramData)}`;
28
+ }
29
+ if (data) {
30
+ url += `&data=${JSON.stringify(data)}`;
31
+ }
32
+ if (isCustom) {
33
+ url += `&isCustom=${isCustom ? "1" : "0"}`;
34
+ }
35
+ let windowOpen = window.open(url, "hiprintWindow", `height=${height}, width=1200, top=20, left=${width}, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no`);
30
36
  };
31
37
  export default {
32
38
  install(app, { router, pinia, isAdmin }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yh-hiprint",
3
- "version": "2.0.2",
3
+ "version": "2.1.1",
4
4
  "description": "Hiprint for Vue3 by NoahLiu in ForceCon in Hunan Changesha",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",