refactor: enhance log retrieval and user interaction in LogsTable component
This commit is contained in:
15
model/log.go
15
model/log.go
@@ -184,7 +184,7 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
err = tx.Order("id desc").Limit(num).Offset(startIdx).Omit("id").Find(&logs).Error
|
err = tx.Order("id desc").Limit(num).Offset(startIdx).Find(&logs).Error
|
||||||
for i := range logs {
|
for i := range logs {
|
||||||
var otherMap map[string]interface{}
|
var otherMap map[string]interface{}
|
||||||
otherMap = common.StrToMap(logs[i].Other)
|
otherMap = common.StrToMap(logs[i].Other)
|
||||||
@@ -193,6 +193,7 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int
|
|||||||
delete(otherMap, "admin_info")
|
delete(otherMap, "admin_info")
|
||||||
}
|
}
|
||||||
logs[i].Other = common.MapToJsonStr(otherMap)
|
logs[i].Other = common.MapToJsonStr(otherMap)
|
||||||
|
logs[i].Id = logs[i].Id % 1024
|
||||||
}
|
}
|
||||||
return logs, total, err
|
return logs, total, err
|
||||||
}
|
}
|
||||||
@@ -203,7 +204,17 @@ func SearchAllLogs(keyword string) (logs []*Log, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SearchUserLogs(userId int, keyword string) (logs []*Log, err error) {
|
func SearchUserLogs(userId int, keyword string) (logs []*Log, err error) {
|
||||||
err = LOG_DB.Where("user_id = ? and type = ?", userId, keyword).Order("id desc").Limit(common.MaxRecentItems).Omit("id").Find(&logs).Error
|
err = LOG_DB.Where("user_id = ? and type = ?", userId, keyword).Order("id desc").Limit(common.MaxRecentItems).Find(&logs).Error
|
||||||
|
for i := range logs {
|
||||||
|
var otherMap map[string]interface{}
|
||||||
|
otherMap = common.StrToMap(logs[i].Other)
|
||||||
|
if otherMap != nil {
|
||||||
|
// delete admin
|
||||||
|
delete(otherMap, "admin_info")
|
||||||
|
}
|
||||||
|
logs[i].Other = common.MapToJsonStr(otherMap)
|
||||||
|
logs[i].Id = logs[i].Id % 1024
|
||||||
|
}
|
||||||
return logs, err
|
return logs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,10 @@ const LogsTable = () => {
|
|||||||
size='small'
|
size='small'
|
||||||
color={stringToColor(text)}
|
color={stringToColor(text)}
|
||||||
style={{ marginRight: 4 }}
|
style={{ marginRight: 4 }}
|
||||||
onClick={() => showUserInfo(record.user_id)}
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
showUserInfo(record.user_id)
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{typeof text === 'string' && text.slice(0, 1)}
|
{typeof text === 'string' && text.slice(0, 1)}
|
||||||
</Avatar>
|
</Avatar>
|
||||||
@@ -205,8 +208,9 @@ const LogsTable = () => {
|
|||||||
<Tag
|
<Tag
|
||||||
color='grey'
|
color='grey'
|
||||||
size='large'
|
size='large'
|
||||||
onClick={() => {
|
onClick={(event) => {
|
||||||
copyText(text);
|
//cancel the row click event
|
||||||
|
copyText(event, text);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{' '}
|
{' '}
|
||||||
@@ -265,8 +269,8 @@ const LogsTable = () => {
|
|||||||
<Tag
|
<Tag
|
||||||
color={stringToColor(text)}
|
color={stringToColor(text)}
|
||||||
size='large'
|
size='large'
|
||||||
onClick={() => {
|
onClick={(event) => {
|
||||||
copyText(text);
|
copyText(event, text);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{' '}
|
{' '}
|
||||||
@@ -518,7 +522,7 @@ const LogsTable = () => {
|
|||||||
let expandDatesLocal = {};
|
let expandDatesLocal = {};
|
||||||
for (let i = 0; i < logs.length; i++) {
|
for (let i = 0; i < logs.length; i++) {
|
||||||
logs[i].timestamp2string = timestamp2string(logs[i].created_at);
|
logs[i].timestamp2string = timestamp2string(logs[i].created_at);
|
||||||
logs[i].key = i;
|
logs[i].key = logs[i].id;
|
||||||
let other = getLogOther(logs[i].other);
|
let other = getLogOther(logs[i].other);
|
||||||
let expandDataLocal = [];
|
let expandDataLocal = [];
|
||||||
if (isAdmin()) {
|
if (isAdmin()) {
|
||||||
@@ -650,11 +654,12 @@ const LogsTable = () => {
|
|||||||
await loadLogs(activePage, pageSize, logType);
|
await loadLogs(activePage, pageSize, logType);
|
||||||
};
|
};
|
||||||
|
|
||||||
const copyText = async (text) => {
|
const copyText = async (e, text) => {
|
||||||
|
e.stopPropagation();
|
||||||
if (await copy(text)) {
|
if (await copy(text)) {
|
||||||
showSuccess('已复制:' + text);
|
showSuccess('已复制:' + text);
|
||||||
} else {
|
} else {
|
||||||
Modal.error({ title: '无法复制到剪贴板,请手动复制', content: text });
|
Modal.error({ title: t('无法复制到剪贴板,请手动复制'), content: text });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
import { Tag } from '@douyinfe/semi-ui';
|
import { Modal, Tag } from '@douyinfe/semi-ui';
|
||||||
|
import { copy, showSuccess } from './utils.js';
|
||||||
|
|
||||||
export function renderText(text, limit) {
|
export function renderText(text, limit) {
|
||||||
if (text.length > limit) {
|
if (text.length > limit) {
|
||||||
@@ -38,6 +39,14 @@ export function renderGroup(group) {
|
|||||||
size='large'
|
size='large'
|
||||||
color={tagColors[group] || stringToColor(group)}
|
color={tagColors[group] || stringToColor(group)}
|
||||||
key={group}
|
key={group}
|
||||||
|
onClick={async (event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
if (await copy(group)) {
|
||||||
|
showSuccess(i18next.t('已复制:') + group);
|
||||||
|
} else {
|
||||||
|
Modal.error({ title: t('无法复制到剪贴板,请手动复制'), content: group });
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{group}
|
{group}
|
||||||
</Tag>
|
</Tag>
|
||||||
|
|||||||
Reference in New Issue
Block a user