Skip to content

Commit 8cea07d

Browse files
committed
refactor: 调整变量名、增加缩放模式枚举
1 parent bea2417 commit 8cea07d

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/components/CanvasArea/Block/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useEffect, useRef } from 'react';
22
import './index.css';
3-
import registerConfig from '../../MaterialPanel/registerConfig';
3+
import registerConfig, { ScaleMode } from '../../MaterialPanel/registerConfig';
44
import React from 'react';
55
import { GlobalContext, IBlock } from '../../../store';
66

77
//私有常量
8-
const scaleDotPoints = ['lt', 'rt', 'lb', 'rb']; // 放大缩小
9-
const scaleLinePoints = ['l', 'r', 't', 'b']; // 横纵伸缩
8+
const scaleDotPoints = ['lt', 'rt', 'lb', 'rb']; // 四角缩放
9+
const scaleLinePoints = ['l', 'r', 't', 'b']; // 横竖缩放
1010

1111
const cursorPoints = {
1212
lt: 'nw',
@@ -203,7 +203,7 @@ let Block = (_props: IProps) => {
203203
{RenderComponent}
204204
{block.focus ? (
205205
<div className="block-focus-shape">
206-
{block.focusShape === 'scaleLine'
206+
{block.scaleMode === ScaleMode.HorizontalVerticalScale
207207
? scaleLinePoints.map(point => (
208208
<span
209209
key={point}

src/components/CanvasArea/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ let CanvasArea = (_props: IProps) => {
7676
top: curTop,
7777
zIndex: 1,
7878
},
79-
focusShape: currentMaterial.focusShape,
79+
scaleMode: currentMaterial.scaleMode,
8080
};
8181
// 3、将组件配置加入画布配置中
8282
currentSchema.blocks.push(config);

src/components/MaterialPanel/registerConfig.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { CSSProperties } from 'react';
22

3+
export enum ScaleMode {
4+
// 四个角度缩放
5+
SquaringScale,
6+
// 横纵伸缩
7+
HorizontalVerticalScale,
8+
}
9+
310
export interface IComponent {
411
label: string;
512
preview: () => JSX.Element | string;
613
render: () => JSX.Element | string;
714
type: string;
8-
focusShape: 'scaleDot' | 'scaleLine';
15+
scaleMode: ScaleMode;
916
style?: CSSProperties;
1017
focus?: boolean;
1118
element?: HTMLElement;
@@ -36,23 +43,23 @@ registerConfig.register({
3643
preview: () => <button style={{ display: 'inline-block', width: '100%', height: '100%' }}>四个角度缩放</button>,
3744
render: () => <button style={{ display: 'inline-block', width: '100%', height: '100%' }}>四个角度缩放</button>,
3845
type: 'text',
39-
focusShape: 'scaleDot',
46+
scaleMode: ScaleMode.SquaringScale,
4047
});
4148

4249
registerConfig.register({
4350
label: '按钮',
4451
preview: () => <button style={{ display: 'inline-block', width: '100%', height: '100%' }}>横纵伸缩</button>,
4552
render: () => <button style={{ display: 'inline-block', width: '100%', height: '100%' }}>横纵伸缩</button>,
4653
type: 'button',
47-
focusShape: 'scaleLine',
54+
scaleMode: ScaleMode.HorizontalVerticalScale,
4855
});
4956

5057
registerConfig.register({
5158
label: '输入框',
5259
preview: () => <input placeholder="预览输入框" />,
5360
render: () => <input placeholder="渲染输入框" />,
5461
type: 'input',
55-
focusShape: 'scaleLine',
62+
scaleMode: ScaleMode.SquaringScale,
5663
});
5764

5865
export default registerConfig;

src/store/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type IBlock = Pick<IComponent, 'type' | 'focus'> & {
1616
zIndex?: number;
1717
};
1818
focus: boolean;
19-
focusShape: IComponent['focusShape'];
19+
scaleMode: IComponent['scaleMode'];
2020
};
2121
interface ISchema {
2222
container: {

0 commit comments

Comments
 (0)