调整 合同、运力、客商、项目
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 懒加载 chunk / CSS preload 失败后的整页恢复。
|
||||
* 常见于:部署后旧 hash 失效、静态服务空闲断连、代理 CONNECTION_RESET。
|
||||
*/
|
||||
|
||||
const RELOAD_FLAG = 'app:chunk-reload-ts';
|
||||
const RELOAD_COOLDOWN_MS = 10000;
|
||||
|
||||
const CHUNK_ERROR_RE =
|
||||
/Failed to fetch dynamically imported module|Importing a module script failed|Unable to preload CSS|error loading dynamically imported module|Loading CSS chunk|Loading chunk .+ failed|ChunkLoadError/i;
|
||||
|
||||
/** 最近一次路由跳转目标,供 onError 时整页落到正确地址 */
|
||||
let pendingFullPath = '';
|
||||
|
||||
export function setPendingRoutePath(fullPath = '') {
|
||||
pendingFullPath = fullPath || '';
|
||||
}
|
||||
|
||||
export function isChunkLoadError(error) {
|
||||
if (!error) return false;
|
||||
const message = error.message || String(error);
|
||||
return CHUNK_ERROR_RE.test(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} 是否已触发刷新(冷却期内返回 false,避免死循环)
|
||||
*/
|
||||
export function reloadForChunkError(targetPath) {
|
||||
const now = Date.now();
|
||||
const last = Number(sessionStorage.getItem(RELOAD_FLAG) || 0);
|
||||
if (now - last < RELOAD_COOLDOWN_MS) {
|
||||
return false;
|
||||
}
|
||||
sessionStorage.setItem(RELOAD_FLAG, String(now));
|
||||
const path = targetPath || pendingFullPath || window.location.pathname + window.location.search + window.location.hash;
|
||||
window.location.assign(path);
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user