feat: 공지사항등록 - 조회수 count 반영

main
minuk926 3 years ago
parent 04cae8b120
commit 6f4ebd0ea0

@ -16,8 +16,11 @@ import axios from 'utils/axios';
import FileSaver from 'file-saver'; import FileSaver from 'file-saver';
class OpstBizService { class OpstBizService {
//----------------------------------------------------------------------------
// Common : 공통
//----------------------------------------------------------------------------
// eslint-disable-next-line no-return-await // 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: 헤더에서 파일 정보 읽을 수 있도록 변경 필요 // TODO: 헤더에서 파일 정보 읽을 수 있도록 변경 필요
fileDownload = async (id, filename, alert) => { fileDownload = async (id, filename, alert) => {
@ -42,6 +45,9 @@ class OpstBizService {
return idx + 1; return idx + 1;
}; };
//----------------------------------------------------------------------------
// PublicBoard : 공지사항 관리
//----------------------------------------------------------------------------
// eslint-disable-next-line no-return-await // eslint-disable-next-line no-return-await
getPublicBoardList = async (params) => { getPublicBoardList = async (params) => {
const res = await axios.get(GET_PUBLIC_BOARD_LIST, { params }); const res = await axios.get(GET_PUBLIC_BOARD_LIST, { params });
@ -52,15 +58,23 @@ class OpstBizService {
return res; return res;
}; };
getPublicBoard = async (inCode) => { savePublicBoard = async (formData) => {
const res = await axios.get(GET_PUBLIC_BOARD + inCode); const config = {
if (res.success) { method: 'post',
// res.data = res.data.map((d, idx) => ({ ...d, rowId: this.setRowId(params, idx) })); data: formData,
return res; headers: { 'Content-Type': 'multipart/form-data' } // , Authorization: localStorage.getItem('access_token') }
} };
return res; // 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) => { modifyPublicBoardHitCount = async (inCode) => {
const res = await axios.put(SAVE_PUBLIC_BOARD_HIT_CNT + inCode); const res = await axios.put(SAVE_PUBLIC_BOARD_HIT_CNT + inCode);
if (res.success) { if (res.success) {
@ -69,16 +83,9 @@ class OpstBizService {
return res; return res;
}; };
// eslint-disable-next-line no-return-await //----------------------------------------------------------------------------
getBoardList = async (params) => { // Parking : 주정차 의견 진술
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;
};
// eslint-disable-next-line no-return-await // eslint-disable-next-line no-return-await
getSimsa680GroupList = async (params) => { getSimsa680GroupList = async (params) => {
const res = await axios.get(GET_PARKING_SIMSA_LIST, { params }); const res = await axios.get(GET_PARKING_SIMSA_LIST, { params });
@ -116,26 +123,16 @@ class OpstBizService {
return res; return res;
}; };
// getComboCodeList(params) { //----------------------------------------------------------------------------
// return reqApi.get(CMM_CODE_LIST_URL, { params }); // Board : 게시판 관리
// .then(r => console.log(r)) //----------------------------------------------------------------------------
// .catch(e => { getBoardList = async (params) => {
// console.log(e) 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;
savePublicBoard = async (formData) => { }
const config = { return res;
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);
}; };
deletePublicBoard = async (inCode) =>
// eslint-disable-next-line no-return-await
await axios.post(DELETE_PUBLIC_BOARD + inCode);
} }
export default new OpstBizService(); export default new OpstBizService();

@ -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;
}

@ -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;
}

@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
// material-ui // material-ui
import { Divider, Grid, Link } from '@mui/material'; import { Button, Divider, Grid, Link } from '@mui/material';
// assets // assets
import { IconFile, IconFileCheck, IconFileText } from '@tabler/icons'; import { IconFile, IconFileCheck, IconFileText } from '@tabler/icons';
@ -16,6 +16,8 @@ import * as React from 'react';
import CmmModal from '../../form/Modal/CmmModal'; import CmmModal from '../../form/Modal/CmmModal';
import * as PropTypes from 'prop-types'; import * as PropTypes from 'prop-types';
import PublicBoardForm from './PublicBoardForm'; import PublicBoardForm from './PublicBoardForm';
import PersonAddTwoToneIcon from '@mui/icons-material/PersonAddTwoTone';
import { deletePublicBoard, getPublicBoardList, modifyPublicBoardHitCount, savePublicBoard } from '../../../apis/public';
const PublicBoard = () => { const PublicBoard = () => {
const [totalCount, setTotalCount] = useState(0); const [totalCount, setTotalCount] = useState(0);
@ -27,6 +29,8 @@ const PublicBoard = () => {
}); });
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [selectedRow, setSelectedRow] = useState({}); const [selectedRow, setSelectedRow] = useState({});
const [create, setCreate] = useState(false);
const [title, setTitle] = useState();
const columns = [ const columns = [
{ headerName: 'No.', headerAlign: 'center', field: 'rowId', align: 'center', width: 70 }, { headerName: 'No.', headerAlign: 'center', field: 'rowId', align: 'center', width: 70 },
@ -67,7 +71,7 @@ const PublicBoard = () => {
size: rowsState.pageSize size: rowsState.pageSize
}; };
opstBizService.getPublicBoardList(params).then((response) => { getPublicBoardList(params).then((response) => {
// console.log(response); // console.log(response);
if (response && response.data) { if (response && response.data) {
setTotalCount(response.count); setTotalCount(response.count);
@ -82,8 +86,10 @@ const PublicBoard = () => {
const handleOnCellClick = (e) => { const handleOnCellClick = (e) => {
if (e?.field === 'inTitle') { if (e?.field === 'inTitle') {
setCreate(false);
setTitle('공지사한 변경');
setSelectedRow(e?.row); setSelectedRow(e?.row);
opstBizService.modifyPublicBoardHitCount(e?.row?.inCode); modifyPublicBoardHitCount(e?.row?.inCode);
setOpen(true); setOpen(true);
} }
}; };
@ -91,23 +97,37 @@ const PublicBoard = () => {
const submitPublicBoard = (type, payload) => { const submitPublicBoard = (type, payload) => {
switch (type) { switch (type) {
case 'SAVE': case 'SAVE':
opstBizService.savePublicBoard(payload); savePublicBoard(payload); // .then((res) => {
search(); search();
setOpen(false); setOpen(false);
// });
break; break;
case 'DELETE': case 'DELETE':
opstBizService.deletePublicBoard(payload); deletePublicBoard(payload); // .then((res) => {
search(); // search();
setOpen(false); setOpen(false);
// });
break; break;
default: default:
search();
setOpen(false);
} }
}; };
const handleCreate = (e) => {
setSelectedRow({});
setTitle('공지사항 등록');
setCreate(true);
setOpen(true);
};
return ( return (
<MainCard> <MainCard>
<Grid container alignItems="right">
<Grid item>
<Button variant="contained" size="small" onClick={handleCreate}>
공지사항등록
</Button>
</Grid>
</Grid>
<Grid item xs={12}> <Grid item xs={12}>
<Divider /> <Divider />
</Grid> </Grid>
@ -122,8 +142,8 @@ const PublicBoard = () => {
setRowsState={setRowsState} setRowsState={setRowsState}
handleCellClick={handleOnCellClick} handleCellClick={handleOnCellClick}
/> />
<CmmModal isBackdrop title="공지사항등록" open={open} setOpen={setOpen}> <CmmModal isBackdrop title={title} open={open} setOpen={setOpen}>
<PublicBoardForm setOpen={setOpen} handleModalSave={submitPublicBoard} {...selectedRow} /> <PublicBoardForm create={create} setOpen={setOpen} handleModalSave={submitPublicBoard} {...selectedRow} />
</CmmModal> </CmmModal>
</MainCard> </MainCard>
); );

@ -1,4 +1,4 @@
import { useEffect, useMemo, useRef, useState } from 'react'; import { useMemo, useRef, useState } from 'react';
import { useAlert } from 'react-alert'; import { useAlert } from 'react-alert';
// material-ui // material-ui
@ -16,17 +16,18 @@ import opstBizService from '../../../apis/OpstBizService';
import * as React from 'react'; import * as React from 'react';
import axios from 'axios'; 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 FileSaver from 'file-saver';
import xitCmm from '../../../commons/XitCmm'; import xitCmm from '../../../commons/XitCmm';
import SearchSection from '../../../layout/MainLayout/Header/SearchSection'; import SearchSection from '../../../layout/MainLayout/Header/SearchSection';
const PublicBoardForm = (props) => { const PublicBoardForm = (props) => {
// eslint-disable-next-line react/prop-types // 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 alert = useAlert();
const quillRef = useRef(); const quillRef = useRef();
const [dept, setDept] = useState(inDept); const [dept, setDept] = useState(inDept);
const [subject, setSubject] = useState(inTitle);
const [contents, setContents] = useState(inContents); const [contents, setContents] = useState(inContents);
const [filesInfo, setFilesInfo] = useState(null); const [filesInfo, setFilesInfo] = useState(null);
const [selectedFile, setSelectedFile] = useState(inFilename); // const [selectedFile, setSelectedFile] = useState(inFilename); //
@ -37,11 +38,11 @@ const PublicBoardForm = (props) => {
}; };
const onSave = (e) => { const onSave = (e) => {
const formData = new FormData(); const formData = new FormData();
formData.append('inCode', inCode); formData.append('inCode', inCode ?? '');
formData.append('inTitle', inTitle); formData.append('inTitle', subject);
formData.append('inDept', dept); formData.append('inDept', dept);
formData.append('inContents', contents); formData.append('inContents', contents);
formData.append('inFilename', selectedFile); formData.append('inFilename', selectedFile ?? '');
if (filesInfo !== null && filesInfo.length > 0) { if (filesInfo !== null && filesInfo.length > 0) {
// eslint-disable-next-line no-plusplus // eslint-disable-next-line no-plusplus
@ -132,17 +133,17 @@ const PublicBoardForm = (props) => {
<> <>
<Grid container spacing={2}> <Grid container spacing={2}>
<Grid item xs={12} sm={4}> <Grid item xs={12} sm={4}>
<TextField required label="제목" value={inTitle} fullWidth /> <TextField required label="제목" value={subject} onChange={(e) => setSubject(e.target.value)} fullWidth />
</Grid> </Grid>
<Grid item xs={12} sm={6}> <Grid item xs={12} sm={6}>
{/* <TextField required label="업무구분" value={inDept} fullWidth /> */} {/* <TextField required label="업무구분" value={inDept} fullWidth /> */}
<Select <Select
disabled disabled={!create}
label="업무구분" label="업무구분"
required required
id="inDept" id="inDept"
name="inDept" name="inDept"
defaultValue={dept} defaultValue={dept ?? setDept('주정차위반')}
onChange={(e) => setDept(e.target.value)} onChange={(e) => setDept(e.target.value)}
fullWidth fullWidth
> >
@ -218,12 +219,24 @@ const PublicBoardForm = (props) => {
/> />
</Grid> </Grid>
</Grid> </Grid>
<Grid item xs={12} sx={{ marginTop: 3, justifyContent: 'right' }}> <Grid item xs={12} spacing={1} sx={{ display: 'flex' }}>
<Button size="small" onClick={onList}> <Grid item xs={2}>
목록 <Button variant="contained" size="small" startIcon={<List />} onClick={onList}>
</Button> 목록
<Button onClick={onSave}>저장</Button> </Button>
<Button onClick={onDelete}>삭제</Button> </Grid>
<Grid item xs={2}>
<Button variant="contained" size="small" startIcon={<Save />} onClick={onSave}>
저장
</Button>
</Grid>
{!create && (
<Grid item xs={2}>
<Button variant="contained" size="small" startIcon={<Delete />} onClick={onDelete}>
삭제
</Button>
</Grid>
)}
</Grid> </Grid>
</> </>
); );

@ -6,7 +6,7 @@ import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography'; import Typography from '@mui/material/Typography';
import Modal from '@mui/material/Modal'; import Modal from '@mui/material/Modal';
import { Divider, Grid, IconButton } from '@mui/material'; import { Divider, Grid, IconButton } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close'; import CloseOutlined from '@mui/icons-material/CloseOutlined';
import MainCard from 'ui-component/cards/MainCard'; import MainCard from 'ui-component/cards/MainCard';
import { styled } from '@mui/material/styles'; import { styled } from '@mui/material/styles';
import { useRef } from 'react'; import { useRef } from 'react';
@ -40,8 +40,8 @@ const CmmModal = ({ isBackdrop = false, open, setOpen, title, children, callback
title={title} title={title}
content={false} content={false}
secondary={ secondary={
<IconButton size="small" onClick={handleClose}> <IconButton size="small" variant="rounded" onClick={handleClose}>
<CloseIcon fontSize="small" /> <CloseOutlined fontSize="small" />
</IconButton> </IconButton>
} }
> >

Loading…
Cancel
Save