Skip to content

Commit 1252559

Browse files
committed
feat(Data Source): add Table relationship management
1 parent 9db73d3 commit 1252559

File tree

7 files changed

+543
-7
lines changed

7 files changed

+543
-7
lines changed

frontend/src/api/datasource.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { request } from '@/utils/request'
33
export const datasourceApi = {
44
check: (data: any) => request.post('/datasource/check', data),
55
check_by_id: (id: any) => request.get(`/datasource/check/${id}`),
6+
relationGet: (id: any) => request.post(`/table_relation/get/${id}`),
7+
relationSave: (dsId: any, data: any) => request.post(`/table_relation/save/${dsId}`, data),
68
add: (data: any) => request.post('/datasource/add', data),
79
list: () => request.get('/datasource/list'),
810
update: (data: any) => request.post('/datasource/update', data),
Lines changed: 6 additions & 0 deletions
Loading

frontend/src/i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"AI Model Configuration": "AI Model Configuration"
88
},
99
"training": {
10+
"add_it_here": "Drag the table name on the left to add it here",
11+
"table_relationship_management": "Table relationship management",
1012
"system_anagement": "System Management",
1113
"data_training": "SQL Sample Lib",
1214
"problem_description": "Problem Description",
@@ -669,4 +671,4 @@
669671
"setting_successfully": "Setting Successfully",
670672
"customize_theme_color": "Customize theme color"
671673
}
672-
}
674+
}

frontend/src/i18n/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"AI Model Configuration": "模型配置"
88
},
99
"training": {
10+
"add_it_here": "拖拽左侧表名,添加到这里",
11+
"table_relationship_management": "表关系管理",
1012
"system_anagement": "系统管理",
1113
"data_training": "SQL 示例库",
1214
"problem_description": "问题描述",
@@ -669,4 +671,4 @@
669671
"setting_successfully": "设置成功",
670672
"customize_theme_color": "自定义主题色"
671673
}
672-
}
674+
}

frontend/src/views/chat/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ const scrollBottom = () => {
514514
if (!isTyping.value && !getRecommendQuestionsLoading.value) {
515515
clearInterval(scrollTime)
516516
}
517+
if (!chatListRef.value) {
518+
clearInterval(scrollTime)
519+
return
520+
}
517521
chatListRef.value!.setScrollTop(innerRef.value!.clientHeight)
518522
}
519523

frontend/src/views/ds/DataTable.vue

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import EmptyBackground from '@/views/dashboard/common/EmptyBackground.vue'
88
import edit from '@/assets/svg/icon_edit_outlined.svg'
99
import { useI18n } from 'vue-i18n'
1010
import ParamsForm from './ParamsForm.vue'
11-
11+
import TableRelationship from '@/views/ds/TableRelationship.vue'
12+
import icon_mindnote_outlined from '@/assets/svg/icon_mindnote_outlined.svg'
1213
interface Table {
1314
name: string
1415
host: string
@@ -54,6 +55,7 @@ const paramsFormRef = ref()
5455
const tableList = ref([] as any[])
5556
const loading = ref(false)
5657
const initLoading = ref(false)
58+
const activeRelationship = ref(false)
5759
const keywords = ref('')
5860
const tableListWithSearch = computed(() => {
5961
if (!keywords.value) return tableList.value
@@ -66,13 +68,29 @@ const showNum = ref(100)
6668
const currentTable = ref<any>({})
6769
const ds = ref<any>({})
6870
const btnSelect = ref('d')
69-
71+
const isDrag = ref(false)
72+
const tableName = ref<any[]>([])
7073
const pageInfo = reactive({
7174
currentPage: 1,
7275
pageSize: 10,
7376
total: 0,
7477
})
78+
const handleRelationship = () => {
79+
activeRelationship.value = !activeRelationship.value
80+
currentTable.value = {}
81+
}
82+
const singleDragStartD = (e: DragEvent, ele: any) => {
83+
isDrag.value = true
84+
e.dataTransfer!.setData('table', JSON.stringify(ele))
85+
}
7586
87+
const getTableName = (val: any) => {
88+
tableName.value = val
89+
}
90+
91+
const singleDragEnd = () => {
92+
isDrag.value = false
93+
}
7694
const handleSizeChange = (val: number) => {
7795
pageInfo.currentPage = 1
7896
pageInfo.pageSize = val
@@ -119,6 +137,7 @@ const handleSelectTableList = () => {
119137
}
120138
121139
const clickTable = (table: any) => {
140+
if (activeRelationship.value) return
122141
loading.value = true
123142
currentTable.value = table
124143
fieldList.value = []
@@ -290,8 +309,14 @@ const btnSelectClick = (val: any) => {
290309
<div
291310
v-for="ele in tableListWithSearch"
292311
:key="ele.table_name"
312+
:draggable="activeRelationship && !tableName.includes(ele.id)"
293313
class="model"
294-
:class="currentTable.table_name === ele.table_name && 'isActive'"
314+
@dragstart="($event: any) => singleDragStartD($event, ele)"
315+
@dragend="singleDragEnd"
316+
:class="[
317+
currentTable.table_name === ele.table_name && 'isActive',
318+
tableName.includes(ele.id) && activeRelationship && 'disabled-table',
319+
]"
295320
:title="ele.table_name"
296321
@click="clickTable(ele)"
297322
>
@@ -318,9 +343,32 @@ const btnSelectClick = (val: any) => {
318343
</div>
319344
</div>
320345
</div>
346+
<div class="table-relationship">
347+
<div @click="handleRelationship" :class="activeRelationship && 'active'" class="btn">
348+
<el-icon size="16">
349+
<icon_mindnote_outlined></icon_mindnote_outlined>
350+
</el-icon>
351+
{{ t('training.table_relationship_management') }}
352+
</div>
353+
</div>
354+
</div>
355+
356+
<div v-if="activeRelationship" class="relationship-content">
357+
<div class="title">{{ t('training.table_relationship_management') }}</div>
358+
<div class="content">
359+
<TableRelationship
360+
@getTableName="getTableName"
361+
:dragging="isDrag"
362+
:id="info.id"
363+
></TableRelationship>
364+
</div>
321365
</div>
322366

323-
<div v-if="currentTable.table_name" v-loading="loading" class="info-table">
367+
<div
368+
v-if="currentTable.table_name && !activeRelationship"
369+
v-loading="loading"
370+
class="info-table"
371+
>
324372
<div class="table-name">
325373
<div class="name">{{ currentTable.table_name }}</div>
326374
<div class="notes">
@@ -336,6 +384,7 @@ const btnSelectClick = (val: any) => {
336384
</el-tooltip>
337385
</div>
338386
</div>
387+
339388
<div class="table-content">
340389
<div class="btn-select">
341390
<el-button
@@ -532,6 +581,46 @@ const btnSelectClick = (val: any) => {
532581
padding: 8px 16px;
533582
height: 100%;
534583
border-right: 1px solid #1f232926;
584+
.table-relationship {
585+
height: 56px;
586+
width: 100%;
587+
display: flex;
588+
align-items: center;
589+
margin-top: 20px;
590+
position: relative;
591+
592+
&::after {
593+
content: '';
594+
width: calc(100% + 32px);
595+
position: absolute;
596+
left: -16px;
597+
background-color: #1f232926;
598+
top: 0;
599+
height: 1px;
600+
}
601+
602+
.btn {
603+
width: 248px;
604+
height: 32px;
605+
cursor: pointer;
606+
border-radius: 6px;
607+
display: flex;
608+
align-items: center;
609+
padding-left: 8px;
610+
.ed-icon {
611+
color: #646a73;
612+
margin-right: 8px;
613+
}
614+
615+
&.active {
616+
color: var(--ed-color-primary);
617+
.ed-icon {
618+
color: var(--ed-color-primary);
619+
}
620+
background-color: var(--ed-color-primary-1a);
621+
}
622+
}
623+
}
535624
.select-table_top {
536625
height: 40px;
537626
display: flex;
@@ -551,7 +640,7 @@ const btnSelectClick = (val: any) => {
551640
}
552641
553642
.list-content {
554-
height: calc(100% - 100px);
643+
height: calc(100% - 156px);
555644
.no-result {
556645
margin-top: 72px;
557646
font-weight: 400;
@@ -569,6 +658,12 @@ const btnSelectClick = (val: any) => {
569658
border-radius: 4px;
570659
cursor: pointer;
571660
661+
&.disabled-table {
662+
background: #dee0e3 !important;
663+
color: #646a73;
664+
cursor: not-allowed;
665+
}
666+
572667
.name {
573668
margin-left: 8px;
574669
font-weight: 500;
@@ -604,6 +699,27 @@ const btnSelectClick = (val: any) => {
604699
}
605700
}
606701
}
702+
.relationship-content {
703+
position: absolute;
704+
right: 0;
705+
top: 0;
706+
width: calc(100% - 280px);
707+
height: 100%;
708+
709+
.content {
710+
height: calc(100% - 56px);
711+
width: 100%;
712+
}
713+
714+
.title {
715+
height: 56px;
716+
padding-left: 24px;
717+
line-height: 56px;
718+
font-weight: 500;
719+
font-size: 16px;
720+
border-bottom: 1px solid #1f232926;
721+
}
722+
}
607723
.info-table {
608724
position: absolute;
609725
right: 0;

0 commit comments

Comments
 (0)