1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| let items = [ { label: <Upload multiple={false} showUploadList={false} accept=".json" customRequest={onSelect}>导入</Upload>, icon: <ImportOutlined/>, key: 1 } ]
<Menu selectedKeys={1} items={menuItems} />
const onSelect = (info: any) => { let {file} = info let reader = new FileReader(); reader.onload = (e: ProgressEvent<FileReader>) => { if (e && e.target && e.target.result) { let space: string = e.target.result.toString(); importSpace(JSON.parse(space)) .then(() => { message.success("导入成功"); }) .catch(e => message.error("导入失败")); } }; reader.readAsText(file); };
|