fix: limit the shown text's length (close #80)

This commit is contained in:
JustSong 2023-05-16 21:33:59 +08:00
parent 519cb030f7
commit e8da98139f
3 changed files with 30 additions and 8 deletions

View File

@ -467,6 +467,13 @@ func CreateUser(c *gin.Context) {
}) })
return return
} }
if err := common.Validate.Struct(&user); err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "输入不合法 " + err.Error(),
})
return
}
if user.DisplayName == "" { if user.DisplayName == "" {
user.DisplayName = user.Username user.DisplayName = user.Username
} }

View File

@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
import { API, showError, showSuccess } from '../helpers'; import { API, showError, showSuccess } from '../helpers';
import { ITEMS_PER_PAGE } from '../constants'; import { ITEMS_PER_PAGE } from '../constants';
import { renderText } from '../helpers/render';
function renderRole(role) { function renderRole(role) {
switch (role) { switch (role) {
@ -64,7 +65,7 @@ const UsersTable = () => {
(async () => { (async () => {
const res = await API.post('/api/user/manage', { const res = await API.post('/api/user/manage', {
username, username,
action, action
}); });
const { success, message } = res.data; const { success, message } = res.data;
if (success) { if (success) {
@ -161,18 +162,18 @@ const UsersTable = () => {
<Table.HeaderCell <Table.HeaderCell
style={{ cursor: 'pointer' }} style={{ cursor: 'pointer' }}
onClick={() => { onClick={() => {
sortUser('username'); sortUser('id');
}} }}
> >
用户名 ID
</Table.HeaderCell> </Table.HeaderCell>
<Table.HeaderCell <Table.HeaderCell
style={{ cursor: 'pointer' }} style={{ cursor: 'pointer' }}
onClick={() => { onClick={() => {
sortUser('display_name'); sortUser('username');
}} }}
> >
显示名称 用户名
</Table.HeaderCell> </Table.HeaderCell>
<Table.HeaderCell <Table.HeaderCell
style={{ cursor: 'pointer' }} style={{ cursor: 'pointer' }}
@ -220,9 +221,17 @@ const UsersTable = () => {
if (user.deleted) return <></>; if (user.deleted) return <></>;
return ( return (
<Table.Row key={user.id}> <Table.Row key={user.id}>
<Table.Cell>{user.username}</Table.Cell> <Table.Cell>{user.id}</Table.Cell>
<Table.Cell>{user.display_name}</Table.Cell> <Table.Cell>
<Table.Cell>{user.email ? user.email : '无'}</Table.Cell> <Popup
content={user.email ? user.email : '未绑定邮箱地址'}
key={user.display_name}
header={user.display_name ? user.display_name : user.username}
trigger={<span>{renderText(user.username, 10)}</span>}
hoverable
/>
</Table.Cell>
<Table.Cell>{user.email ? renderText(user.email, 30) : '无'}</Table.Cell>
<Table.Cell>{user.quota}</Table.Cell> <Table.Cell>{user.quota}</Table.Cell>
<Table.Cell>{renderRole(user.role)}</Table.Cell> <Table.Cell>{renderRole(user.role)}</Table.Cell>
<Table.Cell>{renderStatus(user.status)}</Table.Cell> <Table.Cell>{renderStatus(user.status)}</Table.Cell>

View File

@ -0,0 +1,6 @@
export function renderText(text, limit) {
if (text.length > limit) {
return text.slice(0, limit - 3) + '...';
}
return text;
}