From 3d454f8beb57b4ad58b0dcc69fc2bc2a82c7d581 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Tue, 3 May 2022 20:33:13 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=8B=AC=EC=82=AC=EC=9E=90=20=EC=8B=AC?= =?UTF-8?q?=EC=9D=98=20=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/judge.js | 67 +++++-- src/utils/axios.js | 3 +- .../biz/admin/judge/JudgeRegistReview.jsx | 12 +- src/views/biz/judge/JudgeByUserReview.jsx | 79 +------- src/views/biz/judge/ProcessJudge.jsx | 176 +++++++----------- 5 files changed, 139 insertions(+), 198 deletions(-) diff --git a/src/apis/judge.js b/src/apis/judge.js index d33ab9d..93b5910 100644 --- a/src/apis/judge.js +++ b/src/apis/judge.js @@ -19,6 +19,7 @@ import { } from 'commons/ApiUrl'; import { setRowId } from './common'; import FileSaver from 'file-saver'; +import _ from 'lodash'; // eslint-disable-next-line no-return-await export async function findJudgeDatas(params) { @@ -131,28 +132,15 @@ export async function judgeFileDownload(params, alert) { }) // eslint-disable-next-line consistent-return .then((res) => { - if (res?.isAxiosError || res?.status === 404) { + if (res?.isAxiosError || res?.status === 404 || res?.size <= 0) { alert.show('파일을 다운로드 할 수 없습니다 [파일정보 오류]'); } else { - if (res?.size <= 0) { - alert.show('File not found!'); - return false; - } - // const onChangeFile = (e) => { - // const file = e.target.files[0]; - // if (file.type.includes('image')) { - // alert.show(~~~); - // } - // handleChangeFile(file); - // }; - - // FileSaver.saveAs(res, 'filename'); - // eslint-disable-next-line no-lonely-if if (res?.type.includes('image')) { // const url = window.URL.createObjectURL(res); alert.show(~~~); + // URL.revokeObjectURL() } else { FileSaver.saveAs(res, 'filename'); } @@ -171,3 +159,52 @@ export async function findByUserJudges(params) { } return res; } + +// eslint-disable-next-line consistent-return +async function judgeImgDownload(params, alert) { + // const res = await + // eslint-disable-next-line no-return-await + return await axios.get(GET_JUDGE_FILE_DOWNLOAD, { + responseType: 'blob', + params + }); +} + +async function judgeImgList(res, scCode, fieldCnt, fieldName, dataGb, methodName, alert) { + const arrRtn = []; + // eslint-disable-next-line no-restricted-syntax + for (const idx of _.range(1, fieldCnt, 1)) { + if (res?.data[`${fieldName}${idx}`]) { + // eslint-disable-next-line no-await-in-loop + await judgeImgDownload({ scDatagb: dataGb, scCode, methodName: `${methodName}${idx}` }, alert).then((r) => { + console.log(r); + if (r.size > 0) arrRtn.push(URL.createObjectURL(r)); + }); // .then((r) => { + } + } + console.log(arrRtn); + return arrRtn; +} + +export async function findImages(row, alert) { + const dataGb = row?.msDatagb; + const scCode = row?.msMaincode; + + const res = await findJudge(scCode); + console.log(res); + if (res.success) { + const [picadImgs, frecadImgs, contadImgs] = await Promise.all([ + judgeImgList(res, scCode, 5, 'scPicad', dataGb, 'getScPicad', alert), + judgeImgList(res, scCode, 5, 'scFrecad', dataGb, 'getScFrecad', alert), + judgeImgList(res, scCode, 9, 'scContad', dataGb, 'getScContad', alert) + ]); + + console.log(picadImgs, frecadImgs, contadImgs); + return { + arrPicadImg: picadImgs, + arrFrecadImg: frecadImgs, + arrContadImg: contadImgs + }; + } + return res; +} diff --git a/src/utils/axios.js b/src/utils/axios.js index fa3408e..171e868 100755 --- a/src/utils/axios.js +++ b/src/utils/axios.js @@ -113,7 +113,8 @@ axiosServices.interceptors.response.use( axiosService.interceptors.response.use( (response) => { Swal.close(); - if (!response.data.success) { + // multipart (blob) 요청인 경우 response.data?.success === 'undefined' + if (typeof response.data?.success !== 'undefined' && !response.data?.success) { Swal.fire({ icon: 'error', title: 'Api Error', diff --git a/src/views/biz/admin/judge/JudgeRegistReview.jsx b/src/views/biz/admin/judge/JudgeRegistReview.jsx index 778f9b0..89e5085 100644 --- a/src/views/biz/admin/judge/JudgeRegistReview.jsx +++ b/src/views/biz/admin/judge/JudgeRegistReview.jsx @@ -20,8 +20,10 @@ import NumberFormat from 'react-number-format'; import ExcelDownload from 'views/cmm/file-ctl/ExcelDownload'; import { findJudgeTargets, saveJudgeTargets } from 'apis/judge'; import PropTypes from 'prop-types'; +import { useAlert } from 'react-alert'; const JudgeRegistReview = ({ scDatagb, menuName }) => { + const showAlert = useAlert(); const [scTransfer, setScTransfer] = useState('1'); const [scSeq1, setScSeq1] = useState(2022000001); const [scSeq2, setScSeq2] = useState(2022000899); @@ -94,9 +96,13 @@ const JudgeRegistReview = ({ scDatagb, menuName }) => { setOpen(false); console.log(param); - saveJudgeTargets(param).then(() => { - setSelectionModel([]); - search(); + saveJudgeTargets(param).then((res) => { + if (res?.success) { + setSelectionModel([]); + search(); + } else { + showAlert.show(`${res?.data.message}`); + } }); }; diff --git a/src/views/biz/judge/JudgeByUserReview.jsx b/src/views/biz/judge/JudgeByUserReview.jsx index f410085..8d41348 100644 --- a/src/views/biz/judge/JudgeByUserReview.jsx +++ b/src/views/biz/judge/JudgeByUserReview.jsx @@ -1,80 +1,25 @@ -import { useCallback, useEffect, useRef, useState } from 'react'; +import { useCallback, useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import _ from 'lodash'; -import getYear from 'date-fns/getYear'; // material-ui import { GridActionsCellItem } from '@mui/x-data-grid'; -import { Divider, FormControl, Grid, InputAdornment, Link, MenuItem, OutlinedInput, Select, Typography } from '@mui/material'; +import { Divider, Grid, Typography } from '@mui/material'; import CreditScoreIcon from '@mui/icons-material/CreditScore'; -import { IconSearch } from '@tabler/icons'; // berry ui import MainCard from 'ui-component/cards/MainCard'; // project imports import MuiDataGrid from 'views/cmm/mui-grid/MuiDataGrid'; -import InputLabel from 'ui-component/extended/Form/InputLabel'; import { findByUserJudges } from 'apis/judge'; import CmmModal from 'views/cmm/CmmModal'; import ProcessJudge from './ProcessJudge'; import useAuth from 'hooks/useAuth'; -import { Delete } from '@mui/icons-material'; import Button from '@mui/material/Button'; import { useAlert } from 'react-alert'; -const itemData = [ - { - img: 'https://images.unsplash.com/photo-1551963831-b3b1ca40c98e', - title: 'Breakfast' - }, - { - img: 'https://images.unsplash.com/photo-1551782450-a2132b4ba21d', - title: 'Burger' - }, - { - img: 'https://images.unsplash.com/photo-1522770179533-24471fcdba45', - title: 'Camera' - }, - { - img: 'https://images.unsplash.com/photo-1444418776041-9c7e33cc5a9c', - title: 'Coffee' - }, - { - img: 'https://images.unsplash.com/photo-1533827432537-70133748f5c8', - title: 'Hats' - }, - { - img: 'https://images.unsplash.com/photo-1558642452-9d2a7deb7f62', - title: 'Honey' - }, - { - img: 'https://images.unsplash.com/photo-1516802273409-68526ee1bdd6', - title: 'Basketball' - }, - { - img: 'https://images.unsplash.com/photo-1518756131217-31eb79b20e8f', - title: 'Fern' - }, - { - img: 'https://images.unsplash.com/photo-1597645587822-e99fa5d45d25', - title: 'Mushrooms' - }, - { - img: 'https://images.unsplash.com/photo-1567306301408-9b74779a11af', - title: 'Tomato basil' - }, - { - img: 'https://images.unsplash.com/photo-1471357674240-e1a485acb3e1', - title: 'Sea star' - }, - { - img: 'https://images.unsplash.com/photo-1589118949245-7d38baf380d6', - title: 'Bike' - } -]; - const JudgeByUserReview = ({ msDatagb, menuName }) => { const { user } = useAuth(); const showAlert = useAlert(); @@ -111,24 +56,14 @@ const JudgeByUserReview = ({ msDatagb, menuName }) => { }); }, [msDatagb]); - const processJudge = useCallback( - (row) => () => { - setTitle(`${menuName} 심의 - ${row.msSeq}`); - setRowDatas([row]); - setOpen(true); - }, - [] - ); + const processJudge = (row) => () => { + setTitle(`${menuName} 심의 - ${row.msSeq}`); + setRowDatas([row]); + setOpen(true); + }; const columns = [ // { headerName: 'rowId', field: 'rowId' }, - { - headerName: 'msMaincode', - headerAlign: 'center', - field: 'msMaincode', - align: 'center', - width: 100 - }, { headerName: '접수번호', headerAlign: 'center', diff --git a/src/views/biz/judge/ProcessJudge.jsx b/src/views/biz/judge/ProcessJudge.jsx index a8940cb..4609e0b 100644 --- a/src/views/biz/judge/ProcessJudge.jsx +++ b/src/views/biz/judge/ProcessJudge.jsx @@ -1,124 +1,86 @@ import React, { useEffect, useState } from 'react'; -import { CardMedia, ImageList, ImageListItem } from '@mui/material'; -import { useDropzone } from 'react-dropzone'; -import { Image } from '@mui/icons-material'; -import Box from '@mui/material/Box'; -import PropTypes from 'prop-types'; -import { judgeFileDownload } from '../../../apis/judge'; +import { CardMedia, Grid } from '@mui/material'; +import { findImages } from '../../../apis/judge'; import _ from 'lodash'; -const itemData = [ - { - img: 'https://images.unsplash.com/photo-1551963831-b3b1ca40c98e', - title: 'Breakfast' - }, - { - img: 'https://images.unsplash.com/photo-1551782450-a2132b4ba21d', - title: 'Burger' - }, - { - img: 'https://images.unsplash.com/photo-1522770179533-24471fcdba45', - title: 'Camera' - }, - { - img: 'https://images.unsplash.com/photo-1444418776041-9c7e33cc5a9c', - title: 'Coffee' - }, - { - img: 'https://images.unsplash.com/photo-1533827432537-70133748f5c8', - title: 'Hats' - }, - { - img: 'https://images.unsplash.com/photo-1558642452-9d2a7deb7f62', - title: 'Honey' - }, - { - img: 'https://images.unsplash.com/photo-1516802273409-68526ee1bdd6', - title: 'Basketball' - }, - { - img: 'https://images.unsplash.com/photo-1518756131217-31eb79b20e8f', - title: 'Fern' - }, - { - img: 'https://images.unsplash.com/photo-1597645587822-e99fa5d45d25', - title: 'Mushrooms' - }, - { - img: 'https://images.unsplash.com/photo-1567306301408-9b74779a11af', - title: 'Tomato basil' - }, - { - img: 'https://images.unsplash.com/photo-1471357674240-e1a485acb3e1', - title: 'Sea star' - }, - { - img: 'https://images.unsplash.com/photo-1589118949245-7d38baf380d6', - title: 'Bike' - } -]; +const ProcessJudge = (props) => { + const { rowDatas, showAlert } = props; + const [picadImgs, setPicadImgs] = useState([]); + const [frecadImgs, setFrecadImgs] = useState([]); + const [contadImgs, setContadImgs] = useState([]); -const ProcessJudge = ({ rowDatas, showAlert }) => { - const [previewImage, setPreviewImage] = useState(); - - const { getRootProps, getInputProps } = useDropzone({ - accept: 'image/*', - onDrop: (acceptedFiles) => { - setPreviewImage(URL.createObjectURL(itemData[0].img)); - } - }); - - const viewImg = (scDatagb, scCode, methodName) => { - judgeFileDownload( - { - scDatagb, - scCode, - methodName - }, - showAlert - ); + const getImgList = (row) => { + findImages(row, showAlert).then((res) => { + const { arrPicadImg, arrFrecadImg, arrContadImg } = res; + console.log(res); + // console.log(arrPicadImg, arrFrecadImg, arrContadImg); + setPicadImgs(arrPicadImg); + setFrecadImgs(arrFrecadImg); + setContadImgs(arrContadImg); + }); }; - // rowDatas[0]?[`scFrecad`]; - // rowDatas[0]?[`scContad`]; - // 1. 데이타 조회 - msMaincode로 gnRecallSc - // 2. 이미지 조회 - judgeFileDownload : data['scPicad1'] 가 있는 경우 useEffect(() => { - rowDatas?.forEach((r) => _.range(1, 5, 1).forEach((idx) => viewImg(r.scDatagb, r.msMaincode, `scPicad${idx}`))); + getImgList(rowDatas[0]); }, []); return ( <> - - - + + {picadImgs?.map((img, idx) => ( + + + + ))} + + + {frecadImgs?.map((img, idx) => ( + + + + ))} + + + {contadImgs?.map((img, idx) => ( + + + + ))} + ); }; -ProcessJudge.propTypes = { - rowDatas: PropTypes.array.isRequired, - showAlert: PropTypes.object -}; +// ProcessJudge.propTypes = { +// rowDatas: PropTypes.object.isRequired, +// showAlert: PropTypes.object +// }; export default ProcessJudge;