mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-24 04:33:35 +08:00
8 lines
7.6 KiB
JavaScript
8 lines
7.6 KiB
JavaScript
import{_ as t,o as a,c as s,a3 as i}from"./chunks/framework.D8G7yXPy.js";const k=JSON.parse('{"title":"Menu 与 KeepAlive Store","description":"","frontmatter":{},"headers":[],"relativePath":"reference/store/navigation.md","filePath":"reference/store/navigation.md"}'),n={name:"reference/store/navigation.md"};function o(d,e,r,l,p,h){return a(),s("div",null,[...e[0]||(e[0]=[i(`<h1 id="menu-与-keepalive-store" tabindex="-1">Menu 与 KeepAlive Store <a class="header-anchor" href="#menu-与-keepalive-store" aria-label="Permalink to "Menu 与 KeepAlive Store""></a></h1><h2 id="menu-store" tabindex="-1">Menu Store <a class="header-anchor" href="#menu-store" aria-label="Permalink to "Menu Store""></a></h2><p>路由模块转换成菜单树。Menu Store 负责选中项、标签、面包屑和导航联动,业务页面通常使用 <a href="./../hooks/navigation.html#useappnavigation">useAppNavigation</a> 或 <a href="./../hooks/navigation.html#usesiderbar">useSiderBar</a>。</p><table tabindex="0"><thead><tr><th>Getter</th><th>返回的计算引用</th></tr></thead><tbody><tr><td><code>getMenuOptions</code></td><td>应用菜单树,包含子项。显示逻辑还会使用路由元数据。</td></tr><tr><td><code>getBreadcrumbOptions</code></td><td>当前面包屑项。</td></tr><tr><td><code>getMenuKey</code></td><td>当前菜单 key,通常取完整路径。</td></tr><tr><td><code>getMenuTagOptions</code></td><td>工作区标签列表。</td></tr><tr><td><code>getCurrentMenuOption</code></td><td>当前激活菜单项,初始可能为空。</td></tr><tr><td><code>getCollapsed</code></td><td>侧栏是否折叠。</td></tr></tbody></table><table tabindex="0"><thead><tr><th>Action</th><th>行为</th></tr></thead><tbody><tr><td><code>setupAppMenu()</code></td><td>从已知路由重建菜单、标签与标题,返回 <code>Promise<void></code>。模板会在路由联动首次运行时初始化。</td></tr><tr><td><code>resolveOption(option)</code></td><td>把路由形状转成菜单项。调用方须提供正确的 <code>fullPath</code>,用于 key 和查找。</td></tr><tr><td><code>changeMenuModelValue(key, option, query?)</code></td><td>导航并同步状态;<code>meta.windowOpen</code> 分支打开外部页面。<code>sameLevel</code> 会保留原菜单标签并补面包屑。</td></tr><tr><td><code>collapsedMenu(collapsed)</code></td><td>更新折叠状态。</td></tr><tr><td><code>setMenuTagOptions(options, isAppend = true)</code></td><td>追加或替换标签,参数可为单项或数组。</td></tr><tr><td><code>spliceMenTagOptions(idx, length = 1)</code></td><td>按索引删除标签,拼写保留历史契约。</td></tr><tr><td><code>updateMenuState(key, value, callback?)</code></td><td>更新已有状态字段,普通对象浅合并。需要跨字段联动时使用上述动作。</td></tr></tbody></table><p><code>depthSearchAppMenu(options, key)</code> 从菜单树按完整路径查找菜单项。<code>changeMenuModelValue</code> 不返回 Router 的导航 Promise;需要等待守卫结果时使用 Router 或 <code>navigationTo</code>。更新角色后还要同步服务端授权及直接路由校验,菜单过滤本身不能授权。</p><p><code>piniaMenuStore</code> 在 Local Storage 只持久化 <code>menuKey</code>、<code>collapsed</code>。标签列表单独使用 Session Storage 的 <code>appMenuTagOptions</code>。当前路由变化会重新同步菜单与面包屑,避免手工写缓存制造冲突。</p><h2 id="keepalive-store" tabindex="-1">KeepAlive Store <a class="header-anchor" href="#keepalive-store" aria-label="Permalink to "KeepAlive Store""></a></h2><p><code>useKeepAliveGetters().getKeepAliveInclude</code> 是缓存名称数组的计算引用。<code>useKeepAliveActions()</code> 提供 <code>getKeepAliveInclude()</code> 读队列、<code>setKeepAliveInclude(option)</code> 按路由选项加入名称。仅处理 <code>meta.keepAlive</code> 的页面,达到上限时先移除最早的名称再追加当前名称。实际缓存由 <a href="./../components/route-transition.html">RTransitionComponent</a> 渲染。</p><ul><li>路由 <code>name</code> 必须和页面组件名一致,否则 <code>include</code> 无法匹配。</li><li>Store 只在当前浏览器标签的 Session Storage 持久化名称。刷新后组件实例与表单状态重新创建。</li><li>开关、排除名称和数量在 <a href="./setting.html">Setting Store</a> 的 <code>keepAliveConfig</code> 配置。确认嵌套路由和 query 变化后,测试切回标签的结果。</li></ul><div class="language-ts vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">ts</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { useKeepAliveGetters, useMenuGetters } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> '@/store'</span></span>
|
||
<span class="line"></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">export</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> function</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> useNavigationSummary</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">() {</span></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> const</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">getMenuKey</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">getMenuTagOptions</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> useMenuGetters</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> const</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">getKeepAliveInclude</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> } </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> useKeepAliveGetters</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">()</span></span>
|
||
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> { getMenuKey, getMenuTagOptions, getKeepAliveInclude }</span></span>
|
||
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p><a href="https://github.com/XiaoDaiGua-Ray/ray-template/blob/b5c24a612c0bb6dcf857f058aeaf610ebfcf2eb7/apps/admin/src/store/modules/menu/index.ts" target="_blank" rel="noreferrer">Menu 实现</a> · <a href="https://github.com/XiaoDaiGua-Ray/ray-template/blob/b5c24a612c0bb6dcf857f058aeaf610ebfcf2eb7/apps/admin/src/store/hooks/useMenuStore.ts" target="_blank" rel="noreferrer">Menu Hooks</a> · <a href="https://github.com/XiaoDaiGua-Ray/ray-template/blob/b5c24a612c0bb6dcf857f058aeaf610ebfcf2eb7/apps/admin/src/store/modules/keep-alive/index.ts" target="_blank" rel="noreferrer">KeepAlive 实现</a></p>`,12)])])}const u=t(n,[["render",o]]);export{k as __pageData,u as default};
|