1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-11 13:39:48 +08:00

fix: Export record's to zip, xls, json, xml, txt (#666)

* fix: Export record's to zip

* Add Zip export option in the context menu of the table (#8)

Co-authored-by: Elsio Sanchez <elsiosanche@gmail.com>

Co-authored-by: EdwinBetanc0urt <EdwinBetanco0urt@outlook.com>
Co-authored-by: Elsio Sanchez <45974454+elsiosanchez@users.noreply.github.com>
Co-authored-by: Elsio Sanchez <elsiosanche@gmail.com>
This commit is contained in:
Edwin Betancourt 2021-03-12 18:17:44 -04:00 committed by GitHub
parent 7bf5bcc461
commit ce13f82ec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 32 deletions

View File

@ -1,6 +1,6 @@
import { showNotification } from '@/utils/ADempiere/notification.js' import { showNotification } from '@/utils/ADempiere/notification.js'
import ItemsRelations from './itemsRelations' import ItemsRelations from './itemsRelations'
import { convertFieldsListToShareLink, recursiveTreeSearch } from '@/utils/ADempiere/valueUtils.js' import { clientDateTime, convertFieldsListToShareLink, recursiveTreeSearch } from '@/utils/ADempiere/valueUtils.js'
import { supportedTypes, exportFileFromJson } from '@/utils/ADempiere/exportUtil.js' import { supportedTypes, exportFileFromJson } from '@/utils/ADempiere/exportUtil.js'
import ROUTES from '@/utils/ADempiere/constants/zoomWindow' import ROUTES from '@/utils/ADempiere/constants/zoomWindow'
import relationsMixin from './relationsMixin.js' import relationsMixin from './relationsMixin.js'
@ -342,11 +342,17 @@ export default {
// TODO: Check usage as the selection is exported with the table menu // TODO: Check usage as the selection is exported with the table menu
list = this.getDataSelection list = this.getDataSelection
} }
let title = this.metadataMenu.name
if (this.isEmptyValue(title)) {
title = this.$route.meta.title
}
const data = this.formatJson(filterVal, list) const data = this.formatJson(filterVal, list)
exportFileFromJson({ exportFileFromJson({
header: tHeader, header: tHeader,
data, data,
filename: '', fileName: `${title} ${clientDateTime()}`,
exportType: fotmatToExport exportType: fotmatToExport
}) })
}, },

View File

@ -1,5 +1,5 @@
import { supportedTypes, exportFileFromJson, exportFileZip } from '@/utils/ADempiere/exportUtil.js' import { supportedTypes, exportFileFromJson, exportZipFile } from '@/utils/ADempiere/exportUtil.js'
import { recursiveTreeSearch } from '@/utils/ADempiere/valueUtils.js' import { clientDateTime, recursiveTreeSearch } from '@/utils/ADempiere/valueUtils.js'
import { FIELDS_QUANTITY } from '@/utils/ADempiere/references' import { FIELDS_QUANTITY } from '@/utils/ADempiere/references'
import TableMixin from '@/components/ADempiere/DataTable/mixin/tableMixin.js' import TableMixin from '@/components/ADempiere/DataTable/mixin/tableMixin.js'
@ -197,28 +197,48 @@ export default {
list = this.getDataSelection list = this.getDataSelection
} }
let title = this.panelMetadata.name
if (this.isEmptyValue(title)) {
title = this.$route.meta.title
}
const data = this.formatJson(filterVal, list) const data = this.formatJson(filterVal, list)
exportFileFromJson({ exportFileFromJson({
header, header,
data, data,
filename: '', fileName: `${title} ${clientDateTime()}`,
exportType: formatToExport exportType: formatToExport
}) })
this.closeMenu() this.closeMenu()
}, },
exporZipRecordTable() { /**
* Export records as .txt into compressed .zip file
*/
exporZipRecordTable({
recordContexMenu = false
}) {
const header = this.getterFieldsListHeader const header = this.getterFieldsListHeader
const filterVal = this.getterFieldsListValue const filterVal = this.getterFieldsListValue
let list = this.getDataSelection let list = this.getDataSelection
if (this.getDataSelection.length <= 0) { if (this.getDataSelection.length <= 0) {
list = this.recordsData list = this.recordsData
} }
if (recordContexMenu) {
list = [this.currentRow]
}
const data = this.formatJson(filterVal, list) const data = this.formatJson(filterVal, list)
exportFileZip({
let title = this.panelMetadata.name
if (this.isEmptyValue(title)) {
title = this.$route.meta.title
}
exportZipFile({
header, header,
data, data,
title: this.$route.meta.title, txtName: title,
exportType: 'zip' zipName: `${title} ${clientDateTime()}`
}) })
}, },
formatJson(filterVal, jsonData) { formatJson(filterVal, jsonData) {

View File

@ -18,6 +18,13 @@
{{ format }} {{ format }}
</el-menu-item> </el-menu-item>
</el-submenu> </el-submenu>
<el-menu-item
@click="exporZipRecordTable({
recordContexMenu: true
})"
>
{{ $t('table.dataTable.exportZip') }}
</el-menu-item>
<el-menu-item <el-menu-item
v-if="panelType === 'window'" v-if="panelType === 'window'"
index="delete" index="delete"

View File

@ -1,6 +1,8 @@
import { export_json_to_excel } from '@/vendor/Export2Excel' import { export_json_to_excel } from '@/vendor/Export2Excel'
import { export_txt_to_zip } from '@/vendor/Export2Zip' import { export_txt_to_zip } from '@/vendor/Export2Zip'
import language from '@/lang' import language from '@/lang'
import { convertBooleanToTranslationLang } from '@/utils/ADempiere/valueFormat.js'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
export const reportFormatsList = [ export const reportFormatsList = [
'ps', 'ps',
@ -29,26 +31,28 @@ export const supportedTypes = {
* @param {array} header * @param {array} header
* @param {array} data * @param {array} data
* @param {string} exportType, supportedTypes array * @param {string} exportType, supportedTypes array
* @param {string} fileName .xlsx file name
*/ */
export function exportFileFromJson({ export function exportFileFromJson({
header, header,
data, data,
exportType exportType,
fileName = ''
}) { }) {
const Json = data.map(dataJson => { const jsonData = data.map(row => {
Object.keys(dataJson).forEach(key => { Object.keys(row).forEach(column => {
if (typeof dataJson[key] === 'boolean') { if (typeof row[column] === 'boolean') {
dataJson[key] = dataJson[key] row[column] = convertBooleanToTranslationLang(row[column])
? language.t('components.switchActiveText')
: language.t('components.switchInactiveText')
} }
}) })
return dataJson
return row
}) })
export_json_to_excel({ export_json_to_excel({
header: header, header,
data: Json, data: jsonData,
filename: '', filename: fileName,
bookType: exportType bookType: exportType
}) })
} }
@ -58,27 +62,35 @@ export function exportFileFromJson({
* @autor Edwin Betancourt <EdwinBetanc0urt@outlook.com> * @autor Edwin Betancourt <EdwinBetanc0urt@outlook.com>
* @param {array} header * @param {array} header
* @param {array} data * @param {array} data
* @param {string} title * @param {string} txtName .txt text file name
* @param {string} zipName .zip compressed file name
*/ */
export function exportFileZip({ export function exportZipFile({
header, header,
data, data,
title txtName = '',
zipName = ''
}) { }) {
const Json = data.map(dataJson => { const jsonData = data.map(row => {
Object.keys(dataJson).forEach(key => { Object.keys(row).forEach(column => {
if (typeof dataJson[key] === 'boolean') { if (typeof row[column] === 'boolean') {
dataJson[key] = dataJson[key] row[column] = convertBooleanToTranslationLang(row[column])
? language.t('components.switchActiveText')
: language.t('components.switchInactiveText')
} }
}) })
return dataJson return row
}) })
if (isEmptyValue(zipName)) {
zipName = txtName
}
if (isEmptyValue(txtName)) {
txtName = zipName
}
export_txt_to_zip( export_txt_to_zip(
header, header,
Json, jsonData,
title txtName,
zipName
) )
} }

View File

@ -1,6 +1,7 @@
// A util class for handle format for time, date and others values to beused to display information // A util class for handle format for time, date and others values to beused to display information
// Note that this file use moment library for a easy conversion // Note that this file use moment library for a easy conversion
import moment from 'moment' import moment from 'moment'
import language from '@/lang'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js' import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
import store from '@/store' import store from '@/store'
import { DATE, DATE_PLUS_TIME, TIME, AMOUNT, COSTS_PLUS_PRICES, NUMBER, QUANTITY } from '@/utils/ADempiere/references.js' import { DATE, DATE_PLUS_TIME, TIME, AMOUNT, COSTS_PLUS_PRICES, NUMBER, QUANTITY } from '@/utils/ADempiere/references.js'
@ -27,6 +28,18 @@ export const convertBooleanToString = (booleanValue) => {
return 'N' return 'N'
} }
/**
* Convert boolean value to current translation language
* @param {boolean} booleanValue
* @returns {string} true => 'Yes' or 'Si', false => 'Not' or 'No'
*/
export const convertBooleanToTranslationLang = (booleanValue) => {
if (booleanValue || booleanValue === 'true') {
return language.t('components.switchActiveText')
}
return language.t('components.switchInactiveText')
}
/** /**
* Convert a object to array pairs * Convert a object to array pairs
* @param {object} object, object to convert * @param {object} object, object to convert