mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
update
This commit is contained in:
parent
e24d8e6b75
commit
31c5e283ba
@ -44,27 +44,3 @@ You don’t have to ever use `eject`. The curated feature set is suitable for sm
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `yarn build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
||||
|
@ -2,19 +2,28 @@
|
||||
"name": "admin-frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"homepage": "/hk_reporter/",
|
||||
"homepage": "hk_reporter",
|
||||
"proxy": "http://localhost:8080",
|
||||
"dependencies": {
|
||||
"@ant-design/icons": "^4.6.4",
|
||||
"@testing-library/jest-dom": "^5.11.4",
|
||||
"@testing-library/react": "^11.1.0",
|
||||
"@testing-library/user-event": "^12.1.10",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/node": "^12.0.0",
|
||||
"@types/react": "^17.0.0",
|
||||
"@types/react-dom": "^17.0.0",
|
||||
"antd": "^4.16.13",
|
||||
"axios": "^0.21.4",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-scripts": "4.0.3",
|
||||
"typescript": "^4.1.2",
|
||||
"web-vitals": "^1.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build && rm -r ../src/plugins/nonebot_hk_reporter/admin_page/dist && mv build ../src/plugins/nonebot_hk_reporter/admin_page/dist",
|
||||
"build": "react-scripts build && mv build ../src/plugins/nonebot_hk_reporter/admin_page/dist",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
|
@ -1,25 +0,0 @@
|
||||
import logo from './logo.svg';
|
||||
import './App.css';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>
|
||||
Edit <code>src/App.js</code> and save to reload.
|
||||
</p>
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
@ -1,3 +1,4 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
45
admin-frontend/src/App.tsx
Normal file
45
admin-frontend/src/App.tsx
Normal file
@ -0,0 +1,45 @@
|
||||
import React, { useContext, useEffect, useState } from 'react';
|
||||
import './App.css';
|
||||
import { LoginContext, loginContextDefault, GlobalConfContext } from './utils/context';
|
||||
import { LoginStatus, GlobalConf } from './utils/type';
|
||||
import { Admin } from './pages/admin';
|
||||
import { getGlobalConf } from './api/config';
|
||||
import 'antd/dist/antd.css';
|
||||
|
||||
|
||||
function LoginSwitch() {
|
||||
const {login, save} = useContext(LoginContext);
|
||||
if (login.login) {
|
||||
return <Admin />;
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
not login
|
||||
<button onClick={() => save({login: true, type: 'admin', name: ''})}>1</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [loginStatus, setLogin] = useState(loginContextDefault.login);
|
||||
const [globalConf, setGlobalConf] = useState<GlobalConf>({platformConf: []});
|
||||
// const globalConfContext = useContext(GlobalConfContext);
|
||||
const save = (login: LoginStatus) => setLogin(_ => login);
|
||||
useEffect(() => {
|
||||
const fetchGlobalConf = async () => {
|
||||
const res = await getGlobalConf();
|
||||
setGlobalConf(_ => res);
|
||||
};
|
||||
fetchGlobalConf();
|
||||
}, []);
|
||||
return (
|
||||
<LoginContext.Provider value={{login: loginStatus, save}}>
|
||||
<GlobalConfContext.Provider value={globalConf}>
|
||||
<LoginSwitch />
|
||||
</GlobalConfContext.Provider>
|
||||
</LoginContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
9
admin-frontend/src/api/config.ts
Normal file
9
admin-frontend/src/api/config.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import axios from "axios";
|
||||
import { GlobalConf } from "../utils/type";
|
||||
|
||||
const baseUrl = '/hk_reporter/api/'
|
||||
|
||||
export async function getGlobalConf(): Promise<GlobalConf> {
|
||||
const res = await axios.get<GlobalConf>(`${baseUrl}global_conf`);
|
||||
return res.data;
|
||||
}
|
5
admin-frontend/src/pages/admin.css
Normal file
5
admin-frontend/src/pages/admin.css
Normal file
@ -0,0 +1,5 @@
|
||||
.layout-side .user {
|
||||
height: 32px;
|
||||
margin: 16px;
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
47
admin-frontend/src/pages/admin.tsx
Normal file
47
admin-frontend/src/pages/admin.tsx
Normal file
@ -0,0 +1,47 @@
|
||||
import React, { FC, useContext, useState } from "react";
|
||||
import { LoginContext, GlobalConfContext } from "../utils/context";
|
||||
import { Layout, Menu } from 'antd';
|
||||
import { SubscribeConfig } from '../utils/type';
|
||||
import { SettingOutlined, BugOutlined } from '@ant-design/icons';
|
||||
import './admin.css';
|
||||
|
||||
export function Admin() {
|
||||
const { login } = useContext(LoginContext);
|
||||
const [ tab, changeTab ] = useState("manage");
|
||||
const globalConfContext = useContext(GlobalConfContext);
|
||||
return (
|
||||
<Layout style={{ minHeight: '100vh' }}>
|
||||
<Layout.Sider className="layout-side">
|
||||
<div className="user">
|
||||
</div>
|
||||
<Menu mode="inline" theme="dark" defaultSelectedKeys={[tab]}
|
||||
onClick={({key}) => changeTab(key)}>
|
||||
<Menu.Item key="manage" icon={<SettingOutlined />}>订阅管理</Menu.Item>
|
||||
{ login.type == 'admin' &&
|
||||
<Menu.Item key="log" icon={<BugOutlined />}>查看日志</Menu.Item>
|
||||
}
|
||||
</Menu>
|
||||
</Layout.Sider>
|
||||
<Layout.Content>
|
||||
<div style={{margin: '24px', background: '#fff', minHeight: '640px'}}>
|
||||
{
|
||||
tab == 'manage' ?
|
||||
<div>123</div>
|
||||
: null
|
||||
}
|
||||
</div>
|
||||
</Layout.Content>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
function ConfigPage() {
|
||||
const [ configData, setConfigData ] = useState<Array<SubscribeConfig>>([
|
||||
{
|
||||
platform: 'weibo',
|
||||
target: '123333',
|
||||
catetories: [1, 2],
|
||||
tags: []
|
||||
}
|
||||
]);
|
||||
}
|
1
admin-frontend/src/react-app-env.d.ts
vendored
Normal file
1
admin-frontend/src/react-app-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
@ -1,4 +1,6 @@
|
||||
const reportWebVitals = onPerfEntry => {
|
||||
import { ReportHandler } from 'web-vitals';
|
||||
|
||||
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
getCLS(onPerfEntry);
|
14
admin-frontend/src/utils/context.ts
Normal file
14
admin-frontend/src/utils/context.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { createContext } from "react";
|
||||
import { LoginContextType, GlobalConf } from "./type";
|
||||
|
||||
export const loginContextDefault: LoginContextType = {
|
||||
login: {
|
||||
login: false,
|
||||
type: '',
|
||||
name: ''
|
||||
},
|
||||
save: () => {}
|
||||
};
|
||||
|
||||
export const LoginContext = createContext(loginContextDefault);
|
||||
export const GlobalConfContext = createContext<GlobalConf>({platformConf: []});
|
29
admin-frontend/src/utils/type.ts
Normal file
29
admin-frontend/src/utils/type.ts
Normal file
@ -0,0 +1,29 @@
|
||||
export interface LoginStatus {
|
||||
login: boolean
|
||||
type: String
|
||||
name: String
|
||||
}
|
||||
|
||||
export type LoginContextType = {
|
||||
login: LoginStatus
|
||||
save: (status: LoginStatus) => void
|
||||
}
|
||||
|
||||
export interface SubscribeConfig {
|
||||
platform: String
|
||||
target?: String
|
||||
catetories: Array<number>
|
||||
tags: Array<String>
|
||||
}
|
||||
|
||||
export interface GlobalConf {
|
||||
platformConf: Array<PlatformConfig>
|
||||
}
|
||||
|
||||
export interface PlatformConfig {
|
||||
name: string
|
||||
catetories: Map<number, string>,
|
||||
enableTag: boolean,
|
||||
platformName: string,
|
||||
hasTarget: boolean
|
||||
}
|
26
admin-frontend/tsconfig.json
Normal file
26
admin-frontend/tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,18 +1,26 @@
|
||||
import importlib
|
||||
import socketio
|
||||
from nonebot import get_driver
|
||||
from nonebot.log import logger
|
||||
from nonebot.drivers.fastapi import Driver
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from nonebot import get_driver
|
||||
from nonebot.drivers.fastapi import Driver
|
||||
from nonebot.log import logger
|
||||
import socketio
|
||||
|
||||
from .api import test, get_global_conf
|
||||
|
||||
URL_BASE = '/hk_reporter/'
|
||||
GLOBAL_CONF_URL = f'{URL_BASE}api/global_conf'
|
||||
TEST_URL = f'{URL_BASE}test'
|
||||
|
||||
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")
|
||||
socket_app = socketio.ASGIApp(sio, socketio_path="socket")
|
||||
|
||||
def register_router_fastapi(driver: Driver, socketio):
|
||||
app = driver.server_app
|
||||
static_path = str((Path(__file__).parent / "dist").resolve())
|
||||
app.get(TEST_URL)(test)
|
||||
app.get(GLOBAL_CONF_URL)(get_global_conf)
|
||||
app.mount(URL_BASE, StaticFiles(directory=static_path, html=True), name="hk_reporter")
|
||||
|
||||
def init():
|
||||
@ -28,6 +36,6 @@ def init():
|
||||
if host in ["0.0.0.0", "127.0.0.1"]:
|
||||
host = "localhost"
|
||||
logger.opt(colors=True).info(f"Nonebot test frontend will be running at: "
|
||||
f"<b><u>http://{host}:{port}/test/</u></b>")
|
||||
f"<b><u>http://{host}:{port}{URL_BASE}</u></b>")
|
||||
|
||||
init()
|
||||
|
17
src/plugins/nonebot_hk_reporter/admin_page/api.py
Normal file
17
src/plugins/nonebot_hk_reporter/admin_page/api.py
Normal file
@ -0,0 +1,17 @@
|
||||
from ..platform import platform_manager
|
||||
|
||||
async def test():
|
||||
return {"status": 200, "text": "test"}
|
||||
|
||||
async def get_global_conf():
|
||||
res = []
|
||||
for platform_name, platform in platform_manager.items():
|
||||
res.append({
|
||||
'platformName': platform_name,
|
||||
'categories': platform.categories,
|
||||
'enabledTag': platform.enable_tag,
|
||||
'name': platform.name,
|
||||
'hasTarget': getattr(platform, 'has_target')
|
||||
})
|
||||
return { 'platformConf': res }
|
||||
|
Loading…
x
Reference in New Issue
Block a user