vg-print 1.1.0 → 1.1.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/README.md CHANGED
@@ -550,6 +550,88 @@ const onSave = ({ template, data, templateId }) => {
550
550
  - 通过 `default-lang` 设置初始语言(`cn` 默认为中文);内部会同步 `vue-i18n` 与 `hiprint` 的语言。
551
551
  - 运行时可在页面右上角语言切换菜单切换(无需刷新)。
552
552
 
553
+ ## 数据源使用说明
554
+
555
+ `FullDesigner` 内置了数据源管理与字段绑定能力,可用于将接口字段自动映射到设计器组件字段下拉中。
556
+
557
+ ### 入口与能力
558
+
559
+ - 入口:二级工具栏点击“数据源”打开管理弹窗
560
+ - 能力:数据源配置、测试获取、数据处理脚本、错误处理脚本、字段来源规则(全局/按组件类型)
561
+
562
+ ### 使用流程(推荐)
563
+
564
+ 1. 新增数据源并填写基础信息:
565
+ - 唯一名称
566
+ - 请求地址(URL)
567
+ - 请求方法(GET/POST/PUT/DELETE)
568
+ 2. 按需配置请求头、参数、发送数据:
569
+ - 类型支持:`string`、`number`、`boolean`、`expression`
570
+ 3. 编写“数据处理”脚本(`processCode`)并点击“测试链接”:
571
+ - 左侧显示原始返回(`rawResult`)
572
+ - 右侧显示处理结果(`processed`)
573
+ 4. 配置“字段来源规则”并保存:
574
+ - 看板全局:`manual` 或 `global`
575
+ - 组件规则:`manual` / `global` / `custom`
576
+ 5. 规则生效后,组件字段下拉会按规则自动展示字段列表
577
+
578
+ ### processCode / errorProcessCode 约定
579
+
580
+ - `processCode` 函数形态:
581
+
582
+ ```js
583
+ // (result, isSandbox, DSV, VFR) => { ...; return processed; }
584
+ return result
585
+ ```
586
+
587
+ - `errorProcessCode` 函数形态:
588
+
589
+ ```js
590
+ // (error, isSandbox, DSV, $message, VFR) => { ... }
591
+ $message.error(error.message)
592
+ ```
593
+
594
+ ### 字段结构约定
595
+
596
+ 推荐返回以下结构,字段下拉识别最稳定:
597
+
598
+ ```js
599
+ [
600
+ { text: '字段显示名', field: '字段路径' }
601
+ ]
602
+ ```
603
+
604
+ 如果返回的是对象或对象数组,系统也会自动递归提取字段路径(如 `user.name`、`order.items`)。
605
+
606
+ ### 示例:将接口返回转换为字段列表
607
+
608
+ ```js
609
+ return (result.data || []).map(item => ({
610
+ field: item.column_name,
611
+ text: item.table_comment || item.column_name
612
+ }))
613
+ ```
614
+
615
+ ### 缓存与持久化策略(当前实现)
616
+
617
+ - 数据源配置持久化:`KEY_VG_DATASOURCES`
618
+ - 字段绑定规则持久化:`KEY_VG_FIELD_BINDINGS`
619
+ - 数据源运行时缓存:`KEY_VG_DS_RUNTIME_CACHE`
620
+ - 仅缓存处理后数据(`processed`)
621
+ - 不缓存原始返回(`rawResult`)
622
+ - 默认 TTL:30 分钟
623
+ - 默认最大条目:20
624
+
625
+ ### 常见问题
626
+
627
+ - 测试成功但没有字段:
628
+ - 检查 `processCode` 返回值是否为对象或对象数组
629
+ - 检查数据集 path 是否命中处理结果
630
+ - 字段下拉未更新:
631
+ - 先“测试链接”生成字段,再“保存规则”
632
+ - 表达式参数无效:
633
+ - `expression` 求值异常会被忽略,建议先用简单表达式验证
634
+
553
635
  ## 高级用法(hiprint)
554
636
 
555
637
  本库导出 `hiprint`,可直接创建与操作模板对象(`hiprint.PrintTemplate`):
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vg-print",
3
3
  "description": "vg-print Vue3.x 支持拖拽(分页(不分页)、表头表脚、样式设置、复制粘贴、缩放、撤销重做)生成打印模板、导出json模板数据、静默打印/获取MAC地址(借助客户端)",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "author": "gmcSimple",
6
6
  "license": "MIT",
7
7
  "main": "dist/vg-print.es.js",
Binary file
@@ -1,87 +0,0 @@
1
- import { l as b } from "./index-CFsMCiM-.js";
2
- function M(e) {
3
- return typeof e == "string" && /^data:image\/svg\+xml/i.test(e);
4
- }
5
- function C(e) {
6
- let r = e.indexOf(",");
7
- return r >= 0 ? decodeURIComponent(e.slice(r + 1)) : "";
8
- }
9
- function v(e) {
10
- return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`;
11
- }
12
- function F(e) {
13
- let r = [], t = "", i = 0;
14
- for (let o = 0; o < e.length; o++) {
15
- let n = e[o];
16
- n === "(" && i++, n === ")" && (i = Math.max(0, i - 1)), n === ";" && i === 0 ? (r.push(t), t = "") : t += n;
17
- }
18
- return t.trim() && r.push(t), r.map((o) => o.trim()).filter(Boolean);
19
- }
20
- function k(e) {
21
- let r = [], t = "", i = 0;
22
- for (let n = 0; n < e.length; n++) {
23
- let s = e[n];
24
- s === "(" && i++, s === ")" && (i = Math.max(0, i - 1)), s === "," && i === 0 ? (r.push(t.trim()), t = "") : t += s;
25
- }
26
- t.trim() && r.push(t.trim());
27
- let o = [];
28
- for (let n of r) {
29
- if (/\binset\b/i.test(n)) continue;
30
- let s = n.match(/-?\d+(?:\.\d+)?px/gi) || [], [l = "0px", a = "0px", m = "0px"] = s, u = n.replace(/-?\d+(?:\.\d+)?px/gi, "").replace(/\binset\b/ig, "").trim().replace(/\s{2,}/g, " "), d = !!u && u !== ",";
31
- o.push(`drop-shadow(${l} ${a} ${m}${d ? ` ${u}` : ""})`);
32
- }
33
- return o.join(" ");
34
- }
35
- function y(e) {
36
- let r = F(e), t = null, i = null, o = null, n = [];
37
- for (let l of r) {
38
- let a = l.indexOf(":");
39
- if (a < 0) continue;
40
- let m = l.slice(0, a).trim().toLowerCase(), u = l.slice(a + 1).trim();
41
- m === "box-shadow" ? o = u : m === "filter" ? t = u : m === "-webkit-filter" ? i = u : n.push([m, u]);
42
- }
43
- if (o) {
44
- let l = k(o);
45
- l && (t = t ? `${t} ${l}` : l, i = i ? `${i} ${l}` : l);
46
- }
47
- let s = [...n];
48
- return t && s.push(["filter", t]), i && s.push(["-webkit-filter", i]), s.map(([l, a]) => `${l}:${a}`).join(";");
49
- }
50
- function I(e) {
51
- return e.replace(/([^{}]+)\{([^}]*)\}/g, (r, t, i) => `${t}{${y(i)}}`);
52
- }
53
- function N(e) {
54
- return e = e.replace(/<style[^>]*>([\s\S]*?)<\/style>/gi, (r, t) => r.replace(t, I(t))), e = e.replace(/style=(['"])([\s\S]*?)\1/gi, (r, t, i) => `style=${t}${y(i)}${t}`), e;
55
- }
56
- function S(e) {
57
- if (!b() || !M(e)) return e;
58
- try {
59
- let r = C(e), t = N(r);
60
- return v(t);
61
- } catch {
62
- return e;
63
- }
64
- }
65
- async function R(e, r) {
66
- let { width: t, height: i, scale: o = 1, dpr: n = 1, meta: s = {}, backgroundColor: l } = r;
67
- e = S(e);
68
- let a = new Image();
69
- a.loading = "eager", a.decoding = "sync", a.crossOrigin = "anonymous", a.src = e, await a.decode();
70
- let m = a.naturalWidth, u = a.naturalHeight, d = Number.isFinite(s.w0) ? s.w0 : m, x = Number.isFinite(s.h0) ? s.h0 : u, c, f, $ = Number.isFinite(t), w = Number.isFinite(i);
71
- if ($ && w) c = Math.max(1, t), f = Math.max(1, i);
72
- else if ($) {
73
- let g = t / Math.max(1, d);
74
- c = t, f = x * g;
75
- } else if (w) {
76
- let g = i / Math.max(1, x);
77
- f = i, c = d * g;
78
- } else c = m, f = u;
79
- c = c * o, f = f * o;
80
- let h = document.createElement("canvas");
81
- h.width = c * n, h.height = f * n, h.style.width = `${c}px`, h.style.height = `${f}px`;
82
- let p = h.getContext("2d");
83
- return n !== 1 && p.scale(n, n), l && (p.save(), p.fillStyle = l, p.fillRect(0, 0, c, f), p.restore()), p.drawImage(a, 0, 0, c, f), h;
84
- }
85
- export {
86
- R as W
87
- };
@@ -1,8 +0,0 @@
1
- import { W as a } from "./chunk-MW6X4KTL-BGX4AdvZ.js";
2
- async function o(r, t) {
3
- let i = await a(r, t), e = new Image();
4
- return e.src = i.toDataURL(`image/${t.format}`, t.quality), await e.decode(), e.style.width = `${i.width / t.dpr}px`, e.style.height = `${i.height / t.dpr}px`, e;
5
- }
6
- export {
7
- o as d
8
- };
@@ -1,13 +0,0 @@
1
- import { W as m } from "./chunk-MW6X4KTL-BGX4AdvZ.js";
2
- async function a(n, e) {
3
- let o = e.type;
4
- if (o === "svg") {
5
- let t = decodeURIComponent(n.split(",")[1]);
6
- return new Blob([t], { type: "image/svg+xml" });
7
- }
8
- let i = await m(n, e);
9
- return new Promise((t) => i.toBlob((l) => t(l), `image/${o}`, e.quality));
10
- }
11
- export {
12
- a as m
13
- };
@@ -1,297 +0,0 @@
1
-
2
- @media print {
3
- body {
4
- margin: 0px;
5
- padding: 0px;
6
- }
7
- }
8
-
9
- @page {
10
- margin: 0;
11
- }
12
-
13
- .hiprint-printPaper * {
14
- box-sizing: border-box;
15
- -moz-box-sizing: border-box; /* Firefox */
16
- -webkit-box-sizing: border-box; /* Safari */
17
- image-rendering: -webkit-optimize-contrast; /* 让图片/标尺稍微清楚一点 */
18
- }
19
-
20
- .hiprint-printPaper *:focus {
21
- outline: -webkit-focus-ring-color auto 0px;
22
- }
23
-
24
-
25
- .hiprint-page-break-avoid {
26
- page-break-after: avoid;
27
- }
28
- .hiprint-printPaper {
29
- position: relative;
30
- padding: 0 0 0 0;
31
- page-break-after: always;
32
- -webkit-user-select: none; /* Chrome/Safari/Opera */
33
- -moz-user-select: none; /* Firefox */
34
- user-select: none;
35
- overflow-x: hidden;
36
- overflow: hidden;
37
- }
38
- .hiprint-printPaper .hiprint-printPaper-content {
39
- position: relative;
40
- }
41
- .hiprint-printPaper.design {
42
- overflow: visible;
43
- }
44
-
45
-
46
-
47
- .hiprint-printTemplate .hiprint-printPanel {
48
- page-break-after: always;
49
- }
50
-
51
- .hiprint-printPaper, hiprint-printPanel {
52
- box-sizing: border-box;
53
- border: 0px;
54
- }
55
-
56
- .hiprint-printPanel .hiprint-printPaper:last-child {
57
- page-break-after: avoid;
58
- }
59
-
60
- .hiprint-printTemplate .hiprint-printPanel:last-child {
61
- page-break-after: avoid;
62
- }
63
-
64
- .hiprint-printPaper .hideheaderLinetarget {
65
- border-top: 0px dashed rgb(201, 190, 190) !important;
66
- }
67
-
68
- .hiprint-printPaper .hidefooterLinetarget {
69
- border-top: 0px dashed rgb(201, 190, 190) !important;
70
- }
71
-
72
- .hiprint-printPaper.design {
73
- border: 1px dashed rgba(170,170,170,0.7);
74
- }
75
-
76
- .design .hiprint-printElement-table-content, .design .hiprint-printElement-longText-content {
77
- overflow: hidden;
78
- box-sizing: border-box;
79
- }
80
-
81
- .design .resize-panel {
82
- box-sizing: border-box;
83
- border: 1px dotted;
84
- }
85
-
86
- .hiprint-printElement-text {
87
- background-color: transparent;
88
- background-repeat: repeat;
89
- padding: 0 0 0 0;
90
- border: 0.75pt none rgb(0,0,0);
91
- direction: ltr;
92
- font-family: 'SimSun';
93
- font-size: 9pt;
94
- font-style: normal;
95
- font-weight: normal;
96
- padding-bottom: 0pt;
97
- padding-left: 0pt;
98
- padding-right: 0pt;
99
- padding-top: 0pt;
100
- text-align: left;
101
- text-decoration: none;
102
- line-height: 9.75pt;
103
- box-sizing: border-box;
104
- word-wrap: break-word;
105
- word-break: break-all;
106
- }
107
-
108
- .design .hiprint-printElement-text-content {
109
- border: 1px dashed rgb(206, 188, 188);
110
- box-sizing: border-box;
111
- }
112
-
113
- .hiprint-printElement-longText {
114
- background-color: transparent;
115
- background-repeat: repeat;
116
- border: 0.75pt none rgb(0,0,0);
117
- direction: ltr;
118
- font-family: 'SimSun';
119
- font-size: 9pt;
120
- font-style: normal;
121
- font-weight: normal;
122
- padding-bottom: 0pt;
123
- padding-left: 0pt;
124
- padding-right: 0pt;
125
- padding-top: 0pt;
126
- text-align: left;
127
- text-decoration: none;
128
- line-height: 9.75pt;
129
- box-sizing: border-box;
130
- word-wrap: break-word;
131
- word-break: break-all;
132
- /*white-space: pre-wrap*/
133
- }
134
-
135
-
136
-
137
- .hiprint-printElement-table {
138
- background-color: transparent;
139
- background-repeat: repeat;
140
- color: rgb(0,0,0);
141
- border-color: rgb(0,0,0);
142
- border-style: none;
143
- direction: ltr;
144
- font-family: 'SimSun';
145
- font-size: 9pt;
146
- font-style: normal;
147
- font-weight: normal;
148
- padding-bottom: 0pt;
149
- padding-left: 0pt;
150
- padding-right: 0pt;
151
- padding-top: 0pt;
152
- text-align: left;
153
- text-decoration: none;
154
- padding: 0 0 0 0;
155
- box-sizing: border-box;
156
- line-height: 9.75pt;
157
- }
158
-
159
- .hiprint-printElement-table thead {
160
- background: #e8e8e8;
161
- font-weight: 700;
162
- }
163
-
164
- .hiprint-printElement-tableTarget, .hiprint-printElement-tableTarget tr, .hiprint-printElement-tableTarget td {
165
- border-color: rgb(0,0,0);
166
- /*border-style: none;*/
167
- /*border: 1px solid rgb(0,0,0);*/
168
- font-weight: normal;
169
- direction: ltr;
170
- padding-bottom: 0pt;
171
- padding-left: 4pt;
172
- padding-right: 4pt;
173
- padding-top: 0pt;
174
- text-decoration: none;
175
- vertical-align: middle;
176
- box-sizing: border-box;
177
- word-wrap: break-word;
178
- word-break: break-all;
179
- /*line-height: 9.75pt;
180
- font-size: 9pt;*/
181
- }
182
-
183
- /*.hiprint-printElement-tableTarget tr,*/
184
- .hiprint-printElement-tableTarget td {
185
- height: 18pt;
186
- }
187
-
188
- /* 边框样式(用于打印时保持边框) */
189
- table.hiprint-printElement-tableTarget { width: 100%; }
190
- .hiprint-printElement-tableTarget-border-all { border: 1px solid; }
191
- .hiprint-printElement-tableTarget-border-none { border: 0px solid; }
192
- .hiprint-printElement-tableTarget-border-lr { border-left: 1px solid; border-right: 1px solid; }
193
- .hiprint-printElement-tableTarget-border-left { border-left: 1px solid; }
194
- .hiprint-printElement-tableTarget-border-right { border-right: 1px solid; }
195
- .hiprint-printElement-tableTarget-border-tb { border-top: 1px solid; border-bottom: 1px solid; }
196
- .hiprint-printElement-tableTarget-border-top { border-top: 1px solid; }
197
- .hiprint-printElement-tableTarget-border-bottom { border-bottom: 1px solid; }
198
- .hiprint-printElement-tableTarget-border-td-none td { border: 0px solid; }
199
- .hiprint-printElement-tableTarget-border-td-all td:not(:nth-last-child(-n+2)) { border-right: 1px solid; }
200
- .hiprint-printElement-tableTarget-border-td-all td { border-left: 1px solid; }
201
- .hiprint-printElement-tableTarget-border-td-all td:last-child:first-child { border-left: none; }
202
-
203
- .hiprint-printPaper .hiprint-paperNumber {
204
- font-size: 9pt;
205
- }
206
-
207
- .design .hiprint-printElement-table-handle {
208
- position: absolute;
209
- height: 12pt;
210
- width: 12pt;
211
- background: red;
212
- z-index:1;
213
- }
214
-
215
- .hiprint-printPaper .hiprint-paperNumber-disabled {
216
- float: right !important;
217
- right: 0 !important;
218
- color: gainsboro !important;
219
- }
220
-
221
- .hiprint-printElement-vline, .hiprint-printElement-hline {
222
- border: 0px none rgb(0,0,0);
223
-
224
- }
225
- .hiprint-printElement-vline {
226
- border-left: 0.75pt solid #000;
227
- border-right: 0px none rgb(0,0,0) !important;
228
- border-bottom: 0px none rgb(0,0,0) !important;
229
- border-top: 0px none rgb(0,0,0) !important;
230
- }
231
-
232
- .hiprint-printElement-hline {
233
- border-top: 0.75pt solid #000;
234
- border-right: 0px none rgb(0,0,0) !important;
235
- border-bottom: 0px none rgb(0,0,0) !important;
236
- border-left: 0px none rgb(0,0,0) !important;
237
- }
238
-
239
- .hiprint-printElement-oval, .hiprint-printElement-rect {
240
- border: 0.75pt solid #000;
241
- }
242
-
243
- .hiprint-text-content-middle {
244
- display:table;
245
- }
246
- .hiprint-text-content-middle>div {
247
- display: table-cell;
248
- vertical-align:middle
249
- }
250
-
251
- .hiprint-text-content-bottom {
252
- display: table;
253
- }
254
-
255
- .hiprint-text-content-bottom > div {
256
- display: table-cell;
257
- vertical-align: bottom
258
- }
259
-
260
- /*hi-grid-row */
261
- .hi-grid-row {
262
- position: relative;
263
- height: auto;
264
- margin-right: 0;
265
- margin-left: 0;
266
- zoom: 1;
267
- display: block;
268
- box-sizing: border-box;
269
- }
270
-
271
- .hi-grid-row::after, .hi-grid-row::before {
272
- display: table;
273
- content: '';
274
- box-sizing: border-box;
275
- }
276
-
277
- .hi-grid-col {
278
- display: block;
279
- box-sizing: border-box;
280
- position: relative;
281
- float: left;
282
- flex: 0 0 auto;
283
- }
284
-
285
- .table-grid-row {
286
- margin-left: -0pt;
287
- margin-right: -0pt;
288
- }
289
-
290
- .tableGridColumnsGutterRow {
291
- padding-left: 0pt;
292
- padding-right: 0pt;
293
- }
294
- .hiprint-gridColumnsFooter {
295
- text-align: left;
296
- clear: both;
297
- }
@@ -1,15 +0,0 @@
1
- import { m as f } from "./chunk-Y7FY32AO-CBomeJj8.js";
2
- import { W as t } from "./chunk-MW6X4KTL-BGX4AdvZ.js";
3
- async function w(n, e) {
4
- let c = ((e == null ? void 0 : e.format) || (e == null ? void 0 : e.type) || "").toLowerCase(), a = c === "jpg" ? "jpeg" : c || "png", i = (e == null ? void 0 : e.filename) || `snapdom.${a}`, o = { ...e || {}, format: a, type: a };
5
- if (o.dpr = 1, a === "svg") {
6
- let d = await f(n, { ...o, type: "svg" }), l = URL.createObjectURL(d), m = document.createElement("a");
7
- m.href = l, m.download = i, m.click(), URL.revokeObjectURL(l);
8
- return;
9
- }
10
- let p = await t(n, o), r = document.createElement("a");
11
- r.href = p.toDataURL(`image/${a}`, e == null ? void 0 : e.quality), r.download = i, r.click();
12
- }
13
- export {
14
- w as download
15
- };
package/dist/favicon.ico DELETED
Binary file