forked from sleepy-zone/fabritor-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
51c04d8
commit 985fb37
Showing
4 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { LeftOutlined } from '@ant-design/icons'; | ||
import { Card, Flex } from 'antd'; | ||
|
||
export default function AppSubPanel (props) { | ||
const { title, children, back } = props; | ||
|
||
const back2AppList = () => { | ||
back && back(); | ||
} | ||
|
||
return ( | ||
<Card | ||
bordered={false} | ||
style={{ marginLeft: -24, boxShadow: 'none' }} | ||
bodyStyle={{ padding: 12 }} | ||
title={ | ||
<Flex justify="space-between"> | ||
<LeftOutlined onClick={back2AppList} /> | ||
<p>{title}</p> | ||
</Flex> | ||
} | ||
> | ||
{children} | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { Button, Form, Input, InputNumber, QRCode, Radio, Switch, Collapse, Flex } from 'antd'; | ||
import AppSubPanel from './AppSubPanel'; | ||
import ColorSetter from '@/fabritor/components/ColorSetter'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
import { createFImage } from '@/editor/image'; | ||
|
||
const { Item: FormItem } = Form; | ||
|
||
export default function QRCodePanel (props) { | ||
const { back } = props; | ||
const [form] = Form.useForm(); | ||
const [form2] = Form.useForm(); | ||
const [QRCodeConfig, setQRCodeConfig] = useState({ value: 'fabritor' }); | ||
const qrRef = useRef<HTMLDivElement>(null); | ||
|
||
const handleValuesChange = (values) => { | ||
setQRCodeConfig({ | ||
...QRCodeConfig, | ||
...values | ||
}); | ||
} | ||
|
||
const add2Canvas = () => { | ||
if (!QRCodeConfig.value || !qrRef.current) return; | ||
const canvas = qrRef.current.querySelector('canvas'); | ||
if (!canvas) return; | ||
const img = new Image(); | ||
img.onload = () => { | ||
createFImage({ | ||
imageSource: img | ||
}); | ||
} | ||
img.src = canvas.toDataURL(); | ||
} | ||
|
||
useEffect(() => { | ||
form.setFieldsValue({ | ||
value: 'fabritor', | ||
size: 160 | ||
}); | ||
form2.setFieldsValue({ | ||
color: '#000000', | ||
bgColor: '#00000000', | ||
iconSize: 40, | ||
errorLevel: 'M' | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<AppSubPanel title="二维码" back={back}> | ||
<Form | ||
form={form} | ||
onValuesChange={handleValuesChange} | ||
> | ||
<FormItem name="value" label="文本"> | ||
<Input /> | ||
</FormItem> | ||
<FormItem name="size" label="大小"> | ||
<InputNumber /> | ||
</FormItem> | ||
</Form> | ||
<Collapse | ||
items={[ | ||
{ | ||
key: '1', | ||
label: '其他设置', | ||
children: ( | ||
<Form | ||
form={form2} | ||
onValuesChange={handleValuesChange} | ||
> | ||
<FormItem name="color" label="颜色"> | ||
<ColorSetter /> | ||
</FormItem> | ||
<FormItem name="bgColor" label="背景色"> | ||
<ColorSetter /> | ||
</FormItem> | ||
<FormItem name="errorLevel" label="纠错等级"> | ||
<Radio.Group options={['L', 'M', 'Q', 'H']} /> | ||
</FormItem> | ||
<FormItem name="icon" label="内置图片"> | ||
<Input placeholder="仅支持图片链接" /> | ||
</FormItem> | ||
<FormItem name="iconSize" label="内置图片大小"> | ||
<InputNumber /> | ||
</FormItem> | ||
</Form> | ||
) | ||
} | ||
]} | ||
/> | ||
{ | ||
QRCodeConfig.value ? | ||
<Flex vertical align="center" gap={10} style={{ marginTop: 16 }} ref={qrRef}> | ||
<QRCode | ||
type="canvas" | ||
{...QRCodeConfig} | ||
style={{ maxWidth: 200 }} | ||
/> | ||
<Button type="primary" onClick={add2Canvas}>添加至画布</Button> | ||
</Flex> : null | ||
} | ||
</AppSubPanel> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters