Skip to content

Commit

Permalink
fix: 修复问题
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft committed Nov 5, 2024
1 parent 8579f90 commit 31ded9f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
10 changes: 5 additions & 5 deletions packages/editor/src/components/VariableBind/VariableSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button, Collapse, Form, Modal, Popover, Tree } from 'antd';
import type { CollapseProps } from 'antd';
import { forwardRef, useCallback, useImperativeHandle, useState } from 'react';
import { forwardRef, memo, useCallback, useImperativeHandle, useState } from 'react';
import { DownOutlined, NotificationOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import { usePageStore } from '@/stores/pageStore';
import VsEditor from '../VsEditor';
Expand All @@ -27,11 +27,11 @@ const SelectVariableModal = ({ onSelect }: { onSelect: (record: any) => void },
const getFormAndTable = useCallback(() => {
const list: Array<{ id: string; name: string; elements: any[] }> = [];
Object.keys(elementsMap).map((id) => {
if (id.startsWith('SearchForm_') || id.startsWith('Form_') || id.startsWith('MarsTable_')) {
if (id.startsWith('SearchForm_') || id.startsWith('Form_') || id.startsWith('GridForm_') || id.startsWith('MarsTable_')) {
const { element }: any = getElement(cloneDeep(elements), id);
if (!element) return;
element.elements?.map((item: any) => {
const formItem = elementsMap[item.id].config.props.formItem;
const formItem = elementsMap[item.id]?.config.props.formItem;
if (formItem) {
item.name = `${formItem.label}(${formItem.name})`;
} else {
Expand All @@ -46,7 +46,7 @@ const SelectVariableModal = ({ onSelect }: { onSelect: (record: any) => void },
}
});
return list;
}, [elementsMap]);
}, [elementsMap, elements]);

// 定义树形结构
const treeData: any = [
Expand Down Expand Up @@ -293,4 +293,4 @@ const SelectVariableModal = ({ onSelect }: { onSelect: (record: any) => void },
);
};

export default forwardRef(SelectVariableModal);
export default memo(forwardRef(SelectVariableModal));
12 changes: 8 additions & 4 deletions packages/editor/src/layout/components/Menu/OutlinePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,30 @@ const OutlinePanel = memo(() => {
name,
elements: dragChildren,
};
let parentId = null;
// 移动到组件里面,添加为子组件
if (!info.dropToGap) {
if (dropKey == 'page') {
list.unshift(dropItem);
} else {
const { element } = getElement(list, dropKey);
if (element) {
parentId = dropKey;
element.elements = element.elements || [];
element.elements.unshift(dropItem);
element.elements.unshift({ ...dropItem, parentId: dropKey });
}
}
} else {
const { index, elements } = getElement(list, dropKey) || { item: {}, index: 0 };
parentId = elements[index].parentId;
if (dropPosition === -1) {
elements?.splice(index, 0, dropItem);
elements?.splice(index, 0, { ...dropItem, parentId });
} else {
elements?.splice(index + 1, 0, dropItem);
elements?.splice(index + 1, 0, { ...dropItem, parentId });
}
}
dragSortElements(list);
dragSortElements({ id: dragKey, list, parentId });
setSelectedKeys([]);
};

return (
Expand Down
11 changes: 7 additions & 4 deletions packages/editor/src/packages/Scene/GridForm/GridForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const GridForm = ({ id, type, config, elements, onSearch, onChange, onReset }: C
const [isExpand, setIsExpand] = useState(true);
const [visible, setVisible] = useState(true);
const [len, setlen] = useState(0);
const [minWidth, setMinWidth] = useState(200);
const [initialValues, setInitialValues] = useState({});
const formRef = useRef<HTMLDivElement>(null);
const formItemRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -142,13 +143,15 @@ const GridForm = ({ id, type, config, elements, onSearch, onChange, onReset }: C
const subEl = formItemRef.current?.getBoundingClientRect();
if (!parentEl || !subEl) return;
// 计算可以放入的个数
const count = Math.floor(parentEl.width / subEl.width);
const count = config.props.cols;
const minWidth = Math.floor(parentEl.width / count);
setMinWidth(minWidth);
if (!isExpand) {
setlen(count);
} else {
setlen(elements.length + 1);
}
}, [elements, isExpand]);
}, [elements, isExpand, config.props.cols]);

useEffect(() => {
if (formRef.current) {
Expand Down Expand Up @@ -185,13 +188,13 @@ const GridForm = ({ id, type, config, elements, onSearch, onChange, onReset }: C
<Form
form={form}
style={config.style}
{...omit(config.props, 'minWidth')}
{...omit(config.props, 'cols')}
initialValues={initialValues}
onValuesChange={handleValuesChange}
data-id={id}
data-type={type}
>
<DivWrapper $len={len} $minWidth={config.props.minWidth} ref={formRef}>
<DivWrapper $len={len} $minWidth={minWidth} ref={formRef}>
{elements.length ? (
<MarsRender elements={elements} />
) : (
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/packages/Scene/GridForm/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export default {
},
{
type: 'InputNumber',
label: '最小宽度',
name: ['minWidth'],
label: '每行几列',
name: ['cols'],
},
{
type: 'Title',
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/pages/welcome/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export default function Welcome() {
<h1 className={style.title}>Marsview 低代码搭建</h1>
<p className={style.desc}>让搭建更简单,让开发更高效</p>
<div className={style.count}>
服务 <CountUp end={1000} duration={3} />+ 项目,
<CountUp end={2000} duration={3} />+ 页面
服务 <CountUp end={2000} duration={3} />+ 项目,
<CountUp end={2500} duration={3} />+ 页面
</div>
<div className={style.btnGroup}>
<Button type="primary" ghost size="large" onClick={openDoc}>
Expand Down
5 changes: 3 additions & 2 deletions packages/editor/src/stores/pageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,11 @@ export const usePageStore = create<PageState & PageAction>((set) => ({
);
},
// 组件大纲拖拽排序
dragSortElements(payload: any) {
dragSortElements({ id, list, parentId }: any) {
set(
produce((state) => {
state.page.elements = payload;
state.page.elements = list;
state.page.elementsMap[id].parentId = parentId;
}),
);
},
Expand Down
11 changes: 7 additions & 4 deletions packages/materials/Scene/GridForm/GridForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const GridForm = ({ id, type, config, elements, onSearch, onChange, onReset }: C
const [isExpand, setIsExpand] = useState(true);
const [visible, setVisible] = useState(true);
const [len, setlen] = useState(0);
const [minWidth, setMinWidth] = useState(200);
const [initialValues, setInitialValues] = useState({});
const formRef = useRef<HTMLDivElement>(null);
const formItemRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -114,13 +115,15 @@ const GridForm = ({ id, type, config, elements, onSearch, onChange, onReset }: C
const subEl = formItemRef.current?.getBoundingClientRect();
if (!parentEl || !subEl) return;
// 计算可以放入的个数
const count = Math.floor(parentEl.width / subEl.width);
const count = config.props.cols;
const minWidth = Math.floor(parentEl.width / count);
setMinWidth(minWidth);
if (!isExpand) {
setlen(count);
} else {
setlen(elements.length + 1);
}
}, [elements, isExpand]);
}, [elements, isExpand, config.props.cols]);

// 展开收起
const toggleExpand = () => {
Expand Down Expand Up @@ -150,13 +153,13 @@ const GridForm = ({ id, type, config, elements, onSearch, onChange, onReset }: C
<Form
form={form}
style={config.style}
{...omit(config.props, 'minWidth')}
{...omit(config.props, 'cols')}
initialValues={initialValues}
data-id={id}
data-type={type}
onValuesChange={handleValuesChange}
>
<DivWrapper $len={len} $minWidth={config.props.minWidth} ref={formRef}>
<DivWrapper $len={len} $minWidth={minWidth} ref={formRef}>
{elements.length ? (
<MarsRender elements={elements} />
) : (
Expand Down

0 comments on commit 31ded9f

Please sign in to comment.