ai.touchui-vue 1.39.0 → 1.40.0

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.
@@ -7,8 +7,8 @@ function getBody(areaId) {
7
7
  html.push(document.getElementById(areaId).outerHTML);
8
8
  html.push('</div></div>');
9
9
  html.push('<div id="printFn" class="fn">\r\n');
10
- html.push('<button type="button" onclick="javascript:window.close();" class="to-button to-box-link to-form-readonly to-box-color-default to-box-mode-fill to-input-fillet-normal"><span class="to-icon-close to-box-color-default"><span style="font-size: 100%;"></span></span><span class="to-buttonText to-hide-keep">关闭</span></button>')
11
- html.push('<button type="button" class="to-button to-box-link to-form-readonly to-box-color-primary to-box-mode-fill to-input-fillet-normal" onclick="javascript:window.print();"><span class="to-icon-print to-box-color-default"><span style="font-size: 100%;"></span></span><span class="to-buttonText to-hide-keep">打印</span></button>');
10
+ html.push('<button type="button" data-action="close" class="to-button to-box-link to-form-readonly to-box-color-default to-box-mode-fill to-input-fillet-normal"><span class="to-icon-close to-box-color-default"><span style="font-size: 100%;"></span></span><span class="to-buttonText to-hide-keep">关闭</span></button>')
11
+ html.push('<button type="button" data-action="print" class="to-button to-box-link to-form-readonly to-box-color-primary to-box-mode-fill to-input-fillet-normal"><span class="to-icon-print to-box-color-default"><span style="font-size: 100%;"></span></span><span class="to-buttonText to-hide-keep">打印2</span></button>');
12
12
  html.push('\r\n</div>');
13
13
  html.push('\r\n</div>');
14
14
  return html;
@@ -19,11 +19,9 @@ function replaceBodyContent(newContent) {
19
19
  const parser = new DOMParser();
20
20
  const doc = parser.parseFromString(htmlString, 'text/html');
21
21
 
22
- // 使用 DOMPurify 清理 HTML
22
+ // 使用 DOMPurify 清理 HTML(保留必要的安全规则)
23
23
  doc.body.innerHTML = DOMPurify.sanitize(newContent);
24
-
25
- const newHtmlString = doc.documentElement.outerHTML;
26
- return newHtmlString;
24
+ return doc.documentElement.outerHTML;
27
25
  }
28
26
 
29
27
  export default function(areaId, title) {
@@ -32,8 +30,24 @@ export default function(areaId, title) {
32
30
  pwin.document.write(replaceBodyContent(getBody(areaId).join('')));
33
31
  pwin.document.close();
34
32
  pwin.document.documentElement.classList.add('s_print');
33
+
34
+ // 绑定事件(事件委托)
35
+ pwin.document.addEventListener('click', function(e) {
36
+ const target = e.target.closest('[data-action]'); // 找到带 data-action 的按钮
37
+ if (!target) return;
38
+
39
+ const action = target.dataset.action;
40
+ switch (action) {
41
+ case 'close':
42
+ pwin.window.close(); // 关闭打印窗口
43
+ break;
44
+ case 'print':
45
+ pwin.window.print(); // 执行 print 逻辑
46
+ break;
47
+ }
48
+ });
49
+
35
50
  if (title && typeof title === 'string') {
36
51
  pwin.document.title = title;
37
52
  }
38
- pwin = null;
39
53
  }