-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Showing
19 changed files
with
4,978 additions
and
5,607 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
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
69 changes: 69 additions & 0 deletions
69
packages/editor/src/packages/Basic/CountDown/CountDown.tsx
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,69 @@ | ||
import React, { useState, useEffect, useImperativeHandle, forwardRef } from 'react'; | ||
import { Statistic } from 'antd'; | ||
import { ComponentType } from '@/packages/types'; | ||
import * as icons from '@ant-design/icons'; | ||
import { message } from '@/utils/AntdGlobal'; | ||
|
||
/** | ||
* | ||
* @param props 组件本身属性 | ||
* @param style 组件样式 | ||
* @returns | ||
*/ | ||
const CountDown = ({ id, type, config, onChange, onFinish }: ComponentType, ref: any) => { | ||
const [text, setText] = useState(0); | ||
const [visible, setVisible] = useState(true); | ||
|
||
useEffect(() => { | ||
if (isNaN(config.props?.value)) { | ||
console.error('倒计时组件值必须为时间戳类型'); | ||
message.error('倒计时组件值必须为时间戳'); | ||
return; | ||
} | ||
const originText = config.props?.value?.toString() || ''; | ||
const script = config.props?.script; | ||
let value: string | number = originText; | ||
|
||
if (script) { | ||
try { | ||
const renderFn = new Function('value', `return (${script})(value);`); | ||
value = renderFn(value); | ||
} catch (error) { | ||
console.error(`脚本解析失败`, error); | ||
message.error(JSON.stringify(error)); | ||
} | ||
} | ||
setText(Number(value?.toString())); | ||
}, [config.props.value, config.props?.script]); | ||
|
||
// 对外暴露方法 | ||
useImperativeHandle(ref, () => { | ||
return { | ||
show() { | ||
setVisible(true); | ||
}, | ||
hide() { | ||
setVisible(false); | ||
}, | ||
}; | ||
}); | ||
|
||
const iconsList: { [key: string]: any } = icons; | ||
return ( | ||
visible && ( | ||
<Statistic.Countdown | ||
style={config.style} | ||
{...config.props} | ||
value={text} | ||
format={config.props?.format || undefined} | ||
prefix={config.props.prefix ? React.createElement(iconsList[config.props.prefix]) : null} | ||
suffix={config.props.suffix ? React.createElement(iconsList[config.props.suffix]) : null} | ||
onChange={(val) => onChange?.(val)} | ||
onFinish={() => onFinish?.(text)} | ||
data-id={id} | ||
data-type={type} | ||
/> | ||
) | ||
); | ||
}; | ||
export default forwardRef(CountDown); |
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,81 @@ | ||
/** | ||
* 组件配置和属性值 | ||
*/ | ||
|
||
import { FormInstance } from 'antd'; | ||
import TextSetting from './TextSetting'; | ||
|
||
export default { | ||
// 组件属性配置JSON | ||
attrs: [ | ||
{ | ||
type: 'Title', | ||
label: '基础配置', | ||
key: 'basic', | ||
}, | ||
{ | ||
type: 'Input', | ||
label: '标题', | ||
name: 'title', | ||
}, | ||
{ | ||
type: 'Variable', | ||
label: '显示值', | ||
name: 'value', | ||
}, | ||
{ | ||
type: 'Input', | ||
label: '格式', | ||
name: 'format', | ||
}, | ||
{ | ||
type: 'Icons', | ||
label: '前缀', | ||
name: ['prefix'], | ||
}, | ||
{ | ||
type: 'Icons', | ||
label: '前缀', | ||
name: ['suffix'], | ||
}, | ||
{ | ||
type: 'function', | ||
label: '自定义渲染', | ||
key: 'render', | ||
render: (form: FormInstance) => { | ||
form.setFieldValue( | ||
'script', | ||
`function render(value){ | ||
return value; | ||
}`, | ||
); | ||
return <TextSetting key="render" form={form} />; | ||
}, | ||
}, | ||
], | ||
config: { | ||
// 组件默认属性值 | ||
props: { | ||
title: 'Countdown', | ||
value: Date.now() + 1000 * 60 * 60 * 24 * 2 + 1000 * 30, | ||
format: 'HH:mm:ss', | ||
}, | ||
style: {}, | ||
events: [], | ||
api: {}, | ||
source: '', | ||
}, | ||
// 组件事件 | ||
events: [ | ||
{ | ||
value: 'onChange', | ||
name: '变化事件', | ||
}, | ||
{ | ||
value: 'onFinish', | ||
name: '完成事件', | ||
}, | ||
], | ||
// 组件接口 | ||
api: {}, | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/editor/src/packages/Basic/CountDown/TextSetting.tsx
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,16 @@ | ||
import { Form } from 'antd'; | ||
import VsEditor from '@/components/VsEditor'; | ||
|
||
/** | ||
* 自定义渲染 | ||
*/ | ||
export default function TextSetting(props: any) { | ||
return ( | ||
<> | ||
<Form.Item label="自定义" tooltip="通过编程的方式,实现自定义渲染。"></Form.Item> | ||
<Form.Item name={['script']} noStyle> | ||
<VsEditor /> | ||
</Form.Item> | ||
</> | ||
); | ||
} |
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,2 @@ | ||
export { default as CountDown } from './CountDown'; | ||
export { default as CountDownConfig } from './Schema'; |
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,72 @@ | ||
/** | ||
* 组件配置和属性值 | ||
*/ | ||
|
||
import { FormInstance } from 'antd'; | ||
import TextSetting from './TextSetting'; | ||
|
||
export default { | ||
// 组件属性配置JSON | ||
attrs: [ | ||
{ | ||
type: 'Title', | ||
label: '基础配置', | ||
key: 'basic', | ||
}, | ||
{ | ||
type: 'Input', | ||
label: '标题', | ||
name: 'title', | ||
}, | ||
{ | ||
type: 'Variable', | ||
label: '显示值', | ||
name: 'value', | ||
}, | ||
{ | ||
type: 'InputNumber', | ||
label: '数值精度', | ||
name: 'precision', | ||
}, | ||
{ | ||
type: 'Icons', | ||
label: '前缀', | ||
name: ['prefix'], | ||
}, | ||
{ | ||
type: 'Icons', | ||
label: '前缀', | ||
name: ['suffix'], | ||
}, | ||
{ | ||
type: 'function', | ||
label: '自定义渲染', | ||
key: 'render', | ||
render: (form: FormInstance) => { | ||
form.setFieldValue( | ||
'script', | ||
`function render(value){ | ||
return value; | ||
}`, | ||
); | ||
return <TextSetting key="render" form={form} />; | ||
}, | ||
}, | ||
], | ||
config: { | ||
// 组件默认属性值 | ||
props: { | ||
title: '账户余额', | ||
value: 192672, | ||
precision: 2, | ||
}, | ||
style: {}, | ||
events: [], | ||
api: {}, | ||
source: '', | ||
}, | ||
// 组件事件 | ||
events: [], | ||
// 组件接口 | ||
api: {}, | ||
}; |
61 changes: 61 additions & 0 deletions
61
packages/editor/src/packages/Basic/Statistic/Statistic.tsx
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,61 @@ | ||
import React, { useState, useEffect, useImperativeHandle, forwardRef } from 'react'; | ||
import { Statistic } from 'antd'; | ||
import { ComponentType } from '@/packages/types'; | ||
import * as icons from '@ant-design/icons'; | ||
import { message } from '@/utils/AntdGlobal'; | ||
|
||
/** | ||
* | ||
* @param props 组件本身属性 | ||
* @param style 组件样式 | ||
* @returns | ||
*/ | ||
const MStatistic = ({ id, type, config }: ComponentType, ref: any) => { | ||
const [text, setText] = useState(''); | ||
const [visible, setVisible] = useState(true); | ||
|
||
useEffect(() => { | ||
const originText = config.props?.value?.toString() || ''; | ||
const script = config.props?.script; | ||
let value: string | number = originText; | ||
|
||
if (script) { | ||
try { | ||
const renderFn = new Function('value', `return (${script})(value);`); | ||
value = renderFn(value); | ||
} catch (error) { | ||
console.error(`脚本解析失败`, error); | ||
message.error(JSON.stringify(error)); | ||
} | ||
} | ||
setText(value?.toString()); | ||
}, [config.props.value, config.props?.script]); | ||
|
||
// 对外暴露方法 | ||
useImperativeHandle(ref, () => { | ||
return { | ||
show() { | ||
setVisible(true); | ||
}, | ||
hide() { | ||
setVisible(false); | ||
}, | ||
}; | ||
}); | ||
|
||
const iconsList: { [key: string]: any } = icons; | ||
return ( | ||
visible && ( | ||
<Statistic | ||
style={config.style} | ||
{...config.props} | ||
value={text} | ||
prefix={config.props.prefix ? React.createElement(iconsList[config.props.prefix]) : null} | ||
suffix={config.props.suffix ? React.createElement(iconsList[config.props.suffix]) : null} | ||
data-id={id} | ||
data-type={type} | ||
/> | ||
) | ||
); | ||
}; | ||
export default forwardRef(MStatistic); |
16 changes: 16 additions & 0 deletions
16
packages/editor/src/packages/Basic/Statistic/TextSetting.tsx
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,16 @@ | ||
import { Form } from 'antd'; | ||
import VsEditor from '@/components/VsEditor'; | ||
|
||
/** | ||
* 自定义渲染 | ||
*/ | ||
export default function TextSetting(props: any) { | ||
return ( | ||
<> | ||
<Form.Item label="自定义" tooltip="通过编程的方式,实现自定义渲染。"></Form.Item> | ||
<Form.Item name={['script']} noStyle> | ||
<VsEditor /> | ||
</Form.Item> | ||
</> | ||
); | ||
} |
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,2 @@ | ||
export { default as Statistic } from './Statistic'; | ||
export { default as StatisticConfig } from './Schema'; |
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
Oops, something went wrong.