From 6f4ebd0ea03e83726202efd044f104c39d31ba88 Mon Sep 17 00:00:00 2001 From: minuk926 Date: Wed, 30 Mar 2022 22:04:28 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B3=B5=EC=A7=80=EC=82=AC=ED=95=AD?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20-=20=EC=A1=B0=ED=9A=8C=EC=88=98=20count=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/OpstBizService.js | 73 ++++++++++++------------- src/apis/common.js | 37 +++++++++++++ src/apis/public.js | 44 +++++++++++++++ src/views/biz/board/PublicBoard.jsx | 40 ++++++++++---- src/views/biz/board/PublicBoardForm.jsx | 43 ++++++++++----- src/views/form/Modal/CmmModal.jsx | 6 +- 6 files changed, 177 insertions(+), 66 deletions(-) create mode 100644 src/apis/common.js create mode 100644 src/apis/public.js diff --git a/src/apis/OpstBizService.js b/src/apis/OpstBizService.js index 35399ec..bc2cded 100644 --- a/src/apis/OpstBizService.js +++ b/src/apis/OpstBizService.js @@ -16,8 +16,11 @@ import axios from 'utils/axios'; import FileSaver from 'file-saver'; class OpstBizService { + //---------------------------------------------------------------------------- + // Common : 공통 + //---------------------------------------------------------------------------- // eslint-disable-next-line no-return-await - getComboCodeList = async (params) => await axios.get(GET_CMM_CODE_LIST, { params }); + getComboCodeList = (params) => async () => await axios.get(GET_CMM_CODE_LIST, { params }); // TODO: 헤더에서 파일 정보 읽을 수 있도록 변경 필요 fileDownload = async (id, filename, alert) => { @@ -42,6 +45,9 @@ class OpstBizService { return idx + 1; }; + //---------------------------------------------------------------------------- + // PublicBoard : 공지사항 관리 + //---------------------------------------------------------------------------- // eslint-disable-next-line no-return-await getPublicBoardList = async (params) => { const res = await axios.get(GET_PUBLIC_BOARD_LIST, { params }); @@ -52,15 +58,23 @@ class OpstBizService { return res; }; - getPublicBoard = async (inCode) => { - const res = await axios.get(GET_PUBLIC_BOARD + inCode); - if (res.success) { - // res.data = res.data.map((d, idx) => ({ ...d, rowId: this.setRowId(params, idx) })); - return res; - } - return res; + savePublicBoard = async (formData) => { + const config = { + method: 'post', + data: formData, + headers: { 'Content-Type': 'multipart/form-data' } // , Authorization: localStorage.getItem('access_token') } + }; + // eslint-disable-next-line no-return-await + return await axios(SAVE_PUBLIC_BOARD, config); }; + // eslint-disable-next-line no-return-await + deletePublicBoard = (inCode) => async () => await axios.post(DELETE_PUBLIC_BOARD + inCode); + + // getPublicBoard = async (inCode) => { + // await axios.get(GET_PUBLIC_BOARD + inCode); + // }; + modifyPublicBoardHitCount = async (inCode) => { const res = await axios.put(SAVE_PUBLIC_BOARD_HIT_CNT + inCode); if (res.success) { @@ -69,16 +83,9 @@ class OpstBizService { return res; }; - // eslint-disable-next-line no-return-await - getBoardList = async (params) => { - const res = await axios.get(GET_BOARD_LIST, { params }); - if (res.success) { - res.data = res.data.map((d, idx) => ({ ...d, rowId: this.setRowId(params, idx) })); - return res; - } - return res; - }; - + //---------------------------------------------------------------------------- + // Parking : 주정차 의견 진술 + //---------------------------------------------------------------------------- // eslint-disable-next-line no-return-await getSimsa680GroupList = async (params) => { const res = await axios.get(GET_PARKING_SIMSA_LIST, { params }); @@ -116,26 +123,16 @@ class OpstBizService { return res; }; - // getComboCodeList(params) { - // return reqApi.get(CMM_CODE_LIST_URL, { params }); - // .then(r => console.log(r)) - // .catch(e => { - // console.log(e) - // }); - // } - - savePublicBoard = async (formData) => { - const config = { - method: 'post', - data: formData, - headers: { 'Content-Type': 'multipart/form-data' } // , Authorization: localStorage.getItem('access_token') } - }; - // eslint-disable-next-line no-return-await - return await axios(SAVE_PUBLIC_BOARD, config); + //---------------------------------------------------------------------------- + // Board : 게시판 관리 + //---------------------------------------------------------------------------- + getBoardList = async (params) => { + const res = await axios.get(GET_BOARD_LIST, { params }); + if (res.success) { + res.data = res.data.map((d, idx) => ({ ...d, rowId: this.setRowId(params, idx) })); + return res; + } + return res; }; - - deletePublicBoard = async (inCode) => - // eslint-disable-next-line no-return-await - await axios.post(DELETE_PUBLIC_BOARD + inCode); } export default new OpstBizService(); diff --git a/src/apis/common.js b/src/apis/common.js new file mode 100644 index 0000000..7664c88 --- /dev/null +++ b/src/apis/common.js @@ -0,0 +1,37 @@ +import axios from '../utils/axios'; +import FileSaver from 'file-saver'; +import { GET_CMM_CODE_LIST, GET_FILE_DOWNLOAD } from '../commons/ApiUrl'; + +//---------------------------------------------------------------------------- +// Common : 공통 +//---------------------------------------------------------------------------- + +export function getComboCodeList(params) { + // eslint-disable-next-line no-return-await + return async () => await axios.get(GET_CMM_CODE_LIST, { params }); +} + +// TODO: 헤더에서 파일 정보 읽을 수 있도록 변경 필요 +export function fileDownload(id, filename, alert) { + return async () => { + await axios + .get(GET_FILE_DOWNLOAD + id, { + responseType: 'blob' // 'arrayBuffer', + // withCredentials: process.env.NODE_ENV === 'development' + // headers: { Authorization: window.localStorage.getItem(ACCESS_TOKEN_NAME) } + }) + // eslint-disable-next-line consistent-return + .then((res) => { + if (res.isAxiosError) { + alert.show('파일을 다운로드 할 수 없습니다[파일정보 오류]'); + return false; + } + FileSaver.saveAs(res, filename); + }); + }; +} + +export function setRowId(params, idx) { + if (params && params.page && params.size) return params.page * params.size + idx + 1; + return idx + 1; +} diff --git a/src/apis/public.js b/src/apis/public.js new file mode 100644 index 0000000..b73bc94 --- /dev/null +++ b/src/apis/public.js @@ -0,0 +1,44 @@ +//---------------------------------------------------------------------------- +// PublicBoard : 공지사항 관리 +//---------------------------------------------------------------------------- + +import axios from '../utils/axios'; +import { DELETE_PUBLIC_BOARD, GET_PUBLIC_BOARD_LIST, SAVE_PUBLIC_BOARD, SAVE_PUBLIC_BOARD_HIT_CNT } from '../commons/ApiUrl'; +import { setRowId } from './common'; + +export async function getPublicBoardList(params) { + // return async () => { + const res = await axios.get(GET_PUBLIC_BOARD_LIST, { params }); + if (res.success) { + res.data = res.data.map((d, idx) => ({ ...d, rowId: setRowId(params, idx) })); + return res; + } + return res; + // }; +} + +export async function savePublicBoard(formData) { + // eslint-disable-next-line no-return-await + return await axios(SAVE_PUBLIC_BOARD, { + method: 'post', + data: formData, + headers: { 'Content-Type': 'multipart/form-data' } // , Authorization: localStorage.getItem('access_token') } + }); +} + +export async function deletePublicBoard(inCode) { + // eslint-disable-next-line no-return-await + return await axios.post(DELETE_PUBLIC_BOARD + inCode); +} + +// getPublicBoard = async (inCode) => { +// await axios.get(GET_PUBLIC_BOARD + inCode); +// }; + +export async function modifyPublicBoardHitCount(inCode) { + const res = await axios.put(SAVE_PUBLIC_BOARD_HIT_CNT + inCode); + if (res.success) { + return res; + } + return res; +} diff --git a/src/views/biz/board/PublicBoard.jsx b/src/views/biz/board/PublicBoard.jsx index 8de6e4f..7e1fc46 100644 --- a/src/views/biz/board/PublicBoard.jsx +++ b/src/views/biz/board/PublicBoard.jsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react'; // material-ui -import { Divider, Grid, Link } from '@mui/material'; +import { Button, Divider, Grid, Link } from '@mui/material'; // assets import { IconFile, IconFileCheck, IconFileText } from '@tabler/icons'; @@ -16,6 +16,8 @@ import * as React from 'react'; import CmmModal from '../../form/Modal/CmmModal'; import * as PropTypes from 'prop-types'; import PublicBoardForm from './PublicBoardForm'; +import PersonAddTwoToneIcon from '@mui/icons-material/PersonAddTwoTone'; +import { deletePublicBoard, getPublicBoardList, modifyPublicBoardHitCount, savePublicBoard } from '../../../apis/public'; const PublicBoard = () => { const [totalCount, setTotalCount] = useState(0); @@ -27,6 +29,8 @@ const PublicBoard = () => { }); const [open, setOpen] = useState(false); const [selectedRow, setSelectedRow] = useState({}); + const [create, setCreate] = useState(false); + const [title, setTitle] = useState(); const columns = [ { headerName: 'No.', headerAlign: 'center', field: 'rowId', align: 'center', width: 70 }, @@ -67,7 +71,7 @@ const PublicBoard = () => { size: rowsState.pageSize }; - opstBizService.getPublicBoardList(params).then((response) => { + getPublicBoardList(params).then((response) => { // console.log(response); if (response && response.data) { setTotalCount(response.count); @@ -82,8 +86,10 @@ const PublicBoard = () => { const handleOnCellClick = (e) => { if (e?.field === 'inTitle') { + setCreate(false); + setTitle('공지사한 변경'); setSelectedRow(e?.row); - opstBizService.modifyPublicBoardHitCount(e?.row?.inCode); + modifyPublicBoardHitCount(e?.row?.inCode); setOpen(true); } }; @@ -91,23 +97,37 @@ const PublicBoard = () => { const submitPublicBoard = (type, payload) => { switch (type) { case 'SAVE': - opstBizService.savePublicBoard(payload); + savePublicBoard(payload); // .then((res) => { search(); setOpen(false); + // }); break; case 'DELETE': - opstBizService.deletePublicBoard(payload); - search(); + deletePublicBoard(payload); // .then((res) => { + // search(); setOpen(false); + // }); break; default: - search(); - setOpen(false); } }; + const handleCreate = (e) => { + setSelectedRow({}); + setTitle('공지사항 등록'); + setCreate(true); + setOpen(true); + }; + return ( + + + + + @@ -122,8 +142,8 @@ const PublicBoard = () => { setRowsState={setRowsState} handleCellClick={handleOnCellClick} /> - - + + ); diff --git a/src/views/biz/board/PublicBoardForm.jsx b/src/views/biz/board/PublicBoardForm.jsx index 228697c..22d9d97 100644 --- a/src/views/biz/board/PublicBoardForm.jsx +++ b/src/views/biz/board/PublicBoardForm.jsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useRef, useState } from 'react'; +import { useMemo, useRef, useState } from 'react'; import { useAlert } from 'react-alert'; // material-ui @@ -16,17 +16,18 @@ import opstBizService from '../../../apis/OpstBizService'; import * as React from 'react'; import axios from 'axios'; -import { FileDownload, FileUpload } from '@mui/icons-material'; +import { Delete, FileDownload, FileUpload, List, Save } from '@mui/icons-material'; import FileSaver from 'file-saver'; import xitCmm from '../../../commons/XitCmm'; import SearchSection from '../../../layout/MainLayout/Header/SearchSection'; const PublicBoardForm = (props) => { // eslint-disable-next-line react/prop-types - const { inCode, inDept, inTitle, inHit, inName, inNalja, inFilename, inContents, setOpen, handleModalSave } = props; + const { create, inCode, inDept, inTitle, inHit, inName, inNalja, inFilename, inContents, setOpen, handleModalSave } = props; const alert = useAlert(); const quillRef = useRef(); const [dept, setDept] = useState(inDept); + const [subject, setSubject] = useState(inTitle); const [contents, setContents] = useState(inContents); const [filesInfo, setFilesInfo] = useState(null); const [selectedFile, setSelectedFile] = useState(inFilename); // 파일 @@ -37,11 +38,11 @@ const PublicBoardForm = (props) => { }; const onSave = (e) => { const formData = new FormData(); - formData.append('inCode', inCode); - formData.append('inTitle', inTitle); + formData.append('inCode', inCode ?? ''); + formData.append('inTitle', subject); formData.append('inDept', dept); formData.append('inContents', contents); - formData.append('inFilename', selectedFile); + formData.append('inFilename', selectedFile ?? ''); if (filesInfo !== null && filesInfo.length > 0) { // eslint-disable-next-line no-plusplus @@ -132,17 +133,17 @@ const PublicBoardForm = (props) => { <> - + setSubject(e.target.value)} fullWidth /> {/* */}