/** * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug * Copyright (c) * Released under the AGPL-3.0 License. */ import React, { useState } from 'react'; import { observer } from 'mobx-react'; import { UploadOutlined } from '@ant-design/icons'; import { Modal, Form, Upload, Button, Tooltip, Alert, Cascader, message } from 'antd'; import http from 'libs/http'; import store from './store'; export default observer(function () { const [loading, setLoading] = useState(false); const [fileList, setFileList] = useState([]); const [groupId, setGroupId] = useState([]); function handleSubmit() { if (groupId.length === 0) return message.error('请选择要导入的分组'); setLoading(true); const formData = new FormData(); formData.append('file', fileList[0]); formData.append('group_id', groupId[groupId.length - 1]); http.post('/api/host/import/', formData, {timeout: 120000}) .then(res => { Modal.info({ title: '导入结果', content:
{res.success.length} {res['skip'].length > 0 && {res['skip'].length} } {res['invalid'].length > 0 && {res['invalid'].length} } {res['repeat'].length > 0 && {res['repeat'].length} }
, onOk: () => { store.fetchRecords(); store.importVisible = false } }) }) .finally(() => setLoading(false)) } function handleUpload(v) { if (v.fileList.length === 0) { setFileList([]) } else { setFileList([v.file]) } } return ( store.importVisible = false} confirmLoading={loading} okButtonProps={{disabled: !fileList.length}} onOk={handleSubmit}>
主机导入模板.xlsx false} onChange={handleUpload}> {fileList.length === 0 && ( )}
); })