From 64db39320a7e81c385ed8c466b01795321f14408 Mon Sep 17 00:00:00 2001 From: JustSong Date: Sat, 10 Jun 2023 20:40:07 +0800 Subject: [PATCH 1/2] feat: now able to check all user's log --- model/log.go | 8 +++- web/src/components/LogsTable.js | 78 ++++++++++++++++++++++++++++++--- 2 files changed, 79 insertions(+), 7 deletions(-) diff --git a/model/log.go b/model/log.go index bc096055..52d02a6f 100644 --- a/model/log.go +++ b/model/log.go @@ -35,7 +35,13 @@ func RecordLog(userId int, logType int, content string) { } func GetAllLogs(logType int, startIdx int, num int) (logs []*Log, err error) { - err = DB.Where("type = ?", logType).Order("id desc").Limit(num).Offset(startIdx).Find(&logs).Error + var tx *gorm.DB + if logType == LogTypeUnknown { + tx = DB + } else { + tx = DB.Where("type = ?", logType) + } + err = tx.Order("id desc").Limit(num).Offset(startIdx).Find(&logs).Error return logs, err } diff --git a/web/src/components/LogsTable.js b/web/src/components/LogsTable.js index 1c623898..e5ec5dfa 100644 --- a/web/src/components/LogsTable.js +++ b/web/src/components/LogsTable.js @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; -import { Button, Label, Pagination, Table } from 'semantic-ui-react'; -import { API, showError, timestamp2string } from '../helpers'; +import { Button, Label, Pagination, Select, Table } from 'semantic-ui-react'; +import { API, isAdmin, showError, timestamp2string } from '../helpers'; import { ITEMS_PER_PAGE } from '../constants'; @@ -12,6 +12,19 @@ function renderTimestamp(timestamp) { ); } +const MODE_OPTIONS = [ + { key: 'all', text: '全部用户', value: 'all' }, + { key: 'self', text: '当前用户', value: 'self' }, +]; + +const LOG_OPTIONS = [ + { key: '0', text: '全部', value: 0 }, + { key: '1', text: '充值', value: 1 }, + { key: '2', text: '消费', value: 2 }, + { key: '3', text: '管理', value: 3 }, + { key: '4', text: '系统', value: 4 } +]; + function renderType(type) { switch (type) { case 1: @@ -21,7 +34,7 @@ function renderType(type) { case 3: return ; case 4: - return ; + return ; default: return ; } @@ -33,9 +46,16 @@ const LogsTable = () => { const [activePage, setActivePage] = useState(1); const [searchKeyword, setSearchKeyword] = useState(''); const [searching, setSearching] = useState(false); + const [logType, setLogType] = useState(0); + const [mode, setMode] = useState('self'); // all, self + const showModePanel = isAdmin(); const loadLogs = async (startIdx) => { - const res = await API.get(`/api/log/self/?p=${startIdx}`); + let url = `/api/log/self/?p=${startIdx}&type=${logType}`; + if (mode === 'all') { + url = `/api/log/?p=${startIdx}&type=${logType}`; + } + const res = await API.get(url); const { success, message, data } = res.data; if (success) { if (startIdx === 0) { @@ -74,6 +94,10 @@ const LogsTable = () => { }); }, []); + useEffect(() => { + refresh().then(); + }, [mode, logType]); + const searchLogs = async () => { if (searchKeyword === '') { // if keyword is blank, load files instead. @@ -125,6 +149,19 @@ const LogsTable = () => { > 时间 + { + showModePanel && ( + { + sortLog('user_id'); + }} + width={1} + > + 用户 + + ) + } { @@ -139,7 +176,7 @@ const LogsTable = () => { onClick={() => { sortLog('content'); }} - width={11} + width={showModePanel ? 10 : 11} > 详情 @@ -157,6 +194,11 @@ const LogsTable = () => { return ( {renderTimestamp(log.created_at)} + { + showModePanel && ( + + ) + } {renderType(log.type)} {log.content} @@ -166,7 +208,31 @@ const LogsTable = () => { - + + { + showModePanel && ( + { + setLogType(value); + }} + /> Date: Sat, 10 Jun 2023 20:43:32 +0800 Subject: [PATCH 2/2] docs: update README --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d14aa5cd..82628491 100644 --- a/README.md +++ b/README.md @@ -68,16 +68,17 @@ _✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用 7. 支持**通道管理**,批量创建通道。 8. 支持**用户分组**以及**渠道分组**。 9. 支持渠道**设置模型列表**。 -10. 支持发布公告,设置充值链接,设置新用户初始额度。 -11. 支持丰富的**自定义**设置, +10. 支持**查看额度明细**。 +11. 支持发布公告,设置充值链接,设置新用户初始额度。 +12. 支持丰富的**自定义**设置, 1. 支持自定义系统名称,logo 以及页脚。 2. 支持自定义首页和关于页面,可以选择使用 HTML & Markdown 代码进行自定义,或者使用一个单独的网页通过 iframe 嵌入。 -12. 支持通过系统访问令牌访问管理 API。 -13. 支持用户管理,支持**多种用户登录注册方式**: +13. 支持通过系统访问令牌访问管理 API。 +14. 支持用户管理,支持**多种用户登录注册方式**: + 邮箱登录注册以及通过邮箱进行密码重置。 + [GitHub 开放授权](https://github.com/settings/applications/new)。 + 微信公众号授权(需要额外部署 [WeChat Server](https://github.com/songquanpeng/wechat-server))。 -14. 未来其他大模型开放 API 后,将第一时间支持,并将其封装成同样的 API 访问方式。 +15. 未来其他大模型开放 API 后,将第一时间支持,并将其封装成同样的 API 访问方式。 ## 部署 ### 基于 Docker 进行部署