Ver código fonte

登录返回重定向到登录前的url

albertshaw 7 anos atrás
pai
commit
7119a10d98
1 arquivos alterados com 44 adições e 32 exclusões
  1. 44 32
      js/component/login/loginForm.jsx

+ 44 - 32
js/component/login/loginForm.jsx

@@ -1,5 +1,5 @@
 import React from 'react';
-import { Form, Icon, Input, Button, Checkbox, Spin,message } from 'antd';
+import { Form, Icon, Input, Button, Checkbox, Spin, message } from 'antd';
 import './login.less';
 import ajax from 'jquery/src/ajax/xhr.js'
 import $ from 'jquery/src/ajax';
@@ -29,11 +29,23 @@ const LoginForm = Form.create()(React.createClass({
                         "type": this.props.loginProp,
                         "remember": values.remember
                     }
-                }).done(function (data) {
-                    if (!data.error.length) {
-                        window.location.href = globalConfig.context + "/user/account/index.html";
+                }).done(function (res) {
+                    if (!res.error.length) {
+                        let data = res.data;
+                        if (data && data.requestURI) {
+                            let path = globalConfig.context + data.requestURI
+                            if (data.queryString) {
+                                path += '?' + data.queryString;
+                            }
+                            if (window.location.hash) {
+                                path += window.location.hash;
+                            }
+                            window.location.href = path;
+                        } else {
+                            window.location.href = globalConfig.context + "/user/account/index.html";
+                        }
                     } else {
-                        message.warning(data.error[0].message);
+                        message.warning(res.error[0].message);
                     }
                 }.bind(this)).always(function () {
                     this.props.spinState(false);
@@ -44,34 +56,34 @@ const LoginForm = Form.create()(React.createClass({
     render() {
         const { getFieldDecorator } = this.props.form;
         return (
-                <Form onSubmit={this.handleSubmit} className="login-form">
-                    <FormItem>
-                        {getFieldDecorator('phone', {
-                            rules: [{ required: true, message: '请输入手机号!' }],
-                        })(
-                            <Input addonBefore={<Icon type="user" />} placeholder="手机号" />
-                            )}
-                    </FormItem>
-                    <FormItem>
-                        {getFieldDecorator('password', {
-                            rules: [{ required: true, message: '请输入密码!' }],
-                        })(
-                            <Input addonBefore={<Icon type="lock" />} type="password" placeholder="密码" />
-                            )}
-                    </FormItem>
-                    <FormItem>
-                        {getFieldDecorator('remember', {
-                            valuePropName: 'checked',
-                            initialValue: false,
-                        })(
-                            <Checkbox>记住我</Checkbox>
-                            )}
-                        <ForgetPw theType={this.props.loginProp}/>
-                        <Button type="primary" htmlType="submit" className="login-form-button">
-                            登录
+            <Form onSubmit={this.handleSubmit} className="login-form">
+                <FormItem>
+                    {getFieldDecorator('phone', {
+                        rules: [{ required: true, message: '请输入手机号!' }],
+                    })(
+                        <Input addonBefore={<Icon type="user" />} placeholder="手机号" />
+                        )}
+                </FormItem>
+                <FormItem>
+                    {getFieldDecorator('password', {
+                        rules: [{ required: true, message: '请输入密码!' }],
+                    })(
+                        <Input addonBefore={<Icon type="lock" />} type="password" placeholder="密码" />
+                        )}
+                </FormItem>
+                <FormItem>
+                    {getFieldDecorator('remember', {
+                        valuePropName: 'checked',
+                        initialValue: false,
+                    })(
+                        <Checkbox>记住我</Checkbox>
+                        )}
+                    <ForgetPw theType={this.props.loginProp} />
+                    <Button type="primary" htmlType="submit" className="login-form-button">
+                        登录
                     </Button>
-                    </FormItem>
-                </Form>
+                </FormItem>
+            </Form>
         );
     },
 }));