diff --git a/src/module/enhancesite.jsx b/src/module/enhancesite.jsx new file mode 100644 index 00000000..99f5c8bc --- /dev/null +++ b/src/module/enhancesite.jsx @@ -0,0 +1,107 @@ +console.log( "===== simpread option enhancesite load =====" ) + +import TextField from 'textfield'; +import Button from 'button'; +import Dropdown from 'dropdown'; + +let notify, secret, cur_user = {}, ori_user = {}; + +function loadingState( state, str ) { + if ( state == "init" ) { + notify = new Notify().Render({ content: "数据处理中,请稍等...", state: "loading" }); + } else if ( state == "success" ) { + notify && notify.complete(); + notify = undefined; + new Notify().Render( str + "成功。" ); + } else { + notify && notify.complete(); + notify = undefined; + new Notify().Render( 2, str ); + } +} + +/** + * Get serivce url + * + * @param {string} method name + */ +function getService( method ) { + return ( location.hostname == "simpread.ksria.cn" ? "http://localhost:3000" : "http://simpread.ksria.cn" ) + method; +} + +/** + * Service Fail + * + * @param {object} xhr + * @param {string} textStatus + * @param {object} error + */ +function fail( xhr, textStatus, error ) { + console.error( xhr, status, error ) + loadingState( "fail" ); +} + +export default class Import extends React.Component { + + state = { + login: false, + } + + onSecretChange( event ) { + secret = event.target.value; + } + + login() { + loadingState( "init" ); + $.ajax({ + url : getService( "/users/service/get/" + this.props.uid ), + type : "POST", + data : {secret} + }).done( ( result, textStatus, jqXHR ) => { + if ( result.code == 200 ) { + loadingState( "success", "登录" ); + this.setState({ login: true }); + cur_user = result.data; + ori_user = $.extend( true, {}, cur_user ); + console.log( "current user is ", cur_user ) + } else if ( result.code == 401 ) { + loadingState( "faile", "管理员登陆失败,请验证管理员密匙!" ); + } else loadingState( "faile", "获取后台服务失败,请稍后再试!" ); + }).fail( fail ); + } + + import() { + $.isEmptyObject( cur_user ) && new Notify().Render({ mode: "snackbar", content: "需要先登录到服务器后才能提交!", action: "登录", cancel: "取消", callback: type => { + type == "action" && this.login(); + }}); + } + + render() { + return ( +