Browse Source

fix: JSON.parse修改为parseJsonText

pull/137/head
cp3hnu 1 year ago
parent
commit
90f959af63
8 changed files with 19 additions and 27 deletions
  1. +2
    -5
      react-ui/src/hooks/pageCacheState.ts
  2. +2
    -2
      react-ui/src/pages/Experiment/Info/index.jsx
  3. +3
    -3
      react-ui/src/pages/Pipeline/Info/index.jsx
  4. +1
    -1
      react-ui/src/pages/Pipeline/components/PipelineNodeDrawer/index.tsx
  5. +2
    -1
      react-ui/src/pages/User/Login/index.tsx
  6. +1
    -1
      react-ui/src/utils/index.ts
  7. +4
    -6
      react-ui/src/utils/localStorage.ts
  8. +4
    -8
      react-ui/src/utils/sessionStorage.ts

+ 2
- 5
react-ui/src/hooks/pageCacheState.ts View File

@@ -4,6 +4,7 @@
* @Description: 页面状态缓存,pop 回到这个页面的时候,重新构建之前的状态
*/

import { parseJsonText } from '@/utils';
import { useCallback, useState } from 'react';

const pageKeys: string[] = [];
@@ -14,11 +15,7 @@ const getCacheState = (key: string) => {
const jsonStr = sessionStorage.getItem(key);
if (jsonStr) {
removeCacheState(key);
try {
return JSON.parse(jsonStr);
} catch (error) {
return undefined;
}
return parseJsonText(jsonStr);
}
return undefined;
};


+ 2
- 2
react-ui/src/pages/Experiment/Info/index.jsx View File

@@ -3,7 +3,7 @@ import { useStateRef, useVisible } from '@/hooks';
import { getExperimentIns } from '@/services/experiment/index.js';
import { getWorkflowById } from '@/services/pipeline/index.js';
import themes from '@/styles/theme.less';
import { fittingString } from '@/utils';
import { fittingString, parseJsonText } from '@/utils';
import { elapsedTime, formatDate } from '@/utils/date';
import { to } from '@/utils/promise';
import G6, { Util } from '@antv/g6';
@@ -88,7 +88,7 @@ function ExperimentText() {
setExperimentIns(res.data);
const { status, nodes_status, argo_ins_ns, argo_ins_name } = res.data;
const workflowData = workflowRef.current;
const experimentStatusObjs = JSON.parse(nodes_status);
const experimentStatusObjs = parseJsonText(nodes_status);
workflowData.nodes.forEach((item) => {
const experimentNode = experimentStatusObjs?.[item.id];
updateWorkflowNode(item, experimentNode);


+ 3
- 3
react-ui/src/pages/Pipeline/Info/index.jsx View File

@@ -2,7 +2,7 @@ import KFIcon from '@/components/KFIcon';
import { useStateRef, useVisible } from '@/hooks';
import { getWorkflowById, saveWorkflow } from '@/services/pipeline/index.js';
import themes from '@/styles/theme.less';
import { fittingString, s8 } from '@/utils';
import { fittingString, parseJsonText, s8 } from '@/utils';
import { to } from '@/utils/promise';
import G6 from '@antv/g6';
import { useNavigate, useParams } from '@umijs/max';
@@ -130,7 +130,7 @@ const EditPipeline = () => {

// 渲染数据
const getGraphData = (data) => {
if (graph) {
if (graph && data) {
graph.data(data);
graph.render();
} else {
@@ -283,7 +283,7 @@ const EditPipeline = () => {
const { global_param, dag } = res.data;
setGlobalParam(global_param || []);
if (dag) {
getGraphData(JSON.parse(dag));
getGraphData(parseJsonText(dag));
}
}
};


+ 1
- 1
react-ui/src/pages/Pipeline/components/PipelineNodeDrawer/index.tsx View File

@@ -80,7 +80,7 @@ const PipelineNodeParameter = forwardRef(({ onFormChange }: PipelineNodeParamete
out_parameters: JSON.parse(model.out_parameters),
control_strategy: JSON.parse(model.control_strategy),
};
console.log('model', nodeData);
// console.log('model', nodeData);
setStagingItem({
...nodeData,
});


+ 2
- 1
react-ui/src/pages/User/Login/index.tsx View File

@@ -1,5 +1,6 @@
import { clearSessionToken, setSessionToken } from '@/access';
import { getCaptchaImg, login } from '@/services/system/auth';
import { parseJsonText } from '@/utils';
import { safeInvoke } from '@/utils/functional';
import LocalStorage from '@/utils/localStorage';
import { to } from '@/utils/promise';
@@ -37,7 +38,7 @@ const Login = () => {
const userJson = safeInvoke((text: string) =>
CryptoJS.AES.decrypt(text, AESKEY).toString(CryptoJS.enc.Utf8),
)(userStorage);
const user = safeInvoke(JSON.parse)(userJson);
const user = safeInvoke(parseJsonText)(userJson);
if (user && typeof user === 'object' && user.version === VERSION) {
const { username, password } = user;
form.setFieldsValue({ username: username, password: password, autoLogin: true });


+ 1
- 1
react-ui/src/utils/index.ts View File

@@ -21,7 +21,7 @@ export function getNameByCode(list: any[], code: any) {

// 解析 json 字符串
export function parseJsonText(text?: string | null): any | null {
if (!text) {
if (text === undefined || text === null || text === '') {
return null;
}
try {


+ 4
- 6
react-ui/src/utils/localStorage.ts View File

@@ -1,3 +1,5 @@
import { parseJsonText } from './index';

export default class LocalStorage {
// 登录的用户,包括用户名、密码和版本号
static readonly loginUserKey = 'login-user';
@@ -10,13 +12,9 @@ export default class LocalStorage {
return jsonStr;
}
if (jsonStr) {
try {
return JSON.parse(jsonStr);
} catch (error) {
return undefined;
}
return parseJsonText(jsonStr);
}
return undefined;
return null;
}

static setItem(key: string, state?: any, isObject: boolean = false) {


+ 4
- 8
react-ui/src/utils/sessionStorage.ts View File

@@ -1,3 +1,5 @@
import { parseJsonText } from './index';

export default class SessionStorage {
// 用于新建镜像
static readonly mirrorNameKey = 'mirror-name';
@@ -7,8 +9,6 @@ export default class SessionStorage {
static readonly serviceVersionInfoKey = 'service-version-info';
// 编辑器 url
static readonly editorUrlKey = 'editor-url';
// 数据集、模型资源
static readonly resourceItemKey = 'resource-item';

static getItem(key: string, isObject: boolean = false) {
const jsonStr = sessionStorage.getItem(key);
@@ -16,13 +16,9 @@ export default class SessionStorage {
return jsonStr;
}
if (jsonStr) {
try {
return JSON.parse(jsonStr);
} catch (error) {
return undefined;
}
return parseJsonText(jsonStr);
}
return undefined;
return null;
}

static setItem(key: string, state?: any, isObject: boolean = false) {


Loading…
Cancel
Save