Add customizable tabular data exports
This commit is contained in:
1 parent
5d5781e707
commit
3e6cd85662
15 files changed
+312
-40
No files matched your search
@@ -2,6 +2,7 @@
|
||||
import { useI18n } from 'vue-i18n'
|
||||
const { t } = useI18n()
|
||||
import ArchiveDialog from '../components/ArchiveDialog.vue'
|
||||
import CustomExportDialog from '../components/CustomExportDialog.vue'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { Document, Download, Plus, Refresh, Search, Upload } from '@element-plus/icons-vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
@@ -242,7 +243,16 @@ async function downloadTemplate() {
|
||||
}
|
||||
}
|
||||
|
||||
async function exportRows() {
|
||||
const exportDialog = ref<InstanceType<typeof CustomExportDialog>>()
|
||||
|
||||
async function openExportDialog() {
|
||||
try {
|
||||
const { data } = await http.get<string[]>(`/base-data/${active.value}/export-columns`)
|
||||
exportDialog.value?.open(data, title.value)
|
||||
} catch (error) { ElMessage.error(apiErrorMessage(error)) }
|
||||
}
|
||||
|
||||
async function exportRows(columns: number[], filename: string, format: string) {
|
||||
try {
|
||||
const params = active.value === 'classes'
|
||||
? {
|
||||
@@ -265,7 +275,8 @@ async function exportRows() {
|
||||
await downloadApiFile(
|
||||
`/base-data/${active.value}/export`,
|
||||
`${title.value}.xlsx`,
|
||||
{ params },
|
||||
{ params: { ...params, columns: columns.join(','), format } },
|
||||
filename,
|
||||
)
|
||||
ElMessage.success(t('baseData.exported', { title: title.value }))
|
||||
} catch (error) {
|
||||
@@ -469,7 +480,7 @@ watch(
|
||||
<template v-if="canManage">
|
||||
<el-button :icon="Document" @click="downloadTemplate">{{ t('businessLabels.downloadTemplate') }}</el-button>
|
||||
<el-button :icon="Upload" :loading="importing" @click="chooseImportFile">{{ t('baseData.excelImport') }}</el-button>
|
||||
<el-button :icon="Download" @click="exportRows">{{ t('baseData.export') }}</el-button>
|
||||
<el-button :icon="Download" @click="openExportDialog">{{ t('baseData.export') }}</el-button>
|
||||
<input
|
||||
ref="fileInput"
|
||||
class="visually-hidden"
|
||||
@@ -715,5 +726,6 @@ watch(
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
<CustomExportDialog ref="exportDialog" @export="exportRows" />
|
||||
<ArchiveDialog ref="archiveDialog" @changed="archiveSelection = []; load()" />
|
||||
</template>
|
||||
Reference in new issue
Block a user