Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add chat page for berry #1402

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions web/berry/src/menu-items/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||============================== //

Expand All @@ -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: '渠道',
Expand Down
5 changes: 5 additions & 0 deletions web/berry/src/routes/MainRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand Down Expand Up @@ -39,6 +40,10 @@ const MainRoutes = {
path: 'log',
element: <Log />
},
{
path: 'chat',
element: <Chat />
},
{
path: 'redemption',
element: <Redemption />
Expand Down
37 changes: 37 additions & 0 deletions web/berry/src/views/Chat/index.js
Original file line number Diff line number Diff line change
@@ -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 <div>Loading...</div>;
} 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 (
<iframe
src={chatLink}
style={{ width: "100%", height: "85vh", border: "none" }}
/>
);
} else {
showError("未找到可用令牌,请先创建令牌");
}
};

export default Chat;