message-verify 1.0.1-beta.37 → 1.0.1-beta.39

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/dist/index.d.ts CHANGED
@@ -1,4 +1,31 @@
1
1
  import { ModalConfig, LoginModalConfig } from './utils/type.js';
2
+ import React from 'react';
2
3
  export declare const initFingerprint: () => Promise<string>;
3
4
  export declare const createMessageVerifyModal: (modalProps: ModalConfig) => void;
4
5
  export declare const createReLoginModal: (modalProps: LoginModalConfig) => void;
6
+ export declare class VerifyHandler extends React.Component {
7
+ private verifyPromise;
8
+ createPromise: (detail: any, config: RequestConfig, http: HttpInstance) => Promise<any>;
9
+ private handlePromiseReset;
10
+ render(): null;
11
+ }
12
+ type RequestConfig = {
13
+ hideLoading?: boolean;
14
+ responseType?: string;
15
+ };
16
+ type HttpInstance = {
17
+ defaults: {
18
+ headers: {
19
+ common: Record<string, string>;
20
+ };
21
+ };
22
+ interceptors: {
23
+ request: {
24
+ use: (handler: (config: RequestConfig) => RequestConfig) => void;
25
+ };
26
+ response: {
27
+ use: (handler: (response: any) => any) => void;
28
+ };
29
+ };
30
+ };
31
+ export {};
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import ReactDOM from 'react-dom/client';
3
3
  import VerifyModal from './verify-modal.js';
4
4
  import Fingerprint2 from 'fingerprintjs2';
5
5
  import ReLoginModal from './relogin-modal.js';
6
+ import React from 'react';
6
7
  let fingerprintPromise = null; // 用 Promise 本身作为缓存
7
8
  export const initFingerprint = async () => {
8
9
  console.log('fingerprintPromise:', fingerprintPromise);
@@ -17,6 +18,7 @@ export const initFingerprint = async () => {
17
18
  .join('###');
18
19
  console.log('values:', values);
19
20
  const fingerprint = Fingerprint2.x64hash128(values, 31);
21
+ console.log('fingerprint:', fingerprint);
20
22
  resolve(fingerprint);
21
23
  });
22
24
  });
@@ -54,3 +56,27 @@ const destroyModal = () => {
54
56
  modalRoot = null;
55
57
  }
56
58
  };
59
+ export class VerifyHandler extends React.Component {
60
+ verifyPromise = null;
61
+ createPromise = (detail, config, http) => {
62
+ if (!this.verifyPromise) {
63
+ this.verifyPromise = new Promise((resolve, reject) => {
64
+ createMessageVerifyModal({
65
+ data: detail,
66
+ config,
67
+ http,
68
+ apiResolve: resolve,
69
+ apiReject: reject,
70
+ apiPromiseToEmpty: this.handlePromiseReset,
71
+ });
72
+ }).finally(this.handlePromiseReset);
73
+ }
74
+ return this.verifyPromise;
75
+ };
76
+ handlePromiseReset = () => {
77
+ this.verifyPromise = null;
78
+ };
79
+ render() {
80
+ return null; // 纯逻辑组件不需要渲染
81
+ }
82
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "1.0.1-beta.37",
3
+ "version": "1.0.1-beta.39",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
package/src/index.tsx CHANGED
@@ -3,6 +3,7 @@ import VerifyModal from './verify-modal.js'
3
3
  import Fingerprint2 from 'fingerprintjs2';
4
4
  import ReLoginModal from './relogin-modal.js';
5
5
  import { ModalConfig, LoginModalConfig } from './utils/type.js';
6
+ import React from 'react';
6
7
 
7
8
  let fingerprintPromise: Promise<string> | null = null; // 用 Promise 本身作为缓存
8
9
 
@@ -19,6 +20,7 @@ export const initFingerprint = async (): Promise<string> => {
19
20
  .join('###');
20
21
  console.log('values:', values);
21
22
  const fingerprint = Fingerprint2.x64hash128(values, 31);
23
+ console.log('fingerprint:', fingerprint);
22
24
  resolve(fingerprint);
23
25
  });
24
26
  });
@@ -29,44 +31,95 @@ export const initFingerprint = async (): Promise<string> => {
29
31
  let modalRoot: ReactDOM.Root | null = null
30
32
 
31
33
  export const createMessageVerifyModal = (modalProps: ModalConfig) => {
32
- const container = document.createElement('div')
33
- container.id = 'antd-modal-container'
34
- document.body.appendChild(container)
34
+ const container = document.createElement('div')
35
+ container.id = 'antd-modal-container'
36
+ document.body.appendChild(container)
35
37
 
36
- modalRoot = ReactDOM.createRoot(container)
37
- modalRoot.render(
38
- <VerifyModal
39
- props={{
40
- ...modalProps,
41
- onClose: () => {
42
- modalProps.onClose?.()
43
- destroyModal()
44
- }
45
- }}
46
- />
47
- )
38
+ modalRoot = ReactDOM.createRoot(container)
39
+ modalRoot.render(
40
+ <VerifyModal
41
+ props={{
42
+ ...modalProps,
43
+ onClose: () => {
44
+ modalProps.onClose?.()
45
+ destroyModal()
46
+ }
47
+ }}
48
+ />
49
+ )
48
50
  }
49
51
 
50
52
  // 新增 relogin 弹窗创建方法
51
53
  export const createReLoginModal = (modalProps: LoginModalConfig) => {
52
- const container = document.createElement('div')
53
- container.id = 'antd-modal-container'
54
- document.body.appendChild(container)
54
+ const container = document.createElement('div')
55
+ container.id = 'antd-modal-container'
56
+ document.body.appendChild(container)
55
57
 
56
- modalRoot = ReactDOM.createRoot(container)
57
- modalRoot.render(
58
- <ReLoginModal
59
- props={{
60
- ...modalProps,
61
- }}
62
- />
63
- )
58
+ modalRoot = ReactDOM.createRoot(container)
59
+ modalRoot.render(
60
+ <ReLoginModal
61
+ props={{
62
+ ...modalProps,
63
+ }}
64
+ />
65
+ )
64
66
  }
65
67
 
66
68
  const destroyModal = () => {
67
- if (modalRoot) {
68
- modalRoot.unmount()
69
- document.getElementById('antd-modal-container')?.remove()
70
- modalRoot = null
69
+ if (modalRoot) {
70
+ modalRoot.unmount()
71
+ document.getElementById('antd-modal-container')?.remove()
72
+ modalRoot = null
73
+ }
74
+ }
75
+
76
+ export class VerifyHandler extends React.Component {
77
+ private verifyPromise: Promise<any> | null = null;
78
+
79
+ createPromise = (detail: any, config: RequestConfig, http: HttpInstance): Promise<any> => {
80
+ if (!this.verifyPromise) {
81
+ this.verifyPromise = new Promise((resolve, reject) => {
82
+ createMessageVerifyModal({
83
+ data: detail,
84
+ config,
85
+ http,
86
+ apiResolve: resolve,
87
+ apiReject: reject,
88
+ apiPromiseToEmpty: this.handlePromiseReset,
89
+ } as any);
90
+ }).finally(this.handlePromiseReset);
91
+ }
92
+ return this.verifyPromise;
93
+ };
94
+
95
+ private handlePromiseReset = (): void => {
96
+ this.verifyPromise = null;
97
+ };
98
+
99
+ render() {
100
+ return null; // 纯逻辑组件不需要渲染
71
101
  }
72
- }
102
+ }
103
+
104
+ // 类型定义
105
+ type RequestConfig = {
106
+ hideLoading?: boolean;
107
+ responseType?: string;
108
+ // 根据实际需求扩展其他配置项
109
+ };
110
+
111
+ type HttpInstance = {
112
+ defaults: {
113
+ headers: {
114
+ common: Record<string, string>;
115
+ };
116
+ };
117
+ interceptors: {
118
+ request: {
119
+ use: (handler: (config: RequestConfig) => RequestConfig) => void;
120
+ };
121
+ response: {
122
+ use: (handler: (response: any) => any) => void;
123
+ };
124
+ };
125
+ };