From c4b662b58630abca5220c4b78e11ea2f45754e20 Mon Sep 17 00:00:00 2001 From: carey036 <45777074+carey036@users.noreply.github.com> Date: Tue, 13 Feb 2024 20:36:30 +0800 Subject: [PATCH] feat: add chat page for berry --- web/berry/src/menu-items/panel.js | 45 ++++++++++++++++++------------ web/berry/src/routes/MainRoutes.js | 5 ++++ web/berry/src/views/Chat/index.js | 37 ++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 18 deletions(-) create mode 100644 web/berry/src/views/Chat/index.js diff --git a/web/berry/src/menu-items/panel.js b/web/berry/src/menu-items/panel.js index 556b157f..8bc0699a 100644 --- a/web/berry/src/menu-items/panel.js +++ b/web/berry/src/menu-items/panel.js @@ -8,11 +8,12 @@ import { IconKey, IconGardenCart, IconUser, - IconUserScan + IconUserScan, + IconFileTextAi } from '@tabler/icons-react'; // constant -const icons = { IconDashboard, IconSitemap, IconArticle, IconCoin, IconAdjustments, IconKey, IconGardenCart, IconUser, IconUserScan }; +const icons = { IconDashboard, IconSitemap, IconArticle, IconCoin, IconAdjustments, IconKey, IconGardenCart, IconUser, IconUserScan, IconFileTextAi }; // ==============================|| DASHBOARD MENU ITEMS ||============================== // @@ -29,6 +30,14 @@ const panel = { breadcrumbs: false, isAdmin: false }, + { + id: 'chat', + title: '聊天', + type: 'item', + url: '/panel/chat', + icon: icons.IconFileTextAi, + breadcrumbs: false + }, { id: 'channel', title: '渠道', @@ -38,22 +47,6 @@ const panel = { breadcrumbs: false, isAdmin: true }, - { - id: 'token', - title: '令牌', - type: 'item', - url: '/panel/token', - icon: icons.IconKey, - breadcrumbs: false - }, - { - id: 'log', - title: '日志', - type: 'item', - url: '/panel/log', - icon: icons.IconArticle, - breadcrumbs: false - }, { id: 'redemption', title: '兑换', @@ -80,6 +73,22 @@ const panel = { breadcrumbs: false, isAdmin: true }, + { + id: 'log', + title: '日志', + type: 'item', + url: '/panel/log', + icon: icons.IconArticle, + breadcrumbs: false + }, + { + id: 'token', + title: '令牌', + type: 'item', + url: '/panel/token', + icon: icons.IconKey, + breadcrumbs: false + }, { id: 'profile', title: '我的', diff --git a/web/berry/src/routes/MainRoutes.js b/web/berry/src/routes/MainRoutes.js index 74f7e4c2..e1cee839 100644 --- a/web/berry/src/routes/MainRoutes.js +++ b/web/berry/src/routes/MainRoutes.js @@ -9,6 +9,7 @@ const Log = Loadable(lazy(() => import('views/Log'))); const Redemption = Loadable(lazy(() => import('views/Redemption'))); const Setting = Loadable(lazy(() => import('views/Setting'))); const Token = Loadable(lazy(() => import('views/Token'))); +const Chat = Loadable(lazy(() => import('views/Chat'))); const Topup = Loadable(lazy(() => import('views/Topup'))); const User = Loadable(lazy(() => import('views/User'))); const Profile = Loadable(lazy(() => import('views/Profile'))); @@ -39,6 +40,10 @@ const MainRoutes = { path: 'log', element: }, + { + path: 'chat', + element: + }, { path: 'redemption', element: diff --git a/web/berry/src/views/Chat/index.js b/web/berry/src/views/Chat/index.js new file mode 100644 index 00000000..c40b348b --- /dev/null +++ b/web/berry/src/views/Chat/index.js @@ -0,0 +1,37 @@ +import React, { useEffect, useState } from "react"; +import { API } from 'utils/api'; +import { showError, showSuccess } from 'utils/common'; + +const Chat = () => { + const [value, setValue] = useState([]); + const [isLoading, setIsLoading] = useState(true); // 加载状态 + + const loadTokens = async () => { + setIsLoading(true); // 开始加载 + const res = await API.get(`/api/token/?p=0`); + const { success, message, data } = res.data; + setValue(data); + setIsLoading(false); // 加载完成 + }; + + useEffect(() => { + loadTokens(); + }, []); + + if (isLoading) { + return
Loading...
; + } else if (value.length) { + const siteInfo = JSON.parse(localStorage.getItem("siteInfo")); + const chatLink = siteInfo.chat_link + `#/?settings={"key":"sk-${value[0]?.key}","url":"${siteInfo.server_address}"}`; + return ( +