diff --git a/src/App.js b/src/App.js index 69ac7a8..934e96f 100644 --- a/src/App.js +++ b/src/App.js @@ -9,6 +9,16 @@ import {load_config,bgimg_style} from './Config'; import ImasuguApp from './imasugu/src/App'; function DeprecatedAlert(props) { + if(document.domain==='hole.xmcp.ml') + return ( +
+
+

请使用新域名访问P大树洞!

+

pkuhelper.pku.edu.cn/hole

+

当前域名将停止支持

+
+
+ ); return null; } diff --git a/src/Message.js b/src/Message.js new file mode 100644 index 0000000..2ea98f8 --- /dev/null +++ b/src/Message.js @@ -0,0 +1,65 @@ +import React, {Component, PureComponent} from 'react'; +import {PKUHELPER_ROOT,get_json} from './flows_api'; +import {Time} from './Common'; + +export class MessageViewer extends PureComponent { + constructor(props) { + super(props); + this.state={ + loading_status: 'idle', + msg: [], + }; + } + + componentDidMount() { + this.load(); + } + + load() { + if(this.state.loading_status==='loading') return; + this.setState({ + loading_status: 'loading', + },()=>{ + fetch(PKUHELPER_ROOT+'api_xmcp/hole/system_msg?user_token='+encodeURIComponent(this.props.token)) + .then(get_json) + .then((json)=>{ + if(json.error) + throw new Error(json.error); + else + this.setState({ + loading_status: 'done', + msg: json.result, + }); + }) + .catch((err)=>{ + console.error(err); + alert(''+err); + this.setState({ + loading_status: 'failed', + }); + }) + + }); + } + + render() { + if(this.state.loading_status==='loading') + return (

加载中……

); + else if(this.state.loading_status==='failed') + return (
{this.load()}}>重新加载
); + else if(this.state.loading_status==='done') + return this.state.msg.map((msg)=>( +
+
+
+
+
{msg.content}
+
+
+ )); + else + return null; + } +} \ No newline at end of file diff --git a/src/Title.js b/src/Title.js index ff5d3da..3723167 100644 --- a/src/Title.js +++ b/src/Title.js @@ -116,7 +116,7 @@ class ControlBar extends PureComponent { 'P大树洞 网页版',
- +
{this.props.show_sidebar( '设置', diff --git a/src/UserAction.js b/src/UserAction.js index af15737..5d5efe4 100644 --- a/src/UserAction.js +++ b/src/UserAction.js @@ -1,12 +1,13 @@ import React, {Component, PureComponent} from 'react'; import copy from 'copy-to-clipboard'; import {SafeTextarea} from './Common'; -import {API_VERSION_PARAM,PKUHELPER_ROOT,API} from './flows_api' +import {API_VERSION_PARAM,PKUHELPER_ROOT,API,get_json} from './flows_api' import md5 from 'md5'; import './UserAction.css'; import {API_BASE} from './Common'; +import {MessageViewer} from './Message'; const LOGIN_BASE=PKUHELPER_ROOT+'services/login'; const MAX_IMG_PX=2500; const MAX_IMG_FILESIZE=300000; @@ -68,15 +69,16 @@ export class LoginForm extends Component { }, body: data, }) - .then((res)=>res.json()) + .then(get_json) .then((json)=>{ if(json.code!==0) { if(json.msg) alert(json.msg); throw new Error(JSON.stringify(json)); } + let freshman_welcome=json.uid.indexOf('19')===0 && (+new Date())<1567958400000; // 2019-09-09 0:00 GMT+8 set_token(json.user_token); - alert(`成功以 ${json.name} 的身份登录`); + alert(`成功以 ${json.name} 的身份登录`+(freshman_welcome ? '\n欢迎来到北京大学!' : '')); this.setState({ loading_status: 'done', }); @@ -131,6 +133,13 @@ export class LoginForm extends Component { 您已登录。

+

+ {this.props.show_sidebar( + '系统消息', + + )}}>查看系统消息
+ 当您发送的内容违规时,我们将用系统消息提示您 +

复制 User Token
User Token 可用于迁移登录状态,请勿泄露,因为它与您的账户唯一对应且泄露后无法重置 @@ -222,7 +231,7 @@ export class ReplyForm extends Component { }, body: data, }) - .then((res)=>res.json()) + .then(get_json) .then((json)=>{ if(json.code!==0) { if(json.msg) alert(json.msg); @@ -248,7 +257,7 @@ export class ReplyForm extends Component { render() { return (

- + {this.state.loading_status==='loading' ?