policies.js 1.49 KB
const perm = () => wx?.$hasPermission || {}

/**
 * 从 EquityMenuContext 派生可组合权限谓词,供 registry `visible(ctx)` 使用
 *
 * @param {Object} ctx - createEquityMenuContext 返回值
 * @returns {Record<string, () => boolean>}
 */
export function createPolicies(ctx) {
	const { userInfo, isStaff, mentorFlag, mode } = ctx
	const p = perm()

	return {
		/** 超管 */
		isSuper: () => p.isSuper?.(userInfo),
		/** 非飞行督导 */
		isNotMentor: () => p.isNotMentor?.(userInfo),
		/** 可多选门店(督导/超管等) */
		canSelectMultiStore: () => p.canSelectMultiStore?.(userInfo),
		/** 驻店日报相关权限 */
		canSelectMultiStoreForStaffDaily: () =>
			p.canSelectMultiStoreForStaffDaily?.(userInfo),
		canViewMentorship: () => p.canViewMentorship?.(userInfo),
		canViewRecruit: () => p.canViewRecruit?.(userInfo),
		canViewViolation: () => p.canViewViolation?.(userInfo),
		/** 员工或具备驻店日报督导权限 */
		staffOrMultiStoreDaily: () =>
			isStaff || p.canSelectMultiStoreForStaffDaily?.(userInfo),
		/** 非冀联园区 channelType!=9 */
		notJiLianChannel: () => userInfo?.subLoginUser?.channelType != 9,
		/** 违规查看权限或导师标记 */
		mentorOrViolation: () =>
			p.canViewViolation?.(userInfo) || mentorFlag,
		/** 驻店负责人(loginRoleOnSelectMerchant==4)且为员工 */
		isDeliveryTargetRole: () =>
			isStaff && userInfo?.loginRoleOnSelectMerchant == 4,
		/** properties.mode 为真时展示战败下单 */
		hasDefeatOrderMode: () => !!mode
	}
}