Skip to content

Commit 7567c1e

Browse files
committed
refactor: dashboard preview
1 parent 523b74e commit 7567c1e

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed

backend/apps/dashboard/api/dashboard_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
from fastapi import APIRouter, File, UploadFile, HTTPException
33

44
from apps.dashboard.crud.dashboard_service import get_dashboard_list, preview_with_id,create_dashboard
5-
from apps.dashboard.models.dashboard_model import CreateDashboard
5+
from apps.dashboard.models.dashboard_model import CreateDashboard, DashboardResponse
66
from common.core.deps import SessionDep, CurrentUser
7+
from typing import List
78

89
router = APIRouter(tags=["dashboard"], prefix="/dashboard")
910

10-
@router.get("/list")
11+
@router.post("/list", response_model=List[DashboardResponse])
1112
async def datasource_list(session: SessionDep):
1213
return get_dashboard_list(session=session)
1314

backend/apps/dashboard/crud/dashboard_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from select import select
1+
from sqlalchemy import select
22
from apps.dashboard.models.dashboard_model import CoreDashboard, CreateDashboard
33
from common.core.deps import SessionDep, CurrentUser
44
import uuid
55
def get_dashboard_list(session: SessionDep):
6-
statement = select(CoreDashboard).order_by(CoreDashboard.create_time.desc())
6+
statement = select(CoreDashboard)
77
dashboard_list = session.exec(statement).fetchall()
88
return dashboard_list
99

backend/apps/dashboard/models/dashboard_model.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from sqlmodel import SQLModel, Field
22
from sqlalchemy import String, Column, Text, SmallInteger, BigInteger, Integer,DateTime
3+
from typing import Optional
34
from pydantic import BaseModel
4-
from datetime import datetime
5-
65

76
class CoreDashboard(SQLModel, table=True):
87
__tablename__ = "core_dashboard"
9-
108
id: str = Field(
119
sa_column=Column(String(50), nullable=False, primary_key=True)
1210
)
@@ -124,6 +122,37 @@ class CoreDashboard(SQLModel, table=True):
124122
sa_column=Column(String(50), nullable=True)
125123
)
126124

125+
class DashboardResponse(BaseModel):
126+
id: Optional[str] = None
127+
name: Optional[str] = None
128+
pid: Optional[str] = None
129+
workspace_id: Optional[str] = None
130+
org_id: Optional[str] = None
131+
level: Optional[int] = None
132+
node_type: Optional[str] = None
133+
type: Optional[str] = None
134+
canvas_style_data: Optional[str] = None
135+
component_data: Optional[str] = None
136+
mobile_layout: Optional[int] = None
137+
status: Optional[int] = None
138+
self_watermark_status: Optional[int] = None
139+
sort: Optional[int] = None
140+
create_time: Optional[int] = None # 或者用 datetime 类型
141+
create_by: Optional[str] = None
142+
update_time: Optional[int] = None # 或者用 datetime 类型
143+
update_by: Optional[str] = None
144+
remark: Optional[str] = None
145+
source: Optional[str] = None
146+
delete_flag: Optional[int] = None
147+
delete_time: Optional[int] = None
148+
delete_by: Optional[str] = None
149+
version: Optional[int] = None
150+
content_id: Optional[str] = None
151+
check_version: Optional[str] = None
152+
153+
class Config:
154+
orm_mode = True # 允许从 ORM 对象加载
155+
127156
# dashboard create obj
128157
class CreateDashboard(BaseModel):
129158
id: str = ''

backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies = [
3333
"openpyxl (>=3.1.5,<4.0.0)",
3434
"psycopg2-binary (>=2.9.10,<3.0.0)",
3535
"oracledb (>=3.1.1,<4.0.0)",
36-
"pyyaml (>=6.0.2,<7.0.0)"
36+
"pyyaml (>=6.0.2,<7.0.0)",
3737
]
3838
[[tool.uv.index]]
3939
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"

frontend/src/api/dashboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { request } from '@/utils/request'
22

33
export const dashboardApi = {
4-
list: () => request.get('/dashboard/list'),
4+
list: (params: any) => request.post('/dashboard/list',params),
55
getDashboardInfo: (params:any) => request.post(`/dashboard/get_dashboard/${params.id}`,params),
66
sqNameCheck: (data: any) => request.post('/dashboard/name_check',data),
77
moveResource: (data: any) => request.post('/dashboard/move',data),

frontend/src/views/dashboard/common/ResourceTree.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import router from '@/router'
1616
import {dashboardStoreWithOut} from "@/stores/dashboard/dashboard.ts";
1717
import HandleMore from "@/views/dashboard/common/HandleMore.vue";
1818
import ResourceGroupOpt from "@/views/dashboard/common/ResourceGroupOpt.vue";
19+
import {dashboardApi} from "@/api/dashboard.ts";
1920
2021
const dashboardStore = dashboardStoreWithOut()
2122
const resourceGroupOptRef = ref(null)
@@ -115,7 +116,11 @@ const nodeClick = (data: SQTreeNode, node: any) => {
115116
116117
const getTree = async () => {
117118
state.originResourceTree = []
118-
afterTreeInit()
119+
const params = {}
120+
dashboardApi.list(params).then((res: SQTreeNode[]) => {
121+
state.originResourceTree = res?.data || []
122+
afterTreeInit()
123+
})
119124
}
120125
// @ts-ignore
121126
const flattedTree = computed<SQTreeNode[]>(() => {

0 commit comments

Comments
 (0)