@brushes/component-core 1.1.3 → 1.1.4
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/package.json +2 -1
- package/src/basic-component/container/index.tsx +6 -26
- package/src/basic-component/default/index.tsx +1 -6
- package/src/basic-component/empty/index.tsx +1 -6
- package/src/basic-component/index.tsx +1 -0
- package/src/basic-component/resizer/index.tsx +270 -0
- package/src/basic-component/resizer/numToMeasurement.ts +26 -0
- package/src/components/code.tsx +1 -5
- package/src/components/image.tsx +10 -8
- package/src/setting/title.tsx +0 -4
- package/src/tool/index.tsx +1 -0
- package/src/tool/sm2Crypto.ts +41 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brushes/component-core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"antd": "^5.24.5",
|
|
27
27
|
"lodash": "^4.17.21",
|
|
28
28
|
"react-error-boundary": "^4.0.11",
|
|
29
|
+
"sm-crypto": "^0.3.13",
|
|
29
30
|
"zustand": "^5.0.3"
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -56,10 +56,6 @@ export const IsShowContainer = ({
|
|
|
56
56
|
connectors: { connect, drag }
|
|
57
57
|
} = useNode();
|
|
58
58
|
|
|
59
|
-
const { custom } = useNode((node) => ({
|
|
60
|
-
custom: node.data.custom
|
|
61
|
-
}));
|
|
62
|
-
|
|
63
59
|
let [searchParams] = useSearchParams();
|
|
64
60
|
|
|
65
61
|
const nValue = useMemo(() => {
|
|
@@ -109,8 +105,7 @@ export const IsShowContainer = ({
|
|
|
109
105
|
<div
|
|
110
106
|
style={{
|
|
111
107
|
...margin,
|
|
112
|
-
...padding
|
|
113
|
-
...custom
|
|
108
|
+
...padding
|
|
114
109
|
}}
|
|
115
110
|
ref={(ref: HTMLDivElement) => connect(drag(ref))}
|
|
116
111
|
>
|
|
@@ -120,7 +115,7 @@ export const IsShowContainer = ({
|
|
|
120
115
|
}
|
|
121
116
|
};
|
|
122
117
|
|
|
123
|
-
export const Container = ({ width, text, children,
|
|
118
|
+
export const Container = ({ width, text, children, background, margin = {}, positionValue = {}, padding = {}, backgroundImage, position, $$_actions, $_actions, borderColor, ...props }: any) => {
|
|
124
119
|
// @ts-ignore
|
|
125
120
|
const { styles } = useStyles();
|
|
126
121
|
const { enabled } = useEditor((state) => ({
|
|
@@ -146,13 +141,9 @@ export const Container = ({ width, text, children, className, background, margin
|
|
|
146
141
|
connectors: { connect, drag }
|
|
147
142
|
} = useNode();
|
|
148
143
|
|
|
149
|
-
const { custom } = useNode((node) => ({
|
|
150
|
-
custom: node.data.custom
|
|
151
|
-
}));
|
|
152
|
-
|
|
153
144
|
return (
|
|
154
145
|
<div
|
|
155
|
-
className={
|
|
146
|
+
className={enabled ? styles.category : ''}
|
|
156
147
|
ref={(ref: HTMLDivElement) => connect(drag(ref))}
|
|
157
148
|
style={{
|
|
158
149
|
...margin,
|
|
@@ -164,8 +155,7 @@ export const Container = ({ width, text, children, className, background, margin
|
|
|
164
155
|
...props,
|
|
165
156
|
...positionNewValue,
|
|
166
157
|
background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
|
|
167
|
-
width: ((width + '').includes('%') || (width + '').includes('px')) ? width : `${width}px
|
|
168
|
-
...custom
|
|
158
|
+
width: ((width + '').includes('%') || (width + '').includes('px')) ? width : `${width}px`
|
|
169
159
|
}}
|
|
170
160
|
>
|
|
171
161
|
<Inner text={text} enabled={enabled}>
|
|
@@ -184,10 +174,6 @@ export const OutContainerComponent = ({ width, api, params, children, background
|
|
|
184
174
|
connectors: { connect, drag }
|
|
185
175
|
} = useNode();
|
|
186
176
|
|
|
187
|
-
const { custom } = useNode((node) => ({
|
|
188
|
-
custom: node.data.custom
|
|
189
|
-
}));
|
|
190
|
-
|
|
191
177
|
const { styles } = useStyles();
|
|
192
178
|
return (
|
|
193
179
|
<div
|
|
@@ -200,8 +186,7 @@ export const OutContainerComponent = ({ width, api, params, children, background
|
|
|
200
186
|
...padding,
|
|
201
187
|
...props,
|
|
202
188
|
background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
|
|
203
|
-
width: (width + '').includes('%') ? width : `${width}px
|
|
204
|
-
...custom
|
|
189
|
+
width: (width + '').includes('%') ? width : `${width}px`
|
|
205
190
|
}}
|
|
206
191
|
>
|
|
207
192
|
<Inner enabled={enabled}>{children}</Inner>
|
|
@@ -221,10 +206,6 @@ export const ContainerWrap = ({ width, background, children, backgroundImage, he
|
|
|
221
206
|
connectors: { connect, drag }
|
|
222
207
|
} = useNode();
|
|
223
208
|
|
|
224
|
-
const { custom } = useNode((node) => ({
|
|
225
|
-
custom: node.data.custom
|
|
226
|
-
}));
|
|
227
|
-
|
|
228
209
|
const { enabled } = useEditor((state) => ({
|
|
229
210
|
enabled: state.options.enabled
|
|
230
211
|
}));
|
|
@@ -236,8 +217,7 @@ export const ContainerWrap = ({ width, background, children, backgroundImage, he
|
|
|
236
217
|
width,
|
|
237
218
|
paddingBottom: 5,
|
|
238
219
|
background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
|
|
239
|
-
minHeight: `calc(${height}vh - 110px)
|
|
240
|
-
...custom
|
|
220
|
+
minHeight: `calc(${height}vh - 110px)`
|
|
241
221
|
}}
|
|
242
222
|
>
|
|
243
223
|
<Inner root={true} enabled={enabled}>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { QjIcon } from '@brushes/share-resource';
|
|
2
2
|
import { Watermark } from 'antd';
|
|
3
3
|
import { createStyles } from 'antd-style';
|
|
4
|
-
import { useNode } from '@craftjs/core';
|
|
5
4
|
|
|
6
5
|
const useStyle = createStyles(({ token, css }) => {
|
|
7
6
|
return {
|
|
@@ -25,9 +24,6 @@ const useStyle = createStyles(({ token, css }) => {
|
|
|
25
24
|
});
|
|
26
25
|
|
|
27
26
|
export const DefaultJsx = ({ text = '内容放置区域', root }: { text?: string; root?: boolean }) => {
|
|
28
|
-
const { custom } = useNode((node) => ({
|
|
29
|
-
custom: node.data.custom
|
|
30
|
-
}));
|
|
31
27
|
const { styles } = useStyle();
|
|
32
28
|
return (
|
|
33
29
|
<div
|
|
@@ -41,8 +37,7 @@ export const DefaultJsx = ({ text = '内容放置区域', root }: { text?: strin
|
|
|
41
37
|
fontSize: 50,
|
|
42
38
|
fontWeight: 500,
|
|
43
39
|
display: 'block',
|
|
44
|
-
color: '#bbb'
|
|
45
|
-
...custom,
|
|
40
|
+
color: '#bbb'
|
|
46
41
|
}}
|
|
47
42
|
name={'icon-computer'}
|
|
48
43
|
></QjIcon>
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { Typography } from 'antd';
|
|
2
|
-
import { useNode } from '@craftjs/core';
|
|
3
2
|
|
|
4
3
|
export const SlotEmpty: React.FC<{
|
|
5
4
|
children?: React.ReactNode;
|
|
6
5
|
borderColor?: string;
|
|
7
6
|
}> = ({ children = '当前为插槽容器,可以自定义组件代码。', borderColor = 'rgba(0, 0, 0, 0.1)' }) => {
|
|
8
|
-
const { custom } = useNode((node) => ({
|
|
9
|
-
custom: node.data.custom
|
|
10
|
-
}));
|
|
11
7
|
return (
|
|
12
8
|
<div
|
|
13
9
|
style={{
|
|
@@ -19,8 +15,7 @@ export const SlotEmpty: React.FC<{
|
|
|
19
15
|
fontSize: 12,
|
|
20
16
|
textAlign: 'center',
|
|
21
17
|
fontWeight: 'normal',
|
|
22
|
-
background: 'rgba(255,255,255, 0.2)'
|
|
23
|
-
...custom
|
|
18
|
+
background: 'rgba(255,255,255, 0.2)'
|
|
24
19
|
}}
|
|
25
20
|
>
|
|
26
21
|
<Typography.Text type="secondary">{children}</Typography.Text>
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// import { useNode, useEditor } from '@craftjs/core';
|
|
2
|
+
// import cx from 'classnames';
|
|
3
|
+
// import { debounce } from 'debounce';
|
|
4
|
+
// import { Resizable } from 're-resizable';
|
|
5
|
+
// import { useRef, useEffect, useState, useCallback } from 'react';
|
|
6
|
+
// import { styled } from 'styled-components';
|
|
7
|
+
//
|
|
8
|
+
// import {
|
|
9
|
+
// isPercentage,
|
|
10
|
+
// pxToPercent,
|
|
11
|
+
// percentToPx,
|
|
12
|
+
// getElementDimensions,
|
|
13
|
+
// } from './numToMeasurement';
|
|
14
|
+
//
|
|
15
|
+
// const Indicators = styled.div<{ $bound?: 'row' | 'column' }>`
|
|
16
|
+
// position: absolute;
|
|
17
|
+
// top: 0;
|
|
18
|
+
// left: 0;
|
|
19
|
+
// width: 100%;
|
|
20
|
+
// height: 100%;
|
|
21
|
+
// pointer-events: none;
|
|
22
|
+
// span {
|
|
23
|
+
// position: absolute;
|
|
24
|
+
// width: 8px;
|
|
25
|
+
// height: 8px;
|
|
26
|
+
// background: #fff;
|
|
27
|
+
// border-radius: 100%;
|
|
28
|
+
// display: block;
|
|
29
|
+
// box-shadow: 0px 0px 12px -1px rgba(0, 0, 0, 0.25);
|
|
30
|
+
// z-index: 99999;
|
|
31
|
+
// pointer-events: none;
|
|
32
|
+
// border: 2px solid #36a9e0;
|
|
33
|
+
// &:nth-child(1) {
|
|
34
|
+
// ${(props) =>
|
|
35
|
+
// props.$bound
|
|
36
|
+
// ? props.$bound === 'row'
|
|
37
|
+
// ? `
|
|
38
|
+
// left: 50%;
|
|
39
|
+
// top: -5px;
|
|
40
|
+
// transform:translateX(-50%);
|
|
41
|
+
// `
|
|
42
|
+
// : `
|
|
43
|
+
// top: 50%;
|
|
44
|
+
// left: -5px;
|
|
45
|
+
// transform:translateY(-50%);
|
|
46
|
+
// `
|
|
47
|
+
// : `
|
|
48
|
+
// left: -5px;
|
|
49
|
+
// top:-5px;
|
|
50
|
+
// `}
|
|
51
|
+
// }
|
|
52
|
+
// &:nth-child(2) {
|
|
53
|
+
// right: -5px;
|
|
54
|
+
// top: -5px;
|
|
55
|
+
// display: ${(props) => (props.$bound ? 'none' : 'block')};
|
|
56
|
+
// }
|
|
57
|
+
// &:nth-child(3) {
|
|
58
|
+
// ${(props) =>
|
|
59
|
+
// props.$bound
|
|
60
|
+
// ? props.$bound === 'row'
|
|
61
|
+
// ? `
|
|
62
|
+
// left: 50%;
|
|
63
|
+
// bottom: -3px;
|
|
64
|
+
// transform:translateX(-50%);
|
|
65
|
+
// `
|
|
66
|
+
// : `
|
|
67
|
+
// bottom: 50%;
|
|
68
|
+
// left: -5px;
|
|
69
|
+
// transform:translateY(-50%);
|
|
70
|
+
// `
|
|
71
|
+
// : `
|
|
72
|
+
// left: -5px;
|
|
73
|
+
// bottom:-3px;
|
|
74
|
+
// `}
|
|
75
|
+
// }
|
|
76
|
+
// &:nth-child(4) {
|
|
77
|
+
// bottom: -3px;
|
|
78
|
+
// right: -5px;
|
|
79
|
+
// display: ${(props) => (props.$bound ? 'none' : 'block')};
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
// `;
|
|
83
|
+
//
|
|
84
|
+
// export const Resizer = ({ propKey = { width: 'width', height: 'height' }, children, ...props }: any) => {
|
|
85
|
+
// const {
|
|
86
|
+
// id,
|
|
87
|
+
// actions: { setProp },
|
|
88
|
+
// connectors: { connect },
|
|
89
|
+
// fillSpace,
|
|
90
|
+
// nodeWidth,
|
|
91
|
+
// nodeHeight,
|
|
92
|
+
// parent,
|
|
93
|
+
// active,
|
|
94
|
+
// inNodeContext,
|
|
95
|
+
// } = useNode((node) => {
|
|
96
|
+
// return {
|
|
97
|
+
// parent: node.data.parent,
|
|
98
|
+
// active: node.events.selected,
|
|
99
|
+
// nodeWidth: node.data.props[propKey.width],
|
|
100
|
+
// nodeHeight: node.data.props[propKey.height],
|
|
101
|
+
// fillSpace: node.data.props.fillSpace,
|
|
102
|
+
// }
|
|
103
|
+
// });
|
|
104
|
+
// const { isRootNode, parentDirection } = useEditor((state, query) => {
|
|
105
|
+
// return {
|
|
106
|
+
// parentDirection:
|
|
107
|
+
// parent &&
|
|
108
|
+
// state.nodes[parent] &&
|
|
109
|
+
// state.nodes[parent].data.props.flexDirection,
|
|
110
|
+
// isRootNode: query.node(id).isRoot(),
|
|
111
|
+
// };
|
|
112
|
+
// });
|
|
113
|
+
//
|
|
114
|
+
// const resizable = useRef<Resizable>(null);
|
|
115
|
+
// const isResizing = useRef<Boolean>(false);
|
|
116
|
+
// const editingDimensions = useRef<any>(null);
|
|
117
|
+
// const nodeDimensions = useRef(null);
|
|
118
|
+
// nodeDimensions.current = { width: nodeWidth, height: nodeHeight };
|
|
119
|
+
//
|
|
120
|
+
// /**
|
|
121
|
+
// * Using an internal value to ensure the width/height set in the node is converted to px
|
|
122
|
+
// * because for some reason the <re-resizable /> library does not work well with percentages.
|
|
123
|
+
// */
|
|
124
|
+
// const [internalDimensions, setInternalDimensions] = useState({
|
|
125
|
+
// width: nodeWidth,
|
|
126
|
+
// height: nodeHeight,
|
|
127
|
+
// });
|
|
128
|
+
//
|
|
129
|
+
// const updateInternalDimensionsInPx = useCallback(() => {
|
|
130
|
+
// const { width: nodeWidth, height: nodeHeight } = nodeDimensions.current;
|
|
131
|
+
// const width = percentToPx(
|
|
132
|
+
// nodeWidth,
|
|
133
|
+
// resizable.current &&
|
|
134
|
+
// getElementDimensions(resizable.current.resizable.parentElement).width
|
|
135
|
+
// );
|
|
136
|
+
// const height = percentToPx(
|
|
137
|
+
// nodeHeight,
|
|
138
|
+
// resizable.current &&
|
|
139
|
+
// getElementDimensions(resizable.current.resizable.parentElement).height
|
|
140
|
+
// );
|
|
141
|
+
//
|
|
142
|
+
// setInternalDimensions({
|
|
143
|
+
// width,
|
|
144
|
+
// height,
|
|
145
|
+
// });
|
|
146
|
+
// }, []);
|
|
147
|
+
//
|
|
148
|
+
// const updateInternalDimensionsWithOriginal = useCallback(() => {
|
|
149
|
+
// const { width: nodeWidth, height: nodeHeight } = nodeDimensions.current;
|
|
150
|
+
// setInternalDimensions({
|
|
151
|
+
// width: nodeWidth,
|
|
152
|
+
// height: nodeHeight,
|
|
153
|
+
// });
|
|
154
|
+
// }, []);
|
|
155
|
+
//
|
|
156
|
+
// const getUpdatedDimensions = (width, height) => {
|
|
157
|
+
// const dom = resizable.current.resizable;
|
|
158
|
+
// if (!dom) return;
|
|
159
|
+
//
|
|
160
|
+
// const currentWidth = parseInt(editingDimensions.current.width),
|
|
161
|
+
// currentHeight = parseInt(editingDimensions.current.height);
|
|
162
|
+
//
|
|
163
|
+
// return {
|
|
164
|
+
// width: currentWidth + parseInt(width),
|
|
165
|
+
// height: currentHeight + parseInt(height),
|
|
166
|
+
// };
|
|
167
|
+
// };
|
|
168
|
+
//
|
|
169
|
+
// useEffect(() => {
|
|
170
|
+
// if (!isResizing.current) updateInternalDimensionsWithOriginal();
|
|
171
|
+
// }, [nodeWidth, nodeHeight, updateInternalDimensionsWithOriginal]);
|
|
172
|
+
//
|
|
173
|
+
// useEffect(() => {
|
|
174
|
+
// const listener = debounce(updateInternalDimensionsWithOriginal, 1);
|
|
175
|
+
// window.addEventListener('resize', listener);
|
|
176
|
+
//
|
|
177
|
+
// return () => {
|
|
178
|
+
// window.removeEventListener('resize', listener);
|
|
179
|
+
// };
|
|
180
|
+
// }, [updateInternalDimensionsWithOriginal]);
|
|
181
|
+
//
|
|
182
|
+
// return (
|
|
183
|
+
// <Resizable
|
|
184
|
+
// enable={[
|
|
185
|
+
// 'top',
|
|
186
|
+
// 'left',
|
|
187
|
+
// 'bottom',
|
|
188
|
+
// 'right',
|
|
189
|
+
// 'topLeft',
|
|
190
|
+
// 'topRight',
|
|
191
|
+
// 'bottomLeft',
|
|
192
|
+
// 'bottomRight',
|
|
193
|
+
// ].reduce((acc: any, key) => {
|
|
194
|
+
// acc[key] = active && inNodeContext;
|
|
195
|
+
// return acc;
|
|
196
|
+
// }, {})}
|
|
197
|
+
// style={{margin: '0 auto'}}
|
|
198
|
+
// className={cx([
|
|
199
|
+
// {
|
|
200
|
+
// 'm-auto': isRootNode,
|
|
201
|
+
// flex: true,
|
|
202
|
+
// },
|
|
203
|
+
// ])}
|
|
204
|
+
// ref={(ref) => {
|
|
205
|
+
// if (ref) {
|
|
206
|
+
// resizable.current = ref;
|
|
207
|
+
// connect(resizable.current.resizable);
|
|
208
|
+
// }
|
|
209
|
+
// }}
|
|
210
|
+
// size={internalDimensions}
|
|
211
|
+
// onResizeStart={(e) => {
|
|
212
|
+
// updateInternalDimensionsInPx();
|
|
213
|
+
// e.preventDefault();
|
|
214
|
+
// e.stopPropagation();
|
|
215
|
+
// const dom = resizable.current.resizable;
|
|
216
|
+
// if (!dom) return;
|
|
217
|
+
// editingDimensions.current = {
|
|
218
|
+
// width: dom.getBoundingClientRect().width,
|
|
219
|
+
// height: dom.getBoundingClientRect().height,
|
|
220
|
+
// };
|
|
221
|
+
// isResizing.current = true;
|
|
222
|
+
// }}
|
|
223
|
+
// onResize={(_, __, ___, d) => {
|
|
224
|
+
// const dom = resizable.current.resizable;
|
|
225
|
+
// let { width, height }: any = getUpdatedDimensions(d.width, d.height);
|
|
226
|
+
// if (isPercentage(nodeWidth))
|
|
227
|
+
// width =
|
|
228
|
+
// pxToPercent(width, getElementDimensions(dom.parentElement).width) +
|
|
229
|
+
// '%';
|
|
230
|
+
// else width = `${width}px`;
|
|
231
|
+
//
|
|
232
|
+
// if (isPercentage(nodeHeight))
|
|
233
|
+
// height =
|
|
234
|
+
// pxToPercent(
|
|
235
|
+
// height,
|
|
236
|
+
// getElementDimensions(dom.parentElement).height
|
|
237
|
+
// ) + '%';
|
|
238
|
+
// else height = `${height}px`;
|
|
239
|
+
//
|
|
240
|
+
// if (isPercentage(width) && dom.parentElement.style.width === 'auto') {
|
|
241
|
+
// width = editingDimensions.current.width + d.width + 'px';
|
|
242
|
+
// }
|
|
243
|
+
//
|
|
244
|
+
// if (isPercentage(height) && dom.parentElement.style.height === 'auto') {
|
|
245
|
+
// height = editingDimensions.current.height + d.height + 'px';
|
|
246
|
+
// }
|
|
247
|
+
//
|
|
248
|
+
// setProp((prop: any) => {
|
|
249
|
+
// prop[propKey.width] = width;
|
|
250
|
+
// prop[propKey.height] = height;
|
|
251
|
+
// }, 500);
|
|
252
|
+
// }}
|
|
253
|
+
// onResizeStop={() => {
|
|
254
|
+
// isResizing.current = false;
|
|
255
|
+
// updateInternalDimensionsWithOriginal();
|
|
256
|
+
// }}
|
|
257
|
+
// {...props}
|
|
258
|
+
// >
|
|
259
|
+
// {children}
|
|
260
|
+
// {active && (
|
|
261
|
+
// <Indicators $bound={fillSpace === 'yes' ? parentDirection : false}>
|
|
262
|
+
// <span></span>
|
|
263
|
+
// <span></span>
|
|
264
|
+
// <span></span>
|
|
265
|
+
// <span></span>
|
|
266
|
+
// </Indicators>
|
|
267
|
+
// )}
|
|
268
|
+
// </Resizable>
|
|
269
|
+
// );
|
|
270
|
+
// };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const isPercentage = (val: string) => typeof val === 'string' && val.indexOf('%') > -1;
|
|
2
|
+
|
|
3
|
+
export const percentToPx = (value: any, comparativeValue: number) => {
|
|
4
|
+
if (value.indexOf('px') > -1 || value === 'auto' || !comparativeValue) return value;
|
|
5
|
+
const percent = parseInt(value);
|
|
6
|
+
return (percent / 100) * comparativeValue + 'px';
|
|
7
|
+
};
|
|
8
|
+
export const pxToPercent = (value: any, comparativeValue: number) => {
|
|
9
|
+
const val = (Math.abs(value) / comparativeValue) * 100;
|
|
10
|
+
if (value < 0) return -1 * val;
|
|
11
|
+
else return Math.round(val);
|
|
12
|
+
};
|
|
13
|
+
export const getElementDimensions = (element: HTMLElement) => {
|
|
14
|
+
const computedStyle = getComputedStyle(element);
|
|
15
|
+
|
|
16
|
+
let height = element.clientHeight,
|
|
17
|
+
width = element.clientWidth; // width with padding
|
|
18
|
+
|
|
19
|
+
height -= parseFloat(computedStyle.paddingTop) + parseFloat(computedStyle.paddingBottom);
|
|
20
|
+
width -= parseFloat(computedStyle.paddingLeft) + parseFloat(computedStyle.paddingRight);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
width,
|
|
24
|
+
height
|
|
25
|
+
};
|
|
26
|
+
};
|
package/src/components/code.tsx
CHANGED
|
@@ -2,12 +2,8 @@ import { useEffect, useMemo, useState } from 'react';
|
|
|
2
2
|
import { Button, Form } from 'antd';
|
|
3
3
|
import { useMountedRef } from '@brushes/form';
|
|
4
4
|
import { get } from '@brushes/request';
|
|
5
|
-
import { useNode } from '@craftjs/core';
|
|
6
5
|
|
|
7
6
|
export const CodeComponent = ({ api = '/web/ml/muser/sendPhone.json', codeKey, height = 36 }: { codeKey?: string; api?: string; height?: number }) => {
|
|
8
|
-
const { custom } = useNode((node) => ({
|
|
9
|
-
custom: node.data.custom
|
|
10
|
-
}));
|
|
11
7
|
const form = Form.useFormInstance();
|
|
12
8
|
const verCode = form.getFieldValue('verCode');
|
|
13
9
|
const [dataTime, setDataTime] = useState(0);
|
|
@@ -57,7 +53,7 @@ export const CodeComponent = ({ api = '/web/ml/muser/sendPhone.json', codeKey, h
|
|
|
57
53
|
};
|
|
58
54
|
|
|
59
55
|
return (
|
|
60
|
-
<Button loading={loading} size={'small'} type={'link'} disabled={isfetch} style={{ cursor: 'pointer', height, width: 90
|
|
56
|
+
<Button loading={loading} size={'small'} type={'link'} disabled={isfetch} style={{ cursor: 'pointer', height, width: 90 }} onClick={fetchCode}>
|
|
61
57
|
{dataTime === 0 ? '获取验证码' : `倒计时${dataTime}秒`}
|
|
62
58
|
</Button>
|
|
63
59
|
);
|
package/src/components/image.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
|
|
|
2
2
|
import { Form, Spin } from 'antd';
|
|
3
3
|
import { dynamicFormFields } from '@brushes/form';
|
|
4
4
|
import { createStyles } from 'antd-style';
|
|
5
|
-
import {
|
|
5
|
+
import { encryptBySM2 } from '../tool';
|
|
6
6
|
|
|
7
7
|
const useStyle = createStyles(({ token, css }, { height }: { height: number }) => {
|
|
8
8
|
return {
|
|
@@ -13,10 +13,7 @@ const useStyle = createStyles(({ token, css }, { height }: { height: number }) =
|
|
|
13
13
|
`
|
|
14
14
|
};
|
|
15
15
|
});
|
|
16
|
-
export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', codeKey, height = 40 }: { api?: string; codeKey?: string; height?: number }) => {
|
|
17
|
-
const { custom } = useNode((node) => ({
|
|
18
|
-
custom: node.data.custom
|
|
19
|
-
}));
|
|
16
|
+
export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', codeKey, height = 40, encryption = false }: { api?: string; codeKey?: string; height?: number; encryption?: boolean }) => {
|
|
20
17
|
const { styles } = useStyle({ height });
|
|
21
18
|
const form = Form.useFormInstance();
|
|
22
19
|
const isDisabled = form.getFieldValue('isDisabled');
|
|
@@ -29,7 +26,7 @@ export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', code
|
|
|
29
26
|
}
|
|
30
27
|
}, [isDisabled]);
|
|
31
28
|
|
|
32
|
-
const fetchCode = () => {
|
|
29
|
+
const fetchCode = async () => {
|
|
33
30
|
setLoading(true);
|
|
34
31
|
const { getFieldsValue } = form;
|
|
35
32
|
const { loginName, userPhone, userinfoConPhone, ...rest } = getFieldsValue();
|
|
@@ -39,7 +36,12 @@ export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', code
|
|
|
39
36
|
params = rest[codeKey];
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
|
|
39
|
+
let userPhoneParam = params;
|
|
40
|
+
if (encryption) {
|
|
41
|
+
userPhoneParam = encodeURIComponent(await encryptBySM2(params));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fetch(`${api}?userPhone=${userPhoneParam}`)
|
|
43
45
|
.then((code) => {
|
|
44
46
|
return code;
|
|
45
47
|
})
|
|
@@ -70,7 +72,7 @@ export const ImageCodeComponent = ({ api = '/web/ml/mlogin/getVerCode.img', code
|
|
|
70
72
|
<Spin spinning={loading}>{verImg ? <img src={verImg} onClick={fetchCode} style={{ width: 90, height: height - 2 }} /> : <div style={{ width: 90, height: height - 2 }}></div>}</Spin>
|
|
71
73
|
),
|
|
72
74
|
style: {
|
|
73
|
-
height
|
|
75
|
+
height
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
}
|
package/src/setting/title.tsx
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { Divider } from 'antd';
|
|
2
|
-
import { useNode } from '@craftjs/core';
|
|
3
2
|
|
|
4
3
|
const Title = ({ title }: { title: string }) => {
|
|
5
|
-
const { custom } = useNode((node) => ({
|
|
6
|
-
custom: node.data.custom
|
|
7
|
-
}));
|
|
8
4
|
return (
|
|
9
5
|
<>
|
|
10
6
|
<Divider style={{ fontSize: 13, margin: '2px 0' }} orientation="left">
|
package/src/tool/index.tsx
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { sm2 } from 'sm-crypto';
|
|
2
|
+
import { message } from 'antd';
|
|
3
|
+
import { post } from '@brushes/request';
|
|
4
|
+
|
|
5
|
+
const PUBLIC_KEY_URL = '/web/dd/falgSetting/getFalgSettingByCode.json';
|
|
6
|
+
const PUBLIC_KEY_CODE = 'SM2_PUBLIC_KEY';
|
|
7
|
+
|
|
8
|
+
let publicKeyPromise: Promise<string> | null = null;
|
|
9
|
+
|
|
10
|
+
const requestPublicKey = async (): Promise<string> => {
|
|
11
|
+
const response: any = await post(PUBLIC_KEY_URL, { flagSettingCode: PUBLIC_KEY_CODE });
|
|
12
|
+
|
|
13
|
+
const publicKey = response?.flagSettingInfo || (response?.dataObj && response.dataObj.flagSettingInfo);
|
|
14
|
+
|
|
15
|
+
if (!publicKey) {
|
|
16
|
+
throw new Error('未获取到 SM2 公钥');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return publicKey;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getPublicKey = (): Promise<string> => {
|
|
23
|
+
if (!publicKeyPromise) {
|
|
24
|
+
publicKeyPromise = requestPublicKey().catch((error) => {
|
|
25
|
+
publicKeyPromise = null;
|
|
26
|
+
throw error;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return publicKeyPromise;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const encryptBySM2 = async (plainText: string): Promise<string> => {
|
|
34
|
+
try {
|
|
35
|
+
const publicKey = await getPublicKey();
|
|
36
|
+
return `04${sm2.doEncrypt(String(plainText), publicKey, 1)}`;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
message.error('SM2 密钥获取失败');
|
|
39
|
+
return plainText;
|
|
40
|
+
}
|
|
41
|
+
};
|