Skip to content

Commit

Permalink
chore: 修改自定义组件默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft committed Oct 29, 2024
1 parent 068ee80 commit daf0e80
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/editor/src/pages/home/lib/components/InitValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
export const defaultReactCode = `/**
* 支持React、Antd、dayjs 等插件使用,需要从window对象中导入:
* eg: const { Button } = window.antd;
* const { useEffect,useState } = window.React;
*/
export default ({ id, type, config }, ref) => {
export default ({ id, type, config, onClick }, ref) => {
const { Button } = window.antd;
const format = () => {
return dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss');
};
// 点击会触发父组件的onClick事件,可以在平台中配置事件流。
const handleClick = () => {
onClick && onClick({ id, type });
};
return (
<div className="bgColor" data-id={id} data-type={type}>
<Button style={config.style} {...config.props}>
<Button style={config.style} {...config.props} onClick={handleClick}>
{config.props.text}
</Button>
<p>{format()}</p>
Expand Down Expand Up @@ -145,13 +150,16 @@ export const defaultMdCode = `# 自定义组件
/**
* 支持React、Antd、dayjs 等插件使用,不用导入,直接用即可。
*/
export default ({ id, type, config },ref) => {
export default ({ id, type, config, onClick },ref) => {
const format = () => {
return dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss');
};
const handleClick = () => {
onClick && onClick({ id, type });
};
return (
<div className="bgColor" data-id={id} data-type={type}>
<Button style={config.style} {...config.props}>
<Button style={config.style} {...config.props} onClick={handleClick}>
{config.props.text}
</Button>
<p>{format()}</p>
Expand Down

0 comments on commit daf0e80

Please sign in to comment.