From 99411967019bbf0d7b0b971eae0db2c2c58025f0 Mon Sep 17 00:00:00 2001
From: skyouc <958836976@qq.com>
Date: 星期六, 30 八月 2025 16:27:47 +0800
Subject: [PATCH] 修改任务状态
---
rsf-admin/src/page/components/ImportModal.jsx | 79 ++++++++++++++++++++++++++++++++-------
1 files changed, 64 insertions(+), 15 deletions(-)
diff --git a/rsf-admin/src/page/components/ImportModal.jsx b/rsf-admin/src/page/components/ImportModal.jsx
index 501cb22..caee07f 100644
--- a/rsf-admin/src/page/components/ImportModal.jsx
+++ b/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,13 +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';
-
-const ImportModal = ({ open, onClose, importTemp, useCodeImport, onceBatch = 10 }) => {
+import MatnrList from '../basicInfo/matnr/MatnrList';
+import request from '@/utils/request'
+import ImportExportOutlinedIcon from '@mui/icons-material/ImportExportOutlined';
+const ImportModal = ({ open, onClose, importTemp, useCodeImport, onceBatch = 10, value, parmas = {}}) => {
const refresh = useRefresh();
const translate = useTranslate();
@@ -30,6 +33,7 @@
});
const [file, setFile] = useState(null);
+ const notify = useNotify();
useEffect(() => {
if (importer.state === 'complete') {
@@ -45,8 +49,24 @@
if (!file) {
return;
}
+ 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 {
+ handleClose()
+ notify(msg);
+ refresh()
+ }
- parseCsv(file);
};
const handleClose = () => {
@@ -58,6 +78,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>
@@ -144,22 +180,30 @@
<Alert
severity="info"
action={
- <Button
- component={Link}
- label="common.action.import.download"
- color="info"
- to={importTemp}
- download={'import_template.csv'}
- />
+ <MatnrList.Context.Consumer>
+ {context => (
+ <Button
+ component={Link}
+ onClick={() => {
+ downloadTemplate(context)
+ }}
+ label="common.action.import.download"
+ color="info"
+ to={importTemp}
+ download={'import_template.csv'}
+ />
+ )}
+
+ </MatnrList.Context.Consumer>
}
>
{translate('common.action.import.msg')}
</Alert>
<FileInput
- source="csv"
- label="CSV File"
- accept={{ 'text/csv': ['.csv'] }}
+ source="xlsx"
+ label="Xlsx File"
+ accept={{ 'text/xlsx': ['.xls', '.xlsx'] }}
onChange={handleFileChange}
>
<FileField source="src" title="title" />
@@ -178,6 +222,7 @@
<Toolbar
sx={{
width: '100%',
+ justifyContent: 'end'
}}
>
{importer.state === 'idle' ? (
@@ -185,6 +230,8 @@
<Button
label="common.action.import.title"
variant="contained"
+ startIcon={<ImportExportOutlinedIcon />}
+ size='medium'
onClick={startImport}
disabled={!file}
/>
@@ -201,6 +248,8 @@
</Dialog>
);
}
+{/**涓嬭浇鎵撳嵃妯℃澘锛屼紶鍏ype绫诲瀷锛岃皟鐢ㄤ笅杞芥ā鏉挎帴鍙� */ }
+
function millisecondsToTime(ms) {
var seconds = Math.floor((ms / 1000) % 60);
--
Gitblit v1.9.1