Unverified Commit 99484619 authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

[Optimization][web] Optimization person page (#2059)

* 优化个人中心页面
parent 445f81b1
...@@ -239,37 +239,9 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen ...@@ -239,37 +239,9 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
} }
private UserDTO refreshUserInfo(User user) { private UserDTO refreshUserInfo(User user) {
List<Role> roleList = new LinkedList<>(); UserDTO reBuildUserInfo = buildUserInfo(user.getId());
List<Tenant> tenantList = new LinkedList<>(); UserInfoContextHolder.set(user.getId(), reBuildUserInfo);
return reBuildUserInfo;
List<UserRole> userRoles = userRoleService.getUserRoleByUserId(user.getId());
List<UserTenant> userTenants = userTenantService.getUserTenantByUserId(user.getId());
userRoles.stream()
.forEach(
userRole -> {
Role role =
roleService.getBaseMapper().selectById(userRole.getRoleId());
if (Asserts.isNotNull(role)) {
roleList.add(role);
}
});
userTenants.stream()
.forEach(
userTenant -> {
Tenant tenant = tenantService.getById(userTenant.getTenantId());
if (Asserts.isNotNull(tenant)) {
tenantList.add(tenant);
}
});
UserDTO userInfo = new UserDTO();
userInfo.setUser(user);
userInfo.setRoleList(roleList);
userInfo.setTenantList(tenantList);
UserInfoContextHolder.set(user.getId(), userInfo);
return userInfo;
} }
@Override @Override
...@@ -353,13 +325,12 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen ...@@ -353,13 +325,12 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
@Override @Override
public Result<UserDTO> queryCurrentUserInfo() { public Result<UserDTO> queryCurrentUserInfo() {
UserDTO userInfo = UserInfoContextHolder.get(StpUtil.getLoginIdAsInt()); UserDTO userInfo = UserInfoContextHolder.get(StpUtil.getLoginIdAsInt());
if (Asserts.isNotNull(userInfo)
&& Asserts.isNotNull(userInfo.getUser()) if (Asserts.isNotNull(userInfo)) {
&& Asserts.isNotNull(userInfo.getRoleList()) UserDTO userInfoDto = buildUserInfo(userInfo.getUser().getId());
&& Asserts.isNotNull(userInfo.getTenantList()) userInfoDto.setCurrentTenant(userInfo.getCurrentTenant());
&& Asserts.isNotNull(userInfo.getCurrentTenant())) { UserInfoContextHolder.refresh(StpUtil.getLoginIdAsInt(), userInfoDto);
StpUtil.getSession().set("user", userInfo); return Result.succeed(userInfoDto);
return Result.succeed(userInfo);
} else { } else {
return Result.failed(); return Result.failed();
} }
...@@ -413,4 +384,49 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen ...@@ -413,4 +384,49 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
} }
return userIds; return userIds;
} }
/**
* build user info
*
* @param userId
* @return
*/
private UserDTO buildUserInfo(Integer userId) {
User user = getById(userId);
if (Asserts.isNull(user)) {
return null;
}
List<Role> roleList = new LinkedList<>();
List<Tenant> tenantList = new LinkedList<>();
List<UserRole> userRoles = userRoleService.getUserRoleByUserId(user.getId());
List<UserTenant> userTenants = userTenantService.getUserTenantByUserId(user.getId());
userRoles.stream()
.forEach(
userRole -> {
Role role =
roleService.getBaseMapper().selectById(userRole.getRoleId());
if (Asserts.isNotNull(role)) {
roleList.add(role);
}
});
userTenants.stream()
.forEach(
userTenant -> {
Tenant tenant = tenantService.getById(userTenant.getTenantId());
if (Asserts.isNotNull(tenant)) {
tenantList.add(tenant);
}
});
UserDTO userInfo = new UserDTO();
userInfo.setUser(user);
userInfo.setRoleList(roleList);
userInfo.setTenantList(tenantList);
return userInfo;
}
} }
...@@ -23,7 +23,7 @@ import React from "react"; ...@@ -23,7 +23,7 @@ import React from "react";
const BaseInfo = (props: any) => { const BaseInfo = (props: any) => {
const {user, currentTenant} = props; const {user, tenant} = props;
return <> return <>
<Avatar style={{alignSelf: 'center', marginBottom: 50,}} draggable size={200} src={user.avatar} /> <Avatar style={{alignSelf: 'center', marginBottom: 50,}} draggable size={200} src={user.avatar} />
...@@ -34,7 +34,7 @@ const BaseInfo = (props: any) => { ...@@ -34,7 +34,7 @@ const BaseInfo = (props: any) => {
<Descriptions.Item label={l('user.phone')}>{user.mobile}</Descriptions.Item> <Descriptions.Item label={l('user.phone')}>{user.mobile}</Descriptions.Item>
<Descriptions.Item label={l('user.jobnumber')}>{user.worknum}</Descriptions.Item> <Descriptions.Item label={l('user.jobnumber')}>{user.worknum}</Descriptions.Item>
<Descriptions.Item label={l('user.current.tenant')}> <Descriptions.Item label={l('user.current.tenant')}>
<Tag color={'processing'}>{currentTenant?.tenantCode}</Tag> <Tag color={'processing'}>{tenant?.tenantCode}</Tag>
</Descriptions.Item> </Descriptions.Item>
</Descriptions> </Descriptions>
</> </>
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
* *
*/ */
import React, {useState} from "react"; import React, {useEffect, useState} from "react";
import {useModel} from "@@/exports"; import {useModel} from "@@/exports";
import {Divider, Empty, Form, Space, Tag} from "antd"; import {Descriptions, Divider, Empty, Form, Space, Tag} from "antd";
import {PageContainer, PageLoading, ProCard} from "@ant-design/pro-components"; import {PageContainer, PageLoading, ProCard} from "@ant-design/pro-components";
import {UserBaseInfo} from "@/types/User/data"; import {UserBaseInfo} from "@/types/User/data";
import {l} from "@/utils/intl"; import {l} from "@/utils/intl";
...@@ -30,6 +30,7 @@ import {handleOption} from "@/services/BusinessCrud"; ...@@ -30,6 +30,7 @@ import {handleOption} from "@/services/BusinessCrud";
import {API_CONSTANTS} from "@/services/constants"; import {API_CONSTANTS} from "@/services/constants";
import BaseInfo from "@/pages/Other/PersonCenter/BaseInfo"; import BaseInfo from "@/pages/Other/PersonCenter/BaseInfo";
import Pop from "@/components/Animation/Pop"; import Pop from "@/components/Animation/Pop";
import {flushSync} from "react-dom";
const PersonCenter = () => { const PersonCenter = () => {
...@@ -37,9 +38,26 @@ const PersonCenter = () => { ...@@ -37,9 +38,26 @@ const PersonCenter = () => {
const { initialState, setInitialState } = useModel('@@initialState'); const { initialState, setInitialState } = useModel('@@initialState');
const [activeKey, setActiveKey] = useState('operation'); const [activeKey, setActiveKey] = useState('operation');
const loading = <PageLoading/>; const loading = <PageLoading/>;
const fetchUserInfo = async () => {
const userInfo = await initialState?.fetchUserInfo?.();
if (userInfo) {
flushSync(() => {
setInitialState((s) => ({
...s,
currentUser: userInfo,
}));
});
}
};
useEffect(() => {
fetchUserInfo();
},[initialState?.currentUser]);
if (!initialState) { if (!initialState) {
return loading; return loading;
} }
...@@ -50,6 +68,7 @@ const PersonCenter = () => { ...@@ -50,6 +68,7 @@ const PersonCenter = () => {
const { roleList, tenantList,currentTenant,user } = currentUser; const { roleList, tenantList,currentTenant,user } = currentUser;
/** /**
* renderTenantTagList * renderTenantTagList
* @param {UserBaseInfo.Tenant[]} items * @param {UserBaseInfo.Tenant[]} items
...@@ -57,9 +76,9 @@ const PersonCenter = () => { ...@@ -57,9 +76,9 @@ const PersonCenter = () => {
*/ */
const renderTenantTagList = (items: UserBaseInfo.Tenant[]) => { const renderTenantTagList = (items: UserBaseInfo.Tenant[]) => {
return items?.map((item: UserBaseInfo.Tenant) => { return items?.map((item: UserBaseInfo.Tenant) => {
return <> return <Descriptions.Item key={item.id}>
<Tag color={'success'} key={item.id}>{item.tenantCode} </Tag> <Tag color={'success'} key={item.id}>{item.tenantCode}</Tag>
</> </Descriptions.Item>
}) })
}; };
...@@ -70,9 +89,9 @@ const PersonCenter = () => { ...@@ -70,9 +89,9 @@ const PersonCenter = () => {
*/ */
const renderRoleTagList = (items: UserBaseInfo.Role[]) => { const renderRoleTagList = (items: UserBaseInfo.Role[]) => {
return items?.map((item: UserBaseInfo.Role) => { return items?.map((item: UserBaseInfo.Role) => {
return <> return <Descriptions.Item key={item.id}>
<Tag color={'success'} key={item.id}>{item.roleCode}</Tag> <Tag color={'success'} key={item.id}>{item.roleCode}</Tag>
</> </Descriptions.Item>
}) })
}; };
...@@ -111,18 +130,18 @@ const PersonCenter = () => { ...@@ -111,18 +130,18 @@ const PersonCenter = () => {
return <Pop> return <Pop>
<PageContainer title={false}> <PageContainer title={false}>
<ProCard ghost gutter={[16, 16]} hoverable loading={!loading && currentUser}> <ProCard ghost gutter={[16, 16]} hoverable loading={!loading && currentUser}>
<ProCard style={{height: '91vh',textAlign:'center'}} colSpan="30%" hoverable bordered> <ProCard style={{height: '91vh', textAlign:'center', overflowY: 'auto',}} colSpan="30%" hoverable bordered>
<BaseInfo user={user} currentTenant={currentTenant} /> <BaseInfo user={user} tenant={currentTenant} />
<Divider orientation={'left'} plain >{l('user.tenant')}</Divider> <Divider orientation={'left'} plain >{l('user.tenant')}</Divider>
<Space>{renderTenantTagList(tenantList || [])}</Space> <Descriptions size={'small'} column={4}>{renderTenantTagList(tenantList || [])}</Descriptions>
<Divider plain ></Divider> <Divider plain ></Divider>
<Divider orientation={'left'} plain >{l('user.role')}</Divider> <Divider orientation={'left'} plain >{l('user.role')}</Divider>
<Space>{renderRoleTagList(roleList || [])}</Space> <Descriptions size={'small'} column={4}>{renderRoleTagList(roleList || [])}</Descriptions>
</ProCard> </ProCard>
<ProCard <ProCard
style={{height: '91vh',textAlign:'center'}} hoverable bordered
style={{height: '91vh',textAlign:'center',overflowY: 'auto',}}
tabs={{ tabs={{
activeKey: activeKey, activeKey: activeKey,
type: 'card', type: 'card',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment