1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-09 02:42:47 +00:00

improve account module

This commit is contained in:
shanshuirenjia
2019-07-01 12:38:58 +08:00
parent a279f47cad
commit cb9eb5d78d
4 changed files with 29 additions and 34 deletions

View File

@@ -2,8 +2,8 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import { Utils } from '../../utils/utils';
import editorUtilities from '../../utils/editor-utilties';
import { siteRoot, gettext } from '../../utils/constants';
import { seafileAPI } from '../../utils/seafile-api';
import { siteRoot, gettext, appAvatarURL } from '../../utils/constants';
const propTypes = {
isAdminPanel: PropTypes.bool,
@@ -21,12 +21,8 @@ class Account extends Component {
isStaff: false,
isOrgStaff: false,
usageRate: '',
avatarURL: '',
};
}
componentDidMount(){
this.getAccountInfo();
this.isFirstMounted = true;
}
componentDidUpdate(prevProps) {
@@ -71,13 +67,8 @@ class Account extends Component {
}
onClickAccount = () => {
this.setState({
showInfo: !this.state.showInfo,
});
}
getAccountInfo = () => {
editorUtilities.getAccountInfo().then(resp => {
if (this.isFirstMounted) {
seafileAPI.getAccountInfo().then(resp => {
this.setState({
userName: resp.data.name,
contactEmail: resp.data.email,
@@ -86,9 +77,13 @@ class Account extends Component {
quotaTotal: Utils.bytesToSize(resp.data.total),
isStaff: resp.data.is_staff,
isOrgStaff: resp.data.is_org_staff === 1 ? true : false,
avatarURL: resp.data.avatar_url
showInfo: !this.state.showInfo,
});
});
this.isFirstMounted = false;
} else {
this.setState({showInfo: !this.state.showInfo});
}
}
renderMenu = () => {
@@ -118,21 +113,14 @@ class Account extends Component {
}
renderAvatar = () => {
if (this.state.avatarURL) {
return (
<img src={this.state.avatarURL} width="36" height="36" className="avatar" alt={gettext('Avatar')} />
);
}
return (
<img src="" width="36" height="36" className="avatar" alt={gettext('Avatar')} />
);
return (<img src={appAvatarURL} width="36" height="36" className="avatar" alt={gettext('Avatar')} />);
}
render() {
return (
<div id="account">
<a id="my-info" onClick={this.onClickAccount} className="account-toggle no-deco d-none d-md-block" aria-label="View profile and more">
<span><img src={this.state.avatarURL} width="36" height="36" className="avatar" alt={gettext('Avatar')} /></span>
<span>{this.renderAvatar()}</span>
<span className="fas fa-caret-down vam"></span>
</a>
<span className="account-toggle sf2-icon-more mobile-icon d-md-none" aria-label="View profile and more" onClick={this.onClickAccount}></span>

View File

@@ -16,6 +16,7 @@ export const lang = window.app.config.lang;
export const fileServerRoot = window.app.config.fileServerRoot;
export const seafileVersion = window.app.config.seafileVersion;
export const serviceURL = window.app.config.serviceURL;
export const appAvatarURL = window.app.config.avatarURL;
//pageOptions
export const seafileCollabServer = window.app.pageOptions.seafileCollabServer;

View File

@@ -24,6 +24,7 @@ from seahub.settings import SEAFILE_VERSION, SITE_TITLE, SITE_NAME, \
from seahub.constants import DEFAULT_ADMIN
from seahub.utils import get_site_name, get_service_url
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
try:
from seahub.settings import SEACLOUD_MODE
@@ -87,6 +88,9 @@ def base(request):
if os.path.exists(custom_favicon_file):
favicon_path = CUSTOM_FAVICON_PATH
username = request.user.username
avatar_url, is_default, date_uploaded = api_avatar_url(username, 72)
result = {
'seafile_version': SEAFILE_VERSION,
'site_title': config.SITE_TITLE,
@@ -130,6 +134,7 @@ def base(request):
'service_url': get_service_url().rstrip('/'),
'enable_file_scan': ENABLE_FILE_SCAN,
'enable_work_weixin_departments': ENABLE_WORK_WEIXIN_DEPARTMENTS,
'avatar_url': request.build_absolute_uri(avatar_url),
}
if request.user.is_staff:

View File

@@ -43,6 +43,7 @@
fileServerRoot: '{{ FILE_SERVER_ROOT }}',
serviceURL: '{{ service_url }}',
seafileVersion: '{{ seafile_version }}',
avatarURL: '{{ avatar_url }}'
},
pageOptions: {
csrfToken: "{{ csrf_token }}",