refactor(page): refactor source --> metadata --> table export

This commit is contained in:
qianmoQ 2024-11-15 09:48:43 +08:00
parent 852d0bbc3c
commit c3ba6048a3
7 changed files with 71 additions and 82 deletions

View File

@ -44,10 +44,10 @@ public class TableController
return this.service.fetchData(code, configure); return this.service.fetchData(code, configure);
} }
@PostMapping(value = "export/{id}") @PostMapping(value = "export/{code}")
public CommonResponse exportDataById(@PathVariable Long id, @RequestBody ExportBody configure) public CommonResponse exportDataByCode(@PathVariable String code, @RequestBody ExportBody configure)
{ {
return this.service.exportDataById(id, configure); return this.service.exportDataByCode(code, configure);
} }
@GetMapping(value = "dataDownload/{username}/{filename}") @GetMapping(value = "dataDownload/{username}/{filename}")

View File

@ -19,6 +19,7 @@ public interface TableService
*/ */
CommonResponse<List<TableEntity>> getAllByDatabase(String code); CommonResponse<List<TableEntity>> getAllByDatabase(String code);
/** /**
* Retrieves data from the database based on the provided ID and table filter. * Retrieves data from the database based on the provided ID and table filter.
* *
@ -35,7 +36,7 @@ public interface TableService
* @param configure the export configuration * @param configure the export configuration
* @return the response containing the exported data * @return the response containing the exported data
*/ */
CommonResponse exportDataById(Long id, ExportBody configure); CommonResponse exportDataByCode(String code, ExportBody configure);
Object dataDownload(String username, String filename); Object dataDownload(String username, String filename);

View File

@ -135,12 +135,12 @@ public class TableServiceImpl
} }
@Override @Override
public CommonResponse exportDataById(Long id, ExportBody configure) public CommonResponse exportDataByCode(String code, ExportBody configure)
{ {
TableEntity table = this.repository.findById(id) TableEntity table = this.repository.findByCode(code)
.orElse(null); .orElse(null);
if (table == null) { if (table == null) {
return CommonResponse.failure(String.format("Table [ %s ] not found", id)); return CommonResponse.failure(String.format("Table [ %s ] not found", code));
} }
SourceEntity source = table.getDatabase().getSource(); SourceEntity source = table.getDatabase().getSource();

View File

@ -42,23 +42,18 @@
</div> </div>
</ShadcnContextMenuItem> </ShadcnContextMenuItem>
</ShadcnContextMenuSub> </ShadcnContextMenuSub>
<ShadcnContextMenuSub v-if="dataInfo?.level === StructureEnum.TABLE" :label="$t('source.common.menuExport')">
<ShadcnContextMenuItem @click="visibleExportData(true)">
<div class="flex items-center space-x-1">
<ShadcnIcon icon="ArrowUpFromLine" size="15"/>
<span>{{ $t('source.common.exportData') }}</span>
</div>
</ShadcnContextMenuItem>
</ShadcnContextMenuSub>
</ShadcnContextMenu> </ShadcnContextMenu>
</div> </div>
</ShadcnCard> </ShadcnCard>
<!-- <DropdownMenuGroup v-if="dataInfo?.level === StructureEnum.TABLE">-->
<!-- <DropdownMenuSub>-->
<!-- <DropdownMenuSubTrigger class="cursor-pointer">{{ $t('source.common.menuExport') }}</DropdownMenuSubTrigger>-->
<!-- <DropdownMenuPortal>-->
<!-- <DropdownMenuSubContent>-->
<!-- <DropdownMenuItem v-if="dataInfo?.level === StructureEnum.TABLE" class="cursor-pointer" @click="handlerExportData(true)">-->
<!-- <ArrowUpFromLine :size="18" class="mr-2"/>-->
<!-- {{ $t('source.common.exportData') }}-->
<!-- </DropdownMenuItem>-->
<!-- </DropdownMenuSubContent>-->
<!-- </DropdownMenuPortal>-->
<!-- </DropdownMenuSub>-->
<!-- </DropdownMenuGroup>-->
<!-- <DropdownMenuSeparator/>--> <!-- <DropdownMenuSeparator/>-->
<!-- <DropdownMenuItem v-if="dataInfo?.level === StructureEnum.TABLE" class="cursor-pointer" @click="handlerTruncateTable(true)">--> <!-- <DropdownMenuItem v-if="dataInfo?.level === StructureEnum.TABLE" class="cursor-pointer" @click="handlerTruncateTable(true)">-->
<!-- <Trash :size="18" class="mr-2"/>--> <!-- <Trash :size="18" class="mr-2"/>-->
@ -88,7 +83,11 @@
:info="dataInfo" :info="dataInfo"
@close="visibleCreateColumn(false)"/> @close="visibleCreateColumn(false)"/>
<!-- <TableExport v-if="tableExportVisible" :isVisible="tableExportVisible" :info="dataInfo" @close="handlerExportData(false)"/>--> <TableExport v-if="tableExportVisible"
:isVisible="tableExportVisible"
:info="dataInfo"
@close="visibleExportData(false)"/>
<!-- <TableTruncate v-if="tableTruncateVisible" :isVisible="tableTruncateVisible" :info="dataInfo" @close="handlerTruncateTable(false)"/>--> <!-- <TableTruncate v-if="tableTruncateVisible" :isVisible="tableTruncateVisible" :info="dataInfo" @close="handlerTruncateTable(false)"/>-->
<!-- <TableDrop v-if="tableDropVisible" :isVisible="tableDropVisible" :info="dataInfo" @close="handlerDropTable(false)"/>--> <!-- <TableDrop v-if="tableDropVisible" :isVisible="tableDropVisible" :info="dataInfo" @close="handlerDropTable(false)"/>-->
<!-- <ColumnChange v-if="columnChangeVisible" :isVisible="columnChangeVisible" :info="dataInfo" @close="handlerChangeColumn(false)"/>--> <!-- <ColumnChange v-if="columnChangeVisible" :isVisible="columnChangeVisible" :info="dataInfo" @close="handlerChangeColumn(false)"/>-->
@ -255,7 +254,7 @@ export default defineComponent({
{ {
this.columnCreateVisible = opened this.columnCreateVisible = opened
}, },
handlerExportData(opened: boolean) visibleExportData(opened: boolean)
{ {
this.tableExportVisible = opened this.tableExportVisible = opened
}, },

View File

@ -1,4 +1,4 @@
<template>dd <template>
<ShadcnModal v-model="visible" <ShadcnModal v-model="visible"
height="80%" height="80%"
width="40%" width="40%"
@ -92,13 +92,13 @@
</ShadcnCol> </ShadcnCol>
</ShadcnRow> </ShadcnRow>
<div class="space-x-2"> <ShadcnSpace>
<ShadcnButton type="default" @click="onCancel">{{ $t('common.cancel') }}</ShadcnButton> <ShadcnButton type="default" @click="onCancel">{{ $t('common.cancel') }}</ShadcnButton>
<ShadcnButton submit :loading="loading" :disabled="loading"> <ShadcnButton submit :loading="loading" :disabled="loading">
{{ $t('common.save') }} {{ $t('common.save') }}
</ShadcnButton> </ShadcnButton>
</div> </ShadcnSpace>
</ShadcnForm> </ShadcnForm>
</ShadcnModal> </ShadcnModal>
</template> </template>

View File

@ -123,13 +123,13 @@
</ShadcnCol> </ShadcnCol>
</ShadcnRow> </ShadcnRow>
<div class="space-x-2"> <ShadcnSpace>
<ShadcnButton type="default" @click="onCancel">{{ $t('common.cancel') }}</ShadcnButton> <ShadcnButton type="default" @click="onCancel">{{ $t('common.cancel') }}</ShadcnButton>
<ShadcnButton submit :loading="loading" :disabled="loading"> <ShadcnButton submit :loading="loading" :disabled="loading">
{{ $t('common.save') }} {{ $t('common.save') }}
</ShadcnButton> </ShadcnButton>
</div> </ShadcnSpace>
</ShadcnForm> </ShadcnForm>
</ShadcnModal> </ShadcnModal>
</template> </template>

View File

@ -1,51 +1,38 @@
<template> <template>
<Dialog :is-visible="visible" :title="title as string"> <ShadcnModal v-model="visible"
<div class="grid w-full grid-cols-2 gap-4 pt-1 pl-3 pr-3"> height="33%"
<FormField name="format"> width="40%"
<FormItem class="space-y-2"> :title="title"
<FormLabel>{{ $t('source.common.exportDataFormat') }}</FormLabel> @on-close="onCancel">
<FormMessage/> <ShadcnForm v-model="formState" v-if="formState" @on-submit="onSubmit">
<RadioGroup v-model="formState.format" :default-value="formState.format"> <ShadcnFormItem name="format" :label="$t('source.common.exportDataFormat')">
<div class="flex items-center space-x-2"> <ShadcnRadioGroup v-model="formState.format" name="format">
<RadioGroupItem id="CSV" value="CSV"/> <ShadcnRadio value="CSV">CSV</ShadcnRadio>
<Label for="CSV">CSV</Label> </ShadcnRadioGroup>
</div> </ShadcnFormItem>
</RadioGroup>
</FormItem> <ShadcnFormItem name="count" :label="$t('source.common.exportDataCount')">
</FormField> <ShadcnNumber v-model="formState.count" name="count"/>
<FormField name="count"> </ShadcnFormItem>
<FormItem class="space-y-1">
<FormLabel>{{ $t('source.common.exportDataCount') }}</FormLabel> <ShadcnFormItem name="path" :label="$t('source.common.downloadPath')">
<FormMessage/>
<Input v-model="formState.count" :default-value="formState.count" type="number"/>
</FormItem>
</FormField>
</div>
<div v-if="formState.path" class="grid w-full pt-1 pl-3 pr-3">
<FormField name="path">
<FormItem class="space-y-1">
<FormLabel>{{ $t('source.common.downloadPath') }}</FormLabel>
<FormMessage/>
<div class="flex items-center space-x-1"> <div class="flex items-center space-x-1">
<Input :default-value="formState.path"/> <ShadcnInput v-model="formState.path" disabled="" name="path"/>
<Button size="sm" @click="handlerDownload()"> <ShadcnButton :disabled="!formState.path" @click="onDownload()">
{{ $t('source.common.downloadFile') }} {{ $t('source.common.downloadFile') }}
</Button> </ShadcnButton>
</div> </div>
</FormItem> </ShadcnFormItem>
</FormField>
</div> <ShadcnSpace>
<template #footer> <ShadcnButton type="default" @click="onCancel">{{ $t('common.cancel') }}</ShadcnButton>
<div class="space-x-5">
<Button variant="outline" size="sm" @click="handlerCancel"> <ShadcnButton submit :loading="loading" :disabled="loading">
{{ $t('common.cancel') }} {{ $t('common.save') }}
</Button> </ShadcnButton>
<Button size="sm" :loading="loading" :disabled="loading" @click="handlerSave()"> </ShadcnSpace>
{{ $t('source.common.exportData') }} </ShadcnForm>
</Button> </ShadcnModal>
</div>
</template>
</Dialog>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -53,7 +40,6 @@ import { defineComponent } from 'vue'
import { StructureModel } from '@/model/structure.ts' import { StructureModel } from '@/model/structure.ts'
import TableService from '@/services/table' import TableService from '@/services/table'
import { TableExportModel, TableExportRequest } from '@/model/table' import { TableExportModel, TableExportRequest } from '@/model/table'
import { toNumber } from 'lodash'
export default defineComponent({ export default defineComponent({
name: 'TableExport', name: 'TableExport',
@ -89,33 +75,36 @@ export default defineComponent({
{ {
this.formState = TableExportRequest.of() this.formState = TableExportRequest.of()
if (this.info) { if (this.info) {
this.title = this.$t('source.common.exportDataTable').replace('$VALUE', this.info.title as string) this.title = this.$t('source.common.exportDataTable').replace('$VALUE', String(this.info.title))
} }
}, },
methods: { methods: {
handlerSave() onSubmit()
{ {
if (this.info) { if (this.info) {
this.loading = true this.loading = true
TableService.exportData(toNumber(this.info.applyId), this.formState) TableService.exportData(String(this.info.value), this.formState)
.then(response => { .then(response => {
if (response.status) { if (response.status) {
this.formState.path = response.data this.formState.path = response.data
} }
else { else {
ToastUtils.error(response.message) this.$Message.error({
content: response.message,
showIcon: true
})
} }
}) })
.finally(() => this.loading = false) .finally(() => this.loading = false)
} }
}, },
handlerDownload() onDownload()
{ {
if (this.formState) { if (this.formState) {
window.open(this.formState.path, '_target') window.open(this.formState.path, '_target')
} }
}, },
handlerCancel() onCancel()
{ {
this.visible = false this.visible = false
} }