({ visible, onOk, onCancel }: DevModalProps)
| 15 | } |
| 16 | |
| 17 | const DevModal = ({ visible, onOk, onCancel }: DevModalProps) => { |
| 18 | const [form] = Form.useForm(); |
| 19 | useEffect(() => { |
| 20 | if (visible) { |
| 21 | try { |
| 22 | const microApiList: MicroDevApiList[] = JSON.parse(getLocalStorage(Constant.MICRO_FRONTEND_API_LIST)); |
| 23 | form.setFieldsValue({ microApiList: microApiList.map(i => ({ url: i.url, enabled: i.enabled !== false })) }); |
| 24 | } catch (e) { |
| 25 | debug(e); |
| 26 | } |
| 27 | } |
| 28 | }, [visible, form]); |
| 29 | |
| 30 | const onConfirm = () => { |
| 31 | form.validate().then((result) => { |
| 32 | if (result === true) { |
| 33 | const { microApiList } = form.getFieldsValue(true); |
| 34 | const data = JSON.stringify(unionBy((microApiList as MicroDevApiList[]).filter(i => i.url).map((api) => { |
| 35 | const { url } = api; |
| 36 | const name = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.')); |
| 37 | return { ...api, name }; |
| 38 | }), 'name')); |
| 39 | setLocalStorage(Constant.MICRO_FRONTEND_API_LIST, data); |
| 40 | onOk(data); |
| 41 | } |
| 42 | }); |
| 43 | }; |
| 44 | |
| 45 | return <Dialog |
| 46 | visible={visible} |
| 47 | header="Micro Frontend Dev" |
| 48 | onConfirm={onConfirm} |
| 49 | onClose={onCancel} |
| 50 | onCancel={onCancel} |
| 51 | onClosed={form.reset} |
| 52 | > |
| 53 | <Form layout="vertical" form={form} > |
| 54 | <FormList name={['microApiList']}> |
| 55 | {(fields, { add, remove }) => ( |
| 56 | <> |
| 57 | {fields.map(({ key, name, ...restField }) => ( |
| 58 | <FormItem key={key} > |
| 59 | <FormItem {...restField} name={[name, 'url']} style={{ width: '100%' }}> |
| 60 | <Input /> |
| 61 | </FormItem> |
| 62 | <FormItem {...restField} name={[name, 'enabled']} initialData={true}> |
| 63 | <Switch /> |
| 64 | </FormItem> |
| 65 | <FormItem> |
| 66 | <MinusCircleIcon size="20px" style={{ cursor: 'pointer' }} onClick={() => remove(name)} /> |
| 67 | </FormItem> |
| 68 | </FormItem> |
| 69 | ))} |
| 70 | <FormItem> |
| 71 | <Button icon={<AddIcon />} theme="default" variant="dashed" onClick={() => add({ province: 'bj', area: 'tzmax' })}> |
| 72 | 添加微前端开发环境地址 |
| 73 | </Button> |
| 74 | </FormItem> |
nothing calls this directly
no test coverage detected