MENU-ARCHITECTURE.md
7.96 KB
权益首页 Menu 架构
园区店 ID 用法:全量
docs/YQ-MERCHANT-ID-USAGE.md;sceneType:0 专章docs/EQUITY-SCENE0-YQ-MERCHANT-ID.md。
新增菜单(维护者入口)
新增/修改权益首页菜单项,请先阅读 ADD-MENU-GUIDE-EQUITY.md:含决策流程、示例、检查清单与单测模板。字段细节以本文与 registry.js JSDoc 为准。
精品首页对照:tabIndex/docs/MENU-ARCHITECTURE.md(不可 cross-import tabIndex/menu/)。
数据流
flowchart TD
registry["EQUITY_MENU_REGISTRY / ASYNC_MENU_REGISTRY"]
ctx["createEquityMenuContext"]
sync["buildEquityMenusSync"]
async["resolveAsyncMenuProviders"]
merge["dedupe + sort"]
page["index.js rebuildEquityMenus → setData menuList"]
jump["createEquityMenuJumpHandler → action.type"]
registry --> sync
ctx --> sync
ctx --> async
sync --> merge
async --> merge
merge --> page
page --> jump
模块职责
| 文件 | 导出 | 职责 |
|---|---|---|
constants.js |
SCENE_TYPE, MENU_SECTION
|
权益场景常量(sceneType: 0) |
policies.js |
createPolicies |
从 userInfo / mentorFlag / mode 派生权限谓词 |
context.js |
createEquityMenuContext, getMenuFingerprint
|
构建管道上下文;脏标记指纹(含 mode) |
registry.js |
EQUITY_MENU_REGISTRY, ASYNC_MENU_REGISTRY, DYNAMIC_FORM_MENU_IDS
|
菜单单一数据源 |
toViewModel.js |
registryItemToViewModel |
label→menuText,action→path/navigateToUrl
|
buildMenus.js |
buildEquityMenusSync, buildEquityMenusAsync
|
同步过滤 + 异步合并 |
asyncProviders.js |
resolveAsyncMenuProviders, resolveCustomerClue
|
并行拉接口决定显隐 |
resolveActionType.js |
resolveActionType |
从 view model 解析 action.type
|
jumpHandlers.js |
createEquityMenuJumpHandler |
点击跳转分发 |
badgeProviders.js |
applyEquityMenuBadges |
待审批/招聘/客户线索角标 |
workReportHandler.js |
openWorkReportTemp, onWorkReportPopupSelect
|
工作日报/周报/月报模版 |
WXML 与 view model
首页 index.wxml 单列表 menuList:
| 字段 | WXML 绑定 | 说明 |
|---|---|---|
menuText |
{{ item.menuText }} |
由 label 映射 |
icon |
crowdFunding/{{ item.icon }}.png |
权益固定 crowdFunding/ 前缀 |
tipsNum |
角标数字 | registry 初值 + applyEquityMenuBadges
|
noRead |
bubble_icon |
驻店目标未读 |
注册表字段
字段定义源码:registry.js 顶部 EquityMenuRegistryEntry / EquityMenuAction。
同步条目(EQUITY_MENU_REGISTRY)
| 字段 | 必填 | 消费方 | 说明 |
|---|---|---|---|
id |
是 |
buildMenus 去重、applyEquityMenuBadges、jumpHandlers
|
稳定主键 |
label |
是 |
toViewModel → menuText
|
WXML 展示文案 |
icon |
是 | index.wxml |
crowdFunding/{icon}.png |
section |
是 | 文档/契约 | 权益统一进 menuList
|
action |
是 |
toViewModel、jumpHandlers
|
跳转指令 |
visible |
是 | buildEquityMenusSync |
(ctx) => boolean |
sortVal |
建议 |
buildMenus sort |
升序 |
action.type 一览(权益)
| type | 消费方 | 行为 |
|---|---|---|
router |
jumpHandlers.router |
wx.$router.go,默认 scene: 0
|
navigate |
jumpHandlers.navigate |
wx.navigateTo + 动态表单/场景集市埋点 |
workReport |
jumpHandlers.workReport |
openWorkReportTemp(工作日报三件套) |
createOrderPrompt |
jumpHandlers.createOrderPrompt |
校验链 + showPromptDialog
|
defeatOrder |
jumpHandlers.defeatOrder |
品牌判断 path + 校验 + 跳转 |
salaryPerformance |
jumpHandlers.salaryPerformance |
collegeScene reLaunch |
residentTarget |
jumpHandlers.residentTarget |
驻店目标,带 taskId
|
跳转副作用(shutDownTaskApi)
| 菜单 id | taskId | scene | 触发位置 |
|---|---|---|---|
training_materials |
5 | 0 |
jumpHandlers SHUTDOWN_TASK_BY_ID
|
resolveActionType 回退链
-
reportTypeAttr或path === 'tabWorkOrder.supervisorDaily'→workReport -
navigateToUrl→navigate - 无
path且menuText === '工资绩效'→salaryPerformance - 无
path且id === 'create_order'→createOrderPrompt - 默认 →
router
异步 Provider
| provider key | 菜单 id | 角色 / 前置条件 | 接口 / 显隐逻辑 |
|---|---|---|---|
salaryAppeal |
salary_appeal |
— | 超管直显;否则 hasPerformanceConfig 且 (canViewRecruit \ |
missingReception |
missing_reception |
isStaff \ |
canSelectMultiStoreForStaffDaily |
scriptExtract |
script_extract |
— |
canViewViolation \ |
scriptVerify |
script_verify |
— |
extractCheck;(超管 \ |
aiFunPractice |
ai_fun_practice |
isNotMentor |
同步谓词 |
customerClue |
customer_clue |
— | getYqStoreConfig.customerExchangeFlag === 'Y' |
salaryPerformance |
salary_performance_api |
— |
getBusinessSchoolScene 有结果则显 |
residentTarget |
resident_target |
isStaff、非 canSelectMultiStore
|
getStaffTargetTaskApi(sceneType:0) + task 弹窗 sideEffects |
receptionRecords |
reception_records |
门店在质检列表 \ | 多店督导;且 isNotMentor
|
illegalRecording |
illegal_recording |
同上(无导师限制) | 同上 |
mentorFlag |
— | 非多店督导 |
getStaffMentorFlag → sideEffects.mentorFlag 触发二次重建 |
dynamicForm |
三入口 id |
sceneType:0 + 角色门禁 |
appendDynamicFormEquityMenusAsync |
Provider 返回:{ [key]: { visible, extras?, sideEffects? } };dynamicForm 另返回 items[]。
页面集成(Component)
约束:packageEquity/menu/asyncProviders.js 禁止运行时 import()(微信分包会 403)。API 须在页面层 静态 import 后通过 deps 注入 buildEquityMenusAsync。
// packageEquity/pages/index/index.js
import commonApi from '~/api/api'
import aiApi from '../../aiApi'
import carLifeApi from '../../carEquityApi'
import { checkMerchantDirect, checkMissingReception } from '../../receptionRecordsApi'
import {
buildEquityMenusAsync,
createEquityMenuJumpHandler,
applyEquityMenuBadges
} from '../../menu/index.js'
async rebuildEquityMenus() {
const result = await buildEquityMenusAsync({
userInfo, isStaff, mentorFlag, mode,
deps: {
commonApi,
aiApi,
carLifeApi,
receptionRecordsApi: { checkMerchantDirect, checkMissingReception },
getBusinessSchoolScene
}
})
this.setData({ menuList: result.menuList })
}
// mode 变化
properties.mode.observer() { this.rebuildEquityMenus({ force: true }) }
buildEquityMenusAsync 在异步 provider 异常时会 回退同步菜单(syncItems),避免整页空白。
测试
npm run test:equity
用例前缀:IT-EQ-MENU-*(equityMenu.test.mjs、equityMenuJump.test.mjs)。
Mock:测试顶部 setupWxMock;异步用 createDefaultEquityAsyncDeps 注入 API。