mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-09 01:36:57 +08:00
feat: export
This commit is contained in:
+1
-2
@@ -2,7 +2,7 @@ from fastapi import APIRouter
|
||||
|
||||
from apps.system.api import login, user, aimodel
|
||||
from apps.settings.api import terminology
|
||||
from apps.datasource.api import datasource, export
|
||||
from apps.datasource.api import datasource
|
||||
from apps.chat.api import chat
|
||||
from apps.dashboard.api import dashboard_api
|
||||
|
||||
@@ -12,6 +12,5 @@ api_router.include_router(user.router)
|
||||
api_router.include_router(aimodel.router)
|
||||
api_router.include_router(terminology.router)
|
||||
api_router.include_router(datasource.router)
|
||||
api_router.include_router(export.router)
|
||||
api_router.include_router(chat.router)
|
||||
api_router.include_router(dashboard_api.router)
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
# Author: Junjun
|
||||
# Date: 2025/6/24
|
||||
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from fastapi import APIRouter
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
|
||||
from common.core.deps import SessionDep
|
||||
|
||||
router = APIRouter(tags=["export"], prefix="/export")
|
||||
|
||||
|
||||
@router.get("/png")
|
||||
async def export(session: SessionDep):
|
||||
user_data_dir = tempfile.mkdtemp()
|
||||
|
||||
options = Options()
|
||||
options.add_argument(f"--user-data-dir={user_data_dir}")
|
||||
options.add_argument("--no-sandbox")
|
||||
options.add_argument("--disable-dev-shm-usage")
|
||||
options.add_argument("--headless")
|
||||
service = Service(executable_path='/root/sqlbot/chromedriver-linux64/chromedriver')
|
||||
driver = webdriver.Chrome(service=service, options=options) # 或者使用webdriver.Firefox()等
|
||||
print('init done')
|
||||
# 打开网页
|
||||
driver.get('https://g2.antv.antgroup.com/examples/general/pie/#pie-base')
|
||||
driver.set_window_size(width=1920, height=1080)
|
||||
|
||||
# 等待页面加载完成(根据需要调整时间)
|
||||
|
||||
try:
|
||||
# 等待直到某个元素加载完成,例如某个具体的元素或者某个时间(例如10秒)
|
||||
print("started driver")
|
||||
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "canvas")))
|
||||
except:
|
||||
print("Timeout")
|
||||
|
||||
# 获取整个页面的截图并保存为图片文件
|
||||
driver.save_screenshot('screenshot.png')
|
||||
|
||||
# 关闭浏览器
|
||||
driver.quit()
|
||||
@@ -35,8 +35,6 @@ dependencies = [
|
||||
"oracledb (>=3.1.1,<4.0.0)",
|
||||
"pyyaml (>=6.0.2,<7.0.0)",
|
||||
"fastapi-mcp (>=0.3.4,<0.4.0)",
|
||||
"selenium (>=4.33.0,<5.0.0)",
|
||||
"pillow (>=11.2.1,<12.0.0)",
|
||||
]
|
||||
[[tool.uv.index]]
|
||||
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
|
||||
|
||||
@@ -19,5 +19,4 @@ export const datasourceApi = {
|
||||
saveTable: (data: any) => request.post('/datasource/editTable', data),
|
||||
saveField: (data: any) => request.post('/datasource/editField', data),
|
||||
getDs: (id: number) => request.post(`/datasource/get/${id}`),
|
||||
exportFromServer: () => request.get('/export/png'),
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
@click="editDs(undefined)"
|
||||
>{{ t('ds.add') }}</el-button
|
||||
>
|
||||
<el-button class="border-radius_8" type="primary" :icon="IconOpeAdd" @click="exportPng"
|
||||
>export</el-button
|
||||
>
|
||||
</div>
|
||||
|
||||
<div class="connections-container">
|
||||
@@ -78,17 +75,6 @@ const allDsList = ref<any>([]) // all ds list
|
||||
const router = useRouter()
|
||||
const loading = ref(false)
|
||||
|
||||
const exportPng = () => {
|
||||
datasourceApi
|
||||
.exportFromServer()
|
||||
.then(() => {
|
||||
console.log('export success')
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
})
|
||||
}
|
||||
|
||||
function searchHandle() {
|
||||
if (searchValue.value) {
|
||||
dsList.value = JSON.parse(JSON.stringify(allDsList.value)).filter((item: any) => {
|
||||
|
||||
Reference in New Issue
Block a user