| @@ -4,6 +4,7 @@ | |||||
| * @Description: 页面状态缓存,pop 回到这个页面的时候,重新构建之前的状态 | * @Description: 页面状态缓存,pop 回到这个页面的时候,重新构建之前的状态 | ||||
| */ | */ | ||||
| import { parseJsonText } from '@/utils'; | |||||
| import { useCallback, useState } from 'react'; | import { useCallback, useState } from 'react'; | ||||
| const pageKeys: string[] = []; | const pageKeys: string[] = []; | ||||
| @@ -14,11 +15,7 @@ const getCacheState = (key: string) => { | |||||
| const jsonStr = sessionStorage.getItem(key); | const jsonStr = sessionStorage.getItem(key); | ||||
| if (jsonStr) { | if (jsonStr) { | ||||
| removeCacheState(key); | removeCacheState(key); | ||||
| try { | |||||
| return JSON.parse(jsonStr); | |||||
| } catch (error) { | |||||
| return undefined; | |||||
| } | |||||
| return parseJsonText(jsonStr); | |||||
| } | } | ||||
| return undefined; | return undefined; | ||||
| }; | }; | ||||
| @@ -3,7 +3,7 @@ import { useStateRef, useVisible } from '@/hooks'; | |||||
| import { getExperimentIns } from '@/services/experiment/index.js'; | import { getExperimentIns } from '@/services/experiment/index.js'; | ||||
| import { getWorkflowById } from '@/services/pipeline/index.js'; | import { getWorkflowById } from '@/services/pipeline/index.js'; | ||||
| import themes from '@/styles/theme.less'; | import themes from '@/styles/theme.less'; | ||||
| import { fittingString } from '@/utils'; | |||||
| import { fittingString, parseJsonText } from '@/utils'; | |||||
| import { elapsedTime, formatDate } from '@/utils/date'; | import { elapsedTime, formatDate } from '@/utils/date'; | ||||
| import { to } from '@/utils/promise'; | import { to } from '@/utils/promise'; | ||||
| import G6, { Util } from '@antv/g6'; | import G6, { Util } from '@antv/g6'; | ||||
| @@ -88,7 +88,7 @@ function ExperimentText() { | |||||
| setExperimentIns(res.data); | setExperimentIns(res.data); | ||||
| const { status, nodes_status, argo_ins_ns, argo_ins_name } = res.data; | const { status, nodes_status, argo_ins_ns, argo_ins_name } = res.data; | ||||
| const workflowData = workflowRef.current; | const workflowData = workflowRef.current; | ||||
| const experimentStatusObjs = JSON.parse(nodes_status); | |||||
| const experimentStatusObjs = parseJsonText(nodes_status); | |||||
| workflowData.nodes.forEach((item) => { | workflowData.nodes.forEach((item) => { | ||||
| const experimentNode = experimentStatusObjs?.[item.id]; | const experimentNode = experimentStatusObjs?.[item.id]; | ||||
| updateWorkflowNode(item, experimentNode); | updateWorkflowNode(item, experimentNode); | ||||
| @@ -2,7 +2,7 @@ import KFIcon from '@/components/KFIcon'; | |||||
| import { useStateRef, useVisible } from '@/hooks'; | import { useStateRef, useVisible } from '@/hooks'; | ||||
| import { getWorkflowById, saveWorkflow } from '@/services/pipeline/index.js'; | import { getWorkflowById, saveWorkflow } from '@/services/pipeline/index.js'; | ||||
| import themes from '@/styles/theme.less'; | import themes from '@/styles/theme.less'; | ||||
| import { fittingString, s8 } from '@/utils'; | |||||
| import { fittingString, parseJsonText, s8 } from '@/utils'; | |||||
| import { to } from '@/utils/promise'; | import { to } from '@/utils/promise'; | ||||
| import G6 from '@antv/g6'; | import G6 from '@antv/g6'; | ||||
| import { useNavigate, useParams } from '@umijs/max'; | import { useNavigate, useParams } from '@umijs/max'; | ||||
| @@ -130,7 +130,7 @@ const EditPipeline = () => { | |||||
| // 渲染数据 | // 渲染数据 | ||||
| const getGraphData = (data) => { | const getGraphData = (data) => { | ||||
| if (graph) { | |||||
| if (graph && data) { | |||||
| graph.data(data); | graph.data(data); | ||||
| graph.render(); | graph.render(); | ||||
| } else { | } else { | ||||
| @@ -283,7 +283,7 @@ const EditPipeline = () => { | |||||
| const { global_param, dag } = res.data; | const { global_param, dag } = res.data; | ||||
| setGlobalParam(global_param || []); | setGlobalParam(global_param || []); | ||||
| if (dag) { | if (dag) { | ||||
| getGraphData(JSON.parse(dag)); | |||||
| getGraphData(parseJsonText(dag)); | |||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| @@ -80,7 +80,7 @@ const PipelineNodeParameter = forwardRef(({ onFormChange }: PipelineNodeParamete | |||||
| out_parameters: JSON.parse(model.out_parameters), | out_parameters: JSON.parse(model.out_parameters), | ||||
| control_strategy: JSON.parse(model.control_strategy), | control_strategy: JSON.parse(model.control_strategy), | ||||
| }; | }; | ||||
| console.log('model', nodeData); | |||||
| // console.log('model', nodeData); | |||||
| setStagingItem({ | setStagingItem({ | ||||
| ...nodeData, | ...nodeData, | ||||
| }); | }); | ||||
| @@ -1,5 +1,6 @@ | |||||
| import { clearSessionToken, setSessionToken } from '@/access'; | import { clearSessionToken, setSessionToken } from '@/access'; | ||||
| import { getCaptchaImg, login } from '@/services/system/auth'; | import { getCaptchaImg, login } from '@/services/system/auth'; | ||||
| import { parseJsonText } from '@/utils'; | |||||
| import { safeInvoke } from '@/utils/functional'; | import { safeInvoke } from '@/utils/functional'; | ||||
| import LocalStorage from '@/utils/localStorage'; | import LocalStorage from '@/utils/localStorage'; | ||||
| import { to } from '@/utils/promise'; | import { to } from '@/utils/promise'; | ||||
| @@ -37,7 +38,7 @@ const Login = () => { | |||||
| const userJson = safeInvoke((text: string) => | const userJson = safeInvoke((text: string) => | ||||
| CryptoJS.AES.decrypt(text, AESKEY).toString(CryptoJS.enc.Utf8), | CryptoJS.AES.decrypt(text, AESKEY).toString(CryptoJS.enc.Utf8), | ||||
| )(userStorage); | )(userStorage); | ||||
| const user = safeInvoke(JSON.parse)(userJson); | |||||
| const user = safeInvoke(parseJsonText)(userJson); | |||||
| if (user && typeof user === 'object' && user.version === VERSION) { | if (user && typeof user === 'object' && user.version === VERSION) { | ||||
| const { username, password } = user; | const { username, password } = user; | ||||
| form.setFieldsValue({ username: username, password: password, autoLogin: true }); | form.setFieldsValue({ username: username, password: password, autoLogin: true }); | ||||
| @@ -21,7 +21,7 @@ export function getNameByCode(list: any[], code: any) { | |||||
| // 解析 json 字符串 | // 解析 json 字符串 | ||||
| export function parseJsonText(text?: string | null): any | null { | export function parseJsonText(text?: string | null): any | null { | ||||
| if (!text) { | |||||
| if (text === undefined || text === null || text === '') { | |||||
| return null; | return null; | ||||
| } | } | ||||
| try { | try { | ||||
| @@ -1,3 +1,5 @@ | |||||
| import { parseJsonText } from './index'; | |||||
| export default class LocalStorage { | export default class LocalStorage { | ||||
| // 登录的用户,包括用户名、密码和版本号 | // 登录的用户,包括用户名、密码和版本号 | ||||
| static readonly loginUserKey = 'login-user'; | static readonly loginUserKey = 'login-user'; | ||||
| @@ -10,13 +12,9 @@ export default class LocalStorage { | |||||
| return jsonStr; | return jsonStr; | ||||
| } | } | ||||
| if (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) { | static setItem(key: string, state?: any, isObject: boolean = false) { | ||||
| @@ -1,3 +1,5 @@ | |||||
| import { parseJsonText } from './index'; | |||||
| export default class SessionStorage { | export default class SessionStorage { | ||||
| // 用于新建镜像 | // 用于新建镜像 | ||||
| static readonly mirrorNameKey = 'mirror-name'; | static readonly mirrorNameKey = 'mirror-name'; | ||||
| @@ -7,8 +9,6 @@ export default class SessionStorage { | |||||
| static readonly serviceVersionInfoKey = 'service-version-info'; | static readonly serviceVersionInfoKey = 'service-version-info'; | ||||
| // 编辑器 url | // 编辑器 url | ||||
| static readonly editorUrlKey = 'editor-url'; | static readonly editorUrlKey = 'editor-url'; | ||||
| // 数据集、模型资源 | |||||
| static readonly resourceItemKey = 'resource-item'; | |||||
| static getItem(key: string, isObject: boolean = false) { | static getItem(key: string, isObject: boolean = false) { | ||||
| const jsonStr = sessionStorage.getItem(key); | const jsonStr = sessionStorage.getItem(key); | ||||
| @@ -16,13 +16,9 @@ export default class SessionStorage { | |||||
| return jsonStr; | return jsonStr; | ||||
| } | } | ||||
| if (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) { | static setItem(key: string, state?: any, isObject: boolean = false) { | ||||