refactor: storechanger&functioncenter

This commit is contained in:
yehuozhili
2022-04-24 00:38:03 +08:00
parent 54c99aad0d
commit 5780b1b5f2
28 changed files with 498 additions and 548 deletions

View File

@@ -2,7 +2,7 @@
* @Author: yehuozhili
* @Date: 2021-07-07 14:46:01
* @LastEditors: yehuozhili
* @LastEditTime: 2021-07-13 11:30:17
* @LastEditTime: 2022-04-23 18:40:40
* @FilePath: \dooringx\packages\dooringx-example\src\plugin\formComponents\actionButton.tsx
*/
@@ -39,14 +39,8 @@ function ActionButton(props: ActionButtonProps) {
const functionConfig = functionCenter.getConfigMap();
const functionMap = functionCenter.getFunctionMap();
const functionNameMap = functionCenter.getNameMap();
const isEdit = props.config.getStoreChanger().isEdit();
const dataMap = props.config.getDataCenter().getDataMap();
let modalMap: Record<string, IStoreData>;
if (isEdit) {
modalMap = props.config.getStoreChanger().getOrigin()?.now.modalMap || {};
} else {
modalMap = props.config.getStore().getData().modalMap;
}
let modalMap = props.config.getStore().getData().modalMap;
const handleInputDataSource = useCallback(
(

View File

@@ -2,12 +2,37 @@
* @Author: yehuozhili
* @Date: 2021-07-07 14:22:51
* @LastEditors: yehuozhili
* @LastEditTime: 2021-08-05 14:53:12
* @LastEditTime: 2022-04-24 00:11:35
* @FilePath: \dooringx\packages\dooringx-example\src\plugin\functionMap\index.ts
*/
import { FunctionCenterType } from 'dooringx-lib/dist/core/functionCenter';
export const functionMap: FunctionCenterType = {
sleep: {
fn: (ctx, next, _config, args) => {
const arr = args['_sk'];
let num = parseInt(arr[0]);
if (isNaN(num)) {
next();
} else {
setTimeout(() => {
next();
}, arr[0]);
}
},
config: [
{
name: '输入数值单位ms',
data: ['input'],
options: {
receive: '_sk',
multi: false,
},
},
],
name: '等待',
componentId: '_inner',
},
: {
fn: (ctx, next, _config, args) => {
const arr = args['_sk'];
@@ -39,5 +64,6 @@ export const functionMap: FunctionCenterType = {
},
],
name: '上下文转对象',
componentId: '_inner',
},
};

View File

@@ -2,7 +2,7 @@
* @Author: yehuozhili
* @Date: 2021-07-07 14:35:38
* @LastEditors: yehuozhili
* @LastEditTime: 2021-08-05 15:10:31
* @LastEditTime: 2022-04-24 00:29:46
* @FilePath: \dooringx\packages\dooringx-example\src\plugin\registComponents\button.tsx
*/
@@ -16,7 +16,7 @@ import {
} from 'dooringx-lib';
import { FormMap } from '../formTypes';
import { ComponentRenderConfigProps } from 'dooringx-lib/dist/core/components/componentItem';
let s = 0;
function ButtonTemp(pr: ComponentRenderConfigProps) {
const props = pr.data.props;
const eventCenter = useMemo(() => {
@@ -35,12 +35,13 @@ function ButtonTemp(pr: ComponentRenderConfigProps) {
const [text, setText] = useState('');
const op1 = props.op1;
useEffect(() => {
let unregist = () => {};
let unRegist = () => {};
if (op1) {
console.log('kkk');
const functionCenter = eventCenter.getFunctionCenter();
unregist = functionCenter.register(
`${pr.data.id}+changeText`,
async (ctx, next, config, args: any, _eventList, iname) => {
unRegist = functionCenter.register({
id: `${pr.data.id}+changeText`,
fn: async (ctx, next, config, args: any, _eventList, iname) => {
const userSelect = iname.data;
const ctxVal = changeUserValue(
userSelect['改变文本数据源'],
@@ -49,11 +50,13 @@ function ButtonTemp(pr: ComponentRenderConfigProps) {
config,
ctx
);
const text = ctxVal[0];
s = s++;
const text = ctxVal[0] + s;
setText(text);
next();
},
[
config: [
{
name: '改变文本数据源',
data: ['ctx', 'input', 'dataSource'],
@@ -63,14 +66,16 @@ function ButtonTemp(pr: ComponentRenderConfigProps) {
},
},
],
`${pr.data.id}+改变文本函数`
);
name: `${pr.data.id}+改变文本函数`,
componentId: pr.data.id,
});
}
return () => {
unregist();
if (pr.context === 'preview') {
unRegist(); // 必须在预览时注销,否则影响二次点击效果,不在预览注销影响编辑时跨弹窗
}
};
}, [op1]);
return (
<Button
style={{

View File

@@ -2,7 +2,7 @@
* @Author: yehuozhili
* @Date: 2021-08-05 10:50:57
* @LastEditors: yehuozhili
* @LastEditTime: 2021-08-05 15:10:46
* @LastEditTime: 2022-04-23 23:38:31
* @FilePath: \dooringx\packages\dooringx-example\src\plugin\registComponents\inputCo.tsx
*/
@@ -33,9 +33,9 @@ const InputTemp = (pr: InputProps) => {
let unregist = () => {};
if (props.op1) {
const functionCenter = eventCenter.getFunctionCenter();
unregist = functionCenter.register(
`${pr.data.id}+validate-func`,
async (_ctx, next, _config, _args: any, _eventList, _iname) => {
unregist = functionCenter.register({
id: `${pr.data.id}+validate-func`,
fn: async (_ctx, next, _config, _args: any, _eventList, _iname) => {
if (value === '') {
setErr(props.warnning);
} else {
@@ -43,7 +43,7 @@ const InputTemp = (pr: InputProps) => {
next();
}
},
[
config: [
{
name: '验证已填函数',
data: [],
@@ -53,8 +53,9 @@ const InputTemp = (pr: InputProps) => {
},
},
],
`${pr.data.id}+验证已填函数`
);
name: `${pr.data.id}+验证已填函数`,
componentId: pr.data.id,
});
}
return () => {
unregist();
@@ -65,14 +66,14 @@ const InputTemp = (pr: InputProps) => {
let unregist = () => {};
if (props.op2) {
const functionCenter = eventCenter.getFunctionCenter();
unregist = functionCenter.register(
`${pr.data.id}+get-input`,
async (ctx, next, _config, args: any, _eventList, _iname) => {
unregist = functionCenter.register({
id: `${pr.data.id}+get-input`,
fn: async (ctx, next, _config, args: any, _eventList, _iname) => {
const key = args['_changeval'][0];
ctx[key] = value;
next();
},
[
config: [
{
name: '获取数据至上下文',
data: ['ctx'],
@@ -82,8 +83,9 @@ const InputTemp = (pr: InputProps) => {
},
},
],
`${pr.data.id}+获取输入数据`
);
name: `${pr.data.id}+获取输入数据`,
componentId: pr.data.id,
});
}
return () => {
unregist();