UNPKG

yanzhen-design-vue

Version:

61 lines (60 loc) 1.82 kB
import "../../../_utils/index.mjs"; import { Contacts, contactsTypes } from "../constants/contacts.mjs"; import { ListMode } from "../constants/list-mode.mjs"; import { CONTACTS_API_KEY } from "../constants/apis.mjs"; import { getUserListMode, getUserDefaultRefs } from "./user.mjs"; import { createContactsDefaultRef } from "./createContactsDefaultRef.mjs"; import { $enum } from "ts-enum-util"; import { handleUndefined } from "../../../_utils/enum-utils.mjs"; const getApiSymbol = () => { return { ...CONTACTS_API_KEY }; }; const contactsEnum = $enum(Contacts); function getContactsLabel(contacts) { return $enum.mapValue(contacts).with({ [Contacts.USUALLY]: "常用", [Contacts.USER]: "用户", [Contacts.OUTORG]: "往来单位", [Contacts.ROLE]: "角色", [Contacts.ORGANIZATION]: "组织", [Contacts.GROUP]: "群组", [handleUndefined]: "Unspecified" }); } function getContactsListMode(contacts, children) { return $enum.mapValue(contacts).with({ [Contacts.USUALLY]: ListMode.LIST, [Contacts.USER]: getUserListMode(children), [Contacts.OUTORG]: ListMode.LIST, [Contacts.ROLE]: ListMode.LIST, [Contacts.ORGANIZATION]: ListMode.TREE, [Contacts.GROUP]: ListMode.LIST, [handleUndefined]: "Unspecified" }); } const getContactsTypesMaps = () => { return contactsEnum.map((k) => { return { value: k, label: getContactsLabel(k) }; }); }; const useContactsDefaultRefs = () => { return contactsTypes.reduce((prev, key) => { if (key === Contacts.USER) { prev[key] = getUserDefaultRefs(); } else { prev[key] = createContactsDefaultRef(key); } return prev; }, {}); }; export { contactsEnum, getApiSymbol, getContactsLabel, getContactsListMode, getContactsTypesMaps, useContactsDefaultRefs };