Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5537de3f
authored
Apr 23, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Index page is done
parent
4cce9ab7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
112 additions
and
47 deletions
+112
-47
web/src/App.js
+3
-0
web/src/context/Status/index.js
+20
-0
web/src/context/Status/reducer.js
+20
-0
web/src/index.js
+4
-2
web/src/pages/Home/index.js
+65
-45
No files found.
web/src/App.js
View file @
5537de3f
...
...
@@ -14,6 +14,7 @@ import PasswordResetForm from './components/PasswordResetForm';
import
GitHubOAuth
from
'./components/GitHubOAuth'
;
import
PasswordResetConfirm
from
'./components/PasswordResetConfirm'
;
import
{
UserContext
}
from
'./context/User'
;
import
{
StatusContext
}
from
'./context/Status'
;
import
Channel
from
'./pages/Channel'
;
import
Token
from
'./pages/Token'
;
import
EditToken
from
'./pages/Token/EditToken'
;
...
...
@@ -26,6 +27,7 @@ const About = lazy(() => import('./pages/About'));
function
App
()
{
const
[
userState
,
userDispatch
]
=
useContext
(
UserContext
);
const
[
statusState
,
statusDispatch
]
=
useContext
(
StatusContext
);
const
loadUser
=
()
=>
{
let
user
=
localStorage
.
getItem
(
'user'
);
...
...
@@ -39,6 +41,7 @@ function App() {
const
{
success
,
data
}
=
res
.
data
;
if
(
success
)
{
localStorage
.
setItem
(
'status'
,
JSON
.
stringify
(
data
));
statusDispatch
({
type
:
'set'
,
payload
:
data
});
localStorage
.
setItem
(
'footer_html'
,
data
.
footer_html
);
if
(
data
.
version
!==
process
.
env
.
REACT_APP_VERSION
&&
...
...
web/src/context/Status/index.js
0 → 100644
View file @
5537de3f
// contexts/User/index.jsx
import
React
from
'react'
;
import
{
initialState
,
reducer
}
from
'./reducer'
;
export
const
StatusContext
=
React
.
createContext
({
state
:
initialState
,
dispatch
:
()
=>
null
,
});
export
const
StatusProvider
=
({
children
})
=>
{
const
[
state
,
dispatch
]
=
React
.
useReducer
(
reducer
,
initialState
);
return
(
<
StatusContext
.
Provider
value
=
{[
state
,
dispatch
]}
>
{
children
}
<
/StatusContext.Provider
>
);
};
\ No newline at end of file
web/src/context/Status/reducer.js
0 → 100644
View file @
5537de3f
export
const
reducer
=
(
state
,
action
)
=>
{
switch
(
action
.
type
)
{
case
'set'
:
return
{
...
state
,
status
:
action
.
payload
,
};
case
'unset'
:
return
{
...
state
,
status
:
undefined
,
};
default
:
return
state
;
}
};
export
const
initialState
=
{
status
:
undefined
,
};
web/src/index.js
View file @
5537de3f
...
...
@@ -10,20 +10,22 @@ import './index.css';
import
{
UserProvider
}
from
'./context/User'
;
import
{
ToastContainer
}
from
'react-toastify'
;
import
'react-toastify/dist/ReactToastify.css'
;
import
{
StatusProvider
}
from
'./context/Status'
;
const
root
=
ReactDOM
.
createRoot
(
document
.
getElementById
(
'root'
));
root
.
render
(
<
React
.
StrictMode
>
<
StatusProvider
>
<
UserProvider
>
<
BrowserRouter
>
<
Header
/>
<
Container
className
=
{
'main-content'
}
>
<
App
/>
<
/Container
>
<
ToastContainer
/>
<
ToastContainer
/>
<
Footer
/>
<
/BrowserRouter
>
<
/UserProvider
>
<
/StatusProvider
>
<
/React.StrictMode
>
);
web/src/pages/Home/index.js
View file @
5537de3f
import
React
,
{
useEffect
}
from
'react'
;
import
{
Grid
,
Header
,
Placeholder
,
Segment
}
from
'semantic-ui-react'
;
import
{
API
,
showError
,
showNotice
}
from
'../../helpers'
;
import
React
,
{
useContext
,
useEffect
}
from
'react'
;
import
{
Card
,
Grid
,
Header
,
Segment
}
from
'semantic-ui-react'
;
import
{
API
,
showError
,
showNotice
,
timestamp2string
}
from
'../../helpers'
;
import
{
StatusContext
}
from
'../../context/Status'
;
const
Home
=
()
=>
{
const
[
statusState
,
statusDispatch
]
=
useContext
(
StatusContext
);
const
displayNotice
=
async
()
=>
{
const
res
=
await
API
.
get
(
'/api/notice'
);
const
{
success
,
message
,
data
}
=
res
.
data
;
...
...
@@ -17,57 +20,74 @@ const Home = () => {
}
};
const
getStartTimeString
=
()
=>
{
const
timestamp
=
statusState
?.
status
?.
start_time
;
return
timestamp2string
(
timestamp
);
};
useEffect
(()
=>
{
displayNotice
().
then
();
},
[]);
return
(
<>
<
Segment
>
<
Header
as
=
"h3"
>
示例标题
<
/Header
>
<
Grid
columns
=
{
3
}
stackable
>
<
Grid
.
Column
>
<
Segment
raised
>
<
Placeholder
>
<
Placeholder
.
Header
image
>
<
Placeholder
.
Line
/>
<
Placeholder
.
Line
/>
<
/Placeholder.Header
>
<
Placeholder
.
Paragraph
>
<
Placeholder
.
Line
length
=
"medium"
/>
<
Placeholder
.
Line
length
=
"short"
/>
<
/Placeholder.Paragraph
>
<
/Placeholder
>
<
/Segment
>
<
/Grid.Column
>
<
Header
as
=
'h3'
>
系统状况
<
/Header
>
<
Grid
columns
=
{
2
}
stackable
>
<
Grid
.
Column
>
<
Segment
raised
>
<
Placeholder
>
<
Placeholder
.
Header
image
>
<
Placeholder
.
Line
/>
<
Placeholder
.
Line
/>
<
/Placeholder.Header
>
<
Placeholder
.
Paragraph
>
<
Placeholder
.
Line
length
=
"medium"
/>
<
Placeholder
.
Line
length
=
"short"
/>
<
/Placeholder.Paragraph
>
<
/Placeholder
>
<
/Segment
>
<
Card
fluid
>
<
Card
.
Content
>
<
Card
.
Header
>
系统信息
<
/Card.Header
>
<
Card
.
Meta
>
系统信息总览
<
/Card.Meta
>
<
Card
.
Description
>
<
p
>
名称:
{
statusState
?.
status
?.
system_name
}
<
/p
>
<
p
>
版本:
{
statusState
?.
status
?.
version
}
<
/p
>
<
p
>
源码:
<
a
href
=
'https://github.com/songquanpeng/one-api'
target
=
'_blank'
>
https
:
//github.com/songquanpeng/one-api
<
/a
>
<
/p
>
<
p
>
启动时间:
{
getStartTimeString
()}
<
/p
>
<
/Card.Description
>
<
/Card.Content
>
<
/Card
>
<
/Grid.Column
>
<
Grid
.
Column
>
<
Segment
raised
>
<
Placeholder
>
<
Placeholder
.
Header
image
>
<
Placeholder
.
Line
/>
<
Placeholder
.
Line
/>
<
/Placeholder.Header
>
<
Placeholder
.
Paragraph
>
<
Placeholder
.
Line
length
=
"medium"
/>
<
Placeholder
.
Line
length
=
"short"
/>
<
/Placeholder.Paragraph
>
<
/Placeholder
>
<
/Segment
>
<
Card
fluid
>
<
Card
.
Content
>
<
Card
.
Header
>
系统配置
<
/Card.Header
>
<
Card
.
Meta
>
系统配置总览
<
/Card.Meta
>
<
Card
.
Description
>
<
p
>
邮箱验证:
{
statusState
?.
status
?.
email_verification
===
true
?
'已启用'
:
'未启用'
}
<
/p
>
<
p
>
GitHub
身份验证:
{
statusState
?.
status
?.
github_oauth
===
true
?
'已启用'
:
'未启用'
}
<
/p
>
<
p
>
微信身份验证:
{
statusState
?.
status
?.
wechat_login
===
true
?
'已启用'
:
'未启用'
}
<
/p
>
<
p
>
Turnstile
用户校验:
{
statusState
?.
status
?.
turnstile_check
===
true
?
'已启用'
:
'未启用'
}
<
/p
>
<
/Card.Description
>
<
/Card.Content
>
<
/Card
>
<
/Grid.Column
>
<
/Grid
>
<
/Segment
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment