From 64aaa6012af28ef23d66b1708692d689f3844e40 Mon Sep 17 00:00:00 2001 From: Red-Asuka Date: Sun, 29 Jan 2023 11:14:39 +0800 Subject: [PATCH 1/2] fix(desktop): fix properties not being properly formatted during data import --- src/components/ImportData.vue | 4 +++- src/database/services/ConnectionService.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/ImportData.vue b/src/components/ImportData.vue index 976e6b063..d1d025145 100644 --- a/src/components/ImportData.vue +++ b/src/components/ImportData.vue @@ -318,10 +318,11 @@ export default class ImportData extends Vue { .fromString(data) .subscribe((jsonObj) => { try { - let { messages, subscriptions, will, ...otherProps } = jsonObj + let { messages, subscriptions, properties, will, ...otherProps } = jsonObj // format object messages = JSON.parse(messages) subscriptions = JSON.parse(subscriptions) + properties = JSON.parse(properties) will = JSON.parse(will) Object.keys(otherProps).forEach((item) => { // format boolean @@ -338,6 +339,7 @@ export default class ImportData extends Vue { const oneRealJSONObj = { messages, subscriptions, + properties, will, ...otherProps, } diff --git a/src/database/services/ConnectionService.ts b/src/database/services/ConnectionService.ts index 8106d8b7e..ff16ee251 100644 --- a/src/database/services/ConnectionService.ts +++ b/src/database/services/ConnectionService.ts @@ -355,7 +355,7 @@ export default class ConnectionService { // cascade getAll public async cascadeGetAll(id?: string) { - const query = await this.connectionRepository.createQueryBuilder('cn') + const query = this.connectionRepository.createQueryBuilder('cn') id && query.where('cn.id = :id', { id }) From 0a3f013271b24e88789d36a0eeec50d3474397f7 Mon Sep 17 00:00:00 2001 From: Red-Asuka Date: Sun, 29 Jan 2023 15:15:13 +0800 Subject: [PATCH 2/2] fix(desktop): fix data error when exporting csv file --- src/components/ExportData.vue | 4 +++- src/components/ImportData.vue | 11 ++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/ExportData.vue b/src/components/ExportData.vue index 746f992e2..ec1925d20 100644 --- a/src/components/ExportData.vue +++ b/src/components/ExportData.vue @@ -212,7 +212,9 @@ export default class ExportData extends Vue { } const exportDataToCSV = (jsonContent: ConnectionModel[]) => { try { - const content: string = CSVConvert(jsonContent) + // Prevent CSV from automatically converting string with trailing zeros after decimal point to number. + // https://stackoverflow.com/questions/165042/stop-excel-from-automatically-converting-certain-text-values-to-dates + const content: string = CSVConvert(jsonContent).replace(/"(\d+\.0+)"/g, '="$1"') this.exportDiffFormatData(content, 'CSV') } catch (err) { this.$message.error(err.toString()) diff --git a/src/components/ImportData.vue b/src/components/ImportData.vue index d1d025145..4f23a8bea 100644 --- a/src/components/ImportData.vue +++ b/src/components/ImportData.vue @@ -331,9 +331,14 @@ export default class ImportData extends Vue { } else if (otherProps[item] === 'false') { otherProps[item] = false } else if (this.stringProps.indexOf(item) === -1 && otherProps[item] !== '') { - // format number - const numValue = Number(otherProps[item]) - otherProps[item] = !isNaN(numValue) ? numValue : otherProps[item] + if (/^="(\d+\.0+)"/.test(otherProps[item])) { + // format string number + otherProps[item] = otherProps[item].replace(/^="(\d+\.0+)"/, '$1') + } else { + // format number + const numValue = Number(otherProps[item]) + otherProps[item] = !isNaN(numValue) ? numValue : otherProps[item] + } } }) const oneRealJSONObj = {