ztxkutils 2.3.8 → 2.3.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.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @description 通过iframe双向通信逻辑
3
+ */
4
+ export declare function useOnmessage(messageFn: any): void;
5
+ /**
6
+ * @description 发送消息方法
7
+ * @param iframeWindow 窗口对象
8
+ * @param data 传递的数据
9
+ * @param targetOrigin 发送目标的origin,重要信息需要指定,防止截获
10
+ */
11
+ export declare function iframePostmessage(iframeWindow: any, data: any, targetOrigin?: any): void;
12
+ /**
13
+ * @description 是否显示框架
14
+ */
15
+ export declare function showFrame(): boolean;
@@ -0,0 +1,62 @@
1
+ import { useEffect } from 'react';
2
+ import { g as getUrlSearch } from './tools-d8a41730.js';
3
+ import { WORKFLOW_HIDEFRAME_KEY } from './constants.js';
4
+ import './tslib.es6-f9459658.js';
5
+ import 'dayjs';
6
+ import 'number-precision';
7
+
8
+ /**
9
+ * @description 审批工作流相关操作
10
+ */
11
+ /**
12
+ * @description 通过iframe双向通信逻辑
13
+ */
14
+ function useOnmessage(messageFn) {
15
+ useEffect(function () {
16
+ var messageHandle = function (e) {
17
+ console.log('父页面传递过来的消息', e);
18
+ var messageData = {};
19
+ try {
20
+ messageData = JSON.parse(e.data);
21
+ }
22
+ catch (err) {
23
+ console.log('父页面传递过来的消息解析报错', err);
24
+ }
25
+ messageFn && messageFn(messageData);
26
+ };
27
+ window.addEventListener('message', messageHandle);
28
+ return function () {
29
+ window.removeEventListener('message', messageHandle);
30
+ };
31
+ }, [messageFn]);
32
+ }
33
+ /**
34
+ * @description 发送消息方法
35
+ * @param iframeWindow 窗口对象
36
+ * @param data 传递的数据
37
+ * @param targetOrigin 发送目标的origin,重要信息需要指定,防止截获
38
+ */
39
+ function iframePostmessage(iframeWindow, data, targetOrigin) {
40
+ var _a;
41
+ if (targetOrigin === void 0) { targetOrigin = '*'; }
42
+ var postData = '{}';
43
+ try {
44
+ postData = JSON.stringify(data);
45
+ }
46
+ catch (err) {
47
+ console.log(err);
48
+ }
49
+ (_a = iframeWindow === null || iframeWindow === void 0 ? void 0 : iframeWindow.postMessage) === null || _a === void 0 ? void 0 : _a.call(iframeWindow, postData, targetOrigin);
50
+ }
51
+ /**
52
+ * @description 是否显示框架
53
+ */
54
+ function showFrame() {
55
+ var searchObj = getUrlSearch() || {};
56
+ if (searchObj[WORKFLOW_HIDEFRAME_KEY]) {
57
+ return false;
58
+ }
59
+ return true;
60
+ }
61
+
62
+ export { iframePostmessage, showFrame, useOnmessage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ztxkutils",
3
- "version": "2.3.8",
3
+ "version": "2.3.9",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",