import * as React from 'react'; import { Radio, Select, Box, Input } from '@alifd/next'; import { BehaviorActionProps, BehaviorAction } from '../types'; const fetchLinkList = async (url: string) => (url ? (await fetch(url)).json() : []); interface LinkActionValue { type?: 'internal' | 'external'; target?: string; url?: string; } interface LinkActionOptions { url?: string; responseFormatter: (dataSource: any[]) => any[]; } function fillDefaultValue(value: LinkActionValue) { if (typeof value !== 'object') { console.warn('value passed to fillDefaultValue should be an object'); return; } if (!value.target) { value.target = '_self'; } if (!value.type) { value.type = 'internal'; } } const LinkContent: React.FC> = ({ value = {}, onChange, options = {}, }) => { fillDefaultValue(value); const { url, responseFormatter } = options; const formatter = responseFormatter; const [data, setData] = React.useState([]); React.useEffect(() => { let ignore = false; fetchLinkList(url).then((result) => { if (!ignore) { setData(formatter ? formatter(result) : result); } }); return () => { ignore = true; }; }, [url, formatter]); return ( 跳转方式 { onChange({ ...value, target, }); }} /> 跳转类型 { onChange({ ...value, type, }); }} /> 跳转页面 {value?.type === 'external' ? ( { onChange({ type: value.type || 'internal', url: val, }); }} /> ) : (