mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
♻️ 重构网页后台,改为本地静态资源 (#490)
This commit is contained in:
parent
c8d2e6760f
commit
56c92b3313
@ -1,6 +1,9 @@
|
||||
import os
|
||||
import re
|
||||
import nonebot
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from LittlePaimon.config import config
|
||||
from LittlePaimon.utils import logger, DRIVER
|
||||
@ -8,13 +11,13 @@ from .api import BaseApiRouter
|
||||
from .pages import admin_app, login_page, bind_cookie_page, blank_page
|
||||
|
||||
|
||||
requestAdaptor = '''
|
||||
requestAdaptor = """
|
||||
requestAdaptor(api) {
|
||||
api.headers["token"] = localStorage.getItem("token");
|
||||
return api;
|
||||
},
|
||||
'''
|
||||
responseAdaptor = '''
|
||||
"""
|
||||
responseAdaptor = """
|
||||
responseAdaptor(api, payload, query, request, response) {
|
||||
if (response.data.detail == '登录验证失败或已失效,请重新登录') {
|
||||
window.location.href = '/LittlePaimon/login'
|
||||
@ -24,51 +27,67 @@ responseAdaptor(api, payload, query, request, response) {
|
||||
}
|
||||
return payload
|
||||
},
|
||||
'''
|
||||
"""
|
||||
|
||||
icon_path = 'https://s1.ax1x.com/2023/02/05/pS62DJK.png'
|
||||
icon_path = "https://s1.ax1x.com/2023/02/05/pS62DJK.png"
|
||||
|
||||
|
||||
@DRIVER.on_startup
|
||||
def init_web():
|
||||
app: FastAPI = nonebot.get_app()
|
||||
app.include_router(BaseApiRouter)
|
||||
static_dir = os.path.join(os.path.dirname(__file__), "static")
|
||||
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
||||
logger.info(
|
||||
'Web UI',
|
||||
f'<g>启用成功</g>,默认地址为<m>http://127.0.0.1:{DRIVER.config.port}/LittlePaimon/login</m>',
|
||||
"Web UI",
|
||||
f"<g>启用成功</g>,默认地址为<m>http://127.0.0.1:{DRIVER.config.port}/LittlePaimon/login</m>",
|
||||
)
|
||||
|
||||
@app.get('/LittlePaimon/admin', response_class=HTMLResponse)
|
||||
@app.get("/res/history@latest")
|
||||
async def redirect_history():
|
||||
return RedirectResponse("/static/history.production.min.js", status_code=302)
|
||||
|
||||
@app.get("/res/{path:path}")
|
||||
async def redirect(path: str):
|
||||
resource_name= path.split("/")[-1]
|
||||
return RedirectResponse(
|
||||
f"/static/{resource_name}", status_code=302
|
||||
)
|
||||
|
||||
@app.get("/LittlePaimon/admin", response_class=HTMLResponse)
|
||||
async def admin():
|
||||
if config.admin_enable:
|
||||
return admin_app.render(
|
||||
site_title='LittlePaimon 后台管理',
|
||||
site_title="LittlePaimon 后台管理",
|
||||
site_icon=icon_path,
|
||||
theme=config.admin_theme,
|
||||
cdn="/res",
|
||||
requestAdaptor=requestAdaptor,
|
||||
responseAdaptor=responseAdaptor,
|
||||
)
|
||||
else:
|
||||
return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
|
||||
return blank_page.render(site_title="LittlePaimon", site_icon=icon_path)
|
||||
|
||||
@app.get('/LittlePaimon/login', response_class=HTMLResponse)
|
||||
@app.get("/LittlePaimon/login", response_class=HTMLResponse)
|
||||
async def login():
|
||||
if config.admin_enable:
|
||||
return login_page.render(
|
||||
site_title='登录 | LittlePaimon 后台管理',
|
||||
site_title="登录 | LittlePaimon 后台管理",
|
||||
site_icon=icon_path,
|
||||
cdn="/res",
|
||||
theme=config.admin_theme,
|
||||
)
|
||||
else:
|
||||
return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
|
||||
return blank_page.render(site_title="LittlePaimon", site_icon=icon_path)
|
||||
|
||||
@app.get('/LittlePaimon/cookie', response_class=HTMLResponse)
|
||||
@app.get("/LittlePaimon/cookie", response_class=HTMLResponse)
|
||||
async def bind_cookie():
|
||||
if config.CookieWeb_enable:
|
||||
return bind_cookie_page.render(
|
||||
site_title='绑定Cookie | LittlePaimon',
|
||||
site_title="绑定Cookie | LittlePaimon",
|
||||
site_icon=icon_path,
|
||||
cdn="/res",
|
||||
theme=config.admin_theme,
|
||||
)
|
||||
else:
|
||||
return blank_page.render(site_title='LittlePaimon', site_icon=icon_path)
|
||||
return blank_page.render(site_title="LittlePaimon", site_icon=icon_path)
|
||||
|
291
LittlePaimon/web/static/ang.css
Normal file
291
LittlePaimon/web/static/ang.css
Normal file
File diff suppressed because one or more lines are too long
56113
LittlePaimon/web/static/helper.css
Normal file
56113
LittlePaimon/web/static/helper.css
Normal file
File diff suppressed because it is too large
Load Diff
2
LittlePaimon/web/static/history.production.min.js
vendored
Normal file
2
LittlePaimon/web/static/history.production.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2404
LittlePaimon/web/static/iconfont.css
Normal file
2404
LittlePaimon/web/static/iconfont.css
Normal file
File diff suppressed because one or more lines are too long
290
LittlePaimon/web/static/sdk.css
Normal file
290
LittlePaimon/web/static/sdk.css
Normal file
File diff suppressed because one or more lines are too long
3610
LittlePaimon/web/static/sdk.js
Normal file
3610
LittlePaimon/web/static/sdk.js
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
11932
LittlePaimon/web/static/vue.js
Normal file
11932
LittlePaimon/web/static/vue.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user