完成50%
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// 当前两个产品选项同时决定 OpenAPI GenealogyCreate/UpdateBody 的
|
||||
// visibility 与 joinMode,因此它们是“访问预设”,不是单一可见范围。
|
||||
export const GENEALOGY_ACCESS_PRESET = Object.freeze({
|
||||
MEMBER_ONLY: "MEMBER_ONLY",
|
||||
PUBLIC_APPLY: "PUBLIC_APPLY",
|
||||
});
|
||||
|
||||
export const GENEALOGY_ACCESS_PRESET_OPTIONS = Object.freeze([
|
||||
Object.freeze({
|
||||
value: GENEALOGY_ACCESS_PRESET.MEMBER_ONLY,
|
||||
label: "仅成员可见",
|
||||
}),
|
||||
Object.freeze({
|
||||
value: GENEALOGY_ACCESS_PRESET.PUBLIC_APPLY,
|
||||
label: "公开可申请",
|
||||
}),
|
||||
]);
|
||||
|
||||
export const isGenealogyAccessPreset = (preset) =>
|
||||
Object.values(GENEALOGY_ACCESS_PRESET).includes(preset);
|
||||
|
||||
// 当前导出只在字段说明中给出 0/1/2 示例,并未提供正式 enum。这里锁住页面
|
||||
// 当前能表达的两个组合,未知组合一律返回 null;邀请码模式必须等后端合同补齐,
|
||||
// 不能把 PUBLIC_APPLY 冒充 joinMode=2。
|
||||
const apiAccessByPreset = Object.freeze({
|
||||
[GENEALOGY_ACCESS_PRESET.MEMBER_ONLY]: Object.freeze({
|
||||
visibility: "2",
|
||||
joinMode: "0",
|
||||
}),
|
||||
[GENEALOGY_ACCESS_PRESET.PUBLIC_APPLY]: Object.freeze({
|
||||
visibility: "1",
|
||||
joinMode: "1",
|
||||
}),
|
||||
});
|
||||
|
||||
export const getGenealogyAccessPresetLabel = (preset) =>
|
||||
GENEALOGY_ACCESS_PRESET_OPTIONS.find((item) => item.value === preset)
|
||||
?.label || "访问规则待确认";
|
||||
|
||||
export const toApiGenealogyAccess = (preset) => {
|
||||
const access = apiAccessByPreset[preset];
|
||||
return access ? { ...access } : null;
|
||||
};
|
||||
|
||||
export const fromApiGenealogyAccess = ({ visibility, joinMode } = {}) => {
|
||||
const match = Object.entries(apiAccessByPreset).find(
|
||||
([, access]) =>
|
||||
access.visibility === visibility && access.joinMode === joinMode,
|
||||
);
|
||||
return match?.[0] || null;
|
||||
};
|
||||
Reference in New Issue
Block a user