Skip to content

Commit 4ff9511

Browse files
committed
feat: export
1 parent 82c9b44 commit 4ff9511

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

backend/apps/api.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22

33
from apps.system.api import login, user, aimodel
44
from apps.settings.api import terminology
5-
from apps.datasource.api import datasource
5+
from apps.datasource.api import datasource, export
66
from apps.chat.api import chat
77
from apps.dashboard.api import dashboard_api
88

9-
109
api_router = APIRouter()
1110
api_router.include_router(login.router)
1211
api_router.include_router(user.router)
1312
api_router.include_router(aimodel.router)
1413
api_router.include_router(terminology.router)
1514
api_router.include_router(datasource.router)
15+
api_router.include_router(export.router)
1616
api_router.include_router(chat.router)
1717
api_router.include_router(dashboard_api.router)
18-
19-
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Author: Junjun
2+
# Date: 2025/6/24
3+
4+
import time
5+
6+
from fastapi import APIRouter
7+
from selenium import webdriver
8+
from selenium.webdriver.common.by import By
9+
from selenium.webdriver.support import expected_conditions as EC
10+
from selenium.webdriver.support.ui import WebDriverWait
11+
12+
from common.core.deps import SessionDep
13+
14+
router = APIRouter(tags=["export"], prefix="/export")
15+
16+
17+
@router.get("/png")
18+
async def export(session: SessionDep):
19+
driver = webdriver.Chrome() # 或者使用webdriver.Firefox()等
20+
print('init done')
21+
# 打开网页
22+
driver.get('https://g2.antv.antgroup.com/examples/general/interval/#bar-basic')
23+
driver.set_window_size(width=1920, height=1080)
24+
25+
# 等待页面加载完成(根据需要调整时间)
26+
27+
try:
28+
# 等待直到某个元素加载完成,例如某个具体的元素或者某个时间(例如10秒)
29+
print("started driver")
30+
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "canvas")))
31+
time.sleep(2)
32+
except:
33+
print("Timeout")
34+
35+
# 获取整个页面的截图并保存为图片文件
36+
driver.save_screenshot('screenshot.png')
37+
38+
# 关闭浏览器
39+
driver.quit()

backend/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ dependencies = [
3535
"oracledb (>=3.1.1,<4.0.0)",
3636
"pyyaml (>=6.0.2,<7.0.0)",
3737
"fastapi-mcp (>=0.3.4,<0.4.0)",
38+
"selenium (>=4.33.0,<5.0.0)",
39+
"pillow (>=11.2.1,<12.0.0)",
3840
]
3941
[[tool.uv.index]]
4042
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"

frontend/src/api/datasource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export const datasourceApi = {
1919
saveTable: (data: any) => request.post('/datasource/editTable', data),
2020
saveField: (data: any) => request.post('/datasource/editField', data),
2121
getDs: (id: number) => request.post(`/datasource/get/${id}`),
22+
exportFromServer: () => request.get('/export/png'),
2223
}

frontend/src/views/ds/index.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
@click="editDs(undefined)"
2626
>{{ t('ds.add') }}</el-button
2727
>
28+
<el-button class="border-radius_8" type="primary" :icon="IconOpeAdd" @click="exportPng"
29+
>export</el-button
30+
>
2831
</div>
2932

3033
<div class="connections-container">
@@ -75,6 +78,17 @@ const allDsList = ref<any>([]) // all ds list
7578
const router = useRouter()
7679
const loading = ref(false)
7780
81+
const exportPng = () => {
82+
datasourceApi
83+
.exportFromServer()
84+
.then(() => {
85+
console.log('export success')
86+
})
87+
.catch((e) => {
88+
console.log(e)
89+
})
90+
}
91+
7892
function searchHandle() {
7993
if (searchValue.value) {
8094
dsList.value = JSON.parse(JSON.stringify(allDsList.value)).filter((item: any) => {

0 commit comments

Comments
 (0)