/* * @Author: yehuozhili * @Date: 2021-07-07 14:46:01 * @LastEditors: yehuozhili * @LastEditTime: 2021-07-13 11:30:17 * @FilePath: \dooringx\packages\dooringx-example\src\plugin\formComponents\actionButton.tsx */ import { Button, Col, Input, message, Modal, Row, Select } from 'antd'; import { memo, useMemo, useState } from 'react'; import React, { useCallback } from 'react'; import { UserConfig, createUid, deepCopy } from 'dooringx-lib'; import { unstable_batchedUpdates } from 'react-dom'; import { FormMap } from '../formTypes'; import { CreateOptionsRes } from 'dooringx-lib/dist/core/components/formTypes'; import { IBlockType, IStoreData } from 'dooringx-lib/dist/core/store/storetype'; import { FunctionConfigType } from 'dooringx-lib/dist/core/functionCenter/config'; import { EventCenterUserSelect } from 'dooringx-lib/dist/core/eventCenter'; const { Option } = Select; interface ActionButtonProps { data: CreateOptionsRes; current: IBlockType; config: UserConfig; } function ActionButton(props: ActionButtonProps) { const [visible, setVisible] = useState(false); const [cur, setCur] = useState(''); const eventMap = props.config.getEventCenter().getEventMap(); const currentOption = useMemo(() => { return Object.keys(eventMap).filter((v) => v.indexOf(props.current.id) >= 0); }, [eventMap, props.current.id]); const [search, setSearch] = useState([]); const functionCenter = props.config.getEventCenter().getFunctionCenter(); 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; if (isEdit) { modalMap = props.config.getStoreChanger().getOrigin()?.now.modalMap || {}; } else { modalMap = props.config.getStore().getData().modalMap; } const handleInputDataSource = useCallback( ( w: { uid: string; value: string; detail: Record; }, c: any, name = 'dataSource' ) => { return (
{w.detail[name] && w.detail[name][c.name] && w.detail[name][c.name].map((vvv: string, x: number) => { return ( ); })}
); }, [] ); const handleInput = useCallback( ( w: { uid: string; value: string; detail: Record; }, c: any, name = 'ctx' ) => { return (
{w.detail[name] && w.detail[name][c.name] && w.detail[name][c.name].map((vvv: string, x: number) => { return ( { const value = e.target.value; setSearch((pre) => { pre.forEach((v) => { v.uid === w.uid ? (v.detail[name][c.name][x] = value || '') : ''; }); return [...pre]; }); }} > ); })}
); }, [] ); return (
标识ID {props.current.id} {currentOption.map((j, i) => { return (
{eventMap[j].displayName}
); })} { // 更新store中的eventMap const store = props.config.getStore(); const cloneData: IStoreData = deepCopy(store.getData()); const arr = search.map((v) => { // name: string; // 函数名 // args: Record; // 输入参数都会变成对象传来, // data: Record; // 用户选的种类 键是每个配置项名 const name = v.value; //函数名 const options: FunctionConfigType = functionConfig[name]; const dataMap = v.detail['data']; const combine = options.map((jkk) => { const select: string = dataMap[jkk.name]; // datasource / input / modal let val = {}; if (select) { const value = v.detail[select]; //{name:array<>} const receive = jkk.options.receive; val = { [receive]: value[jkk.name] }; //这里不能换算,否则修改data后值不会更新 } const choose = { [jkk.name]: select }; return { ...v, choose, val, }; }); const combineVal = combine.reduce((prev, next) => { return Object.assign(prev, next.val); }, {}); const combineChoose = combine.reduce((prev, next) => { return Object.assign(prev, next.choose); }, {}); return { name: name, data: combineChoose, args: combineVal, }; }); let displayName = ''; cloneData.block.forEach((v) => { if (v.id === props.current.id) { v.eventMap[cur].userSelect = search; v.eventMap[cur].arr = arr; displayName = v.eventMap[cur].displayName; } }); const eventCenter = props.config.getEventCenter(); eventCenter.manualUpdateMap(cur, displayName, arr); store.setData(cloneData); setVisible(false); }} onCancel={() => { setVisible(false); }} visible={visible} >
触发事件ID: {cur}
{search.map((w, i) => { const current = search.find((v) => v.uid === w.uid); const options: FunctionConfigType | undefined = functionConfig[current?.value || '']; return (
选择函数:
{options && options.map((c) => { if (c.data.length === 0) { return
; } return ( {c.name}: { } {w.detail['data'] && w.detail['data'][c.name] === 'dataSource' && (
{handleInputDataSource(w, c)}
)} {w.detail['data'] && w.detail['data'][c.name] === 'ctx' && (
{handleInput(w, c, 'ctx')}
)} {w.detail['data'] && w.detail['data'][c.name] === 'input' && (
{handleInput(w, c, 'input')}
)} {w.detail['data'] && w.detail['data'][c.name] === 'modal' && (
)}
); })}
); })}
); } export default memo(ActionButton);