From 0a3ea0372040620dbcc5fbe6c548a344c79879e9 Mon Sep 17 00:00:00 2001 From: xlsea Date: Fri, 21 Jun 2024 16:56:18 +0800 Subject: [PATCH] =?UTF-8?q?style(sj=5Fmap=5Freduce):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=88=97=E8=A1=A8=E5=8F=82=E6=95=B0=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflow/modules/common/detail-card.vue | 23 ++++------ src/utils/common.ts | 42 +++++++++++++++++++ .../batch/modules/job-batch-detail-drawer.vue | 17 +------- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/components/workflow/modules/common/detail-card.vue b/src/components/workflow/modules/common/detail-card.vue index 01b392e..e7b8364 100644 --- a/src/components/workflow/modules/common/detail-card.vue +++ b/src/components/workflow/modules/common/detail-card.vue @@ -4,7 +4,7 @@ import type { DataTableColumn } from 'naive-ui'; import { NButton, NCode, NPopover, NTag } from 'naive-ui'; import hljs from 'highlight.js/lib/core'; import json from 'highlight.js/lib/languages/json'; -import { isNotNull, translateOptions } from '@/utils/common'; +import { isNotNull, parseArgsJson, translateOptions } from '@/utils/common'; import { jobExecutorEnum, jobOperationReasonEnum, @@ -236,19 +236,6 @@ const columns = ref[]>([ titleAlign: 'center', minWidth: 120, render: row => { - let argsJson = JSON.parse(row.argsStr!); - - try { - if (argsJson.jobParams) { - argsJson.jobParams = JSON.parse(argsJson.jobParams.replaceAll('\\"', '"')); - } - if (argsJson.mapResult) { - argsJson.mapResult = JSON.parse(argsJson.mapResult.replaceAll('\\"', '"')); - } - } catch {} - - argsJson = JSON.stringify(argsJson, null, ' '); - return ( {{ @@ -258,7 +245,13 @@ const columns = ref[]>([ ), default: () => ( - + ) }} diff --git a/src/utils/common.ts b/src/utils/common.ts index a5aebaa..a19aee1 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -121,3 +121,45 @@ export function toggleHtmlClass(className: string) { export function isNotNull(value: any) { return value !== undefined && value !== null && value !== '' && value !== 'undefined'; } + +export function parseArgsJson(value: string) { + let argsJson; + + try { + argsJson = JSON.parse(value); + + // A helper function to safely parse JSON strings that might contain escaped quotes + const safelyParseJson = (jsonString: string) => { + try { + return JSON.parse(jsonString.replaceAll('\\"', '"')); + } catch (error) { + return jsonString; // Return original string if it's not valid JSON + } + }; + + // Process jobParams if it exists + if (typeof argsJson.jobParams === 'string') { + argsJson.jobParams = safelyParseJson(argsJson.jobParams); + } + + // Process mapResult if it exists + if (typeof argsJson.mapResult === 'string') { + argsJson.mapResult = safelyParseJson(argsJson.mapResult); + } + + // Process maps if it exists + if (typeof argsJson.maps === 'string') { + argsJson.maps = safelyParseJson(argsJson.maps); + + // If maps is a string that represents an array, parse it as JSON + if (argsJson.maps.startsWith('"[') && argsJson.maps.endsWith('"]')) { + argsJson.maps = safelyParseJson(argsJson.maps.slice(1, -1)); + } + } + } catch {} + + // Convert the object back to a pretty-printed JSON string + argsJson = JSON.stringify(argsJson, null, 4); + + return argsJson; +} diff --git a/src/views/job/batch/modules/job-batch-detail-drawer.vue b/src/views/job/batch/modules/job-batch-detail-drawer.vue index d55f714..4476ea8 100644 --- a/src/views/job/batch/modules/job-batch-detail-drawer.vue +++ b/src/views/job/batch/modules/job-batch-detail-drawer.vue @@ -10,7 +10,7 @@ import { taskStatusRecord } from '@/constants/business'; import { $t } from '@/locales'; -import { tagColor } from '@/utils/common'; +import { parseArgsJson, tagColor } from '@/utils/common'; import { useTable } from '@/hooks/common/table'; import { fetchGetJobTaskList } from '@/service/api'; import { fetchJobLogList } from '@/service/api/log'; @@ -121,19 +121,6 @@ const { columns, data, loading, mobilePagination } = useTable({ titleAlign: 'center', minWidth: 120, render: row => { - let argsJson = JSON.parse(row.argsStr!); - - try { - if (argsJson.jobParams) { - argsJson.jobParams = JSON.parse(argsJson.jobParams.replaceAll('\\"', '"')); - } - if (argsJson.mapResult) { - argsJson.mapResult = JSON.parse(argsJson.mapResult.replaceAll('\\"', '"')); - } - } catch {} - - argsJson = JSON.stringify(argsJson, null, ' '); - return ( {{ @@ -146,7 +133,7 @@ const { columns, data, loading, mobilePagination } = useTable({