mirror of
https://gitee.com/devlive-community/datacap.git
synced 2024-11-30 02:57:37 +08:00
refactor(page): refactor source --> metadata --> table export
This commit is contained in:
parent
852d0bbc3c
commit
c3ba6048a3
@ -44,10 +44,10 @@ public class TableController
|
||||
return this.service.fetchData(code, configure);
|
||||
}
|
||||
|
||||
@PostMapping(value = "export/{id}")
|
||||
public CommonResponse exportDataById(@PathVariable Long id, @RequestBody ExportBody configure)
|
||||
@PostMapping(value = "export/{code}")
|
||||
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}")
|
||||
|
@ -19,6 +19,7 @@ public interface TableService
|
||||
*/
|
||||
CommonResponse<List<TableEntity>> getAllByDatabase(String code);
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @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);
|
||||
|
||||
|
@ -135,12 +135,12 @@ public class TableServiceImpl
|
||||
}
|
||||
|
||||
@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);
|
||||
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();
|
||||
|
@ -42,23 +42,18 @@
|
||||
</div>
|
||||
</ShadcnContextMenuItem>
|
||||
</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>
|
||||
</div>
|
||||
</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/>-->
|
||||
<!-- <DropdownMenuItem v-if="dataInfo?.level === StructureEnum.TABLE" class="cursor-pointer" @click="handlerTruncateTable(true)">-->
|
||||
<!-- <Trash :size="18" class="mr-2"/>-->
|
||||
@ -88,7 +83,11 @@
|
||||
:info="dataInfo"
|
||||
@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)"/>-->
|
||||
<!-- <TableDrop v-if="tableDropVisible" :isVisible="tableDropVisible" :info="dataInfo" @close="handlerDropTable(false)"/>-->
|
||||
<!-- <ColumnChange v-if="columnChangeVisible" :isVisible="columnChangeVisible" :info="dataInfo" @close="handlerChangeColumn(false)"/>-->
|
||||
@ -255,7 +254,7 @@ export default defineComponent({
|
||||
{
|
||||
this.columnCreateVisible = opened
|
||||
},
|
||||
handlerExportData(opened: boolean)
|
||||
visibleExportData(opened: boolean)
|
||||
{
|
||||
this.tableExportVisible = opened
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
<template>dd
|
||||
<template>
|
||||
<ShadcnModal v-model="visible"
|
||||
height="80%"
|
||||
width="40%"
|
||||
@ -92,13 +92,13 @@
|
||||
</ShadcnCol>
|
||||
</ShadcnRow>
|
||||
|
||||
<div class="space-x-2">
|
||||
<ShadcnSpace>
|
||||
<ShadcnButton type="default" @click="onCancel">{{ $t('common.cancel') }}</ShadcnButton>
|
||||
|
||||
<ShadcnButton submit :loading="loading" :disabled="loading">
|
||||
{{ $t('common.save') }}
|
||||
</ShadcnButton>
|
||||
</div>
|
||||
</ShadcnSpace>
|
||||
</ShadcnForm>
|
||||
</ShadcnModal>
|
||||
</template>
|
||||
|
@ -123,13 +123,13 @@
|
||||
</ShadcnCol>
|
||||
</ShadcnRow>
|
||||
|
||||
<div class="space-x-2">
|
||||
<ShadcnSpace>
|
||||
<ShadcnButton type="default" @click="onCancel">{{ $t('common.cancel') }}</ShadcnButton>
|
||||
|
||||
<ShadcnButton submit :loading="loading" :disabled="loading">
|
||||
{{ $t('common.save') }}
|
||||
</ShadcnButton>
|
||||
</div>
|
||||
</ShadcnSpace>
|
||||
</ShadcnForm>
|
||||
</ShadcnModal>
|
||||
</template>
|
||||
|
@ -1,51 +1,38 @@
|
||||
<template>
|
||||
<Dialog :is-visible="visible" :title="title as string">
|
||||
<div class="grid w-full grid-cols-2 gap-4 pt-1 pl-3 pr-3">
|
||||
<FormField name="format">
|
||||
<FormItem class="space-y-2">
|
||||
<FormLabel>{{ $t('source.common.exportDataFormat') }}</FormLabel>
|
||||
<FormMessage/>
|
||||
<RadioGroup v-model="formState.format" :default-value="formState.format">
|
||||
<div class="flex items-center space-x-2">
|
||||
<RadioGroupItem id="CSV" value="CSV"/>
|
||||
<Label for="CSV">CSV</Label>
|
||||
</div>
|
||||
</RadioGroup>
|
||||
</FormItem>
|
||||
</FormField>
|
||||
<FormField name="count">
|
||||
<FormItem class="space-y-1">
|
||||
<FormLabel>{{ $t('source.common.exportDataCount') }}</FormLabel>
|
||||
<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">
|
||||
<Input :default-value="formState.path"/>
|
||||
<Button size="sm" @click="handlerDownload()">
|
||||
{{ $t('source.common.downloadFile') }}
|
||||
</Button>
|
||||
</div>
|
||||
</FormItem>
|
||||
</FormField>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="space-x-5">
|
||||
<Button variant="outline" size="sm" @click="handlerCancel">
|
||||
{{ $t('common.cancel') }}
|
||||
</Button>
|
||||
<Button size="sm" :loading="loading" :disabled="loading" @click="handlerSave()">
|
||||
{{ $t('source.common.exportData') }}
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</Dialog>
|
||||
<ShadcnModal v-model="visible"
|
||||
height="33%"
|
||||
width="40%"
|
||||
:title="title"
|
||||
@on-close="onCancel">
|
||||
<ShadcnForm v-model="formState" v-if="formState" @on-submit="onSubmit">
|
||||
<ShadcnFormItem name="format" :label="$t('source.common.exportDataFormat')">
|
||||
<ShadcnRadioGroup v-model="formState.format" name="format">
|
||||
<ShadcnRadio value="CSV">CSV</ShadcnRadio>
|
||||
</ShadcnRadioGroup>
|
||||
</ShadcnFormItem>
|
||||
|
||||
<ShadcnFormItem name="count" :label="$t('source.common.exportDataCount')">
|
||||
<ShadcnNumber v-model="formState.count" name="count"/>
|
||||
</ShadcnFormItem>
|
||||
|
||||
<ShadcnFormItem name="path" :label="$t('source.common.downloadPath')">
|
||||
<div class="flex items-center space-x-1">
|
||||
<ShadcnInput v-model="formState.path" disabled="" name="path"/>
|
||||
<ShadcnButton :disabled="!formState.path" @click="onDownload()">
|
||||
{{ $t('source.common.downloadFile') }}
|
||||
</ShadcnButton>
|
||||
</div>
|
||||
</ShadcnFormItem>
|
||||
|
||||
<ShadcnSpace>
|
||||
<ShadcnButton type="default" @click="onCancel">{{ $t('common.cancel') }}</ShadcnButton>
|
||||
|
||||
<ShadcnButton submit :loading="loading" :disabled="loading">
|
||||
{{ $t('common.save') }}
|
||||
</ShadcnButton>
|
||||
</ShadcnSpace>
|
||||
</ShadcnForm>
|
||||
</ShadcnModal>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
@ -53,7 +40,6 @@ import { defineComponent } from 'vue'
|
||||
import { StructureModel } from '@/model/structure.ts'
|
||||
import TableService from '@/services/table'
|
||||
import { TableExportModel, TableExportRequest } from '@/model/table'
|
||||
import { toNumber } from 'lodash'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'TableExport',
|
||||
@ -89,33 +75,36 @@ export default defineComponent({
|
||||
{
|
||||
this.formState = TableExportRequest.of()
|
||||
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: {
|
||||
handlerSave()
|
||||
onSubmit()
|
||||
{
|
||||
if (this.info) {
|
||||
this.loading = true
|
||||
TableService.exportData(toNumber(this.info.applyId), this.formState)
|
||||
TableService.exportData(String(this.info.value), this.formState)
|
||||
.then(response => {
|
||||
if (response.status) {
|
||||
this.formState.path = response.data
|
||||
}
|
||||
else {
|
||||
ToastUtils.error(response.message)
|
||||
this.$Message.error({
|
||||
content: response.message,
|
||||
showIcon: true
|
||||
})
|
||||
}
|
||||
})
|
||||
.finally(() => this.loading = false)
|
||||
}
|
||||
},
|
||||
handlerDownload()
|
||||
onDownload()
|
||||
{
|
||||
if (this.formState) {
|
||||
window.open(this.formState.path, '_target')
|
||||
}
|
||||
},
|
||||
handlerCancel()
|
||||
onCancel()
|
||||
{
|
||||
this.visible = false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user