|
1 | 1 | <script lang="ts" setup> |
2 | | -import { ref, computed, onMounted } from 'vue' |
| 2 | +import { ref, computed, onMounted, reactive } from 'vue' |
3 | 3 | import { datasourceApi } from '@/api/datasource' |
4 | 4 | import icon_right_outlined from '@/assets/svg/icon_right_outlined.svg' |
5 | 5 | import icon_form_outlined from '@/assets/svg/icon_form_outlined.svg' |
@@ -67,11 +67,32 @@ const currentTable = ref<any>({}) |
67 | 67 | const ds = ref<any>({}) |
68 | 68 | const btnSelect = ref('d') |
69 | 69 |
|
| 70 | +const pageInfo = reactive({ |
| 71 | + currentPage: 1, |
| 72 | + pageSize: 10, |
| 73 | + total: 0, |
| 74 | +}) |
| 75 | +
|
| 76 | +const handleSizeChange = (val: number) => { |
| 77 | + pageInfo.currentPage = 1 |
| 78 | + pageInfo.pageSize = val |
| 79 | +} |
| 80 | +const handleCurrentChange = (val: number) => { |
| 81 | + pageInfo.currentPage = val |
| 82 | +} |
| 83 | +
|
| 84 | +const fieldListComputed = computed(() => { |
| 85 | + const { currentPage, pageSize } = pageInfo |
| 86 | + return fieldList.value.slice((currentPage - 1) * pageSize, currentPage * pageSize) |
| 87 | +}) |
| 88 | +
|
70 | 89 | const init = () => { |
71 | 90 | initLoading.value = true |
72 | 91 | datasourceApi.getDs(props.info.id).then((res) => { |
73 | 92 | ds.value = res |
74 | 93 | fieldList.value = [] |
| 94 | + pageInfo.total = 0 |
| 95 | + pageInfo.currentPage = 1 |
75 | 96 | datasourceApi.tableList(props.info.id).then((res) => { |
76 | 97 | tableList.value = res |
77 | 98 | initLoading.value = false |
@@ -104,6 +125,8 @@ const clickTable = (table: any) => { |
104 | 125 | .fieldList(table.id) |
105 | 126 | .then((res) => { |
106 | 127 | fieldList.value = res |
| 128 | + pageInfo.total = res.length |
| 129 | + pageInfo.currentPage = 1 |
107 | 130 | datasourceApi.previewData(props.info.id, buildData()).then((res) => { |
108 | 131 | previewData.value = res |
109 | 132 | }) |
@@ -191,6 +214,8 @@ const btnSelectClick = (val: any) => { |
191 | 214 | .fieldList(currentTable.value.id) |
192 | 215 | .then((res) => { |
193 | 216 | fieldList.value = res |
| 217 | + pageInfo.total = res.length |
| 218 | + pageInfo.currentPage = 1 |
194 | 219 | }) |
195 | 220 | .finally(() => { |
196 | 221 | loading.value = false |
@@ -308,41 +333,66 @@ const btnSelectClick = (val: any) => { |
308 | 333 | </div> |
309 | 334 |
|
310 | 335 | <div class="preview-or-schema"> |
311 | | - <el-table v-if="btnSelect === 'd'" :data="fieldList" style="width: 100%"> |
312 | | - <el-table-column prop="field_name" :label="t('datasource.field_name')" width="180" /> |
313 | | - <el-table-column prop="field_type" :label="t('datasource.field_type')" width="180" /> |
314 | | - <el-table-column prop="field_comment" :label="t('datasource.field_original_notes')" /> |
315 | | - <el-table-column :label="t('datasource.field_notes_1')"> |
316 | | - <template #default="scope"> |
317 | | - <div class="field-comment"> |
318 | | - <span :title="scope.row.custom_comment" class="notes-in_table">{{ |
319 | | - scope.row.custom_comment |
320 | | - }}</span> |
321 | | - <el-tooltip |
322 | | - :offset="14" |
323 | | - effect="dark" |
324 | | - :content="$t('datasource.edit')" |
325 | | - placement="top" |
326 | | - > |
327 | | - <el-icon class="action-btn" size="16" @click="editField(scope.row)"> |
328 | | - <edit></edit> |
329 | | - </el-icon> |
330 | | - </el-tooltip> |
331 | | - </div> |
332 | | - </template> |
333 | | - </el-table-column> |
334 | | - <el-table-column :label="t('datasource.enabled_status')" width="180"> |
335 | | - <template #default="scope"> |
336 | | - <div style="display: flex; align-items: center"> |
337 | | - <el-switch |
338 | | - v-model="scope.row.checked" |
339 | | - size="small" |
340 | | - @change="changeStatus(scope.row)" |
341 | | - /> |
342 | | - </div> |
343 | | - </template> |
344 | | - </el-table-column> |
345 | | - </el-table> |
| 336 | + <div class="table-content_preview"> |
| 337 | + <el-table v-if="btnSelect === 'd'" :data="fieldListComputed" style="width: 100%"> |
| 338 | + <el-table-column |
| 339 | + prop="field_name" |
| 340 | + :label="t('datasource.field_name')" |
| 341 | + width="180" |
| 342 | + /> |
| 343 | + <el-table-column |
| 344 | + prop="field_type" |
| 345 | + :label="t('datasource.field_type')" |
| 346 | + width="180" |
| 347 | + /> |
| 348 | + <el-table-column |
| 349 | + prop="field_comment" |
| 350 | + :label="t('datasource.field_original_notes')" |
| 351 | + /> |
| 352 | + <el-table-column :label="t('datasource.field_notes_1')"> |
| 353 | + <template #default="scope"> |
| 354 | + <div class="field-comment"> |
| 355 | + <span :title="scope.row.custom_comment" class="notes-in_table">{{ |
| 356 | + scope.row.custom_comment |
| 357 | + }}</span> |
| 358 | + <el-tooltip |
| 359 | + :offset="14" |
| 360 | + effect="dark" |
| 361 | + :content="$t('datasource.edit')" |
| 362 | + placement="top" |
| 363 | + > |
| 364 | + <el-icon class="action-btn" size="16" @click="editField(scope.row)"> |
| 365 | + <edit></edit> |
| 366 | + </el-icon> |
| 367 | + </el-tooltip> |
| 368 | + </div> |
| 369 | + </template> |
| 370 | + </el-table-column> |
| 371 | + <el-table-column :label="t('datasource.enabled_status')" width="180"> |
| 372 | + <template #default="scope"> |
| 373 | + <div style="display: flex; align-items: center"> |
| 374 | + <el-switch |
| 375 | + v-model="scope.row.checked" |
| 376 | + size="small" |
| 377 | + @change="changeStatus(scope.row)" |
| 378 | + /> |
| 379 | + </div> |
| 380 | + </template> |
| 381 | + </el-table-column> |
| 382 | + </el-table> |
| 383 | + </div> |
| 384 | + <div v-if="fieldList.length" class="pagination-container"> |
| 385 | + <el-pagination |
| 386 | + v-model:current-page="pageInfo.currentPage" |
| 387 | + v-model:page-size="pageInfo.pageSize" |
| 388 | + :page-sizes="[10, 20, 30]" |
| 389 | + :background="true" |
| 390 | + layout="total, sizes, prev, pager, next, jumper" |
| 391 | + :total="pageInfo.total" |
| 392 | + @size-change="handleSizeChange" |
| 393 | + @current-change="handleCurrentChange" |
| 394 | + /> |
| 395 | + </div> |
346 | 396 | <template v-else> |
347 | 397 | <div class="preview-num"> |
348 | 398 | {{ t('ds.pieces_in_total', { msg: total, ms: showNum }) }} |
@@ -588,7 +638,17 @@ const btnSelectClick = (val: any) => { |
588 | 638 | .preview-or-schema { |
589 | 639 | margin-top: 16px; |
590 | 640 | height: calc(100% - 50px); |
591 | | - overflow-y: auto; |
| 641 | +
|
| 642 | + .table-content_preview { |
| 643 | + max-height: calc(100% - 50px); |
| 644 | + overflow-y: auto; |
| 645 | + margin-bottom: 16px; |
| 646 | + } |
| 647 | +
|
| 648 | + .pagination-container { |
| 649 | + display: flex; |
| 650 | + justify-content: flex-end; |
| 651 | + } |
592 | 652 |
|
593 | 653 | .field-comment { |
594 | 654 | display: flex; |
|
0 commit comments