Commit bca653f6a3a82d32771a37eafbbc6009bb47e1e8
1 parent
63a2f78f
缓存部分配置
Showing
3 changed files
with
69 additions
and
39 deletions
src/components/Common/CommonHooks/useCommonBase.js
| @@ -224,34 +224,56 @@ const useCommonBase = props => { | @@ -224,34 +224,56 @@ const useCommonBase = props => { | ||
| 224 | * @returns {Promise<Array>} - 表单数据 | 224 | * @returns {Promise<Array>} - 表单数据 |
| 225 | */ | 225 | */ |
| 226 | const handleGetModelConfig = async params => { | 226 | const handleGetModelConfig = async params => { |
| 227 | - const { sModelsId } = params; | ||
| 228 | - const { token, formSrcRoute } = state; | ||
| 229 | - const configUrl = `${commonConfig.server_host | ||
| 230 | - }business/getModelBysId/${sModelsId}?sModelsId=${sModelsId}&sName=${formSrcRoute}`; | ||
| 231 | - const configUrlModel = `${commonConfig.server_host | ||
| 232 | - }/gdsmodule/getGdsmoduleById/${sModelsId}?sModelsId=${sModelsId}&sName=${formSrcRoute}`; | ||
| 233 | - // const getGdsmoduleById | ||
| 234 | - const configReturnModel = (await commonServices.getService(token, configUrlModel)) | ||
| 235 | - .data; | ||
| 236 | - | ||
| 237 | - const configReturn = (await commonServices.getService(token, configUrl)) | ||
| 238 | - .data; | ||
| 239 | - | ||
| 240 | - let formData = []; | ||
| 241 | - if (configReturn.code === 1) { | ||
| 242 | - const [configData] = configReturn.dataset.rows; | ||
| 243 | - formData = configData.formData; | ||
| 244 | - } else { | ||
| 245 | - getServiceError(configReturn); | 227 | + const cacheKey = params.sModelsId; |
| 228 | + const cacheKeyModel = `${params.sModelsId}_model`; | ||
| 229 | + | ||
| 230 | + const localStorageData = localStorage.getItem(cacheKey); | ||
| 231 | + const localStorageDataModel = localStorage.getItem(cacheKeyModel); | ||
| 232 | + | ||
| 233 | + if (localStorageData && localStorageDataModel) { | ||
| 234 | + try { | ||
| 235 | + const parsedData = JSON.parse(localStorageData); | ||
| 236 | + return parsedData; | ||
| 237 | + } catch (e) { | ||
| 238 | + localStorage.removeItem(cacheKey); | ||
| 239 | + localStorage.removeItem(cacheKeyModel); | ||
| 240 | + } | ||
| 246 | } | 241 | } |
| 247 | - const configReturnModelData = configReturnModel?.dataset?.rows?.[0] | ||
| 248 | - if (configReturnModelData) { | ||
| 249 | - formData.forEach(item => { | ||
| 250 | - item.sModelType = configReturnModelData?.sModelType | ||
| 251 | - item.sName = configReturnModelData?.sName | ||
| 252 | - }) | 242 | + const { sModelsId } = params; |
| 243 | + const { token, formSrcRoute } = state; // 确保 state 在此作用域可用 | ||
| 244 | + | ||
| 245 | + const configUrl = `${commonConfig.server_host}business/getModelBysId/${sModelsId}?sModelsId=${sModelsId}&sName=${formSrcRoute}`; | ||
| 246 | + const configUrlModel = `${commonConfig.server_host}/gdsmodule/getGdsmoduleById/${sModelsId}?sModelsId=${sModelsId}&sName=${formSrcRoute}`; | ||
| 247 | + | ||
| 248 | + try { | ||
| 249 | + const configReturnModel = (await commonServices.getService(token, configUrlModel)).data; | ||
| 250 | + const configReturn = (await commonServices.getService(token, configUrl)).data; | ||
| 251 | + | ||
| 252 | + let formData = []; | ||
| 253 | + if (configReturn.code === 1) { | ||
| 254 | + const [configData] = configReturn.dataset.rows; | ||
| 255 | + formData = configData.formData || []; // 增加容错 | ||
| 256 | + } else { | ||
| 257 | + getServiceError(configReturn); | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + const configReturnModelData = configReturnModel?.dataset?.rows?.[0]; | ||
| 261 | + | ||
| 262 | + if (configReturnModelData && formData.length > 0) { | ||
| 263 | + formData.forEach(item => { | ||
| 264 | + item.sModelType = configReturnModelData.sModelType; | ||
| 265 | + item.sName = configReturnModelData.sName; | ||
| 266 | + }); | ||
| 267 | + } | ||
| 268 | + if (params.sModelsId === '12710101117087404588200') { | ||
| 269 | + localStorage.setItem(cacheKeyModel, JSON.stringify(configReturnModelData)); | ||
| 270 | + localStorage.setItem(cacheKey, JSON.stringify(formData)); | ||
| 271 | + } | ||
| 272 | + return formData; | ||
| 273 | + } catch (error) { | ||
| 274 | + console.error('Failed to fetch model config:', error); | ||
| 275 | + throw error; // 抛出错误让调用者处理 | ||
| 253 | } | 276 | } |
| 254 | - return formData; | ||
| 255 | }; | 277 | }; |
| 256 | 278 | ||
| 257 | /* 获取后台数据(数据集) */ | 279 | /* 获取后台数据(数据集) */ |
src/mes/indexMes/index.js
| @@ -626,7 +626,7 @@ const HeaderConponent = () => { | @@ -626,7 +626,7 @@ const HeaderConponent = () => { | ||
| 626 | const SiderComponent = () => { | 626 | const SiderComponent = () => { |
| 627 | const { dispatch, hooksProps, props, ...rest } = useContext(myContext); | 627 | const { dispatch, hooksProps, props, ...rest } = useContext(myContext); |
| 628 | const { currentContent, menuMap, menuMapOpposite } = hooksProps; | 628 | const { currentContent, menuMap, menuMapOpposite } = hooksProps; |
| 629 | - const {managementData = []} = props?.app || {} | 629 | + const { managementData = [] } = props?.app || {} |
| 630 | const teamInformation = commonFunc.showLocalMessage(props, 'teamInformation', '班组信息'); | 630 | const teamInformation = commonFunc.showLocalMessage(props, 'teamInformation', '班组信息'); |
| 631 | 631 | ||
| 632 | const scheduledTask = commonFunc.showLocalMessage(props, 'scheduledTask', '计划任务'); | 632 | const scheduledTask = commonFunc.showLocalMessage(props, 'scheduledTask', '计划任务'); |
| @@ -684,9 +684,9 @@ const SiderComponent = () => { | @@ -684,9 +684,9 @@ const SiderComponent = () => { | ||
| 684 | } | 684 | } |
| 685 | ]; | 685 | ]; |
| 686 | let menuLists = [] | 686 | let menuLists = [] |
| 687 | - managementData && managementData?.forEach(item=>{ | ||
| 688 | - const i = menuList.findIndex(x=>x.title === item.sMenuName) | ||
| 689 | - if (i !== -1){ | 687 | + managementData && managementData?.forEach(item => { |
| 688 | + const i = menuList.findIndex(x => x.title === item.sMenuName) | ||
| 689 | + if (i !== -1) { | ||
| 690 | menuLists.push(menuList[i]) | 690 | menuLists.push(menuList[i]) |
| 691 | } | 691 | } |
| 692 | }) | 692 | }) |
| @@ -700,7 +700,7 @@ const SiderComponent = () => { | @@ -700,7 +700,7 @@ const SiderComponent = () => { | ||
| 700 | c_icon: c_guideIcon | 700 | c_icon: c_guideIcon |
| 701 | } | 701 | } |
| 702 | ]; | 702 | ]; |
| 703 | - const {bManual = false} = props?.app?.userinfo || {} | 703 | + const { bManual = false } = props?.app?.userinfo || {} |
| 704 | if (bManual) { | 704 | if (bManual) { |
| 705 | const index = filteredMenuList.findIndex(item => item.id === 'productionExec'); | 705 | const index = filteredMenuList.findIndex(item => item.id === 'productionExec'); |
| 706 | filteredMenuList.splice(index, 1); | 706 | filteredMenuList.splice(index, 1); |
| @@ -1061,12 +1061,16 @@ const SystemFunComponent = () => { | @@ -1061,12 +1061,16 @@ const SystemFunComponent = () => { | ||
| 1061 | <SwapOutlined /> | 1061 | <SwapOutlined /> |
| 1062 | <span>{bPlcSd ? SwitchAuto : switchToManual}</span> | 1062 | <span>{bPlcSd ? SwitchAuto : switchToManual}</span> |
| 1063 | </div> */} | 1063 | </div> */} |
| 1064 | - <div | 1064 | + <div |
| 1065 | className="restDailyReport" | 1065 | className="restDailyReport" |
| 1066 | onClick={() => { | 1066 | onClick={() => { |
| 1067 | - setTimeout(() => { | ||
| 1068 | - message.success( ClearCache + sSuccess + '!'); | ||
| 1069 | - }, 1000); | 1067 | + setTimeout(() => { |
| 1068 | + const key = '12710101117087404588200'; | ||
| 1069 | + const keyModel = '12710101117087404588200_model'; | ||
| 1070 | + localStorage.removeItem(key); | ||
| 1071 | + localStorage.removeItem(keyModel); | ||
| 1072 | + message.success(ClearCache + sSuccess + '!'); | ||
| 1073 | + }, 1000); | ||
| 1070 | }} | 1074 | }} |
| 1071 | > | 1075 | > |
| 1072 | <UndoOutlined /> | 1076 | <UndoOutlined /> |
src/mes/login/index.js
| @@ -133,6 +133,10 @@ const useLoginEvent = props => { | @@ -133,6 +133,10 @@ const useLoginEvent = props => { | ||
| 133 | 133 | ||
| 134 | // 登录事件 | 134 | // 登录事件 |
| 135 | const handleSubmit = async ({ faceLoginValue = {}, sEmployeeName, sEmployeeNo, sUserId } = {}, configsData) => { | 135 | const handleSubmit = async ({ faceLoginValue = {}, sEmployeeName, sEmployeeNo, sUserId } = {}, configsData) => { |
| 136 | + const key = '12710101117087404588200'; | ||
| 137 | + const keyModel = '12710101117087404588200_model'; | ||
| 138 | + localStorage.removeItem(key); | ||
| 139 | + localStorage.removeItem(keyModel); | ||
| 136 | const bFaceLogin = commonUtils.isNotEmptyObject(faceLoginValue); | 140 | const bFaceLogin = commonUtils.isNotEmptyObject(faceLoginValue); |
| 137 | let masterNewData = {} | 141 | let masterNewData = {} |
| 138 | let dataReturn = {}; | 142 | let dataReturn = {}; |
| @@ -152,7 +156,7 @@ const useLoginEvent = props => { | @@ -152,7 +156,7 @@ const useLoginEvent = props => { | ||
| 152 | masterNewData = { | 156 | masterNewData = { |
| 153 | ...masterNewData, | 157 | ...masterNewData, |
| 154 | sEmployeeNo, | 158 | sEmployeeNo, |
| 155 | - sUserName:sEmployeeName, | 159 | + sUserName: sEmployeeName, |
| 156 | sUserId | 160 | sUserId |
| 157 | } | 161 | } |
| 158 | } | 162 | } |
| @@ -329,9 +333,9 @@ const useLoginEvent = props => { | @@ -329,9 +333,9 @@ const useLoginEvent = props => { | ||
| 329 | const { masterData = {} } = props; | 333 | const { masterData = {} } = props; |
| 330 | const storeMasterData = JSON.parse(JSON.stringify(masterNewData)); | 334 | const storeMasterData = JSON.parse(JSON.stringify(masterNewData)); |
| 331 | const newMasterData = { | 335 | const newMasterData = { |
| 332 | - sUserId:storeMasterData.sUserId, | ||
| 333 | - sUserName:storeMasterData.sUserName, | ||
| 334 | - sUserNo:storeMasterData.sUserNo, | 336 | + sUserId: storeMasterData.sUserId, |
| 337 | + sUserName: storeMasterData.sUserName, | ||
| 338 | + sUserNo: storeMasterData.sUserNo, | ||
| 335 | } | 339 | } |
| 336 | localStorage.setItem( | 340 | localStorage.setItem( |
| 337 | `${commonConfig.prefix}masterData`, | 341 | `${commonConfig.prefix}masterData`, |