Use structuredClone instead of JSON.parse(JSON.stringify()) (S7784)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-10 00:28:30 +08:00
parent 3768c6e5ec
commit 2b0dadedd4
9 changed files with 32 additions and 32 deletions

View File

@@ -920,8 +920,8 @@ function getSequenceData() {
task_seq: selectCfmSeqDirectly.value, task_seq: selectCfmSeqDirectly.value,
}; };
isSubmitReset(); isSubmitReset();
isSubmitCfmSeqDirectly.value = JSON.parse( isSubmitCfmSeqDirectly.value = structuredClone(
JSON.stringify(selectCfmSeqDirectly.value), selectCfmSeqDirectly.value,
); );
break; break;
case "Eventually follows": case "Eventually follows":
@@ -930,8 +930,8 @@ function getSequenceData() {
task_seq: selectCfmSeqEventually.value, task_seq: selectCfmSeqEventually.value,
}; };
isSubmitReset(); isSubmitReset();
isSubmitCfmSeqEventually.value = JSON.parse( isSubmitCfmSeqEventually.value = structuredClone(
JSON.stringify(selectCfmSeqEventually.value), selectCfmSeqEventually.value,
); );
break; break;
case "Short loop(s)": case "Short loop(s)":

View File

@@ -129,7 +129,7 @@ const datadata = computed(() => {
// Sort the Activity List // Sort the Activity List
let newData; let newData;
if (props.data !== null) { if (props.data !== null) {
newData = JSON.parse(JSON.stringify(props.data)); newData = structuredClone(props.data);
sortNumEngZhtw(newData); sortNumEngZhtw(newData);
} }
return newData; return newData;
@@ -195,7 +195,7 @@ function onEnd(evt) {
} }
// created // created
const newlist = JSON.parse(JSON.stringify(props.listSeq)); const newlist = structuredClone(props.listSeq);
listSequence.value = props.isSubmit ? newlist : []; listSequence.value = props.isSubmit ? newlist : [];
emitter.on("reset", (data) => { emitter.on("reset", (data) => {
listSequence.value = []; listSequence.value = [];

View File

@@ -373,7 +373,7 @@ emitter.on("actListData", (data) => {
state.containstTasksData = data; state.containstTasksData = data;
}); });
emitter.on("actRadioData", (newData) => { emitter.on("actRadioData", (newData) => {
const data = JSON.parse(JSON.stringify(newData)); // Deep copy the original cases data const data = structuredClone(newData); // Deep copy the original cases data
const categoryMapping = { const categoryMapping = {
cfmSeqStart: ["Start", "selectCfmSeqStart", "selectCfmSeqEnd"], cfmSeqStart: ["Start", "selectCfmSeqStart", "selectCfmSeqEnd"],

View File

@@ -613,20 +613,20 @@ emitter.on("isRadioChange", (data) => {
switch (selectedRuleType.value) { switch (selectedRuleType.value) {
case "Processing time": case "Processing time":
state.timeCfmPtEteAll = getDurationTime(cfmPtEteWhole.value, "all"); state.timeCfmPtEteAll = getDurationTime(cfmPtEteWhole.value, "all");
state.timeCfmPtEteAllDefault = JSON.parse( state.timeCfmPtEteAllDefault = structuredClone(
JSON.stringify(state.timeCfmPtEteAll), state.timeCfmPtEteAll,
); );
break; break;
case "Waiting time": case "Waiting time":
state.timeCfmWtEteAll = getDurationTime(cfmWtEteWhole.value, "all"); state.timeCfmWtEteAll = getDurationTime(cfmWtEteWhole.value, "all");
state.timeCfmWtEteAllDefault = JSON.parse( state.timeCfmWtEteAllDefault = structuredClone(
JSON.stringify(state.timeCfmWtEteAll), state.timeCfmWtEteAll,
); );
break; break;
case "Cycle time": case "Cycle time":
state.timeCfmCtEteAll = getDurationTime(cfmCtEteWhole.value, "all"); state.timeCfmCtEteAll = getDurationTime(cfmCtEteWhole.value, "all");
state.timeCfmCtEteAllDefault = JSON.parse( state.timeCfmCtEteAllDefault = structuredClone(
JSON.stringify(state.timeCfmCtEteAll), state.timeCfmCtEteAll,
); );
break; break;
default: default:
@@ -645,20 +645,20 @@ emitter.on("isRadioActSeqMoreChange", (data) => {
switch (selectedRuleType.value) { switch (selectedRuleType.value) {
case "Processing time": case "Processing time":
state.timeCfmPtEteAll = getDurationTime(cfmPtEteWhole.value, "all"); state.timeCfmPtEteAll = getDurationTime(cfmPtEteWhole.value, "all");
state.timeCfmPtEteAllDefault = JSON.parse( state.timeCfmPtEteAllDefault = structuredClone(
JSON.stringify(state.timeCfmPtEteAll), state.timeCfmPtEteAll,
); );
break; break;
case "Waiting time": case "Waiting time":
state.timeCfmWtEteAll = getDurationTime(cfmWtEteWhole.value, "all"); state.timeCfmWtEteAll = getDurationTime(cfmWtEteWhole.value, "all");
state.timeCfmWtEteAllDefault = JSON.parse( state.timeCfmWtEteAllDefault = structuredClone(
JSON.stringify(state.timeCfmWtEteAll), state.timeCfmWtEteAll,
); );
break; break;
case "Cycle time": case "Cycle time":
state.timeCfmCtEteAll = getDurationTime(cfmCtEteWhole.value, "all"); state.timeCfmCtEteAll = getDurationTime(cfmCtEteWhole.value, "all");
state.timeCfmCtEteAllDefault = JSON.parse( state.timeCfmCtEteAllDefault = structuredClone(
JSON.stringify(state.timeCfmCtEteAll), state.timeCfmCtEteAll,
); );
break; break;
default: default:

View File

@@ -55,10 +55,10 @@ const durationMax = ref(null);
/** Deep-copies timeData min/max values to the Vue component boundaries. */ /** Deep-copies timeData min/max values to the Vue component boundaries. */
function setTimeValue() { function setTimeValue() {
// Deep copy the original timeData values // Deep copy the original timeData values
minVuemin.value = JSON.parse(JSON.stringify(timeData.value.min)); minVuemin.value = structuredClone(timeData.value.min);
minVuemax.value = JSON.parse(JSON.stringify(timeData.value.max)); minVuemax.value = structuredClone(timeData.value.max);
maxVuemin.value = JSON.parse(JSON.stringify(timeData.value.min)); maxVuemin.value = structuredClone(timeData.value.min);
maxVuemax.value = JSON.parse(JSON.stringify(timeData.value.max)); maxVuemax.value = structuredClone(timeData.value.max);
} }
/** /**

View File

@@ -183,7 +183,7 @@ const traceList = computed(() => {
const caseData = computed(() => { const caseData = computed(() => {
if (infiniteData.value !== null) { if (infiniteData.value !== null) {
const data = JSON.parse(JSON.stringify(infiniteData.value)); // Deep copy the original cases data const data = structuredClone(infiniteData.value); // Deep copy the original cases data
data.forEach((item) => { data.forEach((item) => {
item.facets.forEach((facet, index) => { item.facets.forEach((facet, index) => {
item[`fac_${index}`] = facet.value; // Create a new key-value pair item[`fac_${index}`] = facet.value; // Create a new key-value pair
@@ -201,7 +201,7 @@ const caseData = computed(() => {
}); });
const columnData = computed(() => { const columnData = computed(() => {
const data = JSON.parse(JSON.stringify(props.cases)); // Deep copy the original cases data const data = structuredClone(props.cases); // Deep copy the original cases data
if (!data || data.length === 0) return []; if (!data || data.length === 0) return [];
const facetName = (facName) => const facetName = (facName) =>
facName facName

View File

@@ -228,7 +228,7 @@ const chartData = computed(() => {
}); });
const caseData = computed(() => { const caseData = computed(() => {
const data = JSON.parse(JSON.stringify(infiniteData.value)); // Deep copy the original cases data const data = structuredClone(infiniteData.value); // Deep copy the original cases data
data.forEach((item) => { data.forEach((item) => {
item.attributes.forEach((attribute, index) => { item.attributes.forEach((attribute, index) => {
item[`att_${index}`] = attribute.value; // Create a new key-value pair item[`att_${index}`] = attribute.value; // Create a new key-value pair
@@ -239,7 +239,7 @@ const caseData = computed(() => {
}); });
const columnData = computed(() => { const columnData = computed(() => {
const data = JSON.parse(JSON.stringify(baseCases.value)); // Deep copy the original cases data const data = structuredClone(baseCases.value); // Deep copy the original cases data
let result = [ let result = [
{ field: "id", header: "Case Id" }, { field: "id", header: "Case Id" },
{ field: "started_at", header: "Start time" }, { field: "started_at", header: "Start time" },

View File

@@ -164,7 +164,7 @@ const traceList = computed(() => {
}); });
const caseData = computed(() => { const caseData = computed(() => {
const data = JSON.parse(JSON.stringify(infiniteData.value)); // Deep copy the original cases data const data = structuredClone(infiniteData.value); // Deep copy the original cases data
data.forEach((item) => { data.forEach((item) => {
item.attributes.forEach((attribute, index) => { item.attributes.forEach((attribute, index) => {
item[`att_${index}`] = attribute.value; // Create a new key-value pair item[`att_${index}`] = attribute.value; // Create a new key-value pair
@@ -175,7 +175,7 @@ const caseData = computed(() => {
}); });
const columnData = computed(() => { const columnData = computed(() => {
const data = JSON.parse(JSON.stringify(props.cases)); // Deep copy the original cases data const data = structuredClone(props.cases); // Deep copy the original cases data
let result = [ let result = [
{ field: "id", header: "Case Id" }, { field: "id", header: "Case Id" },
{ field: "started_at", header: "Start time" }, { field: "started_at", header: "Start time" },
@@ -215,7 +215,7 @@ watch(showTraceId, (newValue, oldValue) => {
watch(infiniteFirstCases, (newValue) => { watch(infiniteFirstCases, (newValue) => {
if (infiniteFirstCases.value) if (infiniteFirstCases.value)
infiniteData.value = JSON.parse(JSON.stringify(newValue)); infiniteData.value = structuredClone(newValue);
}); });
/** /**

View File

@@ -586,7 +586,7 @@ const isCompareDisabledButton = computed(() => {
const reallyDeleteData = computed(() => { const reallyDeleteData = computed(() => {
let result = []; let result = [];
if (store.allFiles.length !== 0) { if (store.allFiles.length !== 0) {
result = JSON.parse(JSON.stringify(store.allFiles)); result = structuredClone(store.allFiles);
result = result.filter((file) => file.is_deleted === true); result = result.filter((file) => file.is_deleted === true);
} }
return result; return result;
@@ -602,7 +602,7 @@ watch(filesTag, (newValue) => {
watch(allFiles, (newValue) => { watch(allFiles, (newValue) => {
if (newValue !== null) if (newValue !== null)
compareData.value = JSON.parse(JSON.stringify(newValue)); compareData.value = structuredClone(newValue);
}); });
watch( watch(