cloud-web-corejs 1.0.54-dev.755 → 1.0.54-dev.757
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +15 -0
- package/src/layout/components/AppMain.vue +7 -0
- package/src/microRouter/index.js +63 -9
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -323,12 +323,27 @@ function syncSubRouter() {
|
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
/**
|
|
327
|
+
* 主应用页签"刷新"转发过来时在子应用内部重建当前页组件。
|
|
328
|
+
* 与主应用自身刷新同一套路:先删 keep-alive 缓存,再绕 /redirect 让组件重新创建。
|
|
329
|
+
*/
|
|
330
|
+
function refreshCurrentView() {
|
|
331
|
+
const view = router.currentRoute;
|
|
332
|
+
const fullPath = view.fullPath;
|
|
333
|
+
store.dispatch("tagsView/delCachedView", view).then(() => {
|
|
334
|
+
router.replace({ path: "/redirect" + fullPath }).catch(() => {});
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
326
338
|
export async function update(props = {}) {
|
|
327
339
|
if (props.microActive === false) {
|
|
328
340
|
pauseSubRouter();
|
|
329
341
|
} else if (props.microActive === true) {
|
|
330
342
|
resumeSubRouter();
|
|
331
343
|
}
|
|
344
|
+
if (props.microRefresh) {
|
|
345
|
+
refreshCurrentView();
|
|
346
|
+
}
|
|
332
347
|
}
|
|
333
348
|
|
|
334
349
|
export async function unmount() {
|
|
@@ -32,6 +32,7 @@ import outLink from '@base/views/user/outLink/index.vue';
|
|
|
32
32
|
import unreadDialog from "../../layout/components/notify_message/unreadDialog.vue";
|
|
33
33
|
import watermark from "./watermark";
|
|
34
34
|
import { isRepeatable } from "@base/utils/repeatOpen";
|
|
35
|
+
import { refreshMicroApp } from "@base/microRouter";
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
export default {
|
|
@@ -66,6 +67,12 @@ export default {
|
|
|
66
67
|
// handler 存实例属性并在销毁时 $off:事件总线是应用级单例,
|
|
67
68
|
// 不解绑会在登出重建布局后累积 handler 并钉住旧实例(内存泄露)
|
|
68
69
|
this.reflushRouteViewHandler = (view) => {
|
|
70
|
+
let meta = this.$route.meta || {};
|
|
71
|
+
// 子应用页面不在本 router-view 内(由 qiankun 挂独立容器),
|
|
72
|
+
// 走本地 /redirect 重建只会隐藏再显示容器、实例不变,须转发给子应用自己重建
|
|
73
|
+
if (meta.isMicroApp && refreshMicroApp(meta.appCode)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
69
76
|
if(this.$route.name=="outLink"){
|
|
70
77
|
let t = this.$refs["ref_"+this.$route.path][0];
|
|
71
78
|
t.$baseReload();
|
package/src/microRouter/index.js
CHANGED
|
@@ -22,6 +22,12 @@ const REGISTRY_TIMEOUT = 8000;
|
|
|
22
22
|
const CONTAINER_WRAPPER_ID = "Appmicro";
|
|
23
23
|
const DEBUG_APP_CODE_REG = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
24
24
|
|
|
25
|
+
// 本机调试的约定默认值:包内兜底,各应用 settings.js 无需声明。
|
|
26
|
+
// 需要偏离约定(改端口 / 调真实 appCode 的菜单派发)才在应用 settings.js 里覆盖,
|
|
27
|
+
// 或用 ?microDebug=appB=http://... 单次指定。
|
|
28
|
+
const DEBUG_DEFAULT_APP_CODE = "debugApp";
|
|
29
|
+
const DEBUG_DEFAULT_ENTRY = "http://localhost:17527/";
|
|
30
|
+
|
|
25
31
|
// 保活管理:appCode → { instance, el };离开子应用路由只隐藏容器不卸载,
|
|
26
32
|
// 切回直接显示并经 update 生命周期同步路由,页面状态(页签/表格/表单)得以保留
|
|
27
33
|
let microAppConfigs = {};
|
|
@@ -68,19 +74,52 @@ export function getAppRegistry() {
|
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
+
* 从 URL 读调试开关并落盘 localStorage,读到后即从地址栏抹掉(避免被收藏/分享扩散)。
|
|
78
|
+
* 支持 hash 前后两种位置:?microDebug=xx#/... 与 #/...?microDebug=xx。
|
|
79
|
+
* 取值同 localStorage 四档写法;microDebug=off 清除调试态。
|
|
80
|
+
* 存在意义:settings.microDebugEnabled 是构建期常量、全体用户共用,生产构建里必须失效;
|
|
81
|
+
* 生产环境主应用要装本机子应用,只能靠这种"按浏览器生效"的通道。
|
|
82
|
+
*/
|
|
83
|
+
function readDebugFromUrl() {
|
|
84
|
+
const href = window.location.href || "";
|
|
85
|
+
const matched = href.match(/[?&]microDebug=([^&#]*)/);
|
|
86
|
+
if (!matched) return;
|
|
87
|
+
const value = decodeURIComponent(matched[1] || "").trim();
|
|
88
|
+
try {
|
|
89
|
+
if (!value || value === "off" || value === "0") {
|
|
90
|
+
window.localStorage.removeItem(DEBUG_STORAGE_KEY);
|
|
91
|
+
} else {
|
|
92
|
+
window.localStorage.setItem(DEBUG_STORAGE_KEY, value);
|
|
93
|
+
}
|
|
94
|
+
} catch (e) {
|
|
95
|
+
console.error("[microRouter] 调试开关写入 localStorage 失败:", e.message);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const cleaned = href
|
|
100
|
+
.replace(/([?&])microDebug=[^&#]*&?/, "$1")
|
|
101
|
+
.replace(/[?&](?=#|$)/, ""); // 抹掉后可能残留的空查询串
|
|
102
|
+
window.history.replaceState(null, "", cleaned);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
// replaceState 失败不影响开关本身,忽略
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 本机调试覆盖,三种触发方式(localStorage 优先于 settings 开关):
|
|
110
|
+
* 1) URL 参数 ?microDebug=xx —— 任何环境(含生产构建)都生效,值写入 localStorage
|
|
111
|
+
* 后自动从地址栏抹掉;?microDebug=off 清除。生产环境主应用只能用这种。
|
|
112
|
+
* 2) localStorage.micro_app_debug —— 仅当前浏览器生效,不影响其他用户。四档写法:
|
|
77
113
|
* "1" → settings.microDebugAppCode + microDebugEntry
|
|
78
114
|
* "appB" → appB + 默认调试入口
|
|
79
|
-
* "appB=http://localhost:
|
|
115
|
+
* "appB=http://localhost:17528/" → 指定入口;多个用逗号分隔,可混写
|
|
80
116
|
* '[{"appCode":"..","entry":".."}]' → 完整条目数组
|
|
117
|
+
* 3) settings.microDebugEnabled = true —— 本地起主应用时免设 localStorage;
|
|
118
|
+
* 仅非 production 构建生效,防误留 true 发版后所有用户被指向 localhost。
|
|
81
119
|
* 与注册表按 appCode 合并:已存在的条目覆盖 entry 并强制 enabled,不存在的追加。
|
|
82
120
|
*/
|
|
83
121
|
function getDebugOverrides() {
|
|
122
|
+
readDebugFromUrl();
|
|
84
123
|
let raw = null;
|
|
85
124
|
try {
|
|
86
125
|
raw = window.localStorage.getItem(DEBUG_STORAGE_KEY);
|
|
@@ -89,8 +128,8 @@ function getDebugOverrides() {
|
|
|
89
128
|
}
|
|
90
129
|
raw = raw ? raw.trim() : "";
|
|
91
130
|
const defaults = {
|
|
92
|
-
appCode: settings.microDebugAppCode ||
|
|
93
|
-
entry: settings.microDebugEntry ||
|
|
131
|
+
appCode: settings.microDebugAppCode || DEBUG_DEFAULT_APP_CODE,
|
|
132
|
+
entry: settings.microDebugEntry || DEBUG_DEFAULT_ENTRY,
|
|
94
133
|
};
|
|
95
134
|
let restoreHint
|
|
96
135
|
= "删除 localStorage." + DEBUG_STORAGE_KEY + " 后刷新恢复";
|
|
@@ -324,6 +363,21 @@ function notifyMicroApp(instance, props) {
|
|
|
324
363
|
});
|
|
325
364
|
}
|
|
326
365
|
|
|
366
|
+
/**
|
|
367
|
+
* 转发"刷新当前页"给子应用。
|
|
368
|
+
* 保活模式下主应用那套 delCachedView + /redirect 重建只作用于自己的 router-view,
|
|
369
|
+
* 子应用内容由 qiankun 挂在独立容器里,走一圈只是容器隐藏再显示、实例毫发无损,
|
|
370
|
+
* 表现为点刷新没反应——必须由子应用在自身路由内重建组件。
|
|
371
|
+
* 返回是否已转发(false 表示该应用未装载,调用方回落自身刷新逻辑)。
|
|
372
|
+
*/
|
|
373
|
+
export function refreshMicroApp(appCode) {
|
|
374
|
+
const alive = aliveApps[appCode];
|
|
375
|
+
if (!alive) return false;
|
|
376
|
+
// 带时间戳:qiankun 对相同 props 也会调用 update,但时间戳能让子应用区分每次点击
|
|
377
|
+
notifyMicroApp(alive.instance, { microRefresh: Date.now() });
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
|
|
327
381
|
/** 真正卸载全部子应用(登出等场景按需调用;常规页签切换不卸载) */
|
|
328
382
|
export function unmountAllMicroApps() {
|
|
329
383
|
Object.keys(aliveApps).forEach((code) => {
|