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';
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();

@ -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';
// 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 (
<MainCard>
<Grid container alignItems="right">
<Grid item>
<Button variant="contained" size="small" onClick={handleCreate}>
공지사항등록
</Button>
</Grid>
</Grid>
<Grid item xs={12}>
<Divider />
</Grid>
@ -122,8 +142,8 @@ const PublicBoard = () => {
setRowsState={setRowsState}
handleCellClick={handleOnCellClick}
/>
<CmmModal isBackdrop title="공지사항등록" open={open} setOpen={setOpen}>
<PublicBoardForm setOpen={setOpen} handleModalSave={submitPublicBoard} {...selectedRow} />
<CmmModal isBackdrop title={title} open={open} setOpen={setOpen}>
<PublicBoardForm create={create} setOpen={setOpen} handleModalSave={submitPublicBoard} {...selectedRow} />
</CmmModal>
</MainCard>
);

@ -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) => {
<>
<Grid container spacing={2}>
<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 item xs={12} sm={6}>
{/* <TextField required label="업무구분" value={inDept} fullWidth /> */}
<Select
disabled
disabled={!create}
label="업무구분"
required
id="inDept"
name="inDept"
defaultValue={dept}
defaultValue={dept ?? setDept('주정차위반')}
onChange={(e) => setDept(e.target.value)}
fullWidth
>
@ -218,12 +219,24 @@ const PublicBoardForm = (props) => {
/>
</Grid>
</Grid>
<Grid item xs={12} sx={{ marginTop: 3, justifyContent: 'right' }}>
<Button size="small" onClick={onList}>
목록
</Button>
<Button onClick={onSave}>저장</Button>
<Button onClick={onDelete}>삭제</Button>
<Grid item xs={12} spacing={1} sx={{ display: 'flex' }}>
<Grid item xs={2}>
<Button variant="contained" size="small" startIcon={<List />} onClick={onList}>
목록
</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>
</>
);

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

Loading…
Cancel
Save