Skip to content

Commit

Permalink
fix: 修复问题
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft committed Nov 14, 2024
1 parent 2290e5d commit d4f4ec0
Show file tree
Hide file tree
Showing 5 changed files with 4,813 additions and 5,932 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"preinstall": "npx only-allow pnpm",
"start:editor": "pnpm --filter editor start",
"build:editor": "pnpm --filter editor build",
"deploy:editor": "pnpm build:editor && cross-env PROJECT=editor node ./deploy.js",
"deploy:editor": "rimraf -rf dist/editor && pnpm build:editor && cross-env PROJECT=editor node ./deploy.js",
"start:admin": "pnpm --filter admin start",
"build:admin": "pnpm --filter admin build",
"deploy:admin": "pnpm build:admin && cross-env PROJECT=admin node ./deploy.js",
"deploy:admin": "rimraf -rf dist/admin && pnpm build:admin && cross-env PROJECT=admin node ./deploy.js",
"start:docs": "pnpm --filter docs dev",
"build:docs": "pnpm --filter docs build",
"deploy:docs": "pnpm build:docs && cross-env PROJECT=docs node ./deploy.js",
"build": "pnpm --filter editor build && pnpm --filter admin build && pnpm --filter docs build",
"deploy": "pnpm build && cross-env PROJECT=all node ./deploy.js",
"deploy": "rimraf -rf dist && pnpm build && cross-env PROJECT=all node ./deploy.js",
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
"release:major": "standard-version --release-as major",
"release:minor": "standard-version --release-as minor",
Expand Down Expand Up @@ -75,6 +75,7 @@
"react-quill": "^2.0.0",
"react-responsive": "^10.0.0",
"react-router-dom": "^6.21.2",
"rimraf": "^6.0.1",
"standard-version": "^9.5.0",
"styled-components": "^6.1.13",
"vite": "^5.0.8",
Expand Down
71 changes: 15 additions & 56 deletions packages/materials/Basic/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import React, { forwardRef, useImperativeHandle, useState } from 'react';
import { Badge } from 'antd';
import MarsRender from '@/packages/MarsRender/MarsRender';
import { getComponent } from '@/packages/index';
import { useDrop } from 'react-dnd';
import { usePageStore } from '@/stores/pageStore';
import { default as DivConfig } from '../../Container/Div/Schema'
import { ComponentType, IDragTargetItem } from '../../types';
import { off } from 'process';
import { platform } from 'os';
import { rest } from 'lodash-es';
import MarsRender from '@materials/MarsRender/MarsRender';
import { ComponentType } from '../../types';

export type BadgeSize = 'small' | 'default';

/*泛型只需要定义组件本身用到的属性*/
interface IConfig {
ribbon?: boolean;//是否使用缎带模式
ribbon?: boolean; //是否使用缎带模式
placement?: 'start' | 'end'; //缎带模式下,设置Badge位置
color?: string; // 自定义小圆点的颜色
count?: React.ReactNode; // 展示的数字,大于 overflowCount 时显示为 ${overflowCount}+,为 0 时隐藏
Expand All @@ -38,30 +31,6 @@ interface IConfig {
*/
const MBadge = ({ id, type, config, elements }: ComponentType<IConfig>, ref: any) => {
const [visible, setVisible] = useState(true);
const addChildElements = usePageStore((state) => state.addChildElements);
//拖拽接受
const [, drop] = useDrop({
accept: 'MENU_ITEM',
async drop(item: IDragTargetItem, monitor) {
if (monitor.didDrop()) return;
// 生成默认配置
const { config, events, methods = [] }: any = (await getComponent(item.type + 'Config'))?.default || {};
addChildElements({
type: item.type,
name: item.name,
parentId: id,
id: item.id,
config,
events,
methods,
});
},
// TODO: 拖拽组件时,容器呈现背景色(后期需要判断组件是否可以拖入)
collect: (monitor) => ({
isOver: monitor.isOver(),
canDrop: monitor.canDrop(),
}),
});

// 对外暴露方法
useImperativeHandle(ref, () => {
Expand All @@ -75,33 +44,23 @@ const MBadge = ({ id, type, config, elements }: ComponentType<IConfig>, ref: any
};
});


const { placement, ...restProps } = config.props;

const rewriteProps = !config.props.ribbon ? {
offset: [config.props.offsetX, config.props.offsetY],
...restProps,
} : {
};

const ribbonProps = config.props.ribbon ? {
color: config.props.color,
placement: config.props.placement,
text: config.props.text,
} : {};
const rewriteProps = !config.props.ribbon
? {
offset: [config.props.offsetX, config.props.offsetY],
...restProps,
}
: {};

return (
visible && (
<Badge data-id={id} data-type={type} style={config.style} {...rewriteProps}>
{(<div style={config.style} {...config.props} data-type={type} ref={drop}>
{elements?.length ? (
<MarsRender elements={elements || []} />
) : (
<div className="slots" style={{ height: 100, lineHeight: '100px' }}>
拖拽组件到这里
</div>
)}
</div>)}
<Badge style={config.style} {...rewriteProps}>
{
<div style={config.style} {...config.props}>
{elements?.length ? <MarsRender elements={elements || []} /> : null}
</div>
}
</Badge>
)
);
Expand Down
58 changes: 10 additions & 48 deletions packages/materials/Basic/Ribbon/Ribbon.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React, { forwardRef, useImperativeHandle, useState } from 'react';
import { Badge } from 'antd';
import MarsRender from '@/packages/MarsRender/MarsRender';
import { getComponent } from '@/packages/index';
import { useDrop } from 'react-dnd';
import { usePageStore } from '@/stores/pageStore';
import { default as DivConfig } from '../../Container/Div/Schema'
import { ComponentType, IDragTargetItem } from '../../types';
import './index.less';
import MarsRender from '@materials/MarsRender/MarsRender';
import { ComponentType } from '../../types';

export type BadgeSize = 'small' | 'default';

Expand All @@ -27,31 +22,6 @@ interface IConfig {
*/
const MRibbon = ({ id, type, config, elements }: ComponentType<IConfig>, ref: any) => {
const [visible, setVisible] = useState(true);
const addChildElements = usePageStore((state) => state.addChildElements);
//拖拽接受
const [, drop] = useDrop({
accept: 'MENU_ITEM',
async drop(item: IDragTargetItem, monitor) {
if (monitor.didDrop()) return;
// 生成默认配置
const { config, events, methods = [] }: any = (await getComponent(item.type + 'Config'))?.default || {};
addChildElements({
type: item.type,
name: item.name,
parentId: id,
id: item.id,
config,
events,
methods,
});
},
// TODO: 拖拽组件时,容器呈现背景色(后期需要判断组件是否可以拖入)
collect: (monitor) => ({
isOver: monitor.isOver(),
canDrop: monitor.canDrop(),
}),
});

// 对外暴露方法
useImperativeHandle(ref, () => {
return {
Expand All @@ -64,25 +34,17 @@ const MRibbon = ({ id, type, config, elements }: ComponentType<IConfig>, ref: an
};
});
return (
visible && ((
<span
className='ant-badge'
data-id={id} data-type={type}
>
visible && (
<span className="ant-badge">
<Badge.Ribbon style={config.style} {...config.props}>
{(<div style={config.style} {...config.props} data-type={type} ref={drop}>
{elements?.length ? (
<MarsRender elements={elements || []} />
) : (
<div className="slots" style={{ height: 100, width: 100, lineHeight: '100px' }}>
拖拽组件到这里
</div>
)}
</div>)}
</Badge.Ribbon >
{
<div style={config.style} {...config.props}>
{elements?.length ? <MarsRender elements={elements || []} /> : null}
</div>
}
</Badge.Ribbon>
</span>
)
)
);
};
export default forwardRef(MRibbon);
13 changes: 0 additions & 13 deletions packages/materials/Basic/Ribbon/index.less

This file was deleted.

Loading

0 comments on commit d4f4ec0

Please sign in to comment.