feat: able to add chat page link now (close #70)

This commit is contained in:
JustSong 2023-06-17 23:51:56 +08:00
parent ba89abedf0
commit d97640374c
7 changed files with 73 additions and 17 deletions

View File

@ -14,6 +14,7 @@ var ServerAddress = "http://localhost:3000"
var Footer = "" var Footer = ""
var Logo = "" var Logo = ""
var TopUpLink = "" var TopUpLink = ""
var ChatLink = ""
var UsingSQLite = false var UsingSQLite = false

View File

@ -28,6 +28,7 @@ func GetStatus(c *gin.Context) {
"turnstile_check": common.TurnstileCheckEnabled, "turnstile_check": common.TurnstileCheckEnabled,
"turnstile_site_key": common.TurnstileSiteKey, "turnstile_site_key": common.TurnstileSiteKey,
"top_up_link": common.TopUpLink, "top_up_link": common.TopUpLink,
"chat_link": common.ChatLink,
}, },
}) })
return return

View File

@ -63,6 +63,7 @@ func InitOptionMap() {
common.OptionMap["ModelRatio"] = common.ModelRatio2JSONString() common.OptionMap["ModelRatio"] = common.ModelRatio2JSONString()
common.OptionMap["GroupRatio"] = common.GroupRatio2JSONString() common.OptionMap["GroupRatio"] = common.GroupRatio2JSONString()
common.OptionMap["TopUpLink"] = common.TopUpLink common.OptionMap["TopUpLink"] = common.TopUpLink
common.OptionMap["ChatLink"] = common.ChatLink
common.OptionMapRWMutex.Unlock() common.OptionMapRWMutex.Unlock()
loadOptionsFromDatabase() loadOptionsFromDatabase()
} }
@ -191,6 +192,8 @@ func updateOptionMap(key string, value string) (err error) {
err = common.UpdateGroupRatioByJSONString(value) err = common.UpdateGroupRatioByJSONString(value)
case "TopUpLink": case "TopUpLink":
common.TopUpLink = value common.TopUpLink = value
case "ChatLink":
common.ChatLink = value
case "ChannelDisableThreshold": case "ChannelDisableThreshold":
common.ChannelDisableThreshold, _ = strconv.ParseFloat(value, 64) common.ChannelDisableThreshold, _ = strconv.ParseFloat(value, 64)
} }

View File

@ -23,6 +23,7 @@ import Redemption from './pages/Redemption';
import EditRedemption from './pages/Redemption/EditRedemption'; import EditRedemption from './pages/Redemption/EditRedemption';
import TopUp from './pages/TopUp'; import TopUp from './pages/TopUp';
import Log from './pages/Log'; import Log from './pages/Log';
import Chat from './pages/Chat';
const Home = lazy(() => import('./pages/Home')); const Home = lazy(() => import('./pages/Home'));
const About = lazy(() => import('./pages/About')); const About = lazy(() => import('./pages/About'));
@ -47,6 +48,11 @@ function App() {
localStorage.setItem('system_name', data.system_name); localStorage.setItem('system_name', data.system_name);
localStorage.setItem('logo', data.logo); localStorage.setItem('logo', data.logo);
localStorage.setItem('footer_html', data.footer_html); localStorage.setItem('footer_html', data.footer_html);
if (data.chat_link) {
localStorage.setItem('chat_link', data.chat_link);
} else {
localStorage.removeItem('chat_link');
}
if ( if (
data.version !== process.env.REACT_APP_VERSION && data.version !== process.env.REACT_APP_VERSION &&
data.version !== 'v0.0.0' && data.version !== 'v0.0.0' &&
@ -267,6 +273,14 @@ function App() {
</Suspense> </Suspense>
} }
/> />
<Route
path='/chat'
element={
<Suspense fallback={<Loading></Loading>}>
<Chat />
</Suspense>
}
/>
<Route path='*' element={NotFound} /> <Route path='*' element={NotFound} />
</Routes> </Routes>
); );

View File

@ -7,57 +7,65 @@ import { API, getLogo, getSystemName, isAdmin, isMobile, showSuccess } from '../
import '../index.css'; import '../index.css';
// Header Buttons // Header Buttons
const headerButtons = [ let headerButtons = [
{ {
name: '首页', name: '首页',
to: '/', to: '/',
icon: 'home', icon: 'home'
}, },
{ {
name: '渠道', name: '渠道',
to: '/channel', to: '/channel',
icon: 'sitemap', icon: 'sitemap',
admin: true, admin: true
}, },
{ {
name: '令牌', name: '令牌',
to: '/token', to: '/token',
icon: 'key', icon: 'key'
}, },
{ {
name: '兑换', name: '兑换',
to: '/redemption', to: '/redemption',
icon: 'dollar sign', icon: 'dollar sign',
admin: true, admin: true
}, },
{ {
name: '充值', name: '充值',
to: '/topup', to: '/topup',
icon: 'cart', icon: 'cart'
}, },
{ {
name: '用户', name: '用户',
to: '/user', to: '/user',
icon: 'user', icon: 'user',
admin: true, admin: true
}, },
{ {
name: '日志', name: '日志',
to: '/log', to: '/log',
icon: 'book', icon: 'book'
}, },
{ {
name: '设置', name: '设置',
to: '/setting', to: '/setting',
icon: 'setting', icon: 'setting'
}, },
{ {
name: '关于', name: '关于',
to: '/about', to: '/about',
icon: 'info circle', icon: 'info circle'
}, }
]; ];
if (localStorage.getItem('chat_link')) {
headerButtons.splice(1, 0, {
name: '聊天',
to: '/chat',
icon: 'comments'
});
}
const Header = () => { const Header = () => {
const [userState, userDispatch] = useContext(UserContext); const [userState, userDispatch] = useContext(UserContext);
let navigate = useNavigate(); let navigate = useNavigate();
@ -112,11 +120,11 @@ const Header = () => {
style={ style={
showSidebar showSidebar
? { ? {
borderBottom: 'none', borderBottom: 'none',
marginBottom: '0', marginBottom: '0',
borderTop: 'none', borderTop: 'none',
height: '51px', height: '51px'
} }
: { borderTop: 'none', height: '52px' } : { borderTop: 'none', height: '52px' }
} }
> >

View File

@ -34,6 +34,7 @@ const SystemSetting = () => {
ModelRatio: '', ModelRatio: '',
GroupRatio: '', GroupRatio: '',
TopUpLink: '', TopUpLink: '',
ChatLink: '',
AutomaticDisableChannelEnabled: '', AutomaticDisableChannelEnabled: '',
ChannelDisableThreshold: 0, ChannelDisableThreshold: 0,
LogConsumeEnabled: '' LogConsumeEnabled: ''
@ -109,7 +110,8 @@ const SystemSetting = () => {
name === 'PreConsumedQuota' || name === 'PreConsumedQuota' ||
name === 'ModelRatio' || name === 'ModelRatio' ||
name === 'GroupRatio' || name === 'GroupRatio' ||
name === 'TopUpLink' name === 'TopUpLink' ||
name === 'ChatLink'
) { ) {
setInputs((inputs) => ({ ...inputs, [name]: value })); setInputs((inputs) => ({ ...inputs, [name]: value }));
} else { } else {
@ -155,6 +157,9 @@ const SystemSetting = () => {
if (originInputs['TopUpLink'] !== inputs.TopUpLink) { if (originInputs['TopUpLink'] !== inputs.TopUpLink) {
await updateOption('TopUpLink', inputs.TopUpLink); await updateOption('TopUpLink', inputs.TopUpLink);
} }
if (originInputs['ChatLink'] !== inputs.ChatLink) {
await updateOption('ChatLink', inputs.ChatLink);
}
}; };
const submitSMTP = async () => { const submitSMTP = async () => {
@ -360,6 +365,15 @@ const SystemSetting = () => {
min='0' min='0'
placeholder='例如100' placeholder='例如100'
/> />
<Form.Input
label='聊天页面链接'
name='ChatLink'
onChange={handleInputChange}
autoComplete='new-password'
value={inputs.ChatLink}
type='link'
placeholder='例如 ChatGPT Next Web 的部署地址'
/>
</Form.Group> </Form.Group>
<Form.Group widths='equal'> <Form.Group widths='equal'>
<Form.TextArea <Form.TextArea

View File

@ -0,0 +1,15 @@
import React from 'react';
const Chat = () => {
const chatLink = localStorage.getItem('chat_link');
return (
<iframe
src={chatLink}
style={{ width: '100%', height: '85vh', border: 'none' }}
/>
);
};
export default Chat;