设置cookie为24小时的限制,超过后重新弹出弹框

This commit is contained in:
caishi 2021-10-15 10:27:16 +08:00
parent 3ca38e76a1
commit 0903edfd2c
2 changed files with 18 additions and 26 deletions

View File

@ -3,31 +3,33 @@ import { Modal , Button } from 'antd';
import './Index.scss';
import '../../css/index.scss';
import RenderHtml from '../../../components/render-html';
import axios from 'axios';
import cookie from 'react-cookies';
function SystemNotice({system_notification,history,login,showNotice,hideSystemNotice}){
function SystemNotice({system_notification,history}){
const [ visible , setVisible ] = useState(false);
useEffect(()=>{
if(system_notification && !system_notification.is_read && showNotice){
if(system_notification && !cookie.load('notice_stage')){
setVisible(true);
}
},[system_notification])
function sureContinue() {
if(login && ( system_notification && system_notification.id )){
const url = `/users/${login}/system_notification_histories.json`;
axios.post(url,{
system_notification_id:system_notification.id
}).then(result=>{
if(result && result.status === 0){
setVisible(false);
hideSystemNotice();
}
}).catch(error=>{})
}
// if(login && ( system_notification && system_notification.id )){
// const url = `/users/${login}/system_notification_histories.json`;
// axios.post(url,{
// system_notification_id:system_notification.id
// }).then(result=>{
// if(result && result.status === 0){
// setVisible(false);
// hideSystemNotice();
// }
// }).catch(error=>{})
// }
let inFifteenMinutes = new Date(new Date().getTime() + 24 * 3600 * 1000);//
cookie.save('notice_stage', true,{ expires: inFifteenMinutes });
console.log("cookies:",cookie.load('notice_stage')) ;
setVisible(false);
hideSystemNotice();
}
return (

View File

@ -29,7 +29,6 @@ export function TPMIndexHOC(WrappedComponent) {
email:undefined,
completeProfile:false,
showCP:false,
showNotice:true
}
}
@ -216,15 +215,8 @@ export function TPMIndexHOC(WrappedComponent) {
})
}
hideSystemNotice=()=>{
this.setState({
showNotice:false
})
}
render() {
let { isRender , current_user , giteaVisible , email , completeProfile , showCP , showNotice , mygetHelmetapi } = this.state;
let { isRender , current_user , giteaVisible , email , completeProfile , showCP , mygetHelmetapi } = this.state;
const common = {
showLoginDialog: this.showLoginDialog,
checkIfLogin: this.checkIfLogin,
@ -234,11 +226,9 @@ export function TPMIndexHOC(WrappedComponent) {
return (
<div className="indexHOC">
<SystemNotice
showNotice={showNotice}
system_notification={mygetHelmetapi && mygetHelmetapi.system_notification}
history={this.props.history}
login={current_user && current_user.login}
hideSystemNotice={this.hideSystemNotice}
/>
<EducoderAccount visible={giteaVisible} email={email} onOk={this.onOk}/>
<ProfileModal