add user space edit change

This commit is contained in:
seaheart
2023-07-08 14:59:37 +08:00
parent cd33a867fc
commit 1f120407d7
12 changed files with 100 additions and 55 deletions
+20
View File
@@ -1,5 +1,6 @@
import BaseEntity from '../base/BaseEntity';
import User from '../user/User';
import FileUtil from '../../util/FileUtil';
export interface SpaceFormValues {
name: string;
@@ -33,4 +34,23 @@ export default class Space extends BaseEntity {
uuid: this.uuid ? this.uuid : null,
};
}
getHumanizeTotalSize() {
return FileUtil.humanFileSize(this.totalSize);
}
getHumanizeSizeLimit() {
return FileUtil.humanFileSize(this.sizeLimit);
}
getHumanizeTotalSizeLimit() {
return FileUtil.humanFileSize(this.totalSizeLimit);
}
getUsedPercent() {
if (this.totalSizeLimit === 0) {
return 0;
}
return (this.totalSize / this.totalSizeLimit) * 100;
}
}
+38 -6
View File
@@ -8,6 +8,7 @@ import Filter from '../base/filter/Filter';
import SortFilter from '../base/filter/SortFilter';
import InputFilter from '../base/filter/InputFilter';
import SelectionFilter from '../base/filter/SelectionFilter';
import Space from '../space/Space';
export default class User extends BaseEntity {
//获取当前登录者的信息
@@ -28,12 +29,9 @@ export default class User extends BaseEntity {
avatarUrl: string | null = null;
lastIp: string | null = null;
lastTime: Date = new Date();
//默认大小限制100Mb.
sizeLimit: number = 104857600;
totalSize: number = 0;
totalSizeLimit: number = -1;
status: UserStatus = UserStatus.OK;
spaceUuid: string | null = null;
space: Space | null = null;
constructor(reactComponent?: React.Component) {
super(reactComponent);
@@ -43,6 +41,7 @@ export default class User extends BaseEntity {
super.assign(obj);
this.assignEntity('lastTime', Date);
this.assignEntity('space', Space);
}
getTAG(): string {
@@ -64,8 +63,6 @@ export default class User extends BaseEntity {
password: this.password,
role: this.role,
avatarUrl: this.avatarUrl,
sizeLimit: this.sizeLimit,
totalSizeLimit: this.totalSizeLimit,
uuid: this.uuid ? this.uuid : null,
};
}
@@ -161,6 +158,41 @@ export default class User extends BaseEntity {
}
}
httpSave(
limit: {
sizeLimit: number;
totalSizeLimit: number;
},
successCallback?: any,
errorCallback?: any,
finallyCallback?: any
) {
let that = this;
let url = this.getUrlCreate();
if (this.uuid) {
url = this.getUrlEdit();
}
this.errorMessage = this.validate();
if (this.errorMessage) {
that.defaultErrorHandler(this.errorMessage, errorCallback);
return;
}
this.httpPost(
url,
{ ...this.getForm(), ...limit },
function (response: any) {
that.assign(response.data.data);
SafeUtil.safeCallback(successCallback)(response);
},
errorCallback,
finallyCallback
);
}
//退出登录
httpLogout(successCallback?: any, errorCallback?: any, finalCallback?: any) {
let that = this;
-6
View File
@@ -5,7 +5,6 @@ import Lang from '../global/Lang';
enum UserRole {
GUEST = 'GUEST',
USER = 'USER',
SPACE = 'SPACE',
ADMINISTRATOR = 'ADMINISTRATOR',
}
@@ -22,11 +21,6 @@ let UserRoleMap: { [key in keyof typeof UserRole]: ColorSelectionOption } = {
value: 'USER',
color: Color.PRIMARY,
},
SPACE: {
name: Lang.t('user.roleUserRoleSpace'),
value: UserRole.SPACE,
color: Color.SUCCESS,
},
ADMINISTRATOR: {
name: Lang.t('user.roleAdministrator'),
value: 'ADMINISTRATOR',
+5 -5
View File
@@ -27,20 +27,20 @@ export default class Capacity extends TankComponent<IProps, IState> {
render() {
const { user } = this;
if (!user.space) return null;
return (
<div className="widget-capacity">
{user.totalSizeLimit !== -1 && (
{user.space!.totalSizeLimit !== -1 && (
<Progress
percent={(user.totalSize / user.totalSizeLimit) * 100}
percent={user.space.getUsedPercent()}
showInfo={false}
strokeColor="#215891"
trailColor="#ddd"
/>
)}
<div className="capacity-text">
{`${FileUtil.humanFileSize(
user.totalSize
)} / ${FileUtil.humanFileSize(user.totalSizeLimit)}`}
{`${user.space.getHumanizeTotalSize()} / ${user.space.getHumanizeTotalSizeLimit()}`}
</div>
</div>
);
+3 -3
View File
@@ -373,13 +373,13 @@ export default class List extends TankComponent<IProps, IState> {
m.spaceUuid = this.getSpaceUuid();
//判断文件大小。
if (this.user.sizeLimit >= 0) {
if (file.size > this.user.sizeLimit) {
if (this.user.space!.sizeLimit >= 0) {
if (file.size > this.user.space!.sizeLimit) {
MessageBoxUtil.error(
Lang.t(
'matter.sizeExceedLimit',
StringUtil.humanFileSize(file.size),
StringUtil.humanFileSize(this.user.sizeLimit)
this.user.space?.getHumanizeSizeLimit()
)
);
return;
+5 -2
View File
@@ -42,9 +42,12 @@ export default class MatterImage extends TankComponent<IProps, IState> {
if (file) {
let fileSize = (file as any).size;
if (this.user.sizeLimit >= 0 && fileSize > this.user.sizeLimit) {
if (
this.user.space!.sizeLimit >= 0 &&
fileSize > this.user.space!.sizeLimit
) {
MessageBoxUtil.error(
Lang.t('matter.sizeExceedLimit', fileSize, this.user.sizeLimit)
Lang.t('matter.sizeExceedLimit', fileSize, this.user.space!.sizeLimit)
);
return;
}
-2
View File
@@ -9,13 +9,11 @@ import { Button, Form, Input, InputNumber, Switch } from 'antd';
import { SaveOutlined } from '@ant-design/icons';
import TankContentCard from '../widget/TankContentCard';
import Preference from '../../common/model/preference/Preference';
import FileUtil from '../../common/util/FileUtil';
import { FormInstance } from 'antd/lib/form';
import MessageBoxUtil from '../../common/util/MessageBoxUtil';
import Sun from '../../common/model/global/Sun';
import Lang from '../../common/model/global/Lang';
import MatterImage from '../matter/widget/MatterImage';
import { UserRole } from '../../common/model/user/UserRole';
import InputSize from '../widget/form/InputSize';
interface IProps extends RouteComponentProps {}
+4 -6
View File
@@ -132,8 +132,6 @@ export default class List extends TankComponent<IProps, IState> {
<Row gutter={[10, 10]}>
{pager.data.map((space) => {
const percent = space.totalSize! / space.totalSizeLimit!;
return (
<Col xs={24} sm={24} md={12} lg={8} key={space.uuid}>
<Card
@@ -181,20 +179,20 @@ export default class List extends TankComponent<IProps, IState> {
<>
<div>
{Lang.t('space.sizeLimit')}
{FileUtil.humanFileSize(space.sizeLimit!)}
{space.getHumanizeSizeLimit()}
</div>
<div>
{Lang.t('space.totalSize')}
{FileUtil.humanFileSize(space.totalSize!)}
{space.getHumanizeTotalSize()}
</div>
<div>
{Lang.t('space.totalSizeLimit')}
{FileUtil.humanFileSize(space.totalSizeLimit!)}
{space.getHumanizeTotalSizeLimit()}
</div>
</>
}
>
<Progress percent={Math.round(percent * 100)} />
<Progress percent={Math.round(space.getUsedPercent())} />
</Tooltip>
</div>
</Card>
+3 -3
View File
@@ -213,15 +213,15 @@ export default class Detail extends TankComponent<IProps, IState> {
</InfoCell>
<InfoCell name={Lang.t('user.singleFileSizeLimit')}>
{FileUtil.humanFileSize(currentUser.sizeLimit)}
{currentUser.space?.getHumanizeSizeLimit()}
</InfoCell>
<InfoCell name={Lang.t('user.totalFileSizeLimit')}>
{FileUtil.humanFileSize(currentUser.totalSizeLimit)}
{currentUser.space?.getHumanizeTotalSizeLimit()}
</InfoCell>
<InfoCell name={Lang.t('user.totalFileSize')}>
{FileUtil.humanFileSize(currentUser.totalSize)}
{currentUser.space?.getHumanizeTotalSize()}
</InfoCell>
<InfoCell name={Lang.t('user.status')}>
+16 -13
View File
@@ -65,20 +65,24 @@ export default class Edit extends TankComponent<IProps, IState> {
currentUser.assign(values);
currentUser.httpSave(function () {
MessageBoxUtil.success(Lang.t('operationSuccess'));
currentUser.httpSave(
{
sizeLimit: values.sizeLimit,
totalSizeLimit: values.totalSizeLimit,
},
function () {
MessageBoxUtil.success(Lang.t('operationSuccess'));
//如果是自己的资料修改成功,更新一下本地。
if (user.uuid === currentUser.uuid) {
user.assign(currentUser);
//如果是自己的资料修改成功,更新一下本地。
if (user.uuid === currentUser.uuid) {
user.assign(currentUser);
}
Sun.navigateBack();
}
Sun.navigateBack();
});
);
}
onFinishFailed(errorInfo: any) {}
render() {
let that = this;
@@ -121,7 +125,6 @@ export default class Edit extends TankComponent<IProps, IState> {
name="basic"
ref={this.formRef}
onFinish={this.onFinish.bind(this)}
onFinishFailed={this.onFinishFailed.bind(this)}
onValuesChange={() => {
that.updateUI();
}}
@@ -208,7 +211,7 @@ export default class Edit extends TankComponent<IProps, IState> {
required
name="sizeLimit"
rules={[{ required: true, message: Lang.t('inputRequired') }]}
initialValue={currentUser.sizeLimit}
initialValue={currentUser.space?.sizeLimit}
>
<InputSize
className="w200"
@@ -221,7 +224,7 @@ export default class Edit extends TankComponent<IProps, IState> {
required
name="totalSizeLimit"
rules={[{ required: true, message: Lang.t('inputRequired') }]}
initialValue={currentUser.totalSizeLimit}
initialValue={currentUser.space?.totalSizeLimit}
>
<InputSize
className="w200"
+3 -6
View File
@@ -155,23 +155,20 @@ export default class List extends TankComponent<IProps, IState> {
},
{
title: Lang.t('user.singleFileSizeLimit'),
dataIndex: 'sizeLimit',
render: (text: any, record: User, index: number): React.ReactNode => (
<span>{FileUtil.humanFileSize(record.sizeLimit)}</span>
<span>{record.space?.getHumanizeSizeLimit()}</span>
),
},
{
title: Lang.t('user.totalFileSize'),
dataIndex: 'totalSize',
render: (text: any, record: User, index: number): React.ReactNode => (
<span>{FileUtil.humanFileSize(record.totalSize)}</span>
<span>{record.space?.getHumanizeTotalSize()}</span>
),
},
{
title: Lang.t('user.totalFileSizeLimit'),
dataIndex: 'totalSizeLimit',
render: (text: any, record: User, index: number): React.ReactNode => (
<span>{FileUtil.humanFileSize(record.totalSizeLimit)}</span>
<span>{record.space?.getHumanizeTotalSizeLimit()}</span>
),
},
{
+3 -3
View File
@@ -77,13 +77,13 @@ export default class MobileUserPanel extends TankComponent<IProps, IState> {
{this.showMore ? (
<div className="ml10 panel-detail">
<InfoCell name={Lang.t('user.singleFileSizeLimit')}>
<span>{FileUtil.humanFileSize(user.sizeLimit)}</span>
<span>{user.space?.getHumanizeSizeLimit()}</span>
</InfoCell>
<InfoCell name={Lang.t('user.totalFileSize')}>
<span>{FileUtil.humanFileSize(user.totalSize)}</span>
<span>{user.space?.getHumanizeTotalSize()}</span>
</InfoCell>
<InfoCell name={Lang.t('user.totalFileSizeLimit')}>
<span>{FileUtil.humanFileSize(user.totalSizeLimit)}</span>
<span>{user.space?.getHumanizeTotalSizeLimit()}</span>
</InfoCell>
<InfoCell name={Lang.t('user.status')}>
<Tag color={UserStatusMap[user.status].color}>