2024-01-17 09:37:01 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'umi'
|
|
|
|
import type { UploadProps } from 'antd';
|
2024-01-18 18:27:38 +08:00
|
|
|
import { Button, Upload } from 'antd';
|
2024-01-17 09:37:01 +08:00
|
|
|
import uploadService from '@/services/uploadService'
|
2024-01-18 18:27:38 +08:00
|
|
|
interface PropsType {
|
|
|
|
kb_id: string;
|
|
|
|
getKfList: () => void
|
|
|
|
}
|
|
|
|
type UploadRequestOption = Parameters<
|
|
|
|
NonNullable<UploadProps["customRequest"]>
|
|
|
|
>[0];
|
|
|
|
const Index: React.FC<PropsType> = ({ kb_id, getKfList }) => {
|
|
|
|
const createRequest: (props: UploadRequestOption) => void = async function ({ file, onSuccess, onError }) {
|
2024-01-17 09:37:01 +08:00
|
|
|
const { retcode, data } = await uploadService.uploadFile(file, kb_id);
|
|
|
|
if (retcode === 0) {
|
2024-01-18 18:27:38 +08:00
|
|
|
onSuccess && onSuccess(data, file);
|
2024-01-17 09:37:01 +08:00
|
|
|
|
|
|
|
} else {
|
2024-01-18 18:27:38 +08:00
|
|
|
onError && onError(data);
|
2024-01-17 09:37:01 +08:00
|
|
|
}
|
|
|
|
getKfList && getKfList()
|
|
|
|
};
|
|
|
|
const uploadProps: UploadProps = {
|
|
|
|
customRequest: createRequest,
|
|
|
|
showUploadList: false,
|
|
|
|
};
|
|
|
|
return (<Upload {...uploadProps} >
|
|
|
|
<Button type="link">导入文件</Button>
|
|
|
|
</Upload>)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(({ kFModel, settingModel, loading }) => ({ kFModel, settingModel, loading }))(Index);
|