Skip to content

Commit

Permalink
fix: 1.修复上传问题。2.优化样式单位,增加百分比、vw/vh等。
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft committed Sep 1, 2024
1 parent 8f0dc43 commit 38c27ec
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const BackgroundImage = (props: any) => {
}
};

return <Input value={value} onChange={(e) => handleChange(e.target.value)} />;
return <Input value={value} onChange={(e) => handleChange(e.target.value)} placeholder="http://xxx.png" />;
};

export default BackgroundImage;
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const BackgroundSize = (props: any) => {
props.onChange(val);
};
return (
<Flex gap={5}>
<Flex gap={3}>
<Select
placeholder="请选择"
value={type}
Expand Down
29 changes: 24 additions & 5 deletions packages/editor/src/components/StyleConfig/InputPx.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
import { useEffect, useState } from 'react';
import { InputNumber } from 'antd';

import { InputNumber, Select } from 'antd';
const { Option } = Select;
const InputPx = ({ value, onChange, ...props }: any) => {
const [num, setNum] = useState<null | number | string>('');
const [unit, setUnit] = useState<string>('px');

useEffect(() => {
const num = value?.toString().replace('px', '');
const num = value?.toString().replace(/(px|%|vw|vh|rem|em)/, '');
if (num) setNum(num);
}, [value]);

// 输入框改变
const handleChange = (value: null | number | string) => {
if (value) {
setNum(value);
onChange(value + 'px');
onChange(value + unit);
} else {
setNum(null);
onChange('');
}
};

return <InputNumber placeholder="输入尺寸: 10" {...props} addonAfter="px" value={num} onChange={(val) => handleChange(val)} />;
// 下拉框改变
const handleSelect = (value: string) => {
setUnit(value);
if (num !== null && num !== '') onChange(num + value);
};

const selectAfter = (
<Select defaultValue="px" onChange={handleSelect} size="small">
<Option value="px">px</Option>
<Option value="%">%</Option>
<Option value="vw">vw</Option>
<Option value="vh">vh</Option>
<Option value="em">em</Option>
<Option value="rem">rem</Option>
</Select>
);

return <InputNumber placeholder="输入尺寸: 10" {...props} addonAfter={selectAfter} value={num} onChange={(val) => handleChange(val)} />;
};

export default InputPx;
10 changes: 7 additions & 3 deletions packages/editor/src/components/StyleConfig/MarginInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ const MarginInput = ({ form }: { form: FormInstance }) => {
const handleChange = (value: string) => {
setType(value);
};
const basicLayout = {
labelCol: { span: 5 },
wrapperCol: { span: 18 },
};
return (
<>
<Form.Item label="边距">
<Form.Item label="边距" layout="horizontal" {...basicLayout}>
<Radio.Group optionType="button" value={type} buttonStyle="solid" onChange={(e) => handleChange(e.target.value)}>
<Radio.Button value="all">
<BorderOuterOutlined />
Expand All @@ -34,7 +38,7 @@ const MarginInput = ({ form }: { form: FormInstance }) => {
)}
{type === 'single' && (
<>
<Flex gap={10} style={{ marginTop: 10 }}>
<Flex gap={3} style={{ marginTop: 10 }}>
<Form.Item name={['scopeStyle', 'margin']} hidden>
<InputPx />
</Form.Item>
Expand All @@ -45,7 +49,7 @@ const MarginInput = ({ form }: { form: FormInstance }) => {
<InputPx placeholder="R: 10" />
</Form.Item>
</Flex>
<Flex gap={10} style={{ marginTop: 10 }}>
<Flex gap={3} style={{ marginTop: 10 }}>
<Form.Item name={['scopeStyle', 'marginBottom']} noStyle>
<InputPx placeholder="B: 10" />
</Form.Item>
Expand Down
11 changes: 8 additions & 3 deletions packages/editor/src/components/StyleConfig/PaddingInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ const PaddingInput = ({ form }: { form: FormInstance }) => {
setType(value);
};

const basicLayout = {
labelCol: { span: 5 },
wrapperCol: { span: 18 },
};

return (
<>
<Form.Item label="填充">
<Form.Item label="填充" {...basicLayout}>
<Radio.Group optionType="button" value={type} buttonStyle="solid" onChange={(e) => handleChange(e.target.value)}>
<Radio.Button value="all">
<BorderOuterOutlined />
Expand All @@ -35,7 +40,7 @@ const PaddingInput = ({ form }: { form: FormInstance }) => {
)}
{type === 'single' && (
<>
<Flex gap={10} style={{ marginTop: 10 }}>
<Flex gap={3} style={{ marginTop: 10 }}>
<Form.Item name={['scopeStyle', 'padding']} hidden>
<InputPx placeholder="M" />
</Form.Item>
Expand All @@ -46,7 +51,7 @@ const PaddingInput = ({ form }: { form: FormInstance }) => {
<InputPx placeholder="R: 10" />
</Form.Item>
</Flex>
<Flex gap={10} style={{ marginTop: 10 }}>
<Flex gap={3} style={{ marginTop: 10 }}>
<Form.Item name={['scopeStyle', 'paddingBottom']} noStyle>
<InputPx placeholder="B: 10" />
</Form.Item>
Expand Down
22 changes: 13 additions & 9 deletions packages/editor/src/components/StyleConfig/StyleConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,26 @@ const StyleConfig = () => {
labelCol: { span: 7 },
wrapperCol: { span: 16 },
};
const basicLayout = {
labelCol: { span: 5 },
wrapperCol: { span: 18 },
};
return (
<Form className={styles.ui} {...formLayout} form={form} layout="horizontal" labelAlign="right" onValuesChange={run}>
<TitleStyle>自定义样式</TitleStyle>
<Form.Item name="scopeCss" noStyle>
<VsEditor language="css" />
</Form.Item>
<TitleStyle>基础</TitleStyle>
<Form.Item name={['scopeStyle', 'width']} label={'宽度'}>
<Form.Item name={['scopeStyle', 'width']} label={'宽度'} {...basicLayout}>
<InputPx />
</Form.Item>
<Form.Item name={['scopeStyle', 'height']} label={'高度'}>
<Form.Item name={['scopeStyle', 'height']} label={'高度'} {...basicLayout}>
<InputPx />
</Form.Item>
<MarginInput form={form} />
<PaddingInput form={form} />
<Form.Item key={'opacity'} name={['scopeStyle', 'opacity']} label={'透明度'}>
<Form.Item key={'opacity'} name={['scopeStyle', 'opacity']} label={'透明'} {...basicLayout}>
<Slider min={0} max={1} step={0.1} />
</Form.Item>
<TitleStyle>布局</TitleStyle>
Expand Down Expand Up @@ -236,7 +240,7 @@ const StyleConfig = () => {
></Select>
</Form.Item>
<TitleStyle>定位</TitleStyle>
<Form.Item key={'position'} name={['scopeStyle', 'position']} label={'定位'}>
<Form.Item key={'position'} name={['scopeStyle', 'position']} label={'定位'} {...basicLayout}>
<Select
placeholder={'请选择'}
options={[
Expand Down Expand Up @@ -264,20 +268,20 @@ const StyleConfig = () => {
suffixIcon={<CaretDownOutlined />}
/>
</Form.Item>
<Form.Item key={'zIndex'} name={['scopeStyle', 'zIndex']} label={'zIndex'}>
<InputNumber />
<Form.Item key={'zIndex'} name={['scopeStyle', 'zIndex']} label={'zIndex'} {...basicLayout}>
<InputNumber placeholder="层级" />
</Form.Item>
{!['', undefined, 'static'].includes(form.getFieldValue(['scopeStyle', 'position'])) && (
<Form.Item label="位置">
<Flex gap={10}>
<Form.Item label="位置" {...basicLayout}>
<Flex gap={3}>
<Form.Item name="top" noStyle>
<InputPx placeholder="T: 10" />
</Form.Item>
<Form.Item name="right" noStyle>
<InputPx placeholder="R: 10" />
</Form.Item>
</Flex>
<Flex gap={10} style={{ marginTop: 10 }}>
<Flex gap={3} style={{ marginTop: 10 }}>
<Form.Item name="bottom" noStyle>
<InputPx placeholder="B: 10" />
</Form.Item>
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/layout/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const Header = memo(() => {
const file = new File([blob], `${pageId}-${Date.now()}.png`, { type: 'image/png' });
const res = await uploadImg({
file: file, // File 对象
id: userInfo.userId + '_' + pageId, // 页面ID
});
return res.url;
} catch (error) {
Expand Down

0 comments on commit 38c27ec

Please sign in to comment.