Sfoglia il codice sorgente

将JOSN.parse改为了safeParse

louhangfei 1 anno fa
parent
commit
2d90fe2fbe

+ 8 - 7
src/views/cameras/preview/components/AlgorithmsSetting/utils.ts

@@ -5,6 +5,7 @@ import { isEqual } from 'lodash-es';
 
 import { TimeRangeItem, TimePeriodItem } from './types';
 import { CameraAlgoItem } from '@/api/camera/camera-preview';
+import safeParse from '@/utils/safeParse';
 
 // export const createDefaultTime = (): TimeRangeItem => {
 //   return { id: uid(), value: [dayjs(), dayjs().add(1, 'hour')] as [Dayjs, Dayjs] };
@@ -65,7 +66,7 @@ export const getDetectionTimeJSON = (time?: string): TimeRangeItem[] | null => {
 
 export const getInferParam = (extra: string | undefined | null) => {
   if (!extra) return {};
-  const extraObj = JSON.parse(extra);
+  const extraObj = safeParse(extra);
   const params = extraObj?.inferParams;
   if (!params || (params && params.length == 0)) return {};
   return params[0];
@@ -73,7 +74,7 @@ export const getInferParam = (extra: string | undefined | null) => {
 
 export const getMetaValues = (extra: string | undefined | null) => {
   if (!extra) return [];
-  const extraObj = JSON.parse(extra);
+  const extraObj = safeParse(extra);
   const params = extraObj?.inferParams;
   if (!params || (params && params.length == 0)) return [];
   const metaObjs = params[0]?.metaObjs;
@@ -99,7 +100,7 @@ export const getMetaValues = (extra: string | undefined | null) => {
 
 export const getDetectionTime = (time: string | undefined | null) => {
   if (!time) return [];
-  const timeList = JSON.parse(time);
+  const timeList = safeParse(time);
   if (!timeList || (timeList && timeList.length === 0)) {
     return [];
   }
@@ -108,13 +109,13 @@ export const getDetectionTime = (time: string | undefined | null) => {
 
 export const getInferCode = (extra: string | undefined | null) => {
   if (!extra) return '';
-  const extraObj = JSON.parse(extra);
+  const extraObj = safeParse(extra);
   return extraObj?.inferCode || '';
 };
 
 export const getAlgoType = (extra: string | undefined | null) => {
   if (!extra) return 0;
-  const extraObj = JSON.parse(extra);
+  const extraObj = safeParse(extra);
   const infers = extraObj?.inferParams;
   if (!infers || infers.length === 0) return 0;
   return infers[0]?.algoType || 0;
@@ -122,7 +123,7 @@ export const getAlgoType = (extra: string | undefined | null) => {
 
 export const getCriticalCounts = (extra: string | undefined | null) => {
   if (!extra) return [];
-  const extraObj = JSON.parse(extra);
+  const extraObj = safeParse(extra);
   const infers = extraObj?.inferParams;
   if (!infers || infers.length === 0) return [];
   return infers[0]?.criticalCounts || [];
@@ -149,7 +150,7 @@ interface CommonInfo {
 
 const getCommonInfo = (extra: string | undefined | null): CommonInfo => {
   if (!extra) return {};
-  const extraObj = JSON.parse(extra);
+  const extraObj = safeParse(extra);
   const params = extraObj?.inferParams;
   if (!params || (params && params.length == 0)) return {};
   const regionJudge = params[0]?.regionJudge;