import type { PropType } from 'vue'; import { computed, defineComponent, ref, watch } from 'vue'; import { FButton, FInput, FInputNumber, FOption, FSelect, FSpace } from '@fesjs/fes-design'; import type { IPublicTypeEventHandler } from '@webank/letgo-types'; import { InnerEventHandlerAction } from '@webank/letgo-types'; import type { DocumentModel } from '@webank/letgo-designer'; import Label from './label'; import Separator from './separator'; import RenderOptions from './render-options'; import './modify-block.less'; const actions = [{ value: InnerEventHandlerAction.CONTROL_QUERY, label: '控制查询', }, { value: InnerEventHandlerAction.CONTROL_COMPONENT, label: '控制组件', }, { value: InnerEventHandlerAction.SET_TEMPORARY_STATE, label: '设置变量值', }, { value: InnerEventHandlerAction.SET_LOCAL_STORAGE, label: '设置本地存储', }, { value: InnerEventHandlerAction.RUN_FUNCTION, label: '执行函数', }]; const initOptions: any = { [InnerEventHandlerAction.CONTROL_QUERY]: { namespace: null, method: 'trigger', }, [InnerEventHandlerAction.CONTROL_COMPONENT]: { namespace: null, method: null, }, [InnerEventHandlerAction.SET_TEMPORARY_STATE]: { namespace: null, method: 'setValue', params: [], }, [InnerEventHandlerAction.SET_LOCAL_STORAGE]: { namespace: 'localStorage', method: 'setValue', params: [], }, [InnerEventHandlerAction.RUN_FUNCTION]: { namespace: null, method: null, funcBody: '', params: [], }, }; interface Option { label: string, value: string } export default defineComponent({ name: 'EventHandlerModify', props: { documentModel: Object as PropType, editEvent: Object as PropType, events: { type: Array as PropType, default: () => [] as Option[], }, onChange: Function as PropType<(data: IPublicTypeEventHandler) => void>, }, setup(props) { const innerEditEvent = ref({ ...props.editEvent }); watch(() => props.editEvent, () => { innerEditEvent.value = { ...props.editEvent, }; }); const renderEvent = () => { return props.events.length ? ( ) : null; }; const currentAction = ref(); const changeAction = () => { innerEditEvent.value = { id: innerEditEvent.value.id, name: innerEditEvent.value.name, onlyRunWhen: innerEditEvent.value.onlyRunWhen, waitMs: innerEditEvent.value.waitMs, action: innerEditEvent.value.action, ...initOptions[innerEditEvent.value.action], }; }; const renderAction = () => { return ( ); }; const firstSeparatorText = computed(() => { const item = actions.find(item => item.value === currentAction.value); return item ? `${item.label}选项` : '选项'; }); const onSave = () => { props.onChange({ ...innerEditEvent.value, }); }; const changeCurrentEvent = (content: Record) => { Object.assign(innerEditEvent.value, content); }; return () => { return (
{renderEvent()} {renderAction()} 保存
); }; }, });