25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

222 lines
8.4 KiB

  1. import { useState } from 'react';
  2. // material-ui
  3. import {
  4. Grid,
  5. Typography,
  6. Stack,
  7. Button,
  8. Box
  9. } from '@mui/material';
  10. import { isORGLoggedIn, } from "utils/Utils";
  11. import titleBackgroundImg from 'assets/images/dashboard/gazette-bar.png'
  12. import { FormattedMessage, useIntl } from "react-intl";
  13. import AdsClickRoundedIcon from '@mui/icons-material/AdsClickRounded';
  14. import * as React from "react";
  15. import Loadable from 'components/Loadable';
  16. import * as HttpUtils from "utils/HttpUtils";
  17. import * as UrlUtils from "utils/ApiPathConst";
  18. import * as DateUtils from "utils/DateUtils";
  19. const Message = Loadable(React.lazy(() => import('./Message')));
  20. const Notice = Loadable(React.lazy(() => import('./Notice')));
  21. // import { lazy } from 'react';
  22. const LoadingComponent = Loadable(React.lazy(() => import('../../extra-pages/LoadingComponent')));
  23. import { useNavigate } from "react-router-dom";
  24. // ==============================|| DASHBOARD - DEFAULT ||============================== //
  25. const DashboardDefault = () => {
  26. const navigate = useNavigate()
  27. const intl = useIntl();
  28. const userData = JSON.parse(localStorage.getItem("userData"));
  29. const BackgroundHead = {
  30. // backgroundColor: '#0d47a1',
  31. backgroundImage: `url(${titleBackgroundImg})`,
  32. width: '100%',
  33. height: '100%',
  34. backgroundSize: 'contain',
  35. backgroundRepeat: 'no-repeat',
  36. backgroundColor: '#0C489E',
  37. backgroundPosition: 'right'
  38. }
  39. const { locale } = intl;
  40. const [messageOnReady, setMessageOnReady] = useState(false);
  41. const [onNoticeReady, setNoticeOnReady] = useState(false);
  42. const [isLoading, setLoding] = useState(true);
  43. const [itemList, setItemList] = React.useState([]);
  44. const [listData, setListData] = React.useState([]);
  45. React.useEffect(() => {
  46. loadMessageData()
  47. loadNoticeData()
  48. localStorage.setItem('searchCriteria',"")
  49. }, []);
  50. const getWelcomeMsg=()=>{
  51. var current = new Date()
  52. var curHr = current.getHours()
  53. if (curHr < 12) {
  54. return <FormattedMessage id="welcomeMsg_am" />
  55. } else if (curHr < 18) {
  56. return <FormattedMessage id="welcomeMsg_pm" />
  57. } else {
  58. return <FormattedMessage id="welcomeMsg_night" />
  59. }
  60. }
  61. React.useEffect(() => {
  62. // console.log(messageOnReady)
  63. // console.log(onNoticeReady)
  64. if(messageOnReady&&onNoticeReady){
  65. setLoding(false)
  66. // console.log(123)
  67. }
  68. }, [messageOnReady,onNoticeReady]);
  69. const loadMessageData = () => {
  70. HttpUtils.get({
  71. url: UrlUtils.GET_MSG_DASHBOARD,
  72. onSuccess: function (response) {
  73. let list = []
  74. response.map((item) => {
  75. list.push(
  76. <Button onClick={()=>{navigate("/msg/details/"+item.id);}} color={item.readTime?"gray":"black"} style={{justifyContent: "flex-start"}} sx={{p:2}}>
  77. <Stack direction="column" >
  78. <Typography variant='string' align="justify"><b>{item.subject}</b></Typography>
  79. <Typography align="justify">{DateUtils.datetimeStr(item.sentDate)}</Typography>
  80. </Stack>
  81. </Button>
  82. )
  83. });
  84. setItemList(list);
  85. setMessageOnReady(true);
  86. // console.log('123')
  87. },
  88. onError: function (){
  89. // console.log('123')
  90. setMessageOnReady(true);
  91. }
  92. });
  93. // props.setMessageOnReady(true);
  94. };
  95. const loadNoticeData = () => {
  96. HttpUtils.get({
  97. url: UrlUtils.GET_ANNOUNCE_DASHBOARD,
  98. onSuccess: function (response) {
  99. setListData(response);
  100. setNoticeOnReady(true)
  101. },
  102. onError: function () {
  103. setNoticeOnReady(true)
  104. }
  105. });
  106. };
  107. return (
  108. isLoading ?
  109. <Grid container sx={{ minHeight: '87vh' }} direction="column">
  110. <Grid item xs={12} >
  111. <div style={BackgroundHead}>
  112. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  113. {/* <Typography variant="h5">我的公共啟事</Typography> */}
  114. <Typography color='#FFF' variant="h5" sx={{ ml: 10, display: { xs: 'none', sm: 'none', md: 'block' } }}>
  115. {isORGLoggedIn() ? userData.fullenName: (locale === 'en' ?userData.fullenName: userData.fullchName)}, {getWelcomeMsg()}
  116. </Typography>
  117. </Stack>
  118. </div>
  119. </Grid>
  120. <Grid item xs={12} md={12} sx={{ textAlign: "center" }}>
  121. <Grid container sx={{ minHeight: '75vh', mb: 3 }} direction="column" justifyContent="center" alignItems="center">
  122. <Grid item>
  123. <LoadingComponent />
  124. </Grid>
  125. </Grid>
  126. </Grid>
  127. </Grid>
  128. :
  129. <Grid container sx={{ minHeight: '87vh' }} direction="column">
  130. <Grid item xs={12} >
  131. <div style={BackgroundHead}>
  132. <Stack direction="row" height='70px' justifyContent="flex-start" alignItems="center">
  133. {/* <Typography variant="h5">我的公共啟事</Typography> */}
  134. <Typography color='#FFF' variant="h5" sx={{ ml: 10, display: { xs: 'none', sm: 'none', md: 'block' } }}>
  135. {isORGLoggedIn() ? userData.fullenName: (locale === 'en' ?userData.fullenName: userData.fullchName)}, {getWelcomeMsg()}
  136. </Typography>
  137. </Stack>
  138. </div>
  139. </Grid>
  140. <Grid item xs={12} md={12} sx={{ textAlign: "center" }}>
  141. <Grid container justifyContent="center" spacing={2} sx={{ pt: 2 }} alignitems="stretch" >
  142. <Grid item xs={12} lg={5} sx={{ pt: 2 }} style={{ height: '100%' }}>
  143. <Button
  144. xs={12} onClick={() => { navigate("/publicNotice/apply"); }}
  145. style={{ justifyContent: "flex-start" }}
  146. aria-label={intl.formatMessage({ id: 'submitApplication' })}
  147. sx={{ width: "100%", p: 4, border: '3px solid #e1edfc', borderRadius: '10px', backgroundColor: "#e1edfc" }}
  148. >
  149. <Stack direction="row" spacing={2}>
  150. <AdsClickRoundedIcon />
  151. <Stack direction="column" alignItems="start">
  152. <Typography variant="h4" >
  153. <FormattedMessage id="submitApplication" />
  154. </Typography>
  155. <Typography >
  156. <FormattedMessage id="applicationSubheading" />
  157. </Typography>
  158. </Stack>
  159. </Stack>
  160. </Button>
  161. <Stack direction="row" justifyContent="space-between" sx={{ pl: 2, pr: 2, pt: 2 }} >
  162. <Typography variant="h4">
  163. <FormattedMessage id="announcement" />
  164. </Typography>
  165. <Button
  166. color="gray"
  167. aria-label={intl.formatMessage({ id: 'viewAllAnnouncement' })}
  168. onClick={()=>{navigate("/announcement/search")}}
  169. ><u>
  170. <FormattedMessage id="viewAllAnnouncement" />
  171. </u></Button>
  172. </Stack>
  173. <Box xs={12} md={12} sx={{ p: 1, border: '3px solid #eee', borderRadius: '10px' }} >
  174. <Notice
  175. listData = {listData}
  176. />
  177. </Box>
  178. </Grid>
  179. <Grid item xs={12} lg={5} sx={{ pt: 2 }} style={{ height: '100%' }}>
  180. <Stack direction="row" justifyContent="space-between" sx={{ pl: 2, pr: 2, pt: 2 }} >
  181. <Typography variant="h4">
  182. <FormattedMessage id="systemMessage" />
  183. </Typography>
  184. <Button
  185. aria-label={intl.formatMessage({ id: 'viewAllSystemMessage' })}
  186. onClick={() => { navigate("/msg/search"); }}
  187. color="gray"
  188. ><u>
  189. <FormattedMessage id="viewAllSystemMessage" />
  190. </u></Button>
  191. </Stack>
  192. <Box xs={12} md={12} sx={{ p: 1, fontSize: 12, border: '3px solid #eee', borderRadius: '10px' }} >
  193. <Message
  194. itemList = {itemList}
  195. />
  196. </Box>
  197. </Grid>
  198. </Grid>
  199. </Grid>
  200. </Grid>
  201. );
  202. };
  203. export default DashboardDefault;