ADD-MENU-GUIDE-EQUITY.md 4.84 KB

权益首页新增菜单维护指南

面向 packageEquity 权益首页(packageEquity/pages/index Component)。精品首页见 tabIndex/docs/ADD-MENU-GUIDE.md。不可引用 tabIndex/menu/(分包隔离)。

相关架构:MENU-ARCHITECTURE.md · 字段 JSDoc:registry.js 顶部


1. 数据流(一句话)

菜单定义在注册表 → 管道组装 → 页面单次 setData({ menuList }) → WXML 渲染 → 点击按 action.type 跳转。不要在 index.js 里 push 菜单项。

flowchart LR
  registry["registry.js"]
  build["buildMenus.js"]
  page["index.js rebuildEquityMenus"]
  wxml["index.wxml"]
  jump["jumpHandlers.js"]

  registry --> build --> page --> wxml
  wxml -->|bindtap navGo| jump
概念 说明
稳定主键 id(snake_case)
展示文案 label → view model 的 menuText
场景 sceneType: 0;动态表单 appendDynamicFormEquityMenusAsync
mode properties.mode 控制 defeat_order;observer → rebuildEquityMenus({ force: true })

2. 先判断:要改哪些文件?

场景 改动的文件
A 同步 + 权限显隐 + 已有 action.type 仅 EQUITY_MENU_REGISTRY
B 接口决定显隐 ASYNC_MENU_REGISTRY + asyncProviders.js
C 动态表单三入口 utils/dynamicFormMenus.js(已有 dynamicForm provider)
D 全新跳转方式 jumpHandlers.js + registry action.type
E 角标需接口刷新 badgeProviders.js 按 id 扩展
F 新权限谓词 policies.js + registry visible

跨首页契约:packageDynamicForm/docs/routes-and-menus.md


3. 示例 A — 同步 router(员工可见)

{
  id: 'my_feature',
  label: '我的功能',
  icon: 'my_icon',
  section: MENU_SECTION.MAIN,
  sortVal: 20,
  action: { type: 'router', target: 'packageEquity.myPage' },
  visible: ({ isStaff }) => isStaff
}

defeat_order 需同时判断 mode:

visible: ({ isStaff, policies }) =>
  isStaff && policies.hasDefeatOrderMode()

4. 示例 B — 异步 provider

registry.js ASYNC_MENU_REGISTRY:

{
  id: 'my_async_menu',
  label: '异步入口',
  icon: 'async_icon',
  section: MENU_SECTION.MAIN,
  sortVal: 21,
  action: { type: 'router', target: 'packageEquity.myPage' },
  provider: 'myAsyncMenu'
}

asyncProviders.js:

async function resolveMyAsyncMenu(ctx, commonApi) {
  const res = await commonApi.someApi({})
  return { myAsyncMenu: { visible: !!res?.data } }
}
// resolveAsyncMenuProviders 的 providers 数组中注册
  • packageEquity.extract / salaryAppeal / missingReception 路由 toViewModel 会自动写 path

5. 示例 C — 角标(待审批模式)

在 badgeProviders.js 的 applyEquityMenuBadges 中按 id 查找下标并 setData:

const index = menuList.findIndex(e => e.id === 'my_menu')
if (index > -1) {
  someApi().then(res => {
    page.setData({ [`menuList[${index}].tipsNum`]: res.data.count })
  })
}

registry 可设 tipsNum: 0 初值。


6. 权益特有 action.type

type 行为
createOrderPrompt 校验链 + showPromptDialog
defeatOrder 鸿蒙智行品牌判断 + 校验 + scene: 0
workReport 工作日报/周报/月报模版弹窗
salaryPerformance collegeScene reLaunch
residentTarget 带 taskId

7. 检查清单

  • id 为 snake_case(IT-EQ-MENU-GUIDE-001)
  • 未在 index.js 内联 menuList.push
  • mode 相关项用 policies.hasDefeatOrderMode() 或 ctx.mode
  • 双首页都要上:另改 tabIndex/menu/ + 更新 routes-and-menus.md
  • 补 packageEquity/tests/equityMenu.test.mjs 用例
  • npm run test:equity 全绿

8. 单测模板

it('IT-EQ-MENU-SYNC-XXX: my_menu visible for staff', () => {
  const menuList = buildEquityMenusSync(
    createEquityMenuContext({
      userInfo: { loginRole: 4 },
      isStaff: true,
      mode: 1
    })
  )
  assert.ok(menuList.some(i => i.id === 'my_feature'))
})
npm run test:equity

用例文件:equityMenu.test.mjs、equityMenuJump.test.mjs


9. 四步速记

  1. 判断场景(第 2 节)→ 确定改哪些文件
  2. 在 registry.js(或 async provider)加条目
  3. 补 equityMenu.test.mjs 用例
  4. npm run test:equity + 真机点一遍(含 mode 切换)