forgeplus-react/src/forge/SoftwareFactory/index.jsx

211 lines
6.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React ,{ useEffect , useState } from "react";
import { SnackbarHOC } from "educoder";
import { CNotificationHOC } from "../../modules/courses/common/CNotificationHOC";
import { TPMIndexHOC } from "../../modules/tpm/TPMIndexHOC";
import { withRouter } from "react-router";
import { ImageLayerOfCommentHOC } from "../../modules/page/layers/ImageLayerOfCommentHOC";
import Home from './components/Home/index'
import ProjectStatus from './components/ProjectStatus/index'
import { getNewsAllList, getMainInfos } from '../Information/api';
import next from "./img/next.png";
import Slider from "react-slick";
import './index.scss';
import { getLunar } from "./utils";
import { todayWorkSituation, weekMonthWorkSituation,projectSituation } from "./api";
const setting = {
dots: false,
infinite: true,
speed: 2000,
slidesToShow: 1,
slidesToScroll: 1,
pauseOnDotsHover: true,
autoplaySpeed: Number(localStorage.getItem('pageLoopSpeed')) || 30000,
// pauseOnFocus: false,
autoplay: true,
arrows: false,
pauseOnHover:false,
dotsClass:'fac-dots'
// prevArrow: <img className="slick-prev slick-arrow" src={next} alt="" />,
// nextArrow: <img className="slick-next slick-arrow" src={next} alt="" />,
// afterChange: (index) => setTag(index),
};
function Index(props){
const [id,setId] = useState(undefined)
const [newsList,setNewsList] = useState([])
const homeDom = React.useRef(null)
const proDom = React.useRef(null)
const [timeObj, setTimeObj] = useState({});
const [dayMap, setDayMap] = useState({});
const [weekMap, setWeekMap] = useState({});
const [monthMap, setMonthMap] = useState({});
const [weatherObj, setWetherObj] = useState({});
const [currentMonth, setCurrentMonth] = useState("");
const [projectList, setProjectList] = useState([]);
useEffect(()=>{
getId()
getDay()
getTodayData();
getWeekData();
getMonthData();
getWether();
getProjectList();
const timer = setInterval(() => {
//默认5分钟更新一次
getTodayData();
getWeekData();
getMonthData();
getDay();
getWether();
getProjectList();
}, Number(localStorage.getItem('apiTime')) || 300000);
return () => {
clearInterval(timer);
};
},[])
useEffect(()=>{
let timer = null
if(id){
getNewsList()
timer = setInterval(()=>{
getNewsList()
},Number(localStorage.getItem('apiTime')) || 300000)
return () =>{
clearInterval(timer)
}
}
},[id])
function getNewsList() {
getNewsAllList(id).then(result => {
if (result) {
let rows = result.data.rows;
setNewsList(rows);
}
}).catch(error => { })
}
function getId(){
getMainInfos('xjykyzx').then(result=>{
console.log('result', result)
if(result){
let data = result.data.data;
if(data && data.id){
setId(data.id);
}
}
}).catch(console.error())
}
function getWether() {
// fxLink 当前数据的响应式页面,便于嵌入网站或应用
// now.obsTime 数据观测时间
// now.temp 温度,默认单位:摄氏度
// now.feelsLike 体感温度,默认单位:摄氏度
// now.icon 天气状况的图标代码,另请参考天气图标项目
// now.text 天气状况的文字描述,包括阴晴雨雪等天气状态的描述
// now.wind360 风向360角度
// now.windDir 风向
// now.windScale 风力等级
// now.windSpeed 风速,公里/小时
// now.humidity 相对湿度,百分比数值
// now.precip 过去1小时降水量默认单位毫米
// now.pressure 大气压强,默认单位:百帕
// now.vis 能见度,默认单位:公里
// now.cloud 云量,百分比数值。可能为空
// now.dew 露点温度。可能为空
fetch(
`https://devapi.qweather.com/v7/weather/now?location=112.87,28.22&key=18a193299e4944a7bf3ccf23b38474c2`
)
.then((response) => response.json())
.then((data) => {
setWetherObj({
text: data.now.text,
temp: data.now.temp,
windDir: data.now.windDir,
humidity: data.now.humidity,
});
})
.catch((err) => {});
}
function getTodayData() {
todayWorkSituation().then((res) => {
if (res.data.code === 200) {
setDayMap(res.data.data);
}
});
}
function getWeekData() {
weekMonthWorkSituation("week").then((res) => {
if (res.data.code === 200) {
setWeekMap(res.data.data);
}
});
}
function getMonthData() {
weekMonthWorkSituation("month").then((res) => {
if (res.data.code === 200) {
setMonthMap(res.data.data);
}
});
}
function getProjectList() {
projectSituation().then((res) => {
if (res.data.code === 200) {
let list =
res.data.data.length > 10
? res.data.data.slice(0, 10)
: res.data.data;
setProjectList(list);
}
});
}
function getDay() {
//获取日期数据
const days = [
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六",
];
let time = new Date();
let year = time.getFullYear();
let month = time.getMonth() + 1;
let day = time.getDate();
let obj = {
month: month < 10 ? "0" + month : month.toString(),
day: day < 10 ? "0" + day : day.toString(),
week: days[time.getDay()],
lunar: getLunar(time),
};
setCurrentMonth(`${year}${month}`);
setTimeObj(obj);
}
return (<div className="softFc-wrap">
<Slider {...setting} >
<Home newsList={newsList} timeObj={timeObj} dayMap={dayMap} weekMap={weekMap} monthMap={monthMap} weatherObj={weatherObj} currentMonth={currentMonth} key="home" ref={homeDom}/>
<ProjectStatus key="project" ref={proDom} projectList={projectList}/>
</Slider>
</div>)
}
export default withRouter((CNotificationHOC()(SnackbarHOC()(TPMIndexHOC(ImageLayerOfCommentHOC({
imgSelector: ".imageLayerParent img, .imageLayerParent .imageTarget",
parentSelector: ".newContainer",
})(Index)))))
);