77 lines
3.3 KiB
TypeScript
77 lines
3.3 KiB
TypeScript
// 整壳预览入口:路由 + 应用外壳(layout) + mock 菜单数据,用于验收
|
||
// 「平台菜单点击 → 内部路由跳转 → 侧栏高亮 / 面包屑」整条链路。
|
||
//
|
||
// 存在的理由:业务 dev(8079) 挂在平台 CAS 下,无登录态的自动化浏览器拿不到
|
||
// 真实页面,而这次的问题恰恰只在「侧栏点击」这一步暴露——单独渲染某个页面
|
||
// 是验不出来的。
|
||
//
|
||
// 用法:
|
||
// node preview-ut/mock-server.mjs # mock 数据(8109)
|
||
// npx vite --config preview.vite.config.ts --port 8099
|
||
// 打开 http://localhost:8099/preview-app.html#/__probe_start
|
||
// (起始 hash 故意用未匹配路径:每个菜单项都走 push 分支,避免 router.go(0)
|
||
// 刷新页面导致探针重入)
|
||
//
|
||
// 断言结果写入 document.title,用无头浏览器读取:
|
||
// msedge --headless=new --disable-gpu --virtual-time-budget=20000 --dump-dom <url>
|
||
import { createApp } from "vue";
|
||
import { createPinia } from "pinia";
|
||
import ViewUIPlus from "view-ui-plus";
|
||
import "view-ui-plus/dist/styles/viewuiplus.css";
|
||
import "@/assets/styles/main.scss";
|
||
import "@/assets/styles/layout.css";
|
||
import "@/assets/styles/icons.css";
|
||
import "virtual:uno.css";
|
||
import "virtual:svg-icons-register";
|
||
|
||
import App from "@/App.vue";
|
||
import router from "@/router";
|
||
import utils from "@/utils";
|
||
import mittBus from "@/utils/mitt";
|
||
import directive from "@/utils/directive/index";
|
||
import config from "@/assets/config/host.config";
|
||
|
||
const app = createApp(App);
|
||
app.use(createPinia());
|
||
app.use(router);
|
||
app.use(ViewUIPlus);
|
||
app.config.globalProperties.$conf = config;
|
||
app.config.globalProperties.$utils = utils;
|
||
app.config.globalProperties.$bus = mittBus;
|
||
directive(app);
|
||
app.mount("#app");
|
||
|
||
/** 侧栏解析失败时 layout.linkMenu 弹出的提示文案,出现即视为该菜单项未配置有效路径 */
|
||
const WARN_TEXT = "未配置有效页面路径";
|
||
const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
||
|
||
async function probe() {
|
||
await wait(1500); // 等 App 拉完 GetUserMod 并渲染侧栏
|
||
const links = Array.from(document.querySelectorAll<HTMLElement>(".left-menu .menu-item > a"));
|
||
const out: string[] = [];
|
||
let warned = 0;
|
||
|
||
for (const a of links) {
|
||
const name = a.querySelector(".menu-text")?.textContent?.trim() || "?";
|
||
a.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
||
await wait(400);
|
||
|
||
const warn = document.body.innerText.includes(WARN_TEXT);
|
||
if (warn) warned++;
|
||
// 清掉提示条,避免污染下一项判定
|
||
document.querySelectorAll(".ivu-message").forEach((n) => n.remove());
|
||
|
||
const path = (location.hash || "").replace(/^#/, "") || "/";
|
||
const active = document.querySelector(".left-menu li.active .menu-text")?.textContent?.trim() || "-";
|
||
const crumb = (document.querySelector(".path-nav")?.textContent || "").replace(/\s+/g, "").trim();
|
||
// 流程管理菜单的落地 tab(请假设置页仅 flow tab 用 liucheng 图标)
|
||
const tab = document.querySelector(".sett-tabs .ivu-tabs-tab-active")?.textContent?.trim() || "-";
|
||
|
||
out.push(`${name}=>${path},active=${active},crumb=${crumb},tab=${tab}${warn ? ",!WARN" : ""}`);
|
||
}
|
||
|
||
document.title = `APP|menus=${links.length}|warned=${warned}|` + out.join(" | ");
|
||
}
|
||
|
||
probe();
|