Bläddra i källkod

新增前端静态文件挂载

mrh 9 månader sedan
förälder
incheckning
37110e06bb

+ 10 - 2
ui/backend/main.py

@@ -1,4 +1,5 @@
 import asyncio
+import os
 from pathlib import Path
 import sys
 # 为了避免耦合,微服务,可能确实要将上级的上级目录作为一个单独的进程来处理,此目录作为一个单独的UI项目
@@ -8,9 +9,11 @@ from routers.proxy import router,sub_mgr
 from routers.file import router as file_router
 from routers.worker import router as worker_router
 from fastapi.middleware.cors import CORSMiddleware
+from fastapi.staticfiles import StaticFiles
+from fastapi.responses import FileResponse, JSONResponse
 from contextlib import asynccontextmanager
 from utils.process_mgr import process_manager
-from utils.config import config,WORKER_DIR_BASE
+from utils.config import config,WORKER_DIR_BASE,APP_PATH
 from src.services.celery_worker import CeleryWorker,celery_worker
 from utils.logu import get_logger,logger
 
@@ -46,11 +49,16 @@ app.add_middleware(
     allow_methods=["*"],  # 允许所有方法(GET, POST, PUT, DELETE 等)
     allow_headers=["*"],  # 允许所有头部
 )
-
+app.mount("/assets", StaticFiles(directory=APP_PATH.parent / "fontend/dist/assets"), name="assets")
+# app.mount("/assets", StaticFiles(directory=APP_PATH.parent / "fontend/dist/assets"), name="assets")
 # 将 gpt_router 挂载到应用中
 app.include_router(router, prefix="/api/proxy", tags=["chat"])
 app.include_router(worker_router, prefix="/api/worker", tags=["worker"])
 
+@app.get("/")
+async def homepage():
+    return FileResponse(APP_PATH.parent / "fontend/dist" / 'index.html')
+
 if __name__ == "__main__":
     import uvicorn
     # 注意: 由于涉及到多进程管理机制,因此不能使用 reload 。例如 uvicorn main:app --port 5835 --reload

+ 0 - 2
ui/fontend/src/components.d.ts

@@ -16,7 +16,6 @@ declare module 'vue' {
     ElDescriptions: typeof import('element-plus/es')['ElDescriptions']
     ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem']
     ElDialog: typeof import('element-plus/es')['ElDialog']
-    ElDivider: typeof import('element-plus/es')['ElDivider']
     ElIcon: typeof import('element-plus/es')['ElIcon']
     ElInput: typeof import('element-plus/es')['ElInput']
     ElLink: typeof import('element-plus/es')['ElLink']
@@ -24,7 +23,6 @@ declare module 'vue' {
     ElMenu: typeof import('element-plus/es')['ElMenu']
     ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
     ElRadio: typeof import('element-plus/es')['ElRadio']
-    ElRadioButton: typeof import('element-plus/es')['ElRadioButton']
     ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']
     ElRow: typeof import('element-plus/es')['ElRow']
     ElSpace: typeof import('element-plus/es')['ElSpace']

+ 0 - 11
ui/fontend/src/components/Home.vue

@@ -149,17 +149,6 @@ const fetchTaskStatistics = async () => {
   }
 }
 
-// 定义上传结果
-const uploadResult = ref<{
-  name: string;
-  size: number;
-  uploadTime: string;
-  total_keywords?: number;
-  inserted_count?: number;
-  success?: boolean;
-  error?: string;
-} | null>(null)
-
 // 获取 worker endpoint
 const fetchWorkerEndpoint = async () => {
   try {

+ 4 - 2
ui/fontend/src/components/Proxy.vue

@@ -62,8 +62,10 @@ const get_sys_proxy = async () => {
   }
 }
 
-const proxy_change = (value: string) => {
-  store.setSelectedProxy(value)
+const proxy_change = (value: string | number | boolean | undefined) => {
+  if (value !== undefined) {
+    store.setSelectedProxy(String(value))
+  }
 }
 </script>
 

+ 1 - 1
ui/fontend/src/stores/proxyStore.ts

@@ -85,7 +85,7 @@ export const useProxyStore = defineStore('proxy', () => {
     return data
   }
 
-  function setSelectedProxy(choice: string) {
+  function setSelectedProxy(choice: string ) {
     selectedProxy.value = choice
     localStorage.setItem('selectedProxy', choice)
   }