@brushes/component-core 0.0.33 → 0.1.3
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 -2
- package/scripts/build.sh +4 -0
- package/src/basic-component/container/index.tsx +228 -0
- package/src/basic-component/default/index.tsx +55 -0
- package/src/basic-component/empty/index.tsx +24 -0
- package/{dist/basic-component/index.d.ts → 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 +60 -0
- package/src/components/image.tsx +78 -0
- package/src/context/index.tsx +10 -0
- package/src/setting/basic.tsx +91 -0
- package/src/setting/title.tsx +14 -0
- package/src/store/commonModule.tsx +37 -0
- package/src/store/commonStore.tsx +103 -0
- package/src/store/rootModule.tsx +24 -0
- package/src/store/rootStore.tsx +56 -0
- package/src/store/storeDataConfig.tsx +50 -0
- package/src/tool/combine.ts +11 -0
- package/src/tool/fullpath.ts +13 -0
- package/dist/basic-component/container/index.d.ts +0 -23
- package/dist/basic-component/default/index.d.ts +0 -8
- package/dist/basic-component/empty/index.d.ts +0 -4
- package/dist/basic-component/resizer/index.d.ts +0 -0
- package/dist/basic-component/resizer/numToMeasurement.d.ts +0 -7
- package/dist/components/code.d.ts +0 -5
- package/dist/components/image.d.ts +0 -5
- package/dist/context/index.d.ts +0 -6
- package/dist/index.js +0 -26
- package/dist/setting/basic.d.ts +0 -7
- package/dist/setting/title.d.ts +0 -4
- package/dist/store/commonModule.d.ts +0 -5
- package/dist/store/commonStore.d.ts +0 -56
- package/dist/store/rootModule.d.ts +0 -5
- package/dist/store/rootStore.d.ts +0 -35
- package/dist/store/storeDataConfig.d.ts +0 -0
- package/dist/tool/combine.d.ts +0 -1
- package/dist/tool/fullpath.d.ts +0 -1
- /package/{dist/components/index.d.ts → src/components/index.ts} +0 -0
- /package/{dist/index.d.ts → src/index.ts} +0 -0
- /package/{dist/setting/index.d.ts → src/setting/index.ts} +0 -0
- /package/{dist/store/index.d.ts → src/store/index.tsx} +0 -0
- /package/{dist/tool/index.d.ts → src/tool/index.tsx} +0 -0
package/package.json
CHANGED
package/scripts/build.sh
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { ReactNode, useMemo } from 'react';
|
|
2
|
+
import { DefaultJsx } from '../default';
|
|
3
|
+
import { fullpath } from '../../tool';
|
|
4
|
+
import { createStyles } from 'antd-style';
|
|
5
|
+
import { useEditor, useNode } from '@craftjs/core';
|
|
6
|
+
import { ModuleProvider, useModuleContext, useModuleRootContext } from '../../store';
|
|
7
|
+
import { useSearchParams } from 'react-router-dom';
|
|
8
|
+
import { isEmpty, isUndefined, get } from 'lodash';
|
|
9
|
+
|
|
10
|
+
const useStyles = createStyles(({ token, css }) => {
|
|
11
|
+
return {
|
|
12
|
+
category: css`
|
|
13
|
+
&:hover {
|
|
14
|
+
box-shadow: 0 1px 5px 1px rgba(0, 0, 0, 0.1);
|
|
15
|
+
}
|
|
16
|
+
`,
|
|
17
|
+
width_100: css`
|
|
18
|
+
width: 100%;
|
|
19
|
+
`
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
export const Inner = ({ children, enabled, root, text }: { text?: string; root?: boolean; enabled: boolean; children: ReactNode }) => {
|
|
23
|
+
return <>{children ? children : enabled ? <DefaultJsx text={text} root={root} /> : ''}</>;
|
|
24
|
+
};
|
|
25
|
+
export const IsShowContainer = ({
|
|
26
|
+
moduleShowValue,
|
|
27
|
+
rootKey = '',
|
|
28
|
+
isRevert = false,
|
|
29
|
+
children,
|
|
30
|
+
routerIsShowValue,
|
|
31
|
+
routerIsShow,
|
|
32
|
+
moduleIsShow = '',
|
|
33
|
+
padding,
|
|
34
|
+
storeKey = '',
|
|
35
|
+
margin
|
|
36
|
+
}: {
|
|
37
|
+
isRevert?: boolean;
|
|
38
|
+
routerIsShowValue?: string;
|
|
39
|
+
rootKey?: string;
|
|
40
|
+
moduleShowValue?: string;
|
|
41
|
+
moduleIsShow?: string;
|
|
42
|
+
routerIsShow?: string;
|
|
43
|
+
storeKey: string;
|
|
44
|
+
padding: object;
|
|
45
|
+
margin: object;
|
|
46
|
+
children?: ReactNode;
|
|
47
|
+
}) => {
|
|
48
|
+
const store = useModuleContext((s) => s.moduleStore[storeKey]);
|
|
49
|
+
const rootStore = useModuleRootContext((s) => s.rootStore[rootKey]);
|
|
50
|
+
|
|
51
|
+
const { enabled } = useEditor((state) => ({
|
|
52
|
+
enabled: state.options.enabled
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
const {
|
|
56
|
+
connectors: { connect, drag }
|
|
57
|
+
} = useNode();
|
|
58
|
+
|
|
59
|
+
let [searchParams] = useSearchParams();
|
|
60
|
+
|
|
61
|
+
const nValue = useMemo(() => {
|
|
62
|
+
if (storeKey && store) {
|
|
63
|
+
if (typeof store[moduleIsShow] === 'number') {
|
|
64
|
+
return get(store, moduleIsShow) + '';
|
|
65
|
+
}
|
|
66
|
+
return get(store, moduleIsShow);
|
|
67
|
+
}
|
|
68
|
+
}, [store, storeKey, moduleIsShow]);
|
|
69
|
+
|
|
70
|
+
const rnValue = useMemo(() => {
|
|
71
|
+
if (rootKey && rootStore) {
|
|
72
|
+
if (typeof rootStore[moduleIsShow] === 'number') {
|
|
73
|
+
return get(rootStore, moduleIsShow) + '';
|
|
74
|
+
}
|
|
75
|
+
return get(rootStore, moduleIsShow);
|
|
76
|
+
}
|
|
77
|
+
}, [rootStore, rootKey, moduleIsShow]);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 1: 路由是否包含
|
|
81
|
+
* 2: 路由是否包含 值是否匹配
|
|
82
|
+
* 3: store显示条件Key和value都为空, store是否为空
|
|
83
|
+
* 4: store显示条件Key不为空 store显示条件value为空, store里面的key的值是否空
|
|
84
|
+
* 5: store显示条件Key和store显示条件value都不为空, store里面的key的值和 显示条件value是否匹配
|
|
85
|
+
* 6: 全局Store显示条件Key和value都为空, 全局Store是否为空
|
|
86
|
+
* 7: 全局Store显示条件Key和显示条件value都不为空, 全局Store里面的key的值和 显示条件value是否匹配
|
|
87
|
+
* 8: 全局store显示条件Key不为空 store显示条件value为空, 全局store里面的key的值是否空
|
|
88
|
+
*/
|
|
89
|
+
const conditionType = useMemo(() => {
|
|
90
|
+
const condition =
|
|
91
|
+
(routerIsShow && searchParams.has(routerIsShow) && !routerIsShowValue) || // 1
|
|
92
|
+
(routerIsShow && searchParams.has(routerIsShow) && routerIsShowValue && routerIsShowValue.split(',').includes(searchParams.get(routerIsShow) || '')) || // 2
|
|
93
|
+
(storeKey && !moduleShowValue && !moduleIsShow && !isUndefined(store) && !isEmpty(store)) || // 3
|
|
94
|
+
(moduleIsShow && storeKey && !moduleShowValue && !isUndefined(nValue) && !isEmpty(nValue)) || // 4
|
|
95
|
+
(moduleShowValue && storeKey && moduleIsShow && moduleShowValue.split(',').includes(nValue + '')) || // 5
|
|
96
|
+
(rootKey && !moduleShowValue && !moduleIsShow && !isUndefined(rootStore) && !isEmpty(rootStore)) || // 6
|
|
97
|
+
(moduleIsShow && rootKey && !moduleShowValue && !isUndefined(rnValue) && !isEmpty(rnValue)) || // 7
|
|
98
|
+
(moduleShowValue && rootKey && moduleIsShow && moduleShowValue.split(',').includes(rnValue + '')); // 8
|
|
99
|
+
|
|
100
|
+
return isRevert ? !condition : condition;
|
|
101
|
+
}, [routerIsShow, routerIsShowValue, isRevert, store, storeKey, moduleShowValue, moduleIsShow, nValue, rootKey, rootStore, rnValue]);
|
|
102
|
+
|
|
103
|
+
if (conditionType || enabled) {
|
|
104
|
+
return (
|
|
105
|
+
<div
|
|
106
|
+
style={{
|
|
107
|
+
...margin,
|
|
108
|
+
...padding
|
|
109
|
+
}}
|
|
110
|
+
ref={(ref: HTMLDivElement) => connect(drag(ref))}
|
|
111
|
+
>
|
|
112
|
+
<Inner enabled={enabled}>{children}</Inner>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const Container = ({ width, text, children, background, margin = {}, positionValue = {}, padding = {}, backgroundImage, position, $$_actions, $_actions, borderColor, ...props }: any) => {
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
const { styles } = useStyles();
|
|
121
|
+
const { enabled } = useEditor((state) => ({
|
|
122
|
+
enabled: state.options.enabled
|
|
123
|
+
}));
|
|
124
|
+
//为了右边贴边位置特殊处理
|
|
125
|
+
const positionNewValue = useMemo(() => {
|
|
126
|
+
if (position === 'fixed' && positionValue.right === 0 && enabled) {
|
|
127
|
+
return {
|
|
128
|
+
...positionValue,
|
|
129
|
+
right: 412
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (position === 'fixed' && positionValue.left === 0 && enabled) {
|
|
133
|
+
return {
|
|
134
|
+
...positionValue,
|
|
135
|
+
left: 172
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return positionValue;
|
|
139
|
+
}, [positionValue, position]);
|
|
140
|
+
const {
|
|
141
|
+
connectors: { connect, drag }
|
|
142
|
+
} = useNode();
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<div
|
|
146
|
+
className={enabled ? styles.category : ''}
|
|
147
|
+
ref={(ref: HTMLDivElement) => connect(drag(ref))}
|
|
148
|
+
style={{
|
|
149
|
+
...margin,
|
|
150
|
+
display: 'flex',
|
|
151
|
+
boxSizing: 'border-box',
|
|
152
|
+
position,
|
|
153
|
+
border: `solid 1px ${borderColor}`,
|
|
154
|
+
...padding,
|
|
155
|
+
...props,
|
|
156
|
+
...positionNewValue,
|
|
157
|
+
background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
|
|
158
|
+
width: (width + '').includes('%') ? width : `${width}px`
|
|
159
|
+
}}
|
|
160
|
+
>
|
|
161
|
+
<Inner text={text} enabled={enabled}>
|
|
162
|
+
{children}
|
|
163
|
+
</Inner>
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const OutContainerComponent = ({ width, api, params, children, background, padding = {}, backgroundImage, ...props }: any) => {
|
|
169
|
+
const { enabled } = useEditor((state) => ({
|
|
170
|
+
enabled: state.options.enabled
|
|
171
|
+
}));
|
|
172
|
+
|
|
173
|
+
const {
|
|
174
|
+
connectors: { connect, drag }
|
|
175
|
+
} = useNode();
|
|
176
|
+
|
|
177
|
+
const { styles } = useStyles();
|
|
178
|
+
return (
|
|
179
|
+
<div
|
|
180
|
+
ref={(ref: HTMLDivElement) => connect(drag(ref))}
|
|
181
|
+
className={enabled ? styles.category : ''}
|
|
182
|
+
style={{
|
|
183
|
+
margin: '0 auto',
|
|
184
|
+
display: 'flex',
|
|
185
|
+
boxSizing: 'border-box',
|
|
186
|
+
...padding,
|
|
187
|
+
...props,
|
|
188
|
+
background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
|
|
189
|
+
width: (width + '').includes('%') ? width : `${width}px`
|
|
190
|
+
}}
|
|
191
|
+
>
|
|
192
|
+
<Inner enabled={enabled}>{children}</Inner>
|
|
193
|
+
</div>
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export const OutContainer = (props: any) => {
|
|
198
|
+
return (
|
|
199
|
+
<ModuleProvider>
|
|
200
|
+
<OutContainerComponent {...props} />
|
|
201
|
+
</ModuleProvider>
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
export const ContainerWrap = ({ width, background, children, backgroundImage, height, $$_style = '', $_style = '', ...props }: any) => {
|
|
205
|
+
const {
|
|
206
|
+
connectors: { connect, drag }
|
|
207
|
+
} = useNode();
|
|
208
|
+
|
|
209
|
+
const { enabled } = useEditor((state) => ({
|
|
210
|
+
enabled: state.options.enabled
|
|
211
|
+
}));
|
|
212
|
+
return (
|
|
213
|
+
<div
|
|
214
|
+
{...props}
|
|
215
|
+
ref={(ref: HTMLDivElement) => connect(drag(ref))}
|
|
216
|
+
style={{
|
|
217
|
+
width,
|
|
218
|
+
paddingBottom: 5,
|
|
219
|
+
background: backgroundImage ? `url(${fullpath(backgroundImage)}) repeat-x center 0` : background,
|
|
220
|
+
minHeight: `calc(${height}vh - 110px)`
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<Inner root={true} enabled={enabled}>
|
|
224
|
+
{children}
|
|
225
|
+
</Inner>
|
|
226
|
+
</div>
|
|
227
|
+
);
|
|
228
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { QjIcon } from '@brushes/share-resource';
|
|
2
|
+
import { Watermark } from 'antd';
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
|
|
5
|
+
const useStyle = createStyles(({ token, css }) => {
|
|
6
|
+
return {
|
|
7
|
+
defaultWrap: css`
|
|
8
|
+
border: dashed 1px rgba(0, 0, 0, 0.15);
|
|
9
|
+
width: 100%;
|
|
10
|
+
text-align: center;
|
|
11
|
+
border-radius: ${token.borderRadius}px;
|
|
12
|
+
height: 100%;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
align-items: center;
|
|
15
|
+
display: flex;
|
|
16
|
+
flex-direction: column;
|
|
17
|
+
color: ${token.colorTextLabel};
|
|
18
|
+
p {
|
|
19
|
+
margin-top: 10px;
|
|
20
|
+
font-size: 12px;
|
|
21
|
+
}
|
|
22
|
+
}`
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const DefaultJsx = ({ text = '内容放置区域', root }: { text?: string; root?: boolean }) => {
|
|
27
|
+
const { styles } = useStyle();
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
className={styles.defaultWrap}
|
|
31
|
+
style={{
|
|
32
|
+
minHeight: root ? `calc(100vh - 110px)` : 'auto'
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
<QjIcon
|
|
36
|
+
style={{
|
|
37
|
+
fontSize: 50,
|
|
38
|
+
fontWeight: 500,
|
|
39
|
+
display: 'block',
|
|
40
|
+
color: '#bbb'
|
|
41
|
+
}}
|
|
42
|
+
name={'icon-computer'}
|
|
43
|
+
></QjIcon>
|
|
44
|
+
<p>{text}</p>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const DefaultEditorBg = ({ content = '/', color = 'blue' }: { content?: string; color?: string }) => {
|
|
50
|
+
return (
|
|
51
|
+
<Watermark gap={[1, 1]} font={{ color }} rotate={0} height={10} width={10} content={content}>
|
|
52
|
+
<div style={{ height: 10 }} />
|
|
53
|
+
</Watermark>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Typography } from 'antd';
|
|
2
|
+
|
|
3
|
+
export const SlotEmpty: React.FC<{
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
borderColor?: string;
|
|
6
|
+
}> = ({ children = '当前为插槽容器,可以自定义组件代码。', borderColor = 'rgba(0, 0, 0, 0.1)' }) => {
|
|
7
|
+
return (
|
|
8
|
+
<div
|
|
9
|
+
style={{
|
|
10
|
+
height: '100%',
|
|
11
|
+
width: '100%',
|
|
12
|
+
borderColor,
|
|
13
|
+
borderWidth: 1,
|
|
14
|
+
borderStyle: 'dashed',
|
|
15
|
+
fontSize: 12,
|
|
16
|
+
textAlign: 'center',
|
|
17
|
+
fontWeight: 'normal',
|
|
18
|
+
background: 'rgba(255,255,255, 0.2)'
|
|
19
|
+
}}
|
|
20
|
+
>
|
|
21
|
+
<Typography.Text type="secondary">{children}</Typography.Text>
|
|
22
|
+
</div>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { Button, Form } from 'antd';
|
|
3
|
+
import { useMountedRef } from '@brushes/form';
|
|
4
|
+
import { get } from '@brushes/request';
|
|
5
|
+
|
|
6
|
+
export const CodeComponent = ({ api = '/web/ml/muser/sendPhone.json', codeKey, height = 36 }: { codeKey?: string; api?: string; height?: number }) => {
|
|
7
|
+
const form = Form.useFormInstance();
|
|
8
|
+
const verCode = form.getFieldValue('verCode');
|
|
9
|
+
const [dataTime, setDataTime] = useState(0);
|
|
10
|
+
const [loading, setLoading] = useState(false);
|
|
11
|
+
const isMounted = useMountedRef();
|
|
12
|
+
const isfetch = useMemo(() => {
|
|
13
|
+
return dataTime > 0 || !verCode;
|
|
14
|
+
}, [dataTime, verCode]);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const time = setTimeout(function next() {
|
|
18
|
+
if (dataTime === 0) {
|
|
19
|
+
clearTimeout(time);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (isMounted.current) {
|
|
23
|
+
setDataTime((dataTime) => dataTime - 1);
|
|
24
|
+
}
|
|
25
|
+
}, 1000);
|
|
26
|
+
|
|
27
|
+
return () => clearTimeout(time);
|
|
28
|
+
}, [dataTime, isMounted]);
|
|
29
|
+
|
|
30
|
+
const fetchCode = () => {
|
|
31
|
+
setLoading(true);
|
|
32
|
+
const { getFieldsValue } = form;
|
|
33
|
+
const { loginName, userPhone, userinfoConPhone, verCode, ...rest } = getFieldsValue();
|
|
34
|
+
let params = {
|
|
35
|
+
userPhone: loginName || userPhone || userinfoConPhone,
|
|
36
|
+
code: verCode
|
|
37
|
+
}
|
|
38
|
+
if(codeKey) {
|
|
39
|
+
params = {
|
|
40
|
+
userPhone: rest[codeKey],
|
|
41
|
+
code: verCode
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get(api, params)
|
|
46
|
+
.then(() => {
|
|
47
|
+
setDataTime(1 * 60);
|
|
48
|
+
})
|
|
49
|
+
.catch((error: any) => {})
|
|
50
|
+
.finally(() => {
|
|
51
|
+
setLoading(false);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Button loading={loading} size={'small'} type={'link'} disabled={isfetch} style={{ cursor: 'pointer', height, width: 90 }} onClick={fetchCode}>
|
|
57
|
+
{dataTime === 0 ? '获取验证码' : `倒计时${dataTime}秒`}
|
|
58
|
+
</Button>
|
|
59
|
+
);
|
|
60
|
+
};
|