55 <el-button text :icon =" ArrowLeft" @click =" back()" />
66 {{ props.dsName }}
77 </div >
8- <el-button type =" primary" @click =" save()" >
9- Save
10- </el-button >
118 </el-row >
12- <el-row class =" data" >
13- <el-table-v2
14- :columns =" tableColumns"
15- :data =" tableData"
16- :width =" 1000"
17- :height =" 800"
18- fixed
19- />
9+ <el-row class =" container" >
10+ <el-col :span =" 4" >
11+ Tables
12+ <el-input v-model =" searchValue" />
13+ <div >
14+ <div v-for =" item in tableList" class =" table-item" @click =" clickTable(item)" >{{ item.table_name }}</div >
15+ </div >
16+ </el-col >
17+ <el-col :span =" 20" >
18+ <div v-if =" fieldList.length === 0" >No data</div >
19+ <div v-else >
20+ <div style =" display : flex ;justify-content : space-between ;align-items : center ;" >
21+ <div style =" display : flex ;justify-content : start ;align-items : center ;" >
22+ <span >{{ currentTable.table_name }}</span >
23+ <span >  ; |  ; </span >
24+ <span >
25+ <el-input v-model =" currentTable.custom_comment" />
26+ </span >
27+ </div >
28+ <el-button type =" primary" @click =" save()" >
29+ Save
30+ </el-button >
31+ </div >
32+ <el-tabs v-model =" activeName" class =" demo-tabs" @tab-click =" handleClick" >
33+ <el-tab-pane label =" Table Schema" name =" schema" >
34+ <el-table :data =" fieldList" style =" width : 100% " >
35+ <el-table-column prop =" field_name" label =" Name" width =" 180" />
36+ <el-table-column prop =" field_type" label =" Type" width =" 180" />
37+ <el-table-column prop =" field_comment" label =" Comment" />
38+ <el-table-column label =" Custom Comment" >
39+ <template #default =" scope " >
40+ <div style =" display : flex ; align-items : center " >
41+ <el-input v-model =" scope.row.custom_comment" />
42+ </div >
43+ </template >
44+ </el-table-column >
45+ <el-table-column label =" Status" width =" 180" >
46+ <template #default =" scope " >
47+ <div style =" display : flex ; align-items : center " >
48+ <el-switch
49+ v-model =" scope.row.checked"
50+ size =" small"
51+ />
52+ </div >
53+ </template >
54+ </el-table-column >
55+ </el-table >
56+ </el-tab-pane >
57+ <el-tab-pane label =" Preview" name =" preview" >
58+ <div >Preview 100 items</div >
59+ <el-table :data =" previewData.data" style =" width : 100% ;height : 600px ;" >
60+ <el-table-column v-for =" c in previewData.fields" :prop =" c" :label =" c" />
61+ </el-table >
62+ </el-tab-pane >
63+ </el-tabs >
64+ </div >
65+ </el-col >
2066 </el-row >
21- <el-drawer
22- v-model =" drawer"
23- direction =" btt"
24- :destroy-on-close =" true"
25- :close-on-click-modal =" false"
26- size =" 80%"
27- >
28- <template #header >
29- <div >Detail</div >
30- </template >
31- <template #default >
32- <el-row :gutter =" 20" >
33- <el-table-v2
34- :columns =" fieldColumns"
35- :data =" fieldData"
36- :width =" 1000"
37- :height =" 800"
38- fixed
39- />
40- </el-row >
41- </template >
42- <template #footer >
43- <div style =" flex : auto " >
44- <el-button @click =" cancelClick" >Cancel</el-button >
45- <el-button type =" primary" @click =" confirmClick" >Confirm</el-button >
46- </div >
47- </template >
48- </el-drawer >
4967 </div >
5068</template >
5169
5270<script lang="tsx" setup>
5371import { ref } from ' vue'
5472import { datasourceApi } from ' @/api/datasource'
55- import { ElButton } from ' element-plus'
56- import { h } from ' vue'
5773import { onMounted } from ' vue'
5874import { ArrowLeft } from ' @element-plus/icons-vue'
75+ import type { TabsPaneContext } from ' element-plus'
5976
6077const props = defineProps ({
6178 dsId: { type: [Number ], required: true },
6279 dsName: { type: [String ], required: true }
6380})
6481
65- const drawer = ref <boolean >(false )
66- const tableColumns = ref <any >([
67- {
68- key:" tableName" ,
69- dataKey:" tableName" ,
70- title: ' Table Name' ,
71- width: 150 ,
72- },
73- {
74- key:" tableComment" ,
75- dataKey:" tableComment" ,
76- title: ' Table Comment' ,
77- width: 300 ,
78- },
79- {
80- key: ' operations' ,
81- title: ' Operations' ,
82- cellRenderer : ({ rowData }: { rowData: any }) => {
83- return h (ElButton ,{
84- onClick : () => showFields (rowData .tableName )
85- }," Show Fields" )
86- },
87- width: 150 ,
88- align: ' center' ,
89- }
90- ])
91- const tableData = ref <any >([])
92- const fieldColumns = ref <any >([
93- {
94- key:" fieldName" ,
95- dataKey:" fieldName" ,
96- title: ' Field Name' ,
97- width: 150 ,
98- },
99- {
100- key:" fieldType" ,
101- dataKey:" fieldType" ,
102- title: ' Field Type' ,
103- width: 150 ,
104- },
105- {
106- key:" fieldComment" ,
107- dataKey:" fieldComment" ,
108- title: ' Field Comment' ,
109- width: 300 ,
110- }
111- ])
112- const fieldData = ref <any >([])
11382const dsId = ref <Number >(0 )
83+ const searchValue = ref (' ' )
84+ const tableList = ref <any >([])
85+ const currentTable = ref <any >({})
86+ const fieldList = ref <any >([])
87+ const previewData = ref <any >({})
88+
89+ const activeName = ref (' schema' )
90+
91+ const buildData = () => {
92+ return {" table" : currentTable .value , " fields" : fieldList .value }
93+ }
11494
11595const back = () => {
11696 history .back ()
11797}
11898
11999const save = () => {
120-
121- }
122-
123- const showFields = (tableName : string ) => {
124- drawer .value = true
125- datasourceApi .getFields (dsId .value , tableName ).then ((res ) => {
126- fieldData .value = res
100+ datasourceApi .edit (buildData ()).then (() => {
101+ ElMessage ({
102+ message: ' Save success' ,
103+ type: ' success' ,
104+ showClose: true
105+ })
127106 })
128107}
129108
130- const cancelClick = () => {
131- drawer .value = false
109+ const clickTable = (table : any ) => {
110+ currentTable .value = table
111+ datasourceApi .fieldList (table .id ).then ((res ) => {
112+ fieldList .value = res
113+ datasourceApi .previewData (dsId .value , buildData ()).then ((res ) => {
114+ previewData .value = res
115+ })
116+ })
132117}
133118
134- const confirmClick = () => {
135- // save something
136- cancelClick ()
119+ const handleClick = (tab : TabsPaneContext ) => {
120+ if (tab .paneName === ' preview' ) {
121+ datasourceApi .previewData (dsId .value , buildData ()).then ((res ) => {
122+ previewData .value = res
123+ })
124+ }
137125}
138126
139127onMounted (() => {
140128 dsId .value = props .dsId
141- datasourceApi .getTables (props .dsId ).then ((res ) => {
142- tableData .value = res
129+ fieldList .value = []
130+ datasourceApi .tableList (props .dsId ).then ((res ) => {
131+ tableList .value = res
143132 })
144133})
145-
146- defineExpose ({ open })
147134 </script >
148135
149136<style lang="less" scoped>
@@ -158,5 +145,11 @@ defineExpose({ open })
158145 display : flex ;
159146 align-items : center ;
160147 }
148+ .container {
149+ height : 100% ;
150+ .table-item {
151+ margin : 10px ;
152+ }
153+ }
161154}
162155 </style >
0 commit comments