skyouc
2025-05-02 ee608e161f17082b9fd6e1ed236214a0ac5c2f0e
rsf-admin/src/page/components/ImportModal.jsx
@@ -1,4 +1,4 @@
import { useEffect, useState } from 'react';
import { useEffect, useState, createContext, useContext } from 'react';
import { Box, CircularProgress, Stack, Typography } from '@mui/material';
import Alert from '@mui/material/Alert';
import Dialog from '@mui/material/Dialog';
@@ -13,14 +13,16 @@
    Form,
    Toolbar,
    useRefresh,
    useTranslate
    useTranslate,
    useNotify
} from 'react-admin';
import { Link } from 'react-router-dom';
import DialogCloseButton from './DialogCloseButton';
import { usePapaParse } from './usePapaParse';
import MatnrList from '../basicInfo/matnr/MatnrList';
import request from '@/utils/request'
const ImportModal = ({ open, onClose, importTemp, useCodeImport, onceBatch = 10 }) => {
const ImportModal = ({ open, onClose, importTemp, useCodeImport, onceBatch = 10, value, parmas = {}}) => {
    const refresh = useRefresh();
    const translate = useTranslate();
@@ -31,6 +33,7 @@
    });
    const [file, setFile] = useState(null);
    const notify = useNotify();
    useEffect(() => {
        if (importer.state === 'complete') {
@@ -46,8 +49,21 @@
        if (!file) {
            return;
        }
        console.log(file);
        //TODO 添加上文件上传接口
        const form = new FormData();
        for (const key in parmas) {
            if (parmas.hasOwnProperty(key)) {
                form.append(key, parmas[key]);
            }
        }
        form.append('file', file);
        const { data: { code, data, msg } } = await request.post(`/${value}/import`, form)
        if (code === 200) {
            handleClose()
            notify(msg);
            refresh()
        } else {
            notify(msg);
        }
    };
@@ -60,6 +76,22 @@
        e.preventDefault();
        reset();
    };
    const downloadTemplate = async (type) => {
        const res = await request.post(`/${value}/template/download`, {}, {
            responseType: "blob",
        })
        const url = window.URL.createObjectURL(
            new Blob([res.data], { type: res.headers["content-type"] }),
        );
        const link = document.createElement("a");
        link.href = url;
        link.setAttribute("download", `${value}.xlsx`);
        document.body.appendChild(link);
        link.click();
        link.remove();
    }
    return (
        <Dialog open={open} maxWidth="md" fullWidth>
@@ -211,15 +243,8 @@
        </Dialog>
    );
}
{/**下载打印模板,传入type类型,调用下载模板接口 */}
const downloadTemplate = (type) => {
    // 下载物料模板
    if (type != undefined &&  type == 'matnr') {
    }
    console.log('======>');
    console.log(type);
}
{/**下载打印模板,传入type类型,调用下载模板接口 */ }
function millisecondsToTime(ms) {
    var seconds = Math.floor((ms / 1000) % 60);