mirror of https://github.com/openspug/spug
				
				
				
			U 优化个人中心
							parent
							
								
									d539544fa6
								
							
						
					
					
						commit
						5610bf1fd1
					
				| 
						 | 
				
			
			@ -7,20 +7,20 @@ import React, { useState } from 'react';
 | 
			
		|||
import { Button, Form, Input, message } from 'antd';
 | 
			
		||||
import styles from './index.module.css';
 | 
			
		||||
import { http } from 'libs';
 | 
			
		||||
import store from './store';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export default function Basic(props) {
 | 
			
		||||
  const [nickname, setNickname] = useState(localStorage.getItem('nickname'));
 | 
			
		||||
  const [loading, setLoading] = useState(false);
 | 
			
		||||
 | 
			
		||||
  function handleSubmit() {
 | 
			
		||||
    store.loading = true;
 | 
			
		||||
    setLoading(true);
 | 
			
		||||
    http.patch('/api/account/self/', {nickname})
 | 
			
		||||
      .then(() => {
 | 
			
		||||
        message.success('设置成功,重新登录或刷新页面后生效');
 | 
			
		||||
        localStorage.setItem('nickname', nickname)
 | 
			
		||||
      })
 | 
			
		||||
      .finally(() => store.loading = false)
 | 
			
		||||
      .finally(() =>setLoading(false))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ export default function Basic(props) {
 | 
			
		|||
          <Input value={nickname} placeholder="请输入" onChange={e => setNickname(e.target.value)}/>
 | 
			
		||||
        </Form.Item>
 | 
			
		||||
        <Form.Item>
 | 
			
		||||
          <Button type="primary" loading={store.loading} onClick={handleSubmit}>保存设置</Button>
 | 
			
		||||
          <Button type="primary" loading={loading} onClick={handleSubmit}>保存设置</Button>
 | 
			
		||||
        </Form.Item>
 | 
			
		||||
      </Form>
 | 
			
		||||
    </React.Fragment>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,11 +7,11 @@ import React, { useState } from 'react';
 | 
			
		|||
import { Button, Form, Input, message } from 'antd';
 | 
			
		||||
import styles from './index.module.css';
 | 
			
		||||
import { http } from 'libs';
 | 
			
		||||
import store from './store';
 | 
			
		||||
import history from 'libs/history';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export default function Reset(props) {
 | 
			
		||||
  const [loading, setLoading] = useState(false);
 | 
			
		||||
  const [old_password, setOldPassword] = useState();
 | 
			
		||||
  const [new_password, setNewPassword] = useState();
 | 
			
		||||
  const [new2_password, setNew2Password] = useState();
 | 
			
		||||
| 
						 | 
				
			
			@ -24,14 +24,14 @@ export default function Reset(props) {
 | 
			
		|||
    } else if (new_password !== new2_password) {
 | 
			
		||||
      return message.error('两次输入密码不一致')
 | 
			
		||||
    }
 | 
			
		||||
    store.loading = true;
 | 
			
		||||
    setLoading(true);
 | 
			
		||||
    http.patch('/api/account/self/', {old_password, new_password})
 | 
			
		||||
      .then(() => {
 | 
			
		||||
        message.success('密码修改成功');
 | 
			
		||||
        history.push('/');
 | 
			
		||||
        http.get('/api/account/logout/')
 | 
			
		||||
      })
 | 
			
		||||
      .finally(() => store.loading = false)
 | 
			
		||||
      .finally(() => setLoading(false))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +48,7 @@ export default function Reset(props) {
 | 
			
		|||
          <Input.Password value={new2_password} placeholder="请输入" onChange={e => setNew2Password(e.target.value)}/>
 | 
			
		||||
        </Form.Item>
 | 
			
		||||
        <Form.Item>
 | 
			
		||||
          <Button type="primary" loading={store.loading} onClick={handleSubmit}>保存设置</Button>
 | 
			
		||||
          <Button type="primary" loading={loading} onClick={handleSubmit}>保存设置</Button>
 | 
			
		||||
        </Form.Item>
 | 
			
		||||
      </Form>
 | 
			
		||||
    </React.Fragment>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,12 +0,0 @@
 | 
			
		|||
/**
 | 
			
		||||
 * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug
 | 
			
		||||
 * Copyright (c) <spug.dev@gmail.com>
 | 
			
		||||
 * Released under the AGPL-3.0 License.
 | 
			
		||||
 */
 | 
			
		||||
import { observable } from "mobx";
 | 
			
		||||
 | 
			
		||||
class Store {
 | 
			
		||||
  @observable loading = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default new Store()
 | 
			
		||||
		Loading…
	
		Reference in New Issue