registry.js 10.9 KB
import { RECRUIT_MENU_ENABLED } from '../../config.js'
import { AI_ROUTES } from '../../router/routeAliases.js'
import { MENU_SECTION } from './constants.js'
import {
	DYNAMIC_FORM_EQUITY_MENUS,
	resolveDynamicFormMenuId
} from '../../utils/dynamicFormMenus.js'

/**
 * @typedef {import('./context.js').createEquityMenuContext extends (...args: any[]) => infer R ? R : never} EquityMenuContext
 * 菜单管道上下文:`userInfo`、`isStaff`、`mentorFlag`、`mode`;`ctx.policies` 见 {@link ./policies.js}
 */

/**
 * 菜单跳转指令,由 {@link ./toViewModel.js} 映射为 WXML 字段,由 {@link ./jumpHandlers.js} 按 type 分发。
 *
 * @typedef {Object} EquityMenuAction
 * @property {'router'|'navigate'|'workReport'|'salaryPerformance'|'residentTarget'|'createOrderPrompt'|'defeatOrder'} type
 *   跳转类型,对应 jumpHandlers handlers 键
 * @property {string} [target]
 *   路由名(router)、分包 navigateToUrl(navigate)、workReport 占位路由
 * @property {Object} [params]
 *   传给 `wx.$router.go(target, { params })` 的参数
 * @property {boolean} [usePath]
 *   为 true 时 toViewModel 写 `path`(如 pending_approval)
 * @property {string} [trackEventCode]
 *   navigate 类型点击埋点 eventCode(如 scenario_marketplace)
 */

/**
 * 同步注册表条目(EQUITY_MENU_REGISTRY)。新增条目请对照本类型必填项。
 *
 * @typedef {Object} EquityMenuRegistryEntry
 * @property {string} id
 *   稳定主键:去重、`applyEquityMenuBadges`、`jumpHandlers` 按 id 分支均依赖此字段
 * @property {string} label
 *   展示文案;toViewModel 映射为 `menuText` 供 WXML `item.menuText`
 * @property {string} icon
 *   CDN 图标文件名;权益 WXML 拼接 `crowdFunding/{icon}.png`
 * @property {'main'|'secondary'} section
 *   权益首页统一写入 `data.menuList`(见 MENU-ARCHITECTURE.md)
 * @property {EquityMenuAction} action
 *   跳转指令,必填
 * @property {(ctx: EquityMenuContext) => boolean} visible
 *   同步管道显隐;buildEquityMenusSync 过滤
 * @property {number} [sortVal]
 *   升序排序,越小越靠前
 *
 * --- 可选 UI ---
 * @property {number} [tipsNum]
 *   数字角标:registry 初值 + `applyEquityMenuBadges` 按 id 更新
 * @property {boolean} [noRead]
 *   未读气泡;residentTarget provider 注入 → WXML `bubble_icon`
 * @property {boolean} [default]
 *   标记默认展示类异步入口(文档用,管道不单独处理)
 *
 * --- 可选跳转 / 校验 ---
 * @property {number} [recordId]
 *   埋点 id;jumpHandlers / openWorkReportTemp 调用 pointRecord
 * @property {string} [beforeClick]
 *   跳转前 `wx.$globalDataFunction[beforeClick]()`,返回 true 则中断
 * @property {boolean} [noCheckdailyReport]
 *   为 true 时跳过日报/学习中心/异常单校验(权益 workReport 基座项)
 * @property {'daily'|'weekly'|'monthly'} [reportTypeAttr]
 *   workReport 模版类型
 * @property {string} [reportTypeVal]
 *   工作报表模版 type 参数('1'/'2'/'3')
 */

/**
 * 异步 provider 注入的 view model 附加字段。
 *
 * @typedef {Object} EquityMenuViewModelExtras
 * @property {boolean} [noRead]
 *   驻店目标未读气泡
 * @property {number} [tipsNum]
 *   角标数字;customerClue provider 可注入初值
 */

/**
 * 权益首页同步菜单注册表(单一数据源)。
 * 架构文档见 packageEquity/docs/MENU-ARCHITECTURE.md
 * **新增菜单流程**:packageEquity/docs/ADD-MENU-GUIDE-EQUITY.md
 * 跨首页 id 契约:packageDynamicForm/docs/routes-and-menus.md
 * 变更记录:packageEquity/docs/DEVLOG.md
 *
 * @type {EquityMenuRegistryEntry[]}
 */
export const EQUITY_MENU_REGISTRY = [
	// --- 工作报表基座(仅权益首页常驻)---
	{
		id: 'work_daily_report',
		label: '工作日报',
		icon: 'supervisorDailyNew',
		section: MENU_SECTION.MAIN,
		sortVal: 8,
		recordId: 15,
		noCheckdailyReport: true,
		reportTypeAttr: 'daily',
		reportTypeVal: '1',
		action: { type: 'workReport', target: 'tabWorkOrder.supervisorDaily' },
		visible: () => true
	},
	{
		id: 'work_weekly_report',
		label: '工作周报',
		icon: 'weeklyReport',
		section: MENU_SECTION.MAIN,
		sortVal: 9,
		recordId: 18,
		noCheckdailyReport: true,
		reportTypeAttr: 'weekly',
		reportTypeVal: '2',
		action: { type: 'workReport', target: 'tabWorkOrder.supervisorDaily' },
		visible: () => true
	},
	{
		id: 'work_monthly_report',
		label: '工作月报',
		icon: 'monthlyReport',
		section: MENU_SECTION.MAIN,
		sortVal: 10,
		recordId: 19,
		noCheckdailyReport: true,
		reportTypeAttr: 'monthly',
		reportTypeVal: '3',
		action: { type: 'workReport', target: 'tabWorkOrder.supervisorDaily' },
		visible: () => true
	},
	// --- 员工 / 督导同步入口 ---
	{
		id: 'staff_daily_report',
		label: '驻店日报',
		icon: 'supplementary_order',
		section: MENU_SECTION.MAIN,
		sortVal: 11,
		recordId: 13,
		action: { type: 'router', target: 'tabWorkOrder.staffDaily' },
		visible: ({ policies }) => policies.staffOrMultiStoreDaily()
	},
	{
		id: 'create_order',
		label: '新建工单',
		icon: 'create_order',
		section: MENU_SECTION.MAIN,
		sortVal: 1,
		beforeClick: 'inspectionOfProhibitionBill',
		action: { type: 'createOrderPrompt', target: '' },
		visible: ({ isStaff }) => isStaff
	},
	{
		id: 'abnormal_flow_approval',
		label: '异常流水审批',
		icon: 'refund_review_icon',
		section: MENU_SECTION.MAIN,
		sortVal: 5,
		noCheckdailyReport: true,
		action: {
			type: 'router',
			target: 'tabWorkOrder.abnormalFlowList',
			usePath: true
		},
		visible: ({ isStaff }) => isStaff
	},
	{
		id: 'defeat_order',
		label: '战败下单',
		icon: 'deafeat_order',
		section: MENU_SECTION.MAIN,
		sortVal: 2,
		action: {
			type: 'defeatOrder',
			target: 'packageEquity.createDeafeatOrderBefore'
		},
		visible: ({ isStaff, policies }) =>
			isStaff && policies.hasDefeatOrderMode()
	},
	{
		id: 'bi_report',
		label: 'BI报表',
		icon: 'business_data',
		section: MENU_SECTION.MAIN,
		sortVal: 21,
		recordId: 11,
		action: { type: 'router', target: 'tabOperating.index' },
		visible: ({ policies }) => policies.canSelectMultiStore()
	},
	// --- 角色特有条件 ---
	{
		id: 'delivery_target',
		label: '交车目标',
		icon: 'delivery_target',
		section: MENU_SECTION.MAIN,
		sortVal: 18,
		action: { type: 'router', target: 'packageEquity.deliveryTarget' },
		visible: ({ policies }) => policies.isDeliveryTargetRole()
	},
	{
		id: 'training_materials',
		label: '培训资料',
		icon: 'peixun_icon',
		section: MENU_SECTION.MAIN,
		sortVal: 15,
		action: { type: 'router', target: 'packageEquity.trainingMaterials' },
		visible: ({ policies }) => !policies.canSelectMultiStore()
	},
	{
		id: 'scene_market',
		label: '场景集市',
		icon: 'sceneMarket',
		section: MENU_SECTION.MAIN,
		sortVal: 16,
		action: {
			type: 'navigate',
			target: '/packageEquity/pages/sceneMarket/index/index',
			trackEventCode: 'scenario_marketplace'
		},
		visible: ({ policies }) =>
			policies.canViewRecruit() || policies.canViewMentorship()
	},
	// --- 区域运营 ---
	{
		id: 'recruit_manage',
		label: '招聘管理',
		icon: 'recruit-manage',
		section: MENU_SECTION.MAIN,
		sortVal: 22,
		tipsNum: 0,
		action: { type: 'router', target: 'packageEquity.recruitManage' },
		visible: ({ policies }) =>
			RECRUIT_MENU_ENABLED && policies.canViewRecruit()
	},
	{
		id: 'pending_approval',
		label: '待审批',
		icon: 'refund_review_icon',
		section: MENU_SECTION.MAIN,
		sortVal: 23,
		tipsNum: 0,
		action: {
			type: 'router',
			target: 'tabWorkOrder.refundOperationList',
			usePath: true
		},
		visible: ({ policies }) => policies.canViewRecruit()
	},
	{
		id: 'study_center',
		label: '学习中心',
		icon: 'study-center',
		section: MENU_SECTION.MAIN,
		sortVal: 24,
		action: { type: 'router', target: 'packageStudyCenter.studyCenter' },
		visible: ({ isStaff, policies }) =>
			isStaff && policies.notJiLianChannel()
	}
]

/**
 * 异步 provider 控制的菜单(不在同步管道默认输出)。
 * 显隐由 {@link ./asyncProviders.js} 中 provider 返回值决定。
 *
 * @typedef {Omit<EquityMenuRegistryEntry, 'visible'> & {
 *   provider: string,
 *   visible?: (ctx: EquityMenuContext) => boolean
 * }} AsyncEquityMenuRegistryEntry
 *
 * @type {AsyncEquityMenuRegistryEntry[]}
 */
export const ASYNC_MENU_REGISTRY = [
	{
		id: 'salary_appeal',
		label: '工资申诉',
		icon: 'salary_appeal_icon',
		section: MENU_SECTION.MAIN,
		sortVal: 25,
		action: { type: 'router', target: 'packageEquity.salaryAppeal' },
		provider: 'salaryAppeal'
	},
	{
		id: 'missing_reception',
		label: '接待缺失报备',
		icon: 'missing-reception',
		section: MENU_SECTION.MAIN,
		sortVal: 26,
		action: { type: 'router', target: 'packageEquity.missingReception' },
		provider: 'missingReception'
	},
	{
		id: 'script_extract',
		label: '话术萃取',
		icon: 'extract_icon',
		section: MENU_SECTION.MAIN,
		sortVal: 12,
		default: true,
		action: {
			type: 'router',
			target: 'packageEquity.extract',
			params: { type: 1 }
		},
		provider: 'scriptExtract'
	},
	{
		id: 'script_verify',
		label: '话术核验',
		icon: 'verification_icon',
		section: MENU_SECTION.MAIN,
		sortVal: 13,
		default: true,
		action: {
			type: 'router',
			target: 'packageEquity.extract',
			params: { type: 2 }
		},
		provider: 'scriptVerify'
	},
	{
		id: 'ai_fun_practice',
		label: 'AI趣练',
		icon: 'ai_chat',
		section: MENU_SECTION.MAIN,
		sortVal: 14,
		default: true,
		action: { type: 'router', target: AI_ROUTES.aiCheckStart },
		provider: 'aiFunPractice'
	},
	{
		id: 'customer_clue',
		label: '客户线索',
		icon: 'customer_clue',
		section: MENU_SECTION.MAIN,
		sortVal: 4,
		default: true,
		tipsNum: 0,
		action: { type: 'router', target: 'packageEquity.clueList' },
		provider: 'customerClue'
	},
	{
		id: 'salary_performance_api',
		label: '工资绩效',
		icon: 'businessschoo',
		section: MENU_SECTION.MAIN,
		sortVal: 17,
		action: { type: 'salaryPerformance' },
		provider: 'salaryPerformance'
	},
	{
		id: 'resident_target',
		label: '驻店目标',
		icon: 'resident_target',
		section: MENU_SECTION.MAIN,
		sortVal: 19,
		action: { type: 'residentTarget', target: 'packageEquity.residentTarget' },
		provider: 'residentTarget'
	},
	{
		id: 'reception_records',
		label: '接待记录',
		icon: 'reception-record-icon',
		section: MENU_SECTION.MAIN,
		sortVal: 3,
		default: true,
		action: { type: 'router', target: 'packageEquity.receptionRecords' },
		provider: 'receptionRecords'
	},
	{
		id: 'illegal_recording',
		label: '违规录音处理',
		icon: 'illegal-recording',
		section: MENU_SECTION.MAIN,
		sortVal: 20,
		default: true,
		action: {
			type: 'navigate',
			target: '/packageEquity/pages/receptionRecords/receptionRecords?hideScore=1'
		},
		provider: 'illegalRecording'
	}
]

/**
 * 动态表单入口 id 按稳定路由/埋点元数据解析。
 * 实际菜单项由 `dynamicForm` provider 注入,此处仅登记 id 供查找与单测。
 */
export const DYNAMIC_FORM_MENU_IDS = DYNAMIC_FORM_EQUITY_MENUS.map(item => ({
	id: resolveDynamicFormMenuId(item),
	label: item.menuText,
	provider: 'dynamicForm',
	sortVal: item.sortVal
}))