mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-08-10 20: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:
parent
7bf5bcc461
commit
ce13f82ec7
@ -1,6 +1,6 @@
|
||||
import { showNotification } from '@/utils/ADempiere/notification.js'
|
||||
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 ROUTES from '@/utils/ADempiere/constants/zoomWindow'
|
||||
import relationsMixin from './relationsMixin.js'
|
||||
@ -342,11 +342,17 @@ export default {
|
||||
// TODO: Check usage as the selection is exported with the table menu
|
||||
list = this.getDataSelection
|
||||
}
|
||||
|
||||
let title = this.metadataMenu.name
|
||||
if (this.isEmptyValue(title)) {
|
||||
title = this.$route.meta.title
|
||||
}
|
||||
|
||||
const data = this.formatJson(filterVal, list)
|
||||
exportFileFromJson({
|
||||
header: tHeader,
|
||||
data,
|
||||
filename: '',
|
||||
fileName: `${title} ${clientDateTime()}`,
|
||||
exportType: fotmatToExport
|
||||
})
|
||||
},
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { supportedTypes, exportFileFromJson, exportFileZip } from '@/utils/ADempiere/exportUtil.js'
|
||||
import { recursiveTreeSearch } from '@/utils/ADempiere/valueUtils.js'
|
||||
import { supportedTypes, exportFileFromJson, exportZipFile } from '@/utils/ADempiere/exportUtil.js'
|
||||
import { clientDateTime, recursiveTreeSearch } from '@/utils/ADempiere/valueUtils.js'
|
||||
import { FIELDS_QUANTITY } from '@/utils/ADempiere/references'
|
||||
import TableMixin from '@/components/ADempiere/DataTable/mixin/tableMixin.js'
|
||||
|
||||
@ -197,28 +197,48 @@ export default {
|
||||
list = this.getDataSelection
|
||||
}
|
||||
|
||||
let title = this.panelMetadata.name
|
||||
if (this.isEmptyValue(title)) {
|
||||
title = this.$route.meta.title
|
||||
}
|
||||
|
||||
const data = this.formatJson(filterVal, list)
|
||||
exportFileFromJson({
|
||||
header,
|
||||
data,
|
||||
filename: '',
|
||||
fileName: `${title} ${clientDateTime()}`,
|
||||
exportType: formatToExport
|
||||
})
|
||||
|
||||
this.closeMenu()
|
||||
},
|
||||
exporZipRecordTable() {
|
||||
/**
|
||||
* Export records as .txt into compressed .zip file
|
||||
*/
|
||||
exporZipRecordTable({
|
||||
recordContexMenu = false
|
||||
}) {
|
||||
const header = this.getterFieldsListHeader
|
||||
const filterVal = this.getterFieldsListValue
|
||||
let list = this.getDataSelection
|
||||
if (this.getDataSelection.length <= 0) {
|
||||
list = this.recordsData
|
||||
}
|
||||
if (recordContexMenu) {
|
||||
list = [this.currentRow]
|
||||
}
|
||||
const data = this.formatJson(filterVal, list)
|
||||
exportFileZip({
|
||||
|
||||
let title = this.panelMetadata.name
|
||||
if (this.isEmptyValue(title)) {
|
||||
title = this.$route.meta.title
|
||||
}
|
||||
|
||||
exportZipFile({
|
||||
header,
|
||||
data,
|
||||
title: this.$route.meta.title,
|
||||
exportType: 'zip'
|
||||
txtName: title,
|
||||
zipName: `${title} ${clientDateTime()}`
|
||||
})
|
||||
},
|
||||
formatJson(filterVal, jsonData) {
|
||||
|
@ -18,6 +18,13 @@
|
||||
{{ format }}
|
||||
</el-menu-item>
|
||||
</el-submenu>
|
||||
<el-menu-item
|
||||
@click="exporZipRecordTable({
|
||||
recordContexMenu: true
|
||||
})"
|
||||
>
|
||||
{{ $t('table.dataTable.exportZip') }}
|
||||
</el-menu-item>
|
||||
<el-menu-item
|
||||
v-if="panelType === 'window'"
|
||||
index="delete"
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { export_json_to_excel } from '@/vendor/Export2Excel'
|
||||
import { export_txt_to_zip } from '@/vendor/Export2Zip'
|
||||
import language from '@/lang'
|
||||
import { convertBooleanToTranslationLang } from '@/utils/ADempiere/valueFormat.js'
|
||||
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
|
||||
|
||||
export const reportFormatsList = [
|
||||
'ps',
|
||||
@ -29,26 +31,28 @@ export const supportedTypes = {
|
||||
* @param {array} header
|
||||
* @param {array} data
|
||||
* @param {string} exportType, supportedTypes array
|
||||
* @param {string} fileName .xlsx file name
|
||||
*/
|
||||
export function exportFileFromJson({
|
||||
header,
|
||||
data,
|
||||
exportType
|
||||
exportType,
|
||||
fileName = ''
|
||||
}) {
|
||||
const Json = data.map(dataJson => {
|
||||
Object.keys(dataJson).forEach(key => {
|
||||
if (typeof dataJson[key] === 'boolean') {
|
||||
dataJson[key] = dataJson[key]
|
||||
? language.t('components.switchActiveText')
|
||||
: language.t('components.switchInactiveText')
|
||||
const jsonData = data.map(row => {
|
||||
Object.keys(row).forEach(column => {
|
||||
if (typeof row[column] === 'boolean') {
|
||||
row[column] = convertBooleanToTranslationLang(row[column])
|
||||
}
|
||||
})
|
||||
return dataJson
|
||||
|
||||
return row
|
||||
})
|
||||
|
||||
export_json_to_excel({
|
||||
header: header,
|
||||
data: Json,
|
||||
filename: '',
|
||||
header,
|
||||
data: jsonData,
|
||||
filename: fileName,
|
||||
bookType: exportType
|
||||
})
|
||||
}
|
||||
@ -58,27 +62,35 @@ export function exportFileFromJson({
|
||||
* @autor Edwin Betancourt <EdwinBetanc0urt@outlook.com>
|
||||
* @param {array} header
|
||||
* @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,
|
||||
data,
|
||||
title
|
||||
txtName = '',
|
||||
zipName = ''
|
||||
}) {
|
||||
const Json = data.map(dataJson => {
|
||||
Object.keys(dataJson).forEach(key => {
|
||||
if (typeof dataJson[key] === 'boolean') {
|
||||
dataJson[key] = dataJson[key]
|
||||
? language.t('components.switchActiveText')
|
||||
: language.t('components.switchInactiveText')
|
||||
const jsonData = data.map(row => {
|
||||
Object.keys(row).forEach(column => {
|
||||
if (typeof row[column] === 'boolean') {
|
||||
row[column] = convertBooleanToTranslationLang(row[column])
|
||||
}
|
||||
})
|
||||
return dataJson
|
||||
return row
|
||||
})
|
||||
|
||||
if (isEmptyValue(zipName)) {
|
||||
zipName = txtName
|
||||
}
|
||||
if (isEmptyValue(txtName)) {
|
||||
txtName = zipName
|
||||
}
|
||||
|
||||
export_txt_to_zip(
|
||||
header,
|
||||
Json,
|
||||
title
|
||||
jsonData,
|
||||
txtName,
|
||||
zipName
|
||||
)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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
|
||||
import moment from 'moment'
|
||||
import language from '@/lang'
|
||||
import { isEmptyValue } from '@/utils/ADempiere/valueUtils.js'
|
||||
import store from '@/store'
|
||||
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'
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param {object} object, object to convert
|
||||
|
Loading…
x
Reference in New Issue
Block a user