import type { IControlComponentAction, IControlQueryAction, IPublicTypeEventHandler, IRunFunctionAction, ISetLocalStorageAction, ISetTemporaryStateAction } from '@webank/letgo-types'; import { InnerEventHandlerAction } from '@webank/letgo-types'; import type { PropType } from 'vue'; import { computed, defineComponent, ref } from 'vue'; import { FInput, FOption, FSelect } from '@fesjs/fes-design'; import type { DocumentModel } from '@webank/letgo-designer'; import { DeleteOutlined, PlusCircleOutlined } from '@fesjs/fes-design/icon'; import Label from './label'; import './render-options.less'; export default defineComponent({ name: 'RenderOptions', props: { documentModel: Object as PropType, componentEvent: Object as PropType, onChange: Function as PropType<((content: Record) => void)>, }, setup(props) { const queryOptions = computed(() => { return props.documentModel.code.queries.map((item) => { return { label: item.id, value: item.id, }; }); }); const renderQuery = (data: IControlQueryAction) => { return ( <> ); }; const componentInstanceOptions = computed(() => { return Object.keys(props.documentModel.state.componentsInstance).map((key) => { return { label: key, value: key, }; }); }); const componentMethods = ref<{ label: string, value: string }[]>([]); const selectComponent = (value: string) => { const componentName = props.documentModel.state.componentsInstance[value]._componentName; const metadata = props.documentModel.getComponentMeta(componentName).getMetadata(); componentMethods.value = (metadata.configure?.supports?.methods || []).map((item) => { if (typeof item === 'string') { return { label: item, value: item, }; } return { label: item.name, value: item.name, }; }); }; // TODO 参数配置 const renderComponentMethod = (data: IControlComponentAction) => { return ( <> ); }; const stateOptions = computed(() => { return props.documentModel.code.temporaryStates.map((item) => { return { label: item.id, value: item.id, }; }).concat(props.documentModel.project.code.temporaryStates.map((item) => { return { label: item.id, value: `${item.id}.value`, }; })); }); const renderSetTemporaryState = (data: ISetTemporaryStateAction) => { return ( <> ); }; const renderSetLocalStorage = (data: ISetLocalStorageAction) => { return ( <> ); }; const functionOptions = computed(() => { return props.documentModel.code.functions.map((item) => { return { label: item.id, value: item.id, }; }); }); const addFunctionParam = (data: IRunFunctionAction) => { data.params.push(''); }; const deleteFunctionParam = (data: IRunFunctionAction, index: number) => { data.params.splice(index, 1); }; const renderRunFunction = (data: IRunFunctionAction) => { return ( <> ); }; return () => { if (props.componentEvent.action === InnerEventHandlerAction.CONTROL_QUERY) return renderQuery(props.componentEvent as IControlQueryAction); if (props.componentEvent.action === InnerEventHandlerAction.CONTROL_COMPONENT) return renderComponentMethod(props.componentEvent as IControlComponentAction); if (props.componentEvent.action === InnerEventHandlerAction.SET_TEMPORARY_STATE) return renderSetTemporaryState(props.componentEvent as ISetTemporaryStateAction); if (props.componentEvent.action === InnerEventHandlerAction.SET_LOCAL_STORAGE) return renderSetLocalStorage(props.componentEvent as ISetLocalStorageAction); if (props.componentEvent.action === InnerEventHandlerAction.RUN_FUNCTION) return renderRunFunction(props.componentEvent as IRunFunctionAction); }; }, });