Skip to content

Commit

Permalink
fix: limit the shown text's length (close #80)
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed May 16, 2023
1 parent 519cb03 commit e8da981
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
7 changes: 7 additions & 0 deletions controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ func CreateUser(c *gin.Context) {
})
return
}
if err := common.Validate.Struct(&user); err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "输入不合法 " + err.Error(),
})
return
}
if user.DisplayName == "" {
user.DisplayName = user.Username
}
Expand Down
25 changes: 17 additions & 8 deletions web/src/components/UsersTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link } from 'react-router-dom';
import { API, showError, showSuccess } from '../helpers';

import { ITEMS_PER_PAGE } from '../constants';
import { renderText } from '../helpers/render';

function renderRole(role) {
switch (role) {
Expand Down Expand Up @@ -64,7 +65,7 @@ const UsersTable = () => {
(async () => {
const res = await API.post('/api/user/manage', {
username,
action,
action
});
const { success, message } = res.data;
if (success) {
Expand Down Expand Up @@ -161,18 +162,18 @@ const UsersTable = () => {
<Table.HeaderCell
style={{ cursor: 'pointer' }}
onClick={() => {
sortUser('username');
sortUser('id');
}}
>
用户名
ID
</Table.HeaderCell>
<Table.HeaderCell
style={{ cursor: 'pointer' }}
onClick={() => {
sortUser('display_name');
sortUser('username');
}}
>
显示名称
用户名
</Table.HeaderCell>
<Table.HeaderCell
style={{ cursor: 'pointer' }}
Expand Down Expand Up @@ -220,9 +221,17 @@ const UsersTable = () => {
if (user.deleted) return <></>;
return (
<Table.Row key={user.id}>
<Table.Cell>{user.username}</Table.Cell>
<Table.Cell>{user.display_name}</Table.Cell>
<Table.Cell>{user.email ? user.email : '无'}</Table.Cell>
<Table.Cell>{user.id}</Table.Cell>
<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>{renderRole(user.role)}</Table.Cell>
<Table.Cell>{renderStatus(user.status)}</Table.Cell>
Expand Down
6 changes: 6 additions & 0 deletions web/src/helpers/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function renderText(text, limit) {
if (text.length > limit) {
return text.slice(0, limit - 3) + '...';
}
return text;
}

0 comments on commit e8da981

Please sign in to comment.